| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // Return a new VideoCaptureDeviceClient to forward capture events to this | 71 // Return a new VideoCaptureDeviceClient to forward capture events to this |
| 72 // instance. Some device clients need to allocate resources for the given | 72 // instance. Some device clients need to allocate resources for the given |
| 73 // capture |format| and/or work on Capture Thread (|capture_task_runner|). | 73 // capture |format| and/or work on Capture Thread (|capture_task_runner|). |
| 74 scoped_ptr<media::VideoCaptureDevice::Client> NewDeviceClient( | 74 scoped_ptr<media::VideoCaptureDevice::Client> NewDeviceClient( |
| 75 const scoped_refptr<base::SingleThreadTaskRunner>& capture_task_runner, | 75 const scoped_refptr<base::SingleThreadTaskRunner>& capture_task_runner, |
| 76 const media::VideoCaptureFormat& format); | 76 const media::VideoCaptureFormat& format); |
| 77 | 77 |
| 78 // Start video capturing and try to use the resolution specified in |params|. | 78 // Start video capturing and try to use the resolution specified in |params|. |
| 79 // Buffers will be shared to the client as necessary. The client will continue | 79 // Buffers will be shared to the client as necessary. The client will continue |
| 80 // to receive frames from the device until RemoveClient() is called. | 80 // to receive frames from the device until RemoveClient() is called. |
| 81 void AddClient(const VideoCaptureControllerID& id, | 81 void AddClient(VideoCaptureControllerID id, |
| 82 VideoCaptureControllerEventHandler* event_handler, | 82 VideoCaptureControllerEventHandler* event_handler, |
| 83 base::ProcessHandle render_process, | 83 base::ProcessHandle render_process, |
| 84 media::VideoCaptureSessionId session_id, | 84 media::VideoCaptureSessionId session_id, |
| 85 const media::VideoCaptureParams& params); | 85 const media::VideoCaptureParams& params); |
| 86 | 86 |
| 87 // Stop video capture. This will take back all buffers held by by | 87 // Stop video capture. This will take back all buffers held by by |
| 88 // |event_handler|, and |event_handler| shouldn't use those buffers any more. | 88 // |event_handler|, and |event_handler| shouldn't use those buffers any more. |
| 89 // Returns the session_id of the stopped client, or | 89 // Returns the session_id of the stopped client, or |
| 90 // kInvalidMediaCaptureSessionId if the indicated client was not registered. | 90 // kInvalidMediaCaptureSessionId if the indicated client was not registered. |
| 91 int RemoveClient(const VideoCaptureControllerID& id, | 91 int RemoveClient(VideoCaptureControllerID id, |
| 92 VideoCaptureControllerEventHandler* event_handler); | 92 VideoCaptureControllerEventHandler* event_handler); |
| 93 | 93 |
| 94 // Pause or resume the video capture for specified client. | 94 // Pause or resume the video capture for specified client. |
| 95 void PauseOrResumeClient(const VideoCaptureControllerID& id, | 95 void PauseOrResumeClient(VideoCaptureControllerID id, |
| 96 VideoCaptureControllerEventHandler* event_handler, | 96 VideoCaptureControllerEventHandler* event_handler, |
| 97 bool pause); | 97 bool pause); |
| 98 | 98 |
| 99 int GetClientCount() const; | 99 int GetClientCount() const; |
| 100 | 100 |
| 101 // Return the number of clients that aren't paused. | 101 // Return the number of clients that aren't paused. |
| 102 int GetActiveClientCount() const; | 102 int GetActiveClientCount() const; |
| 103 | 103 |
| 104 // API called directly by VideoCaptureManager in case the device is | 104 // API called directly by VideoCaptureManager in case the device is |
| 105 // prematurely closed. | 105 // prematurely closed. |
| 106 void StopSession(int session_id); | 106 void StopSession(int session_id); |
| 107 | 107 |
| 108 // Return a buffer with id |buffer_id| previously given in | 108 // Return a buffer with id |buffer_id| previously given in |
| 109 // VideoCaptureControllerEventHandler::OnBufferReady. In the case that the | 109 // VideoCaptureControllerEventHandler::OnBufferReady. In the case that the |
| 110 // buffer was backed by a texture, |sync_point| will be waited on before | 110 // buffer was backed by a texture, |sync_point| will be waited on before |
| 111 // destroying or recycling the texture, to synchronize with texture users in | 111 // destroying or recycling the texture, to synchronize with texture users in |
| 112 // the renderer process. | 112 // the renderer process. |
| 113 void ReturnBuffer(const VideoCaptureControllerID& id, | 113 void ReturnBuffer(VideoCaptureControllerID id, |
| 114 VideoCaptureControllerEventHandler* event_handler, | 114 VideoCaptureControllerEventHandler* event_handler, |
| 115 int buffer_id, | 115 int buffer_id, |
| 116 uint32 sync_point); | 116 uint32 sync_point); |
| 117 | 117 |
| 118 const media::VideoCaptureFormat& GetVideoCaptureFormat() const; | 118 const media::VideoCaptureFormat& GetVideoCaptureFormat() const; |
| 119 | 119 |
| 120 bool has_received_frames() const { return has_received_frames_; } | 120 bool has_received_frames() const { return has_received_frames_; } |
| 121 | 121 |
| 122 // Worker functions on IO thread. Called by the VideoCaptureDeviceClient. | 122 // Worker functions on IO thread. Called by the VideoCaptureDeviceClient. |
| 123 void DoIncomingCapturedVideoFrameOnIOThread( | 123 void DoIncomingCapturedVideoFrameOnIOThread( |
| 124 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, | 124 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, |
| 125 const scoped_refptr<media::VideoFrame>& frame, | 125 const scoped_refptr<media::VideoFrame>& frame, |
| 126 const base::TimeTicks& timestamp); | 126 const base::TimeTicks& timestamp); |
| 127 void DoErrorOnIOThread(); | 127 void DoErrorOnIOThread(); |
| 128 void DoLogOnIOThread(const std::string& message); | 128 void DoLogOnIOThread(const std::string& message); |
| 129 void DoBufferDestroyedOnIOThread(int buffer_id_to_drop); | 129 void DoBufferDestroyedOnIOThread(int buffer_id_to_drop); |
| 130 | 130 |
| 131 private: | 131 private: |
| 132 struct ControllerClient; | 132 struct ControllerClient; |
| 133 typedef std::list<ControllerClient*> ControllerClients; | 133 typedef std::list<ControllerClient*> ControllerClients; |
| 134 | 134 |
| 135 // Find a client of |id| and |handler| in |clients|. | 135 // Find a client of |id| and |handler| in |clients|. |
| 136 ControllerClient* FindClient(const VideoCaptureControllerID& id, | 136 ControllerClient* FindClient(VideoCaptureControllerID id, |
| 137 VideoCaptureControllerEventHandler* handler, | 137 VideoCaptureControllerEventHandler* handler, |
| 138 const ControllerClients& clients); | 138 const ControllerClients& clients); |
| 139 | 139 |
| 140 // Find a client of |session_id| in |clients|. | 140 // Find a client of |session_id| in |clients|. |
| 141 ControllerClient* FindClient(int session_id, | 141 ControllerClient* FindClient(int session_id, |
| 142 const ControllerClients& clients); | 142 const ControllerClients& clients); |
| 143 | 143 |
| 144 // The pool of shared-memory buffers used for capturing. | 144 // The pool of shared-memory buffers used for capturing. |
| 145 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 145 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
| 146 | 146 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 157 media::VideoCaptureFormat video_capture_format_; | 157 media::VideoCaptureFormat video_capture_format_; |
| 158 | 158 |
| 159 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; | 159 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; |
| 160 | 160 |
| 161 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); | 161 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 } // namespace content | 164 } // namespace content |
| 165 | 165 |
| 166 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 166 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
| OLD | NEW |