From c21707af66a3931d304e223876a6bbb1967f7623 Mon Sep 17 00:00:00 2001 From: Eunhae Choi Date: Wed, 10 Aug 2016 20:20:29 +0900 Subject: [PATCH] [video frame decoded cb] use handoff signal instead of sinkpad probe Change-Id: If71a04f4ebde1f35490d24e74ce9700542eb3995 --- packaging/libmm-player.spec | 2 +- src/include/mm_player_priv.h | 3 +- src/mm_player_priv.c | 112 ++++++++++++++++++++++++++----------------- 3 files changed, 71 insertions(+), 46 deletions(-) diff --git a/packaging/libmm-player.spec b/packaging/libmm-player.spec index 7f855be..e811b53 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.93 +Version: 0.5.94 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 diff --git a/src/include/mm_player_priv.h b/src/include/mm_player_priv.h index ed8c96c..aba3826 100644 --- a/src/include/mm_player_priv.h +++ b/src/include/mm_player_priv.h @@ -57,7 +57,6 @@ /*--------------------------------------------------------------------------- | GLOBAL #defines: | ---------------------------------------------------------------------------*/ - #define MM_PLAYER_IMGB_MPLANE_MAX 4 #define MM_PLAYER_STREAM_COUNT_MAX 3 @@ -548,6 +547,7 @@ typedef struct { GMutex video_bo_mutex; GList* video_bo_list; /* mm_player_video_bo_info_t, bo list for decoded video data by sw codec */ int video_bo_size; + bool video_stream_prerolled; /* audio stram callback */ mm_player_audio_stream_callback audio_stream_cb; @@ -575,7 +575,6 @@ typedef struct { gboolean bypass_audio_effect; gulong audio_cb_probe_id; - gulong video_cb_probe_id; /* for appsrc */ tBuffer mem_buf; diff --git a/src/mm_player_priv.c b/src/mm_player_priv.c index 33456dd..78e532d 100644 --- a/src/mm_player_priv.c +++ b/src/mm_player_priv.c @@ -177,7 +177,8 @@ static gboolean __mmplayer_gst_handle_duration(mm_player_t* player, GstMess int __mmplayer_switch_audio_sink (mm_player_t* player); static gboolean __mmplayer_gst_remove_fakesink(mm_player_t* player, MMPlayerGstElement* fakesink); static GstPadProbeReturn __mmplayer_audio_stream_probe (GstPad *pad, GstPadProbeInfo *info, gpointer u_data); -static GstPadProbeReturn __mmplayer_video_stream_probe (GstPad *pad, GstPadProbeInfo *info, gpointer u_data); +static void __mmplayer_video_stream_decoded_preroll_cb(GstElement* object, GstBuffer *buffer, GstPad *pad, gpointer data); +static void __mmplayer_video_stream_decoded_render_cb(GstElement* object, GstBuffer *buffer, GstPad *pad, gpointer data); static GstPadProbeReturn __mmplayer_subtitle_adjust_position_probe (GstPad *pad, GstPadProbeInfo *info, gpointer u_data); static int __mmplayer_change_selector_pad (mm_player_t* player, MMPlayerTrackType type, int index); @@ -2695,7 +2696,7 @@ __mmplayer_gst_decode_pad_added (GstElement *elem, GstPad *pad, gpointer data) /* don't make video because of not required, and not support multiple track */ if (stype == MM_DISPLAY_SURFACE_NULL) { - LOGD ("no video sink by null surface or multiple track (%d)", stype); + LOGD ("no video sink by null surface"); MMPlayerResourceState resource_state = RESOURCE_STATE_NONE; if (_mmplayer_resource_manager_get_state(&player->resource_manager, &resource_state) == MM_ERROR_NONE) @@ -2757,17 +2758,30 @@ __mmplayer_gst_decode_pad_added (GstElement *elem, GstPad *pad, gpointer data) } if (stype == MM_DISPLAY_SURFACE_REMOTE) { - MMPLAYER_SIGNAL_CONNECT (player, sinkpad, MM_PLAYER_SIGNAL_TYPE_VIDEOBIN, + MMPLAYER_SIGNAL_CONNECT(player, sinkpad, MM_PLAYER_SIGNAL_TYPE_VIDEOBIN, "notify::caps", G_CALLBACK(__mmplayer_gst_caps_notify_cb), player); } - if (player->set_mode.media_packet_video_stream) - player->video_cb_probe_id = gst_pad_add_probe (sinkpad, GST_PAD_PROBE_TYPE_BUFFER, __mmplayer_video_stream_probe, player, NULL); - - g_object_set (G_OBJECT (fakesink), "async", TRUE, NULL); - g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL); - gst_element_set_state (fakesink, GST_STATE_PAUSED); + if (player->set_mode.media_packet_video_stream) { + g_object_set(G_OBJECT(fakesink), "signal-handoffs", TRUE, NULL); + + MMPLAYER_SIGNAL_CONNECT(player, + G_OBJECT(fakesink), + MM_PLAYER_SIGNAL_TYPE_VIDEOBIN, + "handoff", + G_CALLBACK(__mmplayer_video_stream_decoded_render_cb), + (gpointer)player); + + MMPLAYER_SIGNAL_CONNECT(player, + G_OBJECT(fakesink), + MM_PLAYER_SIGNAL_TYPE_VIDEOBIN, + "preroll-handoff", + G_CALLBACK(__mmplayer_video_stream_decoded_preroll_cb), + (gpointer)player); + } + g_object_set(G_OBJECT(fakesink), "async", TRUE, "sync", TRUE, NULL); + gst_element_set_state(fakesink, GST_STATE_PAUSED); goto DONE; } @@ -5543,10 +5557,23 @@ __mmplayer_video_stream_get_bo(mm_player_t* player, int size) continue; } } +static void +__mmplayer_video_stream_decoded_preroll_cb(GstElement* object, GstBuffer *buffer, GstPad *pad, gpointer data) +{ + mm_player_t* player = (mm_player_t*)data; + MMPLAYER_FENTER(); + MMPLAYER_RETURN_IF_FAIL(player && player->video_stream_cb); -static GstPadProbeReturn -__mmplayer_video_stream_probe (GstPad *pad, GstPadProbeInfo *info, gpointer user_data) + __mmplayer_video_stream_decoded_render_cb(object, buffer, pad, data); + + /* not to send prerolled pkt again */ + player->video_stream_prerolled = TRUE; +} + +static void +__mmplayer_video_stream_decoded_render_cb(GstElement* object, GstBuffer *buffer, GstPad *pad, gpointer data) { + mm_player_t* player = (mm_player_t*)data; GstCaps *caps = NULL; MMPlayerVideoStreamDataType stream; MMVideoBuffer *video_buffer = NULL; @@ -5556,16 +5583,20 @@ __mmplayer_video_stream_probe (GstPad *pad, GstPadProbeInfo *info, gpointer user GstStructure *structure = NULL; const gchar *string_format = NULL; unsigned int fourcc = 0; - mm_player_t* player = (mm_player_t*)user_data; - GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); - MMPLAYER_RETURN_VAL_IF_FAIL(buffer, GST_PAD_PROBE_DROP); - MMPLAYER_RETURN_VAL_IF_FAIL(gst_buffer_n_memory(buffer) , GST_PAD_PROBE_DROP); + MMPLAYER_FENTER(); + MMPLAYER_RETURN_IF_FAIL(player && player->video_stream_cb); + + if (player->video_stream_prerolled) { + player->video_stream_prerolled = FALSE; + LOGD("skip the prerolled pkt not to send it again"); + return; + } caps = gst_pad_get_current_caps(pad); if (caps == NULL) { LOGE( "Caps is NULL." ); - return GST_PAD_PROBE_OK; + return; } /* MMPLAYER_LOG_GST_CAPS_TYPE(caps); */ @@ -5591,7 +5622,7 @@ __mmplayer_video_stream_probe (GstPad *pad, GstPadProbeInfo *info, gpointer user if (stream.width == 0 || stream.height == 0 || stream.format == MM_PIXEL_FORMAT_INVALID) { LOGE("Wrong condition!!"); - return TRUE; + return; } /* set size and timestamp */ @@ -5635,7 +5666,7 @@ __mmplayer_video_stream_probe (GstPad *pad, GstPadProbeInfo *info, gpointer user gst_ret = gst_memory_map(dataBlock, &mapinfo, GST_MAP_READWRITE); if (!gst_ret) { LOGE("fail to gst_memory_map"); - return GST_PAD_PROBE_OK; + return; } stream.stride[0] = stride; @@ -5646,7 +5677,7 @@ __mmplayer_video_stream_probe (GstPad *pad, GstPadProbeInfo *info, gpointer user } else { LOGE("Not support format %d", stream.format); gst_memory_unmap(dataBlock, &mapinfo); - return GST_PAD_PROBE_OK; + return; } size = (stream.stride[0] + stream.stride[1]) * elevation; @@ -5654,7 +5685,7 @@ __mmplayer_video_stream_probe (GstPad *pad, GstPadProbeInfo *info, gpointer user if(!stream.bo[0]) { LOGE("Fail to tbm_bo_alloc!!"); gst_memory_unmap(dataBlock, &mapinfo); - return GST_PAD_PROBE_OK; + return; } thandle = tbm_bo_map(stream.bo[0], TBM_DEVICE_CPU, TBM_OPTION_WRITE); if(thandle.ptr && mapinfo.data) @@ -5675,7 +5706,7 @@ __mmplayer_video_stream_probe (GstPad *pad, GstPadProbeInfo *info, gpointer user gst_memory_unmap(dataBlock, &mapinfo); } - return GST_PAD_PROBE_OK; + return; } static int @@ -5866,12 +5897,23 @@ __mmplayer_gst_create_video_pipeline(mm_player_t* player, GstCaps* caps, MMDispl case MM_DISPLAY_SURFACE_REMOTE: { if (player->set_mode.media_packet_video_stream) { - GstPad* sinkpad = NULL; - sinkpad = gst_element_get_static_pad (player->pipeline->videobin[MMPLAYER_V_SINK].gst, "sink"); - g_object_set (player->pipeline->videobin[MMPLAYER_V_SINK].gst, "sync", TRUE, NULL); - LOGE("add data probe at videosink"); - player->video_cb_probe_id = gst_pad_add_probe (sinkpad, GST_PAD_PROBE_TYPE_BUFFER, __mmplayer_video_stream_probe, player, NULL); + g_object_set(G_OBJECT(player->pipeline->videobin[MMPLAYER_V_SINK].gst), + "sync", TRUE, "signal-handoffs", TRUE, NULL); + + MMPLAYER_SIGNAL_CONNECT(player, + G_OBJECT(player->pipeline->videobin[MMPLAYER_V_SINK].gst), + MM_PLAYER_SIGNAL_TYPE_VIDEOBIN, + "handoff", + G_CALLBACK(__mmplayer_video_stream_decoded_render_cb), + (gpointer)player); + + MMPLAYER_SIGNAL_CONNECT(player, + G_OBJECT(player->pipeline->videobin[MMPLAYER_V_SINK].gst), + MM_PLAYER_SIGNAL_TYPE_VIDEOBIN, + "preroll-handoff", + G_CALLBACK(__mmplayer_video_stream_decoded_preroll_cb), + (gpointer)player); } break; } @@ -13309,6 +13351,7 @@ __mmplayer_release_misc(mm_player_t* player) player->video_stream_cb = NULL; player->video_stream_cb_user_param = NULL; + player->video_stream_prerolled = FALSE; player->audio_stream_cb = NULL; player->audio_stream_render_cb_ex = NULL; @@ -13382,23 +13425,6 @@ __mmplayer_release_misc(mm_player_t* player) player->state_tune_caps = NULL; } - if (player->video_cb_probe_id) - { - GstPad *pad = NULL; - - pad = gst_element_get_static_pad (player->video_fakesink, "sink"); - - if (pad) { - LOGD("release video probe\n"); - - /* release audio callback */ - gst_pad_remove_probe (pad, player->video_cb_probe_id); - player->video_cb_probe_id = 0; - player->video_stream_cb = NULL; - player->video_stream_cb_user_param = NULL; - } - } - MMPLAYER_FLEAVE(); } -- 2.7.4