[Tizen][WebRTC][M0] Enable video capture port on M0
authormsu.koo <msu.koo@samsung.com>
Wed, 21 Jan 2015 06:38:45 +0000 (15:38 +0900)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
On M0 target, camera supports I420 output.

This patch make Tizen video camera port independent
from platform camera output format.
Reviewed by: Min-Soo Koo, SeungSeop Park, Sharath Kamath

Change-Id: Ibcfb1c0ca72b5d0ece02c2adeb23622fb112a255
Signed-off-by: msu.koo <msu.koo@samsung.com>
tizen_src/impl/media/video/capture/tizen/video_capture_device_factory_tizen.cc
tizen_src/impl/media/video/capture/tizen/video_capture_device_tizen.cc

index 4bce5213e3f42e2ed52d77698fb7171f1931a0d0..63b1870f4b1e1c6bd476ed099677131f8bb0ec2f 100644 (file)
 
 namespace {
 
+enum { kMaxWidth = 1280 };
+enum { kMaxHeight = 720 };
+enum { kMaxFramerate = 30 };
+
 media::VideoPixelFormat toChromiumType(camera_pixel_format_e e) {
   switch (e) {
     case CAMERA_PIXEL_FORMAT_NV12:
@@ -41,6 +45,12 @@ bool OnCameraSupportedPreviewResolution(
   std::vector<gfx::Size>* sizes =
       static_cast< std::vector<gfx::Size>* >(user_data);
   DCHECK(sizes);
+
+  if ((width > kMaxWidth && height > kMaxHeight) ||
+      (height > kMaxWidth && width > kMaxHeight)) {
+    return true;
+  }
+
   sizes->push_back(gfx::Size(width, height));
 
   return true;
@@ -60,7 +70,7 @@ bool OnCameraSupportedPreviewFormat(
 bool OnCameraSupportedFPS(camera_attr_fps_e fps, void* user_data) {
   std::vector<int>* list_fps = static_cast< std::vector<int>* >(user_data);
   DCHECK(list_fps);
-  if (CAMERA_ATTR_FPS_AUTO != fps) {
+  if (CAMERA_ATTR_FPS_AUTO != fps && kMaxFramerate >= fps) {
     // AUTO format is not defined on Chromium, so skip.
     list_fps->push_back(static_cast<int>(fps));
   }
@@ -81,6 +91,11 @@ void GenerateChromiumVideoCaptureFormat(
         format.frame_rate = *itrFPS;
         format.pixel_format = *itrFMT;
         outSupportedFormats.push_back(format);
+
+        LOG(INFO) << __FUNCTION__
+                  << " frame_size:" << format.frame_size.width() << "X" << format.frame_size.height()
+                  << " frame_rate:" << format.frame_rate
+                  << " pixel_format:" << format.pixel_format;
       }
     }
   }
@@ -164,7 +179,6 @@ class CameraHandle final {
       device_count = 0;
       LOG(ERROR) << "Cannot read camera count";
     }
-
     return device_count;
   }
 
index 62d8283625e7291cff64465af63bc3037697b8d1..f68476a891b8dd0722e5adaca2c1811b58d2829b 100644 (file)
@@ -27,7 +27,6 @@ namespace {
 enum { kMjpegWidth = 640 };
 enum { kMjpegHeight = 480 };
 enum { kTypicalFramerate = 30 };
-enum { kTypicalFormat = CAMERA_PIXEL_FORMAT_NV12 };
 
 camera_pixel_format_e toCapiType(media::VideoPixelFormat e) {
   switch (e) {
@@ -55,6 +54,37 @@ camera_pixel_format_e toCapiType(media::VideoPixelFormat e) {
   return CAMERA_PIXEL_FORMAT_INVALID;
 }
 
+libyuv::FourCC toLibYUVtype(camera_pixel_format_e e) {
+  switch (e) {
+    case CAMERA_PIXEL_FORMAT_NV12:
+      return libyuv::FOURCC_NV12;
+    case CAMERA_PIXEL_FORMAT_NV21:
+      return libyuv::FOURCC_NV21;
+    case CAMERA_PIXEL_FORMAT_YUYV:
+      return libyuv::FOURCC_YUYV;
+    case CAMERA_PIXEL_FORMAT_UYVY:
+      return libyuv::FOURCC_UYVY;
+    case CAMERA_PIXEL_FORMAT_I420:
+      return libyuv::FOURCC_I420;
+    case CAMERA_PIXEL_FORMAT_YV12:
+      return libyuv::FOURCC_YV12;
+    default:
+      NOTREACHED();
+  }
+  return libyuv::FOURCC_ANY;
+}
+
+bool OnPreviewFormat(
+    camera_pixel_format_e format, void* user_data) {
+  std::vector<camera_pixel_format_e>* list_format =
+      static_cast< std::vector<camera_pixel_format_e>* >(user_data);
+  DCHECK(list_format);
+
+  list_format->push_back(format);
+
+  return true;
+}
+
 } // unnamed namespace
 
 namespace media {
@@ -125,16 +155,10 @@ camera_device_e VideoCaptureDeviceTizen::DeviceNameToCameraId(
 
 void VideoCaptureDeviceTizen::OnCameraCaptured(camera_preview_data_s* frame,
                                                void* data) {
-  if ( frame->format != CAMERA_PIXEL_FORMAT_NV12 ) {
-    NOTIMPLEMENTED();
-    return;
-  }
-
   VideoCaptureDeviceTizen* self = static_cast<VideoCaptureDeviceTizen*>(data);
   camera_attr_fps_e current_fps =
       static_cast<camera_attr_fps_e>(kTypicalFramerate);
   camera_attr_get_preview_fps(self->camera_, &current_fps);
-
   int destination_width = frame->width;
   int destination_height = frame->height;
 
@@ -194,7 +218,7 @@ void VideoCaptureDeviceTizen::OnCameraCaptured(camera_preview_data_s* frame,
                         frame->width, frame->height,
                         frame->width, frame->height,
                         rotation_mode,
-                        libyuv::FOURCC_NV12);
+                        toLibYUVtype(frame->format));
 
   VideoCaptureFormat capture_format_;
   capture_format_.frame_size.SetSize(destination_width, destination_height);
@@ -213,6 +237,12 @@ void VideoCaptureDeviceTizen::OnAllocateAndStart(int width,
                                                  int frame_rate,
                                                  VideoPixelFormat format,
                                                  scoped_ptr<Client> client) {
+  DVLOG(1) << __FUNCTION__
+           << " width:" << width
+           << " height:" << height
+           << " frame_rate:" << frame_rate
+           << " format:" << format;
+
   DCHECK_EQ(worker_.message_loop(), base::MessageLoop::current());
 
   client_ = client.Pass();
@@ -232,12 +262,13 @@ void VideoCaptureDeviceTizen::OnAllocateAndStart(int width,
 
   if (CAMERA_ERROR_NONE !=
       camera_set_preview_resolution(camera_, width, height)) {
-    LOG(WARNING) << "Camera does not support "
-                 << width << " x " << height << " resolution.";
     LOG(WARNING) << "trying default resolution: "
                  << kMjpegWidth << " x " << kMjpegHeight;
+
     if (CAMERA_ERROR_NONE !=
         camera_set_preview_resolution(camera_, kMjpegWidth, kMjpegHeight)) {
+      LOG(ERROR) << "fail to try default resolution: "
+                 << kMjpegWidth << " x " << kMjpegHeight;
       SetErrorState("Camera internal Error");
       return;
     }
@@ -245,11 +276,22 @@ void VideoCaptureDeviceTizen::OnAllocateAndStart(int width,
 
   if (CAMERA_ERROR_NONE !=
       camera_set_preview_format(camera_, toCapiType(format))) {
-    LOG(WARNING) << "Camera does not support file format :"
-                 << toCapiType(format);
-    LOG(WARNING) << "trying default format: " << kTypicalFormat;
-    if (CAMERA_ERROR_NONE != camera_set_preview_format(
-        camera_, (camera_pixel_format_e)kTypicalFormat)) {
+    std::vector<camera_pixel_format_e> supported_formats;
+    if (CAMERA_ERROR_NONE !=
+        camera_foreach_supported_preview_format(
+            camera_, OnPreviewFormat, &supported_formats)) {
+      LOG(ERROR) << "Cannot get the supported formats for camera";
+      SetErrorState("Camera internal Error");
+      return;
+    }
+    if (supported_formats.empty()) {
+      LOG(ERROR) << "Cannot get the supported formats for camera";
+      SetErrorState("Camera internal Error");
+      return;
+    }
+    if (CAMERA_ERROR_NONE !=
+        camera_set_preview_format(camera_, supported_formats[0])) {
+      LOG(ERROR) << "fail to set preview format: " << supported_formats[0];
       SetErrorState("Camera internal Error");
       return;
     }
@@ -262,12 +304,13 @@ void VideoCaptureDeviceTizen::OnAllocateAndStart(int width,
   }
 
   if (CAMERA_ERROR_NONE !=
-      camera_attr_set_preview_fps(camera_, (camera_attr_fps_e)frame_rate)) {
+      camera_attr_set_preview_fps(
+          camera_, static_cast<camera_attr_fps_e>(frame_rate))) {
     LOG(WARNING) << "Camera does not support frame rate:" <<  frame_rate;
     LOG(WARNING) << "trying default frame rate: " << kTypicalFramerate;
     if (CAMERA_ERROR_NONE !=
-        camera_attr_set_preview_fps(camera_,
-                                    (camera_attr_fps_e)kTypicalFramerate)) {
+        camera_attr_set_preview_fps(
+            camera_, static_cast<camera_attr_fps_e>(kTypicalFramerate))) {
       SetErrorState("Camera internal Error");
       return;
     }