Chromium Code Reviews| 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/buildable_video_capture_device.h" | |
| 16 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" | 17 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" |
| 17 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 18 #include "content/common/media/video_capture.h" | 19 #include "content/common/media/video_capture.h" |
| 20 #include "content/public/common/media_stream_request.h" | |
| 19 #include "media/capture/video/video_frame_receiver.h" | 21 #include "media/capture/video/video_frame_receiver.h" |
| 20 #include "media/capture/video_capture_types.h" | 22 #include "media/capture/video_capture_types.h" |
| 21 | 23 |
| 22 namespace content { | 24 namespace content { |
| 23 | 25 |
| 24 // Implementation of media::VideoFrameReceiver that distributes received frames | 26 // Implementation of media::VideoFrameReceiver that distributes received frames |
| 25 // to potentially multiple connected clients. | 27 // to potentially multiple connected clients. |
| 26 class CONTENT_EXPORT VideoCaptureController : public media::VideoFrameReceiver { | 28 // A call to CreateAndStartDeviceAsync() asynchronously brings up the device. If |
| 29 // CreateAndStartDeviceAsync() has beend called, ReleaseDeviceAsync() must be | |
|
emircan
2017/03/16 20:54:03
s/beend/been/
chfremer
2017/03/16 22:02:30
Done.
| |
| 30 // called before releasing the instance. | |
| 31 // Instances must be RefCountedThreadSafe, because an owner | |
| 32 // (VideoCaptureManager) wants to be able to release its reference during an | |
| 33 // (asynchronously executing) run of CreateAndStartDeviceAsync(). To this end, | |
| 34 // the owner passes in the shared ownership as part of |context_reference| into | |
| 35 // CreateAndStartDeviceAsync(). | |
| 36 class CONTENT_EXPORT VideoCaptureController | |
| 37 : public media::VideoFrameReceiver, | |
| 38 public base::RefCountedThreadSafe<VideoCaptureController> { | |
| 27 public: | 39 public: |
| 28 VideoCaptureController(); | 40 VideoCaptureController( |
| 29 ~VideoCaptureController() override; | 41 const std::string& device_id, |
| 42 MediaStreamType stream_type, | |
| 43 const media::VideoCaptureParams& params, | |
| 44 std::unique_ptr<BuildableVideoCaptureDevice> buildable_device); | |
| 30 | 45 |
| 31 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); | 46 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); |
| 32 | 47 |
| 33 // Factory code creating instances of VideoCaptureController may optionally | 48 // Factory code creating instances of VideoCaptureController may optionally |
| 34 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in | 49 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in |
| 35 // this method separate from the constructor to allow clients to create and | 50 // this method separate from the constructor to allow clients to create and |
| 36 // use instances before they can provide the observer. (This is the case with | 51 // use instances before they can provide the observer. (This is the case with |
| 37 // VideoCaptureManager). | 52 // VideoCaptureManager). |
| 38 void SetConsumerFeedbackObserver( | 53 void SetConsumerFeedbackObserver( |
| 39 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> observer); | 54 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> observer); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 std::unique_ptr< | 112 std::unique_ptr< |
| 98 media::VideoCaptureDevice::Client::Buffer::ScopedAccessPermission> | 113 media::VideoCaptureDevice::Client::Buffer::ScopedAccessPermission> |
| 99 buffer_read_permission, | 114 buffer_read_permission, |
| 100 media::mojom::VideoFrameInfoPtr frame_info) override; | 115 media::mojom::VideoFrameInfoPtr frame_info) override; |
| 101 void OnBufferRetired(int buffer_id) override; | 116 void OnBufferRetired(int buffer_id) override; |
| 102 void OnError() override; | 117 void OnError() override; |
| 103 void OnLog(const std::string& message) override; | 118 void OnLog(const std::string& message) override; |
| 104 void OnStarted() override; | 119 void OnStarted() override; |
| 105 void OnStartedUsingGpuDecode() override; | 120 void OnStartedUsingGpuDecode() override; |
| 106 | 121 |
| 122 void CreateAndStartDeviceAsync(const media::VideoCaptureParams& params, | |
| 123 BuildableDeviceCallbacks* callbacks, | |
| 124 std::unique_ptr<Ownership> context_reference); | |
| 125 void ReleaseDeviceAsync(std::unique_ptr<Ownership> context_reference); | |
| 126 bool IsDeviceAlive() const; | |
| 127 bool CorrespondsToController(const VideoCaptureController* controller) const; | |
| 128 void GetPhotoCapabilities( | |
| 129 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) const; | |
| 130 void SetPhotoOptions( | |
| 131 media::mojom::PhotoSettingsPtr settings, | |
| 132 media::VideoCaptureDevice::SetPhotoOptionsCallback callback); | |
| 133 void TakePhoto(media::VideoCaptureDevice::TakePhotoCallback callback); | |
| 134 void MaybeSuspend(); | |
| 135 void Resume(); | |
| 136 void RequestRefreshFrame(); | |
| 137 void SetDesktopCaptureWindowIdAsync( | |
| 138 gfx::NativeViewId window_id, | |
| 139 std::unique_ptr<Ownership> context_reference); | |
| 140 int serial_id() const { return serial_id_; } | |
| 141 const std::string& device_id() const { return device_id_; } | |
| 142 MediaStreamType stream_type() const { return stream_type_; } | |
| 143 const media::VideoCaptureParams& parameters() const { return parameters_; } | |
| 144 | |
| 107 private: | 145 private: |
| 146 friend class base::RefCountedThreadSafe<VideoCaptureController>; | |
| 108 struct ControllerClient; | 147 struct ControllerClient; |
| 109 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; | 148 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; |
| 110 | 149 |
| 111 class BufferContext { | 150 class BufferContext { |
| 112 public: | 151 public: |
| 113 BufferContext( | 152 BufferContext( |
| 114 int buffer_context_id, | 153 int buffer_context_id, |
| 115 int buffer_id, | 154 int buffer_id, |
| 116 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, | 155 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, |
| 117 mojo::ScopedSharedBufferHandle handle); | 156 mojo::ScopedSharedBufferHandle handle); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 146 int frame_feedback_id_; | 185 int frame_feedback_id_; |
| 147 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; | 186 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; |
| 148 mojo::ScopedSharedBufferHandle buffer_handle_; | 187 mojo::ScopedSharedBufferHandle buffer_handle_; |
| 149 double max_consumer_utilization_; | 188 double max_consumer_utilization_; |
| 150 int consumer_hold_count_; | 189 int consumer_hold_count_; |
| 151 std::unique_ptr< | 190 std::unique_ptr< |
| 152 media::VideoCaptureDevice::Client::Buffer::ScopedAccessPermission> | 191 media::VideoCaptureDevice::Client::Buffer::ScopedAccessPermission> |
| 153 buffer_read_permission_; | 192 buffer_read_permission_; |
| 154 }; | 193 }; |
| 155 | 194 |
| 195 ~VideoCaptureController() override; | |
| 196 | |
| 156 // Find a client of |id| and |handler| in |clients|. | 197 // Find a client of |id| and |handler| in |clients|. |
| 157 ControllerClient* FindClient(VideoCaptureControllerID id, | 198 ControllerClient* FindClient(VideoCaptureControllerID id, |
| 158 VideoCaptureControllerEventHandler* handler, | 199 VideoCaptureControllerEventHandler* handler, |
| 159 const ControllerClients& clients); | 200 const ControllerClients& clients); |
| 160 | 201 |
| 161 // Find a client of |session_id| in |clients|. | 202 // Find a client of |session_id| in |clients|. |
| 162 ControllerClient* FindClient(int session_id, | 203 ControllerClient* FindClient(int session_id, |
| 163 const ControllerClients& clients); | 204 const ControllerClients& clients); |
| 164 | 205 |
| 165 std::vector<BufferContext>::iterator FindBufferContextFromBufferContextId( | 206 std::vector<BufferContext>::iterator FindBufferContextFromBufferContextId( |
| 166 int buffer_context_id); | 207 int buffer_context_id); |
| 167 std::vector<BufferContext>::iterator FindUnretiredBufferContextFromBufferId( | 208 std::vector<BufferContext>::iterator FindUnretiredBufferContextFromBufferId( |
| 168 int buffer_id); | 209 int buffer_id); |
| 169 | 210 |
| 170 void OnClientFinishedConsumingBuffer(ControllerClient* client, | 211 void OnClientFinishedConsumingBuffer(ControllerClient* client, |
| 171 int buffer_id, | 212 int buffer_id, |
| 172 double consumer_resource_utilization); | 213 double consumer_resource_utilization); |
| 173 void ReleaseBufferContext( | 214 void ReleaseBufferContext( |
| 174 const std::vector<BufferContext>::iterator& buffer_state_iter); | 215 const std::vector<BufferContext>::iterator& buffer_state_iter); |
| 175 | 216 |
| 176 using EventHandlerAction = | 217 using EventHandlerAction = |
| 177 base::Callback<void(VideoCaptureControllerEventHandler* client, | 218 base::Callback<void(VideoCaptureControllerEventHandler* client, |
| 178 VideoCaptureControllerID id)>; | 219 VideoCaptureControllerID id)>; |
| 179 void PerformForClientsWithOpenSession(EventHandlerAction action); | 220 void PerformForClientsWithOpenSession(EventHandlerAction action); |
| 180 | 221 |
| 222 const int serial_id_; | |
| 223 const std::string device_id_; | |
| 224 const MediaStreamType stream_type_; | |
| 225 const media::VideoCaptureParams parameters_; | |
| 226 std::unique_ptr<BuildableVideoCaptureDevice> buildable_device_; | |
| 227 | |
| 181 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> | 228 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> |
| 182 consumer_feedback_observer_; | 229 consumer_feedback_observer_; |
| 183 | 230 |
| 184 std::vector<BufferContext> buffer_contexts_; | 231 std::vector<BufferContext> buffer_contexts_; |
| 185 | 232 |
| 186 // All clients served by this controller. | 233 // All clients served by this controller. |
| 187 ControllerClients controller_clients_; | 234 ControllerClients controller_clients_; |
| 188 | 235 |
| 189 // Takes on only the states 'STARTING', 'STARTED' and 'ERROR'. 'ERROR' is an | 236 // Takes on only the states 'STARTING', 'STARTED' and 'ERROR'. 'ERROR' is an |
| 190 // absorbing state which stops the flow of data to clients. | 237 // absorbing state which stops the flow of data to clients. |
| 191 VideoCaptureState state_; | 238 VideoCaptureState state_; |
| 192 | 239 |
| 193 int next_buffer_context_id_ = 0; | 240 int next_buffer_context_id_ = 0; |
| 194 | 241 |
| 195 // True if the controller has received a video frame from the device. | 242 // True if the controller has received a video frame from the device. |
| 196 bool has_received_frames_; | 243 bool has_received_frames_; |
| 197 | 244 |
| 198 media::VideoCaptureFormat video_capture_format_; | 245 media::VideoCaptureFormat video_capture_format_; |
| 199 | 246 |
| 200 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; | 247 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; |
| 201 | 248 |
| 202 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); | 249 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); |
| 203 }; | 250 }; |
| 204 | 251 |
| 205 } // namespace content | 252 } // namespace content |
| 206 | 253 |
| 207 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 254 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
| OLD | NEW |