Add API - espp_client_set_ready_to_seek_cb()
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 15 May 2023 07:19:47 +0000 (16:19 +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_event_handler.c
src/client/espp_service_client_priv.h
src/common/espp_service_ipc.c
src/common/espp_service_ipc.h
src/daemon/espp_service_handler.c

index af8dfc1c193712bb7863efd940dde5cd7540d5db..608137f7253868800a0b0515f55379a957e0d945 100644 (file)
@@ -67,6 +67,31 @@ int espp_client_set_prepare_async_done_cb(espp_h espp, espp_prepare_async_done_c
        return ESPP_CLIENT_ERROR_NONE;
 }
 
+int espp_client_set_ready_to_seek_cb(espp_h espp, espp_ready_to_seek_cb callback, void *user_data)
+{
+       espp_s *_espp = (espp_s *)espp;
+       g_autoptr(GMutexLocker) locker = NULL;
+       g_autoptr(GMutexLocker) cb_locker = NULL;
+
+       RET_VAL_IF(!espp, ESPP_CLIENT_ERROR_INVALID_PARAMETER, "espp is NULL");
+       RET_VAL_IF(!callback, ESPP_CLIENT_ERROR_INVALID_PARAMETER, "callback is NULL");
+
+       locker = g_mutex_locker_new(&_espp->mutex);
+
+       if (espp_service_client_socket_request_set_callback(_espp, ESPP_SERVICE_EVENT_CB_READY_TO_SEEK, (void *)callback, user_data) != 0)
+               return ESPP_CLIENT_ERROR_INVALID_OPERATION;
+
+       cb_locker = g_mutex_locker_new(&_espp->cb_mutex);
+       LOG_WARNING_IF_CALLBACK_EXISTS(_espp->ready_to_seek_cb);
+
+       _espp->ready_to_seek_cb.callback = callback;
+       _espp->ready_to_seek_cb.user_data = user_data;
+
+       LOG_INFO("espp[%p] callback[%p] user_data[%p]", espp, callback, user_data);
+
+       return ESPP_CLIENT_ERROR_NONE;
+}
+
 int espp_client_set_seek_done_cb(espp_h espp, espp_seek_done_cb callback, void *user_data)
 {
        espp_s *_espp = (espp_s *)espp;
index 01b226981aefbecb654c456b029c78542bdb1279..e5b61eb1cb1a6ebf09a56e424b8a0255169777ab 100644 (file)
@@ -199,10 +199,11 @@ typedef struct {
 } espp_packet_s;
 
 /**
- * @brief Called when when the ESPP service client handle is prepared to receive es packets after calling espp_client_prepare_async().
+ * @brief Called when when the ESPP service client handle is prepared to receive ESPP packets after calling espp_client_prepare_async().
  * @param[in] stream_type  The stream type
  * @param[in] user_data    The user data passed from the callback registration function
  * @see espp_client_set_ready_to_prepare_cb()
+ * @see espp_client_submit_packet()
  */
 typedef void (*espp_ready_to_prepare_cb)(espp_stream_type_e stream_type, void *user_data);
 
@@ -211,13 +212,27 @@ typedef void (*espp_ready_to_prepare_cb)(espp_stream_type_e stream_type, void *u
  * @param[in] result       The result (@c true = success, @c false = failure)
  * @param[in] user_data    The user data passed from the callback registration function
  * @see espp_client_set_prepare_async_done_cb()
+ * @see espp_client_submit_packet()
  */
 typedef void (*espp_prepare_async_done_cb)(bool result, void *user_data);
 
+/**
+ * @brief Called when the ESPP service client handle is prepared to receive ESPP packets after calling espp_client_seek().
+ * @param[in] stream_type  The stream type
+ * @param[in] time_ms      The seek time in milliseconds
+ * @param[in] user_data    The user data passed from the callback registration function
+ * @see espp_client_set_ready_to_seek_cb()
+ * @see espp_client_seek()
+ * @see espp_client_submit_packet()
+ */
+typedef void (*espp_ready_to_seek_cb)(espp_stream_type_e stream_type, uint64_t time_ms, void *user_data);
+
 /**
  * @brief Called when the seek operation of the ESPP service client handle has been finished.
  * @param[in] user_data    The user data passed from the callback registration function
  * @see espp_client_set_seek_done_cb()
+ * @see espp_client_seek()
+ * @see espp_client_submit_packet()
  */
 typedef void (*espp_seek_done_cb)(void *user_data);
 
@@ -245,7 +260,7 @@ typedef void (*espp_buffer_status_cb)(espp_stream_type_e stream_type, espp_buffe
 typedef void (*espp_resource_conflicted_cb)(void *user_data);
 
 /**
- * @brief Sets a callback function to be invoked when the ESPP service client handle is prepared to receive es packets after calling espp_client_prepare_async().
+ * @brief Sets a callback function to be invoked when the ESPP service client handle is prepared to receive ESPP packets after calling espp_client_prepare_async().
  * @param[in] espp       ESPP service client handle
  * @param[in] callback   Callback function pointer
  * @param[in] user_data  The user data to be passed to the callback function
@@ -255,6 +270,8 @@ typedef void (*espp_resource_conflicted_cb)(void *user_data);
  * @retval #ESPP_CLIENT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #ESPP_CLIENT_ERROR_INVALID_OPERATION Invalid operation
  * @post espp_ready_to_prepare_cb() will be invoked.
+ * @see espp_client_prepare_async()
+ * @see espp_client_submit_packet()
  */
 int espp_client_set_ready_to_prepare_cb(espp_h espp, espp_ready_to_prepare_cb callback, void *user_data);
 
@@ -269,9 +286,27 @@ int espp_client_set_ready_to_prepare_cb(espp_h espp, espp_ready_to_prepare_cb ca
  * @retval #ESPP_CLIENT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #ESPP_CLIENT_ERROR_INVALID_OPERATION Invalid operation
  * @post espp_prepare_async_done_cb() will be invoked.
+ * @see espp_client_submit_packet()
  */
 int espp_client_set_prepare_async_done_cb(espp_h espp, espp_prepare_async_done_cb callback, void *user_data);
 
+/**
+ * @brief Sets a callback function to be invoked when the ESPP service client handle is prepared to receive ESPP packets after calling espp_client_seek().
+ * @param[in] espp       ESPP service client handle
+ * @param[in] callback   Callback function pointer
+ * @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 #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_NONE or #ESPP_STATE_IDLE.
+ * @post espp_ready_to_seek_cb() will be invoked.
+ * @see espp_client_seek()
+ * @see espp_client_submit_packet()
+ */
+int espp_client_set_ready_to_seek_cb(espp_h espp, espp_ready_to_seek_cb callback, void *user_data);
+
 /**
  * @brief Sets a callback function to be invoked when the seek operation of the ESPP service client handle has been finished.
  * @param[in] espp       ESPP service client handle
@@ -284,6 +319,7 @@ int espp_client_set_prepare_async_done_cb(espp_h espp, espp_prepare_async_done_c
  * @retval #ESPP_CLIENT_ERROR_INVALID_OPERATION Invalid operation
  * @post espp_seek_done_cb() will be invoked.
  * @see espp_client_seek()
+ * @see espp_client_submit_packet()
  */
 int espp_client_set_seek_done_cb(espp_h espp, espp_seek_done_cb callback, void *user_data);
 
@@ -652,9 +688,9 @@ int espp_client_set_audio_mute(espp_h espp, bool mute);
  * @retval #ESPP_CLIENT_ERROR_NONE Successful
  * @retval #ESPP_CLIENT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #ESPP_CLIENT_ERROR_INVALID_OPERATION Invalid operation
- * @pre This function must be called after espp_ready_to_prepare_cb() or espp_seek_done_cb() is invoked.
+ * @pre This function must be called after espp_ready_to_prepare_cb() or espp_ready_to_seek_cb() is invoked.
  * @see espp_ready_to_prepare_cb()
- * @see espp_seek_done_cb()
+ * @see espp_ready_to_seek_cb()
  * @see espp_buffer_status_cb()
  */
 int espp_client_submit_packet(espp_h espp, espp_packet_s *packet, espp_submit_error_e *error);
@@ -670,7 +706,7 @@ int espp_client_submit_packet(espp_h espp, espp_packet_s *packet, espp_submit_er
  * @retval #ESPP_CLIENT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #ESPP_CLIENT_ERROR_INVALID_OPERATION Invalid operation
  * @see espp_ready_to_prepare_cb()
- * @see espp_seek_done_cb()
+ * @see espp_ready_to_seek_cb()
  * @see espp_buffer_status_cb()
  */
 int espp_client_submit_eos_packet(espp_h espp, espp_stream_type_e stream_type, espp_submit_error_e *error);
index cda6ee98a1f8f64685e20112be0671d25c5d7efc..8ce9ed2be15490ac869c15c5d3e0217107e7d02e 100644 (file)
@@ -90,6 +90,31 @@ static void __handle_event_cb_prepare_async_done(espp_s *espp, espp_service_data
        result->ret = 0;
 }
 
+static void __handle_event_cb_ready_to_seek(espp_s *espp, espp_service_data_from_server_s *data, espp_service_data_from_client_s *result)
+{
+       int ret;
+       espp_stream_type_e stream_type;
+       uint64_t time_ms;
+
+       ASSERT(espp);
+       ASSERT(data);
+       ASSERT(result);
+
+       ret = espp_service_client_msg_parse_params(data->params, data->event, &stream_type, &time_ms);
+       if (ret != 0)
+               return;
+
+       LOG_INFO("cb params[stream_type:%d, time_ms:%" PRIu64 "]", stream_type, time_ms);
+
+       if (espp->ready_to_seek_cb.callback) {
+               LOG_DEBUG(">>> callback[%p] user_data[%p]", espp->ready_to_seek_cb.callback, espp->ready_to_seek_cb.user_data);
+               ((espp_ready_to_seek_cb)(espp->ready_to_seek_cb.callback))(stream_type, time_ms, espp->ready_to_seek_cb.user_data);
+               LOG_DEBUG("<<< end of the callback");
+       }
+
+       result->ret = 0;
+}
+
 static void __handle_event_cb_seek_done(espp_s *espp, espp_service_data_from_server_s *data, espp_service_data_from_client_s *result)
 {
        ASSERT(espp);
@@ -166,6 +191,7 @@ static func_handler handlers[] = {
        [ESPP_SERVICE_EVENT_MSG] = __handle_event_msg,
        [ESPP_SERVICE_EVENT_CB_READY_TO_PREPARE] = __handle_event_cb_ready_to_prepare,
        [ESPP_SERVICE_EVENT_CB_PREPARE_ASYNC_DONE] = __handle_event_cb_prepare_async_done,
+       [ESPP_SERVICE_EVENT_CB_READY_TO_SEEK] = __handle_event_cb_ready_to_seek,
        [ESPP_SERVICE_EVENT_CB_SEEK_DONE] = __handle_event_cb_seek_done,
        [ESPP_SERVICE_EVENT_CB_EOS] = __handle_event_cb_eos,
        [ESPP_SERVICE_EVENT_CB_BUFFER_STATUS] = __handle_event_cb_buffer_status,
index a900b1eefb854f6542f3723c99e97817912cfed1..1c25a764517da35976f30a69c3fcf971808bd095 100644 (file)
@@ -59,6 +59,7 @@ typedef struct _espp_s {
 
        espp_callback_s ready_to_prepare_cb;
        espp_callback_s prepare_async_done_cb;
+       espp_callback_s ready_to_seek_cb;
        espp_callback_s seek_done_cb;
        espp_callback_s eos_cb;
        espp_callback_s buffer_status_cb;
index c9eb3e5716aea3403a3762f456a2af5adca39bb4..8cfeb8bff74a9610499c1e91d026a841cf084dd5 100644 (file)
@@ -49,6 +49,7 @@ espp_service_ipc_data_s events[] = {
        [ESPP_SERVICE_EVENT_MSG] = { "Message", "s" },
        [ESPP_SERVICE_EVENT_CB_READY_TO_PREPARE] = { "ReadyToPrepareCB", "i" },
        [ESPP_SERVICE_EVENT_CB_PREPARE_ASYNC_DONE] = { "PrepareAsyncDoneCB", "b" },
+       [ESPP_SERVICE_EVENT_CB_READY_TO_SEEK] = { "ReadyToSeekCB", "ik" },
        [ESPP_SERVICE_EVENT_CB_SEEK_DONE] = { "SeekDoneCB", NULL },
        [ESPP_SERVICE_EVENT_CB_EOS] = { "EosCB", NULL },
        [ESPP_SERVICE_EVENT_CB_BUFFER_STATUS] = { "BufferStatusCB", "ii" },
index 11b1375cf1646f009a9b41cfe3c2b2ad07e141ac..7ac3381df72e7c2fb2ef07e927061357a34d5a86 100644 (file)
@@ -58,6 +58,7 @@ typedef enum {
        ESPP_SERVICE_EVENT_MSG,
        ESPP_SERVICE_EVENT_CB_READY_TO_PREPARE,
        ESPP_SERVICE_EVENT_CB_PREPARE_ASYNC_DONE,
+       ESPP_SERVICE_EVENT_CB_READY_TO_SEEK,
        ESPP_SERVICE_EVENT_CB_SEEK_DONE,
        ESPP_SERVICE_EVENT_CB_EOS,
        ESPP_SERVICE_EVENT_CB_BUFFER_STATUS,
index 4df647f703edcd5967d93443a5124e5b4042f003..4e979e9f41fb422a09de5e187fddb079451fc03f 100644 (file)
@@ -703,6 +703,29 @@ static void __prepare_async_done_cb(bool res, void *user_data)
        espp_service_send_data(tbs->event_fd, &data);
 }
 
+static void __ready_to_seek_cb(const int type, uint64_t time_ms, void *user_data)
+{
+       handler_userdata_s *hdata = (handler_userdata_s *)user_data;
+       tb_data_s *tbs;
+       espp_service_data_from_server_s data;
+
+       ASSERT(hdata);
+       ASSERT(hdata->svc);
+       ASSERT(hdata->fd >= 0);
+
+       LOG_DEBUG("type[%d], fd[%d], ESPP[%p]", type, hdata->fd, hdata->espp);
+
+       RET_IF(!(tbs = g_hash_table_lookup(hdata->svc->fd_table, hdata->key)), "failed to g_hash_table_lookup(), key[%s]", hdata->key);
+
+       LOG_DEBUG("event_fd[%d], ESPP[%p]", tbs->event_fd, tbs->espp);
+
+       FILL_SOCKET_MSG_EVENT(data, ESPP_SERVICE_EVENT_CB_READY_TO_SEEK);
+       FILL_SOCKET_MSG_PARAMS(data, ESPP_SERVICE_EVENT_CB_READY_TO_SEEK,
+               "type", type, "time_ms", time_ms);
+
+       espp_service_send_data(tbs->event_fd, &data);
+}
+
 static void __seek_done_cb(void *user_data)
 {
        handler_userdata_s *hdata = (handler_userdata_s *)user_data;
@@ -788,6 +811,7 @@ static void __resource_conflicted_cb(void *user_data)
 static cb_intf_s cb_setters[] = {
        [ESPP_SERVICE_EVENT_CB_READY_TO_PREPARE] = { (set_cb_func)esplusplayer_set_ready_to_prepare_cb, __ready_to_prepare_cb},
        [ESPP_SERVICE_EVENT_CB_PREPARE_ASYNC_DONE] = { (set_cb_func)esplusplayer_set_prepare_async_done_cb, __prepare_async_done_cb},
+       [ESPP_SERVICE_EVENT_CB_READY_TO_SEEK] = { (set_cb_func)esplusplayer_set_ready_to_seek_cb, __ready_to_seek_cb},
        [ESPP_SERVICE_EVENT_CB_SEEK_DONE] = { (set_cb_func)esplusplayer_set_seek_done_cb, __seek_done_cb},
        [ESPP_SERVICE_EVENT_CB_EOS] = { (set_cb_func)esplusplayer_set_eos_cb, __eos_cb},
        [ESPP_SERVICE_EVENT_CB_BUFFER_STATUS] = { (set_cb_func)esplusplayer_set_buffer_status_cb, __buffer_status_cb},