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

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

Issue 2518143004: [Mojo Video Capture] Replace RESOURCE_UTILIZATION with interface ReceiverLoadObserver (Closed)
Patch Set: Fix for android-only code Created 4 years 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // |max_buffers| is the maximum number of video frame buffers in-flight at any 65 // |max_buffers| is the maximum number of video frame buffers in-flight at any
66 // one time. This value should be based on the logical capacity of the 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 67 // capture pipeline, and not on hardware performance. For example, tab
68 // capture requires more buffers than webcam capture because the pipeline is 68 // capture requires more buffers than webcam capture because the pipeline is
69 // longer (it includes read-backs pending in the GPU pipeline). 69 // longer (it includes read-backs pending in the GPU pipeline).
70 explicit VideoCaptureController(int max_buffers); 70 explicit VideoCaptureController(int max_buffers);
71 ~VideoCaptureController() override; 71 ~VideoCaptureController() override;
72 72
73 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); 73 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread();
74 74
75 // Factory code creating instances of VideoCaptureController may optionally
76 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in
77 // 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
79 // VideoCaptureManager).
80 void SetConsumerFeedbackObserver(
81 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> observer);
82
75 // Return a new VideoCaptureDeviceClient to forward capture events to this 83 // Return a new VideoCaptureDeviceClient to forward capture events to this
76 // instance. 84 // instance.
77 std::unique_ptr<media::VideoCaptureDevice::Client> NewDeviceClient(); 85 std::unique_ptr<media::VideoCaptureDevice::Client> NewDeviceClient();
78 86
79 // 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|.
80 // 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
81 // to receive frames from the device until RemoveClient() is called. 89 // to receive frames from the device until RemoveClient() is called.
82 void AddClient(VideoCaptureControllerID id, 90 void AddClient(VideoCaptureControllerID id,
83 VideoCaptureControllerEventHandler* event_handler, 91 VideoCaptureControllerEventHandler* event_handler,
84 media::VideoCaptureSessionId session_id, 92 media::VideoCaptureSessionId session_id,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, 140 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer,
133 scoped_refptr<media::VideoFrame> frame) override; 141 scoped_refptr<media::VideoFrame> frame) override;
134 void OnError() override; 142 void OnError() override;
135 void OnLog(const std::string& message) override; 143 void OnLog(const std::string& message) override;
136 void OnBufferDestroyed(int buffer_id_to_drop) override; 144 void OnBufferDestroyed(int buffer_id_to_drop) override;
137 145
138 private: 146 private:
139 struct ControllerClient; 147 struct ControllerClient;
140 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; 148 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients;
141 149
150 class BufferState {
151 public:
152 explicit BufferState(
153 int buffer_id,
154 int frame_feedback_id,
155 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer,
156 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool,
157 scoped_refptr<media::VideoFrame> frame);
158 ~BufferState();
159 BufferState(const BufferState& other);
160 void RecordConsumerUtilization(double utilization);
161 void IncreaseConsumerCount();
162 void DecreaseConsumerCount();
163 bool HasZeroConsumerHoldCount();
164 void SetConsumerFeedbackObserver(
165 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer);
166
167 private:
168 const int buffer_id_;
169 const int frame_feedback_id_;
170 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_;
171 const scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_;
172 const scoped_refptr<media::VideoFrame> frame_;
173 double max_consumer_utilization_;
174 int consumer_hold_count_;
175 };
176
142 // Notify renderer that a new buffer has been created. 177 // Notify renderer that a new buffer has been created.
143 void DoNewBufferOnIOThread(ControllerClient* client, 178 void DoNewBufferOnIOThread(ControllerClient* client,
144 media::VideoCaptureDevice::Client::Buffer* buffer, 179 media::VideoCaptureDevice::Client::Buffer* buffer,
145 const scoped_refptr<media::VideoFrame>& frame); 180 const scoped_refptr<media::VideoFrame>& frame);
146 181
147 // Find a client of |id| and |handler| in |clients|. 182 // Find a client of |id| and |handler| in |clients|.
148 ControllerClient* FindClient(VideoCaptureControllerID id, 183 ControllerClient* FindClient(VideoCaptureControllerID id,
149 VideoCaptureControllerEventHandler* handler, 184 VideoCaptureControllerEventHandler* handler,
150 const ControllerClients& clients); 185 const ControllerClients& clients);
151 186
152 // Find a client of |session_id| in |clients|. 187 // Find a client of |session_id| in |clients|.
153 ControllerClient* FindClient(int session_id, 188 ControllerClient* FindClient(int session_id,
154 const ControllerClients& clients); 189 const ControllerClients& clients);
155 190
156 // The pool of shared-memory buffers used for capturing. 191 // The pool of shared-memory buffers used for capturing.
157 const scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; 192 const scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_;
158 193
194 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver>
195 consumer_feedback_observer_;
196
197 std::map<int, BufferState> buffer_id_to_state_map_;
198
159 // All clients served by this controller. 199 // All clients served by this controller.
160 ControllerClients controller_clients_; 200 ControllerClients controller_clients_;
161 201
162 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing 202 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing
163 // state which stops the flow of data to clients. 203 // state which stops the flow of data to clients.
164 VideoCaptureState state_; 204 VideoCaptureState state_;
165 205
166 // True if the controller has received a video frame from the device. 206 // True if the controller has received a video frame from the device.
167 bool has_received_frames_; 207 bool has_received_frames_;
168 208
169 media::VideoCaptureFormat video_capture_format_; 209 media::VideoCaptureFormat video_capture_format_;
170 210
171 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; 211 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_;
172 212
173 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); 213 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController);
174 }; 214 };
175 215
176 } // namespace content 216 } // namespace content
177 217
178 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ 218 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698