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

Side by Side Diff: content/browser/renderer_host/media/video_capture_controller.h

Issue 2738763002: [Mojo Video Capture] Introduce abstraction BuildableVideoCaptureDevice (Closed)
Patch Set: Use BuildableDeviceCallbacks* plus OnceClosure instead of DeviceBuildContext Created 3 years, 9 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 unified diff | Download patch
OLDNEW
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 been called, ReleaseDeviceAsync() must be
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
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 base::OnceClosure done_cb);
125 void ReleaseDeviceAsync(base::OnceClosure done_cb);
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(gfx::NativeViewId window_id,
138 base::OnceClosure done_cb);
139 int serial_id() const { return serial_id_; }
140 const std::string& device_id() const { return device_id_; }
141 MediaStreamType stream_type() const { return stream_type_; }
142 const media::VideoCaptureParams& parameters() const { return parameters_; }
mcasas 2017/03/22 00:33:42 Heh two things: this class is starting to have way
chfremer 2017/03/22 17:26:52 I agree with both observations. However, I would a
143
107 private: 144 private:
145 friend class base::RefCountedThreadSafe<VideoCaptureController>;
108 struct ControllerClient; 146 struct ControllerClient;
109 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; 147 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients;
110 148
111 class BufferContext { 149 class BufferContext {
112 public: 150 public:
113 BufferContext( 151 BufferContext(
114 int buffer_context_id, 152 int buffer_context_id,
115 int buffer_id, 153 int buffer_id,
116 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, 154 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer,
117 mojo::ScopedSharedBufferHandle handle); 155 mojo::ScopedSharedBufferHandle handle);
(...skipping 28 matching lines...) Expand all
146 int frame_feedback_id_; 184 int frame_feedback_id_;
147 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; 185 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_;
148 mojo::ScopedSharedBufferHandle buffer_handle_; 186 mojo::ScopedSharedBufferHandle buffer_handle_;
149 double max_consumer_utilization_; 187 double max_consumer_utilization_;
150 int consumer_hold_count_; 188 int consumer_hold_count_;
151 std::unique_ptr< 189 std::unique_ptr<
152 media::VideoCaptureDevice::Client::Buffer::ScopedAccessPermission> 190 media::VideoCaptureDevice::Client::Buffer::ScopedAccessPermission>
153 buffer_read_permission_; 191 buffer_read_permission_;
154 }; 192 };
155 193
194 ~VideoCaptureController() override;
195
156 // Find a client of |id| and |handler| in |clients|. 196 // Find a client of |id| and |handler| in |clients|.
157 ControllerClient* FindClient(VideoCaptureControllerID id, 197 ControllerClient* FindClient(VideoCaptureControllerID id,
158 VideoCaptureControllerEventHandler* handler, 198 VideoCaptureControllerEventHandler* handler,
159 const ControllerClients& clients); 199 const ControllerClients& clients);
160 200
161 // Find a client of |session_id| in |clients|. 201 // Find a client of |session_id| in |clients|.
162 ControllerClient* FindClient(int session_id, 202 ControllerClient* FindClient(int session_id,
163 const ControllerClients& clients); 203 const ControllerClients& clients);
164 204
165 std::vector<BufferContext>::iterator FindBufferContextFromBufferContextId( 205 std::vector<BufferContext>::iterator FindBufferContextFromBufferContextId(
166 int buffer_context_id); 206 int buffer_context_id);
167 std::vector<BufferContext>::iterator FindUnretiredBufferContextFromBufferId( 207 std::vector<BufferContext>::iterator FindUnretiredBufferContextFromBufferId(
168 int buffer_id); 208 int buffer_id);
169 209
170 void OnClientFinishedConsumingBuffer(ControllerClient* client, 210 void OnClientFinishedConsumingBuffer(ControllerClient* client,
171 int buffer_id, 211 int buffer_id,
172 double consumer_resource_utilization); 212 double consumer_resource_utilization);
173 void ReleaseBufferContext( 213 void ReleaseBufferContext(
174 const std::vector<BufferContext>::iterator& buffer_state_iter); 214 const std::vector<BufferContext>::iterator& buffer_state_iter);
175 215
176 using EventHandlerAction = 216 using EventHandlerAction =
177 base::Callback<void(VideoCaptureControllerEventHandler* client, 217 base::Callback<void(VideoCaptureControllerEventHandler* client,
178 VideoCaptureControllerID id)>; 218 VideoCaptureControllerID id)>;
179 void PerformForClientsWithOpenSession(EventHandlerAction action); 219 void PerformForClientsWithOpenSession(EventHandlerAction action);
180 220
221 const int serial_id_;
222 const std::string device_id_;
223 const MediaStreamType stream_type_;
224 const media::VideoCaptureParams parameters_;
225 std::unique_ptr<BuildableVideoCaptureDevice> buildable_device_;
226
181 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> 227 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver>
182 consumer_feedback_observer_; 228 consumer_feedback_observer_;
183 229
184 std::vector<BufferContext> buffer_contexts_; 230 std::vector<BufferContext> buffer_contexts_;
185 231
186 // All clients served by this controller. 232 // All clients served by this controller.
187 ControllerClients controller_clients_; 233 ControllerClients controller_clients_;
188 234
189 // Takes on only the states 'STARTING', 'STARTED' and 'ERROR'. 'ERROR' is an 235 // Takes on only the states 'STARTING', 'STARTED' and 'ERROR'. 'ERROR' is an
190 // absorbing state which stops the flow of data to clients. 236 // absorbing state which stops the flow of data to clients.
191 VideoCaptureState state_; 237 VideoCaptureState state_;
192 238
193 int next_buffer_context_id_ = 0; 239 int next_buffer_context_id_ = 0;
194 240
195 // True if the controller has received a video frame from the device. 241 // True if the controller has received a video frame from the device.
196 bool has_received_frames_; 242 bool has_received_frames_;
197 243
198 media::VideoCaptureFormat video_capture_format_; 244 media::VideoCaptureFormat video_capture_format_;
199 245
200 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; 246 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_;
201 247
202 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); 248 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController);
203 }; 249 };
204 250
205 } // namespace content 251 } // namespace content
206 252
207 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ 253 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698