[0.6.293] Fix Svace/Coverity issues
[platform/core/multimedia/libmm-player.git] / src / mm_player_priv.c
index 2b7bd0a..3689bed 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:                                                                                       |
 ---------------------------------------------------------------------------*/
@@ -1038,10 +1040,12 @@ __mmplayer_gst_combiner_event_probe(GstPad *pad, GstPadProbeInfo *info, gpointer
        case GST_EVENT_EOS:
                {
                        /* in case of gapless, drop eos event not to send it to sink */
+                       MMPLAYER_RECONFIGURE_LOCK(player);
                        if (player->gapless.reconfigure && !player->msg_posted) {
                                LOGD("[%d] %s:%s EOS received but will be drop", stream_type, GST_DEBUG_PAD_NAME(pad));
                                ret = GST_PAD_PROBE_DROP;
                        }
+                       MMPLAYER_RECONFIGURE_UNLOCK(player);
                        break;
                }
        case GST_EVENT_STREAM_START:
@@ -4257,9 +4261,9 @@ __mmplayer_update_subtitle(GstElement *object, GstBuffer *buffer, GstPad *pad, g
                LOGI("subtitle duration is invalid, subtitle duration change "
                        "GST_CLOCK_TIME_NONE -> %" GST_TIME_FORMAT, GST_TIME_ARGS(duration));
        }
-       msg.subtitle.duration = GST_TIME_AS_MSECONDS(duration);
+       msg.subtitle.duration = (unsigned long)GST_TIME_AS_MSECONDS(duration);
 
-       LOGD("update subtitle : [%ld msec] %s", msg.subtitle.duration, (char *)msg.data);
+       LOGD("update subtitle : [%lu msec] %s", msg.subtitle.duration, (char *)msg.data);
 
        MMPLAYER_POST_MSG(player, MM_MESSAGE_UPDATE_SUBTITLE, &msg);
        gst_buffer_unmap(buffer, &mapinfo);
@@ -4277,17 +4281,13 @@ __mmplayer_subtitle_adjust_position_probe(GstPad *pad, GstPadProbeInfo *info, gp
        gint64 adjusted_timestamp = 0;
        GstBuffer *buffer = gst_pad_probe_info_get_buffer(info);
 
-       MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, GST_PAD_PROBE_DROP);
 
-       if (player->set_mode.subtitle_off) {
-               LOGD("subtitle is OFF.");
-               return TRUE;
-       }
+       if (player->set_mode.subtitle_off)
+               return GST_PAD_PROBE_OK;
 
-       if (player->adjust_subtitle_pos == 0) {
-               LOGD("nothing to do");
-               return TRUE;
-       }
+       if (player->adjust_subtitle_pos == 0)
+               return GST_PAD_PROBE_OK;
 
        cur_timestamp = GST_BUFFER_TIMESTAMP(buffer);
        adjusted_timestamp = (gint64)cur_timestamp + ((gint64)player->adjust_subtitle_pos * G_GINT64_CONSTANT(1000000));
@@ -4295,7 +4295,7 @@ __mmplayer_subtitle_adjust_position_probe(GstPad *pad, GstPadProbeInfo *info, gp
        if (adjusted_timestamp < 0) {
                LOGD("adjusted_timestamp under zero");
                MMPLAYER_FLEAVE();
-               return FALSE;
+               return GST_PAD_PROBE_DROP;
        }
 
        GST_BUFFER_TIMESTAMP(buffer) = (GstClockTime) adjusted_timestamp;
@@ -6078,12 +6078,10 @@ _mmplayer_typefind_have_type(GstElement *tf, guint probability,
 
        MMPLAYER_RETURN_IF_FAIL(player && tf && caps);
 
-       MMPLAYER_LOG_GST_CAPS_TYPE(caps);
        MMPLAYER_FREEIF(player->type_caps_str);
        player->type_caps_str = gst_caps_to_string(caps);
-       if (player->type_caps_str)
-               LOGD("[handle: %p] media type %s found, probability %d%% / %d",
-                               player, player->type_caps_str, probability, gst_caps_get_size(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_caps_str, "audio/x-raw-int"))) {
@@ -7567,14 +7565,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 */
@@ -7863,7 +7866,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),
@@ -7888,8 +7891,15 @@ _mmplayer_gst_element_added(GstBin *bin, GstElement *element, gpointer data)
                }
        } 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;
 
@@ -8059,15 +8069,15 @@ __mmplayer_check_subtitle(mmplayer_t *player)
 
        /* get subtitle attribute */
        attrs = MMPLAYER_GET_ATTRS(player);
-       if (!attrs)
-               return FALSE;
+       MMPLAYER_RETURN_VAL_IF_FAIL(attrs, FALSE);
 
        mm_attrs_get_string_by_name(attrs, "subtitle_uri", &subtitle_uri);
-       if (!subtitle_uri || !strlen(subtitle_uri))
+       if (!subtitle_uri || (strlen(subtitle_uri) == 0)) {
+               MMPLAYER_FLEAVE();
                return FALSE;
+       }
 
        SECURE_LOGD("subtitle uri is %s[%zu]", subtitle_uri, strlen(subtitle_uri));
-       player->is_external_subtitle_present = TRUE;
 
        MMPLAYER_FLEAVE();
 
@@ -8346,14 +8356,26 @@ _mmplayer_sync_subtitle_pipeline(mmplayer_t *player)
 
        LOGD("seek time = %"G_GINT64_FORMAT", rate = %f", time, player->playback_rate);
        event = gst_event_new_seek(player->playback_rate, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH), GST_SEEK_TYPE_SET, time, GST_SEEK_TYPE_NONE, -1);
-       if (event) {
-               _mmplayer_gst_send_event_to_sink(player, event);
-       } else {
+       if (!event) {
                result = MM_ERROR_PLAYER_INTERNAL;
                LOGE("gst_event_new_seek failed"); /* pipeline will got error and can not be recovered */
                goto ERROR;
        }
 
+       if (player->seek_state == MMPLAYER_SEEK_IN_PROGRESS) {
+               GstElement *text_sink = GST_ELEMENT_CAST(player->pipeline->textbin[MMPLAYER_T_FAKE_SINK].gst);
+               if (GST_IS_ELEMENT(text_sink)) {
+                       if (gst_element_send_event(text_sink, event))
+                               LOGD("sending event[%s] to subtitle sink element [%s] success!",
+                                               GST_EVENT_TYPE_NAME(event), GST_ELEMENT_NAME(text_sink));
+                       else
+                               LOGE("sending event[%s] to subtitle sink element [%s] failed!",
+                                               GST_EVENT_TYPE_NAME(event), GST_ELEMENT_NAME(text_sink));
+               }
+       } else {
+               _mmplayer_gst_send_event_to_sink(player, event);
+       }
+
        /* sync state with current pipeline */
        gst_element_sync_state_with_parent(textbin[MMPLAYER_T_BIN].gst);
        gst_element_sync_state_with_parent(mainbin[MMPLAYER_M_SUBPARSE].gst);
@@ -8557,6 +8579,7 @@ _mmplayer_set_external_subtitle_path(MMHandleType hplayer, const char *filepath)
                }
                MMPLAYER_SUBTITLE_INFO_UNLOCK(player);
        }
+       player->is_external_subtitle_present = TRUE;
 
        MMPLAYER_FLEAVE();
        return result;
@@ -8727,6 +8750,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);
@@ -9069,7 +9093,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 */
        }