[UTC][player][Non-ACR][use default context for _prepared_cb]
authorEunhae Choi <eunhae1.choi@samsung.com>
Thu, 15 Dec 2016 11:22:32 +0000 (20:22 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Thu, 15 Dec 2016 11:22:38 +0000 (20:22 +0900)
Change-Id: Ie6dc569462168d63f6382dbf969edc5d7631e402
Signed-off-by: Eunhae Choi <eunhae1.choi@samsung.com>
src/utc/player/utc-media-player-es.c
src/utc/player/utc-media-player.c

index 05bce19..ec8cf85 100644 (file)
@@ -62,28 +62,14 @@ static gboolean timeout_func(gpointer data)
 
 static void wait_for_async()
 {
-    GMainContext *context = g_main_context_new();
-    GSource *source = g_timeout_source_new(5000);
-
-    /* attach source to context */
-    g_source_attach (source, context);
-
-    g_mainloop = g_main_loop_new(context, FALSE);
-
-    /* set the callback for this source */
-    g_source_set_callback (source, timeout_func, g_mainloop, NULL);
-
-    g_main_loop_run(g_mainloop);
-
-    /* after attaching with the GSource, destroy() is needed */
-    g_source_destroy(source);
-
-    /* unref the last reference we got for GSource */
-    g_source_unref(source);
-
-    /* main loop should be destroyed before unref the context */
-    g_main_loop_unref(g_mainloop);
-    g_main_context_unref(context);
+       int timeout_id;
+       g_mainloop = g_main_loop_new(NULL, FALSE);
+
+       timeout_id = g_timeout_add(5000, timeout_func, g_mainloop);
+       g_main_loop_run(g_mainloop);
+       g_source_remove(timeout_id);
+       g_main_loop_unref(g_mainloop);
+       g_mainloop = NULL;
 }
 
 static void seek_completed_cb(void *user_data)
@@ -982,8 +968,11 @@ int utc_player_unset_media_stream_buffer_status_cb_n(void)
  */
 int utc_player_set_media_stream_seek_cb_p(void)
 {
+#define PREPARE_MAX_TIMEOUT 5
+
     assert(!_is_broken);
     int ret = 0;
+    int repeat = 0;
     player_state_e state;
 
     ret = player_get_state (player, &state);
@@ -1021,7 +1010,10 @@ int utc_player_set_media_stream_seek_cb_p(void)
         return 0;
     }
 
-    usleep(500 * 1000);
+    for (repeat = 0; repeat < PREPARE_MAX_TIMEOUT; repeat++) {
+        wait_for_async();
+    }
+
     pthread_join(feeding_thread_id, NULL);
     assert_eq(g_ret, PLAYER_ERROR_NONE);
     usleep(1000);
index e5fcd0d..0e37b9d 100644 (file)
@@ -66,7 +66,7 @@ static gboolean timeout_func(gpointer data)
     return FALSE;
 }
 
-static void wait_for_async()
+static void wait_for_async(bool custom)
 {
     GMainContext *context = g_main_context_new();
     GSource *source = g_timeout_source_new(5000);
@@ -74,12 +74,23 @@ static void wait_for_async()
     /* attach source to context */
     g_source_attach (source, context);
 
-    g_mainloop = g_main_loop_new(context, FALSE);
+    if (custom) {
+        g_mainloop = g_main_loop_new(context, FALSE);
 
-    /* set the callback for this source */
-    g_source_set_callback (source, timeout_func, g_mainloop, NULL);
+        /* set the callback for this source */
+        g_source_set_callback (source, timeout_func, g_mainloop, NULL);
 
-    g_main_loop_run(g_mainloop);
+        g_main_loop_run(g_mainloop);
+
+    } else {
+        int timeout_id;
+
+        g_mainloop = g_main_loop_new(NULL, FALSE);
+        timeout_id = g_timeout_add(5000, timeout_func, g_mainloop);
+
+        g_main_loop_run(g_mainloop);
+        g_source_remove(timeout_id);
+    }
 
     /* after attaching with the GSource, destroy() is needed */
     g_source_destroy(source);
@@ -90,6 +101,8 @@ static void wait_for_async()
     /* main loop should be destroyed before unref the context */
     g_main_loop_unref(g_mainloop);
     g_main_context_unref(context);
+
+    g_mainloop = NULL;
 }
 
 void focus_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state,
@@ -351,7 +364,7 @@ int utc_media_player_get_play_position_p(void)
 
     int ret = player_set_play_position(player, position, TRUE, player_seek_completed_cb_func, NULL);
     assert_eq(ret, PLAYER_ERROR_NONE);
-    wait_for_async();
+    wait_for_async(FALSE);
 
     int millisecond;
     int ret2 = player_get_play_position(player, &millisecond);
@@ -778,7 +791,7 @@ int utc_media_player_set_sound_type_p(void)
         assert_eq(ret, PLAYER_ERROR_NONE);
         player_start(player);
         assert_eq(ret, PLAYER_ERROR_NONE);
-        wait_for_async();
+        wait_for_async(TRUE);
         ret = sound_manager_get_current_sound_type(&type);
         assert_eq(ret, SOUND_MANAGER_ERROR_NONE);
         assert_eq(SOUND_TYPE_MEDIA, type);
@@ -1828,8 +1841,8 @@ int utc_media_player_prepare_async_p(void)
     ret = player_prepare_async(player, player_prepared_cb_func, NULL);
     assert_eq(ret, PLAYER_ERROR_NONE);
 
-    for(repeat=0; repeat<5; repeat++) {
-        wait_for_async();
+    for(repeat=0; repeat<PREPARE_MAX_TIMEOUT; repeat++) {
+        wait_for_async(FALSE);
         if(_is_pass)
             break;
     }