Add sub function for media packet format 32/270032/4
authorJeongmo Yang <jm80.yang@samsung.com>
Mon, 24 Jan 2022 11:35:07 +0000 (20:35 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 26 Jan 2022 10:56:37 +0000 (10:56 +0000)
- Minor change
 : Rename some static functions.

[Version] 0.4.73
[Issue Type] Update

Change-Id: Ic24589c732f717c154c6291f3500a9f6ba7b327f
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
packaging/capi-media-camera.spec
src/camera.c

index cf5246c..cc214eb 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-camera
 Summary:    A Camera API
-Version:    0.4.72
+Version:    0.4.73
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index bb180cd..661140a 100644 (file)
@@ -47,11 +47,11 @@ static int g_camera_log_level = CAMERA_LOG_LEVEL_INFO;
 static bool __camera_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_handle *bo_handle);
 static void __camera_release_imported_bo(tbm_bo *bo);
 
-static int __camera_media_packet_create(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream,
+static int __camera_create_media_packet(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream,
        camera_media_packet_data *mp_data, media_packet_h *packet);
-static int __camera_media_packet_data_create(int ret_fd, int *tfd, int num_buffer_fd, tbm_bo bo,
+static int __camera_create_media_packet_data(int ret_fd, int *tfd, int num_buffer_fd, tbm_bo bo,
        tbm_bo *buffer_bo, tbm_bo data_bo, camera_media_packet_data **mp_data);
-static void __camera_media_packet_data_release(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info);
+static void __camera_release_media_packet_data(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info);
 
 static gboolean __camera_allocate_preview_buffer(camera_h camera);
 static void __camera_release_preview_buffer(camera_h camera);
@@ -373,16 +373,16 @@ static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv
        if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] ||
                cb_info->is_evas_render ||
                cb_info->bridge) {
-               ret = __camera_media_packet_data_create(ret_fd, tfd, num_buffer_fd, bo, buffer_bo, data_bo, &mp_data);
+               ret = __camera_create_media_packet_data(ret_fd, tfd, num_buffer_fd, bo, buffer_bo, data_bo, &mp_data);
                if (ret != CAMERA_ERROR_NONE) {
-                       CAM_LOG_ERROR("__camera_media_packet_data_create failed[0x%x]", ret);
+                       CAM_LOG_ERROR("__camera_create_media_packet_data failed[0x%x]", ret);
                        goto _PREVIEW_CB_HANDLER_DONE;
                }
 
-               ret = __camera_media_packet_create(cb_info, stream, mp_data, &pkt);
+               ret = __camera_create_media_packet(cb_info, stream, mp_data, &pkt);
                if (ret != CAMERA_ERROR_NONE) {
-                       CAM_LOG_ERROR("__camera_media_packet_create failed[0x%x]", ret);
-                       __camera_media_packet_data_release(mp_data, cb_info);
+                       CAM_LOG_ERROR("__camera_create_media_packet failed[0x%x]", ret);
+                       __camera_release_media_packet_data(mp_data, cb_info);
                        mp_data = NULL;
                        goto _PREVIEW_CB_HANDLER_DONE;
                }
@@ -1018,7 +1018,7 @@ int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mi
 }
 
 
-static int __camera_media_packet_data_create(int ret_fd, int *tfd, int num_buffer_fd, tbm_bo bo,
+static int __camera_create_media_packet_data(int ret_fd, int *tfd, int num_buffer_fd, tbm_bo bo,
        tbm_bo *buffer_bo, tbm_bo data_bo, camera_media_packet_data **mp_data)
 {
        int i = 0;
@@ -1069,7 +1069,7 @@ static int __camera_media_packet_data_create(int ret_fd, int *tfd, int num_buffe
        return ret;
 }
 
-static void __camera_media_packet_data_release(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info)
+static void __camera_release_media_packet_data(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info)
 {
        int i = 0;
 
@@ -1230,21 +1230,17 @@ static tbm_surface_h __camera_get_tbm_surface(MMCamcorderVideoStreamDataType *st
 }
 
 
-static int __camera_media_packet_create(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream,
-       camera_media_packet_data *mp_data, media_packet_h *packet)
+static int __camera_update_media_packet_format(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream)
 {
-       media_packet_h pkt = NULL;
-       bool make_pkt_fmt = false;
-       tbm_surface_h tsurf = NULL;
-       media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
-       int ret = 0;
+       int ret = CAMERA_ERROR_NONE;
        int pkt_fmt_width = 0;
        int pkt_fmt_height = 0;
+       bool make_pkt_fmt = false;
+       media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
        media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
 
-       if (cb_info == NULL || stream == NULL || mp_data == NULL || packet == NULL) {
-               CAM_LOG_ERROR("invalid parameter - cb_info:%p, stream:%p, mp_data:%p, packet:%p",
-                       cb_info, stream, mp_data, packet);
+       if (!cb_info || !stream) {
+               CAM_LOG_ERROR("invalid parameter - %p, %p", cb_info, stream);
                return CAMERA_ERROR_INVALID_PARAMETER;
        }
 
@@ -1252,25 +1248,6 @@ static int __camera_media_packet_create(camera_cb_info_s *cb_info, MMCamcorderVi
        if (ret != CAMERA_ERROR_NONE)
                return ret;
 
-       switch (stream->data_type) {
-       case MM_CAM_STREAM_DATA_ENCODED:
-               /* TODO */
-               break;
-       case MM_CAM_STREAM_DATA_DEPTH:
-               /* TODO */
-               break;
-       case MM_CAM_STREAM_DATA_RGB:
-               break;
-       default: /* YUV */
-               tsurf = __camera_get_tbm_surface(stream, mp_data);
-               if (!tsurf) {
-                       CAM_LOG_ERROR("tbm surface failed. %dx%d, format %d, num_buffer_fd %d, data_bo %p",
-                               stream->width, stream->height, stream->format, mp_data->num_buffer_fd, mp_data->data_bo);
-                       return CAMERA_ERROR_INVALID_OPERATION;
-               }
-               break;
-       }
-
        /* check media packet format */
        if (cb_info->pkt_fmt) {
                media_format_get_video_info(cb_info->pkt_fmt,
@@ -1300,19 +1277,59 @@ static int __camera_media_packet_create(camera_cb_info_s *cb_info, MMCamcorderVi
 
                ret = media_format_create(&cb_info->pkt_fmt);
                if (ret != MEDIA_FORMAT_ERROR_NONE) {
-                       CAM_LOG_WARNING("media_format_create failed 0x%x", ret);
-                       goto _PACKET_CREATE_FAILED;
+                       CAM_LOG_ERROR("media_format_create failed 0x%x", ret);
+                       return CAMERA_ERROR_INVALID_OPERATION;
                }
 
                ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
                ret |= media_format_set_video_width(cb_info->pkt_fmt, stream->width);
                ret |= media_format_set_video_height(cb_info->pkt_fmt, stream->height);
                if (ret != MEDIA_FORMAT_ERROR_NONE) {
-                       CAM_LOG_WARNING("media format set failed 0x%x", ret);
-                       goto _PACKET_CREATE_FAILED;
+                       CAM_LOG_ERROR("media format set failed 0x%x", ret);
+                       return CAMERA_ERROR_INVALID_OPERATION;
                }
        }
 
+       return CAMERA_ERROR_NONE;
+}
+
+
+static int __camera_create_media_packet(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream,
+       camera_media_packet_data *mp_data, media_packet_h *packet)
+{
+       media_packet_h pkt = NULL;
+       tbm_surface_h tsurf = NULL;
+       int ret = 0;
+
+       if (!cb_info || !stream || !mp_data || !packet) {
+               CAM_LOG_ERROR("invalid parameter - %p, %p, %p, %p",
+                       cb_info, stream, mp_data, packet);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = __camera_update_media_packet_format(cb_info, stream);
+       if (ret != CAMERA_ERROR_NONE)
+               return ret;
+
+       switch (stream->data_type) {
+       case MM_CAM_STREAM_DATA_ENCODED:
+               /* TODO */
+               break;
+       case MM_CAM_STREAM_DATA_DEPTH:
+               /* TODO */
+               break;
+       case MM_CAM_STREAM_DATA_RGB:
+               break;
+       default: /* YUV */
+               tsurf = __camera_get_tbm_surface(stream, mp_data);
+               if (!tsurf) {
+                       CAM_LOG_ERROR("tbm surface failed. %dx%d, format %d, num_buffer_fd %d, data_bo %p",
+                               stream->width, stream->height, stream->format, mp_data->num_buffer_fd, mp_data->data_bo);
+                       return CAMERA_ERROR_INVALID_OPERATION;
+               }
+               break;
+       }
+
        /* create media packet */
        ret = media_packet_new_from_tbm_surface(cb_info->pkt_fmt,
                tsurf, (media_packet_dispose_cb)_camera_media_packet_dispose,
@@ -1378,7 +1395,7 @@ void _camera_media_packet_dispose(media_packet_h pkt, void *user_data)
                pkt, mp_data, tsurf);
 
        g_mutex_lock(&cb_info->mp_data_mutex);
-       __camera_media_packet_data_release(mp_data, cb_info);
+       __camera_release_media_packet_data(mp_data, cb_info);
        g_mutex_unlock(&cb_info->mp_data_mutex);
 
        if (tsurf)