}
#define LOOP_RUNNING_WAIT_TIME_MS 2500
-int focus_init_context(int index)
+int focus_init_context(int index, bool is_for_watching)
{
int ret = MM_ERROR_NONE;
GMainContext *focus_context;
+ GThread **focus_cb_thread = NULL;
+ char *focus_cb_thread_name;
debug_fenter();
goto ERROR;
}
- g_focus_sound_handle[index].focus_cb_thread = g_thread_new("focus-cb-thread",
+ if (is_for_watching) {
+ focus_cb_thread = &g_focus_sound_handle[index].focus_watch_cb_thread;
+ focus_cb_thread_name = "focus-watch-cb-thread";
+ } else {
+ focus_cb_thread = &g_focus_sound_handle[index].focus_cb_thread;
+ focus_cb_thread_name = "focus-cb-thread";
+ }
+
+ *focus_cb_thread = g_thread_new(focus_cb_thread_name,
_focus_thread_func,
g_focus_sound_handle[index].focus_loop);
- if (g_focus_sound_handle[index].focus_cb_thread == NULL) {
+ if (*focus_cb_thread == NULL) {
debug_error("could not create thread..");
goto ERROR;
}
- debug_warning("focus cb thread[%p] with mainloop[%p] is created for index(%d)",
- g_focus_sound_handle[index].focus_cb_thread, g_focus_sound_handle[index].focus_loop, index);
+ debug_warning("focus cb thread[%p] with mainloop[%p] is created for index(%d), is_for_watching(%d)",
+ *focus_cb_thread, g_focus_sound_handle[index].focus_loop, index, is_for_watching);
if ((ret = _focus_loop_is_running_timed_wait(g_focus_sound_handle[index].focus_loop, LOOP_RUNNING_WAIT_TIME_MS))) {
debug_error("failed to _focus_loop_is_running_timed_wait(), ret[0x%x]", ret);
ERROR:
if (g_focus_sound_handle[index].focus_loop) {
- if (g_focus_sound_handle[index].focus_cb_thread) {
+ if (*focus_cb_thread) {
g_main_loop_quit(g_focus_sound_handle[index].focus_loop);
- g_thread_join(g_focus_sound_handle[index].focus_cb_thread);
- debug_warning("after thread join, thread[%p], mainloop[%p] for index(%d)",
- g_focus_sound_handle[index].focus_cb_thread, g_focus_sound_handle[index].focus_loop, index);
- g_focus_sound_handle[index].focus_cb_thread = NULL;
+ g_thread_join(*focus_cb_thread);
+ debug_warning("after thread join, thread[%p], mainloop[%p] for index(%d), is_for_watching(%d)",
+ *focus_cb_thread, g_focus_sound_handle[index].focus_loop, index, is_for_watching);
+ *focus_cb_thread = NULL;
}
g_main_loop_unref(g_focus_sound_handle[index].focus_loop);
g_focus_sound_handle[index].focus_loop = NULL;
return MM_ERROR_SOUND_INTERNAL;
}
-void focus_deinit_context(int index)
+void focus_deinit_context(int index, bool is_for_watching)
{
+ GThread **focus_cb_thread = NULL;
+
debug_fenter();
if (index < 0 || index >= FOCUS_HANDLE_MAX) {
return;
}
- if (!g_focus_sound_handle[index].focus_loop || !g_focus_sound_handle[index].focus_cb_thread) {
- debug_error("focus_loop[%p] or focus_cb_thread[%p] is null",
- g_focus_sound_handle[index].focus_loop, g_focus_sound_handle[index].focus_cb_thread);
+ if (!g_focus_sound_handle[index].focus_loop ||
+ (!is_for_watching && !g_focus_sound_handle[index].focus_cb_thread) ||
+ (is_for_watching && !g_focus_sound_handle[index].focus_watch_cb_thread)) {
+ debug_error("focus_loop[%p] or focus_cb_thread[%p] or focus_watch_cb_thread[%p] is null",
+ g_focus_sound_handle[index].focus_loop, g_focus_sound_handle[index].focus_cb_thread,
+ g_focus_sound_handle[index].focus_watch_cb_thread);
return;
}
g_main_loop_quit(g_focus_sound_handle[index].focus_loop);
- g_thread_join(g_focus_sound_handle[index].focus_cb_thread);
- debug_warning("after thread join, thread[%p], mainloop[%p] for index(%d)",
- g_focus_sound_handle[index].focus_cb_thread, g_focus_sound_handle[index].focus_loop, index);
+
+ if (is_for_watching)
+ focus_cb_thread = &g_focus_sound_handle[index].focus_watch_cb_thread;
+ else
+ focus_cb_thread = &g_focus_sound_handle[index].focus_cb_thread;
+ g_thread_join(*focus_cb_thread);
+
+ debug_warning("after thread join, thread[%p], mainloop[%p] for index(%d), is_for_watching(%d)",
+ *focus_cb_thread, g_focus_sound_handle[index].focus_loop, index, is_for_watching);
g_main_loop_unref(g_focus_sound_handle[index].focus_loop);
g_focus_sound_handle[index].focus_loop = NULL;
- g_focus_sound_handle[index].focus_cb_thread = NULL;
+ *focus_cb_thread = NULL;
debug_fleave();
}