From 6781342d3c992d27ca928ab03d833c6d5f508ac8 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Fri, 19 Apr 2013 16:41:17 +0100 Subject: [PATCH] ecore_audio: Guard against attaching an input twice Add check in input_attach and change test case accordingly Signed-off-by: Daniel Willmann --- src/lib/ecore_audio/ecore_audio_obj_out.c | 6 ++++++ src/lib/ecore_audio/ecore_audio_obj_out_pulse.c | 7 +++++-- src/tests/ecore/ecore_test_ecore_audio.c | 7 ++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/lib/ecore_audio/ecore_audio_obj_out.c b/src/lib/ecore_audio/ecore_audio_obj_out.c index 1e7b2d2..253cf62 100644 --- a/src/lib/ecore_audio/ecore_audio_obj_out.c +++ b/src/lib/ecore_audio/ecore_audio_obj_out.c @@ -29,6 +29,12 @@ static void _input_attach(Eo *eo_obj, void *_pd, va_list *list) in = eo_data_get(input, ECORE_AUDIO_OBJ_IN_CLASS); + if (ret) + *ret = EINA_FALSE; + + if (in->output == eo_obj) + return; + if (in->output) eo_do(in->output, ecore_audio_obj_out_input_detach(input)); in->output = eo_obj; diff --git a/src/lib/ecore_audio/ecore_audio_obj_out_pulse.c b/src/lib/ecore_audio/ecore_audio_obj_out_pulse.c index 4402694..0232a10 100644 --- a/src/lib/ecore_audio/ecore_audio_obj_out_pulse.c +++ b/src/lib/ecore_audio/ecore_audio_obj_out_pulse.c @@ -116,6 +116,10 @@ static Eina_Bool _input_attach_internal(Eo *eo_obj, Eo *in) Eina_Bool ret; Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS); + eo_do_super(eo_obj, MY_CLASS, ecore_audio_obj_out_input_attach(in, &ret)); + if (!ret) + return EINA_FALSE; + ss.format = PA_SAMPLE_FLOAT32LE; eo_do(in, ecore_audio_obj_in_samplerate_get((int *)&ss.rate)); eo_do(in, ecore_audio_obj_in_speed_get(&speed)); @@ -127,11 +131,10 @@ static Eina_Bool _input_attach_internal(Eo *eo_obj, Eo *in) stream = pa_stream_new(class_vars.context, name, &ss, NULL); if (!stream) { ERR("Could not create stream"); + eo_do_super(eo_obj, MY_CLASS, ecore_audio_obj_out_input_detach(in)); return EINA_FALSE; } - eo_do_super(eo_obj, MY_CLASS, ecore_audio_obj_out_input_attach(in, &ret)); - eo_do(in, eo_event_callback_add(ECORE_AUDIO_EV_IN_SAMPLERATE_CHANGED, _update_samplerate_cb, eo_obj)); eo_do(in, eo_base_data_set("pulse_data", stream, NULL)); diff --git a/src/tests/ecore/ecore_test_ecore_audio.c b/src/tests/ecore/ecore_test_ecore_audio.c index 60f9ede..c70b9be 100644 --- a/src/tests/ecore/ecore_test_ecore_audio.c +++ b/src/tests/ecore/ecore_test_ecore_audio.c @@ -412,6 +412,7 @@ START_TEST(ecore_test_ecore_audio_obj_in_out) { Eo *out2; Eina_List *in3; + Eina_Bool attached; Eo *in = eo_add(ECORE_AUDIO_OBJ_IN_CLASS, NULL); Eo *in2 = eo_add(ECORE_AUDIO_OBJ_IN_CLASS, NULL); @@ -429,7 +430,11 @@ START_TEST(ecore_test_ecore_audio_obj_in_out) fail_if(eina_list_count(in3) != 0); - fail_if(!eo_do(out, ecore_audio_obj_out_input_attach(in, NULL))); + fail_if(!eo_do(out, ecore_audio_obj_out_input_attach(in, &attached))); + fail_if(!attached); + + fail_if(!eo_do(out, ecore_audio_obj_out_input_attach(in, &attached))); + fail_if(attached); fail_if(!eo_do(in, ecore_audio_obj_in_output_get(&out2))); -- 2.7.4