| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "base/memory/ref_counted.h" | 48 #include "base/memory/ref_counted.h" |
| 49 #include "base/memory/weak_ptr.h" | 49 #include "base/memory/weak_ptr.h" |
| 50 #include "base/process/process.h" | 50 #include "base/process/process.h" |
| 51 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 51 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
| 52 #include "content/common/content_export.h" | 52 #include "content/common/content_export.h" |
| 53 #include "content/common/media/video_capture.h" | 53 #include "content/common/media/video_capture.h" |
| 54 #include "media/capture/video/video_frame_receiver.h" | 54 #include "media/capture/video/video_frame_receiver.h" |
| 55 #include "media/capture/video_capture_types.h" | 55 #include "media/capture/video_capture_types.h" |
| 56 | 56 |
| 57 namespace media { | 57 namespace media { |
| 58 class FrameBufferPool; | 58 class VideoCaptureBufferPool; |
| 59 } | 59 } |
| 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 // |max_buffers| is the maximum number of video frame buffers in-flight at any |
| 66 // one time. This value should be based on the logical capacity of the |
| 67 // capture pipeline, and not on hardware performance. For example, tab |
| 68 // capture requires more buffers than webcam capture because the pipeline is |
| 69 // longer (it includes read-backs pending in the GPU pipeline). |
| 70 explicit VideoCaptureController(int max_buffers); |
| 66 ~VideoCaptureController() override; | 71 ~VideoCaptureController() override; |
| 67 | 72 |
| 68 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); | 73 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); |
| 69 | 74 |
| 70 // Factory code creating instances of VideoCaptureController must set a | |
| 71 // FrameBufferPool before any of the media::VideoFrameReceiver are used. | |
| 72 // Setting the observer is done in this method separate from the constructor | |
| 73 // in order to allow use the media::VideoFrameReceiver methods | |
| 74 // before the observer can be provided. (This is the case with | |
| 75 // VideoCaptureManager). | |
| 76 void SetFrameBufferPool( | |
| 77 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool); | |
| 78 | |
| 79 // Factory code creating instances of VideoCaptureController may optionally | 75 // Factory code creating instances of VideoCaptureController may optionally |
| 80 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in | 76 // set a VideoFrameConsumerFeedbackObserver. Setting the observer is done in |
| 81 // 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 |
| 82 // 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 |
| 83 // VideoCaptureManager). | 79 // VideoCaptureManager). |
| 84 void SetConsumerFeedbackObserver( | 80 void SetConsumerFeedbackObserver( |
| 85 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> observer); | 81 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> observer); |
| 86 | 82 |
| 83 // Return a new VideoCaptureDeviceClient to forward capture events to this |
| 84 // instance. |
| 85 std::unique_ptr<media::VideoCaptureDevice::Client> NewDeviceClient(); |
| 86 |
| 87 // Start video capturing and try to use the resolution specified in |params|. | 87 // Start video capturing and try to use the resolution specified in |params|. |
| 88 // Buffers will be shared to the client as necessary. The client will continue | 88 // Buffers will be shared to the client as necessary. The client will continue |
| 89 // to receive frames from the device until RemoveClient() is called. | 89 // to receive frames from the device until RemoveClient() is called. |
| 90 void AddClient(VideoCaptureControllerID id, | 90 void AddClient(VideoCaptureControllerID id, |
| 91 VideoCaptureControllerEventHandler* event_handler, | 91 VideoCaptureControllerEventHandler* event_handler, |
| 92 media::VideoCaptureSessionId session_id, | 92 media::VideoCaptureSessionId session_id, |
| 93 const media::VideoCaptureParams& params); | 93 const media::VideoCaptureParams& params); |
| 94 | 94 |
| 95 // Stop video capture. This will take back all buffers held by by | 95 // Stop video capture. This will take back all buffers held by by |
| 96 // |event_handler|, and |event_handler| shouldn't use those buffers any more. | 96 // |event_handler|, and |event_handler| shouldn't use those buffers any more. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 private: | 146 private: |
| 147 struct ControllerClient; | 147 struct ControllerClient; |
| 148 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; | 148 typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients; |
| 149 | 149 |
| 150 class BufferState { | 150 class BufferState { |
| 151 public: | 151 public: |
| 152 explicit BufferState( | 152 explicit BufferState( |
| 153 int buffer_id, | 153 int buffer_id, |
| 154 int frame_feedback_id, | 154 int frame_feedback_id, |
| 155 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, | 155 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, |
| 156 media::FrameBufferPool* frame_buffer_pool, | 156 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool, |
| 157 scoped_refptr<media::VideoFrame> frame); | 157 scoped_refptr<media::VideoFrame> frame); |
| 158 ~BufferState(); | 158 ~BufferState(); |
| 159 BufferState(const BufferState& other); | 159 BufferState(const BufferState& other); |
| 160 void RecordConsumerUtilization(double utilization); | 160 void RecordConsumerUtilization(double utilization); |
| 161 void IncreaseConsumerCount(); | 161 void IncreaseConsumerCount(); |
| 162 void DecreaseConsumerCount(); | 162 void DecreaseConsumerCount(); |
| 163 bool HasZeroConsumerHoldCount(); | 163 bool HasZeroConsumerHoldCount(); |
| 164 void SetConsumerFeedbackObserver( | 164 void SetConsumerFeedbackObserver( |
| 165 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer); | 165 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer); |
| 166 void SetFrameBufferPool(media::FrameBufferPool* frame_buffer_pool); | |
| 167 | 166 |
| 168 private: | 167 private: |
| 169 const int buffer_id_; | 168 const int buffer_id_; |
| 170 const int frame_feedback_id_; | 169 const int frame_feedback_id_; |
| 171 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; | 170 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer_; |
| 172 media::FrameBufferPool* frame_buffer_pool_; | 171 const scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; |
| 173 const scoped_refptr<media::VideoFrame> frame_; | 172 const scoped_refptr<media::VideoFrame> frame_; |
| 174 double max_consumer_utilization_; | 173 double max_consumer_utilization_; |
| 175 int consumer_hold_count_; | 174 int consumer_hold_count_; |
| 176 }; | 175 }; |
| 177 | 176 |
| 178 // Notify renderer that a new buffer has been created. | 177 // Notify renderer that a new buffer has been created. |
| 179 void DoNewBufferOnIOThread(ControllerClient* client, | 178 void DoNewBufferOnIOThread(ControllerClient* client, |
| 180 media::VideoCaptureDevice::Client::Buffer* buffer, | 179 media::VideoCaptureDevice::Client::Buffer* buffer, |
| 181 const scoped_refptr<media::VideoFrame>& frame); | 180 const scoped_refptr<media::VideoFrame>& frame); |
| 182 | 181 |
| 183 // Find a client of |id| and |handler| in |clients|. | 182 // Find a client of |id| and |handler| in |clients|. |
| 184 ControllerClient* FindClient(VideoCaptureControllerID id, | 183 ControllerClient* FindClient(VideoCaptureControllerID id, |
| 185 VideoCaptureControllerEventHandler* handler, | 184 VideoCaptureControllerEventHandler* handler, |
| 186 const ControllerClients& clients); | 185 const ControllerClients& clients); |
| 187 | 186 |
| 188 // Find a client of |session_id| in |clients|. | 187 // Find a client of |session_id| in |clients|. |
| 189 ControllerClient* FindClient(int session_id, | 188 ControllerClient* FindClient(int session_id, |
| 190 const ControllerClients& clients); | 189 const ControllerClients& clients); |
| 191 | 190 |
| 192 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool_; | 191 // The pool of shared-memory buffers used for capturing. |
| 192 const scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; |
| 193 | 193 |
| 194 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> | 194 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> |
| 195 consumer_feedback_observer_; | 195 consumer_feedback_observer_; |
| 196 | 196 |
| 197 std::map<int, BufferState> buffer_id_to_state_map_; | 197 std::map<int, BufferState> buffer_id_to_state_map_; |
| 198 | 198 |
| 199 // All clients served by this controller. | 199 // All clients served by this controller. |
| 200 ControllerClients controller_clients_; | 200 ControllerClients controller_clients_; |
| 201 | 201 |
| 202 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing | 202 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing |
| 203 // state which stops the flow of data to clients. | 203 // state which stops the flow of data to clients. |
| 204 VideoCaptureState state_; | 204 VideoCaptureState state_; |
| 205 | 205 |
| 206 // True if the controller has received a video frame from the device. | 206 // True if the controller has received a video frame from the device. |
| 207 bool has_received_frames_; | 207 bool has_received_frames_; |
| 208 | 208 |
| 209 media::VideoCaptureFormat video_capture_format_; | 209 media::VideoCaptureFormat video_capture_format_; |
| 210 | 210 |
| 211 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; | 211 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; |
| 212 | 212 |
| 213 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); | 213 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 } // namespace content | 216 } // namespace content |
| 217 | 217 |
| 218 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 218 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
| OLD | NEW |