Add API - espp_client_set_buffer_status_cb()
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 11 May 2023 01:48:25 +0000 (10:48 +0900)
committer이상철/Tizen Platform Lab(SR)/삼성전자 <sc11.lee@samsung.com>
Thu, 11 May 2023 05:35:24 +0000 (14:35 +0900)
[Version] 0.1.10

Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/espp-service.spec
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 3117543039aea43ae00596ae5d9fe3569e6aaaa9..989eb184fb3ec0c781b00c532fd42faff5196f01 100644 (file)
@@ -1,6 +1,6 @@
 Name:       espp-service
 Summary:    ESPP service package which contains client lib. and daemon binary
-Version:    0.1.9
+Version:    0.1.10
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 2e59325f24601bc11494ea64a8a21fea0d7c781f..fbd33a37d40ab6b079c46801929b7515b0ef3214 100644 (file)
@@ -109,6 +109,29 @@ int espp_client_set_eos_cb(espp_h espp, espp_eos_cb callback, void *user_data)
        return ESPP_CLIENT_ERROR_NONE;
 }
 
+int espp_client_set_buffer_status_cb(espp_h espp, espp_buffer_status_cb callback, void *user_data)
+{
+       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(!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_BUFFER_STATUS, (void *)callback, user_data) != 0)
+               return ESPP_CLIENT_ERROR_INVALID_OPERATION;
+
+       LOG_WARNING_IF_CALLBACK_EXISTS(_espp->buffer_status_cb);
+
+       _espp->buffer_status_cb.callback = callback;
+       _espp->buffer_status_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_resource_conflicted_cb(espp_h espp, espp_resource_conflicted_cb callback, void *user_data)
 {
        espp_s *_espp = (espp_s *)espp;
index 135a66121030a78e640f61a18d6a24d84806ac22..c4b8b81ebf8c61446caf71d35611230fe06acf87 100644 (file)
@@ -113,6 +113,14 @@ typedef enum {
        ESPP_DISPLAY_MODE_DST_ROI,          /**< Destination RoI */
 } espp_display_mode_e;
 
+/**
+ * @brief Enumerations for the buffer status
+ */
+typedef enum {
+       ESPP_BUFFER_STATUS_UNDERRUN,   /**< Underrun */
+       ESPP_BUFFER_STATUS_OVERRUN,    /**< Overrun */
+} espp_buffer_status_e;
+
 /**
  * @brief Enumerations for the submit error
  */
@@ -194,6 +202,15 @@ typedef void (*espp_seek_done_cb)(void *user_data);
  */
 typedef void (*espp_eos_cb)(void *user_data);
 
+/**
+ * @brief Called when the buffer of the ESPP service client handle faces underrun or overrun condition.
+ * @param[in] stream_type    The stream type
+ * @param[in] buffer_status  The buffer status
+ * @param[in] user_data      The user data passed from the callback registration function
+ * @see espp_client_set_buffer_status_cb()
+ */
+typedef void (*espp_buffer_status_cb)(espp_stream_type_e stream_type, espp_buffer_status_e buffer_status, void *user_data);
+
 /**
  * @brief Called when a H/W resource of the ESPP service client handle has been conflicted.
  * @param[in] user_data    The user data passed from the callback registration function
@@ -257,6 +274,20 @@ int espp_client_set_seek_done_cb(espp_h espp, espp_seek_done_cb callback, void *
  */
 int espp_client_set_eos_cb(espp_h espp, espp_eos_cb callback, void *user_data);
 
+/**
+ * @brief Sets a callback function to be invoked when the buffer of the ESPP service client handle faces underrun or overflow condition.
+ * @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
+ * @post espp_buffer_status_cb() will be invoked.
+ */
+int espp_client_set_buffer_status_cb(espp_h espp, espp_buffer_status_cb callback, void *user_data);
+
 /**
  * @brief Sets a callback function to be invoked when when a H/W resource of the ESPP service client handle has been conflicted.
  * @param[in] espp       ESPP service client handle
@@ -452,8 +483,10 @@ 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
- * @post espp_ready_to_prepare_cb() will be invoked.
+ * @pre This function must be called after espp_ready_to_prepare_cb() or espp_seek_done_cb() is invoked.
  * @see espp_ready_to_prepare_cb()
+ * @see espp_seek_done_cb()
+ * @see espp_buffer_status_cb()
  */
 int espp_client_submit_packet(espp_h espp, espp_packet_s *packet, espp_submit_error_e *error);
 
index 0892bce5420b34377cabb2fe78ed839a064f7bad..5e1a41cafc8af2cdde9ac93d440d83904921bbe5 100644 (file)
@@ -120,12 +120,40 @@ static void __handle_event_cb_eos(espp_s *espp, espp_service_data_from_server_s
        result->ret = 0;
 }
 
+static void __handle_event_cb_buffer_status(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;
+       espp_buffer_status_e buffer_status;
+
+       ASSERT(espp);
+       ASSERT(data);
+       ASSERT(result);
+
+       result->ret = -1;
+
+       ret = espp_service_client_msg_parse_params(data->params, data->event, &stream_type, &buffer_status);
+       if (ret != 0)
+               return;
+
+       LOG_INFO("cb params[stream_type:%d, buffer_status:%d]", stream_type, buffer_status);
+
+       if (espp->buffer_status_cb.callback) {
+               LOG_DEBUG(">>> callback[%p] user_data[%p]", espp->buffer_status_cb.callback, espp->buffer_status_cb.user_data);
+               ((espp_buffer_status_cb)(espp->buffer_status_cb.callback))(stream_type, buffer_status, espp->buffer_status_cb.user_data);
+               LOG_DEBUG("<<< end of the callback");
+       }
+
+       result->ret = 0;
+}
+
 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_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,
 };
 
 static void __func_handler(espp_s *espp, espp_service_data_from_server_s *data, espp_service_data_from_client_s *result)
index 13df858a1c5b27a01b92988676f39ac65b58c470..8e7900c92830455230faee50db7048db788bd818 100644 (file)
@@ -59,6 +59,7 @@ typedef struct _espp_s {
        espp_callback_s prepare_async_done_cb;
        espp_callback_s seek_done_cb;
        espp_callback_s eos_cb;
+       espp_callback_s buffer_status_cb;
        espp_callback_s resource_conflicted_cb;
 } espp_s;
 
index 0d7c73d0d4d9cbc9df41ae1f079c642f6e4546fc..58a6a26ad75e539b2dd35e2ced90ed33931a2e7c 100644 (file)
@@ -41,6 +41,7 @@ espp_service_ipc_data_s events[] = {
        [ESPP_SERVICE_EVENT_CB_PREPARE_ASYNC_DONE] = { "PrepareAsyncDoneCB", "b" },
        [ESPP_SERVICE_EVENT_CB_SEEK_DONE] = { "SeekDoneCB", NULL },
        [ESPP_SERVICE_EVENT_CB_EOS] = { "EosCB", NULL },
+       [ESPP_SERVICE_EVENT_CB_BUFFER_STATUS] = { "BufferStatusCB", "ii" },
        [ESPP_SERVICE_EVENT_CB_RESOURCE_CONFLICTED] = { "PrepareAsyncDoneCB", NULL },
 };
 
index 675ca8cca69c2cfff9d1928e77003739e6b96608..05afc2cd5b788538fae4fabc4b5aa852cdb6b54e 100644 (file)
@@ -50,6 +50,7 @@ typedef enum {
        ESPP_SERVICE_EVENT_CB_PREPARE_ASYNC_DONE,
        ESPP_SERVICE_EVENT_CB_SEEK_DONE,
        ESPP_SERVICE_EVENT_CB_EOS,
+       ESPP_SERVICE_EVENT_CB_BUFFER_STATUS,
        ESPP_SERVICE_EVENT_CB_RESOURCE_CONFLICTED,
 } espp_service_event_e;
 
index a70b0af3161b679016ff6c9c9c5a8b4cf755c2a9..426ac5d7b8c556e506eb8c31eab601469964830f 100644 (file)
@@ -495,6 +495,28 @@ static void __eos_cb(void *user_data)
        espp_service_send_data(tbs->event_fd, &data);
 }
 
+static void __buffer_status_cb(const int stream_type, const int buffer_status, 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("stream_type[%d], buffer_status[%d], fd[%d], ESPP[%p]", stream_type, buffer_status, 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_BUFFER_STATUS);
+       FILL_SOCKET_MSG_PARAMS(data, ESPP_SERVICE_EVENT_CB_BUFFER_STATUS,
+               "stream_type", stream_type, "buffer_status", buffer_status);
+       espp_service_send_data(tbs->event_fd, &data);
+}
+
 static void __resource_conflicted_cb(void *user_data)
 {
        handler_userdata_s *hdata = (handler_userdata_s *)user_data;
@@ -520,6 +542,7 @@ static cb_intf_s cb_setters[] = {
        [ESPP_SERVICE_EVENT_CB_PREPARE_ASYNC_DONE] = { (set_cb_func)esplusplayer_set_prepare_async_done_cb, __prepare_async_done_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},
        [ESPP_SERVICE_EVENT_CB_RESOURCE_CONFLICTED] = { (set_cb_func)esplusplayer_set_resource_conflicted_cb, __resource_conflicted_cb},
 };