Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_VIDEO_CAPTURE_DEVICE_CHROMEOS_H_ | |
| 6 #define MEDIA_CAPTURE_VIDEO_CHROMEOS_VIDEO_CAPTURE_DEVICE_CHROMEOS_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <string> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "base/threading/thread.h" | |
| 15 #include "media/capture/video/chromeos/mojo/arc_camera3.mojom.h" | |
| 16 #include "media/capture/video/video_capture_device.h" | |
| 17 #include "media/capture/video/video_capture_device_descriptor.h" | |
| 18 #include "media/capture/video_capture_types.h" | |
| 19 | |
| 20 namespace display { | |
| 21 | |
| 22 class Display; | |
| 23 | |
| 24 } // namespace display | |
| 25 | |
| 26 namespace media { | |
| 27 | |
| 28 class CameraHalDelegate; | |
| 29 class CameraDeviceDelegate; | |
| 30 | |
| 31 // Implementation of VideoCaptureDevice for ChromeOS with ARC++ camera HALv3. | |
| 32 class CAPTURE_EXPORT VideoCaptureDeviceArcChromeOS final | |
| 33 : public VideoCaptureDevice { | |
| 34 public: | |
| 35 // Converts the HAL pixel format |from| to Chromium pixel format. Returns | |
| 36 // PIXEL_FORMAT_UNKNOWN if |from| is not supported. | |
| 37 static VideoPixelFormat PixFormatHalToChromium( | |
| 38 arc::mojom::HalPixelFormat from); | |
| 39 | |
| 40 // Converts the Chromium pixel format |from| to DRM pixel format. Returns 0 | |
| 41 // if |from| is not supported. | |
| 42 static uint32_t PixFormatChromiumToDrm(VideoPixelFormat from); | |
| 43 | |
| 44 VideoCaptureDeviceArcChromeOS( | |
| 45 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | |
| 46 const VideoCaptureDeviceDescriptor& device_descriptor, | |
| 47 scoped_refptr<CameraHalDelegate> camera_hal_delegate); | |
| 48 | |
| 49 ~VideoCaptureDeviceArcChromeOS() final; | |
| 50 | |
| 51 // VideoCaptureDevice implementation. | |
| 52 void AllocateAndStart(const VideoCaptureParams& params, | |
| 53 std::unique_ptr<Client> client) final; | |
| 54 void StopAndDeAllocate() final; | |
| 55 void TakePhoto(TakePhotoCallback callback) final; | |
| 56 void GetPhotoCapabilities(GetPhotoCapabilitiesCallback callback) final; | |
| 57 void SetPhotoOptions(mojom::PhotoSettingsPtr settings, | |
| 58 SetPhotoOptionsCallback callback) final; | |
| 59 | |
| 60 private: | |
| 61 // Internal methods which AllocateAndStart depends on to create a camera | |
| 62 // device. OnGotCameraInfo and OnOpenDevice are callbacks provided to the | |
| 63 // |camera_hal_delegate_| Mojo IPC calls, and are run on the | |
| 64 // |module_task_runner_| of |camera_hal_delegate_|. | |
| 65 void OnGotCameraInfo(const VideoCaptureParams& params, | |
| 66 std::unique_ptr<Client> client, | |
| 67 base::WaitableEvent* started, | |
| 68 int32_t result, | |
| 69 arc::mojom::CameraInfoPtr camera_info); | |
| 70 void OnOpenedDevice(const VideoCaptureParams& params, | |
| 71 std::unique_ptr<Client> client, | |
| 72 base::WaitableEvent* started, | |
| 73 arc::mojom::CameraMetadataPtr static_metadata, | |
| 74 int32_t result, | |
| 75 arc::mojom::Camera3DeviceOpsPtr device_ops); | |
| 76 | |
| 77 const VideoCaptureDeviceDescriptor device_descriptor_; | |
| 78 | |
| 79 // A reference to the CameraHalDelegate instance in the VCD factory. This is | |
| 80 // used by AllocateAndStart to query camera info and create the camera device. | |
| 81 const scoped_refptr<CameraHalDelegate> camera_hal_delegate_; | |
| 82 | |
| 83 // A reference to the thread that all the VideoCaptureDevice interface methods | |
| 84 // are called. | |
| 85 const scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; | |
| 86 | |
| 87 // The thread that all the Mojo operations of |camera_device_delegate_| take | |
| 88 // place. Started in CreateDeviceOnCaptureThread and stopped in | |
|
wuchengli
2017/05/18 04:26:14
s/CreateDeviceOnCaptureThread/AllocateAndStart
jcliang
2017/05/22 13:54:14
Done.
| |
| 89 // StopAndDeAllocate, where the access to the base::Thread methods are | |
| 90 // sequenced on |capture_task_runner_|. | |
| 91 base::Thread device_thread_; | |
| 92 | |
| 93 // Internal delegate doing the actual capture setting, buffer allocation and | |
| 94 // circulation with the camera HAL. Created on |module_task_runner_| of | |
| 95 // |camera_hal_delegate_| in OnOpenedDevice and deleted in StopAndDeAllocate | |
| 96 // on |capture_task_runner_|. The creation and deletion of | |
| 97 // |camera_device_delegate_| is serialized through a WaitableEvent. | |
| 98 // All methods of |camera_device_delegate_| operate on |device_thread_|. | |
| 99 scoped_refptr<CameraDeviceDelegate> camera_device_delegate_; | |
| 100 | |
| 101 class ScreenObserverDelegate; | |
| 102 | |
| 103 void SetRotation(int rotation); | |
| 104 void SetDisplayRotation(const display::Display& display); | |
| 105 | |
| 106 scoped_refptr<ScreenObserverDelegate> screen_observer_delegate_; | |
| 107 const VideoFacingMode lens_facing_; | |
| 108 const int camera_orientation_; | |
| 109 // Whether the incoming frames should rotate when the device rotates. | |
| 110 const bool rotates_with_device_; | |
| 111 | |
| 112 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceArcChromeOS); | |
| 113 }; | |
| 114 | |
| 115 } // namespace media | |
| 116 | |
| 117 #endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_VIDEO_CAPTURE_DEVICE_CHROMEOS_H_ | |
| OLD | NEW |