fixup! Support YUYV and JPEG formats for Camera 22/316122/3
authorSuhaspoornachandra <s.poornachan@samsung.com>
Tue, 10 Dec 2024 10:17:59 +0000 (15:47 +0530)
committerBot Blink <blinkbot@samsung.com>
Wed, 11 Dec 2024 00:35:47 +0000 (00:35 +0000)
This patch fixes Coverity and SVACE issues related to checking return
value of the libyuv functions.

libyuv::YUY2ToI420() returns only 0, so check is removed and in other
cases check is added where it was missing.

Change-Id: Ib9707063e9ac20b63ab7f38c800a9e6c9213010e
Signed-off-by: Suhaspoornachandra <s.poornachan@samsung.com>
tizen_src/chromium_impl/media/capture/video/tizen/video_capture_device_tizen.cc

index 5aa93916fe5e487f4fcdef8a655fb2c8560cc8ac..3ef206cb395369592d5503b4d6a523a0d6c8b45a 100644 (file)
@@ -446,11 +446,10 @@ void VideoCaptureDeviceTizen::PreviewCameraCaptured(ScopedMediaPacket pkt) {
     case MEDIA_FORMAT_YUYV:
       void* data_yuv;
       media_packet_get_video_plane_data_ptr(pkt.get(), 0, &data_yuv);
-      if (libyuv::YUY2ToI420(reinterpret_cast<uint8_t*>(data_yuv), src_stride_y,
-                             y_plane, dest_stride_y, u_plane, dest_stride_uv,
-                             v_plane, dest_stride_uv, width, height)) {
-        error_message = "Failed to Convert YUYV to I420";
-      }
+      // YUY2ToI420 always returns 0 no need to check return value here.
+      libyuv::YUY2ToI420(reinterpret_cast<uint8_t*>(data_yuv), src_stride_y,
+                         y_plane, dest_stride_y, u_plane, dest_stride_uv,
+                         v_plane, dest_stride_uv, width, height);
       break;
 #if defined(TIZEN_MULTIMEDIA_MJPEG_SUPPORT)
     case MEDIA_FORMAT_MJPEG:
@@ -588,26 +587,34 @@ void VideoCaptureDeviceTizen::OnCameraCaptured(camera_preview_data_s* frame,
   uint8_t* y_plane = static_cast<uint8_t*>(buffer_handle->data());
   uint8_t* u_plane = y_plane + dest_stride_y * dest_height;
   uint8_t* v_plane = u_plane + dest_stride_uv * dest_height / 2;
+  std::string error_message;
 
   switch (frame->format) {
     case CAMERA_PIXEL_FORMAT_NV12:
       src_stride_uv = src_stride_y;
-      libyuv::NV12ToI420Rotate(
-          reinterpret_cast<uint8_t*>(frame->data.double_plane.y), src_stride_y,
-          reinterpret_cast<uint8_t*>(frame->data.double_plane.uv),
-          src_stride_uv, y_plane, dest_stride_y, u_plane, dest_stride_uv,
-          v_plane, dest_stride_uv, frame->width, frame->height, mode);
+      if (libyuv::NV12ToI420Rotate(
+              reinterpret_cast<uint8_t*>(frame->data.double_plane.y),
+              src_stride_y,
+              reinterpret_cast<uint8_t*>(frame->data.double_plane.uv),
+              src_stride_uv, y_plane, dest_stride_y, u_plane, dest_stride_uv,
+              v_plane, dest_stride_uv, frame->width, frame->height, mode)) {
+        error_message = "Failed to Convert NV12 to I420";
+      }
       break;
 
     case CAMERA_PIXEL_FORMAT_I420:
       // FIXME: Verify if I420 format is working.
       src_stride_uv = (src_stride_y + 1) / 2;
-      libyuv::I420Rotate(
-          reinterpret_cast<uint8_t*>(frame->data.triple_plane.y), src_stride_y,
-          reinterpret_cast<uint8_t*>(frame->data.triple_plane.u), src_stride_uv,
-          reinterpret_cast<uint8_t*>(frame->data.triple_plane.v), src_stride_uv,
-          y_plane, dest_stride_y, u_plane, dest_stride_uv, v_plane,
-          dest_stride_uv, frame->width, frame->height, mode);
+      if (libyuv::I420Rotate(
+              reinterpret_cast<uint8_t*>(frame->data.triple_plane.y),
+              src_stride_y,
+              reinterpret_cast<uint8_t*>(frame->data.triple_plane.u),
+              src_stride_uv,
+              reinterpret_cast<uint8_t*>(frame->data.triple_plane.v),
+              src_stride_uv, y_plane, dest_stride_y, u_plane, dest_stride_uv,
+              v_plane, dest_stride_uv, frame->width, frame->height, mode)) {
+        error_message = "Failed to Rotate I420 buffer";
+      }
       break;
 
     case CAMERA_PIXEL_FORMAT_YUYV: {
@@ -623,11 +630,13 @@ void VideoCaptureDeviceTizen::OnCameraCaptured(camera_preview_data_s* frame,
       break;
 #if defined(TIZEN_MULTIMEDIA_MJPEG_SUPPORT)
     case CAMERA_PIXEL_FORMAT_MJPEG:
-      libyuv::ConvertToI420(
-          frame->data.encoded_plane.data, frame->data.encoded_plane.size,
-          y_plane, dest_stride_y, u_plane, dest_stride_uv, v_plane,
-          dest_stride_uv, 0, 0, dest_width, dest_height, dest_width,
-          dest_height, libyuv::kRotate0, libyuv::FOURCC_MJPG);
+      if (libyuv::ConvertToI420(
+              frame->data.encoded_plane.data, frame->data.encoded_plane.size,
+              y_plane, dest_stride_y, u_plane, dest_stride_uv, v_plane,
+              dest_stride_uv, 0, 0, dest_width, dest_height, dest_width,
+              dest_height, libyuv::kRotate0, libyuv::FOURCC_MJPG)) {
+        error_message = "Failed to Convert MJPEG to I420";
+      }
       break;
 #endif
     default:
@@ -636,6 +645,11 @@ void VideoCaptureDeviceTizen::OnCameraCaptured(camera_preview_data_s* frame,
       return;
   }
 
+  if (!error_message.empty()) {
+    LOG(ERROR) << error_message;
+    return;
+  }
+
   base::TimeTicks now = base::TimeTicks::Now();
   if (self->first_ref_time_.is_null())
     self->first_ref_time_ = now;