| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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/base/video_capture_types.h" | 54 #include "media/base/video_capture_types.h" |
| 55 #include "media/capture/video/video_capture_device.h" | 55 #include "media/capture/video/video_capture_device.h" |
| 56 | 56 |
| 57 namespace content { | 57 namespace content { |
| 58 class VideoCaptureBufferPool; | 58 class VideoCaptureBufferPool; |
| 59 | 59 |
| 60 class CONTENT_EXPORT VideoCaptureController { | 60 class CONTENT_EXPORT VideoFrameReceiver { |
| 61 public: |
| 62 virtual ~VideoFrameReceiver(){}; |
| 63 |
| 64 virtual void OnIncomingCapturedVideoFrame( |
| 65 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, |
| 66 const scoped_refptr<media::VideoFrame>& frame) = 0; |
| 67 virtual void OnError() = 0; |
| 68 virtual void OnLog(const std::string& message) = 0; |
| 69 virtual void OnBufferDestroyed(int buffer_id_to_drop) = 0; |
| 70 }; |
| 71 |
| 72 class CONTENT_EXPORT VideoCaptureController : public VideoFrameReceiver { |
| 61 public: | 73 public: |
| 62 // |max_buffers| is the maximum number of video frame buffers in-flight at any | 74 // |max_buffers| is the maximum number of video frame buffers in-flight at any |
| 63 // one time. This value should be based on the logical capacity of the | 75 // one time. This value should be based on the logical capacity of the |
| 64 // capture pipeline, and not on hardware performance. For example, tab | 76 // capture pipeline, and not on hardware performance. For example, tab |
| 65 // capture requires more buffers than webcam capture because the pipeline is | 77 // capture requires more buffers than webcam capture because the pipeline is |
| 66 // longer (it includes read-backs pending in the GPU pipeline). | 78 // longer (it includes read-backs pending in the GPU pipeline). |
| 67 explicit VideoCaptureController(int max_buffers); | 79 explicit VideoCaptureController(int max_buffers); |
| 68 virtual ~VideoCaptureController(); | 80 ~VideoCaptureController() override; |
| 69 | 81 |
| 70 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); | 82 base::WeakPtr<VideoCaptureController> GetWeakPtrForIOThread(); |
| 71 | 83 |
| 72 // Return a new VideoCaptureDeviceClient to forward capture events to this | 84 // Return a new VideoCaptureDeviceClient to forward capture events to this |
| 73 // instance. | 85 // instance. |
| 74 std::unique_ptr<media::VideoCaptureDevice::Client> NewDeviceClient(); | 86 std::unique_ptr<media::VideoCaptureDevice::Client> NewDeviceClient(); |
| 75 | 87 |
| 76 // Start video capturing and try to use the resolution specified in |params|. | 88 // Start video capturing and try to use the resolution specified in |params|. |
| 77 // Buffers will be shared to the client as necessary. The client will continue | 89 // Buffers will be shared to the client as necessary. The client will continue |
| 78 // to receive frames from the device until RemoveClient() is called. | 90 // to receive frames from the device until RemoveClient() is called. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 void ReturnBuffer(VideoCaptureControllerID id, | 130 void ReturnBuffer(VideoCaptureControllerID id, |
| 119 VideoCaptureControllerEventHandler* event_handler, | 131 VideoCaptureControllerEventHandler* event_handler, |
| 120 int buffer_id, | 132 int buffer_id, |
| 121 const gpu::SyncToken& sync_token, | 133 const gpu::SyncToken& sync_token, |
| 122 double consumer_resource_utilization); | 134 double consumer_resource_utilization); |
| 123 | 135 |
| 124 const media::VideoCaptureFormat& GetVideoCaptureFormat() const; | 136 const media::VideoCaptureFormat& GetVideoCaptureFormat() const; |
| 125 | 137 |
| 126 bool has_received_frames() const { return has_received_frames_; } | 138 bool has_received_frames() const { return has_received_frames_; } |
| 127 | 139 |
| 128 // Worker functions on IO thread. Called by the VideoCaptureDeviceClient. | 140 // Implementation of VideoFrameReceiver interface: |
| 129 virtual void DoIncomingCapturedVideoFrameOnIOThread( | 141 void OnIncomingCapturedVideoFrame( |
| 130 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, | 142 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, |
| 131 const scoped_refptr<media::VideoFrame>& frame); | 143 const scoped_refptr<media::VideoFrame>& frame) override; |
| 132 virtual void DoErrorOnIOThread(); | 144 void OnError() override; |
| 133 virtual void DoLogOnIOThread(const std::string& message); | 145 void OnLog(const std::string& message) override; |
| 134 virtual void DoBufferDestroyedOnIOThread(int buffer_id_to_drop); | 146 void OnBufferDestroyed(int buffer_id_to_drop) override; |
| 135 | 147 |
| 136 private: | 148 private: |
| 137 struct ControllerClient; | 149 struct ControllerClient; |
| 138 typedef std::list<ControllerClient*> ControllerClients; | 150 typedef std::list<ControllerClient*> ControllerClients; |
| 139 | 151 |
| 140 // Notify renderer that a new buffer has been created. | 152 // Notify renderer that a new buffer has been created. |
| 141 void DoNewBufferOnIOThread(ControllerClient* client, | 153 void DoNewBufferOnIOThread(ControllerClient* client, |
| 142 media::VideoCaptureDevice::Client::Buffer* buffer, | 154 media::VideoCaptureDevice::Client::Buffer* buffer, |
| 143 const scoped_refptr<media::VideoFrame>& frame); | 155 const scoped_refptr<media::VideoFrame>& frame); |
| 144 | 156 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 167 media::VideoCaptureFormat video_capture_format_; | 179 media::VideoCaptureFormat video_capture_format_; |
| 168 | 180 |
| 169 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; | 181 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; |
| 170 | 182 |
| 171 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); | 183 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); |
| 172 }; | 184 }; |
| 173 | 185 |
| 174 } // namespace content | 186 } // namespace content |
| 175 | 187 |
| 176 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 188 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
| OLD | NEW |