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 // Factory code creating instances of VideoCaptureController must set a | 70 // Factory code creating instances of VideoCaptureController may optionally |
71 // FrameBufferPool before any of the media::VideoFrameReceiver are used. | 71 // set a FrameBufferPool. Setting the host is done in this method |
72 // Setting the observer is done in this method separate from the constructor | 72 // separate from the constructor to allow clients to create and use instances |
73 // in order to allow use the media::VideoFrameReceiver methods | 73 // before they can provide the observer. (This is the case with |
74 // before the observer can be provided. (This is the case with | |
75 // VideoCaptureManager). | 74 // VideoCaptureManager). |
76 void SetFrameBufferPool( | 75 void SetFrameBufferPool( |
77 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool); | 76 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool); |
78 | 77 |
79 // Factory code creating instances of VideoCaptureController may optionally | 78 // Factory code creating instances of VideoCaptureController may optionally |
80 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in | 79 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in |
81 // this method separate from the constructor to allow clients to create and | 80 // this method separate from the constructor to allow clients to create and |
82 // use instances before they can provide the observer. (This is the case with | 81 // use instances before they can provide the observer. (This is the case with |
83 // VideoCaptureManager). | 82 // VideoCaptureManager). |
84 void SetConsumerFeedbackObserver( | 83 void SetConsumerFeedbackObserver( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 int buffer_id, | 129 int buffer_id, |
131 const gpu::SyncToken& sync_token, | 130 const gpu::SyncToken& sync_token, |
132 double consumer_resource_utilization); | 131 double consumer_resource_utilization); |
133 | 132 |
134 const media::VideoCaptureFormat& GetVideoCaptureFormat() const; | 133 const media::VideoCaptureFormat& GetVideoCaptureFormat() const; |
135 | 134 |
136 bool has_received_frames() const { return has_received_frames_; } | 135 bool has_received_frames() const { return has_received_frames_; } |
137 | 136 |
138 // Implementation of media::VideoFrameReceiver interface: | 137 // Implementation of media::VideoFrameReceiver interface: |
139 void OnIncomingCapturedVideoFrame( | 138 void OnIncomingCapturedVideoFrame( |
140 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, | 139 media::VideoCaptureDevice::Client::Buffer buffer, |
141 scoped_refptr<media::VideoFrame> frame) override; | 140 scoped_refptr<media::VideoFrame> frame) override; |
142 void OnError() override; | 141 void OnError() override; |
143 void OnLog(const std::string& message) override; | 142 void OnLog(const std::string& message) override; |
144 void OnBufferDestroyed(int buffer_id_to_drop) override; | 143 void OnBufferDestroyed(int buffer_id_to_drop) override; |
145 | 144 |
146 private: | 145 private: |
147 struct ControllerClient; | 146 struct ControllerClient; |
148 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; | 147 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; |
149 | 148 |
150 class BufferState { | 149 class BufferState { |
151 public: | 150 public: |
152 explicit BufferState( | 151 explicit BufferState( |
153 int buffer_id, | 152 int buffer_id, |
154 int frame_feedback_id, | 153 int frame_feedback_id, |
155 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, | 154 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, |
156 media::FrameBufferPool* frame_buffer_pool, | 155 media::FrameBufferPool* frame_buffer_pool); |
157 scoped_refptr<media::VideoFrame> frame); | |
158 ~BufferState(); | 156 ~BufferState(); |
159 BufferState(const BufferState& other); | 157 BufferState(const BufferState& other); |
160 void RecordConsumerUtilization(double utilization); | 158 void RecordConsumerUtilization(double utilization); |
161 void IncreaseConsumerCount(); | 159 void IncreaseConsumerCount(); |
162 void DecreaseConsumerCount(); | 160 void DecreaseConsumerCount(); |
163 bool HasZeroConsumerHoldCount(); | 161 bool HasZeroConsumerHoldCount(); |
164 void SetConsumerFeedbackObserver( | 162 void SetConsumerFeedbackObserver( |
165 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer); | 163 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer); |
166 void SetFrameBufferPool(media::FrameBufferPool* frame_buffer_pool); | 164 void SetFrameBufferPool(media::FrameBufferPool* frame_buffer_pool); |
167 | 165 |
168 private: | 166 private: |
169 const int buffer_id_; | 167 const int buffer_id_; |
170 const int frame_feedback_id_; | 168 const int frame_feedback_id_; |
171 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; | 169 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; |
172 media::FrameBufferPool* frame_buffer_pool_; | 170 media::FrameBufferPool* frame_buffer_pool_; |
173 const scoped_refptr<media::VideoFrame> frame_; | |
174 double max_consumer_utilization_; | 171 double max_consumer_utilization_; |
175 int consumer_hold_count_; | 172 int consumer_hold_count_; |
176 }; | 173 }; |
177 | 174 |
178 // Notify renderer that a new buffer has been created. | |
179 void DoNewBufferOnIOThread(ControllerClient* client, | |
180 media::VideoCaptureDevice::Client::Buffer* buffer, | |
181 const scoped_refptr<media::VideoFrame>& frame); | |
182 | |
183 // Find a client of |id| and |handler| in |clients|. | 175 // Find a client of |id| and |handler| in |clients|. |
184 ControllerClient* FindClient(VideoCaptureControllerID id, | 176 ControllerClient* FindClient(VideoCaptureControllerID id, |
185 VideoCaptureControllerEventHandler* handler, | 177 VideoCaptureControllerEventHandler* handler, |
186 const ControllerClients& clients); | 178 const ControllerClients& clients); |
187 | 179 |
188 // Find a client of |session_id| in |clients|. | 180 // Find a client of |session_id| in |clients|. |
189 ControllerClient* FindClient(int session_id, | 181 ControllerClient* FindClient(int session_id, |
190 const ControllerClients& clients); | 182 const ControllerClients& clients); |
191 | 183 |
192 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_; | 184 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_; |
(...skipping 16 matching lines...) Expand all Loading... |
209 media::VideoCaptureFormat video_capture_format_; | 201 media::VideoCaptureFormat video_capture_format_; |
210 | 202 |
211 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; | 203 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; |
212 | 204 |
213 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); | 205 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); |
214 }; | 206 }; |
215 | 207 |
216 } // namespace content | 208 } // namespace content |
217 | 209 |
218 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 210 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
OLD | NEW |