From 21539e5c2a4634cdc46d731713a9554c83e39215 Mon Sep 17 00:00:00 2001 From: Eunhae Choi Date: Mon, 25 Jun 2018 19:46:45 +0900 Subject: [PATCH] [0.3.96] add new playback time api in nsec Change-Id: I6a0d61747f843c412d59ebde64be440de2770025 --- packaging/capi-media-player.spec | 2 +- src/player.c | 156 ++++++++++++++++++++++++++++++++++----- 2 files changed, 138 insertions(+), 20 deletions(-) diff --git a/packaging/capi-media-player.spec b/packaging/capi-media-player.spec index 4b1be2c..2e11829 100644 --- a/packaging/capi-media-player.spec +++ b/packaging/capi-media-player.spec @@ -1,6 +1,6 @@ Name: capi-media-player Summary: A Media Player API -Version: 0.3.95 +Version: 0.3.96 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/player.c b/src/player.c index ebab0a3..2cfbe39 100644 --- a/src/player.c +++ b/src/player.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -2536,18 +2537,18 @@ int player_pause(player_h player) return ret; } -int player_set_play_position(player_h player, int millisecond, bool accurate, player_seek_completed_cb callback, void *user_data) +static int _set_play_position(player_h player, int64_t pos, bool accurate, player_seek_completed_cb callback, void *user_data) { PLAYER_INSTANCE_CHECK(player); - PLAYER_CHECK_CONDITION(millisecond >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER"); + PLAYER_CHECK_CONDITION(pos >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER"); int ret = PLAYER_ERROR_NONE; muse_player_api_e api = MUSE_PLAYER_API_SET_PLAY_POSITION; player_cli_s *pc = (player_cli_s *) player; char *ret_buf = NULL; - int pos = millisecond; LOGD("ENTER"); + if (!pc->cb_info) { LOGE("cb_info is null"); return PLAYER_ERROR_INVALID_OPERATION; @@ -2564,14 +2565,14 @@ int player_set_play_position(player_h player, int millisecond, bool accurate, pl pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_DROP; else pc->cb_info->seek_cb_state = PLAYER_SEEK_CB_STATE_WAIT; - LOGI("Event type : %d, pos : %d, accurate : %d", MUSE_PLAYER_EVENT_TYPE_SEEK, millisecond, accurate); + LOGI("Event type : %d, pos : %"PRId64", accurate : %d", MUSE_PLAYER_EVENT_TYPE_SEEK, pos, accurate); pc->cb_info->user_cb[MUSE_PLAYER_EVENT_TYPE_SEEK] = callback; pc->cb_info->user_data[MUSE_PLAYER_EVENT_TYPE_SEEK] = user_data; } g_mutex_unlock(&pc->cb_info->seek_cb_mutex); PLAYER_SEND_MSG(api, pc, ret_buf, ret, - MUSE_TYPE_INT, "pos", pos, + MUSE_TYPE_INT64, "pos", pos, MUSE_TYPE_INT, "accurate", (int)accurate); if (ret != PLAYER_ERROR_NONE) { @@ -2593,30 +2594,102 @@ int player_set_play_position(player_h player, int millisecond, bool accurate, pl return ret; } -int player_get_play_position(player_h player, int *millisecond) + +int player_set_play_position(player_h player, int milliseconds, bool accurate, player_seek_completed_cb callback, void *user_data) +{ + PLAYER_INSTANCE_CHECK(player); + PLAYER_CHECK_CONDITION(milliseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER"); + + int ret = PLAYER_ERROR_NONE; + int64_t pos = (int64_t)(milliseconds * G_GINT64_CONSTANT(1000000)); + + LOGD("ENTER"); + + ret = _set_play_position(player, pos, accurate, callback, user_data); + + LOGD("LEAVE 0x%X", ret); + return ret; +} + +int player_set_play_position_nsec(player_h player, int64_t nanoseconds, bool accurate, player_seek_completed_cb callback, void *user_data) { PLAYER_INSTANCE_CHECK(player); - PLAYER_NULL_ARG_CHECK(millisecond); + PLAYER_CHECK_CONDITION(nanoseconds >= 0, PLAYER_ERROR_INVALID_PARAMETER, "PLAYER_ERROR_INVALID_PARAMETER"); + + int ret = PLAYER_ERROR_NONE; + int64_t pos = nanoseconds; + + LOGD("ENTER"); + + ret = _set_play_position(player, pos, accurate, callback, user_data); + + LOGD("LEAVE 0x%X", ret); + return ret; +} + +static int _get_play_position(player_h player, int64_t *pos) +{ + PLAYER_INSTANCE_CHECK(player); + PLAYER_NULL_ARG_CHECK(pos); int ret = PLAYER_ERROR_NONE; muse_player_api_e api = MUSE_PLAYER_API_GET_PLAY_POSITION; player_cli_s *pc = (player_cli_s *) player; - int pos; char *ret_buf = NULL; - LOGD("ENTER"); - PLAYER_SEND_MSG(api, pc, ret_buf, ret); if (ret == PLAYER_ERROR_NONE) { - player_msg_get(pos, ret_buf); - *millisecond = pos; + bool ret_val = true; + ret_val = _player_get_param_value(ret_buf, + MUSE_TYPE_INT64, "pos", (void *)pos, + INVALID_MUSE_TYPE_VALUE); + if (!ret_val) { + ret = PLAYER_ERROR_INVALID_OPERATION; + } } g_free(ret_buf); return ret; } + +int player_get_play_position(player_h player, int *milliseconds) +{ + PLAYER_INSTANCE_CHECK(player); + PLAYER_NULL_ARG_CHECK(milliseconds); + + int ret = PLAYER_ERROR_NONE; + int64_t pos = 0; + + /* LOGD("ENTER"); */ + + ret = _get_play_position(player, &pos); + if (ret == PLAYER_ERROR_NONE) { + *milliseconds = (int)(pos / G_GINT64_CONSTANT(1000000)); + } + + return ret; +} + +int player_get_play_position_nsec(player_h player, int64_t *nanoseconds) +{ + PLAYER_INSTANCE_CHECK(player); + PLAYER_NULL_ARG_CHECK(nanoseconds); + + int ret = PLAYER_ERROR_NONE; + int64_t pos = 0; + + /* LOGD("ENTER"); */ + + ret = _get_play_position(player, &pos); + if (ret == PLAYER_ERROR_NONE) { + *nanoseconds = pos; + } + + return ret; +} + int player_set_mute(player_h player, bool muted) { PLAYER_INSTANCE_CHECK(player); @@ -2691,28 +2764,73 @@ int player_is_looping(player_h player, bool * plooping) return ret; } -int player_get_duration(player_h player, int *pduration) +static int _get_duration(player_h player, int64_t *duration) { PLAYER_INSTANCE_CHECK(player); - PLAYER_NULL_ARG_CHECK(pduration); + PLAYER_NULL_ARG_CHECK(duration); + int ret = PLAYER_ERROR_NONE; muse_player_api_e api = MUSE_PLAYER_API_GET_DURATION; player_cli_s *pc = (player_cli_s *) player; char *ret_buf = NULL; - int duration = 0; LOGD("ENTER"); PLAYER_SEND_MSG(api, pc, ret_buf, ret); if (ret == PLAYER_ERROR_NONE) { - player_msg_get(duration, ret_buf); - *pduration = duration; + bool ret_val = true; + ret_val = _player_get_param_value(ret_buf, + MUSE_TYPE_INT64, "duration", (void *)duration, + INVALID_MUSE_TYPE_VALUE); + if (!ret_val) { + ret = PLAYER_ERROR_INVALID_OPERATION; + } } g_free(ret_buf); return ret; } + +int player_get_duration(player_h player, int *milliseconds) +{ + PLAYER_INSTANCE_CHECK(player); + PLAYER_NULL_ARG_CHECK(milliseconds); + + int ret = PLAYER_ERROR_NONE; + int64_t duration = 0; /* nsec */ + + LOGD("ENTER"); + + ret = _get_duration(player, &duration); + if (ret == PLAYER_ERROR_NONE) { + /* convert time from ns to ms */ + *milliseconds = (int)(duration / G_GINT64_CONSTANT(1000000)); + } + + LOGD("LEAVE 0x%X", ret); + return ret; +} + +int player_get_duration_nsec(player_h player, int64_t *nanoseconds) +{ + PLAYER_INSTANCE_CHECK(player); + PLAYER_NULL_ARG_CHECK(nanoseconds); + + int ret = PLAYER_ERROR_NONE; + int64_t duration = 0; /* nsec */ + + LOGD("ENTER"); + + ret = _get_duration(player, &duration); + if (ret == PLAYER_ERROR_NONE) { + *nanoseconds = duration; + } + + LOGD("LEAVE 0x%X", ret); + return ret; +} + /* The player_display_type_e is different at wearable profile */ int _player_convert_display_type(player_display_type_e type, player_private_display_type_e *out_type) { @@ -3626,7 +3744,7 @@ int player_set_subtitle_path(player_h player, const char *path) return ret; } -int player_set_subtitle_position_offset(player_h player, int millisecond) +int player_set_subtitle_position_offset(player_h player, int milliseconds) { PLAYER_INSTANCE_CHECK(player); int ret = PLAYER_ERROR_NONE; @@ -3636,7 +3754,7 @@ int player_set_subtitle_position_offset(player_h player, int millisecond) LOGD("ENTER"); - PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "millisecond", millisecond); + PLAYER_SEND_MSG(api, pc, ret_buf, ret, MUSE_TYPE_INT, "milliseconds", milliseconds); g_free(ret_buf); return ret; -- 2.7.4