Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(825)

Unified Diff: media/capture/video/chromeos/camera_hal_delegate.h

Issue 2837273004: media: add video capture device for ARC++ camera HAL v3 (Closed)
Patch Set: WIP: media: add video capture device for ARC++ camera HAL v3 Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/capture/video/chromeos/camera_hal_delegate.h
diff --git a/media/capture/video/chromeos/camera_hal_delegate.h b/media/capture/video/chromeos/camera_hal_delegate.h
new file mode 100644
index 0000000000000000000000000000000000000000..15f305ae241e09916402be4e2d2cf71bce756506
--- /dev/null
+++ b/media/capture/video/chromeos/camera_hal_delegate.h
@@ -0,0 +1,136 @@
+// Copyright 2017 The Chromium Authors. 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_CHROMEOS_CAMERA_HAL_DELEGATE_H_
+#define MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_
+
+#include "base/macros.h"
+#include "base/synchronization/waitable_event.h"
+#include "base/threading/thread.h"
+#include "media/capture/video/chromeos/mojo/arc_camera3.mojom.h"
+#include "media/capture/video/video_capture_device_factory.h"
+#include "media/capture/video_capture_types.h"
+#include "mojo/public/cpp/bindings/binding.h"
+
+namespace media {
+
+// VideoCaptureDeviceFactoryChromeOS delegates all its VCD factory interface
+// function calls to CameraHalDelegate.
+
+class CAPTURE_EXPORT CameraHalDelegate final
+ : public base::RefCountedThreadSafe<CameraHalDelegate>,
+ public arc::mojom::CameraModuleCallbacks {
+ public:
+ CameraHalDelegate(
+ const scoped_refptr<base::SingleThreadTaskRunner> module_task_runner);
+
+ // Establishes the Mojo IPC channel to the camera HAL adapter. This method
+ // should be called before any other methods of CameraHalDelegate is called.
+ // Called by VideoCaptureDeviceFactoryChromeOS::Init on the browser IO thread.
+ bool StartCameraModuleIpc();
+
+ // Delegation methods for the VideoCaptureDeviceFactory interface. These
+ // methods are called by VideoCaptureDeviceFactoryChromeOS directly. They
+ // operate on the same thread that the VideoCaptureDeviceFactoryChromeOS runs
+ // on.
+ std::unique_ptr<VideoCaptureDevice> CreateDevice(
+ const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
+ const VideoCaptureDeviceDescriptor& device_descriptor);
+ void GetSupportedFormats(
+ const VideoCaptureDeviceDescriptor& device_descriptor,
+ VideoCaptureFormats* supported_formats);
+ void GetDeviceDescriptors(VideoCaptureDeviceDescriptors* device_descriptors);
+
+ // Synchronous method to get the camera info of |camera_id|. This method may
+ // be called on any thread.
+ using GetCameraInfoCallback =
+ base::Callback<void(int32_t, arc::mojom::CameraInfoPtr)>;
+ void GetCameraInfo(int32_t camera_id, const GetCameraInfoCallback& callback);
+
+ // Asynchronous method to open the camera device desginated by |camera_id|.
+ // This method may be called on any thread; |callback| will run on
+ // |module_task_runner_|.
+ using OpenDeviceCallback =
+ base::Callback<void(int32_t, arc::mojom::Camera3DeviceOpsPtr)>;
+ void OpenDevice(int32_t camera_id, const OpenDeviceCallback& callback);
+
+ private:
+ friend class base::RefCountedThreadSafe<CameraHalDelegate>;
+
+ ~CameraHalDelegate();
+
+ // Resets the Mojo interface and bindings.
+ void ResetMojoInterfaceOnModuleThread(base::WaitableEvent* interface_closed);
+
+ // Internal method to attempt to update the camera info for all cameras.
+ // Runs on the same thread as CreateDevice, GetSupportedFormats, and
+ // GetDeviceDescriptors. This is the only entry point to update
+ // |num_cameras_| and |camera_info_|.
+ bool UpdateCameraInfo();
+
+ // The actual methods that update the camera info. These methods run on
+ // |module_task_runner_|.
+ void UpdateCameraInfoOnModuleThread();
+ void OnGotNumberOfCamerasOnModuleThread(int32_t num_cameras);
+ void GetCameraInfoOnModuleThread(int32_t camera_id,
+ const GetCameraInfoCallback& callback);
+ void OnGotCameraInfoOnModuleThread(int32_t camera_id,
+ int32_t result,
+ arc::mojom::CameraInfoPtr camera_info);
+
+ // Signaled when |num_cameras_| and |camera_info_| are updated. Queried and
+ // waited by UpdateCameraInfo, signaled by OnGotCameraInfoOnModuleThread, and
+ // reset by CameraDeviceStatusChange.
+ base::WaitableEvent camera_info_updated_;
+
+ // Indicates if a camera info update is in flight, to prevent issuing
+ // duplicated GetCameraInfo calls to |camera_module_delegate_|.
+ bool updating_camera_info_;
+
+ // |num_cameras_| stores the number of camera devices reported by the camera
+ // HAL, and |camera_info_| stores the camera info of each camera device.
+ // They are modified only on |module_task_runner_|. They are also read in
+ // GetSupportedFormats and GetDeviceDescriptors, in which the access is
+ // sequenced through UpdateCameraInfo and |camera_info_updated_| to avoid race
+ // conditions.
+ uint32_t num_cameras_;
+ std::unordered_map<int32_t, arc::mojom::CameraInfoPtr> camera_info_;
+
+ // Called by OpenDevice to actually open the device specified by |camera_id|.
+ // This method runs on |module_task_runner_|.
+ void OpenDeviceOnModuleThread(int32_t camera_id,
+ const OpenDeviceCallback& callback);
+
+ // Registers camera HAL module callback functions. SetCallbacks is called
+ // after GetNumberOfCameras is called for the first time, and before any other
+ // calls to |camera_module_|. These methods run on |module_task_runner_|.
+ void SetCallbacksOnModuleThread();
+ void OnSetCallbacksOnModuleThread(int32_t result);
+ // Indicates if the module callbacks are successfully registered.
+ bool module_callbacks_registered_;
+
+ // CameraModuleCallbacks implementation. Operates on |module_task_runner_|.
+ void CameraDeviceStatusChange(
+ int32_t camera_id,
+ arc::mojom::CameraDeviceStatus new_status) final;
+
+ base::ThreadChecker thread_checker_;
+
+ // The task runner where all the camera module Mojo communication takes place.
+ const scoped_refptr<base::SingleThreadTaskRunner> module_task_runner_;
+
+ // The Mojo proxy to access the camera module at the remote camera HAL. Bound
+ // to |module_task_runner_|.
+ arc::mojom::CameraModulePtr camera_module_;
+
+ // The Mojo binding serving the camera module callbacks. Bound to
+ // |module_task_runner_|.
+ mojo::Binding<arc::mojom::CameraModuleCallbacks> camera_module_callbacks_;
+
+ DISALLOW_COPY_AND_ASSIGN(CameraHalDelegate);
+};
+
+} // namespace media
+
+#endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_

Powered by Google App Engine
This is Rietveld 408576698