Add metadata for "is_delta_frame" of H.264 format 53/316753/6 accepted/tizen/unified/20240829.153513 accepted/tizen/unified/dev/20240901.214751 accepted/tizen/unified/x/20240830.014111
authorJeongmo Yang <jm80.yang@samsung.com>
Tue, 27 Aug 2024 23:32:31 +0000 (08:32 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 28 Aug 2024 06:49:45 +0000 (15:49 +0900)
- Fix svace issues
 : SEC_DO_NOT_USE_INT_IN_FOR_LOOP
 : OVERFLOW_AFTER_CHECK.EX

[Version] 1.1.1
[Issue Type] Update

Change-Id: I04c49eb5f9a9f5a8170958463542a189cb349d34
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
packaging/hal-backend-camera-v4l2.spec
src/hal_backend_camera_v4l2.c

index b7d69726749b2977f17135512b75ed4d95cc0dfb..112478b6d4aa54b6d98cadde6279bf6c3d3bdd1a 100644 (file)
@@ -8,7 +8,7 @@
 
 Name:       hal-backend-camera-v4l2
 Summary:    Tizen Camera Hal using generic V4L2 interface
-Version:    1.1.0
+Version:    1.1.1
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 9e76afa336ab32683e9d5c28c4719ff8cfba5ee2..cb4ff1c43dd1aadb11f51849f63c4d5cd638b163 100644 (file)
@@ -737,12 +737,13 @@ static int __camera_get_device_info(int device_index, int device_fd, char *node_
                                        break;
                                }
                        } else {
-                               if (resolution_count == VIRTUAL_CAMERA_RES_MAX)
+                               if (resolution_count < VIRTUAL_CAMERA_RES_MAX) {
+                                       v4l2_frame.discrete.width = g_virtual_camera_res[resolution_count].width;
+                                       v4l2_frame.discrete.height = g_virtual_camera_res[resolution_count].height;
+                                       v4l2_frame.type = V4L2_FRMSIZE_TYPE_DISCRETE;
+                               } else {
                                        break;
-
-                               v4l2_frame.discrete.width = g_virtual_camera_res[resolution_count].width;
-                               v4l2_frame.discrete.height = g_virtual_camera_res[resolution_count].height;
-                               v4l2_frame.type = V4L2_FRMSIZE_TYPE_DISCRETE;
+                               }
                        }
 
                        if (resolution_count + 1 >= RESOLUTION_COUNT_MAX) {
@@ -856,7 +857,7 @@ static int __camera_get_device_info(int device_index, int device_fd, char *node_
 
 static int __camera_get_device_info_list(void)
 {
-       int i = 0;
+       size_t i = 0;
        int ret = CAMERA_ERROR_NONE;
        int device_count = 0;
        int device_fd = CAMERA_HAL_INITIAL_FD;
@@ -932,7 +933,7 @@ static int __camera_get_device_info_list(void)
        LOGD("device node count : %zu", glob_buf.gl_pathc);
 
        for (i = 0 ; i < glob_buf.gl_pathc ; i++) {
-               LOGD("[%d] check device [%s]", i, glob_buf.gl_pathv[i]);
+               LOGD("[%zu] check device [%s]", i, glob_buf.gl_pathv[i]);
 
                device_fd = open(glob_buf.gl_pathv[i], O_RDWR);
                if (device_fd < 0) {
@@ -1444,12 +1445,71 @@ _CAPTURE_DONE:
 }
 
 
+static gboolean __camera_h264_is_delta_frame(guint8 *data, uint32_t size)
+{
+       uint32_t offset = 0;
+       uint32_t zero_count = 0;
+       uint32_t nal_unit_type = 0;
+
+       if (!data) {
+               LOGW("NULL data");
+               return FALSE;
+       }
+
+CHECK_AGAIN:
+       zero_count = 0;
+       while (offset < size) {
+               if (data[offset] == 0x0) {
+                       zero_count++;
+               } else if (data[offset] == 0x1) {
+                       if (zero_count == 2 || zero_count == 3) {
+                               /* break to check NAL unit type */
+                               offset++;
+                               break;
+                       }
+                       zero_count = 0;
+               } else {
+                       zero_count = 0;
+               }
+
+               offset++;
+       }
+
+       if (offset >= size) {
+               LOGD("invalid offset[%u], size[%u]", offset, size);
+               return FALSE;
+       }
+
+       nal_unit_type = data[offset] & 0x1F;
+       offset++;
+
+       switch (nal_unit_type) {
+       case 1:
+               LOGD("non-IDR picture");
+               return TRUE;
+       case 5:
+               LOGD("IDR picture");
+               return FALSE;
+       case 7:
+               LOGD("SPS(Sequence Parameter Set)");
+               goto CHECK_AGAIN;
+       case 8:
+               LOGD("PPS(Picture Parameter Set)");
+               goto CHECK_AGAIN;
+       default:
+               LOGD("unhandled NAL unit type[%u]", nal_unit_type);
+               return FALSE;
+       }
+}
+
+
 static void *__camera_buffer_handler_func(gpointer data)
 {
        int error = CAMERA_ERROR_NONE;
        int index = 0;
        hal_camera_handle *handle = (hal_camera_handle *)data;
        uint32_t bytesused = 0;
+       camera_metadata_s meta;
 
        if (!handle) {
                LOGE("NULL handle for buffer handler");
@@ -1485,6 +1545,11 @@ static void *__camera_buffer_handler_func(gpointer data)
                        break;
                }
 
+               memset(&meta, 0x0, sizeof(camera_metadata_s));
+
+               if (handle->preview_format.stream_format == CAMERA_PIXEL_FORMAT_H264)
+                       meta.is_delta_frame = __camera_h264_is_delta_frame((guint8 *)handle->camera_buffers[index].planes[0].data, bytesused);
+
                handle->buffer_dequeued_count++;
                handle->camera_buffers[index].planes[0].bytesused = bytesused;
 
@@ -1493,7 +1558,7 @@ static void *__camera_buffer_handler_func(gpointer data)
                g_mutex_unlock(&handle->buffer_lock);
 
                if (handle->preview_cb) {
-                       handle->preview_cb(&handle->camera_buffers[index], NULL, handle->preview_cb_data);
+                       handle->preview_cb(&handle->camera_buffers[index], &meta, handle->preview_cb_data);
                } else {
                        LOGW("preview callback is NULL");
                        camera_v4l2_release_preview_buffer((void *)handle, index);