From b701039cdb137f46f876e6bc6125a6e148794529 Mon Sep 17 00:00:00 2001 From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> Date: Fri, 22 Feb 2008 14:45:45 -0500 Subject: [PATCH] Add user config for audio devices in GTk GUI The server sends the list of the sound card it founds on the system to the GTk without checking it is a capture or a playback device TODO: improve the list sent ( must add abstraction device plug, default, etc..) TODO: improve sound quality for capture --- sflphone-gtk/src/configwindow.c | 39 +- src/audio/audiolayer.cpp | 258 +++++++---- src/audio/audiolayer.h | 28 +- src/audio/audiortp.cpp | 2 +- src/global.h | 15 +- src/iaxvoiplink.cpp | 8 +- src/managerimpl.cpp | 786 ++++++++++++++++---------------- src/sipcall.cpp | 1 - 8 files changed, 607 insertions(+), 530 deletions(-) diff --git a/sflphone-gtk/src/configwindow.c b/sflphone-gtk/src/configwindow.c index 09e8df5413..94030500b6 100644 --- a/sflphone-gtk/src/configwindow.c +++ b/sflphone-gtk/src/configwindow.c @@ -169,8 +169,7 @@ config_window_fill_output_audio_device_list() { GtkTreeIter iter; gchar** list; - gchar** details; - gchar* audioDevice; + gchar** audioDevice; gtk_list_store_clear(outputAudioDeviceManagerStore); @@ -179,13 +178,11 @@ config_window_fill_output_audio_device_list() // For each device name included in list int c = 0; - for(audioDevice = list[c]; audioDevice != NULL; audioDevice = list[c]) + for(audioDevice = list; *list ; list++) { - c++; - int index = atoi(audioDevice); - details = dbus_get_audio_device_details(index); gtk_list_store_append(outputAudioDeviceManagerStore, &iter); - gtk_list_store_set(outputAudioDeviceManagerStore, &iter, 0, details[0], 1, index, -1); + gtk_list_store_set(outputAudioDeviceManagerStore, &iter, 0, *list, 1, c, -1); + c++; } } @@ -231,8 +228,7 @@ config_window_fill_input_audio_device_list() { GtkTreeIter iter; gchar** list; - gchar** details; - gchar* audioDevice; + gchar** audioDevice; gtk_list_store_clear(inputAudioDeviceManagerStore); @@ -241,13 +237,14 @@ config_window_fill_input_audio_device_list() // For each device name included in list int c = 0; - for(audioDevice = list[c]; audioDevice != NULL; audioDevice = list[c]) + for(audioDevice = list; *list; list++) { - c++; - int index = atoi(audioDevice); - details = dbus_get_audio_device_details(index); + + //int index = atoi(audioDevice); + //details = dbus_get_audio_device_details(index); gtk_list_store_append(inputAudioDeviceManagerStore, &iter); - gtk_list_store_set(inputAudioDeviceManagerStore, &iter, 0, details[0], 1, index, -1); + gtk_list_store_set(inputAudioDeviceManagerStore, &iter, 0, *list, 1, c, -1); + c++; } } @@ -348,12 +345,12 @@ static void detect_all_audio_settings() { // Update lists -// config_window_fill_output_audio_device_list(); -// config_window_fill_input_audio_device_list(); + config_window_fill_output_audio_device_list(); + config_window_fill_input_audio_device_list(); // Select active device in combo box -// select_active_output_audio_device(); -// select_active_input_audio_device(); + select_active_output_audio_device(); + select_active_input_audio_device(); } /** @@ -919,7 +916,7 @@ create_audio_tab () gtk_widget_show(titleLabel); // Set choices of output devices outputAudioDeviceManagerStore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); -// config_window_fill_output_audio_device_list(); + config_window_fill_output_audio_device_list(); outputDeviceComboBox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(outputAudioDeviceManagerStore)); // select_active_output_audio_device(); gtk_label_set_mnemonic_widget(GTK_LABEL(titleLabel), outputDeviceComboBox); @@ -940,9 +937,9 @@ create_audio_tab () gtk_widget_show(titleLabel); // Set choices of output devices inputAudioDeviceManagerStore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); -// config_window_fill_input_audio_device_list(); + config_window_fill_input_audio_device_list(); inputDeviceComboBox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(inputAudioDeviceManagerStore)); -// select_active_input_audio_device(); + select_active_input_audio_device(); gtk_label_set_mnemonic_widget(GTK_LABEL(titleLabel), inputDeviceComboBox); g_signal_connect(G_OBJECT(inputDeviceComboBox), "changed", G_CALLBACK(select_audio_input_device), inputDeviceComboBox); diff --git a/src/audio/audiolayer.cpp b/src/audio/audiolayer.cpp index db39e5fc62..e02ea6cdee 100644 --- a/src/audio/audiolayer.cpp +++ b/src/audio/audiolayer.cpp @@ -22,14 +22,12 @@ #include <cstdio> #include <cstdlib> -#include <iostream> #include "audiolayer.h" #include "../global.h" #include "../manager.h" #include "../user_cfg.h" -#define PCM_NAME_DEFAULT "default" #define PCM_PAUSE 1 #define PCM_RESUME 0 @@ -38,10 +36,7 @@ #endif AudioLayer::AudioLayer(ManagerImpl* manager) - : _urgentRingBuffer(SIZEBUF) - , _mainSndRingBuffer(SIZEBUF) - , _micRingBuffer(SIZEBUF) - , _defaultVolume(100) +: _defaultVolume(100) , _errorMessage("") , _manager(manager) , _playback_handle( NULL ) @@ -53,6 +48,7 @@ _inChannel = 1; // don't put in stereo _outChannel = 1; // don't put in stereo _echoTesting = false; + get_alsa_version(); #ifdef SFL_TEST_SINE leftPhase_ = 0; @@ -88,8 +84,24 @@ AudioLayer::~AudioLayer (void) bool -AudioLayer::openDevice (int indexIn, int indexOut, int sampleRate, int frameSize) +AudioLayer::openDevice (int indexIn, int indexOut, int sampleRate, int frameSize, int flag) { + + if(device_closed = false) + { + _debugAlsa(" CLose the current devices\n"); + if(_capture_handle && (flag == 0 || flag == 2)){ + snd_pcm_drop( _capture_handle ); + snd_pcm_close( _capture_handle ); + _capture_handle = 0; + } + if(_playback_handle && ( flag == 0 || flag == 1)){ + snd_pcm_drop( _playback_handle ); + snd_pcm_close( _playback_handle ); + _playback_handle = 0; + } + } + _indexIn = indexIn; _indexOut = indexOut; _sampleRate = sampleRate; @@ -101,8 +113,10 @@ AudioLayer::openDevice (int indexIn, int indexOut, int sampleRate, int frameSize _debug(" : frame per buffer=%d\n", FRAME_PER_BUFFER); ost::MutexLock guard( _mutex ); - // TODO: Must be dynamic - return open_device( PCM_NAME_DEFAULT ); + + std::string pcmp = buildDeviceTopo(PCM_FRONT, indexOut ); + std::string pcmc = buildDeviceTopo(PCM_FRONT, indexIn ); + return open_device( pcmp , pcmc, flag); } int @@ -115,13 +129,10 @@ AudioLayer::getDeviceCount() void AudioLayer::startStream(void) { - // STATE PREPARED + _debug(" Start stream\n"); ost::MutexLock guard( _mutex ); - _debug(" entry startStream() - c => %d - p => %d\n", snd_pcm_state(_capture_handle), snd_pcm_state( _playback_handle)); snd_pcm_start( _capture_handle ) ; - snd_pcm_start( _playback_handle ) ; - // STATE RUNNING - _debug(" exit startStream() - c => %d - p => %d\n", snd_pcm_state(_capture_handle), snd_pcm_state( _playback_handle)); + //snd_pcm_start( _playback_handle ) ; } @@ -129,19 +140,17 @@ AudioLayer::startStream(void) AudioLayer::stopStream(void) { ost::MutexLock guard( _mutex ); - _debug(" entry stopStream() - c => %d - p => %d\n", snd_pcm_state(_capture_handle), snd_pcm_state( _playback_handle)); snd_pcm_drop( _capture_handle ); snd_pcm_prepare( _capture_handle ); - snd_pcm_drop( _playback_handle ); - snd_pcm_prepare( _playback_handle ); - _debug(" exit stopStream() - c => %d - p => %d\n", snd_pcm_state(_capture_handle), snd_pcm_state( _playback_handle)); + //snd_pcm_drop( _playback_handle ); + //snd_pcm_prepare( _playback_handle ); } void AudioLayer::sleep(int msec) { - //snd_pcm_wait(_playback_handle, msec); + snd_pcm_wait(_playback_handle, msec); } bool @@ -156,17 +165,25 @@ AudioLayer::isStreamActive (void) int -AudioLayer::putMain(void* buffer, int toCopy) +AudioLayer::playSamples(void* buffer, int toCopy) { ost::MutexLock guard( _mutex ); - if ( _playback_handle ) + if ( _playback_handle ){ write(buffer, toCopy); + } return 0; } - void -AudioLayer::flushMain() + + int +AudioLayer::playRingTone( void* buffer, int toCopy) { + _debug(" %d\n", toCopy); + ost::MutexLock guard( _mutex ); + if( _playback_handle ) + snd_pcm_start( _playback_handle ); + write(buffer, toCopy); + return 0; } int @@ -174,7 +191,7 @@ AudioLayer::putUrgent(void* buffer, int toCopy) { ost::MutexLock guard( _mutex ); if ( _playback_handle ) - //write(buffer, toCopy); + write(buffer, toCopy); return 0; } @@ -204,10 +221,6 @@ AudioLayer::getMic(void *buffer, int toCopy) return 0; } - void -AudioLayer::flushMic() -{ -} bool AudioLayer::isStreamStopped (void) @@ -247,70 +260,75 @@ AudioLayer::isCaptureActive(void) { bool -AudioLayer::open_device(std::string pcm_name) +AudioLayer::open_device(std::string pcm_p, std::string pcm_c, int flag) { int err; snd_pcm_hw_params_t *hwparams = NULL; unsigned int rate_in = _sampleRate; unsigned int rate_out = _sampleRate; - int direction = 0; - snd_pcm_uframes_t period_size_in = 1024; - snd_pcm_uframes_t buffer_size_in = 2048; - snd_pcm_uframes_t period_size_out = 2048; - snd_pcm_uframes_t buffer_size_out = 4096; + int dir = 0; + unsigned int period_count_in = 2; + snd_pcm_uframes_t period_size_in = 2048; //rate_in * _frameSize / 1000 ; + snd_pcm_uframes_t buffer_size_in = 4096; + unsigned int period_count_out = 2; + snd_pcm_uframes_t period_size_out = 2048 ; + snd_pcm_uframes_t buffer_size_out = 4096 ; snd_pcm_sw_params_t *swparams = NULL; - _debug(" Opening capture device %s\n", pcm_name.c_str()); - if(err = snd_pcm_open(&_capture_handle, pcm_name.c_str(), SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK) < 0){ - _debug(" Error while opening capture device %s (%s)\n", pcm_name.c_str(), snd_strerror(err)); - return false; - } - if( err = snd_pcm_hw_params_malloc( &hwparams ) < 0 ) { - _debug(" Cannot allocate hardware parameter structure (%s)\n", snd_strerror(err)); - return false; - } - if( err = snd_pcm_hw_params_any(_capture_handle, hwparams) < 0) _debug(" Cannot initialize hardware parameter structure (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params_set_access( _capture_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) _debug(" Cannot set access type (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params_set_format( _capture_handle, hwparams, SND_PCM_FORMAT_S16_LE) < 0) _debug(" Cannot set sample format (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params_set_rate_near( _capture_handle, hwparams, &rate_in, &direction) < 0) _debug(" Cannot set sample rate (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params_set_channels( _capture_handle, hwparams, 1) < 0) _debug(" Cannot set channel count (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params_set_period_size_near( _capture_handle, hwparams, &period_size_out , &direction) < 0) _debug(" Cannot set period size (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params_set_buffer_size_near( _capture_handle, hwparams, &buffer_size_out ) < 0) _debug(" Cannot set buffer size (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params( _capture_handle, hwparams ) < 0) _debug(" Cannot set hw parameters (%s)\n", snd_strerror(err)); - snd_pcm_hw_params_free( hwparams ); - - - _debug(" Opening playback device %s\n", pcm_name.c_str()); - if(err = snd_pcm_open(&_playback_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0){ - _debug(" Error while opening playback device %s (%s)\n", pcm_name.c_str(), snd_strerror(err)); - return false; + if(flag == 0 || flag == 2) + { + _debug(" Opening capture device %s\n", pcm_c.c_str()); + if(err = snd_pcm_open(&_capture_handle, pcm_c.c_str() , SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK) < 0){ + _debug(" Error while opening capture device %s (%s)\n", pcm_c.c_str(), snd_strerror(err)); + return false; + } + if( err = snd_pcm_hw_params_malloc( &hwparams ) < 0 ) { + _debug(" Cannot allocate hardware parameter structure (%s)\n", snd_strerror(err)); + return false; + } + if( err = snd_pcm_hw_params_any(_capture_handle, hwparams) < 0) _debug(" Cannot initialize hardware parameter structure (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params_set_access( _capture_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) _debug(" Cannot set access type (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params_set_format( _capture_handle, hwparams, SND_PCM_FORMAT_S16_LE) < 0) _debug(" Cannot set sample format (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params_set_rate_near( _capture_handle, hwparams, &rate_in, &dir) < 0) _debug(" Cannot set sample rate (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params_set_channels( _capture_handle, hwparams, 1) < 0) _debug(" Cannot set channel count (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params_set_period_size_near( _capture_handle, hwparams, &period_size_out , &dir) < 0) _debug(" Cannot set period size (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params_set_buffer_size_near( _capture_handle, hwparams, &buffer_size_out ) < 0) _debug(" Cannot set buffer size (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params( _capture_handle, hwparams ) < 0) _debug(" Cannot set hw parameters (%s)\n", snd_strerror(err)); + snd_pcm_hw_params_free( hwparams ); + device_closed = false; } - if( err = snd_pcm_hw_params_malloc( &hwparams ) < 0 ) { - _debug(" Cannot allocate hardware parameter structure (%s)\n", snd_strerror(err)); - return false; + + if(flag == 0 || flag == 1) + { + + _debug(" Opening playback device %s\n", pcm_p.c_str()); + if(err = snd_pcm_open(&_playback_handle, pcm_p.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0){ + _debug(" Error while opening playback device %s (%s)\n", pcm_p.c_str(), snd_strerror(err)); + return false; + } + if( err = snd_pcm_hw_params_malloc( &hwparams ) < 0 ) { + _debug(" Cannot allocate hardware parameter structure (%s)\n", snd_strerror(err)); + return false; + } + if( err = snd_pcm_hw_params_any( _playback_handle, hwparams) < 0) _debug(" Cannot initialize hardware parameter structure (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params_set_access( _playback_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) _debug(" Cannot set access type (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params_set_format( _playback_handle, hwparams, SND_PCM_FORMAT_S16_LE) < 0) _debug(" Cannot set sample format (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params_set_rate_near( _playback_handle, hwparams, &rate_out, &dir) < 0) _debug(" Cannot set sample rate (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params_set_channels( _playback_handle, hwparams, 1) < 0) _debug(" Cannot set channel count (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params_set_period_size_near( _playback_handle, hwparams, &period_size_out , &dir) < 0) _debug(" Cannot set period size (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params_set_buffer_size_near( _playback_handle, hwparams, &buffer_size_out ) < 0) _debug(" Cannot set buffer size (%s)\n", snd_strerror(err)); + if( err = snd_pcm_hw_params( _playback_handle, hwparams ) < 0) _debug(" Cannot set hw parameters (%s)\n", snd_strerror(err)); + snd_pcm_hw_params_free( hwparams ); + + snd_pcm_uframes_t val = 1024 ; + snd_pcm_sw_params_alloca( &swparams ); + snd_pcm_sw_params_current( _playback_handle, swparams ); + + if( err = snd_pcm_sw_params_set_start_threshold( _playback_handle, swparams, val ) < 0 ) _debug(" Cannot set start threshold (%s)\n", snd_strerror(err)); + if( err = snd_pcm_sw_params_set_stop_threshold( _playback_handle, swparams, val*4 ) < 0 ) _debug(" Cannot get stop threshold (%s)\n", snd_strerror(err)); + if( err = snd_pcm_sw_params( _playback_handle, swparams ) < 0 ) _debug(" Cannot set sw parameters (%s)\n", snd_strerror(err)); + device_closed = false; } - if( err = snd_pcm_hw_params_any( _playback_handle, hwparams) < 0) _debug(" Cannot initialize hardware parameter structure (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params_set_access( _playback_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) _debug(" Cannot set access type (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params_set_format( _playback_handle, hwparams, SND_PCM_FORMAT_S16_LE) < 0) _debug(" Cannot set sample format (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params_set_rate_near( _playback_handle, hwparams, &rate_out, &direction) < 0) _debug(" Cannot set sample rate (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params_set_channels( _playback_handle, hwparams, 1) < 0) _debug(" Cannot set channel count (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params_set_period_size_near( _playback_handle, hwparams, &period_size_out , &direction) < 0) _debug(" Cannot set period size (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params_set_buffer_size_near( _playback_handle, hwparams, &buffer_size_out ) < 0) _debug(" Cannot set buffer size (%s)\n", snd_strerror(err)); - if( err = snd_pcm_hw_params( _playback_handle, hwparams ) < 0) _debug(" Cannot set hw parameters (%s)\n", snd_strerror(err)); - snd_pcm_hw_params_free( hwparams ); - - snd_pcm_uframes_t val; - snd_pcm_sw_params_alloca( &swparams ); - snd_pcm_sw_params_current( _playback_handle, swparams ); - - if( err = snd_pcm_sw_params_get_start_threshold( swparams, &val ) < 0 ) _debug(" Cannot get start threshold (%s)\n", snd_strerror(err)); - if( err = snd_pcm_sw_params_get_stop_threshold( swparams, &val ) < 0 ) _debug(" Cannot get stop threshold (%s)\n", snd_strerror(err)); - if( err = snd_pcm_sw_params_get_boundary( swparams, &val ) < 0 ) _debug(" Cannot get boundary (%s)\n", snd_strerror(err)); - if( err = snd_pcm_sw_params_set_silence_threshold( _playback_handle, swparams, 0 ) < 0 ) _debug(" Cannot set silence threshold (%s)\n", snd_strerror(err)); - if( err = snd_pcm_sw_params_set_silence_size( _playback_handle, swparams, 0 ) < 0 ) _debug(" Cannot set silence size (%s)\n", snd_strerror(err)); - if( err = snd_pcm_sw_params( _playback_handle, swparams ) < 0 ) _debug(" Cannot set sw parameters (%s)\n", snd_strerror(err)); - - device_closed = false; return true; } @@ -356,7 +374,6 @@ AudioLayer::read( void* target_buffer, int toCopy) { if(device_closed || _capture_handle == NULL) return 0; - int bytes; snd_pcm_uframes_t frames = snd_pcm_bytes_to_frames( _capture_handle, toCopy); if( bytes = snd_pcm_readi( _capture_handle, target_buffer, frames) < 0 ) { @@ -404,3 +421,76 @@ AudioLayer::handle_xrun_state( void ) else _debug(" Get status failed\n"); } + + +void +AudioLayer::get_devices_info( void ){ + snd_pcm_info_t *info; + snd_pcm_info_alloca( &info ); + //int card = snd_pcm_info_get_card( info ); + _debug("device %d - subdevice %d - card %d\n", snd_pcm_info_get_device(info), snd_pcm_info_get_subdevice( info ), snd_pcm_info_get_card( info )); +} + + std::string +AudioLayer::get_alsa_version( void ) +{ + std::stringstream out; + std::string version; + std::ifstream file( "/proc/asound/version" ); + out << file.rdbuf(); + version = out.str(); + //version << std::cout << system("cat /proc/asound/version"); + _debugAlsa("%s\n", version.c_str()); + return version; +} + + std::vector<std::string> +AudioLayer::get_sound_cards( void ) +{ + std::stringstream out; + std::string sound_cards; + std::ifstream file( "/proc/asound/cards" ); + out << file.rdbuf(); + sound_cards = out.str(); + //_debugAlsa("%s\n", sound_cards.c_str()); + return parse_sound_cards(sound_cards); +} + + std::vector< std::string > +AudioLayer::parse_sound_cards( std::string& list) +{ + std::vector<std::string> lines; + typedef boost::tokenizer<boost::char_separator<char> > tokenizer; + boost::char_separator<char> ret("\n"); + tokenizer tokens( list , ret ); + for(tokenizer::iterator tok_iter = tokens.begin() ; tok_iter != tokens.end() ; ++tok_iter) + { + lines.push_back(*tok_iter); + } + // We keep only the fisrt line of each device description --> the interesting one + int size = lines.size(); + // 2 lines of description per sound card + int nb_cards = size / 2 ; + for(size = 0 ; size < nb_cards ; size++) + { + // for each card, we keep the first one + lines.erase(lines.begin() + 2*size + 1); + } + lines.resize(nb_cards); + return lines; +} + + std::string +AudioLayer::buildDeviceTopo( std::string prefixe, int suffixe) +{ + if( prefixe == PCM_DEFAULT) + return prefixe; + std::string pcm = prefixe; + std::ostringstream ss; + ss << suffixe; + pcm.append(":"); + pcm.append(ss.str()); + return pcm; +} + + diff --git a/src/audio/audiolayer.h b/src/audio/audiolayer.h index 09c8408e22..438cf17ff4 100644 --- a/src/audio/audiolayer.h +++ b/src/audio/audiolayer.h @@ -24,17 +24,19 @@ #define _AUDIO_LAYER_H #include <cc++/thread.h> // for ost::Mutex +#include <boost/tokenizer.hpp> #include "../global.h" -#include "ringbuffer.h" #include "audiodevice.h" #include <vector> #include <alsa/asoundlib.h> - +#include <iostream> +#include <fstream> +#include <istream> +#include <sstream> #define FRAME_PER_BUFFER 160 -class RingBuffer; class ManagerImpl; class AudioLayer { @@ -47,8 +49,9 @@ class AudioLayer { * @param indexOut * @param sampleRate * @param frameSize + * @param flag - 0 --> open playback and capture ; 1 --> open playback only ; 2 --> open capture only */ - bool openDevice(int, int, int, int); + bool openDevice(int, int, int, int, int); void startStream(void); void stopStream(void); void sleep(int); @@ -58,16 +61,15 @@ class AudioLayer { bool isStreamStopped(void); void closeStream(); - void flushMain(); - int putMain(void* buffer, int toCopy); + int playSamples(void* buffer, int toCopy); + int playRingTone( void* buffer, int toCopy); int putUrgent(void* buffer, int toCopy); int canGetMic(); int getMic(void *, int); - void flushMic(); + std::vector<std::string> get_sound_cards( void ); + std::string buildDeviceTopo( std::string prefixe, int suffixe); int audioCallback (const void *, void *, unsigned long); - //int miniAudioCallback (const void *, void *, unsigned long, - //const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags); void setErrorMessage(const std::string& error) { _errorMessage = error; } std::string getErrorMessage() { return _errorMessage; } @@ -101,15 +103,15 @@ class AudioLayer { void toggleEchoTesting(); private: - bool open_device( std::string ); + bool open_device( std::string , std::string , int); int write( void* , int ); int read( void*, int ); bool is_playback_active( void ); bool is_capture_active( void ); void handle_xrun_state( void ); - RingBuffer _urgentRingBuffer; - RingBuffer _mainSndRingBuffer; - RingBuffer _micRingBuffer; + void get_devices_info( void ); + std::string get_alsa_version( void ); + std::vector<std::string> parse_sound_cards( std::string& ); ManagerImpl* _manager; // augment coupling, reduce indirect access // a audiolayer can't live without manager diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp index 393faa799b..202ccddf5a 100644 --- a/src/audio/audiortp.cpp +++ b/src/audio/audiortp.cpp @@ -428,7 +428,7 @@ try { #endif - audiolayer->putMain(toAudioLayer, nbSample * sizeof(SFLDataFormat)); + audiolayer->playSamples(toAudioLayer, nbSample * sizeof(SFLDataFormat)); // Notify (with a beep) an incoming call when there is already a call countTime += time->getSecond(); if (Manager::instance().incomingCallWaiting() > 0) { diff --git a/src/global.h b/src/global.h index 0f13cf1c46..ede4ac32a2 100644 --- a/src/global.h +++ b/src/global.h @@ -48,7 +48,8 @@ typedef short int16; #define _debugMid(...) fprintf(stderr, __VA_ARGS__) #define _debugEnd(...) fprintf(stderr, __VA_ARGS__) #define _debugException(...) fprintf(stderr, "[sfl-excep] " __VA_ARGS__ "\n") - #define _debugInit(...) fprintf(stderr, "[sfl-init.] " __VA_ARGS__ "\n") + #define _debugInit(...) fprintf(stderr, "[sfl-init] " __VA_ARGS__ "\n") + #define _debugAlsa(...) fprintf(stderr, "[alsa-debug] " __VA_ARGS__ ) #else #define _debug(...) #define _debugStart(...) @@ -56,6 +57,7 @@ typedef short int16; #define _debugEnd(...) #define _debugException(...) #define _debugInit(...) + #define _debugAlsa(...) #endif #define SFLPHONED_VERSION "0.7.2" @@ -72,14 +74,7 @@ typedef short int16; #define CHANNELS 2 #define SIZEBUF 1024*1024 -// Codecs payloads, as defined in RFC3551 -// http://www.iana.org/assignments/rtp-parameters -// http://www.gnu.org/software/ccrtp/doc/refman/html/formats_8h.html#a0 -/*#define PAYLOAD_CODEC_ULAW 0 // PCMU 8000 -#define PAYLOAD_CODEC_ALAW 8 // PCMA 8000 -#define PAYLOAD_CODEC_GSM 3 // GSM 8000 -// http://www.ietf.org/rfc/rfc3952.txt -#define PAYLOAD_CODEC_ILBC 97*/ - +#define PCM_FRONT "plug:front" +#define PCM_DEFAULT "default" #endif // __GLOBAL_H__ diff --git a/src/iaxvoiplink.cpp b/src/iaxvoiplink.cpp index b8acfe09f7..bbd810c011 100644 --- a/src/iaxvoiplink.cpp +++ b/src/iaxvoiplink.cpp @@ -305,7 +305,7 @@ IAXVoIPLink::sendAudioFromMic(void) // Audio codec still not determined. if (audiolayer) { // To keep latency low.. - audiolayer->flushMic(); + //audiolayer->flushMic(); } return; } @@ -548,7 +548,7 @@ IAXVoIPLink::answer(const CallID& id) // Start audio audiolayer->startStream(); - audiolayer->flushMic(); + //audiolayer->flushMic(); return true; } @@ -749,7 +749,7 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call) } Manager::instance().peerAnsweredCall(id); - audiolayer->flushMic(); + //audiolayer->flushMic(); audiolayer->startStream(); // start audio here? } else { @@ -875,7 +875,7 @@ AudioCodec* audiocodec; toAudioLayer = _receiveDataDecoded; // int to int #endif } - audiolayer->putMain(toAudioLayer, nbSample * sizeof(SFLDataFormat)); + audiolayer->playSamples(toAudioLayer, nbSample * sizeof(SFLDataFormat)); } else { _debug("IAX: incoming audio, but no sound card open"); } diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 9f9d8baf1a..4cb2bae2c8 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -109,7 +109,7 @@ ManagerImpl::~ManagerImpl (void) _debug("%s stop correctly.\n", PROGNAME); } -void + void ManagerImpl::init() { // Load accounts, init map @@ -127,6 +127,8 @@ ManagerImpl::init() // Initialize the list of supported audio codecs initAudioCodec(); + getAudioInputDeviceList(); + AudioLayer *audiolayer = getAudioDriver(); if (audiolayer!=0) { unsigned int sampleRate = audiolayer->getSampleRate(); @@ -193,7 +195,7 @@ ManagerImpl::switchCall(const CallID& id ) { // Management of events' IP-phone user /////////////////////////////////////////////////////////////////////////////// /* Main Thread */ -bool + bool ManagerImpl::outgoingCall(const std::string& accountid, const CallID& id, const std::string& to) { if (!accountExists(accountid)) { @@ -220,14 +222,14 @@ ManagerImpl::outgoingCall(const std::string& accountid, const CallID& id, const } //THREAD=Main : for outgoing Call -bool + bool ManagerImpl::answerCall(const CallID& id) { stopTone(false); /*if (hasCurrentCall()) - { + { onHoldCall(getCurrentCallId()); - }*/ + }*/ AccountID accountid = getAccountFromCall( id ); if (accountid == AccountNULL) { _debug("Answering Call: Call doesn't exists\n"); @@ -241,8 +243,8 @@ ManagerImpl::answerCall(const CallID& id) } //Place current call on hold if it isn't - - + + // if it was waiting, it's waiting no more if (_dbus) _dbus->getCallManager()->callStateChanged(id, "CURRENT"); removeWaitingCall(id); @@ -251,7 +253,7 @@ ManagerImpl::answerCall(const CallID& id) } //THREAD=Main -bool + bool ManagerImpl::sendTextMessage(const AccountID& accountId, const std::string& to, const std::string& message) { if (accountExists(accountId)) { @@ -261,7 +263,7 @@ ManagerImpl::sendTextMessage(const AccountID& accountId, const std::string& to, } //THREAD=Main -bool + bool ManagerImpl::hangupCall(const CallID& id) { stopTone(true); @@ -277,13 +279,13 @@ ManagerImpl::hangupCall(const CallID& id) bool returnValue = getAccountLink(accountid)->hangup(id); removeCallAccount(id); switchCall(""); - - + + return returnValue; } //THREAD=Main -bool + bool ManagerImpl::cancelCall (const CallID& id) { stopTone(true); @@ -298,12 +300,12 @@ ManagerImpl::cancelCall (const CallID& id) removeWaitingCall(id); removeCallAccount(id); switchCall(""); - + return returnValue; } //THREAD=Main -bool + bool ManagerImpl::onHoldCall(const CallID& id) { stopTone(true); @@ -316,16 +318,16 @@ ManagerImpl::onHoldCall(const CallID& id) _debug("Setting ONHOLD, Account %s, callid %s\n", accountid.c_str(), id.c_str()); bool returnValue = getAccountLink(accountid)->onhold(id); - + removeWaitingCall(id); if (_dbus) _dbus->getCallManager()->callStateChanged(id, "HOLD"); switchCall(""); - + return returnValue; } //THREAD=Main -bool + bool ManagerImpl::offHoldCall(const CallID& id) { stopTone(false); @@ -334,13 +336,13 @@ ManagerImpl::offHoldCall(const CallID& id) _debug("5 Manager OffHold Call: Call doesn't exists\n"); return false; } - + //Place current call on hold if it isn't if (hasCurrentCall()) { onHoldCall(getCurrentCallId()); } - + _debug("Setting OFFHOLD, Account %s, callid %s\n", accountid.c_str(), id.c_str()); bool returnValue = getAccountLink(accountid)->offhold(id); @@ -357,7 +359,7 @@ ManagerImpl::offHoldCall(const CallID& id) } //THREAD=Main -bool + bool ManagerImpl::transferCall(const CallID& id, const std::string& to) { stopTone(true); @@ -391,7 +393,7 @@ ManagerImpl::unmute() { } //THREAD=Main : Call:Incoming -bool + bool ManagerImpl::refuseCall (const CallID& id) { stopTone(true); @@ -413,7 +415,7 @@ ManagerImpl::refuseCall (const CallID& id) } //THREAD=Main -bool + bool ManagerImpl::saveConfig (void) { _debug("Saving Configuration...\n"); @@ -425,7 +427,7 @@ ManagerImpl::saveConfig (void) } //THREAD=Main -bool + bool ManagerImpl::initRegisterAccounts() { _debugInit("Initiate VoIP Links Registration"); @@ -444,7 +446,7 @@ ManagerImpl::initRegisterAccounts() //THREAD=Main // Currently unused -bool + bool ManagerImpl::registerAccount(const AccountID& accountId) { _debug("Register one VoIP Link\n"); @@ -456,7 +458,7 @@ ManagerImpl::registerAccount(const AccountID& accountId) AccountMap::iterator iter = _accountMap.begin(); while ( iter != _accountMap.end() ) { if ( iter->second ) { - iter->second->unregisterVoIPLink(); + iter->second->unregisterVoIPLink(); } iter++; } @@ -467,7 +469,7 @@ ManagerImpl::registerAccount(const AccountID& accountId) //THREAD=Main // Currently unused -bool + bool ManagerImpl::unregisterAccount(const AccountID& accountId) { _debug("Unregister one VoIP Link\n"); @@ -479,7 +481,7 @@ ManagerImpl::unregisterAccount(const AccountID& accountId) } //THREAD=Main -bool + bool ManagerImpl::sendDtmf(const CallID& id, char code) { AccountID accountid = getAccountFromCall( id ); @@ -491,23 +493,23 @@ ManagerImpl::sendDtmf(const CallID& id, char code) int sendType = getConfigInt(SIGNALISATION, SEND_DTMF_AS); bool returnValue = false; switch (sendType) { - case 0: // SIP INFO - playDtmf(code); - returnValue = getAccountLink(accountid)->carryingDTMFdigits(id, code); - break; - - case 1: // Audio way - break; - case 2: // rfc 2833 - break; - default: // unknown - error config? - break; + case 0: // SIP INFO + playDtmf(code); + returnValue = getAccountLink(accountid)->carryingDTMFdigits(id, code); + break; + + case 1: // Audio way + break; + case 2: // rfc 2833 + break; + default: // unknown - error config? + break; } return returnValue; } //THREAD=Main | VoIPLink -bool + bool ManagerImpl::playDtmf(char code) { // HERE are the variable: @@ -553,9 +555,9 @@ ManagerImpl::playDtmf(char code) try { // We activate the stream if it's not active yet. if (!audiolayer->isStreamActive()) { - audiolayer->startStream(); + audiolayer->startStream(); } else { - audiolayer->sleep(pulselen); // in milliseconds + audiolayer->sleep(pulselen); // in milliseconds } } catch(...) { _debugException("Portaudio exception when playing a dtmf"); @@ -607,7 +609,7 @@ ManagerImpl::isWaitingCall(const CallID& id) { // Management of event peer IP-phone //////////////////////////////////////////////////////////////////////////////// // SipEvent Thread -bool + bool ManagerImpl::incomingCall(Call* call, const AccountID& accountId) { _debug("Incoming call\n"); @@ -620,7 +622,7 @@ ManagerImpl::incomingCall(Call* call, const AccountID& accountId) ringtone(); switchCall(call->getCallId()); } else { - addWaitingCall(call->getCallId()); + addWaitingCall(call->getCallId()); } std::string from = call->getPeerName(); @@ -648,7 +650,7 @@ ManagerImpl::incomingMessage(const AccountID& accountId, const std::string& mess } //THREAD=VoIP CALL=Outgoing -void + void ManagerImpl::peerAnsweredCall(const CallID& id) { if (isCurrentCall(id)) { @@ -658,7 +660,7 @@ ManagerImpl::peerAnsweredCall(const CallID& id) } //THREAD=VoIP Call=Outgoing -void + void ManagerImpl::peerRingingCall(const CallID& id) { if (isCurrentCall(id)) { @@ -668,7 +670,7 @@ ManagerImpl::peerRingingCall(const CallID& id) } //THREAD=VoIP Call=Outgoing/Ingoing -void + void ManagerImpl::peerHungupCall(const CallID& id) { AccountID accountid = getAccountFromCall( id ); @@ -683,14 +685,14 @@ ManagerImpl::peerHungupCall(const CallID& id) } removeWaitingCall(id); removeCallAccount(id); - + } //THREAD=VoIP void ManagerImpl::callBusy(const CallID& id) { _debug("Call busy\n"); - + if (_dbus) _dbus->getCallManager()->callStateChanged(id, "BUSY"); if (isCurrentCall(id) ) { playATone(Tone::TONE_BUSY); @@ -701,7 +703,7 @@ ManagerImpl::callBusy(const CallID& id) { } //THREAD=VoIP -void + void ManagerImpl::callFailure(const CallID& id) { _debug("Call failed\n"); @@ -712,83 +714,83 @@ ManagerImpl::callFailure(const CallID& id) } removeCallAccount(id); removeWaitingCall(id); - + } //THREAD=VoIP -void + void ManagerImpl::displayTextMessage(const CallID& id, const std::string& message) { /*if(_gui) { - _gui->displayTextMessage(id, message); - }*/ + _gui->displayTextMessage(id, message); + }*/ } //THREAD=VoIP -void + void ManagerImpl::displayErrorText(const CallID& id, const std::string& message) { /*if(_gui) { _gui->displayErrorText(id, message); - } else { + } else { std::cerr << message << std::endl; - }*/ + }*/ } //THREAD=VoIP -void + void ManagerImpl::displayError (const std::string& error) { /*if(_gui) { _gui->displayError(error); - }*/ + }*/ } //THREAD=VoIP -void + void ManagerImpl::displayStatus(const std::string& status) { /*if(_gui) { _gui->displayStatus(status); - }*/ + }*/ } //THREAD=VoIP -void + void ManagerImpl::displayConfigError (const std::string& message) { /*if(_gui) { _gui->displayConfigError(message); - }*/ + }*/ } //THREAD=VoIP -void + void ManagerImpl::startVoiceMessageNotification(const AccountID& accountId, const std::string& nb_msg) { if (_dbus) _dbus->getCallManager()->voiceMailNotify(accountId, atoi(nb_msg.c_str()) ); } //THREAD=VoIP -void + void ManagerImpl::stopVoiceMessageNotification(const AccountID& accountId) { if (_dbus) _dbus->getCallManager()->voiceMailNotify(accountId, 0 ); } //THREAD=VoIP -void + void ManagerImpl::registrationSucceed(const AccountID& accountid) { Account* acc = getAccount(accountid); - if ( acc ) { + if ( acc ) { //acc->setState(true); if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); } } //THREAD=VoIP -void + void ManagerImpl::registrationFailed(const AccountID& accountid) { Account* acc = getAccount(accountid); @@ -804,6 +806,7 @@ ManagerImpl::registrationFailed(const AccountID& accountid) bool ManagerImpl::playATone(Tone::TONEID toneId) { int hasToPlayTone = getConfigInt(SIGNALISATION, PLAY_TONES); + if (!hasToPlayTone) return false; if (_telephoneTone != 0) { @@ -811,15 +814,26 @@ ManagerImpl::playATone(Tone::TONEID toneId) { _telephoneTone->setCurrentTone(toneId); _toneMutex.leaveMutex(); + /*AudioLoop* audioloop = getTelephoneTone(); + unsigned int nbSampling = audioloop->getSize(); + _debug("Telephone tone size = %d\n", nbSampling); + SFLDataFormat buf[nbSampling];*/ + //audioloop->getNext(buf, audioloop->getSize()); + //audiolayer->putUrgent(buf, sizeof(SFLDataFormat)*nbSampling); try { AudioLayer* audiolayer = getAudioDriver(); - if (audiolayer) { audiolayer->startStream(); } + if (audiolayer) { + _debug("Should ring back\n"); + //audiolayer->playRingTone( buf, sizeof(SFLDataFormat)*nbSampling); + audiolayer->startStream(); + } } catch(...) { _debugException("Off hold could not start audio stream"); return false; } } - return true; + //} +return true; } /** @@ -854,7 +868,7 @@ ManagerImpl::stopTone(bool stopAudio=true) { /** * Multi Thread */ -bool + bool ManagerImpl::playTone() { //return playATone(Tone::TONE_DIALTONE); @@ -880,7 +894,7 @@ ManagerImpl::ringback () { /** * Multi Thread */ -void + void ManagerImpl::ringtone() { int hasToPlayTone = getConfigInt(SIGNALISATION, PLAY_TONES); @@ -905,6 +919,7 @@ ManagerImpl::ringtone() _audiofile.start(); _toneMutex.leaveMutex(); try { + _debug(" Ringtone if everything would have worked fine\n"); audiolayer->startStream(); } catch(...) { _debugException("Audio file couldn't start audio stream"); @@ -914,7 +929,7 @@ ManagerImpl::ringtone() } } -AudioLoop* + AudioLoop* ManagerImpl::getTelephoneTone() { if(_telephoneTone != 0) { @@ -926,7 +941,7 @@ ManagerImpl::getTelephoneTone() } } -AudioLoop* + AudioLoop* ManagerImpl::getTelephoneFile() { ost::MutexLock m(_toneMutex); @@ -962,7 +977,7 @@ ManagerImpl::notificationIncomingCall(void) { /** * Multi Thread */ -bool + bool ManagerImpl::getStunInfo (StunAddress4& stunSvrAddr, int port) { StunAddress4 mappedAddr; @@ -990,19 +1005,19 @@ ManagerImpl::getStunInfo (StunAddress4& stunSvrAddr, int port) return false; } -bool + bool ManagerImpl::behindNat(const std::string& svr, int port) { StunAddress4 stunSvrAddr; stunSvrAddr.addr = 0; - + // Convert char* to StunAddress4 structure bool ret = stunParseServerName ((char*)svr.data(), stunSvrAddr); if (!ret) { _debug("SIP: Stun server address (%s) is not valid\n", svr.data()); return 0; } - + // Firewall address //_debug("STUN server: %s\n", svr.data()); return getStunInfo(stunSvrAddr, port); @@ -1015,7 +1030,7 @@ ManagerImpl::behindNat(const std::string& svr, int port) /** * Initialization: Main Thread * @return 1: ok - -1: error directory + -1: error directory */ int ManagerImpl::createSettingsPath (void) { @@ -1037,7 +1052,7 @@ ManagerImpl::createSettingsPath (void) { /** * Initialization: Main Thread */ -void + void ManagerImpl::initConfigFile (void) { std::string type_str("string"); @@ -1083,7 +1098,7 @@ ManagerImpl::initConfigFile (void) /** * Initialization: Main Thread */ -void + void ManagerImpl::initAudioCodec (void) { _debugInit("Active Codecs List"); @@ -1100,7 +1115,7 @@ ManagerImpl::initAudioCodec (void) } } -std::vector<std::string> + std::vector<std::string> ManagerImpl::retrieveActiveCodecs() { std::vector<std::string> order; @@ -1117,7 +1132,7 @@ ManagerImpl::retrieveActiveCodecs() return order; } -void + void ManagerImpl::setActiveCodecList(const std::vector<std::string>& list) { _debug("Set active codecs list"); @@ -1128,7 +1143,7 @@ ManagerImpl::setActiveCodecList(const std::vector<std::string>& list) setConfig("Audio", "ActiveCodecs", s); } -std::string + std::string ManagerImpl::serialize(std::vector<std::string> v) { int i; @@ -1141,7 +1156,7 @@ ManagerImpl::serialize(std::vector<std::string> v) } -std::vector <std::string> + std::vector <std::string> ManagerImpl::getActiveCodecList( void ) { _debug("Get Active codecs list"); @@ -1163,14 +1178,14 @@ ManagerImpl::getActiveCodecList( void ) /** * Send the list of codecs to the client through DBus. */ -std::vector< std::string > + std::vector< std::string > ManagerImpl::getCodecList( void ) { std::vector<std::string> list; CodecMap codecs = _codecDescriptorMap.getCodecMap(); CodecOrder order = _codecDescriptorMap.getActiveCodecs(); CodecMap::iterator iter = codecs.begin(); - + while(iter!=codecs.end()) { std::stringstream ss; @@ -1184,13 +1199,13 @@ ManagerImpl::getCodecList( void ) return list; } -std::vector<std::string> + std::vector<std::string> ManagerImpl::getCodecDetails( const ::DBus::Int32& payload ) { std::vector<std::string> v; std::stringstream ss; - + v.push_back(_codecDescriptorMap.getCodecName((CodecType)payload)); ss << _codecDescriptorMap.getSampleRate((CodecType)payload); v.push_back((ss.str()).data()); @@ -1208,112 +1223,91 @@ ManagerImpl::getCodecDetails( const ::DBus::Int32& payload ) /** * Get list of supported audio manager */ -std::vector<std::string> + std::vector<std::string> ManagerImpl::getAudioManagerList(void) { - std::vector<std::string> v; - _debug("Get audio manager list"); - - // Return only ALSA for now - v.push_back("ALSA"); - return v; + std::vector<std::string> v; + _debug("Get audio manager list"); + + // Return only ALSA for now + v.push_back("ALSA"); + return v; } /** * Set audio manager (always put ALSA) */ -void + void ManagerImpl::setAudioManager(const std::string& audioManager) { - _debug("Set audio manager"); - // Do nothing for now + _debug("Set audio manager"); + // Do nothing for now } /** * Get list of supported audio output device */ -std::vector<std::string> + std::vector<std::string> ManagerImpl::getAudioOutputDeviceList(void) { - _debug("Get audio output device list"); - //return _audiodriver->getAudioDeviceList(paALSA, _audiodriver->OutputDevice); + _debug("Get audio output device list"); + return _audiodriver -> get_sound_cards(); } /** * Set audio output device */ -void + void ManagerImpl::setAudioOutputDevice(const int index) { - _debug("Set audio output device"); - _audiodriver->openDevice(_audiodriver->getIndexIn(), index, _audiodriver->getSampleRate(), _audiodriver->getFrameSize()); - printf("%d audio output set\n", index); + _debug("Set audio output device"); + _audiodriver->openDevice(_audiodriver->getIndexIn(), index, _audiodriver->getSampleRate(), _audiodriver->getFrameSize(), 1); } /** * Get list of supported audio input device */ -std::vector<std::string> + std::vector<std::string> ManagerImpl::getAudioInputDeviceList(void) { - _debug("Get audio input device list"); - //return _audiodriver->getAudioDeviceList(paALSA, _audiodriver->InputDevice); + _debug("Get audio input device list\n"); + return _audiodriver -> get_sound_cards(); } /** * Set audio input device */ -void + void ManagerImpl::setAudioInputDevice(const int index) { - _debug("Set audio input device"); - _audiodriver->openDevice(index, _audiodriver->getIndexOut(), _audiodriver->getSampleRate(), _audiodriver->getFrameSize()); - printf("%d audio input set\n", index); + _debug("Set audio input device"); + _audiodriver->openDevice(index, _audiodriver->getIndexOut(), _audiodriver->getSampleRate(), _audiodriver->getFrameSize(), 2); } /** * Get string array representing integer indexes of output and input device */ -std::vector<std::string> + std::vector<std::string> ManagerImpl::getCurrentAudioDevicesIndex() { - _debug("Get current audio devices index"); - std::vector<std::string> v; - - char index[10]; - sprintf(index, "%d", _audiodriver->getIndexOut()); - v.push_back(index); - sprintf(index, "%d", _audiodriver->getIndexIn()); - v.push_back(index); - - return v; + _debug("Get current audio devices index"); + std::vector<std::string> v; + std::stringstream ss; + ss << _audiodriver->getIndexOut(); + v.push_back( ss.str() ); + ss << _audiodriver->getIndexIn(); + v.push_back( ss.str() ); + return v; } /** * Get name, max input channels, max output channels, sample rate of audio device */ -std::vector<std::string> + std::vector<std::string> ManagerImpl::getAudioDeviceDetails(const int index) { - _debug("Get audio input device list"); - /*std::vector<std::string> v; + _debug("Get audio input device list"); - try - { - portaudio::System& sys = portaudio::System::instance(); - portaudio::Device& device = sys.deviceByIndex(index); - - char answer[10]; - v.push_back(device.name()); - sprintf(answer, "%d", device.maxInputChannels()); - v.push_back(answer); - sprintf(answer, "%d", device.maxOutputChannels()); - v.push_back(answer); - sprintf(answer, "%d", device.defaultSampleRate()); - v.push_back(answer); - } - catch (...) {} - return v;*/ } @@ -1321,7 +1315,7 @@ ManagerImpl::getAudioDeviceDetails(const int index) /** * Initialization: Main Thread */ -void + void ManagerImpl::initAudioDriver(void) { _debugInit("AudioLayer Creation"); @@ -1339,7 +1333,7 @@ ManagerImpl::initAudioDriver(void) /** * Initialization: Main Thread and gui */ -void + void ManagerImpl::selectAudioDriver (void) { //int noDevice = getConfigInt(AUDIO, DRIVER_NAME); @@ -1347,9 +1341,9 @@ ManagerImpl::selectAudioDriver (void) int noDeviceOut = getConfigInt(AUDIO, DRIVER_NAME_OUT); int sampleRate = getConfigInt(AUDIO, DRIVER_SAMPLE_RATE); if (sampleRate <=0 || sampleRate > 48000) { - sampleRate = 8000; + sampleRate = 8000; } - int frameSize = getConfigInt(AUDIO, DRIVER_FRAME_SIZE); + int frameSize = getConfigInt(AUDIO, DRIVER_FRAME_SIZE); // this is when no audio device in/out are set // or the audio device in/out are set to 0 @@ -1360,7 +1354,7 @@ ManagerImpl::selectAudioDriver (void) //} _debugInit(" AudioLayer Opening Device"); _audiodriver->setErrorMessage(""); - _audiodriver->openDevice(noDeviceIn, noDeviceOut, sampleRate, frameSize); + _audiodriver->openDevice(noDeviceIn, noDeviceOut, sampleRate, frameSize, 0); } /** @@ -1368,7 +1362,7 @@ ManagerImpl::selectAudioDriver (void) * Informations will be store inside a map DNSService->_services * Initialization: Main Thread */ -void + void ManagerImpl::initZeroconf(void) { #ifdef USE_ZEROCONF @@ -1385,7 +1379,7 @@ ManagerImpl::initZeroconf(void) * Init the volume for speakers/micro from 0 to 100 value * Initialization: Main Thread */ -void + void ManagerImpl::initVolume() { _debugInit("Initiate Volume"); @@ -1397,7 +1391,7 @@ ManagerImpl::initVolume() * configuration function requests * Main Thread */ -bool + bool ManagerImpl::getZeroconf(const std::string& sequenceId) { bool returnValue = false; @@ -1420,13 +1414,13 @@ ManagerImpl::getZeroconf(const std::string& sequenceId) TXTRecordMap record = iter->second.getTXTRecords(); TXTRecordMap::iterator iterTXT = record.begin(); while(iterTXT!=record.end()) { - argTXT.clear(); - argTXT.push_back(iter->first); - argTXT.push_back(iterTXT->first); - argTXT.push_back(iterTXT->second); - argTXT.push_back(newTXT); - // _gui->sendMessage("101",sequenceId,argTXT); - iterTXT++; + argTXT.clear(); + argTXT.push_back(iter->first); + argTXT.push_back(iterTXT->first); + argTXT.push_back(iterTXT->second); + argTXT.push_back(newTXT); + // _gui->sendMessage("101",sequenceId,argTXT); + iterTXT++; } iter++; } @@ -1441,7 +1435,7 @@ ManagerImpl::getZeroconf(const std::string& sequenceId) /** * Main Thread */ -bool + bool ManagerImpl::attachZeroconfEvents(const std::string& sequenceId, Pattern::Observer& observer) { bool returnValue = false; @@ -1460,7 +1454,7 @@ ManagerImpl::attachZeroconfEvents(const std::string& sequenceId, Pattern::Observ #endif return returnValue; } -bool + bool ManagerImpl::detachZeroconfEvents(Pattern::Observer& observer) { bool returnValue = false; @@ -1482,18 +1476,18 @@ ManagerImpl::detachZeroconfEvents(Pattern::Observer& observer) */ /** * DEPRECATED -bool -ManagerImpl::getEvents() { - initRegisterAccounts(); - return true; -} -*/ + bool + ManagerImpl::getEvents() { + initRegisterAccounts(); + return true; + } + */ // TODO: rewrite this /** * Main Thread */ -bool + bool ManagerImpl::getCallStatus(const std::string& sequenceId) { if (!_dbus) { return false; } @@ -1511,20 +1505,20 @@ ManagerImpl::getCallStatus(const std::string& sequenceId) Call::ConnectionState state = call->getConnectionState(); if (state != Call::Connected) { switch(state) { - case Call::Trying: code="110"; status = "Trying"; break; - case Call::Ringing: code="111"; status = "Ringing"; break; - case Call::Progressing: code="125"; status = "Progressing"; break; - case Call::Disconnected: code="125"; status = "Disconnected"; break; - default: code=""; status= ""; + case Call::Trying: code="110"; status = "Trying"; break; + case Call::Ringing: code="111"; status = "Ringing"; break; + case Call::Progressing: code="125"; status = "Progressing"; break; + case Call::Disconnected: code="125"; status = "Disconnected"; break; + default: code=""; status= ""; } } else { switch (call->getState()) { - case Call::Active: code="112"; status = "Established"; break; - case Call::Hold: code="114"; status = "Held"; break; - case Call::Busy: code="113"; status = "Busy"; break; - case Call::Refused: code="125"; status = "Refused"; break; - case Call::Error: code="125"; status = "Error"; break; - case Call::Inactive: code="125"; status = "Inactive"; break; + case Call::Active: code="112"; status = "Established"; break; + case Call::Hold: code="114"; status = "Held"; break; + case Call::Busy: code="113"; status = "Busy"; break; + case Call::Refused: code="125"; status = "Refused"; break; + case Call::Error: code="125"; status = "Error"; break; + case Call::Inactive: code="125"; status = "Inactive"; break; } } @@ -1546,13 +1540,13 @@ ManagerImpl::getCallStatus(const std::string& sequenceId) iter++; } - + return true; } //THREAD=Main /* Unused, Deprecated */ -bool + bool ManagerImpl::getConfigAll(const std::string& sequenceId) { bool returnValue = false; @@ -1569,7 +1563,7 @@ ManagerImpl::getConfigAll(const std::string& sequenceId) } //THREAD=Main -bool + bool ManagerImpl::getConfig(const std::string& section, const std::string& name, TokenList& arg) { return _config.getConfigTreeItemToken(section, name, arg); @@ -1577,7 +1571,7 @@ ManagerImpl::getConfig(const std::string& section, const std::string& name, Toke //THREAD=Main // throw an Conf::ConfigTreeItemException if not found -int + int ManagerImpl::getConfigInt(const std::string& section, const std::string& name) { try { @@ -1591,7 +1585,7 @@ ManagerImpl::getConfigInt(const std::string& section, const std::string& name) //THREAD=Main std::string ManagerImpl::getConfigString(const std::string& section, const std::string& -name) + name) { try { return _config.getConfigTreeItemValue(section, name); @@ -1602,14 +1596,14 @@ name) } //THREAD=Main -bool + bool ManagerImpl::setConfig(const std::string& section, const std::string& name, const std::string& value) { return _config.setConfigTreeItem(section, name, value); } //THREAD=Main -bool + bool ManagerImpl::setConfig(const std::string& section, const std::string& name, int value) { std::ostringstream valueStream; @@ -1618,89 +1612,89 @@ ManagerImpl::setConfig(const std::string& section, const std::string& name, int } //THREAD=Main -bool + bool ManagerImpl::getConfigList(const std::string& sequenceId, const std::string& name) { /* - bool returnValue = false; - TokenList tk; - if (name == "codecdescriptor") { - - CodecMap map = _codecDescriptorMap.getCodecMap(); - CodecMap::iterator iter = map.begin(); - while( iter != map.end() ) { - tk.clear(); - std::ostringstream strType; - strType << iter->first; - tk.push_back(strType.str()); - if (iter->second != -1) { - tk.push_back(iter->second); - } else { - tk.push_back(strType.str()); - } - // _gui->sendMessage("100", sequenceId, tk); - iter++; - } - returnValue = true; + bool returnValue = false; + TokenList tk; + if (name == "codecdescriptor") { + + CodecMap map = _codecDescriptorMap.getCodecMap(); + CodecMap::iterator iter = map.begin(); + while( iter != map.end() ) { + tk.clear(); + std::ostringstream strType; + strType << iter->first; + tk.push_back(strType.str()); + if (iter->second != -1) { + tk.push_back(iter->second); + } else { + tk.push_back(strType.str()); + } + // _gui->sendMessage("100", sequenceId, tk); + iter++; + } + returnValue = true; } else if (name == "ringtones") { - // add empty line - std::ostringstream str; - str << 1; - tk.push_back(str.str()); - tk.push_back(""); // filepath - //_gui->sendMessage("100", sequenceId, tk); + // add empty line + std::ostringstream str; + str << 1; + tk.push_back(str.str()); + tk.push_back(""); // filepath + //_gui->sendMessage("100", sequenceId, tk); - // share directory - std::string path = std::string(PROGSHAREDIR) + DIR_SEPARATOR_STR + RINGDIR; - int nbFile = 1; - returnValue = getDirListing(sequenceId, path, &nbFile); + // share directory + std::string path = std::string(PROGSHAREDIR) + DIR_SEPARATOR_STR + RINGDIR; + int nbFile = 1; + returnValue = getDirListing(sequenceId, path, &nbFile); - // home directory - path = std::string(HOMEDIR) + DIR_SEPARATOR_STR + "." + PROGDIR + DIR_SEPARATOR_STR + RINGDIR; - getDirListing(sequenceId, path, &nbFile); + // home directory + path = std::string(HOMEDIR) + DIR_SEPARATOR_STR + "." + PROGDIR + DIR_SEPARATOR_STR + RINGDIR; + getDirListing(sequenceId, path, &nbFile); } else if (name == "audiodevice") { - returnValue = getAudioDeviceList(sequenceId, AudioLayer::InputDevice | AudioLayer::OutputDevice); + returnValue = getAudioDeviceList(sequenceId, AudioLayer::InputDevice | AudioLayer::OutputDevice); } else if (name == "audiodevicein") { - returnValue = getAudioDeviceList(sequenceId, AudioLayer::InputDevice); + returnValue = getAudioDeviceList(sequenceId, AudioLayer::InputDevice); } else if (name == "audiodeviceout") { - returnValue = getAudioDeviceList(sequenceId, AudioLayer::OutputDevice); + returnValue = getAudioDeviceList(sequenceId, AudioLayer::OutputDevice); } else if (name == "countrytones") { - returnValue = getCountryTones(sequenceId); + returnValue = getCountryTones(sequenceId); } return returnValue;*/ return true; } //THREAD=Main -bool + bool ManagerImpl::getAudioDeviceList(const std::string& sequenceId, int ioDeviceMask) { AudioLayer* audiolayer = getAudioDriver(); if (audiolayer == 0) { return false; } bool returnValue = false; - + // TODO: test when there is an error on initializing... TokenList tk; AudioDevice* device = 0; int nbDevice = audiolayer->getDeviceCount(); - /* - for (int index = 0; index < nbDevice; index++ ) { - device = audiolayer->getAudioDeviceInfo(index, ioDeviceMask); - if (device != 0) { - tk.clear(); - std::ostringstream str; str << index; tk.push_back(str.str()); - tk.push_back(device->getName()); - tk.push_back(device->getApiName()); - std::ostringstream rate; rate << (int)(device->getRate()); tk.push_back(rate.str()); - //_gui->sendMessage("100", sequenceId, tk); - - // don't forget to delete it after - delete device; device = 0; - } + /* + for (int index = 0; index < nbDevice; index++ ) { + device = audiolayer->getAudioDeviceInfo(index, ioDeviceMask); + if (device != 0) { + tk.clear(); + std::ostringstream str; str << index; tk.push_back(str.str()); + tk.push_back(device->getName()); + tk.push_back(device->getApiName()); + std::ostringstream rate; rate << (int)(device->getRate()); tk.push_back(rate.str()); + //_gui->sendMessage("100", sequenceId, tk); + + // don't forget to delete it after + delete device; device = 0; + } }*/ returnValue = true; - + std::ostringstream rate; rate << "VARIABLE"; tk.clear(); @@ -1711,7 +1705,7 @@ ManagerImpl::getAudioDeviceList(const std::string& sequenceId, int ioDeviceMask) } //THREAD=Main -bool + bool ManagerImpl::getCountryTones(const std::string& sequenceId) { // see ToneGenerator for the list... @@ -1748,13 +1742,13 @@ ManagerImpl::getDirListing(const std::string& sequenceId, const std::string& pat fileName = cFileName; filePathName = path + DIR_SEPARATOR_STR + cFileName; if (fileName.length() && fileName[0]!='.' && !ost::isDir(filePathName.c_str())) { - tk.clear(); - std::ostringstream str; - str << (*nbFile); - tk.push_back(str.str()); - tk.push_back(filePathName); - //_gui->sendMessage("100", sequenceId, tk); - (*nbFile)++; + tk.clear(); + std::ostringstream str; + str << (*nbFile); + tk.push_back(str.str()); + tk.push_back(filePathName); + //_gui->sendMessage("100", sequenceId, tk); + (*nbFile)++; } } return true; @@ -1764,17 +1758,17 @@ ManagerImpl::getDirListing(const std::string& sequenceId, const std::string& pat } } -std::vector< std::string > + std::vector< std::string > ManagerImpl::getAccountList() { std::vector< std::string > v; - + AccountMap::iterator iter = _accountMap.begin(); while ( iter != _accountMap.end() ) { if ( iter->second != 0 ) { _debug("Account List: %s\n", iter->first.data()); v.push_back(iter->first.data()); - + } iter++; } @@ -1784,135 +1778,135 @@ ManagerImpl::getAccountList() -std::map< std::string, std::string > + std::map< std::string, std::string > ManagerImpl::getAccountDetails(const AccountID& accountID) { std::map<std::string, std::string> a; std::string accountType; enum VoIPLink::RegistrationState state = _accountMap[accountID]->getRegistrationState(); - + accountType = getConfigString(accountID, CONFIG_ACCOUNT_TYPE); a.insert( - std::pair<std::string, std::string>( - CONFIG_ACCOUNT_ALIAS, - getConfigString(accountID, CONFIG_ACCOUNT_ALIAS) - ) - ); + std::pair<std::string, std::string>( + CONFIG_ACCOUNT_ALIAS, + getConfigString(accountID, CONFIG_ACCOUNT_ALIAS) + ) + ); /*a.insert( std::pair<std::string, std::string>( - CONFIG_ACCOUNT_AUTO_REGISTER, - getConfigString(accountID, CONFIG_ACCOUNT_AUTO_REGISTER)== "1" ? "TRUE": "FALSE" - ) + CONFIG_ACCOUNT_AUTO_REGISTER, + getConfigString(accountID, CONFIG_ACCOUNT_AUTO_REGISTER)== "1" ? "TRUE": "FALSE" + ) );*/ a.insert( - std::pair<std::string, std::string>( - CONFIG_ACCOUNT_ENABLE, - getConfigString(accountID, CONFIG_ACCOUNT_ENABLE) == "1" ? "TRUE": "FALSE" - ) - ); + std::pair<std::string, std::string>( + CONFIG_ACCOUNT_ENABLE, + getConfigString(accountID, CONFIG_ACCOUNT_ENABLE) == "1" ? "TRUE": "FALSE" + ) + ); a.insert( - std::pair<std::string, std::string>( - "Status", - (state == VoIPLink::Registered ? "REGISTERED": - (state == VoIPLink::Unregistered ? "UNREGISTERED": - (state == VoIPLink::Trying ? "TRYING": - (state == VoIPLink::Error ? "ERROR": "ERROR")))) - ) - ); + std::pair<std::string, std::string>( + "Status", + (state == VoIPLink::Registered ? "REGISTERED": + (state == VoIPLink::Unregistered ? "UNREGISTERED": + (state == VoIPLink::Trying ? "TRYING": + (state == VoIPLink::Error ? "ERROR": "ERROR")))) + ) + ); a.insert( - std::pair<std::string, std::string>( - CONFIG_ACCOUNT_TYPE, accountType - ) - ); + std::pair<std::string, std::string>( + CONFIG_ACCOUNT_TYPE, accountType + ) + ); if (accountType == "SIP") { a.insert( - std::pair<std::string, std::string>( - SIP_FULL_NAME, - getConfigString(accountID, SIP_FULL_NAME) - ) - ); + std::pair<std::string, std::string>( + SIP_FULL_NAME, + getConfigString(accountID, SIP_FULL_NAME) + ) + ); a.insert( - std::pair<std::string, std::string>( - SIP_USER_PART, - getConfigString(accountID, SIP_USER_PART) - ) - ); + std::pair<std::string, std::string>( + SIP_USER_PART, + getConfigString(accountID, SIP_USER_PART) + ) + ); a.insert( - std::pair<std::string, std::string>( - SIP_AUTH_NAME, - getConfigString(accountID, SIP_AUTH_NAME) - ) - ); + std::pair<std::string, std::string>( + SIP_AUTH_NAME, + getConfigString(accountID, SIP_AUTH_NAME) + ) + ); a.insert( - std::pair<std::string, std::string>( - SIP_PASSWORD, - getConfigString(accountID, SIP_PASSWORD) - ) - ); + std::pair<std::string, std::string>( + SIP_PASSWORD, + getConfigString(accountID, SIP_PASSWORD) + ) + ); a.insert( - std::pair<std::string, std::string>( - SIP_HOST_PART, - getConfigString(accountID, SIP_HOST_PART) - ) - ); + std::pair<std::string, std::string>( + SIP_HOST_PART, + getConfigString(accountID, SIP_HOST_PART) + ) + ); a.insert( - std::pair<std::string, std::string>( - SIP_PROXY, - getConfigString(accountID, SIP_PROXY) - ) - ); + std::pair<std::string, std::string>( + SIP_PROXY, + getConfigString(accountID, SIP_PROXY) + ) + ); a.insert( - std::pair<std::string, std::string>( - SIP_STUN_SERVER, - getConfigString(accountID, SIP_STUN_SERVER) - ) - ); + std::pair<std::string, std::string>( + SIP_STUN_SERVER, + getConfigString(accountID, SIP_STUN_SERVER) + ) + ); a.insert( - std::pair<std::string, std::string>( - SIP_USE_STUN, - getConfigString(accountID, SIP_USE_STUN) == "1" ? "TRUE": "FALSE" - ) - ); + std::pair<std::string, std::string>( + SIP_USE_STUN, + getConfigString(accountID, SIP_USE_STUN) == "1" ? "TRUE": "FALSE" + ) + ); } else if (accountType == "IAX") { a.insert( - std::pair<std::string, std::string>( - IAX_FULL_NAME, - getConfigString(accountID, IAX_FULL_NAME) - ) - ); + std::pair<std::string, std::string>( + IAX_FULL_NAME, + getConfigString(accountID, IAX_FULL_NAME) + ) + ); a.insert( - std::pair<std::string, std::string>( - IAX_HOST, - getConfigString(accountID, IAX_HOST) - ) - ); + std::pair<std::string, std::string>( + IAX_HOST, + getConfigString(accountID, IAX_HOST) + ) + ); a.insert( - std::pair<std::string, std::string>( - IAX_USER, - getConfigString(accountID, IAX_USER) - ) - ); + std::pair<std::string, std::string>( + IAX_USER, + getConfigString(accountID, IAX_USER) + ) + ); a.insert( - std::pair<std::string, std::string>( - IAX_PASS, - getConfigString(accountID, IAX_PASS) - ) - ); + std::pair<std::string, std::string>( + IAX_PASS, + getConfigString(accountID, IAX_PASS) + ) + ); } else { // Unknown type _debug("Unknown account type in getAccountDetails(): %s", accountType.c_str()); } - + return a; } -void + void ManagerImpl::setAccountDetails( const ::DBus::String& accountID, - const std::map< ::DBus::String, ::DBus::String >& details ) + const std::map< ::DBus::String, ::DBus::String >& details ) { std::string accountType = (*details.find(CONFIG_ACCOUNT_TYPE)).second; @@ -1920,7 +1914,7 @@ ManagerImpl::setAccountDetails( const ::DBus::String& accountID, //setConfig(accountID, CONFIG_ACCOUNT_AUTO_REGISTER, // (*details.find(CONFIG_ACCOUNT_AUTO_REGISTER)).second == "TRUE" ? "1": "0" ); setConfig(accountID, CONFIG_ACCOUNT_ENABLE, - (*details.find(CONFIG_ACCOUNT_ENABLE)).second == "TRUE" ? "1": "0" ); + (*details.find(CONFIG_ACCOUNT_ENABLE)).second == "TRUE" ? "1": "0" ); setConfig(accountID, CONFIG_ACCOUNT_TYPE, accountType); if (accountType == "SIP") { @@ -1932,7 +1926,7 @@ ManagerImpl::setAccountDetails( const ::DBus::String& accountID, //setConfig(accountID, SIP_PROXY, (*details.find(SIP_PROXY)).second); //setConfig(accountID, SIP_STUN_SERVER,(*details.find(SIP_STUN_SERVER)).second); //setConfig(accountID, SIP_USE_STUN, - // (*details.find(SIP_USE_STUN)).second == "TRUE" ? "1" : "0"); + // (*details.find(SIP_USE_STUN)).second == "TRUE" ? "1" : "0"); } else if (accountType == "IAX") { setConfig(accountID, IAX_FULL_NAME, (*details.find(IAX_FULL_NAME)).second); @@ -1942,7 +1936,7 @@ ManagerImpl::setAccountDetails( const ::DBus::String& accountID, } else { _debug("Unknown account type in setAccountDetails(): %s\n", accountType.c_str()); } - + saveConfig(); /* @@ -1969,7 +1963,7 @@ ManagerImpl::setAccountDetails( const ::DBus::String& accountID, } -void + void ManagerImpl::addAccount(const std::map< ::DBus::String, ::DBus::String >& details) { /** @todo Deal with both the _accountMap and the Configuration */ @@ -1995,11 +1989,11 @@ ManagerImpl::addAccount(const std::map< ::DBus::String, ::DBus::String >& detail setAccountDetails(accountID.str(), details); saveConfig(); - + if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); } -void + void ManagerImpl::removeAccount(const AccountID& accountID) { // Get it down and dying @@ -2014,25 +2008,25 @@ ManagerImpl::removeAccount(const AccountID& accountID) _config.removeSection(accountID); saveConfig(); - + if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); } -std::string + std::string ManagerImpl::getDefaultAccount() { - - std::string id; - id = getConfigString(PREFERENCES, "DefaultAccount"); - _debug("Default Account = %s\n",id.c_str()); - return id; + + std::string id; + id = getConfigString(PREFERENCES, "DefaultAccount"); + _debug("Default Account = %s\n",id.c_str()); + return id; } -void + void ManagerImpl::setDefaultAccount(const AccountID& accountID) { - // we write into the Preferences section the field Default - setConfig("Preferences", "DefaultAccount", accountID); + // we write into the Preferences section the field Default + setConfig("Preferences", "DefaultAccount", accountID); } @@ -2060,26 +2054,26 @@ ManagerImpl::setSwitch(const std::string& switchName, std::string& message) { int newSampleRate = audiolayer->getSampleRate(); if (!error.empty()) { - message = error; - return false; + message = error; + return false; } if (newSampleRate != oldSampleRate) { - _toneMutex.enterMutex(); + _toneMutex.enterMutex(); - _debug("Unload Telephone Tone\n"); - delete _telephoneTone; _telephoneTone = NULL; - _debug("Unload DTMF Key\n"); - delete _dtmfKey; _dtmfKey = NULL; + _debug("Unload Telephone Tone\n"); + delete _telephoneTone; _telephoneTone = NULL; + _debug("Unload DTMF Key\n"); + delete _dtmfKey; _dtmfKey = NULL; - _debug("Load Telephone Tone\n"); - std::string country = getConfigString(PREFERENCES, ZONE_TONE); - _telephoneTone = new TelephoneTone(country, newSampleRate); + _debug("Load Telephone Tone\n"); + std::string country = getConfigString(PREFERENCES, ZONE_TONE); + _telephoneTone = new TelephoneTone(country, newSampleRate); - _debugInit("Loading DTMF key"); - _dtmfKey = new DTMF(newSampleRate); + _debugInit("Loading DTMF key"); + _dtmfKey = new DTMF(newSampleRate); - _toneMutex.leaveMutex(); + _toneMutex.leaveMutex(); } message = _("Change with success"); @@ -2103,7 +2097,7 @@ ManagerImpl::setSwitch(const std::string& switchName, std::string& message) { } // ACCOUNT handling -bool + bool ManagerImpl::associateCallToAccount(const CallID& callID, const AccountID& accountID) { if (getAccountFromCall(callID) == AccountNULL) { // nothing with the same ID @@ -2119,7 +2113,7 @@ ManagerImpl::associateCallToAccount(const CallID& callID, const AccountID& accou } } -AccountID + AccountID ManagerImpl::getAccountFromCall(const CallID& callID) { ost::MutexLock m(_callAccountMapMutex); @@ -2131,7 +2125,7 @@ ManagerImpl::getAccountFromCall(const CallID& callID) } } -bool + bool ManagerImpl::removeCallAccount(const CallID& callID) { ost::MutexLock m(_callAccountMapMutex); @@ -2141,12 +2135,12 @@ ManagerImpl::removeCallAccount(const CallID& callID) return false; } -CallID + CallID ManagerImpl::getNewCallID() { std::ostringstream random_id("s"); random_id << (unsigned)rand(); - + // when it's not found, it return "" // generate, something like s10000s20000s4394040 while (getAccountFromCall(random_id.str()) != AccountNULL) { @@ -2157,7 +2151,7 @@ ManagerImpl::getNewCallID() return random_id.str(); } -short + short ManagerImpl::loadAccountMap() { _debugStart("Load account:"); @@ -2202,28 +2196,28 @@ ManagerImpl::loadAccountMap() // SIP Loading X account... short nbAccountSIP = ACCOUNT_SIP_COUNT_DEFAULT; for (short iAccountSIP = 0; iAccountSIP<nbAccountSIP; iAccountSIP++) { - std::ostringstream accountName; - accountName << "SIP" << iAccountSIP; - - tmpAccount = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, accountName.str()); - if (tmpAccount!=0) { - _debugMid(" %s", accountName.str().data()); - _accountMap[accountName.str()] = tmpAccount; - nbAccount++; - } + std::ostringstream accountName; + accountName << "SIP" << iAccountSIP; + + tmpAccount = AccountCreator::createAccount(AccountCreator::SIP_ACCOUNT, accountName.str()); + if (tmpAccount!=0) { + _debugMid(" %s", accountName.str().data()); + _accountMap[accountName.str()] = tmpAccount; + nbAccount++; + } } // IAX Loading X account... short nbAccountIAX = ACCOUNT_IAX_COUNT_DEFAULT; for (short iAccountIAX = 0; iAccountIAX<nbAccountIAX; iAccountIAX++) { - std::ostringstream accountName; - accountName << "IAX" << iAccountIAX; - tmpAccount = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, accountName.str()); - if (tmpAccount!=0) { - _debugMid(" %s", accountName.str().data()); - _accountMap[accountName.str()] = tmpAccount; - nbAccount++; - } + std::ostringstream accountName; + accountName << "IAX" << iAccountIAX; + tmpAccount = AccountCreator::createAccount(AccountCreator::IAX_ACCOUNT, accountName.str()); + if (tmpAccount!=0) { + _debugMid(" %s", accountName.str().data()); + _accountMap[accountName.str()] = tmpAccount; + nbAccount++; + } } _debugEnd("\n"); */ @@ -2231,7 +2225,7 @@ ManagerImpl::loadAccountMap() return nbAccount; } -void + void ManagerImpl::unloadAccountMap() { _debug("Unloading account map...\n"); @@ -2244,7 +2238,7 @@ ManagerImpl::unloadAccountMap() _accountMap.clear(); } -bool + bool ManagerImpl::accountExists(const AccountID& accountID) { AccountMap::iterator iter = _accountMap.find(accountID); @@ -2254,7 +2248,7 @@ ManagerImpl::accountExists(const AccountID& accountID) return true; } -Account* + Account* ManagerImpl::getAccount(const AccountID& accountID) { AccountMap::iterator iter = _accountMap.find(accountID); @@ -2264,7 +2258,7 @@ ManagerImpl::getAccount(const AccountID& accountID) return iter->second; } -VoIPLink* + VoIPLink* ManagerImpl::getAccountLink(const AccountID& accountID) { Account* acc = getAccount(accountID); diff --git a/src/sipcall.cpp b/src/sipcall.cpp index b839ca9f49..c9811e7e0a 100644 --- a/src/sipcall.cpp +++ b/src/sipcall.cpp @@ -361,7 +361,6 @@ SIPCall::sdp_complete_message(sdp_message_t * remote_sdp, osip_message_t * msg) _debug("remote payload = %s\n", tmp); CodecType audiocodec = (CodecType)payload; if (audiocodec != (CodecType)-1 && _codecMap.isActive(audiocodec)) { - _debug("PAYLOAD = %i", payload); listCodec << payload << " "; //listRtpMap << "a=rtpmap:" << payload << " " << audiocodec->getCodecName() << "/" << audiocodec->getClockRate(); listRtpMap << "a=rtpmap:" << payload << " " << _codecMap.getCodecName(audiocodec) << "/" << _codecMap.getSampleRate(audiocodec); -- GitLab