From: NAMJEONGYOON Date: Tue, 30 Aug 2016 07:44:02 +0000 (+0900) Subject: clean up the code about lock X-Git-Tag: submit/tizen/20160907.074000^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=557194220f20b8b4460de98d767d7af1d1fe5478;p=platform%2Fcore%2Fmultimedia%2Flibmm-player.git clean up the code about lock Change-Id: I8feada959bb4759dea00769bd5c8db3a81dc5a5c --- diff --git a/packaging/libmm-player.spec b/packaging/libmm-player.spec index d58a534..9b2997b 100644 --- a/packaging/libmm-player.spec +++ b/packaging/libmm-player.spec @@ -1,6 +1,6 @@ Name: libmm-player Summary: Multimedia Framework Player Library -Version: 0.5.97 +Version: 0.5.98 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 diff --git a/src/include/mm_player_utils.h b/src/include/mm_player_utils.h index 41fec00..ee2a5e2 100644 --- a/src/include/mm_player_utils.h +++ b/src/include/mm_player_utils.h @@ -52,12 +52,46 @@ if (x) \ g_free(x); \ x = NULL; -#define MMPLAYER_CMD_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->cmd_lock) -#define MMPLAYER_CMD_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t*)x_player)->cmd_lock) -#define MMPLAYER_PLAYBACK_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->playback_lock) -#define MMPLAYER_PLAYBACK_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t*)x_player)->playback_lock) #define MMPLAYER_GET_ATTRS(x_player) ((mm_player_t*)x_player)->attrs +/* command */ +#define MMPLAYER_CMD_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->cmd_lock) +#define MMPLAYER_CMD_TRYLOCK(x_player) g_mutex_trylock(&((mm_player_t *)x_player)->cmd_lock) +#define MMPLAYER_CMD_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t*)x_player)->cmd_lock) + +/* playback */ +#define MMPLAYER_PLAYBACK_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->playback_lock) +#define MMPLAYER_PLAYBACK_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t*)x_player)->playback_lock) + +/* capture thread */ +#define MMPLAYER_CAPTURE_THREAD_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->capture_thread_mutex) +#define MMPLAYER_CAPTURE_THREAD_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t *)x_player)->capture_thread_mutex) +#define MMPLAYER_CAPTURE_THREAD_WAIT(x_player) g_cond_wait(&((mm_player_t *)x_player)->capture_thread_cond, &((mm_player_t *)x_player)->capture_thread_mutex) +#define MMPLAYER_CAPTURE_THREAD_SIGNAL(x_player) g_cond_signal(&((mm_player_t *)x_player)->capture_thread_cond); + +/* next play thread */ +#define MMPLAYER_NEXT_PLAY_THREAD_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->next_play_thread_mutex) +#define MMPLAYER_NEXT_PLAY_THREAD_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t *)x_player)->next_play_thread_mutex) +#define MMPLAYER_NEXT_PLAY_THREAD_WAIT(x_player) g_cond_wait(&((mm_player_t *)x_player)->next_play_thread_cond, &((mm_player_t *)x_player)->next_play_thread_mutex) +#define MMPLAYER_NEXT_PLAY_THREAD_SIGNAL(x_player) g_cond_signal(&((mm_player_t *)x_player)->next_play_thread_cond); + +/* repeat thread */ +#define MMPLAYER_REPEAT_THREAD_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->repeat_thread_mutex) +#define MMPLAYER_REPEAT_THREAD_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t *)x_player)->repeat_thread_mutex) +#define MMPLAYER_REPEAT_THREAD_WAIT(x_player) g_cond_wait(&((mm_player_t *)x_player)->repeat_thread_cond, &((mm_player_t *)x_player)->repeat_thread_mutex) +#define MMPLAYER_REPEAT_THREAD_SIGNAL(x_player) g_cond_signal(&((mm_player_t *)x_player)->repeat_thread_cond); + +/* handling fakesink */ +#define MMPLAYER_FSINK_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->fsink_lock) +#define MMPLAYER_FSINK_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t *)x_player)->fsink_lock) + +/* video stream bo */ +#define MMPLAYER_VIDEO_BO_LOCK(x_player) g_mutex_lock(&((mm_player_t *)x_player)->video_bo_mutex) +#define MMPLAYER_VIDEO_BO_UNLOCK(x_player) g_mutex_unlock(&((mm_player_t *)x_player)->video_bo_mutex) +#define MMPLAYER_VIDEO_BO_WAIT(x_player) g_cond_wait(&((mm_player_t *)x_player)->video_bo_cond, &((mm_player_t *)x_player)->video_bo_mutex) +#define MMPLAYER_VIDEO_BO_WAIT_UNTIL(x_player, end_time) g_cond_wait_until(&((mm_player_t *)x_player)->video_bo_cond, &((mm_player_t *)x_player)->video_bo_mutex, end_time); +#define MMPLAYER_VIDEO_BO_SIGNAL(x_player) g_cond_signal(&((mm_player_t *)x_player)->video_bo_cond); + #if 0 #define MMPLAYER_FENTER(); LOGD(""); #define MMPLAYER_FLEAVE(); LOGD(""); diff --git a/src/mm_player_capture.c b/src/mm_player_capture.c index 57a02f3..fc096b7 100644 --- a/src/mm_player_capture.c +++ b/src/mm_player_capture.c @@ -91,10 +91,10 @@ _mmplayer_release_video_capture(mm_player_t* player) { MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED); /* release capture thread */ - g_mutex_lock(&player->capture_thread_mutex); + MMPLAYER_CAPTURE_THREAD_LOCK(player); player->capture_thread_exit = TRUE; - g_cond_signal(&player->capture_thread_cond); - g_mutex_unlock(&player->capture_thread_mutex); + MMPLAYER_CAPTURE_THREAD_SIGNAL(player); + MMPLAYER_CAPTURE_THREAD_UNLOCK(player); LOGD("waitting for capture thread exit"); g_thread_join(player->capture_thread); @@ -285,10 +285,10 @@ __mmplayer_capture_thread(gpointer data) MMPLAYER_RETURN_VAL_IF_FAIL(player, NULL); - g_mutex_lock(&player->capture_thread_mutex); + MMPLAYER_CAPTURE_THREAD_LOCK(player); while (!player->capture_thread_exit) { LOGD("capture thread started. waiting for signal"); - g_cond_wait(&player->capture_thread_cond, &player->capture_thread_mutex); + MMPLAYER_CAPTURE_THREAD_WAIT(player); if (player->capture_thread_exit) { LOGD("exiting capture thread"); @@ -458,7 +458,7 @@ ERROR: } EXIT: - g_mutex_unlock(&player->capture_thread_mutex); + MMPLAYER_CAPTURE_THREAD_UNLOCK(player); return NULL; } @@ -603,7 +603,7 @@ __mmplayer_get_video_frame_from_buffer(mm_player_t* player, GstPad *pad, GstBuff DONE: /* do convert colorspace */ - g_cond_signal(&player->capture_thread_cond); + MMPLAYER_CAPTURE_THREAD_SIGNAL(player); MMPLAYER_FLEAVE(); diff --git a/src/mm_player_es.c b/src/mm_player_es.c index c90924c..ef61f83 100644 --- a/src/mm_player_es.c +++ b/src/mm_player_es.c @@ -515,9 +515,8 @@ _mmplayer_submit_packet(MMHandleType hplayer, media_packet_h packet) /* keep push without error handling */ } - if (duration == 0) { + if (duration == 0) duration = DEFAULT_VIDEO_FRAME_DURATION * GST_MSECOND; - } GST_BUFFER_DURATION(_buffer) = (GstClockTime)duration; } diff --git a/src/mm_player_priv.c b/src/mm_player_priv.c index 9209f6a..1fbeb27 100644 --- a/src/mm_player_priv.c +++ b/src/mm_player_priv.c @@ -785,10 +785,10 @@ static gpointer __mmplayer_next_play_thread(gpointer data) MMPLAYER_RETURN_VAL_IF_FAIL(player, NULL); - g_mutex_lock(&player->next_play_thread_mutex); + MMPLAYER_NEXT_PLAY_THREAD_LOCK(player); while (!player->next_play_thread_exit) { LOGD("next play thread started. waiting for signal.\n"); - g_cond_wait(&player->next_play_thread_cond, &player->next_play_thread_mutex); + MMPLAYER_NEXT_PLAY_THREAD_WAIT(player); LOGD("reconfigure pipeline for gapless play.\n"); @@ -811,7 +811,7 @@ static gpointer __mmplayer_next_play_thread(gpointer data) __mmplayer_activate_next_source(player, GST_STATE_PLAYING); } - g_mutex_unlock(&player->next_play_thread_mutex); + MMPLAYER_NEXT_PLAY_THREAD_UNLOCK(player); return NULL; } @@ -825,10 +825,10 @@ static gpointer __mmplayer_repeat_thread(gpointer data) MMPLAYER_RETURN_VAL_IF_FAIL(player, NULL); - g_mutex_lock(&player->repeat_thread_mutex); + MMPLAYER_REPEAT_THREAD_LOCK(player); while (!player->repeat_thread_exit) { LOGD("repeat thread started. waiting for signal.\n"); - g_cond_wait(&player->repeat_thread_cond, &player->repeat_thread_mutex); + MMPLAYER_REPEAT_THREAD_WAIT(player); if (player->repeat_thread_exit) { LOGD("exiting repeat thread\n"); @@ -837,7 +837,7 @@ static gpointer __mmplayer_repeat_thread(gpointer data) /* lock */ - g_mutex_lock(&player->cmd_lock); + MMPLAYER_CMD_LOCK(player); attrs = MMPLAYER_GET_ATTRS(player); @@ -881,10 +881,10 @@ static gpointer __mmplayer_repeat_thread(gpointer data) } /* unlock */ - g_mutex_unlock(&player->cmd_lock); + MMPLAYER_CMD_UNLOCK(player); } - g_mutex_unlock(&player->repeat_thread_mutex); + MMPLAYER_REPEAT_THREAD_UNLOCK(player); return NULL; } @@ -1172,7 +1172,7 @@ __mmplayer_gst_callback(GstBus *bus, GstMessage *msg, gpointer data) // @ if (smooth_repeat) { LOGD("smooth repeat enabled. seeking operation will be excuted in new thread\n"); - g_cond_signal(&player->repeat_thread_cond); + MMPLAYER_REPEAT_THREAD_SIGNAL(player); break; } else { @@ -1883,7 +1883,7 @@ __mmplayer_gst_remove_fakesink(mm_player_t* player, MMPlayerGstElement* fakesink MMPLAYER_RETURN_VAL_IF_FAIL(fakesink, TRUE); /* lock */ - g_mutex_lock(&player->fsink_lock); + MMPLAYER_FSINK_LOCK(player); if (!fakesink->gst) goto ERROR; @@ -1920,14 +1920,14 @@ __mmplayer_gst_remove_fakesink(mm_player_t* player, MMPlayerGstElement* fakesink gst_element_set_locked_state(fakesink->gst, FALSE); - g_mutex_unlock(&player->fsink_lock); + MMPLAYER_FSINK_UNLOCK(player); return TRUE; ERROR: if (fakesink->gst) gst_element_set_locked_state(fakesink->gst, FALSE); - g_mutex_unlock(&player->fsink_lock); + MMPLAYER_FSINK_UNLOCK(player); return FALSE; } @@ -4850,7 +4850,7 @@ int _mmplayer_video_stream_release_bo(mm_player_t* player, void* bo) MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED); MMPLAYER_RETURN_VAL_IF_FAIL(bo, MM_ERROR_INVALID_ARGUMENT); - g_mutex_lock(&player->video_bo_mutex); + MMPLAYER_VIDEO_BO_LOCK(player); if (player->video_bo_list) { for (l = g_list_first(player->video_bo_list); l; l = g_list_next(l)) { @@ -4858,8 +4858,8 @@ int _mmplayer_video_stream_release_bo(mm_player_t* player, void* bo) if (tmp && tmp->bo == bo) { tmp->using = FALSE; LOGD("release bo %p", bo); - g_mutex_unlock(&player->video_bo_mutex); - g_cond_signal(&player->video_bo_cond); + MMPLAYER_VIDEO_BO_UNLOCK(player); + MMPLAYER_VIDEO_BO_SIGNAL(player); return ret; } } @@ -4867,7 +4867,7 @@ int _mmplayer_video_stream_release_bo(mm_player_t* player, void* bo) /* hw codec is running or the list was reset for DRC. */ LOGW("there is no bo list."); } - g_mutex_unlock(&player->video_bo_mutex); + MMPLAYER_VIDEO_BO_UNLOCK(player); LOGW("failed to find bo %p", bo); return ret; @@ -4881,7 +4881,7 @@ __mmplayer_video_stream_destroy_bo_list(mm_player_t* player) MMPLAYER_FENTER(); MMPLAYER_RETURN_IF_FAIL(player); - g_mutex_lock(&player->video_bo_mutex); + MMPLAYER_VIDEO_BO_LOCK(player); if (player->video_bo_list) { LOGD("destroy video_bo_list : %d", g_list_length(player->video_bo_list)); for (l = g_list_first(player->video_bo_list); l; l = g_list_next(l)) { @@ -4896,7 +4896,7 @@ __mmplayer_video_stream_destroy_bo_list(mm_player_t* player) player->video_bo_list = NULL; } player->video_bo_size = 0; - g_mutex_unlock(&player->video_bo_mutex); + MMPLAYER_VIDEO_BO_UNLOCK(player); MMPLAYER_FLEAVE(); return; @@ -4916,7 +4916,7 @@ __mmplayer_video_stream_get_bo(mm_player_t* player, int size) player->video_bo_size = size; } - g_mutex_lock(&player->video_bo_mutex); + MMPLAYER_VIDEO_BO_LOCK(player); if ((!player->video_bo_list) || (g_list_length(player->video_bo_list) < player->ini.num_of_video_bo)) { @@ -4953,7 +4953,7 @@ __mmplayer_video_stream_get_bo(mm_player_t* player, int size) player->video_extra_num_buffers = player->ini.num_of_video_bo/2; if (idx == 0) { - g_mutex_unlock(&player->video_bo_mutex); + MMPLAYER_VIDEO_BO_UNLOCK(player); return NULL; } @@ -4967,21 +4967,21 @@ __mmplayer_video_stream_get_bo(mm_player_t* player, int size) if (tmp && (tmp->using == FALSE)) { LOGD("found bo %p to use", tmp->bo); tmp->using = TRUE; - g_mutex_unlock(&player->video_bo_mutex); + MMPLAYER_VIDEO_BO_UNLOCK(player); return tmp->bo; } } if (!ret) { LOGE("failed to get bo in %d timeout", player->ini.video_bo_timeout); - g_mutex_unlock(&player->video_bo_mutex); + MMPLAYER_VIDEO_BO_UNLOCK(player); return NULL; } if (player->ini.video_bo_timeout <= 0) { - g_cond_wait(&player->video_bo_cond, &player->video_bo_mutex); + MMPLAYER_VIDEO_BO_WAIT(player); } else { gint64 timeout = g_get_monotonic_time() + player->ini.video_bo_timeout*G_TIME_SPAN_SECOND; - ret = g_cond_wait_until(&player->video_bo_cond, &player->video_bo_mutex, timeout); + ret = MMPLAYER_VIDEO_BO_WAIT_UNTIL(player, timeout); } continue; } @@ -8146,7 +8146,7 @@ __mmplayer_can_do_interrupt(mm_player_t *player) } /* check other thread */ - if (!g_mutex_trylock(&player->cmd_lock)) { + if (!MMPLAYER_CMD_TRYLOCK(player)) { LOGW("locked already, cmd state : %d", player->cmd); /* check application command */ @@ -8154,7 +8154,7 @@ __mmplayer_can_do_interrupt(mm_player_t *player) LOGW("playing.. should wait cmd lock then, will be interrupted"); /* lock will be released at mrp_resource_release_cb() */ - g_mutex_lock(&player->cmd_lock); + MMPLAYER_CMD_LOCK(player); goto INTERRUPT; } LOGW("nothing to do"); @@ -8528,7 +8528,7 @@ ERROR: /* free thread */ if (player->repeat_thread) { player->repeat_thread_exit = TRUE; - g_cond_signal(&player->repeat_thread_cond); + MMPLAYER_REPEAT_THREAD_SIGNAL(player); g_thread_join(player->repeat_thread); player->repeat_thread = NULL; @@ -8540,7 +8540,7 @@ ERROR: /* free next play thread */ if (player->next_play_thread) { player->next_play_thread_exit = TRUE; - g_cond_signal(&player->next_play_thread_cond); + MMPLAYER_NEXT_PLAY_THREAD_SIGNAL(player); g_thread_join(player->next_play_thread); player->next_play_thread = NULL; @@ -8698,7 +8698,7 @@ _mmplayer_destroy(MMHandleType handle) // @ /* release repeat thread */ if (player->repeat_thread) { player->repeat_thread_exit = TRUE; - g_cond_signal(&player->repeat_thread_cond); + MMPLAYER_REPEAT_THREAD_SIGNAL(player); LOGD("waitting for repeat thread exit\n"); g_thread_join(player->repeat_thread); @@ -8710,7 +8710,7 @@ _mmplayer_destroy(MMHandleType handle) // @ /* release next play thread */ if (player->next_play_thread) { player->next_play_thread_exit = TRUE; - g_cond_signal(&player->next_play_thread_cond); + MMPLAYER_NEXT_PLAY_THREAD_SIGNAL(player); LOGD("waitting for next play thread exit\n"); g_thread_join(player->next_play_thread); @@ -11391,7 +11391,7 @@ __mmplayer_deactivate_old_path(mm_player_t *player) } MMPLAYER_PLAYBACK_LOCK(player); - g_cond_signal(&player->next_play_thread_cond); + MMPLAYER_NEXT_PLAY_THREAD_SIGNAL(player); MMPLAYER_FLEAVE(); return; @@ -11829,7 +11829,7 @@ __mmplayer_gst_decode_drained(GstElement *bin, gpointer data) return; } - if (!g_mutex_trylock(&player->cmd_lock)) { + if (!MMPLAYER_CMD_TRYLOCK(player)) { LOGW("Fail to get cmd lock"); return; } @@ -11837,7 +11837,7 @@ __mmplayer_gst_decode_drained(GstElement *bin, gpointer data) if (!__mmplayer_verify_next_play_path(player)) { LOGD("decoding is finished."); __mmplayer_reset_gapless_state(player); - g_mutex_unlock(&player->cmd_lock); + MMPLAYER_CMD_UNLOCK(player); return; } @@ -11847,7 +11847,7 @@ __mmplayer_gst_decode_drained(GstElement *bin, gpointer data) /* deactivate pipeline except sinkbins to set up the new pipeline of next uri*/ __mmplayer_deactivate_old_path(player); - g_mutex_unlock(&player->cmd_lock); + MMPLAYER_CMD_UNLOCK(player); MMPLAYER_FLEAVE(); }