[0.6.134] check elem state before read caps 88/190488/2
authorEunhae Choi <eunhae1.choi@samsung.com>
Tue, 2 Oct 2018 11:22:36 +0000 (20:22 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Tue, 2 Oct 2018 12:08:27 +0000 (21:08 +0900)
- fix crash issue
- do not access the video caps before finishing the autoplugging
  which is changed(unref and created) if video is detected.

Change-Id: Ib1ce8d66147f72bd9f61c81d5034c13074d1e27d

src/mm_player_es.c

index e6d6a1b..7df51cd 100644 (file)
@@ -160,24 +160,33 @@ __mmplayer_update_video_info(MMHandleType hplayer, media_format_h fmt)
 
        MMPLAYER_FENTER();
 
-       MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
+       MMPLAYER_RETURN_VAL_IF_FAIL(player && player->v_stream_caps, FALSE);
        MMPLAYER_RETURN_VAL_IF_FAIL(fmt, FALSE);
 
-       if (player->v_stream_caps) {
-               str = gst_caps_get_structure(player->v_stream_caps, 0);
-               if (!gst_structure_get_int(str, "width", &cur_width))
-                       LOGD("missing 'width' field in video caps");
-
-               if (!gst_structure_get_int(str, "height", &cur_height))
-                       LOGD("missing 'height' field in video caps");
-
-               media_format_get_video_info(fmt, &mimetype, &width, &height, NULL, NULL);
-               if ((cur_width != width) || (cur_height != height)) {
-                       LOGW("resolution is changed %dx%d -> %dx%d",
-                               cur_width, cur_height, width, height);
-                       _mmplayer_set_video_info(hplayer, fmt);
-                       ret = TRUE;
-               }
+       if (MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PAUSED &&
+               MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PLAYING) {
+               LOGW("skip update video info, state: %s", MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)));
+               return FALSE;
+       }
+
+       str = gst_caps_get_structure(player->v_stream_caps, 0);
+       if (!str) {
+               LOGE("failed to get caps info");
+               return FALSE;
+       }
+
+       if (!gst_structure_get_int(str, "width", &cur_width))
+               LOGD("missing 'width' field in video caps");
+
+       if (!gst_structure_get_int(str, "height", &cur_height))
+               LOGD("missing 'height' field in video caps");
+
+       media_format_get_video_info(fmt, &mimetype, &width, &height, NULL, NULL);
+       if ((cur_width != width) || (cur_height != height)) {
+               LOGW("resolution is changed %dx%d -> %dx%d",
+                       cur_width, cur_height, width, height);
+               _mmplayer_set_video_info(hplayer, fmt);
+               ret = TRUE;
        }
 
        MMPLAYER_FLEAVE();
@@ -500,6 +509,19 @@ _mmplayer_submit_packet(MMHandleType hplayer, media_packet_h packet)
                        gst_buffer_unmap(_buffer, &buff_info);
                }
 
+               /* wait till the pipeline is ready to get data, if not some data is missed */
+               while ((GST_STATE(element) < GST_STATE_PAUSED) && (wait_cnt < PLAYER_DATA_PUSH_WAIT_COUNT)) {
+                       LOGW("wait to update source state : %d, %d", player->state, GST_STATE(element));
+                       usleep(PLAYER_STATE_CHECK_INTERVAL);
+                       wait_cnt++;
+               }
+
+               if (wait_cnt == PLAYER_DATA_PUSH_WAIT_COUNT) {
+                       LOGE("source is not ready %d", GST_STATE(element));
+                       ret = MM_ERROR_PLAYER_INTERNAL;
+                       goto ERROR;
+               }
+
                if (streamtype == MM_PLAYER_STREAM_TYPE_VIDEO) {
                        /* get format to check video format */
                        media_packet_get_format(packet, &fmt);
@@ -532,18 +554,6 @@ _mmplayer_submit_packet(MMHandleType hplayer, media_packet_h packet)
                }
                GST_BUFFER_PTS(_buffer) = (GstClockTime)pts;
 
-               while ((GST_STATE(element) < GST_STATE_PAUSED) && (wait_cnt < PLAYER_DATA_PUSH_WAIT_COUNT)) {
-                       LOGW("wait to update source state : %d, %d", player->state, GST_STATE(element));
-                       usleep(PLAYER_STATE_CHECK_INTERVAL);
-                       wait_cnt++;
-               }
-
-               if (wait_cnt == PLAYER_DATA_PUSH_WAIT_COUNT) {
-                       LOGE("source is not ready %d", GST_STATE(element));
-                       ret = MM_ERROR_PLAYER_INTERNAL;
-                       goto ERROR;
-               }
-
                if (MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PLAYING) {
                        /* the pushed pts should be lager than current position if it is not in playing state. */
                        LOGD("type:%s, curr pos: %"G_GINT64_FORMAT", pushed pts:%"G_GINT64_FORMAT", size:%"G_GUINT64_FORMAT,