--- /dev/null
+// Copyright 2019 The Samsung Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/capture/video/tizen/camera_device_tizen.h"
+
+#include "media/capture/video/tizen/video_capture_device_tizen.h"
+
+namespace media {
+
+enum { kMaxWidth = 1280 };
+enum { kMaxHeight = 720 };
+enum { kMaxFramerate = CAMERA_ATTR_FPS_30 };
+
+media::VideoPixelFormat toChromiumType(camera_pixel_format_e e) {
+ switch (e) {
+ case CAMERA_PIXEL_FORMAT_NV12:
+ return media::PIXEL_FORMAT_NV12;
+ case CAMERA_PIXEL_FORMAT_NV21:
+ return media::PIXEL_FORMAT_NV21;
+ case CAMERA_PIXEL_FORMAT_YUYV:
+ return media::PIXEL_FORMAT_YUY2;
+ case CAMERA_PIXEL_FORMAT_RGB888:
+ return media::PIXEL_FORMAT_RGB24;
+ case CAMERA_PIXEL_FORMAT_UYVY:
+ return media::PIXEL_FORMAT_UYVY;
+ case CAMERA_PIXEL_FORMAT_ARGB:
+ return media::PIXEL_FORMAT_ARGB;
+ case CAMERA_PIXEL_FORMAT_I420:
+ return media::PIXEL_FORMAT_I420;
+ case CAMERA_PIXEL_FORMAT_YV12:
+ return media::PIXEL_FORMAT_YV12;
+ case CAMERA_PIXEL_FORMAT_JPEG:
+ return media::PIXEL_FORMAT_MJPEG;
+ default:
+ NOTREACHED();
+ }
+ return media::PIXEL_FORMAT_UNKNOWN;
+}
+
+bool OnCameraSupportedPreviewResolution(int width,
+ int height,
+ void* user_data) {
+ std::vector<gfx::Size>* sizes =
+ static_cast<std::vector<gfx::Size>*>(user_data);
+ DCHECK(sizes);
+
+ if ((width > kMaxWidth && height > kMaxHeight) ||
+ (height > kMaxWidth && width > kMaxHeight)) {
+ DVLOG(1) << "Ignore resolution [width:" << width << " x height:" << height
+ << "] and continue to next resolution";
+ return true;
+ }
+ sizes->push_back(gfx::Size(width, height));
+ return true;
+}
+
+bool OnCameraSupportedPreviewFormat(camera_pixel_format_e format,
+ void* user_data) {
+ std::vector<media::VideoPixelFormat>* list_format =
+ static_cast<std::vector<media::VideoPixelFormat>*>(user_data);
+ DCHECK(list_format);
+
+ list_format->push_back(toChromiumType(format));
+ return true;
+}
+
+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 ||
+ static_cast<camera_attr_fps_e>(kMaxFramerate) < fps) {
+ // AUTO format is not defined on Chromium, so skip.
+ DVLOG(1) << "Ignore fps: [CAMERA_ATTR_FPS_AUTO = " << CAMERA_ATTR_FPS_AUTO
+ << "] OR fps: [" << fps << " > " << kMaxFramerate << "]";
+ return true;
+ }
+ list_fps->push_back(static_cast<int>(fps));
+ return true;
+}
+
+void GenerateChromiumVideoCaptureFormat(
+ std::vector<media::CameraCapability>& capabilities,
+ const std::vector<media::VideoPixelFormat>& formats,
+ std::vector<media::VideoCaptureFormat>& outSupportedFormats) {
+ for (auto supportedFrameInfo : capabilities) {
+ for (auto supportedFormat : formats) {
+ media::VideoCaptureFormat format;
+ format.frame_size = supportedFrameInfo.resolution;
+ format.frame_rate = supportedFrameInfo.fps;
+ format.pixel_format = supportedFormat;
+ outSupportedFormats.push_back(format);
+ DVLOG(1) << " frame_size:" << format.frame_size.width() << "X"
+ << format.frame_size.height()
+ << " frame_rate:" << format.frame_rate
+ << " pixel_format:" << format.pixel_format;
+ }
+ }
+}
+
+CameraHandle::CameraHandle() : camera_handle_(NULL), client_(NULL) {
+ LOG(INFO) << "Creating the camera instance";
+ device_name_ = CAMERA_DEVICE_CAMERA0;
+ ResetHandle(device_name_);
+}
+
+CameraHandle::~CameraHandle() {
+ if (camera_handle_ != NULL)
+ camera_destroy(camera_handle_);
+}
+
+void CameraHandle::ResetHandle(camera_device_e device_name) {
+ if (camera_handle_ != NULL) {
+ if (client_ != NULL)
+ client_->OnStreamStopped();
+
+ camera_destroy(camera_handle_);
+ camera_handle_ = NULL;
+ }
+
+ int err = 0;
+ if (CAMERA_ERROR_NONE !=
+ (err = camera_create(device_name, &camera_handle_))) {
+ camera_handle_ = NULL;
+ LOG(ERROR) << "Cannot create camera, Error:"
+ << media::VideoCaptureDeviceTizen::GetErrorString(err);
+ } else {
+ device_name_ = device_name;
+ }
+}
+
+void CameraHandle::SetClient(CameraHandleClient* client) {
+ client_ = client;
+}
+
+void CameraHandle::UnsetClient(CameraHandleClient* client) {
+ if (client_ == client)
+ client_ = NULL;
+}
+
+CameraHandle* CameraHandle::GetInstance() {
+ return base::Singleton<CameraHandle>::get();
+}
+
+bool CameraHandle::IsValid() {
+ return camera_handle_ != NULL;
+}
+
+bool CameraHandle::GetSupportedPreviewResolutions(
+ std::vector<CameraCapability::Resolution>& supported_resolutions) const {
+ int err = 0;
+ if (CAMERA_ERROR_NONE !=
+ (err = camera_foreach_supported_preview_resolution(
+ camera_handle_, OnCameraSupportedPreviewResolution,
+ &supported_resolutions))) {
+ LOG(ERROR) << "Cannot get the supported resolutions for camera, Error:"
+ << media::VideoCaptureDeviceTizen::GetErrorString(err);
+ return false;
+ }
+ return true;
+}
+
+bool CameraHandle::GetSupportedPreviewPixelFormats(
+ std::vector<media::VideoPixelFormat>& supported_formats) const {
+ int err = 0;
+ if (CAMERA_ERROR_NONE != (err = camera_foreach_supported_preview_format(
+ camera_handle_, OnCameraSupportedPreviewFormat,
+ &supported_formats))) {
+ LOG(ERROR) << "Cannot get the supported formats for camera, Error:"
+ << media::VideoCaptureDeviceTizen::GetErrorString(err);
+ return false;
+ }
+ return true;
+}
+
+bool CameraHandle::GetSupportedPreviewCapabilities(
+ std::vector<CameraCapability>& supported_capabilities) const {
+ std::vector<CameraCapability::Resolution> preview_resolutions;
+ if (!GetSupportedPreviewResolutions(preview_resolutions))
+ return false;
+
+ for (auto resolution : preview_resolutions) {
+ std::vector<int> frame_rates;
+ int width = resolution.width();
+ int height = resolution.height();
+ if (CAMERA_ERROR_NONE != camera_attr_foreach_supported_fps_by_resolution(
+ camera_handle_, width, height,
+ OnCameraSupportedFPS, &frame_rates)) {
+ LOG(WARNING) << "Cannot get the supported FPS for this resolution : "
+ << width << "X" << height;
+ continue;
+ }
+
+ for (auto rate : frame_rates)
+ supported_capabilities.push_back(CameraCapability(resolution, rate));
+ }
+
+ if (supported_capabilities.empty())
+ return false;
+
+ return true;
+}
+
+void CameraHandle::GetDeviceSupportedFormats(
+ media::VideoCaptureFormats& supported_formats) {
+ std::vector<media::VideoPixelFormat> supported_pixel_formats;
+ std::vector<CameraCapability> supported_capabilities;
+
+ if (!IsValid()) {
+ LOG(ERROR) << "Cannot use camera";
+ return;
+ }
+
+ if (!GetSupportedPreviewPixelFormats(supported_pixel_formats))
+ return;
+
+ if (!GetSupportedPreviewCapabilities(supported_capabilities))
+ return;
+
+ supported_formats.clear();
+ GenerateChromiumVideoCaptureFormat(
+ supported_capabilities, supported_pixel_formats, supported_formats);
+}
+
+int CameraHandle::GetMaxFrameRate(
+ CameraCapability::Resolution resolution) const {
+ std::vector<int> frame_rates;
+ int err = 0;
+ if (CAMERA_ERROR_NONE !=
+ (err = camera_attr_foreach_supported_fps_by_resolution(
+ camera_handle_, resolution.width(), resolution.height(),
+ OnCameraSupportedFPS, &frame_rates))) {
+ LOG(ERROR) << "Cannot get the supported FPS for this resolution : "
+ << resolution.width() << "X" << resolution.height() << " Error: "
+ << media::VideoCaptureDeviceTizen::GetErrorString(err);
+ return 0;
+ }
+
+ return *std::max_element(frame_rates.begin(), frame_rates.end());
+}
+
+int CameraHandle::GetDeviceCounts() {
+ int device_count = 0;
+ int err = 0;
+ if (CAMERA_ERROR_NONE !=
+ (err = camera_get_device_count(camera_handle_, &device_count))) {
+ device_count = 0;
+ LOG(ERROR) << "Cannot read camera count, Error:"
+ << media::VideoCaptureDeviceTizen::GetErrorString(err);
+ }
+ return device_count;
+}
+
+} // namespace media
-// Copyright 2014 The Samsung Authors. All rights reserved.
+// Copyright 2019 The Samsung Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <camera.h>
+#include "base/logging.h"
#include "base/memory/singleton.h"
+#include "media/capture/video/tizen/camera_device_tizen.h"
#include "media/capture/video/tizen/video_capture_device_tizen.h"
-namespace {
-
-enum { kMaxWidth = 1280 };
-enum { kMaxHeight = 720 };
-enum { kMaxFramerate = CAMERA_ATTR_FPS_30 };
-
-media::VideoPixelFormat toChromiumType(camera_pixel_format_e e) {
- switch (e) {
- case CAMERA_PIXEL_FORMAT_NV12:
- return media::PIXEL_FORMAT_NV12;
- case CAMERA_PIXEL_FORMAT_NV21:
- return media::PIXEL_FORMAT_NV21;
- case CAMERA_PIXEL_FORMAT_YUYV:
- return media::PIXEL_FORMAT_YUY2;
- case CAMERA_PIXEL_FORMAT_RGB888:
- return media::PIXEL_FORMAT_RGB24;
- case CAMERA_PIXEL_FORMAT_UYVY:
- return media::PIXEL_FORMAT_UYVY;
- case CAMERA_PIXEL_FORMAT_ARGB:
- return media::PIXEL_FORMAT_ARGB;
- case CAMERA_PIXEL_FORMAT_I420:
- return media::PIXEL_FORMAT_I420;
- case CAMERA_PIXEL_FORMAT_YV12:
- return media::PIXEL_FORMAT_YV12;
- case CAMERA_PIXEL_FORMAT_JPEG:
- return media::PIXEL_FORMAT_MJPEG;
- default:
- NOTREACHED();
- }
- return media::PIXEL_FORMAT_UNKNOWN;
-}
-
-static std::string GetCameraErrorMessage(int err_code) {
- return media::VideoCaptureDeviceTizen::GetCameraErrorMessage(err_code);
-}
-
-bool OnCameraSupportedPreviewResolution(int width,
- int height,
- void* user_data) {
- std::vector<gfx::Size>* sizes =
- static_cast<std::vector<gfx::Size>*>(user_data);
- DCHECK(sizes);
-
- if ((width > kMaxWidth && height > kMaxHeight) ||
- (height > kMaxWidth && width > kMaxHeight)) {
- DVLOG(1) << "Ignore resolution [width:" << width << " x height:" << height
- << "] and continue to next resolution";
- return true;
- }
- sizes->push_back(gfx::Size(width, height));
- return true;
-}
-
-bool OnCameraSupportedPreviewFormat(camera_pixel_format_e format,
- void* user_data) {
- std::vector<media::VideoPixelFormat>* list_format =
- static_cast<std::vector<media::VideoPixelFormat>*>(user_data);
- DCHECK(list_format);
-
- list_format->push_back(toChromiumType(format));
- return true;
-}
-
-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 ||
- static_cast<camera_attr_fps_e>(kMaxFramerate) < fps) {
- // AUTO format is not defined on Chromium, so skip.
- DVLOG(1) << "Ignore fps: [CAMERA_ATTR_FPS_AUTO = " << CAMERA_ATTR_FPS_AUTO
- << "] OR fps: [" << fps << " > " << kMaxFramerate << "]";
- return true;
- }
- list_fps->push_back(static_cast<int>(fps));
- return true;
-}
-
-void GenerateChromiumVideoCaptureFormat(
- const std::vector<gfx::Size>& frame_sizes,
- const std::vector<int>& fps,
- const std::vector<media::VideoPixelFormat>& formats,
- std::vector<media::VideoCaptureFormat>& outSupportedFormats) {
- for (auto itrS = frame_sizes.begin(); itrS != frame_sizes.end(); itrS++) {
- for (auto itrFPS = fps.begin(); itrFPS != fps.end(); itrFPS++) {
- for (auto itrFMT = formats.begin(); itrFMT != formats.end(); itrFMT++) {
- media::VideoCaptureFormat format;
- format.frame_size = *itrS;
- format.frame_rate = *itrFPS;
- format.pixel_format = *itrFMT;
- outSupportedFormats.push_back(format);
-
- DVLOG(1) << " frame_size:" << format.frame_size.width() << "X"
- << format.frame_size.height()
- << " frame_rate:" << format.frame_rate
- << " pixel_format:" << format.pixel_format;
- }
- }
- }
-}
-
-class CameraHandle final {
- public:
- static CameraHandle* GetInstance() {
- return base::Singleton<CameraHandle>::get();
- }
-
- bool IsValid() const { return camera_handle_ != NULL; }
-
- void GetDeviceSupportedFormats(
- media::VideoCaptureFormats& supported_formats) const {
- int err = 0;
- std::vector<gfx::Size> supported_frame_sizes;
- std::vector<int> supported_frame_rates;
- std::vector<media::VideoPixelFormat> supported_pixel_formats;
-
- if (!IsValid()) {
- LOG(ERROR) << "Cannot use camera";
- return;
- }
-
- if (CAMERA_ERROR_NONE !=
- (err = camera_foreach_supported_preview_resolution(
- camera_handle_, OnCameraSupportedPreviewResolution,
- &supported_frame_sizes))) {
- LOG(ERROR) << "Cannot get the supported resolutions for camera, Error:"
- << GetCameraErrorMessage(err);
- return;
- }
-
- if (CAMERA_ERROR_NONE !=
- (err = camera_foreach_supported_preview_format(
- camera_handle_, OnCameraSupportedPreviewFormat,
- &supported_pixel_formats))) {
- LOG(ERROR) << "Cannot get the supported formats for camera, Error:"
- << GetCameraErrorMessage(err);
- return;
- }
-
- if (CAMERA_ERROR_NONE !=
- (err = camera_attr_foreach_supported_fps(
- camera_handle_, OnCameraSupportedFPS, &supported_frame_rates))) {
- LOG(ERROR) << "Cannot get the supported FPS for camera, Error:"
- << GetCameraErrorMessage(err);
- return;
- }
- supported_formats.clear();
- GenerateChromiumVideoCaptureFormat(
- supported_frame_sizes, supported_frame_rates, supported_pixel_formats,
- supported_formats);
- }
-
- int GetDeviceCounts() const {
- int device_count = 0;
- int err = 0;
- if (CAMERA_ERROR_NONE !=
- (err = camera_get_device_count(camera_handle_, &device_count))) {
- device_count = 0;
- LOG(ERROR) << "Cannot read camera count, Error:"
- << GetCameraErrorMessage(err);
- }
- return device_count;
- }
-
- private:
- CameraHandle() : camera_handle_(NULL) {
- int err = 0;
- if (CAMERA_ERROR_NONE !=
- (err = camera_create(CAMERA_DEVICE_CAMERA0, &camera_handle_))) {
- camera_handle_ = NULL;
- LOG(ERROR) << "Cannot create camera, Error:"
- << GetCameraErrorMessage(err);
- }
- }
-
- CameraHandle(const CameraHandle&) = delete;
- CameraHandle& operator=(const CameraHandle&) = delete;
-
- ~CameraHandle() {
- if (camera_handle_ != NULL)
- camera_destroy(camera_handle_);
- }
-
- CameraHandle(const CameraHandle&) = delete;
- CameraHandle& operator=(const CameraHandle&) = delete;
-
- camera_h camera_handle_;
-
- friend struct base::DefaultSingletonTraits<CameraHandle>;
-};
-
-} // namespace
-
namespace media {
VideoCaptureDeviceFactoryTizen::VideoCaptureDeviceFactoryTizen(
VideoCaptureDeviceFactoryTizen::~VideoCaptureDeviceFactoryTizen() {}
-scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryTizen::Create(
- const VideoCaptureDevice::Name& name) {
+VideoCaptureErrorOrDevice VideoCaptureDeviceFactoryTizen::CreateDevice(
+ const VideoCaptureDeviceDescriptor& device_descriptor) {
DCHECK(thread_checker_.CalledOnValidThread());
+ // FIXME: is device discriptor needed? or just the name is sufficient?
- return scoped_ptr<VideoCaptureDevice>(new VideoCaptureDeviceTizen(name));
+ std::unique_ptr<VideoCaptureDeviceTizen> device(
+ new VideoCaptureDeviceTizen(device_descriptor));
+ return VideoCaptureErrorOrDevice(std::move(device));
}
-void VideoCaptureDeviceFactoryTizen::GetDeviceNames(
- VideoCaptureDevice::Names* const device_names) {
- DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(device_names->empty());
+void VideoCaptureDeviceFactoryTizen::GetDevicesInfo(
+ GetDevicesInfoCallback callback) {
+ std::vector<VideoCaptureDeviceInfo> devices_info;
CameraHandle* camera_handle = CameraHandle::GetInstance();
+ LOG(INFO) << "Received the camera handle:"
+ << camera_handle->GetCameraHandle();
if (!camera_handle->IsValid()) {
LOG(ERROR) << "Cannot use camera";
LOG(ERROR) << "No camera on this device.";
return;
}
- VideoCaptureDevice::Name primary_camera(
+ VideoCaptureControlSupport control_support;
+ control_support.pan = false;
+ control_support.tilt = false;
+ control_support.zoom = false;
+ devices_info.emplace_back(VideoCaptureDeviceDescriptor(
VideoCaptureDeviceTizen::kFrontCameraName,
- VideoCaptureDeviceTizen::GetFrontCameraID());
+ VideoCaptureDeviceTizen::GetFrontCameraID(), "front_camera",
+ VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE, control_support,
+ VideoCaptureTransportType::OTHER_TRANSPORT));
- device_names->push_back(primary_camera);
if (device_count == 2) {
- VideoCaptureDevice::Name secondary_camera(
+ devices_info.emplace_back(VideoCaptureDeviceDescriptor(
VideoCaptureDeviceTizen::kBackCameraName,
- VideoCaptureDeviceTizen::GetBackCameraID());
- device_names->push_back(secondary_camera);
+ VideoCaptureDeviceTizen::GetBackCameraID(), "back_camera",
+ VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE, control_support,
+ VideoCaptureTransportType::OTHER_TRANSPORT));
}
-}
-
-void VideoCaptureDeviceFactoryTizen::GetDeviceSupportedFormats(
- const VideoCaptureDevice::Name& device,
- VideoCaptureFormats* supported_formats) {
- DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(supported_formats != NULL);
- CameraHandle* camera_handle = CameraHandle::GetInstance();
-
- if (!camera_handle->IsValid()) {
- LOG(ERROR) << "Cannot use camera";
- return;
- }
- camera_handle->GetDeviceSupportedFormats(*supported_formats);
-}
-// static
-VideoCaptureDeviceFactory*
-VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory(
- scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
- return (new VideoCaptureDeviceFactoryTizen(ui_task_runner));
+ VideoCaptureFormats supported_formats;
+ camera_handle->GetDeviceSupportedFormats(supported_formats);
+ devices_info.back().supported_formats = std::move(supported_formats);
+ std::move(callback).Run(std::move(devices_info));
}
} // namespace media
-// Copyright (c) 2012 The Samsung Authors. All rights reserved.
+// Copyright (c) 2019 The Samsung Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/bind.h"
#include "third_party/libyuv/include/libyuv.h"
-#include "tizen/profile_info.h"
-#include "ui/gfx/screen.h"
-
-#if defined(WEBRTC_DEBUG_DUMPFILE)
-#include <fcntl.h>
-#include <unistd.h>
-#endif
-
-#if defined(WEBRTC_DEBUG_DUMPFILE)
-int fd_1 = -1;
-int fd_2 = -1;
-#define WEBRTC_DEBUG_INITDUMP() { \
- struct stat st = {0}; \
- if (stat("/opt/usr", &st) == -1) { \
- mkdir("/opt/usr", 0644); \
- } \
- LOG(INFO) << " DUMP OUTPUT to file: /opt/usr/before.yuv, /opt/usr/after.yuv"; \
- fd_1 = open( "/opt/usr/before.yuv", O_WRONLY | O_CREAT | O_EXCL, 0644); \
- fd_2 = open( "/opt/usr/after.yuv", O_WRONLY | O_CREAT | O_EXCL, 0644); \
-}
-#else
-#define WEBRTC_DEBUG_INITDUMP() { \
-/* Do nothing */ }
-#endif
-
-#if defined(WEBRTC_DEBUG_DUMPFILE)
-#define WEBRTC_DEBUG_DUMPFRAME(frame, yplane) { \
- int written = \
- write(fd_1, frame->data.triple_plane.y, frame->data.triple_plane.y_size); \
- written += \
- write(fd_1, frame->data.triple_plane.u, frame->data.triple_plane.u_size); \
- written += \
- write(fd_1, frame->data.triple_plane.v, frame->data.triple_plane.v_size); \
- LOG(INFO) << written << " bytes written to dump file. before.yuv"; \
- written = write(fd_2, yplane, frame->width * frame->height * 3 / 2); \
- LOG(INFO) << written << " bytes written to dump file. after.yuv"; \
-}
-#else
-#define WEBRTC_DEBUG_DUMPFRAME(frame, yplane) { \
-/* Do nothing */ }
-#endif
+#include "tizen/system_info.h"
+#include "ui/display/display.h"
+#include "ui/display/screen.h"
namespace {
+#define ENUM_CASE(x) \
+ case x: \
+ return #x; \
+ break
+
enum { kMjpegWidth = 640 };
enum { kMjpegHeight = 480 };
enum { kTypicalFramerate = 30 };
-enum { kTypicalFormat = CAMERA_PIXEL_FORMAT_NV12 };
enum CameraOrientation {
DEGREE_0 = 0,
DEGREE_90 = 90,
DEGREE_360 = 360,
};
-struct _video_capture_err {
- camera_error_e err_code;
- std::string err_msg;
-};
-
-const static _video_capture_err video_capture_err[] = {
- {CAMERA_ERROR_NONE, "Successful"},
- {CAMERA_ERROR_INVALID_PARAMETER, "Invalid parameter"},
- {CAMERA_ERROR_INVALID_STATE, "Invalid state"},
- {CAMERA_ERROR_OUT_OF_MEMORY, "Out of memory"},
- {CAMERA_ERROR_DEVICE, "Device error"},
- {CAMERA_ERROR_INVALID_OPERATION, "Internal error"},
- {CAMERA_ERROR_SOUND_POLICY, "Blocked by Audio Session Manager"},
- {CAMERA_ERROR_SECURITY_RESTRICTED, "Restricted by security system policy"},
- {CAMERA_ERROR_DEVICE_BUSY,
- "The device is using another application or working on some operation"},
- {CAMERA_ERROR_DEVICE_NOT_FOUND, "No camera device"},
- {CAMERA_ERROR_SOUND_POLICY_BY_CALL,
- "Blocked by Audio Session Manager - CALL"},
- {CAMERA_ERROR_SOUND_POLICY_BY_ALARM,
- "Blocked by Audio Session Manager - ALARM"},
- {CAMERA_ERROR_ESD, "ESD situation "},
- {CAMERA_ERROR_PERMISSION_DENIED,
- "The access to the resources can not be granted"},
- {CAMERA_ERROR_NOT_SUPPORTED, "The feature is not supported"},
-};
-
camera_pixel_format_e toCapiType(media::VideoPixelFormat e) {
switch (e) {
case media::PIXEL_FORMAT_NV12:
return CAMERA_PIXEL_FORMAT_INVALID;
}
-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;
-}
-
struct CameraSpec {
const char* device_id_;
CameraOrientation orientation_;
const std::vector<CameraSpec>& GetCameraSpec() {
const static std::vector<CameraSpec> kMobileCameraSpecs = {
- {media::VideoCaptureDeviceTizen::GetFrontCameraID().c_str(), DEGREE_270},
- {media::VideoCaptureDeviceTizen::GetBackCameraID().c_str(), DEGREE_90}};
+ {media::VideoCaptureDeviceTizen::GetFrontCameraID(), DEGREE_270},
+ {media::VideoCaptureDeviceTizen::GetBackCameraID(), DEGREE_90}};
const static std::vector<CameraSpec> kCommonCameraSpecs = {
- {media::VideoCaptureDeviceTizen::GetFrontCameraID().c_str(), DEGREE_0}};
+ {media::VideoCaptureDeviceTizen::GetFrontCameraID(), DEGREE_0}};
if (IsMobileProfile() || IsWearableProfile())
return kMobileCameraSpecs;
return kCommonCameraSpecs;
}
-} // unnamed namespace
+} // unnamed namespace
namespace media {
+#if TIZEN_MM_DEBUG_VIDEO_DUMP_DECODED_FRAME == 1
+FrameDumper* frameDumper;
+#endif
+
const std::string VideoCaptureDeviceTizen::kFrontCameraName = "front";
const std::string VideoCaptureDeviceTizen::kBackCameraName = "back";
const std::string VideoCaptureDeviceTizen::kCameraId1 = "1";
// Note : Camera ID for Mobile or Wearable profile > Front : 1 / Back : 0
-const std::string VideoCaptureDeviceTizen::GetFrontCameraID() {
- if (IsMobileProfile() || IsWearableProfile())
- return VideoCaptureDeviceTizen::kCameraId1;
+const char* VideoCaptureDeviceTizen::GetFrontCameraID() {
+ if (IsMobileProfile())
+ return VideoCaptureDeviceTizen::kCameraId1.c_str();
else
- return VideoCaptureDeviceTizen::kCameraId0;
+ return VideoCaptureDeviceTizen::kCameraId0.c_str();
}
// static
-const std::string VideoCaptureDeviceTizen::GetBackCameraID() {
- if (IsMobileProfile() || IsWearableProfile())
- return VideoCaptureDeviceTizen::kCameraId0;
+const char* VideoCaptureDeviceTizen::GetBackCameraID() {
+ if (IsMobileProfile())
+ return VideoCaptureDeviceTizen::kCameraId0.c_str();
else
- return VideoCaptureDeviceTizen::kCameraId1;
+ return VideoCaptureDeviceTizen::kCameraId1.c_str();
}
static CameraOrientation GetCameraOrientation(const char* device_id) {
return DEGREE_0;
}
-const std::string VideoCaptureDevice::Name::GetModel() const {
- return "tizen camera";
-}
-
-VideoCaptureDeviceTizen::VideoCaptureDeviceTizen(const Name& device_name)
- : state_(kIdle),
- device_name_(device_name),
- worker_("VideoCapture"),
+VideoCaptureDeviceTizen::VideoCaptureDeviceTizen(
+ const VideoCaptureDeviceDescriptor& device_descriptor)
+ : camera_(nullptr),
buffer_(),
- camera_(NULL) {
- WEBRTC_DEBUG_INITDUMP();
+ device_descriptor_(device_descriptor),
+ worker_("VideoCapture"),
+ is_capturing_(false),
+ use_media_packet_(false),
+ state_(kIdle) {
+#if TIZEN_MM_DEBUG_VIDEO_DUMP_DECODED_FRAME == 1
+ frameDumper = new FrameDumper();
+#endif
+
+ if (IsMobileProfile())
+ use_media_packet_ = true;
}
VideoCaptureDeviceTizen::~VideoCaptureDeviceTizen() {
+ CameraHandle::GetInstance()->UnsetClient(this);
state_ = kIdle;
DCHECK(!worker_.IsRunning());
}
+void VideoCaptureDeviceTizen::OnStreamStopped() {
+ SetErrorState("Camera handle reset", FROM_HERE);
+}
+
void VideoCaptureDeviceTizen::AllocateAndStart(
const VideoCaptureParams& params,
- scoped_ptr<VideoCaptureDevice::Client> client) {
+ std::unique_ptr<VideoCaptureDevice::Client> client) {
DCHECK(!worker_.IsRunning());
worker_.Start();
- worker_.message_loop()->PostTask(
- FROM_HERE, base::BindOnce(&VideoCaptureDeviceTizen::OnAllocateAndStart,
- base::Unretained(this),
- params.requested_format.frame_size.width(),
- params.requested_format.frame_size.height(),
- params.requested_format.frame_rate,
- params.requested_format.pixel_format,
- base::Passed(&client)));
+ worker_.task_runner()->PostTask(
+ FROM_HERE,
+ base::BindOnce(&VideoCaptureDeviceTizen::OnAllocateAndStart,
+ base::Unretained(this),
+ params.requested_format.frame_size.width(),
+ params.requested_format.frame_size.height(),
+ params.requested_format.frame_rate,
+ params.requested_format.pixel_format, std::move(client)));
}
void VideoCaptureDeviceTizen::StopAndDeAllocate() {
DCHECK(worker_.IsRunning());
- worker_.message_loop()->PostTask(
+ worker_.task_runner()->PostTask(
FROM_HERE, base::BindOnce(&VideoCaptureDeviceTizen::OnStopAndDeAllocate,
base::Unretained(this)));
worker_.Stop();
}
-#if !defined(EWK_BRINGUP)
camera_device_e VideoCaptureDeviceTizen::DeviceNameToCameraId(
- const VideoCaptureDevice::Name& device_name) {
- if (device_name.id().compare("0") == 0){
+ const VideoCaptureDeviceDescriptor& device_descriptor) {
+ if (device_descriptor.device_id.compare("0") == 0) {
return CAMERA_DEVICE_CAMERA0;
- } else if (device_name.id().compare("1") == 0) {
+ } else if (device_descriptor.device_id.compare("1") == 0) {
return CAMERA_DEVICE_CAMERA1;
} else {
NOTREACHED();
}
return static_cast<camera_device_e>(-1);
}
-#endif
-std::string VideoCaptureDeviceTizen::GetCameraErrorMessage(int err_code) {
- for (size_t i = 0; i < arraysize(video_capture_err); i++) {
- if (video_capture_err[i].err_code ==
- static_cast<camera_error_e>(err_code)) {
- return video_capture_err[i].err_msg;
+bool VideoCaptureDeviceTizen::IsCapturing() {
+ base::AutoLock auto_lock(capturing_state_lock_);
+ return is_capturing_;
+}
+
+void VideoCaptureDeviceTizen::ChangeCapturingState(bool state) {
+ base::AutoLock auto_lock(capturing_state_lock_);
+ is_capturing_ = state;
+}
+
+void VideoCaptureDeviceTizen::OnCameraCapturedWithMediaPacket(
+ media_packet_h pkt,
+ void* data) {
+ VideoCaptureDeviceTizen* self = static_cast<VideoCaptureDeviceTizen*>(data);
+
+ if (self->IsCapturing()) {
+ media_packet_destroy(pkt);
+ return;
+ }
+
+ self->ChangeCapturingState(true);
+ ScopedMediaPacket packet_proxy(pkt);
+ self->worker_.task_runner()->PostTask(
+ FROM_HERE,
+ base::BindOnce(&VideoCaptureDeviceTizen::PreviewCameraCaptured,
+ base::Unretained(self), std::move(packet_proxy)));
+}
+
+void VideoCaptureDeviceTizen::PreviewCameraCaptured(ScopedMediaPacket pkt) {
+ if (!client_) {
+ ChangeCapturingState(false);
+ return;
+ }
+ ScopedMediaFormat format;
+ media_format_h fmt = nullptr;
+ media_packet_get_format(pkt.get(), &fmt);
+ format.reset(fmt);
+
+ media_format_mimetype_e mime;
+ int width, height, avg_bps, max_bps;
+
+ media_format_get_video_info(format.get(), &mime, &width, &height, &avg_bps,
+ &max_bps);
+ CHECK((mime == MEDIA_FORMAT_I420) || (mime == MEDIA_FORMAT_NV12));
+
+ camera_attr_fps_e current_fps =
+ static_cast<camera_attr_fps_e>(kTypicalFramerate);
+ camera_attr_get_preview_fps(camera_, ¤t_fps);
+
+ int orientation =
+ display::Screen::GetScreen()->GetPrimaryDisplay().RotationAsDegree();
+
+ gfx::Size target_resolution(width, height);
+
+ int target_rotation =
+ (orientation +
+ GetCameraOrientation(device_descriptor_.device_id.c_str())) %
+ DEGREE_360;
+
+ int src_stride_y = width;
+ int src_stride_uv = (src_stride_y + 1) / 2;
+
+ media::VideoCaptureFormat videocaptureformat;
+ videocaptureformat.frame_size = gfx::Size(width, height);
+ videocaptureformat.frame_rate = static_cast<int>(current_fps);
+ videocaptureformat.pixel_format = media::PIXEL_FORMAT_I420;
+
+ int dest_width = width;
+ int dest_height = height;
+ if (target_rotation == 90 || target_rotation == 270)
+ std::swap(dest_height, dest_width);
+
+ videocaptureformat.frame_size = gfx::Size(dest_width, dest_height);
+ auto reservation_result_code = client_->ReserveOutputBuffer(
+ videocaptureformat.frame_size, media::PIXEL_FORMAT_I420, 0, &buffer_);
+ if (reservation_result_code !=
+ VideoCaptureDevice::Client::ReserveResult::kSucceeded) {
+ LOG(ERROR) << "Failed to reserve I420 output buffer.";
+ ChangeCapturingState(false);
+ return;
+ }
+
+ libyuv::RotationMode mode =
+ static_cast<libyuv::RotationMode>(target_rotation);
+
+ int dest_stride_y = dest_width;
+ int dest_stride_uv = (dest_stride_y + 1) / 2;
+
+ std::unique_ptr<VideoCaptureBufferHandle> buffer_handle =
+ buffer_.handle_provider->GetHandleForInProcessAccess();
+
+ 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;
+
+ if (mime == MEDIA_FORMAT_NV12) {
+ src_stride_uv = src_stride_y;
+
+ void *data_y, *data_uv;
+ media_packet_get_video_plane_data_ptr(pkt.get(), 0, &data_y);
+ media_packet_get_video_plane_data_ptr(pkt.get(), 1, &data_uv);
+
+ libyuv::NV12ToI420Rotate(reinterpret_cast<uint8_t*>(data_y), src_stride_y,
+ reinterpret_cast<uint8_t*>(data_uv), src_stride_uv,
+ y_plane, dest_stride_y, u_plane, dest_stride_uv,
+ v_plane, dest_stride_uv, width, height, mode);
+ base::TimeTicks now = base::TimeTicks::Now();
+ if (first_ref_time_.is_null())
+ first_ref_time_ = now;
+
+ client_->OnIncomingCapturedBuffer(std::move(buffer_), videocaptureformat,
+ now, now - first_ref_time_);
+ } else if (mime == MEDIA_FORMAT_I420) {
+ // FIXME: Verify if I420 format is working.
+ void *data_y, *data_u, *data_v;
+ media_packet_get_video_plane_data_ptr(pkt.get(), 0, &data_y);
+ media_packet_get_video_plane_data_ptr(pkt.get(), 1, &data_u);
+ media_packet_get_video_plane_data_ptr(pkt.get(), 2, &data_v);
+
+ if (libyuv::I420Rotate(reinterpret_cast<uint8_t*>(data_y), src_stride_y,
+ reinterpret_cast<uint8_t*>(data_u), src_stride_uv,
+ reinterpret_cast<uint8_t*>(data_v), src_stride_uv,
+ y_plane, src_stride_y, u_plane, src_stride_uv,
+ v_plane, src_stride_uv, width, height, mode)) {
+ LOG(ERROR) << "Failed to I420Rotate buffer";
+ ChangeCapturingState(false);
+ return;
}
+
+ base::TimeTicks now = base::TimeTicks::Now();
+ if (first_ref_time_.is_null())
+ first_ref_time_ = now;
+
+ client_->OnIncomingCapturedBuffer(std::move(buffer_), videocaptureformat,
+ now, now - first_ref_time_);
+ } else {
+ LOG(ERROR) << "frame->format( " << mime
+ << ") is not implemented or not supported by chromium.";
}
- return std::string("Camera Internal Error");
+
+ ChangeCapturingState(false);
}
void VideoCaptureDeviceTizen::OnCameraCaptured(camera_preview_data_s* frame,
void* data) {
- CHECK(frame->format == CAMERA_PIXEL_FORMAT_I420);
+ CHECK((frame->format == CAMERA_PIXEL_FORMAT_I420) ||
+ (frame->format == CAMERA_PIXEL_FORMAT_NV12));
+#if TIZEN_MM_DEBUG_VIDEO_DUMP_DECODED_FRAME == 1
+ frameDumper->DumpFrame(frame);
+#endif
VideoCaptureDeviceTizen* self = static_cast<VideoCaptureDeviceTizen*>(data);
+ if (!self->client_)
+ return;
camera_attr_fps_e current_fps =
static_cast<camera_attr_fps_e>(kTypicalFramerate);
camera_attr_get_preview_fps(self->camera_, ¤t_fps);
- DVLOG(3) << " width:" << frame->width
- << " height:" << frame->height;
+ DVLOG(3) << " width:" << frame->width << " height:" << frame->height;
+
+ const display::Display display =
+ display::Screen::GetScreen()->GetPrimaryDisplay();
- const gfx::Display display =
- gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
int orientation = display.RotationAsDegree();
gfx::Size target_resolution(frame->width, frame->height);
- int target_rotation = (orientation +
- GetCameraOrientation(self->device_name_.id().c_str())) % DEGREE_360;
+ int target_rotation =
+ (orientation +
+ GetCameraOrientation(self->device_descriptor_.device_id.c_str())) %
+ DEGREE_360;
int src_stride_y = frame->width;
int src_stride_uv = (src_stride_y + 1) / 2;
- WEBRTC_DEBUG_DUMPFRAME(frame, yplane);
media::VideoCaptureFormat videocaptureformat;
videocaptureformat.frame_size = gfx::Size(frame->width, frame->height);
videocaptureformat.frame_rate = static_cast<int>(current_fps);
videocaptureformat.pixel_format = media::PIXEL_FORMAT_I420;
- self->client_->OnIncomingCapturedYuvData(
- reinterpret_cast<uint8*>(frame->data.triple_plane.y),
- reinterpret_cast<uint8*>(frame->data.triple_plane.u),
- reinterpret_cast<uint8*>(frame->data.triple_plane.v),
- src_stride_y, src_stride_uv, src_stride_uv,
- videocaptureformat, target_rotation, base::TimeTicks::Now());
+ int dest_width = frame->width;
+ int dest_height = frame->height;
+ if (target_rotation == 90 || target_rotation == 270)
+ std::swap(dest_height, dest_width);
+
+ videocaptureformat.frame_size = gfx::Size(dest_width, dest_height);
+
+ auto reservation_result_code = self->client_->ReserveOutputBuffer(
+ videocaptureformat.frame_size, media::PIXEL_FORMAT_I420, 0,
+ &self->buffer_);
+
+ if (reservation_result_code !=
+ VideoCaptureDevice::Client::ReserveResult::kSucceeded)
+ DLOG(ERROR) << "Couldn't allocate Capture Buffer";
+
+ libyuv::RotationMode mode =
+ static_cast<libyuv::RotationMode>(target_rotation);
+
+ int dest_stride_y = dest_width;
+ int dest_stride_uv = (dest_stride_y + 1) / 2;
+
+ std::unique_ptr<VideoCaptureBufferHandle> buffer_handle =
+ self->buffer_.handle_provider->GetHandleForInProcessAccess();
+
+ DCHECK(buffer_handle->data()) << "Buffer has NO backing memory";
+
+ 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;
+
+ if (frame->format == 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);
+ } else if (frame->format == 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);
+ } else {
+ LOG(INFO) << "Unsupported Format";
+ return;
+ }
+
+ base::TimeTicks now = base::TimeTicks::Now();
+ if (self->first_ref_time_.is_null())
+ self->first_ref_time_ = now;
+
+ self->client_->OnIncomingCapturedBuffer(std::move(self->buffer_),
+ videocaptureformat, now,
+ now - self->first_ref_time_);
}
-void VideoCaptureDeviceTizen::OnAllocateAndStart(int width,
- int height,
- int frame_rate,
- VideoPixelFormat format,
- scoped_ptr<Client> client) {
- DVLOG(3) << " width:" << width
- << " height:" << height
- << " frame_rate:" << frame_rate
- << " format:" << media::VideoPixelFormatToString(format).c_str();
+void VideoCaptureDeviceTizen::OnAllocateAndStart(
+ int width,
+ int height,
+ int frame_rate,
+ VideoPixelFormat format,
+ std::unique_ptr<Client> client) {
+ DVLOG(3) << " width:" << width << " height:" << height
+ << " frame_rate:" << frame_rate
+ << " format:" << media::VideoPixelFormatToString(format).c_str();
- DCHECK_EQ(worker_.message_loop(), base::MessageLoop::current());
+ DCHECK(worker_.task_runner()->BelongsToCurrentThread());
client_ = std::move(client);
-#if !defined(EWK_BRINGUP)
- if (CAMERA_ERROR_NONE !=
- camera_create(DeviceNameToCameraId(device_name_), &camera_)) {
- LOG(ERROR) << "Fail to create camera";
- SetErrorState("Fail to create camera");
+ CameraHandle* camera_instance = CameraHandle::GetInstance();
+ if (camera_instance == nullptr) {
+ SetErrorState("Failed to get camera instance", FROM_HERE);
+ return;
+ }
+
+ if (camera_instance->GetDeviceName() !=
+ DeviceNameToCameraId(device_descriptor_)) {
+ camera_instance->ResetHandle(DeviceNameToCameraId(device_descriptor_));
+ }
+
+ camera_instance->SetClient(this);
+ camera_ = camera_instance->GetCameraHandle();
+ if (camera_ == nullptr) {
+ SetErrorState("Camera creation failed", FROM_HERE);
return;
}
-#endif
- if (CAMERA_ERROR_NONE !=
- camera_set_display(camera_, CAMERA_DISPLAY_TYPE_NONE, NULL)) {
- LOG(ERROR) << "Fail to set using camera buffer";
- SetErrorState("Camera internal Error");
+ int err = camera_set_display(camera_, CAMERA_DISPLAY_TYPE_NONE, nullptr);
+ if (CAMERA_ERROR_NONE != err) {
+ SetErrorState(GetErrorString(err), FROM_HERE);
return;
}
- if (CAMERA_ERROR_NONE !=
- camera_set_preview_resolution(camera_, width, height)) {
- LOG(WARNING) << "trying default resolution: "
- << kMjpegWidth << " x " << kMjpegHeight;
+ err = camera_set_preview_format(camera_, toCapiType(format));
+ if (CAMERA_ERROR_NONE != err) {
+ LOG(ERROR) << "camera_set_preview_format failed. Error# "
+ << GetErrorString(err);
- 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");
+ std::vector<media::VideoPixelFormat> supported_formats;
+ if (!camera_instance->GetSupportedPreviewPixelFormats(supported_formats)) {
+ SetErrorState("Camera internal error", FROM_HERE);
+ return;
+ }
+
+ LOG(ERROR) << "Trying with format (" << supported_formats[0] << ")";
+ err = camera_set_preview_format(camera_, toCapiType(supported_formats[0]));
+ if (CAMERA_ERROR_NONE != err) {
+ SetErrorState(GetErrorString(err), FROM_HERE);
return;
}
}
- if (CAMERA_ERROR_NONE !=
- camera_set_preview_format(camera_, toCapiType(format))) {
- 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");
+ err = camera_set_preview_resolution(camera_, width, height);
+ if (CAMERA_ERROR_NONE != err) {
+ LOG(ERROR) << "camera_set_preview_resolution failed. Error#" << err
+ << ". Trying default resolution: " << kMjpegWidth << " x "
+ << kMjpegHeight;
+
+ width = kMjpegWidth;
+ height = kMjpegHeight;
+ err = camera_set_preview_resolution(camera_, width, height);
+ if (CAMERA_ERROR_NONE != err) {
+ SetErrorState(GetErrorString(err), FROM_HERE);
return;
}
- if (supported_formats.empty()) {
- LOG(ERROR) << "Cannot get the supported formats for camera";
- SetErrorState("Camera internal Error");
+ }
+
+ if (use_media_packet_) {
+ err = camera_set_media_packet_preview_cb(
+ camera_, OnCameraCapturedWithMediaPacket, this);
+ if (CAMERA_ERROR_NONE != err) {
+ SetErrorState(GetErrorString(err), FROM_HERE);
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");
+ } else {
+ err = camera_set_preview_cb(camera_, OnCameraCaptured, this);
+ if (CAMERA_ERROR_NONE != err) {
+ SetErrorState(GetErrorString(err), FROM_HERE);
return;
}
}
- if (CAMERA_ERROR_NONE !=
- camera_set_preview_cb(camera_, OnCameraCaptured, this)) {
- SetErrorState("Camera internal Error");
- return;
+ err = camera_attr_set_preview_fps(camera_,
+ static_cast<camera_attr_fps_e>(frame_rate));
+ if (CAMERA_ERROR_NONE != err) {
+ LOG(ERROR) << "camera_attr_set_preview_fps failed. Error# " << err;
+
+ int max_supported_fps = camera_instance->GetMaxFrameRate(
+ CameraCapability::Resolution(width, height));
+ if (!max_supported_fps) {
+ SetErrorState("Camera internal error", FROM_HERE);
+ return;
+ }
+
+ err = camera_attr_set_preview_fps(
+ camera_, static_cast<camera_attr_fps_e>(max_supported_fps));
+ if (CAMERA_ERROR_NONE != err) {
+ SetErrorState(GetErrorString(err), FROM_HERE);
+ return;
+ }
}
- if (CAMERA_ERROR_NONE !=
- 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_, static_cast<camera_attr_fps_e>(kTypicalFramerate))) {
- SetErrorState("Camera internal Error");
+ if (IsMobileProfile() &&
+ (camera_instance->GetDeviceName() == CAMERA_DEVICE_CAMERA1)) {
+ err = camera_attr_set_stream_flip(camera_, CAMERA_FLIP_VERTICAL);
+ if (CAMERA_ERROR_NONE != err) {
+ SetErrorState(GetErrorString(err), FROM_HERE);
return;
}
}
+
state_ = kCapturing;
- if (CAMERA_ERROR_NONE != camera_start_preview(camera_)) {
- LOG(ERROR) << "Fail to start camera";
- SetErrorState("Camera internal Error");
+ err = camera_start_preview(camera_);
+ if (CAMERA_ERROR_NONE != err) {
+ SetErrorState(GetErrorString(err), FROM_HERE);
+ return;
}
+
+ if (IsMobileProfile())
+ WakeUpDisplayAndAcquireDisplayLock();
}
void VideoCaptureDeviceTizen::OnStopAndDeAllocate() {
- DCHECK_EQ(worker_.message_loop(), base::MessageLoop::current());
+ DCHECK(worker_.task_runner()->BelongsToCurrentThread());
+ if (use_media_packet_)
+ camera_unset_media_packet_preview_cb(camera_);
+ else
+ camera_unset_preview_cb(camera_);
camera_stop_preview(camera_);
- camera_destroy(camera_);
+
+ if (IsMobileProfile())
+ ReleaseDisplayLock();
state_ = kIdle;
client_.reset();
}
-void VideoCaptureDeviceTizen::SetErrorState(const std::string& reason) {
- LOG(ERROR) << "Camera Error: " << reason;
+const char* VideoCaptureDeviceTizen::GetErrorString(int err_code) {
+ switch (err_code) {
+ ENUM_CASE(CAMERA_ERROR_NONE);
+ ENUM_CASE(CAMERA_ERROR_INVALID_PARAMETER);
+ ENUM_CASE(CAMERA_ERROR_INVALID_STATE);
+ ENUM_CASE(CAMERA_ERROR_OUT_OF_MEMORY);
+ ENUM_CASE(CAMERA_ERROR_DEVICE);
+ ENUM_CASE(CAMERA_ERROR_INVALID_OPERATION);
+ ENUM_CASE(CAMERA_ERROR_SECURITY_RESTRICTED);
+ ENUM_CASE(CAMERA_ERROR_DEVICE_BUSY);
+ ENUM_CASE(CAMERA_ERROR_DEVICE_NOT_FOUND);
+ ENUM_CASE(CAMERA_ERROR_ESD);
+ ENUM_CASE(CAMERA_ERROR_PERMISSION_DENIED);
+ ENUM_CASE(CAMERA_ERROR_NOT_SUPPORTED);
+ ENUM_CASE(CAMERA_ERROR_RESOURCE_CONFLICT);
+ ENUM_CASE(CAMERA_ERROR_SERVICE_DISCONNECTED);
+ };
+ NOTREACHED() << "Unknown camera error code #" << err_code;
+ return "";
+}
+
+void VideoCaptureDeviceTizen::SetErrorState(const char* error,
+ const base::Location& location) {
+ LOG(ERROR) << "Camera error# " << error << " from "
+ << location.function_name() << "(" << location.line_number()
+ << ")";
+
DCHECK(!worker_.IsRunning() ||
- worker_.message_loop() == base::MessageLoop::current());
+ worker_.task_runner()->BelongsToCurrentThread());
state_ = kError;
- client_->OnError(FROM_HERE, reason);
+ // EWK_BRINGUP: Handle VideoCaptureError
+ ChangeCapturingState(false);
+ client_->OnError(
+ VideoCaptureError::kVideoCaptureControllerIsAlreadyInErrorState, location,
+ error);
}
} // namespace media