#include <dlog.h>
#include "muse_player.h"
#include "legacy_player.h"
+#include "legacy_player_internal.h"
#include "legacy_player_private.h"
#define MIN_BUFFERING_TIME_MS 0 /* use platform default value */
return PLAYER_ERROR_NONE;
}
+static int
+__set_buffer_export_callback(legacy_player_t *handle)
+{
+ int ret = MM_ERROR_NONE;
+
+ if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME])
+ ret = mm_player_set_video_decoded_callback(handle->mm_handle,
+ (mm_player_video_decoded_callback)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME], handle->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME]);
+
+ if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME])
+ ret = mm_player_set_audio_decoded_callback(handle->mm_handle, handle->pcm_extract_opt,
+ (mm_player_audio_decoded_callback)handle->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME], handle->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME]);
+
+ return ret;
+}
+
static player_state_e __convert_player_state(mmplayer_state_e state)
{
if (state == MM_PLAYER_STATE_NONE)
return state + 1;
}
+static void __buffer_status_callback(legacy_player_t *handle, MMMessageParamType *msg)
+{
+ muse_player_event_e event_type;
+ muse_player_event_e event_type_internal;
+ player_media_stream_buffer_status_e buffer_status;
+ unsigned long long buffer_bytes;
+
+ /* check public api callback, higher priority */
+ if (msg->buffer_status.stream_type == MM_PLAYER_STREAM_TYPE_AUDIO) {
+ event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
+ event_type_internal = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
+ } else if (msg->buffer_status.stream_type == MM_PLAYER_STREAM_TYPE_VIDEO) {
+ event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
+ event_type_internal = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
+ } else {
+ LOGE("invalid stream type %d", msg->buffer_status.stream_type);
+ return;
+ }
+
+ buffer_status = msg->buffer_status.status;
+ buffer_bytes = msg->buffer_status.bytes;
+
+ LEGACY_PLAYER_USER_CB_LOCK(handle, event_type);
+ if (handle->user_cb[event_type]) {
+ LOGD("event type %d, status %d", event_type, buffer_status);
+ ((player_media_stream_buffer_status_cb)handle->user_cb[event_type])(buffer_status, handle->user_data[event_type]);
+ LEGACY_PLAYER_USER_CB_UNLOCK(handle, event_type);
+ return;
+ }
+ LEGACY_PLAYER_USER_CB_UNLOCK(handle, event_type);
+
+ /* check internal api callback */
+ LEGACY_PLAYER_USER_CB_LOCK(handle, event_type_internal);
+ if (handle->user_cb[event_type_internal]) {
+ LOGD("event type %d, status %d, bytes %llu", event_type_internal, buffer_status, buffer_bytes);
+ ((player_media_stream_buffer_status_cb_ex)handle->user_cb[event_type_internal])(buffer_status, buffer_bytes, handle->user_data[event_type_internal]);
+ }
+ LEGACY_PLAYER_USER_CB_UNLOCK(handle, event_type_internal);
+}
+
+static void __video_stream_changed_callback(legacy_player_t *handle)
+{
+ int ret = MM_ERROR_NONE;
+ muse_player_event_e event_type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
+ int width = 0;
+ int height = 0;
+ int fps = 0;
+ int bit_rate = 0;
+
+ ret = mm_player_get_attribute(handle->mm_handle, NULL,
+ MM_PLAYER_VIDEO_WIDTH, &width,
+ MM_PLAYER_VIDEO_HEIGHT, &height,
+ MM_PLAYER_VIDEO_FPS, &fps,
+ MM_PLAYER_VIDEO_BITRATE, &bit_rate, (char *)NULL);
+
+ if (ret != MM_ERROR_NONE) {
+ LOGE("get attr is failed");
+ return;
+ }
+
+ ((player_video_stream_changed_cb)handle->user_cb[event_type])(width, height, fps, bit_rate, handle->user_data[event_type]);
+ return;
+}
+
static int __msg_callback(int message, void *param, void *user_data)
{
legacy_player_t *handle = (legacy_player_t *)user_data;
LOGI("MM_MESSAGE_PLAY_POSITION (%"PRId64" ns)", msg->time.elapsed);
handle->last_play_position = msg->time.elapsed;
break;
- case MM_MESSAGE_UNKNOWN: /* 0x00 */
- case MM_MESSAGE_WARNING: /* 0x02 */
- case MM_MESSAGE_CONNECTING: /* 0x100 */
- case MM_MESSAGE_CONNECTED: /* 0x101 */
- case MM_MESSAGE_BLUETOOTH_ON: /* 0x106 */
- case MM_MESSAGE_BLUETOOTH_OFF: /* 0x107 */
- case MM_MESSAGE_RTP_SENDER_REPORT: /* 0x10a */
- case MM_MESSAGE_RTP_RECEIVER_REPORT: /* 0x10b */
- case MM_MESSAGE_RTP_SESSION_STATUS: /* 0x10c */
- case MM_MESSAGE_SENDER_STATE: /* 0x10d */
- case MM_MESSAGE_RECEIVER_STATE: /* 0x10e */
+ case MM_MESSAGE_VIDEO_STREAM_CHANGED:
+ if (handle->user_cb[MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED])
+ __video_stream_changed_callback(handle);
+ break;
+ case MM_MESSAGE_PUSH_BUFFER_STATUS:
+ __buffer_status_callback(handle, msg);
+ break;
+ case MM_MESSAGE_PUSH_BUFFER_SEEK_DATA:
+ {
+ muse_player_event_e event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
+
+ if (msg->seek_data.stream_type == MM_PLAYER_STREAM_TYPE_AUDIO)
+ event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
+
+ if (handle->user_cb[event_type])
+ ((player_media_stream_seek_cb)handle->user_cb[event_type])(msg->seek_data.offset, handle->user_data[event_type]);
+
+ break;
+ }
+ case MM_MESSAGE_UNKNOWN:
+ case MM_MESSAGE_WARNING:
+ case MM_MESSAGE_CONNECTING:
+ case MM_MESSAGE_CONNECTED:
+ case MM_MESSAGE_RTP_SENDER_REPORT:
+ case MM_MESSAGE_RTP_RECEIVER_REPORT:
+ case MM_MESSAGE_RTP_SESSION_STATUS:
default:
break;
}
if (ret != MM_ERROR_NONE)
LOGW("Failed to set message callback function (0x%x)", ret);
+ ret = __set_buffer_export_callback(handle);
+ if (ret != MM_ERROR_NONE) {
+ LOGW("Failed to set buffer export callback function (0x%x)", ret);
+ return __player_convert_error_code(ret, (char *)__FUNCTION__);
+ }
+
if (handle->display_type == PLAYER_DISPLAY_TYPE_NONE) {
ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_surface_type", MM_DISPLAY_SURFACE_NULL, (char *)NULL);
if (ret != MM_ERROR_NONE)
if (ret != MM_ERROR_NONE)
LOGW("Failed to set message callback function (0x%x)", ret);
+ ret = __set_buffer_export_callback(handle);
+ if (ret != MM_ERROR_NONE) {
+ LOGW("Failed to set buffer export callback function (0x%x)", ret);
+ return __player_convert_error_code(ret, (char *)__FUNCTION__);
+ }
+
if (handle->display_type == PLAYER_DISPLAY_TYPE_NONE) {
ret = mm_player_set_attribute(handle->mm_handle, NULL, "display_surface_type", MM_DISPLAY_SURFACE_NULL, (char *)NULL);
if (ret != MM_ERROR_NONE)
LOGE("PLAYER_ERROR_INVALID_STATE : current state - %d", handle->state);
return PLAYER_ERROR_INVALID_STATE;
}
- ret = mm_player_get_attribute(handle->mm_handle, NULL, "content_video_fps", fps, "content_video_bitrate", bit_rate, (char *)NULL);
+ ret = mm_player_get_attribute(handle->mm_handle, NULL, MM_PLAYER_VIDEO_FPS, fps, MM_PLAYER_VIDEO_BITRATE, bit_rate, (char *)NULL);
if (ret != MM_ERROR_NONE)
return __player_convert_error_code(ret, (char *)__FUNCTION__);
int legacy_player_set_media_packet_video_frame_decoded_cb(legacy_player_h player, legacy_player_media_packet_video_decoded_cb callback, void *user_data)
{
legacy_player_t *handle = (legacy_player_t *)player;
- int ret = MM_ERROR_NONE;
PLAYER_INSTANCE_CHECK(player);
PLAYER_NULL_ARG_CHECK(callback);
PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
- ret = mm_player_set_video_decoded_callback(handle->mm_handle, (mm_player_video_decoded_callback)callback, user_data);
- if (ret != MM_ERROR_NONE)
- return __player_convert_error_code(ret, (char *)__FUNCTION__);
+ handle->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = callback;
+ handle->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME] = user_data;
return PLAYER_ERROR_NONE;
}
-static bool __video_stream_changed_callback(void *user_data)
-{
- legacy_player_t *handle = (legacy_player_t *)user_data;
- int ret = MM_ERROR_NONE;
- muse_player_event_e event_type = MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED;
-
- LOGE("event type %d", event_type);
-
- if (handle->user_cb[event_type]) {
- int width = 0, height = 0, fps = 0, bit_rate = 0;
- ret = mm_player_get_attribute(handle->mm_handle, NULL,
- MM_PLAYER_VIDEO_WIDTH, &width,
- MM_PLAYER_VIDEO_HEIGHT, &height,
- "content_video_fps", &fps,
- "content_video_bitrate", &bit_rate, (char *)NULL);
-
- if (ret != MM_ERROR_NONE) {
- LOGE("get attr is failed");
- return false;
- }
- ((player_video_stream_changed_cb)handle->user_cb[event_type])(width, height, fps, bit_rate, handle->user_data[event_type]);
- return true;
- }
-
- LOGE("video stream changed cb was not set.");
- return false;
-}
-
int legacy_player_set_video_stream_changed_cb(legacy_player_h player, player_video_stream_changed_cb callback, void *user_data)
{
legacy_player_t *handle = (legacy_player_t *)player;
- int ret = MM_ERROR_NONE;
PLAYER_INSTANCE_CHECK(player);
PLAYER_NULL_ARG_CHECK(callback);
PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
- ret = mm_player_set_video_stream_changed_callback(handle->mm_handle, (mm_player_stream_changed_callback)__video_stream_changed_callback, (void *)handle);
- if (ret != MM_ERROR_NONE)
- return __player_convert_error_code(ret, (char *)__FUNCTION__);
-
return __set_callback(MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED, player, callback, user_data);
}
return PLAYER_ERROR_NONE;
}
-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)
-{
- legacy_player_t *handle = (legacy_player_t *)user_data;
- muse_player_event_e event_type;
-
- if (type == PLAYER_STREAM_TYPE_AUDIO)
- event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS;
- else if (type == PLAYER_STREAM_TYPE_VIDEO)
- event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS;
- else
- return false;
-
- LOGE("event type %d", event_type);
-
- if (handle->user_cb[event_type]) {
- ((player_media_stream_buffer_status_cb)handle->user_cb[event_type])(status, handle->user_data[event_type]);
- } else {
- LOGE("[type:%d] buffer status cb was not set.", type);
- return false;
- }
-
- return true;
-}
-
-static bool __media_stream_seek_data_callback(player_stream_type_e type, unsigned long long offset, void *user_data)
-{
- legacy_player_t *handle = (legacy_player_t *)user_data;
- muse_player_event_e event_type;
-
- if (type == PLAYER_STREAM_TYPE_AUDIO)
- event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK;
- else if (type == PLAYER_STREAM_TYPE_VIDEO)
- event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK;
- else
- return false;
-
- LOGE("event type %d", event_type);
-
- if (handle->user_cb[event_type]) {
- ((player_media_stream_seek_cb)handle->user_cb[event_type])(offset, handle->user_data[event_type]);
- } else {
- LOGE("[type:%d] seek cb was not set.", type);
- return false;
- }
-
- return true;
-}
-
int legacy_player_set_media_stream_buffer_status_cb(legacy_player_h player, player_stream_type_e type, player_media_stream_buffer_status_cb callback, void *user_data)
{
legacy_player_t *handle = (legacy_player_t *)player;
- int ret = MM_ERROR_NONE;
PLAYER_INSTANCE_CHECK(player);
PLAYER_NULL_ARG_CHECK(callback);
PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
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, (void *)handle);
-
- if (ret != MM_ERROR_NONE)
- return __player_convert_error_code(ret, (char *)__FUNCTION__);
-
if (type == PLAYER_STREAM_TYPE_VIDEO)
return __set_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS, player, callback, user_data);
else
int legacy_player_set_media_stream_seek_cb(legacy_player_h player, player_stream_type_e type, player_media_stream_seek_cb callback, void *user_data)
{
legacy_player_t *handle = (legacy_player_t *)player;
- int ret = MM_ERROR_NONE;
PLAYER_INSTANCE_CHECK(player);
PLAYER_NULL_ARG_CHECK(callback);
PLAYER_STATE_CHECK(handle, PLAYER_STATE_IDLE);
return PLAYER_ERROR_INVALID_PARAMETER;
}
- ret = mm_player_set_media_stream_seek_data_callback(handle->mm_handle, type, (mm_player_media_stream_seek_data_callback)__media_stream_seek_data_callback, (void *)handle);
- if (ret != MM_ERROR_NONE)
- return __player_convert_error_code(ret, (char *)__FUNCTION__);
-
if (type == PLAYER_STREAM_TYPE_VIDEO)
return __set_callback(MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK, player, callback, user_data);
int legacy_player_set_pcm_extraction_mode(legacy_player_h player, bool sync, legacy_player_media_packet_audio_decoded_cb callback, void *user_data)
{
legacy_player_t *handle = (legacy_player_t *)player;
- int ret = MM_ERROR_NONE;
PLAYER_INSTANCE_CHECK(player);
PLAYER_NULL_ARG_CHECK(callback);
mmplayer_audio_extract_opt_e opt = MM_PLAYER_AUDIO_EXTRACT_DEINTERLEAVE; /* sync is true */
if (!sync)
opt = MM_PLAYER_AUDIO_EXTRACT_NO_SYNC_WITH_CLOCK | MM_PLAYER_AUDIO_EXTRACT_DEINTERLEAVE;
- ret = mm_player_set_audio_decoded_callback(handle->mm_handle, opt, (mm_player_audio_decoded_callback)callback, user_data);
- if (ret != MM_ERROR_NONE)
- return __player_convert_error_code(ret, (char *)__FUNCTION__);
+ handle->pcm_extract_opt = opt;
+ handle->user_cb[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME] = callback;
+ handle->user_data[MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_AUDIO_FRAME] = user_data;
return PLAYER_ERROR_NONE;
}
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)
-{
- legacy_player_t *handle = (legacy_player_t *)user_data;
- muse_player_event_e event_type;
-
- if (!handle) {
- LOGE("user_data param is null");
- return false;
- }
-
- if (type == PLAYER_STREAM_TYPE_AUDIO)
- event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
- else if (type == PLAYER_STREAM_TYPE_VIDEO)
- event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO;
- else
- return false;
-
- LOGE("event type %d, status %d, bytes %llu", event_type, status, bytes);
-
- LEGACY_PLAYER_USER_CB_LOCK(handle, event_type);
-
- 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("[type:%d] buffer status cb was not set.", type);
- LEGACY_PLAYER_USER_CB_UNLOCK(handle, event_type);
- return false;
- }
-
- LEGACY_PLAYER_USER_CB_UNLOCK(handle, event_type);
-
- return true;
-}
-
-
int legacy_player_set_media_stream_buffer_status_cb_ex(legacy_player_h player, player_stream_type_e type, player_media_stream_buffer_status_cb_ex callback, void *user_data)
{
legacy_player_t *handle = (legacy_player_t *)player;
- int ret = MM_ERROR_NONE;
muse_player_event_e event_type;
PLAYER_INSTANCE_CHECK(player);
PLAYER_NULL_ARG_CHECK(callback);
else
event_type = MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO;
-
- 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) {
- LEGACY_PLAYER_USER_CB_UNLOCK(handle, event_type);
- return __player_convert_error_code(ret, (char *)__FUNCTION__);
- }
-
LEGACY_PLAYER_USER_CB_LOCK(handle, event_type);
handle->user_cb[event_type] = callback;