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 // 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 Loading... |
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 BufferState { |
144 public: | 144 public: |
145 explicit BufferState( | 145 explicit BufferState( |
146 int buffer_id, | 146 int buffer_id, |
147 int frame_feedback_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 ~BufferState(); |
151 BufferState(const BufferState& other); | 151 BufferState(const BufferState& other); |
| 152 BufferState& operator=(const BufferState& other); |
| 153 int buffer_id() const { return buffer_id_; } |
| 154 bool is_retired() const { return is_retired_; } |
| 155 void set_is_retired() { is_retired_ = true; } |
152 void RecordConsumerUtilization(double utilization); | 156 void RecordConsumerUtilization(double utilization); |
153 void IncreaseConsumerCount(); | 157 void IncreaseConsumerCount(); |
154 void DecreaseConsumerCount(); | 158 void DecreaseConsumerCount(); |
155 bool HasZeroConsumerHoldCount(); | 159 bool HasZeroConsumerHoldCount(); |
156 void SetConsumerFeedbackObserver( | 160 void SetConsumerFeedbackObserver( |
157 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer); | 161 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer); |
158 void SetFrameBufferPool(media::FrameBufferPool* frame_buffer_pool); | 162 void SetFrameBufferPool(media::FrameBufferPool* frame_buffer_pool); |
159 | 163 |
160 private: | 164 private: |
161 const int buffer_id_; | 165 int buffer_id_; |
162 const int frame_feedback_id_; | 166 bool is_retired_ = false; |
| 167 int frame_feedback_id_; |
163 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; | 168 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; |
164 media::FrameBufferPool* frame_buffer_pool_; | 169 media::FrameBufferPool* frame_buffer_pool_; |
165 double max_consumer_utilization_; | 170 double max_consumer_utilization_; |
166 int consumer_hold_count_; | 171 int consumer_hold_count_; |
167 }; | 172 }; |
168 | 173 |
169 // Find a client of |id| and |handler| in |clients|. | 174 // Find a client of |id| and |handler| in |clients|. |
170 ControllerClient* FindClient(VideoCaptureControllerID id, | 175 ControllerClient* FindClient(VideoCaptureControllerID id, |
171 VideoCaptureControllerEventHandler* handler, | 176 VideoCaptureControllerEventHandler* handler, |
172 const ControllerClients& clients); | 177 const ControllerClients& clients); |
173 | 178 |
174 // Find a client of |session_id| in |clients|. | 179 // Find a client of |session_id| in |clients|. |
175 ControllerClient* FindClient(int session_id, | 180 ControllerClient* FindClient(int session_id, |
176 const ControllerClients& clients); | 181 const ControllerClients& clients); |
177 | 182 |
| 183 void OnClientFinishedConsumingBuffer(ControllerClient* client, |
| 184 int buffer_id, |
| 185 double consumer_resource_utilization); |
| 186 void ReleaseBufferState( |
| 187 const std::vector<BufferState>::iterator& buffer_state_iter); |
| 188 |
178 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_; | 189 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_; |
179 | 190 |
180 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> | 191 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> |
181 consumer_feedback_observer_; | 192 consumer_feedback_observer_; |
182 | 193 |
183 std::map<int, BufferState> buffer_id_to_state_map_; | 194 std::vector<BufferState> buffer_states_; |
184 | 195 |
185 // All clients served by this controller. | 196 // All clients served by this controller. |
186 ControllerClients controller_clients_; | 197 ControllerClients controller_clients_; |
187 | 198 |
188 // 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 |
189 // state which stops the flow of data to clients. | 200 // state which stops the flow of data to clients. |
190 VideoCaptureState state_; | 201 VideoCaptureState state_; |
191 | 202 |
192 // 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. |
193 bool has_received_frames_; | 204 bool has_received_frames_; |
194 | 205 |
195 media::VideoCaptureFormat video_capture_format_; | 206 media::VideoCaptureFormat video_capture_format_; |
196 | 207 |
197 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; | 208 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; |
198 | 209 |
199 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); | 210 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); |
200 }; | 211 }; |
201 | 212 |
202 } // namespace content | 213 } // namespace content |
203 | 214 |
204 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 215 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
OLD | NEW |