edje multisense: fix a broken implementation. 86/262586/4 accepted/tizen/unified/20210822.213311 submit/tizen/20210818.053418 submit/tizen/20210818.080539 submit/tizen/20210819.014835
authorHermet Park <chuneon.park@samsung.com>
Fri, 13 Aug 2021 10:10:48 +0000 (19:10 +0900)
committerHermet Park <chuneon.park@samsung.com>
Tue, 17 Aug 2021 05:16:00 +0000 (05:16 +0000)
The latest efl doesn't allow the null parent object.
efl_add_ref() is recommended in this case.

Also, apis doesn't allow the thread calls.
The calls must be synced on the main thread.

Change-Id: Id25ce83900b88bc7630710b808c9fe84b921cf6e

src/lib/ecore_audio/ecore_audio_obj_out_tizen.c
src/lib/edje/edje_multisense.c

index eb0dc29..eb6460d 100644 (file)
@@ -104,9 +104,7 @@ static Eina_Bool _module_load(Ecore_Audio_Out_Tizen_Data *td)
 
 static void _stream_write_cb(void *handle, size_t len EINA_UNUSED, void *data)
 {
-   Eo *in = data;
-   Ecore_Audio_Out_Tizen_Data *_td;
-   _td = efl_key_data_get(in, "mod_data");
+   Ecore_Audio_Out_Tizen_Data *_td = data;
    if (!_td) return;
 
    void *buf;
@@ -115,7 +113,11 @@ static void _stream_write_cb(void *handle, size_t len EINA_UNUSED, void *data)
 
    _td->func->get_buffer_size(handle, &wlen);
    buf = malloc(wlen);
-   bread = ecore_audio_obj_in_read(in, buf, wlen);
+
+   //Guarantee Thread safety.
+   ecore_thread_main_loop_begin();
+   bread = ecore_audio_obj_in_read(_td->attached_in, buf, wlen);
+   ecore_thread_main_loop_end();
 
    if (bread > 0)
      {
@@ -125,6 +127,16 @@ static void _stream_write_cb(void *handle, size_t len EINA_UNUSED, void *data)
    free(buf);
 }
 
+
+static Eina_Bool
+_is_input_attached(Eo *eo_obj, Eo *in)
+{
+   Ecore_Audio_Output *out_obj = efl_data_scope_get(eo_obj, ECORE_AUDIO_OUT_CLASS);
+   if (!out_obj->inputs) return EINA_FALSE;
+   return !!eina_list_data_find(out_obj->inputs, in);
+}
+
+
 EOLIAN static Eina_Bool
 _ecore_audio_out_tizen_ecore_audio_out_input_attach(Eo *eo_obj, Ecore_Audio_Out_Tizen_Data *_td, Eo *in)
 {
@@ -134,6 +146,8 @@ _ecore_audio_out_tizen_ecore_audio_out_input_attach(Eo *eo_obj, Ecore_Audio_Out_
    int samplerate = 0;
    int channels = 0;
 
+   if (_is_input_attached(eo_obj, in)) return EINA_TRUE;
+
    ret2 = ecore_audio_obj_out_input_attach(efl_super(eo_obj, MY_CLASS), in);
    if (!ret2)
       return EINA_FALSE;
@@ -152,7 +166,7 @@ _ecore_audio_out_tizen_ecore_audio_out_input_attach(Eo *eo_obj, Ecore_Audio_Out_
    efl_key_data_set(in, "mod_data", _td);
    efl_key_data_set(in, "pcm_fmt", strdup("S16"));
    _td->attached_in = in;
-   ret = _td->func->set_write_cb(handle, _stream_write_cb, in);
+   ret = _td->func->set_write_cb(handle, _stream_write_cb, _td);
    if (ret)
      {
         ecore_audio_obj_out_input_detach(efl_super(eo_obj, MY_CLASS), in);
index 66c2bc3..513bf8b 100644 (file)
@@ -220,7 +220,7 @@ _edje_multisense_internal_sound_sample_play(Edje *ed, const char *sample_name, c
                   out = efl_add(ECORE_AUDIO_OUT_WASAPI_CLASS, NULL, efl_event_callback_add(efl_added, ECORE_AUDIO_OUT_WASAPI_EVENT_CONTEXT_FAIL, _out_fail, NULL));
 # else
 #if HAVE_TIZENAUDIO
-                  if (!(out = efl_add(ECORE_AUDIO_OUT_TIZEN_CLASS, NULL)))
+                  if (!(out = efl_add_ref(ECORE_AUDIO_OUT_TIZEN_CLASS, NULL)))
                     {
                        ERR("Could not create multisense audio out (Tizen Audio)");
 #endif