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

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

Issue 2607203002: [Mojo Video Capture] Retire buffers when Android Chromium goes to the background (Closed)
Patch Set: Support reused buffer ids in Controller Created 3 years, 10 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 const media::VideoCaptureFormat& GetVideoCaptureFormat() const; 127 const media::VideoCaptureFormat& GetVideoCaptureFormat() const;
128 128
129 bool has_received_frames() const { return has_received_frames_; } 129 bool has_received_frames() const { return has_received_frames_; }
130 130
131 // Implementation of media::VideoFrameReceiver interface: 131 // Implementation of media::VideoFrameReceiver interface:
132 void OnIncomingCapturedVideoFrame( 132 void OnIncomingCapturedVideoFrame(
133 media::VideoCaptureDevice::Client::Buffer buffer, 133 media::VideoCaptureDevice::Client::Buffer buffer,
134 scoped_refptr<media::VideoFrame> frame) override; 134 scoped_refptr<media::VideoFrame> frame) override;
135 void OnError() override; 135 void OnError() override;
136 void OnLog(const std::string& message) override; 136 void OnLog(const std::string& message) override;
137 void OnBufferDestroyed(int buffer_id_to_drop) override; 137 void OnBufferRetired(int buffer_id) override;
138 138
139 private: 139 private:
140 struct ControllerClient; 140 struct ControllerClient;
141 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; 141 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients;
142 142
143 class BufferState { 143 class BufferContext {
144 public: 144 public:
145 explicit BufferState( 145 explicit BufferContext(
mcasas 2017/02/03 23:24:22 nit: Doesn't need to be explicit since it has > 1
chfremer 2017/02/06 18:16:35 Done.
146 int buffer_context_id,
146 int buffer_id, 147 int buffer_id,
147 int frame_feedback_id,
148 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, 148 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer,
149 media::FrameBufferPool* frame_buffer_pool); 149 media::FrameBufferPool* frame_buffer_pool);
150 ~BufferState(); 150 ~BufferContext();
151 BufferState(const BufferState& other); 151 BufferContext(const BufferContext& other);
152 BufferContext& operator=(const BufferContext& other);
153 int buffer_context_id() const { return buffer_context_id_; }
154 int buffer_id() const { return buffer_id_; }
155 bool is_retired() const { return is_retired_; }
156 void set_is_retired() { is_retired_ = true; }
157 void set_frame_feedback_id(int id) { frame_feedback_id_ = id; }
158 void set_consumer_feedback_observer(
159 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer) {
160 consumer_feedback_observer_ = consumer_feedback_observer;
161 }
162 void set_frame_buffer_pool(media::FrameBufferPool* frame_buffer_pool) {
163 frame_buffer_pool_ = frame_buffer_pool;
164 }
152 void RecordConsumerUtilization(double utilization); 165 void RecordConsumerUtilization(double utilization);
153 void IncreaseConsumerCount(); 166 void IncreaseConsumerCount();
154 void DecreaseConsumerCount(); 167 void DecreaseConsumerCount();
155 bool HasZeroConsumerHoldCount(); 168 bool HasZeroConsumerHoldCount();
156 void SetFrameFeedbackId(int id);
157 void SetConsumerFeedbackObserver(
158 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer);
159 void SetFrameBufferPool(media::FrameBufferPool* frame_buffer_pool);
160 169
161 private: 170 private:
162 const int buffer_id_; 171 int buffer_context_id_;
mcasas 2017/02/03 23:24:22 Can be const
chfremer 2017/02/06 18:16:35 Assignment operator is needed for usage in std::ve
163 int frame_feedback_id_; 172 int buffer_id_;
173 bool is_retired_ = false;
174 int frame_feedback_id_ = 0;
164 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; 175 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_;
165 media::FrameBufferPool* frame_buffer_pool_; 176 media::FrameBufferPool* frame_buffer_pool_;
166 double max_consumer_utilization_; 177 double max_consumer_utilization_;
167 int consumer_hold_count_; 178 int consumer_hold_count_ = 0;
mcasas 2017/02/03 23:24:22 In general try to initialize only once, and by pre
chfremer 2017/02/06 18:16:35 Done.
168 }; 179 };
169 180
170 // Find a client of |id| and |handler| in |clients|. 181 // Find a client of |id| and |handler| in |clients|.
171 ControllerClient* FindClient(VideoCaptureControllerID id, 182 ControllerClient* FindClient(VideoCaptureControllerID id,
172 VideoCaptureControllerEventHandler* handler, 183 VideoCaptureControllerEventHandler* handler,
173 const ControllerClients& clients); 184 const ControllerClients& clients);
174 185
175 // Find a client of |session_id| in |clients|. 186 // Find a client of |session_id| in |clients|.
176 ControllerClient* FindClient(int session_id, 187 ControllerClient* FindClient(int session_id,
177 const ControllerClients& clients); 188 const ControllerClients& clients);
178 189
190 std::vector<BufferContext>::iterator FindBufferContextFromBufferContextId(
191 int buffer_context_id);
192 std::vector<BufferContext>::iterator FindUnretiredBufferContextFromBufferId(
193 int buffer_id);
194
195 void OnClientFinishedConsumingBuffer(ControllerClient* client,
196 int buffer_id,
197 double consumer_resource_utilization);
198 void ReleaseBufferContext(
199 const std::vector<BufferContext>::iterator& buffer_state_iter);
mcasas 2017/02/03 23:24:22 Perhaps we could make a public using BuferContext
chfremer 2017/02/06 18:16:35 To be honest, I am not currently a fan of the "usi
200
179 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_; 201 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_;
180 202
181 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> 203 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver>
182 consumer_feedback_observer_; 204 consumer_feedback_observer_;
183 205
184 std::map<int, BufferState> buffer_id_to_state_map_; 206 std::vector<BufferContext> buffer_contexts_;
185 207
186 // All clients served by this controller. 208 // All clients served by this controller.
187 ControllerClients controller_clients_; 209 ControllerClients controller_clients_;
188 210
189 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing 211 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing
190 // state which stops the flow of data to clients. 212 // state which stops the flow of data to clients.
191 VideoCaptureState state_; 213 VideoCaptureState state_;
192 214
215 int next_buffer_context_id_ = 0;
216
193 // True if the controller has received a video frame from the device. 217 // True if the controller has received a video frame from the device.
194 bool has_received_frames_; 218 bool has_received_frames_;
195 219
196 media::VideoCaptureFormat video_capture_format_; 220 media::VideoCaptureFormat video_capture_format_;
197 221
198 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; 222 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_;
199 223
200 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); 224 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController);
201 }; 225 };
202 226
203 } // namespace content 227 } // namespace content
204 228
205 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ 229 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698