From e62b71c15a8c43e91a3032414ae1b0974d9a6867 Mon Sep 17 00:00:00 2001 From: Eunhye Choi Date: Fri, 18 Sep 2020 17:06:20 +0900 Subject: [PATCH] [0.6.241] apply select-stream event for audio only - keep the previous path for decodebin2 - apply select-stream event with uridecodebin3 to release decoder and display resource in case the audio-only is enabled. Change-Id: I559c352f8b1496b135af5218ed15467effd837e1 --- packaging/libmm-player.spec | 2 +- src/include/mm_player.h | 6 +- src/include/mm_player_attrs.h | 1 + src/include/mm_player_priv.h | 1 - src/include/mm_player_tracks.h | 3 +- src/mm_player.c | 16 ----- src/mm_player_attrs.c | 11 ++++ src/mm_player_priv.c | 137 +++++++++++++++++++++++++++-------------- src/mm_player_tracks.c | 1 - 9 files changed, 112 insertions(+), 66 deletions(-) diff --git a/packaging/libmm-player.spec b/packaging/libmm-player.spec index 5c303a2..d123de8 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.6.240 +Version: 0.6.241 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 diff --git a/src/include/mm_player.h b/src/include/mm_player.h index f0f3eb4..6ca6646 100644 --- a/src/include/mm_player.h +++ b/src/include/mm_player.h @@ -316,6 +316,11 @@ */ #define MM_PLAYER_MEDIA_STREAM_INPUT_FORMAT "media_stream_input_format" +/** + * MM_PLAYER_AUDIO_ONLY (int) + */ +#define MM_PLAYER_AUDIO_ONLY "audio_only" + #define BUFFER_MAX_PLANE_NUM (4) /** @@ -1366,7 +1371,6 @@ int mm_player_get_max_adaptive_variant_limit(MMHandleType player, int *bandwidth * These functions are to set/get the audio only mode */ int mm_player_set_audio_only(MMHandleType player, bool audio_only); -int mm_player_get_audio_only(MMHandleType player, bool *audio_only); /** * These functions are to get the streaming buffering time diff --git a/src/include/mm_player_attrs.h b/src/include/mm_player_attrs.h index 0955bc3..15e64e4 100644 --- a/src/include/mm_player_attrs.h +++ b/src/include/mm_player_attrs.h @@ -92,6 +92,7 @@ typedef enum { MMPLAYER_ATTRS_AUDIO_OFFLOAD, MMPLAYER_ATTRS_AUDIO_OFFLOAD_FORMAT, MMPLAYER_ATTRS_MEDIA_STREAM_INPUT_FORMAT, + MMPLAYER_ATTRS_AUDIO_ONLY, MMPLAYER_ATTRS_NUM } mmplayer_attrs_id_e; diff --git a/src/include/mm_player_priv.h b/src/include/mm_player_priv.h index adb4636..f939b7e 100644 --- a/src/include/mm_player_priv.h +++ b/src/include/mm_player_priv.h @@ -875,7 +875,6 @@ int _mmplayer_get_adaptive_variant_info(MMHandleType hplayer, int *num, char **v int _mmplayer_set_max_adaptive_variant_limit(MMHandleType hplayer, int bandwidth, int width, int height); int _mmplayer_get_max_adaptive_variant_limit(MMHandleType hplayer, int *bandwidth, int *width, int *height); int _mmplayer_set_audio_only(MMHandleType hplayer, bool audio_only); -int _mmplayer_get_audio_only(MMHandleType hplayer, bool *paudio_only); int _mmplayer_get_streaming_buffering_time(MMHandleType hplayer, int *prebuffer_ms, int *rebuffer_ms); int _mmplayer_set_codec_type(MMHandleType hplayer, mmplayer_stream_type_e stream_type, mmplayer_codec_type_e codec_type); int _mmplayer_set_replaygain_enabled(MMHandleType hplayer, bool enabled); diff --git a/src/include/mm_player_tracks.h b/src/include/mm_player_tracks.h index 9bdb259..4a64b90 100644 --- a/src/include/mm_player_tracks.h +++ b/src/include/mm_player_tracks.h @@ -29,7 +29,8 @@ extern "C" { #endif -#define DEFAULT_TRACK 0 +#define DEFAULT_TRACK_INDEX 0 +#define INVALID_TRACK_INDEX -1 void _mmplayer_track_initialize(mmplayer_t *player); diff --git a/src/mm_player.c b/src/mm_player.c index 0049f75..e572e20 100644 --- a/src/mm_player.c +++ b/src/mm_player.c @@ -1010,22 +1010,6 @@ int mm_player_set_audio_only(MMHandleType player, bool audio_only) return result; } -int mm_player_get_audio_only(MMHandleType player, bool *audio_only) -{ - int result = MM_ERROR_NONE; - - MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED); - MMPLAYER_RETURN_VAL_IF_FAIL(audio_only, MM_ERROR_INVALID_ARGUMENT); - - MMPLAYER_CMD_LOCK(player); - - result = _mmplayer_get_audio_only(player, audio_only); - - MMPLAYER_CMD_UNLOCK(player); - - return result; -} - int mm_player_360_is_content_spherical(MMHandleType player, bool *is_spherical) { int result = MM_ERROR_NONE; diff --git a/src/mm_player_attrs.c b/src/mm_player_attrs.c index fbf5c9b..3e83de5 100644 --- a/src/mm_player_attrs.c +++ b/src/mm_player_attrs.c @@ -1178,6 +1178,17 @@ MMHandleType _mmplayer_construct_attribute(MMHandleType handle) {.count = 0}, NULL, }, + { + MMPLAYER_ATTRS_AUDIO_ONLY, + (char *)"audio_only", /* MM_PLAYER_AUDIO_ONLY */ + MM_ATTRS_TYPE_INT, + MM_ATTRS_FLAG_RW, + {(void *)FALSE}, + MM_ATTRS_VALID_TYPE_INT_RANGE, + {.int_min = FALSE}, + {.int_max = TRUE}, + NULL, + }, }; MMPLAYER_RETURN_VAL_IF_FAIL(handle, 0); diff --git a/src/mm_player_priv.c b/src/mm_player_priv.c index 8396f5f..c90a9e0 100644 --- a/src/mm_player_priv.c +++ b/src/mm_player_priv.c @@ -196,6 +196,7 @@ static gboolean __mmplayer_swcodec_set_bo(mmplayer_t *player, mmplayer_video_dec static void __mmplayer_set_pause_state(mmplayer_t *player); static void __mmplayer_set_playing_state(mmplayer_t *player); +static int __mmplayer_switch_stream(mmplayer_t *player, mmplayer_track_type_e type, int index); /*=========================================================================================== | | | FUNCTION DEFINITIONS | @@ -1465,10 +1466,10 @@ __mmplayer_set_decode_track_info(mmplayer_t *player, mmplayer_track_type_e type) /* change track to active pad */ active_index = player->track[type].active_track_index; - if ((active_index != DEFAULT_TRACK) && + if ((active_index != DEFAULT_TRACK_INDEX) && (__mmplayer_change_selector_pad(player, type, active_index) != MM_ERROR_NONE)) { LOGW("failed to change %d type track to %d", type, active_index); - player->track[type].active_track_index = DEFAULT_TRACK; + player->track[type].active_track_index = DEFAULT_TRACK_INDEX; return; } @@ -2127,14 +2128,11 @@ _mmplayer_update_video_overlay_param(mmplayer_t *player, const char *param_name) return MM_ERROR_NONE; } -int -_mmplayer_set_audio_only(MMHandleType hplayer, bool audio_only) +static int __mmplayer_set_disable_overlay_option(mmplayer_t *player, bool disable) { gboolean disable_overlay = FALSE; - mmplayer_t *player = (mmplayer_t *)hplayer; MMPLAYER_FENTER(); - MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED); MMPLAYER_RETURN_VAL_IF_FAIL(player->pipeline->videobin && player->pipeline->videobin[MMPLAYER_V_SINK].gst, MM_ERROR_PLAYER_NO_OP); /* invalid op */ @@ -2146,24 +2144,24 @@ _mmplayer_set_audio_only(MMHandleType hplayer, bool audio_only) g_object_get(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "disable-overlay", &disable_overlay, NULL); - if (audio_only == (bool)disable_overlay) { - LOGE("It's the same with current setting: (%d)", audio_only); + if (disable == (bool)disable_overlay) { + LOGE("It's the same with current setting: (%d)", disable); return MM_ERROR_NONE; } - if (audio_only) { + if (disable) { LOGE("disable overlay"); g_object_set(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "disable-overlay", TRUE, NULL); /* release overlay resource */ if (__mmplayer_release_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE) { LOGE("failed to release overlay resource"); - goto ERROR; + return MM_ERROR_PLAYER_INTERNAL; } } else { if (_mmplayer_acquire_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY) != MM_ERROR_NONE) { LOGE("failed to acquire video overlay resource"); - goto ERROR; + return MM_ERROR_PLAYER_INTERNAL; } player->interrupted_by_resource = FALSE; @@ -2172,39 +2170,46 @@ _mmplayer_set_audio_only(MMHandleType hplayer, bool audio_only) g_object_set(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "disable-overlay", FALSE, NULL); } -ERROR: MMPLAYER_FLEAVE(); return MM_ERROR_NONE; } int -_mmplayer_get_audio_only(MMHandleType hplayer, bool *paudio_only) +_mmplayer_set_audio_only(MMHandleType hplayer, bool audio_only) { + int ret = MM_ERROR_NONE; mmplayer_t *player = (mmplayer_t *)hplayer; - gboolean disable_overlay = FALSE; MMPLAYER_FENTER(); - MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED); - MMPLAYER_RETURN_VAL_IF_FAIL(paudio_only, MM_ERROR_INVALID_ARGUMENT); - MMPLAYER_RETURN_VAL_IF_FAIL(player->pipeline->videobin && - player->pipeline->videobin[MMPLAYER_V_SINK].gst, - MM_ERROR_PLAYER_NO_OP); /* invalid op */ - if (!g_object_class_find_property(G_OBJECT_GET_CLASS(player->pipeline->videobin[MMPLAYER_V_SINK].gst), "disable-overlay")) { - LOGW("Display control is not supported"); - return MM_ERROR_PLAYER_INTERNAL; + if (MMPLAYER_USE_DECODEBIN(player)) { + ret = __mmplayer_set_disable_overlay_option(player, audio_only); + goto EXIT; } - g_object_get(player->pipeline->videobin[MMPLAYER_V_SINK].gst, "disable-overlay", &disable_overlay, NULL); + if (audio_only) { + MMPLAYER_RETURN_VAL_IF_FAIL(player->pipeline->videobin && + player->pipeline->videobin[MMPLAYER_V_SINK].gst, + MM_ERROR_PLAYER_NO_OP); /* invalid op */ - *paudio_only = (bool)disable_overlay; + __mmplayer_switch_stream(player, MM_PLAYER_TRACK_TYPE_VIDEO, INVALID_TRACK_INDEX); - LOGD("audio_only : %d", *paudio_only); + /* release decoder resource */ + if (__mmplayer_release_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_DECODER) != MM_ERROR_NONE) { + LOGE("failed to release video decoder resources"); + return MM_ERROR_PLAYER_INTERNAL; + } + player->can_support_codec &= ~FOUND_PLUGIN_VIDEO; + } else { + __mmplayer_switch_stream(player, MM_PLAYER_TRACK_TYPE_VIDEO, DEFAULT_TRACK_INDEX); + } - MMPLAYER_FLEAVE(); +EXIT: + mm_player_set_attribute(hplayer, NULL, MM_PLAYER_AUDIO_ONLY, (int)audio_only, (char *)NULL); - return MM_ERROR_NONE; + MMPLAYER_FLEAVE(); + return ret; } int @@ -7464,27 +7469,61 @@ DONE: } void -_mmplayer_gst_decode_pad_removed(GstElement *elem, GstPad *new_pad, +_mmplayer_gst_decode_pad_removed(GstElement *elem, GstPad *pad, gpointer data) { - //mmplayer_t *player = (mmplayer_t *)data; - GstCaps *caps = NULL; + int ret = MM_ERROR_NONE; + mmplayer_t *player = (mmplayer_t *)data; + mmplayer_gst_element_t *mainbin = player->pipeline->mainbin; + mmplayer_gst_element_t *videobin = player->pipeline->videobin; + gint timeout = MMPLAYER_STATE_CHANGE_TIMEOUT(player); - LOGD("[Decodebin2] pad-removed signal"); + MMPLAYER_FENTER(); + MMPLAYER_RETURN_IF_FAIL(player && player->pipeline && mainbin); - caps = gst_pad_query_caps(new_pad, NULL); - if (!caps) { - LOGW("query caps is NULL"); + LOGD("decoded pad %s:%s removed", GST_DEBUG_PAD_NAME(pad)); + + if (MMPLAYER_USE_DECODEBIN(player)) + return; + + if (!videobin || !g_str_has_prefix (GST_PAD_NAME (pad), "video")) + return; + + ret = _mmplayer_gst_set_state(player, mainbin[MMPLAYER_M_V_CONCAT].gst, GST_STATE_NULL, FALSE, timeout); + if (ret != MM_ERROR_NONE) { + LOGE("fail to change state to NULL"); return; } - gchar *caps_str = NULL; - caps_str = gst_caps_to_string(caps); + ret = _mmplayer_gst_set_state(player, videobin[MMPLAYER_V_BIN].gst, GST_STATE_NULL, FALSE, timeout); + if (ret != MM_ERROR_NONE) { + LOGE("fail to change state to NULL"); + return; + } - LOGD("pad removed caps : %s from %s", caps_str, GST_ELEMENT_NAME(elem)); + if (!gst_bin_remove(GST_BIN_CAST(mainbin[MMPLAYER_M_PIPE].gst), mainbin[MMPLAYER_M_V_CONCAT].gst)) { + LOGE("failed to remove video concat"); + } - MMPLAYER_FREEIF(caps_str); - gst_caps_unref(caps); + if (!gst_bin_remove(GST_BIN_CAST(mainbin[MMPLAYER_M_PIPE].gst), videobin[MMPLAYER_V_BIN].gst)) { + LOGE("failed to remove videobin"); + } + + gst_object_unref(GST_OBJECT(mainbin[MMPLAYER_M_V_CONCAT].gst)); + mainbin[MMPLAYER_M_V_CONCAT].gst = NULL; + mainbin[MMPLAYER_M_V_CONCAT].id = 0; + + gst_object_unref(GST_OBJECT(videobin[MMPLAYER_V_BIN].gst)); + MMPLAYER_FREEIF(player->pipeline->videobin); + + ret = __mmplayer_release_hw_resource(player, MMPLAYER_RESOURCE_TYPE_VIDEO_OVERLAY); + if (ret != MM_ERROR_NONE) + LOGE("failed to release overlay resources"); + + player->videodec_linked = 0; + + MMPLAYER_GENERATE_DOT_IF_ENABLED(player, "pipeline-pad-removed"); + MMPLAYER_FLEAVE(); } void @@ -7784,7 +7823,8 @@ __mmplayer_release_misc_post(mmplayer_t *player) player->audio_stream_changed_cb = NULL; player->audio_stream_changed_cb_user_param = NULL; - mm_player_set_attribute((MMHandleType)player, NULL, "content_video_found", 0, NULL); + mm_player_set_attribute((MMHandleType)player, NULL, + "content_video_found", 0, MM_PLAYER_AUDIO_ONLY, 0, NULL); /* clean found audio decoders */ if (player->audio_decoders) { @@ -8344,16 +8384,19 @@ __mmplayer_switch_stream(mmplayer_t *player, mmplayer_track_type_e type, int ind guint active_idx = 0; GstStream *stream = NULL; GList *streams = NULL; - GstEvent *ev = NULL; GstCaps *caps = NULL; + MMPLAYER_FENTER(); LOGD("Switching Streams... type: %d, index: %d", type, index); player->track[type].active_track_index = index; for (int i = 0; i < MM_PLAYER_TRACK_TYPE_MAX; i++) { /* FIXME: need to consider the non display type or audio only in case of MM_PLAYER_TRACK_TYPE_VIDEO */ - if (player->track[i].total_track_num > 0) { + LOGD("track type:%d, total: %d, active: %d", i, + player->track[i].total_track_num, player->track[i].active_track_index); + if (player->track[i].total_track_num > 0 && + player->track[i].active_track_index > INVALID_TRACK_INDEX) { active_idx = player->track[i].active_track_index; stream = g_ptr_array_index(player->track[i].streams, active_idx); streams = g_list_append (streams, (gchar *)gst_stream_get_stream_id(stream)); @@ -8369,10 +8412,14 @@ __mmplayer_switch_stream(mmplayer_t *player, mmplayer_track_type_e type, int ind } } - ev = gst_event_new_select_streams(streams); - gst_element_send_event(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, ev); - g_list_free(streams); + if (streams) { + LOGD("send select stream event"); + gst_element_send_event(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, + gst_event_new_select_streams(streams)); + g_list_free(streams); + } + MMPLAYER_FLEAVE(); return MM_ERROR_NONE; } diff --git a/src/mm_player_tracks.c b/src/mm_player_tracks.c index d685e1b..f4c761d 100644 --- a/src/mm_player_tracks.c +++ b/src/mm_player_tracks.c @@ -25,7 +25,6 @@ #include "mm_player_tracks.h" #include "mm_player_attrs.h" -#define INVALID_TRACK_INDEX -1 #define LANGUAGE_CODE_SIZE (3 + 1) /* Size of ISO-639-1, and considering the nul-terminator */ /*--------------------------------------------------------------------------------------- -- 2.7.4