From 1419785268b8158e28730a5552d930a9a4847f47 Mon Sep 17 00:00:00 2001 From: Yun Liu <yun@yun.(none)> Date: Tue, 20 Jan 2009 10:31:56 -0500 Subject: [PATCH] Fix bug ticket # 137 --- sflphone-gtk/src/audioconf.c | 17 ++++++++++------- sflphone-gtk/src/dbus.c | 22 +++++++++++----------- src/audio/audiostream.cpp | 12 ++++++++++-- src/audio/pulselayer.cpp | 11 +++++++++-- src/audio/pulselayer.h | 2 ++ 5 files changed, 42 insertions(+), 22 deletions(-) diff --git a/sflphone-gtk/src/audioconf.c b/sflphone-gtk/src/audioconf.c index d7b20f282f..e8d0a71ac1 100644 --- a/sflphone-gtk/src/audioconf.c +++ b/sflphone-gtk/src/audioconf.c @@ -90,15 +90,18 @@ config_window_fill_output_audio_plugin_list() // Call dbus to retreive list list = dbus_get_output_audio_plugin_list(); - // For each API name included in list int c = 0; - for(managerName = list[c]; managerName != NULL; managerName = list[c]) - { - c++; - gtk_list_store_append(pluginlist, &iter); - gtk_list_store_set(pluginlist, &iter, 0 , managerName, -1); - } + + if (list != NULL){ + for(managerName = list[c]; managerName != NULL; managerName = list[c]) + { + c++; + gtk_list_store_append(pluginlist, &iter); + gtk_list_store_set(pluginlist, &iter, 0 , managerName, -1); + } + } + list = NULL; } /** diff --git a/sflphone-gtk/src/dbus.c b/sflphone-gtk/src/dbus.c index a5f037e1a3..8795c1ef8b 100644 --- a/sflphone-gtk/src/dbus.c +++ b/sflphone-gtk/src/dbus.c @@ -823,22 +823,22 @@ dbus_get_input_audio_plugin_list() gchar** dbus_get_output_audio_plugin_list() { - g_print("Before get output audio plugin list"); gchar** array; GError* error = NULL; - org_sflphone_SFLphone_ConfigurationManager_get_output_audio_plugin_list( - configurationManagerProxy, - &array, - &error); - g_print("After"); - if(error) + + if(!org_sflphone_SFLphone_ConfigurationManager_get_output_audio_plugin_list( configurationManagerProxy, &array, &error)) { - g_printerr("Failed to call get_output_audio_plugin_list() on ConfigurationManager: %s\n", error->message); - g_error_free(error); + if(error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) + g_printerr ("Caught remote method (get_output_audio_plugin_list) exception %s: %s\n", dbus_g_error_get_name(error), error->message); + else + g_printerr("Error while calling get_out_audio_plugin_list: %s\n", error->message); + g_error_free (error); + return NULL; } - else + else{ g_print("DBus called get_output_audio_plugin_list() on ConfigurationManager\n"); - return array; + return array; + } } void diff --git a/src/audio/audiostream.cpp b/src/audio/audiostream.cpp index 254f8ae19e..63654ce076 100644 --- a/src/audio/audiostream.cpp +++ b/src/audio/audiostream.cpp @@ -18,9 +18,11 @@ */ #include <audiostream.h> +#include "pulselayer.h" static pa_channel_map channel_map ; + AudioStream::AudioStream( pa_context* context, int type, std::string desc, double vol UNUSED ) : _audiostream(NULL), _streamType(type), _streamDescription(desc), flag(PA_STREAM_AUTO_TIMING_UPDATE), sample_spec(), _volume() { @@ -48,19 +50,25 @@ AudioStream::disconnect( void ) pa_stream_unref( pulseStream() ); } - void +void AudioStream::stream_state_callback( pa_stream* s, void* user_data UNUSED ) { _debug("The state of the stream changed\n"); assert(s); switch(pa_stream_get_state(s)){ case PA_STREAM_CREATING: - case PA_STREAM_TERMINATED: _debug("Stream is creating...\n"); break; + case PA_STREAM_TERMINATED: + _debug("Stream is terminating...\n" ); + PulseLayer::streamState++; + break; case PA_STREAM_READY: _debug("Stream successfully created, connected to %s\n", pa_stream_get_device_name( s )); break; + case PA_STREAM_UNCONNECTED: + _debug("Stream unconnected\n"); + break; case PA_STREAM_FAILED: default: _debug("Stream error - Sink/Source doesn't exists: %s\n" , pa_strerror(pa_context_errno(pa_stream_get_context(s)))); diff --git a/src/audio/pulselayer.cpp b/src/audio/pulselayer.cpp index ef6e6a52b5..98a6cd6aa5 100644 --- a/src/audio/pulselayer.cpp +++ b/src/audio/pulselayer.cpp @@ -21,6 +21,8 @@ int framesPerBuffer = 2048; +int PulseLayer::streamState; + static void audioCallback ( pa_stream* s, size_t bytes, void* userdata ) { assert( s && bytes ); @@ -39,6 +41,7 @@ static void audioCallback ( pa_stream* s, size_t bytes, void* userdata ) , record() , cache() { + PulseLayer::streamState = 0; _debug("Pulse audio constructor: Create context\n"); } @@ -54,10 +57,14 @@ PulseLayer::~PulseLayer (void) void PulseLayer::closeLayer( void ) -{ +{ playback->disconnect(); record->disconnect(); - pa_context_disconnect( context ); + + while(PulseLayer::streamState != 2) + ; + PulseLayer::streamState = 0; + pa_context_disconnect( context ); pa_context_unref( context ); sleep(2); } diff --git a/src/audio/pulselayer.h b/src/audio/pulselayer.h index 2a055c81c6..dc22bfaedd 100644 --- a/src/audio/pulselayer.h +++ b/src/audio/pulselayer.h @@ -255,6 +255,8 @@ class PulseLayer : public AudioLayer { int spkrVolume; int micVolume; +public: + static int streamState; }; #endif // _PULSE_LAYER_H_ -- GitLab