| 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 std::vector<BufferState>::iterator FindBufferState(int buffer_id); |
| 184 |
| 185 void OnClientFinishedConsumingBuffer(ControllerClient* client, |
| 186 int buffer_id, |
| 187 double consumer_resource_utilization); |
| 188 void ReleaseBufferState( |
| 189 const std::vector<BufferState>::iterator& buffer_state_iter); |
| 190 |
| 178 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_; | 191 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_; |
| 179 | 192 |
| 180 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> | 193 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> |
| 181 consumer_feedback_observer_; | 194 consumer_feedback_observer_; |
| 182 | 195 |
| 183 std::map<int, BufferState> buffer_id_to_state_map_; | 196 std::vector<BufferState> buffer_states_; |
| 184 | 197 |
| 185 // All clients served by this controller. | 198 // All clients served by this controller. |
| 186 ControllerClients controller_clients_; | 199 ControllerClients controller_clients_; |
| 187 | 200 |
| 188 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing | 201 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing |
| 189 // state which stops the flow of data to clients. | 202 // state which stops the flow of data to clients. |
| 190 VideoCaptureState state_; | 203 VideoCaptureState state_; |
| 191 | 204 |
| 192 // True if the controller has received a video frame from the device. | 205 // True if the controller has received a video frame from the device. |
| 193 bool has_received_frames_; | 206 bool has_received_frames_; |
| 194 | 207 |
| 195 media::VideoCaptureFormat video_capture_format_; | 208 media::VideoCaptureFormat video_capture_format_; |
| 196 | 209 |
| 197 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; | 210 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; |
| 198 | 211 |
| 199 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); | 212 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); |
| 200 }; | 213 }; |
| 201 | 214 |
| 202 } // namespace content | 215 } // namespace content |
| 203 | 216 |
| 204 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 217 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
| OLD | NEW |