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

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

Issue 2597833002: Reland [Mojo Video Capture] Decouple VCController from VCBufferPool and VCDeviceClient (Closed)
Patch Set: Rebase Created 3 years, 11 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 // VideoCaptureController is the glue between a VideoCaptureDevice and all 5 // VideoCaptureController is the glue between a VideoCaptureDevice and all
6 // VideoCaptureHosts that have connected to it. A controller exists on behalf of 6 // VideoCaptureHosts that have connected to it. A controller exists on behalf of
7 // one (and only one) VideoCaptureDevice; both are owned by the 7 // one (and only one) VideoCaptureDevice; both are owned by the
8 // VideoCaptureManager. 8 // VideoCaptureManager.
9 // 9 //
10 // The VideoCaptureController is responsible for: 10 // The VideoCaptureController is responsible for:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "base/memory/ref_counted.h" 48 #include "base/memory/ref_counted.h"
49 #include "base/memory/weak_ptr.h" 49 #include "base/memory/weak_ptr.h"
50 #include "base/process/process.h" 50 #include "base/process/process.h"
51 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" 51 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
52 #include "content/common/content_export.h" 52 #include "content/common/content_export.h"
53 #include "content/common/media/video_capture.h" 53 #include "content/common/media/video_capture.h"
54 #include "media/capture/video/video_frame_receiver.h" 54 #include "media/capture/video/video_frame_receiver.h"
55 #include "media/capture/video_capture_types.h" 55 #include "media/capture/video_capture_types.h"
56 56
57 namespace media { 57 namespace media {
58 class VideoCaptureBufferPool; 58 class FrameBufferPool;
59 } 59 }
60 60
61 namespace content { 61 namespace content {
62 62
63 class CONTENT_EXPORT VideoCaptureController : public media::VideoFrameReceiver { 63 class CONTENT_EXPORT VideoCaptureController : public media::VideoFrameReceiver {
64 public: 64 public:
65 // |max_buffers| is the maximum number of video frame buffers in-flight at any 65 VideoCaptureController();
66 // one time. This value should be based on the logical capacity of the
67 // capture pipeline, and not on hardware performance. For example, tab
68 // capture requires more buffers than webcam capture because the pipeline is
69 // longer (it includes read-backs pending in the GPU pipeline).
70 explicit VideoCaptureController(int max_buffers);
71 ~VideoCaptureController() override; 66 ~VideoCaptureController() override;
72 67
73 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); 68 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread();
74 69
70 // Factory code creating instances of VideoCaptureController must set a
71 // FrameBufferPool before any of the media::VideoFrameReceiver are used.
72 // Setting the observer is done in this method separate from the constructor
73 // in order to allow use the media::VideoFrameReceiver methods
74 // before the observer can be provided. (This is the case with
75 // VideoCaptureManager).
76 void SetFrameBufferPool(
77 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool);
78
75 // Factory code creating instances of VideoCaptureController may optionally 79 // Factory code creating instances of VideoCaptureController may optionally
76 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in 80 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in
77 // this method separate from the constructor to allow clients to create and 81 // this method separate from the constructor to allow clients to create and
78 // use instances before they can provide the observer. (This is the case with 82 // use instances before they can provide the observer. (This is the case with
79 // VideoCaptureManager). 83 // VideoCaptureManager).
80 void SetConsumerFeedbackObserver( 84 void SetConsumerFeedbackObserver(
81 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> observer); 85 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> observer);
82 86
83 // Return a new VideoCaptureDeviceClient to forward capture events to this
84 // instance.
85 std::unique_ptr<media::VideoCaptureDevice::Client> NewDeviceClient();
86
87 // Start video capturing and try to use the resolution specified in |params|. 87 // Start video capturing and try to use the resolution specified in |params|.
88 // Buffers will be shared to the client as necessary. The client will continue 88 // Buffers will be shared to the client as necessary. The client will continue
89 // to receive frames from the device until RemoveClient() is called. 89 // to receive frames from the device until RemoveClient() is called.
90 void AddClient(VideoCaptureControllerID id, 90 void AddClient(VideoCaptureControllerID id,
91 VideoCaptureControllerEventHandler* event_handler, 91 VideoCaptureControllerEventHandler* event_handler,
92 media::VideoCaptureSessionId session_id, 92 media::VideoCaptureSessionId session_id,
93 const media::VideoCaptureParams& params); 93 const media::VideoCaptureParams& params);
94 94
95 // Stop video capture. This will take back all buffers held by by 95 // Stop video capture. This will take back all buffers held by by
96 // |event_handler|, and |event_handler| shouldn't use those buffers any more. 96 // |event_handler|, and |event_handler| shouldn't use those buffers any more.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 private: 143 private:
144 struct ControllerClient; 144 struct ControllerClient;
145 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; 145 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients;
146 146
147 class BufferState { 147 class BufferState {
148 public: 148 public:
149 explicit BufferState( 149 explicit BufferState(
150 int buffer_id, 150 int buffer_id,
151 int frame_feedback_id, 151 int frame_feedback_id,
152 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, 152 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer,
153 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool, 153 media::FrameBufferPool* frame_buffer_pool,
154 scoped_refptr<media::VideoFrame> frame); 154 scoped_refptr<media::VideoFrame> frame);
155 ~BufferState(); 155 ~BufferState();
156 BufferState(const BufferState& other); 156 BufferState(const BufferState& other);
157 void RecordConsumerUtilization(double utilization); 157 void RecordConsumerUtilization(double utilization);
158 void IncreaseConsumerCount(); 158 void IncreaseConsumerCount();
159 void DecreaseConsumerCount(); 159 void DecreaseConsumerCount();
160 bool HasZeroConsumerHoldCount(); 160 bool HasZeroConsumerHoldCount();
161 void SetConsumerFeedbackObserver( 161 void SetConsumerFeedbackObserver(
162 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer); 162 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer);
163 void SetFrameBufferPool(media::FrameBufferPool* frame_buffer_pool);
163 164
164 private: 165 private:
165 const int buffer_id_; 166 const int buffer_id_;
166 const int frame_feedback_id_; 167 const int frame_feedback_id_;
167 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; 168 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_;
168 const scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; 169 media::FrameBufferPool* frame_buffer_pool_;
169 const scoped_refptr<media::VideoFrame> frame_; 170 const scoped_refptr<media::VideoFrame> frame_;
170 double max_consumer_utilization_; 171 double max_consumer_utilization_;
171 int consumer_hold_count_; 172 int consumer_hold_count_;
172 }; 173 };
173 174
174 // Notify renderer that a new buffer has been created. 175 // Notify renderer that a new buffer has been created.
175 void DoNewBufferOnIOThread(ControllerClient* client, 176 void DoNewBufferOnIOThread(ControllerClient* client,
176 media::VideoCaptureDevice::Client::Buffer* buffer, 177 media::VideoCaptureDevice::Client::Buffer* buffer,
177 const scoped_refptr<media::VideoFrame>& frame); 178 const scoped_refptr<media::VideoFrame>& frame);
178 179
179 // Find a client of |id| and |handler| in |clients|. 180 // Find a client of |id| and |handler| in |clients|.
180 ControllerClient* FindClient(VideoCaptureControllerID id, 181 ControllerClient* FindClient(VideoCaptureControllerID id,
181 VideoCaptureControllerEventHandler* handler, 182 VideoCaptureControllerEventHandler* handler,
182 const ControllerClients& clients); 183 const ControllerClients& clients);
183 184
184 // Find a client of |session_id| in |clients|. 185 // Find a client of |session_id| in |clients|.
185 ControllerClient* FindClient(int session_id, 186 ControllerClient* FindClient(int session_id,
186 const ControllerClients& clients); 187 const ControllerClients& clients);
187 188
188 // The pool of shared-memory buffers used for capturing. 189 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_;
189 const scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_;
190 190
191 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> 191 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver>
192 consumer_feedback_observer_; 192 consumer_feedback_observer_;
193 193
194 std::map<int, BufferState> buffer_id_to_state_map_; 194 std::map<int, BufferState> buffer_id_to_state_map_;
195 195
196 // All clients served by this controller. 196 // All clients served by this controller.
197 ControllerClients controller_clients_; 197 ControllerClients controller_clients_;
198 198
199 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing 199 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing
200 // state which stops the flow of data to clients. 200 // state which stops the flow of data to clients.
201 VideoCaptureState state_; 201 VideoCaptureState state_;
202 202
203 // True if the controller has received a video frame from the device. 203 // True if the controller has received a video frame from the device.
204 bool has_received_frames_; 204 bool has_received_frames_;
205 205
206 media::VideoCaptureFormat video_capture_format_; 206 media::VideoCaptureFormat video_capture_format_;
207 207
208 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; 208 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_;
209 209
210 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); 210 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController);
211 }; 211 };
212 212
213 } // namespace content 213 } // namespace content
214 214
215 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ 215 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/OWNERS ('k') | content/browser/renderer_host/media/video_capture_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698