ecore_audio: Guard against attaching an input twice
authorDaniel Willmann <d.willmann@samsung.com>
Fri, 19 Apr 2013 15:41:17 +0000 (16:41 +0100)
committerDaniel Willmann <d.willmann@samsung.com>
Fri, 19 Apr 2013 17:34:16 +0000 (18:34 +0100)
Add check in input_attach and change test case accordingly

Signed-off-by: Daniel Willmann <d.willmann@samsung.com>
src/lib/ecore_audio/ecore_audio_obj_out.c
src/lib/ecore_audio/ecore_audio_obj_out_pulse.c
src/tests/ecore/ecore_test_ecore_audio.c

index 1e7b2d2..253cf62 100644 (file)
@@ -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;
 
index 4402694..0232a10 100644 (file)
@@ -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));
index 60f9ede..c70b9be 100644 (file)
@@ -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)));