add internal api about buffer status cb with bytes info 77/56377/1 accepted/tizen/mobile/20160108.005416 accepted/tizen/tv/20160108.005437 accepted/tizen/wearable/20160108.005510 submit/tizen/20160107.071246
authorEunhae Choi <eunhae1.choi@samsung.com>
Thu, 7 Jan 2016 06:44:37 +0000 (15:44 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Thu, 7 Jan 2016 06:45:00 +0000 (15:45 +0900)
Change-Id: Ia1c89286226e6a795102473861952525ba3d40ef

include/mobile/player_internal.h
include/player_private.h
include/wearable/player_internal.h
src/player.c
src/player_internal.c
test/legacy_player_es_push_test.c

index 75e1c395596c3a4a628d5bcfbd1cc8c7be6333e1..210e72e69ad87558f2b276ae79a32630e159dad7 100644 (file)
@@ -55,6 +55,18 @@ typedef struct {
  */
 typedef void (*player_audio_pcm_extraction_cb)(player_audio_raw_data_s *audio_raw_frame, void *user_data);
 
+/**
+ * @brief Called when the buffer level drops below the min size or exceeds the max size.
+ * @since_tizen 3.0
+ * @remarks This API is used for media stream playback only.
+ * @param[in] status The buffer status
+ * @param[in] bytes The current buffer level bytes
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see player_set_media_stream_buffer_status_cb_ex()
+ * @see player_set_media_stream_buffer_max_size()
+ * @see player_set_media_stream_buffer_min_threshold()
+ */
+typedef void (*player_media_stream_buffer_status_cb_ex) (player_media_stream_buffer_status_e status, unsigned long long bytes, void *user_data);
 
 /**
  * @brief Registers a callback function to be invoked when audio frame is decoded. Audio only contents is possible. If included video, error happens.
@@ -110,6 +122,40 @@ int player_set_pcm_spec(player_h player, const char *format, int samplerate, int
  */
 int player_set_streaming_playback_rate(player_h player, float rate);
 
+/**
+ * @brief Registers a callback function to be invoked when buffer underrun or overflow is occurred.
+ * @since_tizen 3.0
+ * @remarks This API is used for media stream playback only.
+ * @param[in] player   The handle to the media player
+ * @param[in] type     The type of target stream
+ * @param[in] callback The buffer status callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #PLAYER_ERROR_NONE Successful
+ * @retval #PLAYER_ERROR_INVALID_STATE Invalid player state
+ * @retval #PLAYER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre The player state must be set to #PLAYER_STATE_IDLE by calling player_create() or player_unprepare().
+ * @post player_media_stream_buffer_status_cb_ex() will be invoked.
+ * @see player_unset_media_stream_buffer_status_cb_ex()
+ * @see player_media_stream_buffer_status_cb_ex()
+ */
+int player_set_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e type, player_media_stream_buffer_status_cb_ex callback, void *user_data);
+
+/**
+ * @brief Unregisters the buffer status callback function.
+ * @since_tizen 3.0
+ * @remarks This API is used for media stream playback only.
+ * @param[in] player The handle to the media player
+ * @param[in] type   The type of target stream
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #PLAYER_ERROR_NONE Successful
+ * @retval #PLAYER_ERROR_INVALID_STATE Invalid player state
+ * @retval #PLAYER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see player_set_media_stream_buffer_status_cb()
+ */
+int player_unset_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e type);
 
 /**
  * @}
index 81e006915fc751bdfd92ea2b0a0b62d2d1b78f4e..56d43f4045bf7e62282b6d1f5eff218047c8ce2e 100644 (file)
@@ -82,6 +82,8 @@ typedef enum {
 #endif
        _PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS,
        _PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS,
+       _PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO,
+       _PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO,
        _PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK,
        _PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK,
        _PLAYER_EVENT_TYPE_AUDIO_STREAM_CHANGED,
index 9d9f3b89e0cf9efa248ec6cd10a1a54bfdbf807d..6f168ff1ce4c31859ddbdb566288475cc1f1d3a2 100644 (file)
@@ -55,6 +55,18 @@ typedef struct {
  */
 typedef void (*player_audio_pcm_extraction_cb)(player_audio_raw_data_s *audio_raw_frame, void *user_data);
 
+/**
+ * @brief Called when the buffer level drops below the min size or exceeds the max size.
+ * @since_tizen 3.0
+ * @remarks This API is used for media stream playback only.
+ * @param[in] status The buffer status
+ * @param[in] bytes The current buffer level bytes
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see player_set_media_stream_buffer_status_cb_ex()
+ * @see player_set_media_stream_buffer_max_size()
+ * @see player_set_media_stream_buffer_min_threshold()
+ */
+typedef void (*player_media_stream_buffer_status_cb_ex) (player_media_stream_buffer_status_e status, unsigned long long bytes, void *user_data);
 
 /**
  * @brief Registers a callback function to be invoked when audio frame is decoded. Audio only contents is possible. If included video, error happens.
@@ -109,6 +121,40 @@ int player_set_pcm_spec(player_h player, const char *format, int samplerate, int
  */
 int player_set_streaming_playback_rate(player_h player, float rate);
 
+/**
+ * @brief Registers a callback function to be invoked when buffer underrun or overflow is occurred.
+ * @since_tizen 3.0
+ * @remarks This API is used for media stream playback only.
+ * @param[in] player   The handle to the media player
+ * @param[in] type     The type of target stream
+ * @param[in] callback The buffer status callback function to register
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #PLAYER_ERROR_NONE Successful
+ * @retval #PLAYER_ERROR_INVALID_STATE Invalid player state
+ * @retval #PLAYER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre The player state must be set to #PLAYER_STATE_IDLE by calling player_create() or player_unprepare().
+ * @post player_media_stream_buffer_status_cb_ex() will be invoked.
+ * @see player_unset_media_stream_buffer_status_cb_ex()
+ * @see player_media_stream_buffer_status_cb_ex()
+ */
+int player_set_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e type, player_media_stream_buffer_status_cb_ex callback, void *user_data);
+
+/**
+ * @brief Unregisters the buffer status callback function.
+ * @since_tizen 3.0
+ * @remarks This API is used for media stream playback only.
+ * @param[in] player The handle to the media player
+ * @param[in] type   The type of target stream
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #PLAYER_ERROR_NONE Successful
+ * @retval #PLAYER_ERROR_INVALID_STATE Invalid player state
+ * @retval #PLAYER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see player_set_media_stream_buffer_status_cb()
+ */
+int player_unset_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e type);
 
 /**
  * @}
index 90395314586e7eb527b34d56174753c03dda4675..9a09aa87389001e1ce137e02697d881831666993 100644 (file)
@@ -2627,7 +2627,7 @@ int player_unset_video_stream_changed_cb(player_h player)
                return PLAYER_ERROR_NONE;
 }
 
-static bool __media_stream_buffer_status_callback(player_stream_type_e type, player_media_stream_buffer_status_e status, void *user_data)
+static bool __media_stream_buffer_status_callback(player_stream_type_e type, player_media_stream_buffer_status_e status, unsigned long long bytes, void *user_data)
 {
        player_s *handle = (player_s *)user_data;
        _player_event_e event_type;
index f8b1ae209993789dd9f7ebdab82c4ec4ea065d2c..93da242e57ce0253fc2087b943618e055bb4d26d 100644 (file)
@@ -121,3 +121,90 @@ int player_set_streaming_playback_rate(player_h player, float rate)
        }
        return ret;
 }
+
+static bool __media_stream_buffer_status_callback_ex(player_stream_type_e type, player_media_stream_buffer_status_e status, unsigned long long bytes, void *user_data)
+{
+       player_s *handle = (player_s *)user_data;
+       _player_event_e event_type;
+
+       if (type == PLAYER_STREAM_TYPE_AUDIO)
+               event_type = _PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
+       else if (type == PLAYER_STREAM_TYPE_VIDEO)
+               event_type = _PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
+       else
+               return FALSE;
+
+       LOGE("[%s] event type %d, status %d, bytes %llu", __FUNCTION__, event_type, status, bytes);
+
+       if (handle->user_cb[event_type]) {
+               ((player_media_stream_buffer_status_cb_ex)handle->user_cb[event_type])(status, bytes, handle->user_data[event_type]);
+       } else {
+               LOGE("[%s][type:%d] buffer status cb was not set.", __FUNCTION__, type);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+
+int player_set_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e type, player_media_stream_buffer_status_cb_ex callback, void *user_data)
+{
+       int ret;
+       PLAYER_INSTANCE_CHECK(player);
+       PLAYER_NULL_ARG_CHECK(callback);
+       player_s *handle = (player_s *)player;
+       _player_event_e event_type;
+
+       if (handle->state != PLAYER_STATE_IDLE) {
+               LOGE("[%s] PLAYER_ERROR_INVALID_STATE(0x%08x) : current state - %d", __FUNCTION__, PLAYER_ERROR_INVALID_STATE, handle->state);
+               return PLAYER_ERROR_INVALID_STATE;
+       }
+       /* the type can be expaned with default and text. */
+       if ((type != PLAYER_STREAM_TYPE_VIDEO) && (type != PLAYER_STREAM_TYPE_AUDIO)) {
+               LOGE("[%s] PLAYER_ERROR_INVALID_PARAMETER(type : %d)", __FUNCTION__, type);
+               return PLAYER_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = mm_player_set_media_stream_buffer_status_callback(handle->mm_handle, type, (mm_player_media_stream_buffer_status_callback)__media_stream_buffer_status_callback_ex, (void *)handle);
+
+       if (ret != MM_ERROR_NONE)
+               return __player_convert_error_code(ret, (char *)__FUNCTION__);
+
+       if (type == PLAYER_STREAM_TYPE_VIDEO)
+               event_type = _PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
+       else
+               event_type = _PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
+
+       LOGI("[%s] Event type : %d ", __FUNCTION__, type);
+
+       handle->user_cb[event_type] = callback;
+       handle->user_data[event_type] = user_data;
+
+       return PLAYER_ERROR_NONE;
+}
+
+int player_unset_media_stream_buffer_status_cb_ex(player_h player, player_stream_type_e type)
+{
+       int ret;
+       PLAYER_INSTANCE_CHECK(player);
+       player_s *handle = (player_s *)player;
+       _player_event_e event_type;
+
+       if (type == PLAYER_STREAM_TYPE_VIDEO)
+               event_type = _PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
+       else if (type == PLAYER_STREAM_TYPE_AUDIO)
+               event_type = _PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
+       else
+               return PLAYER_ERROR_INVALID_PARAMETER;
+
+       handle->user_cb[event_type] = NULL;
+       handle->user_data[event_type] = NULL;
+
+       LOGI("[%s] Event type : %d ", __FUNCTION__, type);
+
+       ret = mm_player_set_media_stream_buffer_status_callback(handle->mm_handle, type, NULL, NULL);
+       if (ret != MM_ERROR_NONE)
+               return __player_convert_error_code(ret, (char *)__FUNCTION__);
+       else
+               return PLAYER_ERROR_NONE;
+}
index 08dbc3e8e719713255cc94cdd4ea013848c1ebd8..6b51ef88acb16b1c6507a37d9d1e66dddaa3b024 100644 (file)
@@ -18,6 +18,7 @@
 #include <tbm_surface.h>
 #include <dlog.h>
 #include <player.h>
+#include <player_internal.h>
 #include <glib.h>
 #include <appcore-efl.h>
 #ifdef HAVE_WAYLAND
@@ -199,7 +200,7 @@ static int app_pause(void *data)
        }
 
        if (ad->player_handle == NULL) {
-               printf("player_handle is NULL");
+               LOGE("player_handle is NULL");
                return -1;
        }
 
@@ -208,14 +209,14 @@ static int app_pause(void *data)
                ad->feeding_thread_id = 0;
        }
 
-       player_unset_media_stream_buffer_status_cb(ad->player_handle, PLAYER_STREAM_TYPE_VIDEO);
-       player_unset_media_stream_buffer_status_cb(ad->player_handle, PLAYER_STREAM_TYPE_AUDIO);
+       player_unset_media_stream_buffer_status_cb_ex(ad->player_handle, PLAYER_STREAM_TYPE_VIDEO);
+       player_unset_media_stream_buffer_status_cb_ex(ad->player_handle, PLAYER_STREAM_TYPE_AUDIO);
        player_unset_media_stream_seek_cb(ad->player_handle, PLAYER_STREAM_TYPE_VIDEO);
        player_unset_media_stream_seek_cb(ad->player_handle, PLAYER_STREAM_TYPE_AUDIO);
 
        ret = player_unprepare(ad->player_handle);
        if (ret != PLAYER_ERROR_NONE) {
-               printf("player_unprepare failed : 0x%x", ret);
+               LOGE("player_unprepare failed : 0x%x", ret);
                return false;
        }
 
@@ -228,7 +229,7 @@ static int app_pause(void *data)
        /* destroy player handle */
        ret = player_destroy(ad->player_handle);
        if (ret != PLAYER_ERROR_NONE) {
-               printf("player_destroy failed : 0x%x", ret);
+               LOGE("player_destroy failed : 0x%x", ret);
                return false;
        }
 
@@ -454,20 +455,24 @@ static void feed_video_data_thread_func(void *data)
        }
 }
 
-void _video_buffer_status_cb(player_media_stream_buffer_status_e status, void *user_data)
+void _video_buffer_status_cb_ex(player_media_stream_buffer_status_e status, unsigned long long bytes, void *user_data)
 {
-       if (status == PLAYER_MEDIA_STREAM_BUFFER_UNDERRUN)
-               LOGE("video buffer is underrun state");
-       else if (status == PLAYER_MEDIA_STREAM_BUFFER_OVERFLOW)
-               LOGE("video buffer is overrun state");
+       if (status == PLAYER_MEDIA_STREAM_BUFFER_UNDERRUN) {
+               LOGE("video buffer is underrun state, current level byte = %llu", bytes);
+       }
+       else if (status == PLAYER_MEDIA_STREAM_BUFFER_OVERFLOW) {
+               LOGE("video buffer is overrun state, current level byte = %llu", bytes);
+       }
 }
 
-void _audio_buffer_status_cb(player_media_stream_buffer_status_e status, void *user_data)
+void _audio_buffer_status_cb_ex(player_media_stream_buffer_status_e status, unsigned long long bytes, void *user_data)
 {
-       if (status == PLAYER_MEDIA_STREAM_BUFFER_UNDERRUN)
-               LOGE("audio buffer is underrun state");
-       else if (status == PLAYER_MEDIA_STREAM_BUFFER_OVERFLOW)
-               LOGE("audio buffer is overrun state");
+       if (status == PLAYER_MEDIA_STREAM_BUFFER_UNDERRUN) {
+               LOGE("audio buffer is underrun state, current level byte = %llu", bytes);
+       }
+       else if (status == PLAYER_MEDIA_STREAM_BUFFER_OVERFLOW) {
+               LOGE("audio buffer is overrun state, current level byte = %llu", bytes);
+       }
 }
 
 void _video_seek_data_cb(unsigned long long offset, void *user_data)
@@ -517,12 +522,15 @@ static int app_reset(bundle *b, void *data)
        media_format_set_video_width(ad->video_fmt, ES_DEFAULT_VIDEO_FORMAT_WIDTH);
        media_format_set_video_height(ad->video_fmt, ES_DEFAULT_VIDEO_FORMAT_HEIGHT);
 
-       ret = player_set_media_stream_buffer_status_cb(ad->player_handle, PLAYER_STREAM_TYPE_VIDEO, _video_buffer_status_cb, (void *)ad);
+       player_set_media_stream_buffer_max_size(ad->player_handle, PLAYER_STREAM_TYPE_VIDEO, (unsigned long long)800*1024);
+       player_set_media_stream_buffer_min_threshold(ad->player_handle, PLAYER_STREAM_TYPE_VIDEO, 50);
+
+       ret = player_set_media_stream_buffer_status_cb_ex(ad->player_handle, PLAYER_STREAM_TYPE_VIDEO, _video_buffer_status_cb_ex, (void *)ad);
        if (ret != PLAYER_ERROR_NONE) {
                LOGE("player set video buffer status cb failed : 0x%x", ret);
                goto FAILED;
        }
-       ret = player_set_media_stream_buffer_status_cb(ad->player_handle, PLAYER_STREAM_TYPE_AUDIO, _audio_buffer_status_cb, (void *)ad);
+       ret = player_set_media_stream_buffer_status_cb_ex(ad->player_handle, PLAYER_STREAM_TYPE_AUDIO, _audio_buffer_status_cb_ex, (void *)ad);
        if (ret != PLAYER_ERROR_NONE) {
                LOGE("player set audio buffer status cb failed : 0x%x", ret);
                goto FAILED;