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 // blah blah blah... | |
|
wuchengli
2017/04/28 06:29:28
Update this.
jcliang
2017/04/28 08:27:49
Removed.
| |
| 6 | |
| 7 #ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_VIDEO_CAPTURE_DEVICE_CHROMEOS_H_ | |
| 8 #define MEDIA_CAPTURE_VIDEO_CHROMEOS_VIDEO_CAPTURE_DEVICE_CHROMEOS_H_ | |
| 9 | |
| 10 #include <stdint.h> | |
| 11 | |
| 12 #include <memory> | |
| 13 #include <string> | |
| 14 | |
| 15 #include "base/macros.h" | |
| 16 #include "base/threading/thread.h" | |
| 17 #include "media/capture/video/chromeos/mojo/arc_camera3.mojom.h" | |
| 18 #include "media/capture/video/video_capture_device.h" | |
| 19 #include "media/capture/video/video_capture_device_descriptor.h" | |
| 20 #include "media/capture/video_capture_types.h" | |
| 21 | |
| 22 namespace display { | |
| 23 | |
| 24 class Display; | |
| 25 | |
| 26 } // namespace display | |
| 27 | |
| 28 namespace media { | |
| 29 | |
| 30 class CameraHalDelegate; | |
| 31 class CameraDeviceDelegate; | |
| 32 | |
| 33 // Implementation of VideoCaptureDevice for ChromeOS with ARC++ camera HALv3. | |
| 34 class CAPTURE_EXPORT VideoCaptureDeviceArcChromeOS final | |
| 35 : public VideoCaptureDevice { | |
| 36 public: | |
| 37 // Converts the HAL pixel format |from| to Chromium pixel format. Returns | |
| 38 // PIXEL_FORMAT_UNKNOWN if |from| is not supported. | |
| 39 static VideoPixelFormat PixFormatHalToChromium( | |
| 40 arc::mojom::HalPixelFormat from); | |
| 41 | |
| 42 // Converts the Chromium pixel format |from| to DRM pixel format. Returns 0 | |
| 43 // if |from| is not supported. | |
| 44 static uint32_t PixFormatChromiumToDrm(VideoPixelFormat from); | |
| 45 | |
| 46 VideoCaptureDeviceArcChromeOS( | |
| 47 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | |
| 48 const VideoCaptureDeviceDescriptor& device_descriptor, | |
| 49 scoped_refptr<CameraHalDelegate> camera_hal_delegate); | |
| 50 | |
| 51 ~VideoCaptureDeviceArcChromeOS() final; | |
| 52 | |
| 53 // VideoCaptureDevice implementation. | |
| 54 void AllocateAndStart(const VideoCaptureParams& params, | |
| 55 std::unique_ptr<Client> client) final; | |
| 56 void StopAndDeAllocate() final; | |
| 57 void TakePhoto(TakePhotoCallback callback) final; | |
| 58 void GetPhotoCapabilities(GetPhotoCapabilitiesCallback callback) final; | |
| 59 void SetPhotoOptions(mojom::PhotoSettingsPtr settings, | |
| 60 SetPhotoOptionsCallback callback) final; | |
| 61 | |
| 62 private: | |
| 63 // Internal methods which AllocateAndStart depends on to create a camera | |
| 64 // device. OnGotCameraInfo and OnOpenDevice are callbacks provided to the | |
| 65 // |camera_hal_delegate_| Mojo IPC calls, and are run on the | |
| 66 // |module_task_runner_| of |camera_hal_delegate_|. | |
| 67 void OnGotCameraInfo(const VideoCaptureParams& params, | |
| 68 std::unique_ptr<Client> client, | |
| 69 int32_t result, | |
| 70 arc::mojom::CameraInfoPtr camera_info); | |
| 71 void OnOpenedDevice(const VideoCaptureParams& params, | |
| 72 std::unique_ptr<Client> client, | |
| 73 arc::mojom::CameraMetadataPtr static_metadata, | |
| 74 int32_t result, | |
| 75 arc::mojom::Camera3DeviceOpsPtr device_ops); | |
| 76 | |
| 77 // CreateDeviceOnCaptureThread creates the CameraDeviceDelegate instance and | |
| 78 // assigns to |camera_device_delegate_|. This method runs on | |
| 79 // |capture_task_runner_| to make sure the access to |camera_device_delegate_| | |
| 80 // and |device_thread_| is sequenced. | |
| 81 void CreateDeviceOnCaptureThread( | |
| 82 const VideoCaptureParams& params, | |
| 83 std::unique_ptr<Client> client, | |
| 84 arc::mojom::CameraMetadataPtr static_metadata, | |
| 85 int32_t result, | |
| 86 mojo::InterfacePtrInfo<arc::mojom::Camera3DeviceOps> device_ops_info); | |
| 87 | |
| 88 const VideoCaptureDeviceDescriptor device_descriptor_; | |
| 89 | |
| 90 // A reference to the CameraHalDelegate instance in the VCD factory. This is | |
| 91 // used by AllocateAndStart to query camera info and create the camera device. | |
| 92 const scoped_refptr<CameraHalDelegate> camera_hal_delegate_; | |
| 93 | |
| 94 // A reference to the thread that all the VideoCaptureDevice interface methods | |
| 95 // are called. | |
| 96 const scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; | |
| 97 | |
| 98 // The thread that all the Mojo operations of |camera_device_delegate_| take | |
| 99 // place. Started in CreateDeviceOnCaptureThread and stopped in | |
| 100 // StopAndDeAllocate, where the access to the base::Thread methods are | |
| 101 // sequenced on |capture_task_runner_|. | |
| 102 base::Thread device_thread_; | |
| 103 | |
| 104 // Variable indicating whether VideoCaptureDevice instance is being stopped. | |
| 105 // We need |stopping_| to ensure correct behavior because AllocateAndStart is | |
| 106 // asynchronous and StopAndDeAllocate may be called between when | |
| 107 // AllocateAndStart is called and when |camera_device_delegate_| is actually | |
| 108 // created. |stopping_| must only be accessed on |capture_task_runner_|. | |
| 109 bool stopping_; | |
| 110 | |
| 111 // Internal delegate doing the actual capture setting, buffer allocation and | |
| 112 // circulation with the camera HAL. Created and deleted in the thread where | |
| 113 // VideoCaptureDeviceArcChromeOS lives, but otherwise operates on | |
| 114 // |device_thread_|. | |
| 115 scoped_refptr<CameraDeviceDelegate> camera_device_delegate_; | |
| 116 | |
| 117 class ScreenObserverDelegate; | |
| 118 | |
| 119 void SetRotation(int rotation); | |
| 120 void SetDisplayRotation(const display::Display& display); | |
| 121 | |
| 122 scoped_refptr<ScreenObserverDelegate> screen_observer_delegate_; | |
| 123 const VideoFacingMode lens_facing_; | |
| 124 const int camera_orientation_; | |
| 125 // Whether the incoming frames should rotate when the device rotates. | |
| 126 const bool rotates_with_device_; | |
| 127 | |
| 128 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceArcChromeOS); | |
| 129 }; | |
| 130 | |
| 131 } // namespace media | |
| 132 | |
| 133 #endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_VIDEO_CAPTURE_DEVICE_CHROMEOS_H_ | |
| OLD | NEW |