From 61adac76b43f7e08829ebbab526baf36472a0013 Mon Sep 17 00:00:00 2001 From: "msu.koo" Date: Wed, 21 Jan 2015 15:38:45 +0900 Subject: [PATCH] [Tizen][WebRTC][M0] Enable video capture port on M0 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 --- .../video_capture_device_factory_tizen.cc | 18 ++++- .../tizen/video_capture_device_tizen.cc | 79 ++++++++++++++----- 2 files changed, 77 insertions(+), 20 deletions(-) diff --git a/tizen_src/impl/media/video/capture/tizen/video_capture_device_factory_tizen.cc b/tizen_src/impl/media/video/capture/tizen/video_capture_device_factory_tizen.cc index 4bce5213e3f4..63b1870f4b1e 100644 --- a/tizen_src/impl/media/video/capture/tizen/video_capture_device_factory_tizen.cc +++ b/tizen_src/impl/media/video/capture/tizen/video_capture_device_factory_tizen.cc @@ -10,6 +10,10 @@ 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* sizes = static_cast< std::vector* >(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* list_fps = static_cast< std::vector* >(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(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; } diff --git a/tizen_src/impl/media/video/capture/tizen/video_capture_device_tizen.cc b/tizen_src/impl/media/video/capture/tizen/video_capture_device_tizen.cc index 62d8283625e7..f68476a891b8 100644 --- a/tizen_src/impl/media/video/capture/tizen/video_capture_device_tizen.cc +++ b/tizen_src/impl/media/video/capture/tizen/video_capture_device_tizen.cc @@ -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* list_format = + static_cast< std::vector* >(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(data); camera_attr_fps_e current_fps = static_cast(kTypicalFramerate); camera_attr_get_preview_fps(self->camera_, ¤t_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) { + 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 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(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(kTypicalFramerate))) { SetErrorState("Camera internal Error"); return; } -- 2.34.1