OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/process/process.h" | 15 #include "base/process/process.h" |
16 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 16 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
17 #include "content/browser/renderer_host/media/video_capture_provider.h" | 17 #include "content/browser/renderer_host/media/video_capture_provider.h" |
18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
19 #include "content/common/media/video_capture.h" | 19 #include "content/common/media/video_capture.h" |
20 #include "content/public/common/media_stream_request.h" | 20 #include "content/public/common/media_stream_request.h" |
21 #include "media/capture/video/video_frame_receiver.h" | 21 #include "media/capture/video/video_frame_receiver.h" |
22 #include "media/capture/video_capture_types.h" | 22 #include "media/capture/video_capture_types.h" |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 | 25 |
| 26 class VideoCaptureDeviceLaunchObserver; |
| 27 |
26 // Implementation of media::VideoFrameReceiver that distributes received frames | 28 // Implementation of media::VideoFrameReceiver that distributes received frames |
27 // to potentially multiple connected clients. | 29 // to potentially multiple connected clients. |
28 // A call to CreateAndStartDeviceAsync() asynchronously brings up the device. If | 30 // A call to CreateAndStartDeviceAsync() asynchronously brings up the device. If |
29 // CreateAndStartDeviceAsync() has been called, ReleaseDeviceAsync() must be | 31 // CreateAndStartDeviceAsync() has been called, ReleaseDeviceAsync() must be |
30 // called before releasing the instance. | 32 // called before releasing the instance. |
31 // Instances must be RefCountedThreadSafe, because an owner | 33 // Instances must be RefCountedThreadSafe, because an owner |
32 // (VideoCaptureManager) wants to be able to release its reference during an | 34 // (VideoCaptureManager) wants to be able to release its reference during an |
33 // (asynchronously executing) run of CreateAndStartDeviceAsync(). To this end, | 35 // (asynchronously executing) run of CreateAndStartDeviceAsync(). To this end, |
34 // the owner passes in the shared ownership as part of |context_reference| into | 36 // the owner passes in the shared ownership as part of |done_cb| into |
35 // CreateAndStartDeviceAsync(). | 37 // CreateAndStartDeviceAsync(). |
36 class CONTENT_EXPORT VideoCaptureController | 38 class CONTENT_EXPORT VideoCaptureController |
37 : public media::VideoFrameReceiver, | 39 : public media::VideoFrameReceiver, |
| 40 public VideoCaptureDeviceLauncher::Callbacks, |
38 public base::RefCountedThreadSafe<VideoCaptureController> { | 41 public base::RefCountedThreadSafe<VideoCaptureController> { |
39 public: | 42 public: |
40 VideoCaptureController( | 43 VideoCaptureController( |
41 const std::string& device_id, | 44 const std::string& device_id, |
42 MediaStreamType stream_type, | 45 MediaStreamType stream_type, |
43 const media::VideoCaptureParams& params, | 46 const media::VideoCaptureParams& params, |
44 std::unique_ptr<BuildableVideoCaptureDevice> buildable_device); | 47 std::unique_ptr<VideoCaptureDeviceLauncher> device_launcher); |
45 | 48 |
46 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); | 49 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); |
47 | 50 |
48 // Factory code creating instances of VideoCaptureController may optionally | |
49 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in | |
50 // this method separate from the constructor to allow clients to create and | |
51 // use instances before they can provide the observer. (This is the case with | |
52 // VideoCaptureManager). | |
53 void SetConsumerFeedbackObserver( | |
54 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> observer); | |
55 | |
56 // Start video capturing and try to use the resolution specified in |params|. | 51 // Start video capturing and try to use the resolution specified in |params|. |
57 // Buffers will be shared to the client as necessary. The client will continue | 52 // Buffers will be shared to the client as necessary. The client will continue |
58 // to receive frames from the device until RemoveClient() is called. | 53 // to receive frames from the device until RemoveClient() is called. |
59 void AddClient(VideoCaptureControllerID id, | 54 void AddClient(VideoCaptureControllerID id, |
60 VideoCaptureControllerEventHandler* event_handler, | 55 VideoCaptureControllerEventHandler* event_handler, |
61 media::VideoCaptureSessionId session_id, | 56 media::VideoCaptureSessionId session_id, |
62 const media::VideoCaptureParams& params); | 57 const media::VideoCaptureParams& params); |
63 | 58 |
64 // Stop video capture. This will take back all buffers held by by | 59 // Stop video capture. This will take back all buffers held by by |
65 // |event_handler|, and |event_handler| shouldn't use those buffers any more. | 60 // |event_handler|, and |event_handler| shouldn't use those buffers any more. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 std::unique_ptr< | 107 std::unique_ptr< |
113 media::VideoCaptureDevice::Client::Buffer::ScopedAccessPermission> | 108 media::VideoCaptureDevice::Client::Buffer::ScopedAccessPermission> |
114 buffer_read_permission, | 109 buffer_read_permission, |
115 media::mojom::VideoFrameInfoPtr frame_info) override; | 110 media::mojom::VideoFrameInfoPtr frame_info) override; |
116 void OnBufferRetired(int buffer_id) override; | 111 void OnBufferRetired(int buffer_id) override; |
117 void OnError() override; | 112 void OnError() override; |
118 void OnLog(const std::string& message) override; | 113 void OnLog(const std::string& message) override; |
119 void OnStarted() override; | 114 void OnStarted() override; |
120 void OnStartedUsingGpuDecode() override; | 115 void OnStartedUsingGpuDecode() override; |
121 | 116 |
122 void CreateAndStartDeviceAsync( | 117 // Implementation of VideoCaptureDeviceLauncher::Callbacks interface: |
123 const media::VideoCaptureParams& params, | 118 void OnDeviceLaunched( |
124 BuildableVideoCaptureDevice::Callbacks* callbacks, | 119 std::unique_ptr<LaunchedVideoCaptureDevice> device) override; |
125 base::OnceClosure done_cb); | 120 void OnDeviceLaunchFailed() override; |
| 121 void OnDeviceLaunchAborted() override; |
| 122 |
| 123 void CreateAndStartDeviceAsync(const media::VideoCaptureParams& params, |
| 124 VideoCaptureDeviceLaunchObserver* callbacks, |
| 125 base::OnceClosure done_cb); |
126 void ReleaseDeviceAsync(base::OnceClosure done_cb); | 126 void ReleaseDeviceAsync(base::OnceClosure done_cb); |
127 bool IsDeviceAlive() const; | 127 bool IsDeviceAlive() const; |
128 void GetPhotoCapabilities( | 128 void GetPhotoCapabilities( |
129 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) const; | 129 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) const; |
130 void SetPhotoOptions( | 130 void SetPhotoOptions( |
131 media::mojom::PhotoSettingsPtr settings, | 131 media::mojom::PhotoSettingsPtr settings, |
132 media::VideoCaptureDevice::SetPhotoOptionsCallback callback); | 132 media::VideoCaptureDevice::SetPhotoOptionsCallback callback); |
133 void TakePhoto(media::VideoCaptureDevice::TakePhotoCallback callback); | 133 void TakePhoto(media::VideoCaptureDevice::TakePhotoCallback callback); |
134 void MaybeSuspend(); | 134 void MaybeSuspend(); |
135 void Resume(); | 135 void Resume(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 215 |
216 using EventHandlerAction = | 216 using EventHandlerAction = |
217 base::Callback<void(VideoCaptureControllerEventHandler* client, | 217 base::Callback<void(VideoCaptureControllerEventHandler* client, |
218 VideoCaptureControllerID id)>; | 218 VideoCaptureControllerID id)>; |
219 void PerformForClientsWithOpenSession(EventHandlerAction action); | 219 void PerformForClientsWithOpenSession(EventHandlerAction action); |
220 | 220 |
221 const int serial_id_; | 221 const int serial_id_; |
222 const std::string device_id_; | 222 const std::string device_id_; |
223 const MediaStreamType stream_type_; | 223 const MediaStreamType stream_type_; |
224 const media::VideoCaptureParams parameters_; | 224 const media::VideoCaptureParams parameters_; |
225 std::unique_ptr<BuildableVideoCaptureDevice> buildable_device_; | 225 std::unique_ptr<VideoCaptureDeviceLauncher> device_launcher_; |
226 | 226 std::unique_ptr<LaunchedVideoCaptureDevice> launched_device_; |
227 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> | 227 VideoCaptureDeviceLaunchObserver* device_launch_observer_; |
228 consumer_feedback_observer_; | |
229 | 228 |
230 std::vector<BufferContext> buffer_contexts_; | 229 std::vector<BufferContext> buffer_contexts_; |
231 | 230 |
232 // All clients served by this controller. | 231 // All clients served by this controller. |
233 ControllerClients controller_clients_; | 232 ControllerClients controller_clients_; |
234 | 233 |
235 // Takes on only the states 'STARTING', 'STARTED' and 'ERROR'. 'ERROR' is an | 234 // Takes on only the states 'STARTING', 'STARTED' and 'ERROR'. 'ERROR' is an |
236 // absorbing state which stops the flow of data to clients. | 235 // absorbing state which stops the flow of data to clients. |
237 VideoCaptureState state_; | 236 VideoCaptureState state_; |
238 | 237 |
239 int next_buffer_context_id_ = 0; | 238 int next_buffer_context_id_ = 0; |
240 | 239 |
241 // True if the controller has received a video frame from the device. | 240 // True if the controller has received a video frame from the device. |
242 bool has_received_frames_; | 241 bool has_received_frames_; |
243 | 242 |
244 base::Optional<media::VideoCaptureFormat> video_capture_format_; | 243 base::Optional<media::VideoCaptureFormat> video_capture_format_; |
245 | 244 |
246 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; | 245 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; |
247 | 246 |
248 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); | 247 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); |
249 }; | 248 }; |
250 | 249 |
251 } // namespace content | 250 } // namespace content |
252 | 251 |
253 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 252 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
OLD | NEW |