Add API - espp_client_get_playing_time()
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 15 May 2023 02:11:11 +0000 (11:11 +0900)
committer이상철/Tizen Platform Lab(SR)/삼성전자 <sc11.lee@samsung.com>
Mon, 15 May 2023 08:22:29 +0000 (17:22 +0900)
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
src/client/espp_service_client.c
src/client/espp_service_client.h
src/client/espp_service_client_priv.h
src/client/espp_service_client_socket.c
src/common/espp_service_ipc.c
src/common/espp_service_ipc.h
src/daemon/espp_service_handler.c

index 21f6757a58f120192c22bca12836cfe06238b5a4..ccf83bbc437e8d372188bd263b43393d835cfbbc 100644 (file)
@@ -381,6 +381,24 @@ int espp_client_get_state(espp_h espp, espp_state_e *state)
        return ESPP_CLIENT_ERROR_NONE;
 }
 
+int espp_client_get_playing_time(espp_h espp, uint64_t *time_ms)
+{
+       espp_s *_espp = (espp_s *)espp;
+       g_autoptr(GMutexLocker) locker = NULL;
+
+       RET_VAL_IF(!espp, ESPP_CLIENT_ERROR_INVALID_PARAMETER, "espp is NULL");
+       RET_VAL_IF(!time_ms, ESPP_CLIENT_ERROR_INVALID_PARAMETER, "time_ms is NULL");
+
+       locker = g_mutex_locker_new(&_espp->mutex);
+
+       if (espp_service_client_socket_request_get_playing_time(_espp, time_ms) != 0)
+               return ESPP_CLIENT_ERROR_INVALID_OPERATION;
+
+       LOG_INFO("espp[%p] time_ms[%" PRIu64 "]", espp, *time_ms);
+
+       return ESPP_CLIENT_ERROR_NONE;
+}
+
 int espp_client_set_audio_stream_info(espp_h espp, espp_audio_stream_info_s *info)
 {
        espp_s *_espp = (espp_s *)espp;
index 062b2e7fc108cbd92ba16ce7c462f2e31eee6eb9..447ce968d3d7364743a5336a3d7307202b1dbdca 100644 (file)
@@ -489,7 +489,7 @@ int espp_client_prepare_async(espp_h espp);
 int espp_client_seek(espp_h espp, uint64_t time_ms);
 
 /**
- * @brief Gets current stats of the ESPP service client handle.
+ * @brief Gets the current stats of the ESPP service client handle.
  * @param[in] espp    ESPP service client handle
  * @param[out] state  The state of the handle
  * @return @c 0 on success,
@@ -501,6 +501,20 @@ int espp_client_seek(espp_h espp, uint64_t time_ms);
  */
 int espp_client_get_state(espp_h espp, espp_state_e *state);
 
+/**
+ * @brief Gets the current playing time of the ESPP service client handle.
+ * @param[in] espp      ESPP service client handle
+ * @param[out] time_ms  The playing time in milliseconds
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #ESPP_CLIENT_ERROR_NONE Successful
+ * @retval #ESPP_CLIENT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ESPP_CLIENT_ERROR_INVALID_OPERATION Invalid operation
+ * @pre The state must be #ESPP_STATE_PAUSED or #ESPP_STATE_PLAYING.
+ * @see espp_client_prepare_async()
+ */
+int espp_client_get_playing_time(espp_h espp, uint64_t *time_ms);
+
 /**
  * @brief Sets the audio stream information to the ESPP service client handle.
  * @remarks This function must be called before calling the espp_client_prepare_async().
index 1932711d079807c770b60f8b6f0b75cd6997068a..dec45c6909c451644b87dcf5d5f60658b5c37d86 100644 (file)
@@ -80,6 +80,7 @@ int espp_service_client_socket_request_resume(espp_s *espp);
 int espp_service_client_socket_request_prepare_async(espp_s *espp);
 int espp_service_client_socket_request_seek(espp_s *espp, uint64_t time_ms);
 int espp_service_client_socket_request_get_state(espp_s *espp, espp_state_e *state);
+int espp_service_client_socket_request_get_playing_time(espp_s *espp, uint64_t *time_ms);
 int espp_service_client_socket_request_set_audio_stream_info(espp_s *espp, espp_audio_stream_info_s *info);
 int espp_service_client_socket_request_set_video_stream_info(espp_s *espp, espp_video_stream_info_s *info);
 int espp_service_client_socket_request_set_display_surface_id(espp_s *espp, espp_display_type_e type, unsigned int surface_id, int x, int y, int w, int h);
index 1bc8e175eed8c484c7bf5920fef538fcba60ac69..c0c56f7e392f3ad0ed5afc68596eab5ba69bf4ca 100644 (file)
@@ -498,6 +498,29 @@ int espp_service_client_socket_request_get_state(espp_s *espp, espp_state_e *sta
        return 0;
 }
 
+int espp_service_client_socket_request_get_playing_time(espp_s *espp, uint64_t *time_ms)
+{
+       espp_service_data_from_client_s data;
+       espp_service_data_from_server_s result;
+
+       ASSERT(espp);
+       ASSERT(time_ms);
+
+       RET_VAL_IF(espp->fd == -1, -1, "fd is -1");
+
+       FILL_SOCKET_MSG_REQUEST(data, ESPP_SERVICE_REQUEST_GET_PLAYING_TIME);
+       if (send_data(espp->fd, &data, &result) != 0)
+               return -1;
+
+       RET_VAL_IF_SERVER_RESULT_ERROR(result, -1);
+
+       LOG_DEBUG("espp[%p], fd[%d]", espp, espp->fd);
+
+       *time_ms = result.ret_time;
+
+       return 0;
+}
+
 int espp_service_client_socket_request_set_audio_stream_info(espp_s *espp, espp_audio_stream_info_s *info)
 {
        espp_service_data_from_client_s data;
index d5f40c5c39fe17f84c89bcf706560a2dd79b38c9..fc075094aa5cc27a069b7219c99d99222662202a 100644 (file)
@@ -30,6 +30,7 @@ espp_service_ipc_data_s requests[] = {
        [ESPP_SERVICE_REQUEST_PREPARE_ASYNC] = { "PrepareAsync", NULL },
        [ESPP_SERVICE_REQUEST_SEEK] = { "Seek", "k" },
        [ESPP_SERVICE_REQUEST_GET_STATE] = { "GetState", NULL },
+       [ESPP_SERVICE_REQUEST_GET_PLAYING_TIME] = { "GetPlayingTime", NULL },
        [ESPP_SERVICE_REQUEST_SET_AUDIO_STREAM_INFO] = { "SetAudioStreamInfo", "suiuuu" },
        [ESPP_SERVICE_REQUEST_SET_VIDEO_STREAM_INFO] = { "SetVideoStreamInfo", "suiuuuuuu" },
        [ESPP_SERVICE_REQUEST_SET_DISPLAY_SURFACE_ID] = { "SetDisplaySurfaceId", "iuiiii" },
index 6a6773d06071e09fb0508b61aca2a5f5742cc72c..85e669a399529ebe1bbf3503865435cd28f8338d 100644 (file)
@@ -39,6 +39,7 @@ typedef enum {
        ESPP_SERVICE_REQUEST_PREPARE_ASYNC,
        ESPP_SERVICE_REQUEST_SEEK,
        ESPP_SERVICE_REQUEST_GET_STATE,
+       ESPP_SERVICE_REQUEST_GET_PLAYING_TIME,
        ESPP_SERVICE_REQUEST_SET_AUDIO_STREAM_INFO,
        ESPP_SERVICE_REQUEST_SET_VIDEO_STREAM_INFO,
        ESPP_SERVICE_REQUEST_SET_DISPLAY_SURFACE_ID,
@@ -84,6 +85,7 @@ typedef struct {
        union {
                int ret;
                espp_service_event_e event;
+               uint64_t ret_time;
        };
        char params[MAX_PARAMS_LEN];
 } espp_service_data_from_server_s;
index 602b242a7b6bcfd3dfc2e71cae73af563b33a5a8..56ed60128ff8597c2970b57518258d5e429ba608 100644 (file)
@@ -326,6 +326,29 @@ static void __handle_get_state(handler_userdata_s *hdata, espp_service_data_from
        result->ret = ret;
 }
 
+static void __handle_get_playing_time(handler_userdata_s *hdata, espp_service_data_from_client_s *data, espp_service_data_from_server_s *result)
+{
+       int ret;
+       uint64_t time_ms;
+
+       ASSERT(hdata);
+       ASSERT(data);
+       ASSERT(result);
+       ASSERT(hdata->svc);
+       ASSERT(hdata->fd >= 0);
+
+       result->ret = -1;
+
+       RET_IF(!g_hash_table_lookup(hdata->svc->fd_table, hdata->key), "failed to g_hash_table_lookup(), key[%s]", hdata->key);
+
+       ret = esplusplayer_get_playing_time((esplusplayer_handle)hdata->espp, &time_ms);
+       RET_IF(ret != ESPLUSPLAYER_ERROR_TYPE_NONE, "failed to esplusplayer_get_playing_time(), ESPP[%p]", hdata->espp);
+
+       LOG_INFO("fd[%d], ESPP[%p]: esplusplayer_get_playing_time() success, time_ms[%" PRIu64 "]", hdata->fd, hdata->espp, time_ms);
+
+       result->ret_time = time_ms;
+}
+
 static void __handle_set_audio_stream_info(handler_userdata_s *hdata, espp_service_data_from_client_s *data, espp_service_data_from_server_s *result)
 {
        int ret;
@@ -783,6 +806,7 @@ static func_handler handlers[] = {
        [ESPP_SERVICE_REQUEST_PREPARE_ASYNC] = __handle_prepare_async,
        [ESPP_SERVICE_REQUEST_SEEK] = __handle_seek,
        [ESPP_SERVICE_REQUEST_GET_STATE] = __handle_get_state,
+       [ESPP_SERVICE_REQUEST_GET_PLAYING_TIME] = __handle_get_playing_time,
        [ESPP_SERVICE_REQUEST_SET_AUDIO_STREAM_INFO] = __handle_set_audio_stream_info,
        [ESPP_SERVICE_REQUEST_SET_VIDEO_STREAM_INFO] = __handle_set_video_stream_info,
        [ESPP_SERVICE_REQUEST_SET_DISPLAY_SURFACE_ID] = __handle_set_display_surface_id,