[M108 Migration][MM] getUserMedia bringup patch. 72/287872/7
authorSuhaspoornachandra <s.poornachan@samsung.com>
Tue, 7 Feb 2023 07:00:16 +0000 (12:30 +0530)
committerBot Blink <blinkbot@samsung.com>
Thu, 2 Mar 2023 02:51:21 +0000 (02:51 +0000)
 - Enable Tizen port to use camera api.
 - Fix device orientation issue.
 - Use sw path to rendering camera preview.

References:
https://review.tizen.org/gerrit/279607
https://review.tizen.org/gerrit/280370
https://review.tizen.org/gerrit/280507

Change-Id: I3655507ac09d2d3183bacfbdfbc14387b53b109f
Signed-off-by: Suhaspoornachandra <s.poornachan@samsung.com>
15 files changed:
content/browser/renderer_host/media/video_capture_controller.cc
content/public/common/content_features.cc
media/capture/BUILD.gn
media/capture/video/create_video_capture_device_factory.cc
third_party/blink/renderer/modules/mediastream/webmediaplayer_ms.cc
tizen_src/chromium_impl/content/browser/browser_efl.gni
tizen_src/chromium_impl/media/base/efl/media_player_util_efl.cc
tizen_src/chromium_impl/media/base/efl/media_player_util_efl.h
tizen_src/chromium_impl/media/capture/video/tizen/camera_device_tizen.cc [new file with mode: 0644]
tizen_src/chromium_impl/media/capture/video/tizen/camera_device_tizen.h [new file with mode: 0644]
tizen_src/chromium_impl/media/capture/video/tizen/video_capture_device_factory_tizen.cc
tizen_src/chromium_impl/media/capture/video/tizen/video_capture_device_factory_tizen.h
tizen_src/chromium_impl/media/capture/video/tizen/video_capture_device_tizen.cc
tizen_src/chromium_impl/media/capture/video/tizen/video_capture_device_tizen.h
tizen_src/chromium_impl/media/media_efl.gni

index fb79c68..49794bd 100644 (file)
@@ -292,7 +292,11 @@ VideoCaptureController::VideoCaptureController(
       device_launcher_(std::move(device_launcher)),
       emit_log_message_cb_(std::move(emit_log_message_cb)),
       device_launch_observer_(nullptr),
+#if defined(TIZEN_MULTIMEDIA)
+      state_(blink::VIDEO_CAPTURE_STATE_STARTED),
+#else
       state_(blink::VIDEO_CAPTURE_STATE_STARTING),
+#endif
       has_received_frames_(false) {
   DCHECK_CURRENTLY_ON(BrowserThread::IO);
 }
index 3e0efe3..2ce7fba 100644 (file)
@@ -673,7 +673,12 @@ BASE_FEATURE(kMojoDedicatedThread,
 // Enables/disables the video capture service.
 BASE_FEATURE(kMojoVideoCapture,
              "MojoVideoCapture",
-             base::FEATURE_ENABLED_BY_DEFAULT);
+#if defined(TIZEN_MULTIMEDIA)
+             base::FEATURE_DISABLED_BY_DEFAULT
+#else
+             base::FEATURE_ENABLED_BY_DEFAULT
+#endif
+);
 
 // A secondary switch used in combination with kMojoVideoCapture.
 // This is intended as a kill switch to allow disabling the service on
index 6a0df28..6b81676 100644 (file)
@@ -8,6 +8,10 @@ import("//build/config/ui.gni")
 import("//media/media_options.gni")
 import("//testing/test.gni")
 
+if (tizen_multimedia) {
+  import("//tizen_src/chromium_impl/media/media_efl.gni")
+}
+
 group("capture") {
   public_deps = [
     ":capture_lib",
@@ -163,6 +167,11 @@ component("capture_lib") {
     "//ui/gfx",
   ]
 
+  if (tizen_multimedia) {
+    configs += external_media_capture_config
+    sources += external_media_capture_sources
+  }
+
   if (is_android) {
     public_deps += [
       "content/android",
index b4abd2b..2df72fd 100644 (file)
 #include "media/capture/video/fuchsia/video_capture_device_factory_fuchsia.h"
 #endif
 
+#if defined(TIZEN_MULTIMEDIA)
+#include "media/capture/video/tizen/video_capture_device_factory_tizen.h"
+#endif
+
 namespace media {
 
 namespace {
@@ -55,6 +59,9 @@ CreateFakeVideoCaptureDeviceFactory() {
 std::unique_ptr<VideoCaptureDeviceFactory>
 CreatePlatformSpecificVideoCaptureDeviceFactory(
     scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
+#if defined(TIZEN_MULTIMEDIA)
+  return std::make_unique<VideoCaptureDeviceFactoryTizen>(ui_task_runner);
+#endif
 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
   return std::make_unique<VideoCaptureDeviceFactoryLinux>(ui_task_runner);
 #elif BUILDFLAG(IS_CHROMEOS_ASH)
index 01b3e05..0d78986 100644 (file)
 #include "third_party/blink/renderer/platform/wtf/cross_thread_copier_media.h"
 #include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
 
+#if BUILDFLAG(IS_TIZEN)
+#include "tizen/system_info.h"
+#endif
+
 namespace WTF {
 
 template <>
@@ -207,6 +211,12 @@ class WebMediaPlayerMS::FrameDeliverer {
             kUseGpuMemoryBufferVideoFramesMinResolution.width() ||
         frame->visible_rect().height() <
             kUseGpuMemoryBufferVideoFramesMinResolution.height();
+#elif (BUILDFLAG(IS_TIZEN_TV) && defined(TIZEN_VIDEO_HOLE)) || \
+    defined(TIZEN_EMULATOR_SUPPORT)
+    skip_creating_gpu_memory_buffer = true;
+#elif BUILDFLAG(IS_TIZEN)
+    if (IsCommonProfile())
+      skip_creating_gpu_memory_buffer = true;
 #endif  // BUILDFLAG(IS_WIN)
 
     if (skip_creating_gpu_memory_buffer) {
index d0f3989..d8d24db 100644 (file)
@@ -141,6 +141,8 @@ if (tizen_multimedia) {
   external_content_browser_efl_configs += [
     "//tizen_src/build:esplusplayer",
     "//tizen_src/build:libesplusplayer",
+    "//tizen_src/build:capi-media-player",
+    "//tizen_src/build:libcapi-media-player",
   ]
 
   external_content_browser_efl_sources += [
index 3655861..60f291f 100644 (file)
@@ -77,6 +77,11 @@ MediaError GetMediaError(int capi_player_error) {
   return retval;
 }
 
+void MediaFormatDeleter::operator()(media_format_s* ptr) const {
+  if (ptr != nullptr)
+    media_format_unref(ptr);
+}
+
 void MediaPacketDeleter::operator()(media_packet_s* ptr) const {
   if (ptr != nullptr)
     media_packet_destroy(ptr);
index 596ccb8..2f74670 100644 (file)
@@ -5,17 +5,22 @@
 #ifndef MEDIA_BASE_EFL_MEDIA_PLAYER_UTIL_EFL_H_
 #define MEDIA_BASE_EFL_MEDIA_PLAYER_UTIL_EFL_H_
 
+#include <player.h>
+
 #include "media/base/media_export.h"
 #include "url/gurl.h"
 
-struct media_packet_s;
-
 namespace media {
 
+struct MediaFormatDeleter {
+  void operator()(media_format_s* ptr) const;
+};
+
 struct MediaPacketDeleter {
   void operator()(media_packet_s* ptr) const;
 };
 
+typedef std::unique_ptr<media_format_s, MediaFormatDeleter> ScopedMediaFormat;
 typedef std::unique_ptr<media_packet_s, MediaPacketDeleter> ScopedMediaPacket;
 
 typedef enum {
diff --git a/tizen_src/chromium_impl/media/capture/video/tizen/camera_device_tizen.cc b/tizen_src/chromium_impl/media/capture/video/tizen/camera_device_tizen.cc
new file mode 100644 (file)
index 0000000..703389c
--- /dev/null
@@ -0,0 +1,254 @@
+// 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
diff --git a/tizen_src/chromium_impl/media/capture/video/tizen/camera_device_tizen.h b/tizen_src/chromium_impl/media/capture/video/tizen/camera_device_tizen.h
new file mode 100644 (file)
index 0000000..f649d04
--- /dev/null
@@ -0,0 +1,77 @@
+// Copyright 2019 Samsung Electronics Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_CAPTURE_VIDEO_TIZEN_CAMERA_DEVICE_TIZEN_H_
+#define MEDIA_CAPTURE_VIDEO_TIZEN_CAMERA_DEVICE_TIZEN_H_
+
+#include <camera.h>
+#include <vector>
+
+#include "base/memory/singleton.h"
+#include "media/base/video_types.h"
+#include "ui/gfx/gpu_memory_buffer.h"
+
+namespace media {
+
+struct VideoCaptureFormat;
+typedef std::vector<VideoCaptureFormat> VideoCaptureFormats;
+
+struct CameraCapability {
+  typedef gfx::Size Resolution;
+  typedef int Fps;
+
+  CameraCapability() : fps(0) {}
+
+  CameraCapability(gfx::Size frame, int rate) : resolution(frame), fps(rate) {}
+
+  Resolution resolution;
+  Fps fps;
+};
+
+class CameraHandleClient {
+ public:
+  virtual void OnStreamStopped() {}
+
+ protected:
+  virtual ~CameraHandleClient() {}
+};
+
+class CameraHandle final {
+ public:
+  static CameraHandle* GetInstance();
+
+  camera_h GetCameraHandle() { return camera_handle_; }
+  camera_device_e GetDeviceName() { return device_name_; }
+
+  bool IsValid();
+  bool GetSupportedPreviewPixelFormats(
+      std::vector<media::VideoPixelFormat>& supported_formats) const;
+  void GetDeviceSupportedFormats(media::VideoCaptureFormats& supported_formats);
+  int GetMaxFrameRate(CameraCapability::Resolution) const;
+  int GetDeviceCounts();
+  void ResetHandle(camera_device_e device_name);
+  void SetClient(CameraHandleClient* client);
+  void UnsetClient(CameraHandleClient* client);
+
+ private:
+  CameraHandle();
+  ~CameraHandle();
+
+  CameraHandle(const CameraHandle&) = delete;
+  CameraHandle& operator=(const CameraHandle&) = delete;
+
+  bool GetSupportedPreviewResolutions(
+      std::vector<CameraCapability::Resolution>& supported_resolutions) const;
+  bool GetSupportedPreviewCapabilities(std::vector<CameraCapability>&) const;
+
+  camera_h camera_handle_;
+  camera_device_e device_name_;
+  CameraHandleClient* client_;
+
+  friend struct base::DefaultSingletonTraits<CameraHandle>;
+};
+
+}  // namespace media
+
+#endif  // MEDIA_CAPTURE_VIDEO_TIZEN_CAMERA_DEVICE_TIZEN_H_
index 4205b15..aa935bb 100644 (file)
@@ -1,4 +1,4 @@
-// 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(
@@ -209,18 +19,22 @@ 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";
@@ -232,38 +46,28 @@ void VideoCaptureDeviceFactoryTizen::GetDeviceNames(
     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
index 8c4f77a..77cfed6 100644 (file)
@@ -18,10 +18,6 @@ class MEDIA_EXPORT VideoCaptureDeviceFactoryTizen
  public:
   explicit VideoCaptureDeviceFactoryTizen(
       scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
-  VideoCaptureDeviceFactoryTizen(const VideoCaptureDeviceFactoryTizen&) =
-      delete;
-  VideoCaptureDeviceFactoryTizen& operator=(
-      const VideoCaptureDeviceFactoryTizen&) = delete;
   ~VideoCaptureDeviceFactoryTizen() override;
 
   VideoCaptureDeviceFactoryTizen(const VideoCaptureDeviceFactoryTizen&) =
@@ -29,12 +25,9 @@ class MEDIA_EXPORT VideoCaptureDeviceFactoryTizen
   VideoCaptureDeviceFactoryTizen& operator=(
       const VideoCaptureDeviceFactoryTizen&) = delete;
 
-  scoped_ptr<VideoCaptureDevice> Create(
-      const VideoCaptureDevice::Name& device_name) override;
-  void GetDeviceNames(VideoCaptureDevice::Names* device_names) override;
-  void GetDeviceSupportedFormats(
-      const VideoCaptureDevice::Name& device,
-      VideoCaptureFormats* supported_formats) override;
+  VideoCaptureErrorOrDevice CreateDevice(
+      const VideoCaptureDeviceDescriptor& device_descriptor) override;
+  void GetDevicesInfo(GetDevicesInfoCallback callback) override;
 
  private:
   scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
index 2fc0250..85251ff 100644 (file)
@@ -1,4 +1,4 @@
-// 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.
 
@@ -6,54 +6,20 @@
 
 #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,
@@ -62,33 +28,6 @@ enum CameraOrientation {
   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:
@@ -115,17 +54,6 @@ camera_pixel_format_e toCapiType(media::VideoPixelFormat e) {
   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_;
@@ -133,11 +61,11 @@ struct CameraSpec {
 
 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;
@@ -145,10 +73,14 @@ const std::vector<CameraSpec>& GetCameraSpec() {
     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";
 
@@ -156,19 +88,19 @@ const std::string VideoCaptureDeviceTizen::kCameraId0 = "0";
 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) {
@@ -182,215 +114,486 @@ 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_, &current_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_, &current_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
index d6d6258..9e732e3 100644 (file)
@@ -1,4 +1,4 @@
-// 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.
 
@@ -8,47 +8,56 @@
 #ifndef MEDIA_VIDEO_CAPTURE_TIZEN_VIDEO_CAPTURE_DEVICE_TIZEN_H_
 #define MEDIA_VIDEO_CAPTURE_TIZEN_VIDEO_CAPTURE_DEVICE_TIZEN_H_
 
-#include <camera.h>
-
 #include "base/threading/thread.h"
+#include "base/time/time.h"
+#include "media/base/efl/media_player_util_efl.h"
+#include "media/capture/video/tizen/camera_device_tizen.h"
 #include "media/capture/video/video_capture_device.h"
 
 namespace media {
 
-class VideoCaptureDeviceTizen : public VideoCaptureDevice {
+class VideoCaptureDeviceTizen : public VideoCaptureDevice,
+                                public CameraHandleClient {
  public:
   const static std::string kFrontCameraName;
   const static std::string kBackCameraName;
   const static std::string kCameraId0;
   const static std::string kCameraId1;
-  const static std::string GetFrontCameraID();
-  const static std::string GetBackCameraID();
+  const static char* GetFrontCameraID();
+  const static char* GetBackCameraID();
 
-  explicit VideoCaptureDeviceTizen(const Name& device_name);
+  explicit VideoCaptureDeviceTizen(
+      const VideoCaptureDeviceDescriptor& device_descriptor);
   virtual ~VideoCaptureDeviceTizen() override;
 
-  virtual void AllocateAndStart(const VideoCaptureParams& params,
-                                std::unique_ptr<Client> client) override;
+  VideoCaptureDeviceTizen() = delete;
+  VideoCaptureDeviceTizen(const VideoCaptureDeviceTizen&) = delete;
+  VideoCaptureDeviceTizen& operator=(const VideoCaptureDeviceTizen&) = delete;
+
+  void AllocateAndStart(const VideoCaptureParams& params,
+                        std::unique_ptr<Client> client) override;
 
-  virtual void StopAndDeAllocate() override;
+  void StopAndDeAllocate() override;
+
+  void OnStreamStopped() override;
 
-#if !defined(EWK_BRINGUP)
-  // FIXME: Name is undefined.
   static camera_device_e DeviceNameToCameraId(
-    const VideoCaptureDevice::Name& device_name);
-#endif
+      const VideoCaptureDeviceDescriptor& device_descriptor);
 
   static std::string GetCameraErrorMessage(int err_code);
+  static void OnCameraCapturedWithMediaPacket(media_packet_h pkt, void* data);
+  static void OnCameraCaptured(camera_preview_data_s* frame, void* data);
+
+  static const char* GetErrorString(int err_code);
 
  private:
   enum InternalState {
-    kIdle,  // The device driver is opened but camera is not in use.
+    kIdle,       // The device driver is opened but camera is not in use.
     kCapturing,  // Video is being captured.
-    kError  // Error accessing HW functions.
-            // User needs to recover by destroying the object.
+    kError       // Error accessing HW functions.
+                 // User needs to recover by destroying the object.
   };
 
-  static void OnCameraCaptured(camera_preview_data_s* frame, void* data);
   void OnAllocateAndStart(int width,
                           int height,
                           int frame_rate,
@@ -56,15 +65,26 @@ class VideoCaptureDeviceTizen : public VideoCaptureDevice {
                           std::unique_ptr<Client> client);
   void OnStopAndDeAllocate();
 
-  void SetErrorState(const std::string& reason);
+  // For handling the camera preview callback returning mediapacket
+  bool IsCapturing();
+  void ChangeCapturingState(bool state);
+  void PreviewCameraCaptured(ScopedMediaPacket pkt);
 
-  InternalState state_;
+  void SetErrorState(const char* reason, const base::Location& location);
+
+  camera_h camera_;
   std::unique_ptr<VideoCaptureDevice::Client> client_;
-  Name device_name_;
+  VideoCaptureDevice::Client::Buffer buffer_;
+  base::Lock capturing_state_lock_;
+
+  VideoCaptureDeviceDescriptor device_descriptor_;
   base::Thread worker_;  // Thread used for reading data from the device.
-  std::unique_ptr<VideoCaptureDevice::Client::Buffer> buffer_;
-  camera_h camera_;
-  // DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceTizen);
+
+  bool is_capturing_;
+  bool use_media_packet_;
+  InternalState state_;
+
+  base::TimeTicks first_ref_time_;
 };
 
 }  // namespace media
index 7a06278..07c9db2 100644 (file)
@@ -12,6 +12,8 @@ external_exclude_media_efl_sources = []
 external_media_efl_config = []
 external_media_video_decode_config = []
 external_media_video_decode_sources = []
+external_media_capture_config = []
+external_media_capture_sources = []
 
 if (use_ozone) {
   external_media_efl_deps += [ "//tizen_src/chromium_impl/ui/ozone:ozone_efl" ]
@@ -74,6 +76,20 @@ if (tizen_multimedia) {
       "//tizen_src/chromium_impl/media/base/tizen/video_plane_controller_esplusplayer.h",
     ]
   }
+
+  external_media_capture_config += [
+    "//tizen_src/build:capi-media-camera",
+    "//tizen_src/build:libcapi-media-camera",
+  ]
+
+  external_media_capture_sources += [
+    "//tizen_src/chromium_impl/media/capture/video/tizen/camera_device_tizen.cc",
+    "//tizen_src/chromium_impl/media/capture/video/tizen/camera_device_tizen.h",
+    "//tizen_src/chromium_impl/media/capture/video/tizen/video_capture_device_factory_tizen.cc",
+    "//tizen_src/chromium_impl/media/capture/video/tizen/video_capture_device_factory_tizen.h",
+    "//tizen_src/chromium_impl/media/capture/video/tizen/video_capture_device_tizen.cc",
+    "//tizen_src/chromium_impl/media/capture/video/tizen/video_capture_device_tizen.h",
+  ]
 }
 
 if (tizen_audio_io) {