Apply encoding/decoding codec_data for json structured string format
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 15 May 2023 10:56:10 +0000 (19:56 +0900)
committer이상철/Tizen Platform Lab(SR)/삼성전자 <sc11.lee@samsung.com>
Tue, 16 May 2023 06:41:30 +0000 (15:41 +0900)
The 'codec_data' member in the ESPP packet data is binary.
To get valid string by glib json API, this binary data is encrypted on the client side,
and it'll be decrypted on the daemon side before passing it to the glib json API.

Invalid range check for espp_service_event_e has been fixed.

[Version] 0.2.2

Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/espp-service.spec
src/client/espp_service_client_socket.c
src/daemon/espp_service_handler.c

index 9a8c1b7b0d685081a069524bea9d9c69568efd93..cc7298ac51ffb5c5a8a4c97476a21699b56f034d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       espp-service
 Summary:    ESPP service package which contains client lib. and daemon binary
-Version:    0.2.1
+Version:    0.2.2
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index ecfddd03df19e00c83fd2b756e5c528a6f9a25e6..762b4782ef20921a961e8c02885d4272b558995d 100644 (file)
@@ -525,14 +525,18 @@ int espp_service_client_socket_request_set_audio_stream_info(espp_s *espp, espp_
 {
        espp_service_data_from_client_s data;
        espp_service_data_from_server_s result;
+       g_autofree gchar *base64_codec_data = NULL;
 
        ASSERT(espp);
        ASSERT(info);
        RET_VAL_IF(espp->fd == -1, -1, "fd is -1");
 
+       /* NOTE that encoding 'codec_data' member with base64 to avoid parsing json string error on the daemon side. */
+       if (info->codec_data_length > 0)
+               base64_codec_data = g_base64_encode((guchar *)info->codec_data, info->codec_data_length);
        FILL_SOCKET_MSG_REQUEST(data, ESPP_SERVICE_REQUEST_SET_AUDIO_STREAM_INFO);
        FILL_SOCKET_MSG_PARAMS(data, ESPP_SERVICE_REQUEST_SET_AUDIO_STREAM_INFO,
-               "codec_data", info->codec_data, "codec_data_length", info->codec_data_length, "mime_type", info->mime_type,
+               "codec_data", base64_codec_data, "codec_data_length", info->codec_data_length, "mime_type", info->mime_type,
                "bitrate", info->bitrate, "channels", info->channels, "sample_rate", info->sample_rate);
        if (send_data(espp->fd, &data, &result) != 0)
                return -1;
@@ -548,14 +552,18 @@ int espp_service_client_socket_request_set_video_stream_info(espp_s *espp, espp_
 {
        espp_service_data_from_client_s data;
        espp_service_data_from_server_s result;
+       g_autofree gchar *base64_codec_data = NULL;
 
        ASSERT(espp);
        ASSERT(info);
        RET_VAL_IF(espp->fd == -1, -1, "fd is -1");
 
+       /* NOTE that encoding 'codec_data' member with base64 to avoid parsing json string error on the daemon side. */
+       if (info->codec_data_length > 0)
+               base64_codec_data = g_base64_encode((guchar *)info->codec_data, info->codec_data_length);
        FILL_SOCKET_MSG_REQUEST(data, ESPP_SERVICE_REQUEST_SET_VIDEO_STREAM_INFO);
        FILL_SOCKET_MSG_PARAMS(data, ESPP_SERVICE_REQUEST_SET_VIDEO_STREAM_INFO,
-               "codec_data", info->codec_data, "codec_data_length", info->codec_data_length, "mime_type", info->mime_type,
+               "codec_data", base64_codec_data, "codec_data_length", info->codec_data_length, "mime_type", info->mime_type,
                "width", info->width, "height", info->height, "max_width", info->max_width, "max_height", info->max_height,
                "framerate_num", info->framerate_num, "framerate_den", info->framerate_den);
        if (send_data(espp->fd, &data, &result) != 0)
index cb23f85ca21a13a524f3116c7ede83cf2bfccfcf..815dea7179ec1253847bc76152add24d495892cd 100644 (file)
@@ -353,6 +353,8 @@ static void __handle_set_audio_stream_info(handler_userdata_s *hdata, espp_servi
 {
        int ret;
        esplusplayer_audio_stream_info info;
+       g_autofree guchar *codec_data = NULL;
+       gsize len;
 
        ASSERT(hdata);
        ASSERT(data);
@@ -370,6 +372,13 @@ static void __handle_set_audio_stream_info(handler_userdata_s *hdata, espp_servi
        if (ret != 0)
                return;
 
+       /* NOTE that decoding 'codec_data' member with base64 here, see the client side. */
+       if (info.codec_data_length > 0) {
+               LOG_DEBUG("base64 codec_data[%s]", info.codec_data);
+               codec_data = g_base64_decode((gchar *)info.codec_data, &len);
+               ASSERT(len == info.codec_data_length);
+               info.codec_data = (char *)codec_data;
+       }
        ret = esplusplayer_set_audio_stream_info((esplusplayer_handle)hdata->espp, &info);
        RET_IF(ret != ESPLUSPLAYER_ERROR_TYPE_NONE, "failed to esplusplayer_set_audio_stream_info(), ESPP[%p]", hdata->espp);
 
@@ -382,6 +391,8 @@ static void __handle_set_video_stream_info(handler_userdata_s *hdata, espp_servi
 {
        int ret;
        esplusplayer_video_stream_info info;
+       g_autofree guchar *codec_data = NULL;
+       gsize len;
 
        ASSERT(hdata);
        ASSERT(data);
@@ -400,6 +411,13 @@ static void __handle_set_video_stream_info(handler_userdata_s *hdata, espp_servi
        if (ret != 0)
                return;
 
+       /* NOTE that decoding 'codec_data' member with base64 here, see the client side. */
+       if (info.codec_data_length > 0) {
+               LOG_DEBUG("base64 codec_data[%s]", info.codec_data);
+               codec_data = g_base64_decode((gchar *)info.codec_data, &len);
+               ASSERT(len == info.codec_data_length);
+               info.codec_data = (char *)codec_data;
+       }
        ret = esplusplayer_set_video_stream_info((esplusplayer_handle)hdata->espp, &info);
        RET_IF(ret != ESPLUSPLAYER_ERROR_TYPE_NONE, "failed to esplusplayer_set_video_stream_info(), ESPP[%p]", hdata->espp);
 
@@ -860,7 +878,7 @@ static void __handle_set_callback(handler_userdata_s *hdata, espp_service_data_f
        if (ret != 0)
                return;
 
-       RET_IF(cb_type < ESPP_SERVICE_EVENT_CB_READY_TO_PREPARE || cb_type > ESPP_SERVICE_EVENT_CB_RESOURCE_CONFLICTED,
+       RET_IF(cb_type < ESPP_SERVICE_EVENT_CB_READY_TO_PREPARE || cb_type > ESPP_SERVICE_EVENT_CB_ERROR,
                "invalid cb_type[%d]", cb_type);
 
        ret = cb_setters[cb_type].set_cb((esplusplayer_handle)hdata->espp, cb_setters[cb_type].callback, hdata);