Support encoded and RGB data in __camera_create_media_packet() 88/270288/5 accepted/tizen/unified/20220224.125816 submit/tizen/20220223.001807
authorJeongmo Yang <jm80.yang@samsung.com>
Thu, 27 Jan 2022 02:19:48 +0000 (11:19 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Mon, 14 Feb 2022 03:59:56 +0000 (12:59 +0900)
- Minor change
 : Remove unnecessary word in some function name.
 : Remove unnecessary comments.
 : Remove duplicated code.
 : Update _camera_media_packet_dispose().

[Version] 0.4.74
[Issue Type] Update

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

index aa95198..53d2978 100644 (file)
@@ -238,7 +238,7 @@ typedef struct _camera_device_manager {
 } camera_device_manager;
 
 
-int _camera_get_tbm_surface_format(int in_format, uint32_t *out_format);
+int _camera_get_tbm_format(int in_format, uint32_t *out_format);
 int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mimetype);
 void _camera_media_packet_dispose(media_packet_h pkt, void *user_data);
 int _camera_start_evas_rendering(camera_h camera);
index cc214eb..7143635 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-camera
 Summary:    A Camera API
-Version:    0.4.73
+Version:    0.4.74
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 661140a..c3f50cc 100644 (file)
@@ -314,14 +314,6 @@ static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv
                goto _PREVIEW_CB_HANDLER_DONE;
        }
 
-       if (num_buffer_fd == 0 && CAMERA_IS_FD_VALID(tfd[1])) {
-               /* import tbm data_bo and get virtual address */
-               if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[1], &data_bo, &data_bo_handle)) {
-                       CAM_LOG_ERROR("failed to import data fd %d", tfd[1]);
-                       goto _PREVIEW_CB_HANDLER_DONE;
-               }
-       }
-
        /* import tbm bo and get virtual address */
        if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[0], &bo, &bo_handle)) {
                CAM_LOG_ERROR("failed to import fd %d", tfd[0]);
@@ -333,6 +325,17 @@ static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv
        /* get stream info */
        stream = (MMCamcorderVideoStreamDataType *)buf_pos;
 
+       if (num_buffer_fd == 0 && CAMERA_IS_FD_VALID(tfd[1])) {
+               /* import tbm data_bo and get virtual address */
+               if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[1], &data_bo, &data_bo_handle)) {
+                       CAM_LOG_ERROR("failed to import data fd %d", tfd[1]);
+                       goto _PREVIEW_CB_HANDLER_DONE;
+               }
+
+               if (stream->data_type == MM_CAM_STREAM_DATA_ENCODED)
+                       stream->data.encoded.data = data_bo_handle.ptr;
+       }
+
        for (i = 0 ; i < num_buffer_fd ; i++) {
                /* import buffer bo and get virtual address */
                if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[i + 1], &buffer_bo[i], &buffer_bo_handle[i])) {
@@ -900,7 +903,7 @@ void _camera_msg_return_buffer(int ret_fd, camera_cb_info_s *cb_info)
 }
 
 
-int _camera_get_tbm_surface_format(int in_format, uint32_t *out_format)
+int _camera_get_tbm_format(int in_format, uint32_t *out_format)
 {
        if (in_format <= MM_PIXEL_FORMAT_INVALID ||
            in_format >= MM_PIXEL_FORMAT_NUM ||
@@ -1008,6 +1011,19 @@ int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mi
        case MM_PIXEL_FORMAT_ARGB:
                *mimetype = MEDIA_FORMAT_ARGB;
                break;
+       case MM_PIXEL_FORMAT_ENCODED_H264:
+               /* TODO: How can we determine the profile for H.264 format? */
+               *mimetype = MEDIA_FORMAT_H264_SP;
+               break;
+       case MM_PIXEL_FORMAT_ENCODED_MJPEG:
+               *mimetype = MEDIA_FORMAT_MJPEG;
+               break;
+       case MM_PIXEL_FORMAT_ENCODED_VP8:
+               *mimetype = MEDIA_FORMAT_VP8;
+               break;
+       case MM_PIXEL_FORMAT_ENCODED_VP9:
+               *mimetype = MEDIA_FORMAT_VP9;
+               break;
        default:
                CAM_LOG_ERROR("invalid in_format %d", in_format);
                return CAMERA_ERROR_INVALID_PARAMETER;
@@ -1125,9 +1141,8 @@ static tbm_surface_h __camera_get_tbm_surface(MMCamcorderVideoStreamDataType *st
 {
        int i = 0;
        int ret = CAMERA_ERROR_NONE;
-       int num_buffer_fd = 0;
-       uint32_t bo_format = 0;
-       tbm_bo *buffer_bo = NULL;
+       uint32_t tbm_format = 0;
+       tbm_bo bos[BUFFER_MAX_PLANE_NUM] = {NULL, };
        tbm_surface_info_s tsurf_info;
 
        if (!stream || !mp_data) {
@@ -1135,98 +1150,73 @@ static tbm_surface_h __camera_get_tbm_surface(MMCamcorderVideoStreamDataType *st
                return NULL;
        }
 
-       buffer_bo = mp_data->buffer_bo;
-       num_buffer_fd = mp_data->num_buffer_fd;
-
-       memset(&tsurf_info, 0x0, sizeof(tbm_surface_info_s));
-
-       for (i = 0 ; i < BUFFER_MAX_PLANE_NUM ; i++)
-               tsurf_info.planes[i].stride = stream->stride[i];
+       if (mp_data->num_buffer_fd < 1 && !mp_data->data_bo) {
+               CAM_LOG_ERROR("No valid data");
+               return NULL;
+       }
 
-       ret = _camera_get_tbm_surface_format(stream->format, &bo_format);
+       ret = _camera_get_tbm_format(stream->format, &tbm_format);
        if (ret != CAMERA_ERROR_NONE)
                return NULL;
 
+       memset(&tsurf_info, 0x0, sizeof(tbm_surface_info_s));
+
+       if (mp_data->num_buffer_fd > 0) {
+               for (i = 0 ; i < mp_data->num_buffer_fd ; i++)
+                       bos[i] = mp_data->buffer_bo[i];
+       } else {
+               bos[0] = mp_data->data_bo;
+       }
+
        tsurf_info.width = stream->width;
        tsurf_info.height = stream->height;
-       tsurf_info.format = bo_format;
-       tsurf_info.bpp = tbm_surface_internal_get_bpp(bo_format);
-       tsurf_info.num_planes = tbm_surface_internal_get_num_planes(bo_format);
-
-       if (num_buffer_fd > 0) {
-               switch (bo_format) {
-               case TBM_FORMAT_NV12:
-               case TBM_FORMAT_NV21:
-                       tsurf_info.planes[0].size = stream->stride[0] * stream->elevation[0];
-                       tsurf_info.planes[1].size = stream->stride[1] * stream->elevation[1];
-                       tsurf_info.planes[0].offset = 0;
-                       if (num_buffer_fd == 1)
-                               tsurf_info.planes[1].offset = tsurf_info.planes[0].size;
-                       tsurf_info.size = tsurf_info.planes[0].size + tsurf_info.planes[1].size;
-                       break;
-//LCOV_EXCL_START
-               case TBM_FORMAT_YUV420:
-               case TBM_FORMAT_YVU420:
-                       tsurf_info.planes[0].size = stream->stride[0] * stream->elevation[0];
-                       tsurf_info.planes[1].size = stream->stride[1] * stream->elevation[1];
-                       tsurf_info.planes[2].size = stream->stride[2] * stream->elevation[2];
-                       tsurf_info.planes[0].offset = 0;
-                       if (num_buffer_fd == 1) {
-                               tsurf_info.planes[1].offset = tsurf_info.planes[0].size;
-                               tsurf_info.planes[2].offset = tsurf_info.planes[0].size + tsurf_info.planes[1].size;
-                       }
-                       tsurf_info.size = tsurf_info.planes[0].size + tsurf_info.planes[1].size + tsurf_info.planes[2].size;
-                       break;
-               case TBM_FORMAT_UYVY:
-               case TBM_FORMAT_YUYV:
-                       tsurf_info.planes[0].size = (stream->stride[0] * stream->elevation[0]) << 1;
-                       tsurf_info.planes[0].offset = 0;
-                       tsurf_info.size = tsurf_info.planes[0].size;
-                       break;
-               default:
-                       break;
-//LCOV_EXCL_STOP
-               }
+       tsurf_info.format = tbm_format;
+       tsurf_info.bpp = tbm_surface_internal_get_bpp(tbm_format);
+       tsurf_info.num_planes = tbm_surface_internal_get_num_planes(tbm_format);
 
-               return tbm_surface_internal_create_with_bos(&tsurf_info, buffer_bo, num_buffer_fd);
-       } else if (mp_data->data_bo) {
-//LCOV_EXCL_START
-               switch (bo_format) {
-               case TBM_FORMAT_NV12:
-               case TBM_FORMAT_NV21:
-                       tsurf_info.planes[0].size = stream->width * stream->height;
-                       tsurf_info.planes[1].size = (tsurf_info.planes[0].size) >> 1;
-                       tsurf_info.planes[0].offset = 0;
-                       tsurf_info.planes[1].offset = tsurf_info.planes[0].size;
-                       tsurf_info.size = tsurf_info.planes[0].size + tsurf_info.planes[1].size;
-                       break;
-               case TBM_FORMAT_YUV420:
-               case TBM_FORMAT_YVU420:
-                       tsurf_info.planes[0].size = stream->width * stream->height;
-                       tsurf_info.planes[1].size = (stream->width >> 1) * (stream->height >> 1);
-                       tsurf_info.planes[2].size = tsurf_info.planes[1].size;
-                       tsurf_info.planes[0].offset = 0;
-                       tsurf_info.planes[1].offset = tsurf_info.planes[0].size;
-                       tsurf_info.planes[2].offset = tsurf_info.planes[0].size + tsurf_info.planes[1].size;
-                       tsurf_info.size = tsurf_info.planes[0].size + tsurf_info.planes[1].size + tsurf_info.planes[2].size;
-                       break;
-               case TBM_FORMAT_UYVY:
-               case TBM_FORMAT_YUYV:
-                       tsurf_info.planes[0].size = (stream->width * stream->height) << 1;
-                       tsurf_info.planes[0].offset = 0;
-                       tsurf_info.size = tsurf_info.planes[0].size;
-                       break;
-               default:
-                       break;
+       switch (tbm_format) {
+       case TBM_FORMAT_NV12:
+               /* fall through */
+       case TBM_FORMAT_NV21:
+               /* fall through */
+       case TBM_FORMAT_YUV420:
+               /* fall through */
+       case TBM_FORMAT_YVU420:
+               /* fall through */
+       case TBM_FORMAT_UYVY:
+               /* fall through */
+       case TBM_FORMAT_YUYV:
+               for (i = 0 ; i < (int)tsurf_info.num_planes ; i++) {
+                       tsurf_info.planes[i].stride = stream->stride[i];
+                       tsurf_info.planes[i].size = stream->stride[i] * stream->elevation[i];
+                       if (i != 0 && mp_data->num_buffer_fd <= 1)
+                               tsurf_info.planes[i].offset = tsurf_info.planes[i - 1].offset + tsurf_info.planes[i - 1].size;
+                       tsurf_info.size += tsurf_info.planes[i].size;
+
+                       CAM_LOG_VERBOSE("[plane:%d] st[%d], el[%d], size[%d]",
+                               i, stream->stride[i], stream->elevation[i], tsurf_info.planes[i].size);
                }
-
-               return tbm_surface_internal_create_with_bos(&tsurf_info, &mp_data->data_bo, 1);
+               break;
+//LCOV_EXCL_START
+       case TBM_FORMAT_RGB565:
+               /* fall through */
+       case TBM_FORMAT_RGB888:
+               /* fall through */
+       case TBM_FORMAT_RGBA8888:
+               /* fall through */
+       case TBM_FORMAT_ARGB8888:
+               tsurf_info.planes[0].size = stream->data.rgb.length_data;
+               tsurf_info.planes[0].offset = 0;
+               tsurf_info.size = stream->data.rgb.length_data;
+               break;
+       default:
+               CAM_LOG_ERROR("Not supported format[%d]", stream->format);
+               return NULL;
 //LCOV_EXCL_STOP
        }
 
-       CAM_LOG_ERROR("should not be reached here");
-
-       return NULL;
+       return tbm_surface_internal_create_with_bos(&tsurf_info, bos,
+               mp_data->num_buffer_fd > 0 ? mp_data->num_buffer_fd : 1);
 }
 
 
@@ -1313,33 +1303,33 @@ static int __camera_create_media_packet(camera_cb_info_s *cb_info, MMCamcorderVi
 
        switch (stream->data_type) {
        case MM_CAM_STREAM_DATA_ENCODED:
-               /* TODO */
+               ret = media_packet_new_from_external_memory(cb_info->pkt_fmt,
+                       stream->data.encoded.data, stream->data.encoded.length_data,
+                       (media_packet_dispose_cb)_camera_media_packet_dispose, (void *)cb_info,
+                       &pkt);
                break;
        case MM_CAM_STREAM_DATA_DEPTH:
-               /* TODO */
-               break;
-       case MM_CAM_STREAM_DATA_RGB:
-               break;
-       default: /* YUV */
+               CAM_LOG_ERROR("DEPTH type is not supported");
+               return CAMERA_ERROR_NOT_SUPPORTED;
+       default: /* YUV and RGB */
                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;
                }
+
+               ret = media_packet_new_from_tbm_surface(cb_info->pkt_fmt,
+                       tsurf, (media_packet_dispose_cb)_camera_media_packet_dispose,
+                       (void *)cb_info, &pkt);
                break;
        }
 
-       /* create media packet */
-       ret = media_packet_new_from_tbm_surface(cb_info->pkt_fmt,
-               tsurf, (media_packet_dispose_cb)_camera_media_packet_dispose,
-               (void *)cb_info, &pkt);
        if (ret != MEDIA_PACKET_ERROR_NONE) {
-               CAM_LOG_ERROR("media_packet_new failed 0x%x", ret);
+               CAM_LOG_ERROR("media_packet_new[t:%d] failed 0x%x", stream->data_type, ret);
                goto _PACKET_CREATE_FAILED;
        }
 
-       /* set media packet data */
        ret = media_packet_set_extra(pkt, (void *)mp_data);
        if (ret != MEDIA_PACKET_ERROR_NONE) {
                CAM_LOG_ERROR("media_packet_set_extra failed");
@@ -1350,7 +1340,6 @@ static int __camera_create_media_packet(camera_cb_info_s *cb_info, MMCamcorderVi
        if (media_packet_set_pts(pkt, (uint64_t)(stream->timestamp) * 1000000) != MEDIA_PACKET_ERROR_NONE)
                CAM_LOG_WARNING("media_packet_set_pts failed");
 
-       /* set rotation */
        if (media_packet_set_rotate_method(pkt, (media_packet_rotate_method_e)stream->rotation) != MEDIA_PACKET_ERROR_NONE)
                CAM_LOG_WARNING("media_packet_set_rotate_method failed");
 
@@ -1382,24 +1371,22 @@ void _camera_media_packet_dispose(media_packet_h pkt, void *user_data)
        }
 
        ret = media_packet_get_extra(pkt, (void **)&mp_data);
-       if (ret != MEDIA_PACKET_ERROR_NONE) {
+       if (ret != MEDIA_PACKET_ERROR_NONE || !mp_data) {
                CAM_LOG_ERROR("media_packet_get_extra failed 0x%x", ret);
                return;
        }
 
        ret = media_packet_get_tbm_surface(pkt, &tsurf);
-       if (ret != MEDIA_PACKET_ERROR_NONE)
-               CAM_LOG_ERROR("get tbm_surface failed 0x%x", ret);
 
        CAM_LOG_VERBOSE("media packet[%p] - mp_data[%p],tsurf[%p]",
                pkt, mp_data, tsurf);
 
+       if (tsurf)
+               tbm_surface_destroy(tsurf);
+
        g_mutex_lock(&cb_info->mp_data_mutex);
        __camera_release_media_packet_data(mp_data, cb_info);
        g_mutex_unlock(&cb_info->mp_data_mutex);
-
-       if (tsurf)
-               tbm_surface_destroy(tsurf);
 }
 
 static void __camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_msg, muse_camera_event_e event, int *tfd)