[0.6.283] Fix the problem that not play until the end in gapless mode
[platform/core/multimedia/libmm-player.git] / src / mm_player_priv.c
index 71c03d7..2b7bd0a 100644 (file)
@@ -917,7 +917,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 +986,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 +1005,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 +1219,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 +1234,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 +1258,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 +1282,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 +1429,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;
@@ -6521,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;
 }
@@ -6579,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);
 
@@ -6593,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 */
@@ -7650,15 +7690,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();
 }