| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 VideoCaptureController(); | 65 VideoCaptureController(); |
| 66 ~VideoCaptureController() override; | 66 ~VideoCaptureController() override; |
| 67 | 67 |
| 68 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); | 68 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); |
| 69 | 69 |
| 70 // A FrameBufferPool must to be set in order for video frames to be | 70 // A FrameBufferPool may optionally be set in order to receive notifications |
| 71 // processed. While no FrameBufferPool is set, incoming video frames are | 71 // when a frame is starting to get consumed and has finished getting consumed. |
| 72 // ignored. It is legal to reset a previously set FrameBufferPool by calling | |
| 73 // this method with a nullptr. | |
| 74 void SetFrameBufferPool( | 72 void SetFrameBufferPool( |
| 75 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool); | 73 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool); |
| 76 | 74 |
| 77 // Factory code creating instances of VideoCaptureController may optionally | 75 // Factory code creating instances of VideoCaptureController may optionally |
| 78 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in | 76 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in |
| 79 // this method separate from the constructor to allow clients to create and | 77 // this method separate from the constructor to allow clients to create and |
| 80 // use instances before they can provide the observer. (This is the case with | 78 // use instances before they can provide the observer. (This is the case with |
| 81 // VideoCaptureManager). | 79 // VideoCaptureManager). |
| 82 void SetConsumerFeedbackObserver( | 80 void SetConsumerFeedbackObserver( |
| 83 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> observer); | 81 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> observer); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 VideoCaptureControllerEventHandler* event_handler, | 123 VideoCaptureControllerEventHandler* event_handler, |
| 126 int buffer_id, | 124 int buffer_id, |
| 127 double consumer_resource_utilization); | 125 double consumer_resource_utilization); |
| 128 | 126 |
| 129 const media::VideoCaptureFormat& GetVideoCaptureFormat() const; | 127 const media::VideoCaptureFormat& GetVideoCaptureFormat() const; |
| 130 | 128 |
| 131 bool has_received_frames() const { return has_received_frames_; } | 129 bool has_received_frames() const { return has_received_frames_; } |
| 132 | 130 |
| 133 // Implementation of media::VideoFrameReceiver interface: | 131 // Implementation of media::VideoFrameReceiver interface: |
| 134 void OnIncomingCapturedVideoFrame( | 132 void OnIncomingCapturedVideoFrame( |
| 135 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, | 133 media::VideoCaptureDevice::Client::Buffer buffer, |
| 136 scoped_refptr<media::VideoFrame> frame) override; | 134 scoped_refptr<media::VideoFrame> frame) override; |
| 137 void OnError() override; | 135 void OnError() override; |
| 138 void OnLog(const std::string& message) override; | 136 void OnLog(const std::string& message) override; |
| 139 void OnBufferDestroyed(int buffer_id_to_drop) override; | 137 void OnBufferDestroyed(int buffer_id_to_drop) override; |
| 140 | 138 |
| 141 private: | 139 private: |
| 142 struct ControllerClient; | 140 struct ControllerClient; |
| 143 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; | 141 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; |
| 144 | 142 |
| 145 class BufferState { | 143 class BufferState { |
| 146 public: | 144 public: |
| 147 explicit BufferState( | 145 explicit BufferState( |
| 148 int buffer_id, | 146 int buffer_id, |
| 149 int frame_feedback_id, | 147 int frame_feedback_id, |
| 150 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, | 148 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, |
| 151 media::FrameBufferPool* frame_buffer_pool, | 149 media::FrameBufferPool* frame_buffer_pool); |
| 152 scoped_refptr<media::VideoFrame> frame); | |
| 153 ~BufferState(); | 150 ~BufferState(); |
| 154 BufferState(const BufferState& other); | 151 BufferState(const BufferState& other); |
| 155 void RecordConsumerUtilization(double utilization); | 152 void RecordConsumerUtilization(double utilization); |
| 156 void IncreaseConsumerCount(); | 153 void IncreaseConsumerCount(); |
| 157 void DecreaseConsumerCount(); | 154 void DecreaseConsumerCount(); |
| 158 bool HasZeroConsumerHoldCount(); | 155 bool HasZeroConsumerHoldCount(); |
| 159 void SetConsumerFeedbackObserver( | 156 void SetConsumerFeedbackObserver( |
| 160 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer); | 157 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer); |
| 161 void SetFrameBufferPool(media::FrameBufferPool* frame_buffer_pool); | 158 void SetFrameBufferPool(media::FrameBufferPool* frame_buffer_pool); |
| 162 | 159 |
| 163 private: | 160 private: |
| 164 const int buffer_id_; | 161 const int buffer_id_; |
| 165 const int frame_feedback_id_; | 162 const int frame_feedback_id_; |
| 166 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; | 163 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; |
| 167 media::FrameBufferPool* frame_buffer_pool_; | 164 media::FrameBufferPool* frame_buffer_pool_; |
| 168 const scoped_refptr<media::VideoFrame> frame_; | |
| 169 double max_consumer_utilization_; | 165 double max_consumer_utilization_; |
| 170 int consumer_hold_count_; | 166 int consumer_hold_count_; |
| 171 }; | 167 }; |
| 172 | 168 |
| 173 // Notify renderer that a new buffer has been created. | |
| 174 void DoNewBufferOnIOThread(ControllerClient* client, | |
| 175 media::VideoCaptureDevice::Client::Buffer* buffer, | |
| 176 const scoped_refptr<media::VideoFrame>& frame); | |
| 177 | |
| 178 // Find a client of |id| and |handler| in |clients|. | 169 // Find a client of |id| and |handler| in |clients|. |
| 179 ControllerClient* FindClient(VideoCaptureControllerID id, | 170 ControllerClient* FindClient(VideoCaptureControllerID id, |
| 180 VideoCaptureControllerEventHandler* handler, | 171 VideoCaptureControllerEventHandler* handler, |
| 181 const ControllerClients& clients); | 172 const ControllerClients& clients); |
| 182 | 173 |
| 183 // Find a client of |session_id| in |clients|. | 174 // Find a client of |session_id| in |clients|. |
| 184 ControllerClient* FindClient(int session_id, | 175 ControllerClient* FindClient(int session_id, |
| 185 const ControllerClients& clients); | 176 const ControllerClients& clients); |
| 186 | 177 |
| 187 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_; | 178 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 204 media::VideoCaptureFormat video_capture_format_; | 195 media::VideoCaptureFormat video_capture_format_; |
| 205 | 196 |
| 206 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; | 197 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; |
| 207 | 198 |
| 208 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); | 199 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); |
| 209 }; | 200 }; |
| 210 | 201 |
| 211 } // namespace content | 202 } // namespace content |
| 212 | 203 |
| 213 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 204 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
| OLD | NEW |