From: Jeongmo Yang Date: Tue, 27 Aug 2024 23:32:31 +0000 (+0900) Subject: Add metadata for "is_delta_frame" of H.264 format X-Git-Tag: accepted/tizen/unified/20240829.153513^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F53%2F316753%2F6;p=platform%2Fhal%2Fbackend%2Fcamera-v4l2.git Add metadata for "is_delta_frame" of H.264 format - 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 --- diff --git a/packaging/hal-backend-camera-v4l2.spec b/packaging/hal-backend-camera-v4l2.spec index b7d6972..112478b 100644 --- a/packaging/hal-backend-camera-v4l2.spec +++ b/packaging/hal-backend-camera-v4l2.spec @@ -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 diff --git a/src/hal_backend_camera_v4l2.c b/src/hal_backend_camera_v4l2.c index 9e76afa..cb4ff1c 100644 --- a/src/hal_backend_camera_v4l2.c +++ b/src/hal_backend_camera_v4l2.c @@ -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);