[0.6.114] check source state before pushing data 41/180041/1
authorEunhae Choi <eunhae1.choi@samsung.com>
Thu, 24 May 2018 09:49:47 +0000 (18:49 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Thu, 24 May 2018 09:49:47 +0000 (18:49 +0900)
Change-Id: I7b19e679c0da7e25d03c3a37bc5ae4a0cdbf22d8

packaging/libmm-player.spec
src/mm_player_es.c

index 11e1576..05e2954 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-player
 Summary:    Multimedia Framework Player Library
-Version:    0.6.113
+Version:    0.6.114
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 6e3aee1..dd09bf8 100644 (file)
@@ -38,6 +38,8 @@
 #define DEFAULT_FRAMERATE_NUM 30
 #define DEFAULT_FRAMERATE_DEN 1
 #define DEFAULT_VIDEO_FRAME_DURATION 33 /* ms */
+#define PLAYER_DATA_PUSH_WAIT_COUNT 10
+#define PLAYER_STATE_CHECK_INTERVAL (100*1000)
 
 /*---------------------------------------------------------------------------
 |    LOCAL FUNCTION PROTOTYPES:                                             |
@@ -479,6 +481,7 @@ _mmplayer_submit_packet(MMHandleType hplayer, media_packet_h packet)
                GstMapInfo buff_info = GST_MAP_INFO_INIT;
                uint64_t pts = 0;
                uint64_t duration = 0;
+               int wait_cnt = 0;
 
                /* get size */
                _buffer = gst_buffer_new_and_alloc(size);
@@ -527,14 +530,26 @@ _mmplayer_submit_packet(MMHandleType hplayer, media_packet_h packet)
                        goto ERROR;
                }
                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;
+               }
+
                gst_app_src_push_buffer(GST_APP_SRC(element), _buffer);
        }
 
        /* check eos */
        if (media_packet_is_end_of_stream(packet, &is_eos) != MEDIA_PACKET_ERROR_NONE) {
                LOGE("failed to get eos info");
-               ret = MM_ERROR_PLAYER_INTERNAL;
-               goto ERROR;
+               return MM_ERROR_PLAYER_INTERNAL;
        }
 
        if (is_eos) {
@@ -542,7 +557,10 @@ _mmplayer_submit_packet(MMHandleType hplayer, media_packet_h packet)
                g_signal_emit_by_name(element, "end-of-stream", &ret);
        }
 
+       return ret;
+
 ERROR:
+       gst_buffer_unref(_buffer);
        return ret;
 }