#define PLAYER_STATE_CHECK(player, expected_state) \
PLAYER_CHECK_CONDITION(player->state == expected_state, PLAYER_ERROR_INVALID_STATE, "PLAYER_ERROR_INVALID_STATE")
+#define PLAYER_INTERNAL_STATE_CHECK(player, expected_state) \
+ PLAYER_CHECK_CONDITION(player->internal_state == expected_state, PLAYER_ERROR_INVALID_STATE, "PLAYER_ERROR_INVALID_STATE")
+
#define PLAYER_NULL_ARG_CHECK(arg) \
PLAYER_CHECK_CONDITION((arg), PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER")
typedef struct {
muse_player_event_e type;
- player_state_e state;
+ player_state_e set_state;
+ player_state_e unset_state;
} legacy_player_callback_pre_state_t;
int _lplayer_convert_error_code(int code, char *func_name);
}
}
-static int __lplayer_check_callback_precondition(legacy_player_t *handle, muse_player_event_e type)
+static int __lplayer_check_callback_precondition(legacy_player_t *handle, muse_player_event_e type, bool set)
{
int i = 0;
int size = 0;
+ player_internal_state_e cb_state = PLAYER_INTERNAL_STATE_NONE;
+
legacy_player_callback_pre_state_t callback_pre_state[] = {
- {MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME, PLAYER_STATE_IDLE},
- {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS, PLAYER_STATE_IDLE},
- {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS, PLAYER_STATE_IDLE},
- {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO, PLAYER_STATE_IDLE},
- {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO, PLAYER_STATE_IDLE},
- {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK, PLAYER_STATE_IDLE},
- {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK, PLAYER_STATE_IDLE},
- {MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED, PLAYER_STATE_IDLE},
+ {MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME, PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_IDLE},
+ {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS, PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
+ {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS, PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
+ {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_BUFFER_STATUS_WITH_INFO, PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
+ {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_BUFFER_STATUS_WITH_INFO, PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
+ {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_VIDEO_SEEK, PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
+ {MUSE_PLAYER_EVENT_TYPE_MEDIA_STREAM_AUDIO_SEEK, PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
+ {MUSE_PLAYER_EVENT_TYPE_VIDEO_STREAM_CHANGED, PLAYER_INTERNAL_STATE_IDLE, PLAYER_INTERNAL_STATE_NONE},
};
size = sizeof(callback_pre_state)/sizeof(legacy_player_callback_pre_state_t);
/* check pre-state */
for (; i < size; i++) {
if (type == callback_pre_state[i].type) {
- PLAYER_STATE_CHECK(handle, callback_pre_state[i].state);
+ if (set)
+ cb_state = callback_pre_state[i].set_state;
+ else
+ cb_state = callback_pre_state[i].unset_state;
+
+ if (cb_state == PLAYER_INTERNAL_STATE_NONE)
+ break;
+
+ PLAYER_INTERNAL_STATE_CHECK(handle, cb_state);
break;
}
}
PLAYER_INSTANCE_CHECK(player);
PLAYER_NULL_ARG_CHECK(callback);
- ret = __lplayer_check_callback_precondition(handle, type);
+ ret = __lplayer_check_callback_precondition(handle, type, true);
if (ret != PLAYER_ERROR_NONE) {
LOGE("precondition failure, type %d", type);
return ret;
int legacy_player_unset_callback(legacy_player_h player, muse_player_event_e type)
{
+ int ret = MM_ERROR_NONE;
legacy_player_t *handle = (legacy_player_t *)player;
PLAYER_INSTANCE_CHECK(player);
LOGD("event type : %d ", type);
+ ret = __lplayer_check_callback_precondition(handle, type, false);
+ if (ret != PLAYER_ERROR_NONE) {
+ LOGE("precondition failure, type %d", type);
+ return ret;
+ }
+
L_PLAYER_USER_CB_LOCK(player, type);
handle->user_cb[type] = NULL;
PLAYER_SEND_EVENT_MSG(api, ev, module, MUSE_TYPE_INT, "percent", percent);
}
-static void __mplayer_set_enable_data_export(legacy_player_h player, void *data, bool set)
-{
- muse_module_h module = (muse_module_h)data;
- muse_player_handle_t *muse_player = (muse_player_handle_t *)muse_server_ipc_get_handle(module);
-
- muse_player->export_video_data = set;
-}
-
static void *__mplayer_callback_function[MUSE_PLAYER_EVENT_TYPE_NUM] = {
NULL, /* MUSE_PLAYER_EVENT_TYPE_PREPARE */
__mplayer_default_callback, /* MUSE_PLAYER_EVENT_TYPE_COMPLETE */
NULL, /* MUSE_PLAYER_EVENT_TYPE_AUDIO_FRAME, DEPRECATED_PLAYER_INTERNAL_API */
};
-static int __mplayer_set_callback_func(legacy_player_h player, muse_player_event_e type, bool set, void *user_data)
+static int __mplayer_set_callback_func(muse_player_handle_t *muse_player, muse_player_event_e type, bool set, void *user_data)
{
int ret = PLAYER_ERROR_NONE;
return PLAYER_ERROR_INVALID_OPERATION;
}
- if (type == MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME)
- __mplayer_set_enable_data_export(player, user_data, set);
-
if (set)
- ret = legacy_player_set_callback(player, type, __mplayer_callback_function[type], user_data);
+ ret = legacy_player_set_callback(muse_player->player_handle, type, __mplayer_callback_function[type], user_data);
else
- ret = legacy_player_unset_callback(player, type);
+ ret = legacy_player_unset_callback(muse_player->player_handle, type);
+
+ if (type == MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME) {
+
+ if (ret == PLAYER_ERROR_NONE) {
+ muse_player->export_video_data = set;
+ } else if ((ret == PLAYER_ERROR_INVALID_STATE) && !set) {
+ player_state_e curr_state = PLAYER_STATE_NONE;
+
+ /* if current state is ready, data exporting need to be blocked */
+ ret = legacy_player_get_state(muse_player->player_handle, &curr_state);
+ if (ret == PLAYER_ERROR_NONE && (curr_state <= PLAYER_STATE_READY))
+ muse_player->export_video_data = false;
+ }
+ }
return ret;
}
int ret = PLAYER_ERROR_NONE;
muse_player_api_e api = MUSE_PLAYER_API_UNPREPARE;
muse_player_handle_t *muse_player = NULL;
+ bool unset_cb = false;
muse_player = (muse_player_handle_t *)muse_server_ipc_get_handle(module);
+ unset_cb = !muse_player->export_video_data;
/* decoder buffer need to be released first to destroy pipeline */
__mplayer_remove_export_media_packet(module);
ret = legacy_player_unprepare(muse_player->player_handle);
+ /* if the data exporting was blocked, the legacy player callback need to be cleared.
+ clearing legacy player cb is possible in idle state only */
+ if (unset_cb)
+ legacy_player_unset_callback(muse_player->player_handle, MUSE_PLAYER_EVENT_TYPE_MEDIA_PACKET_VIDEO_FRAME);
+
__mplayer_remove_export_data(module, 0, true);
PLAYER_RETURN_MSG(api, ret, module);
}
muse_player = (muse_player_handle_t *)muse_server_ipc_get_handle(module);
- ret = __mplayer_set_callback_func(muse_player->player_handle, type, set, module);
+ ret = __mplayer_set_callback_func(muse_player, type, set, module);
if (ret != PLAYER_ERROR_NONE) {
LOGE("failed to set callback type %d", type);
/* goto EXIT; */
Name: mmsvc-player
Summary: A Media Player module for muse server
-Version: 0.2.115
+Version: 0.2.116
Release: 0
Group: Multimedia/Libraries
License: Apache-2.0