[0.6.289] Fix not-linked error during prepare
[platform/core/multimedia/libmm-player.git] / src / mm_player_priv.c
index 64aa9b9..1004e50 100644 (file)
 #define DEFAULT_PCM_OUT_SAMPLERATE     44100
 #define DEFAULT_PCM_OUT_CHANNEL        2
 
+#define MQ_UNLINKED_CACHE_TIME         (500 * GST_MSECOND)
+
 /*---------------------------------------------------------------------------
 |    LOCAL CONSTANT DEFINITIONS:                                                                                       |
 ---------------------------------------------------------------------------*/
@@ -917,7 +919,7 @@ ERROR:
 }
 
 static GstPadProbeReturn
-__mmplayer_gst_selector_blocked(GstPad *pad, GstPadProbeInfo *info, gpointer data)
+__mmplayer_gst_combiner_blocked(GstPad *pad, GstPadProbeInfo *info, gpointer data)
 {
        LOGD("pad(%s:%s) is blocked", GST_DEBUG_PAD_NAME(pad));
        return GST_PAD_PROBE_OK;
@@ -986,7 +988,7 @@ __mmplayer_gst_selector_update_start_time(mmplayer_t *player, mmplayer_track_typ
 }
 
 static GstPadProbeReturn
-__mmplayer_gst_selector_event_probe(GstPad *pad, GstPadProbeInfo *info, gpointer data)
+__mmplayer_gst_combiner_event_probe(GstPad *pad, GstPadProbeInfo *info, gpointer data)
 {
        GstPadProbeReturn ret = GST_PAD_PROBE_OK;
        GstEvent *event = GST_PAD_PROBE_INFO_DATA(info);
@@ -1005,7 +1007,23 @@ __mmplayer_gst_selector_event_probe(GstPad *pad, GstPadProbeInfo *info, gpointer
                return ret;
 
        MMPLAYER_GST_GET_CAPS_INFO_FROM_PAD(pad, caps, str, name, caps_ret);
-       if (!caps_ret)
+       if (!caps_ret) {
+               GstStream *stream = NULL;
+
+               if (GST_EVENT_TYPE(event) != GST_EVENT_STREAM_START)
+                       goto ERROR;
+
+               gst_event_parse_stream (event, &stream);
+               if (stream == NULL) {
+                       LOGW ("Got a STREAM_START event without a GstStream");
+                       goto ERROR;
+               }
+
+               name = gst_stream_type_get_name(gst_stream_get_stream_type(stream));
+               gst_object_unref (stream);
+       }
+
+       if (!name)
                goto ERROR;
 
        if (strstr(name, "audio")) {
@@ -1203,10 +1221,11 @@ ERROR:
 }
 
 static GstElement *
-__mmplayer_gst_make_concat(mmplayer_t *player, main_element_id_e elem_idx)
+__mmplayer_gst_make_concat(mmplayer_t *player, main_element_id_e elem_idx, mmplayer_track_type_e stream_type)
 {
        GstElement *pipeline = NULL;
-       GstElement *concat = NULL;
+       g_autoptr(GstElement) concat = NULL;
+       g_autoptr(GstPad) srcpad = NULL;
 
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline && player->pipeline->mainbin, NULL);
@@ -1217,13 +1236,21 @@ __mmplayer_gst_make_concat(mmplayer_t *player, main_element_id_e elem_idx)
                return NULL;
        }
 
+       srcpad = gst_element_get_static_pad(concat, "src");
+
+       LOGD("blocking %s:%s", GST_DEBUG_PAD_NAME(srcpad));
+       player->track[stream_type].block_id = gst_pad_add_probe(srcpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
+                       __mmplayer_gst_combiner_blocked, NULL, NULL);
+       player->track[stream_type].event_probe_id = gst_pad_add_probe(srcpad, GST_PAD_PROBE_TYPE_EVENT_BOTH|GST_PAD_PROBE_TYPE_EVENT_FLUSH,
+                       __mmplayer_gst_combiner_event_probe, player, NULL);
+
+
        gst_element_set_state(concat, GST_STATE_PAUSED);
 
        pipeline = player->pipeline->mainbin[MMPLAYER_M_PIPE].gst;
        if (!gst_bin_add(GST_BIN(pipeline), concat)) {
                LOGE("failed to add concat to pipeline");
                gst_element_set_state(concat, GST_STATE_NULL);
-               gst_object_unref(GST_OBJECT(concat));
                return NULL;
        }
 
@@ -1233,7 +1260,7 @@ __mmplayer_gst_make_concat(mmplayer_t *player, main_element_id_e elem_idx)
        player->pipeline->mainbin[elem_idx].gst = concat;
 
        MMPLAYER_FLEAVE();
-       return concat;
+       return g_steal_pointer(&concat);
 }
 
 static GstElement *
@@ -1257,9 +1284,9 @@ __mmplayer_gst_make_selector(mmplayer_t *player, main_element_id_e elem_idx, mmp
 
        LOGD("blocking %s:%s", GST_DEBUG_PAD_NAME(srcpad));
        player->track[stream_type].block_id = gst_pad_add_probe(srcpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
-               __mmplayer_gst_selector_blocked, NULL, NULL);
+               __mmplayer_gst_combiner_blocked, NULL, NULL);
        player->track[stream_type].event_probe_id = gst_pad_add_probe(srcpad, GST_PAD_PROBE_TYPE_EVENT_BOTH|GST_PAD_PROBE_TYPE_EVENT_FLUSH,
-               __mmplayer_gst_selector_event_probe, player, NULL);
+               __mmplayer_gst_combiner_event_probe, player, NULL);
 
        gst_element_set_state(selector, GST_STATE_PAUSED);
 
@@ -1404,7 +1431,7 @@ _mmplayer_gst_decode_pad_added(GstElement *elem, GstPad *pad, gpointer data)
                if (MMPLAYER_USE_DECODEBIN(player))
                        combiner = __mmplayer_gst_make_selector(player, elem_idx, stream_type);
                else
-                       combiner = __mmplayer_gst_make_concat(player, elem_idx);
+                       combiner = __mmplayer_gst_make_concat(player, elem_idx, stream_type);
 
                if (!combiner)
                        goto ERROR;
@@ -4418,7 +4445,7 @@ __mmplayer_gst_destroy_pipeline(mmplayer_t *player)
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_INVALID_HANDLE);
 
        /* cleanup stuffs */
-       MMPLAYER_FREEIF(player->type);
+       MMPLAYER_FREEIF(player->type_caps_str);
        player->no_more_pad = FALSE;
        player->num_dynamic_pad = 0;
 
@@ -4485,11 +4512,6 @@ __mmplayer_gst_destroy_pipeline(mmplayer_t *player)
        }
        MMPLAYER_FREEIF(player->album_art);
 
-       if (player->type_caps) {
-               gst_caps_unref(player->type_caps);
-               player->type_caps = NULL;
-       }
-
        if (player->v_stream_caps) {
                gst_caps_unref(player->v_stream_caps);
                player->v_stream_caps = NULL;
@@ -5919,7 +5941,7 @@ _mmplayer_get_duration(MMHandleType hplayer, gint64 *duration)
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
        MMPLAYER_RETURN_VAL_IF_FAIL(duration, MM_ERROR_COMMON_INVALID_ARGUMENT);
 
-       if (g_strrstr(player->type, "video/mpegts"))
+       if (g_strrstr(player->type_caps_str, "video/mpegts"))
                __mmplayer_update_duration_value(player);
 
        *duration = player->duration;
@@ -6009,9 +6031,9 @@ static void
 __mmplayer_update_content_type_info(mmplayer_t *player)
 {
        MMPLAYER_FENTER();
-       MMPLAYER_RETURN_IF_FAIL(player && player->type);
+       MMPLAYER_RETURN_IF_FAIL(player && player->type_caps_str);
 
-       if (__mmplayer_is_midi_type(player->type)) {
+       if (__mmplayer_is_midi_type(player->type_caps_str)) {
                player->bypass_audio_effect = TRUE;
                return;
        }
@@ -6021,19 +6043,19 @@ __mmplayer_update_content_type_info(mmplayer_t *player)
                return;
        }
 
-       if (g_strrstr(player->type, "application/x-hls")) {
+       if (g_strrstr(player->type_caps_str, "application/x-hls")) {
                /* If it can't know exact type when it parses uri because of redirection case,
                 * it will be fixed by typefinder or when doing autoplugging.
                 */
                player->profile.uri_type = MM_PLAYER_URI_TYPE_HLS;
                player->streamer->is_adaptive_streaming = TRUE;
-       } else if (g_strrstr(player->type, "application/dash+xml")) {
+       } else if (g_strrstr(player->type_caps_str, "application/dash+xml")) {
                player->profile.uri_type = MM_PLAYER_URI_TYPE_DASH;
                player->streamer->is_adaptive_streaming = TRUE;
        }
 
        /* in case of TS, fixed buffering mode should be used because player can not get exact duration time */
-       if ((player->streamer->is_adaptive_streaming) || (g_strrstr(player->type, "video/mpegts"))) {
+       if ((player->streamer->is_adaptive_streaming) || (g_strrstr(player->type_caps_str, "video/mpegts"))) {
                player->streamer->buffering_req.mode = MM_PLAYER_BUFFERING_MODE_FIXED;
 
                if (player->streamer->buffering_req.rebuffer_time <= MIN_BUFFERING_TIME) { /* if user did not set the rebuffer value */
@@ -6058,23 +6080,13 @@ _mmplayer_typefind_have_type(GstElement *tf, guint probability,
 
        MMPLAYER_RETURN_IF_FAIL(player && tf && caps);
 
-       /* store type string */
-       if (player->type_caps) {
-               gst_caps_unref(player->type_caps);
-               player->type_caps = NULL;
-       }
-
-       player->type_caps = gst_caps_copy(caps);
-       MMPLAYER_LOG_GST_CAPS_TYPE(player->type_caps);
-
-       MMPLAYER_FREEIF(player->type);
-       player->type = gst_caps_to_string(caps);
-       if (player->type)
-               LOGD("[handle: %p] media type %s found, probability %d%% / %d",
-                               player, player->type, probability, gst_caps_get_size(caps));
+       MMPLAYER_FREEIF(player->type_caps_str);
+       player->type_caps_str = gst_caps_to_string(caps);
+       LOGD("[handle: %p] media type %s found, probability %d%% / %d",
+                       player, player->type_caps_str, probability, gst_caps_get_size(caps));
 
        if ((!MMPLAYER_IS_RTSP_STREAMING(player)) &&
-               (g_strrstr(player->type, "audio/x-raw-int"))) {
+               (g_strrstr(player->type_caps_str, "audio/x-raw-int"))) {
                LOGE("not support media format");
 
                if (player->msg_posted == FALSE) {
@@ -6103,7 +6115,7 @@ _mmplayer_typefind_have_type(GstElement *tf, guint probability,
 
                if (!_mmplayer_gst_create_decoder(player, pad, caps)) {
                        gboolean async = FALSE;
-                       LOGE("failed to autoplug %s", player->type);
+                       LOGE("failed to autoplug %s", player->type_caps_str);
 
                        mm_attrs_get_int_by_name(player->attrs, "profile_prepare_async", &async);
 
@@ -6200,7 +6212,7 @@ __mmplayer_gst_make_queue2(mmplayer_t *player)
        /* NOTE : in case of ts streaming, player could not get the correct duration info *
         *                skip the pull mode(file or ring buffering) setting. */
        if (dur_bytes > 0) {
-               if (!g_strrstr(player->type, "video/mpegts")) {
+               if (!g_strrstr(player->type_caps_str, "video/mpegts")) {
                        type = MUXED_BUFFER_TYPE_MEM_RING_BUFFER;
                        player->streamer->ring_buffer_size = player->ini.http_ring_buffer_size;
                }
@@ -6534,6 +6546,12 @@ __mmplayer_get_next_uri(mmplayer_t *player)
                return FALSE;
        }
 
+       if (!MMPLAYER_USE_DECODEBIN(player)) {
+               if (player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst)
+                       g_object_set(G_OBJECT(player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst),
+                               "uri", profile.uri, NULL);
+       }
+
        SECURE_LOGD("next playback uri: %s", uri);
        return TRUE;
 }
@@ -6592,6 +6610,8 @@ __mmplayer_verify_gapless_play_path(mmplayer_t *player)
        }
 
        num_of_uri = g_list_length(player->uri_info.uri_list);
+       if (!MMPLAYER_USE_DECODEBIN(player))
+               player->gapless.running = TRUE;
 
        LOGD("repeat count = %d, num_of_list = %d", count, num_of_uri);
 
@@ -6606,6 +6626,13 @@ __mmplayer_verify_gapless_play_path(mmplayer_t *player)
                        LOGD("there is no next uri and no repeat");
                        goto ERROR;
                }
+
+               if (!MMPLAYER_USE_DECODEBIN(player)) {
+                       if (player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst)
+                               g_object_set(G_OBJECT(player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst),
+                                       "uri", player->profile.uri, NULL);
+               }
+
                LOGD("looping cnt %d", count);
        } else {
                /* gapless playback path */
@@ -7202,7 +7229,7 @@ __mmplayer_is_offload_supported_type(mmplayer_t *player)
           this function need to be updated according to the supported media format
           @see player->ini.audio_offload_media_format */
 
-       if (__mmplayer_is_only_mp3_type(player->type)) {
+       if (__mmplayer_is_only_mp3_type(player->type_caps_str)) {
                LOGD("offload supportable media format type");
                return TRUE;
        }
@@ -7219,7 +7246,7 @@ __mmplayer_can_build_audio_offload_path(mmplayer_t *player)
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_VAL_IF_FAIL(player && player->attrs, FALSE);
 
-       LOGD("current stream : %s, sink: %s", player->type, player->ini.audio_offload_sink_element);
+       LOGD("current stream : %s, sink: %s", player->type_caps_str, player->ini.audio_offload_sink_element);
        if (!__mmplayer_is_offload_supported_type(player))
                goto DONE;
 
@@ -7470,8 +7497,8 @@ _mmplayer_gst_decode_autoplug_select(GstElement *bin,  GstPad *pad,
        LOGD("[handle: %p] found new element [%s] to link", player, factory_name);
 
        /* store type string */
-       if (player->type == NULL) {
-               player->type = gst_caps_to_string(caps);
+       if (player->type_caps_str == NULL) {
+               player->type_caps_str = gst_caps_to_string(caps);
                __mmplayer_update_content_type_info(player);
        }
 
@@ -7540,14 +7567,19 @@ _mmplayer_gst_decode_autoplug_select(GstElement *bin,  GstPad *pad,
                gint stype = 0;
                gint width = 0;
                GstStructure *str = NULL;
-               mm_attrs_get_int_by_name(player->attrs, "display_surface_type", &stype);
 
-               /* don't make video because of not required */
-               if ((stype == MM_DISPLAY_SURFACE_NULL) &&
-                       (!player->set_mode.video_export)) {
-                       LOGD("no need video decoding, expose pad");
-                       result = GST_AUTOPLUG_SELECT_EXPOSE;
-                       goto DONE;
+               /* parsebin in adaptivedemux get error if there is no parser */
+               if ((!g_strrstr(GST_ELEMENT_NAME(bin), "parsebin")) ||
+                       ((!MMPLAYER_IS_HTTP_LIVE_STREAMING(player)) && (!MMPLAYER_IS_DASH_STREAMING(player)))) {
+                       mm_attrs_get_int_by_name(player->attrs, "display_surface_type", &stype);
+
+                       /* don't make video because of not required */
+                       if ((stype == MM_DISPLAY_SURFACE_NULL) &&
+                               (!player->set_mode.video_export)) {
+                               LOGD("no need video decoding, expose pad");
+                               result = GST_AUTOPLUG_SELECT_EXPOSE;
+                               goto DONE;
+                       }
                }
 
                /* get w/h for omx state-tune */
@@ -7663,15 +7695,22 @@ _mmplayer_gst_about_to_finish(GstElement *bin, gpointer data)
 
        if (!__mmplayer_verify_gapless_play_path(player)) {
                LOGD("decoding is finished.");
-               MMPLAYER_CMD_UNLOCK(player);
-               return;
+               if (MMPLAYER_USE_DECODEBIN(player)) {
+                       MMPLAYER_CMD_UNLOCK(player);
+                       return;
+               }
        }
 
-       _mmplayer_set_reconfigure_state(player, TRUE);
-       MMPLAYER_CMD_UNLOCK(player);
-
-       MMPLAYER_POST_MSG(player, MM_MESSAGE_FLUSH_BUFFER, NULL);
-       __mmplayer_deactivate_old_path(player);
+       if (MMPLAYER_USE_DECODEBIN(player)) {
+               _mmplayer_set_reconfigure_state(player, TRUE);
+               MMPLAYER_CMD_UNLOCK(player);
+               MMPLAYER_POST_MSG(player, MM_MESSAGE_FLUSH_BUFFER, NULL);
+               __mmplayer_deactivate_old_path(player);
+       } else {
+               player->gapless.update_segment[MM_PLAYER_TRACK_TYPE_AUDIO] = FALSE;
+               player->gapless.update_segment[MM_PLAYER_TRACK_TYPE_VIDEO] = FALSE;
+               MMPLAYER_CMD_UNLOCK(player);
+       }
 
        MMPLAYER_FLEAVE();
 }
@@ -7805,13 +7844,13 @@ _mmplayer_gst_element_added(GstBin *bin, GstElement *element, gpointer data)
                        player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].id = MMPLAYER_M_ADAPTIVE_DEMUX;
                        player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].gst = element;
 
-                       MMPLAYER_FREEIF(player->type);
+                       MMPLAYER_FREEIF(player->type_caps_str);
 
                        if (g_strrstr(factory_name, "hlsdemux")) {
-                               player->type = g_strdup("application/x-hls");
+                               player->type_caps_str = g_strdup("application/x-hls");
                                player->profile.uri_type = MM_PLAYER_URI_TYPE_HLS;
                        } else if (g_strrstr(factory_name, "dashdemux")) {
-                               player->type = g_strdup("application/dash+xml");
+                               player->type_caps_str = g_strdup("application/dash+xml");
                                player->profile.uri_type = MM_PLAYER_URI_TYPE_DASH;
                        } else {
                                LOGE("not supported type");
@@ -7829,7 +7868,7 @@ _mmplayer_gst_element_added(GstBin *bin, GstElement *element, gpointer data)
                                player->streamer->buffering_req.prebuffer_time);
 
                        g_object_set(player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].gst,
-                               "max-bandwidth", player->adaptive_info.limit.bandwidth,
+                               "max-bitrate", player->adaptive_info.limit.bandwidth,
                                "max-video-width", player->adaptive_info.limit.width,
                                "max-video-height", player->adaptive_info.limit.height,
                                "low-watermark-time", (guint64)(player->streamer->buffering_req.prebuffer_time * GST_MSECOND),
@@ -7848,14 +7887,21 @@ _mmplayer_gst_element_added(GstBin *bin, GstElement *element, gpointer data)
 
        if (g_strrstr(factory_name, "mpegaudioparse")) {
                if ((MMPLAYER_IS_HTTP_STREAMING(player)) &&
-                       (__mmplayer_is_only_mp3_type(player->type))) {
+                       (__mmplayer_is_only_mp3_type(player->type_caps_str))) {
                        LOGD("[mpegaudioparse] set streaming pull mode.");
                        g_object_set(G_OBJECT(element), "http-pull-mp3dec", TRUE, NULL);
                }
        } else if ((player->pipeline->mainbin[MMPLAYER_M_DEMUX].gst) &&
                (g_strrstr(GST_ELEMENT_NAME(element), "multiqueue"))) {
+
                LOGD("plugged element is multiqueue. take it %s", GST_ELEMENT_NAME(element));
 
+               /* set mq unlinked cache size to avoid not-linked error */
+               gboolean sync_by_running_time = FALSE;
+               g_object_get(G_OBJECT(element), "sync-by-running-time", &sync_by_running_time, NULL);
+               if (sync_by_running_time)
+                       g_object_set(G_OBJECT(element), "unlinked-cache-time", MQ_UNLINKED_CACHE_TIME, NULL);
+
                player->pipeline->mainbin[MMPLAYER_M_DEMUXED_S_BUFFER].id = MMPLAYER_M_DEMUXED_S_BUFFER;
                player->pipeline->mainbin[MMPLAYER_M_DEMUXED_S_BUFFER].gst = element;
 
@@ -8693,6 +8739,7 @@ _mmplayer_change_track_language(MMHandleType hplayer, mmplayer_track_type_e type
 
        player = (mmplayer_t *)hplayer;
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_RETURN_VAL_IF_FAIL(type < MM_PLAYER_TRACK_TYPE_MAX, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        if (!player->pipeline) {
                LOGE("Track %d pre setting -> %d", type, index);
@@ -9035,7 +9082,7 @@ _mmplayer_set_max_adaptive_variant_limit(MMHandleType hplayer, int bandwidth, in
        if (player->pipeline && player->pipeline->mainbin && player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].gst) {
                LOGD("update max limit of %s", GST_ELEMENT_NAME(player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].gst));
                g_object_set(player->pipeline->mainbin[MMPLAYER_M_ADAPTIVE_DEMUX].gst,
-                                               "max-bandwidth", bandwidth, "max-video-width", width, "max-video-height", height, NULL);
+                                               "max-bitrate", bandwidth, "max-video-width", width, "max-video-height", height, NULL);
 
                /* FIXME: seek to current position for applying new variant limitation */
        }
@@ -9943,12 +9990,12 @@ __mmplayer_set_playing_state(mmplayer_t *player)
         * So, if it's not set yet, fill it with found data.
         */
        if (!audio_codec) {
-               if (g_strrstr(player->type, "audio/midi"))
+               if (g_strrstr(player->type_caps_str, "audio/midi"))
                        audio_codec = "MIDI";
-               else if (g_strrstr(player->type, "audio/x-amr"))
+               else if (g_strrstr(player->type_caps_str, "audio/x-amr"))
                        audio_codec = "AMR";
-               else if (g_strrstr(player->type, "audio/mpeg")
-                               && !g_strrstr(player->type, "mpegversion=(int)1"))
+               else if (g_strrstr(player->type_caps_str, "audio/mpeg")
+                               && !g_strrstr(player->type_caps_str, "mpegversion=(int)1"))
                        audio_codec = "AAC";
                else
                        audio_codec = "unknown";