| 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 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 48 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
| 49 | 49 |
| 50 #include <list> | 50 #include <list> |
| 51 #include <map> | 51 #include <map> |
| 52 | 52 |
| 53 #include "base/compiler_specific.h" | 53 #include "base/compiler_specific.h" |
| 54 #include "base/memory/ref_counted.h" | 54 #include "base/memory/ref_counted.h" |
| 55 #include "base/memory/scoped_ptr.h" | 55 #include "base/memory/scoped_ptr.h" |
| 56 #include "base/memory/weak_ptr.h" | 56 #include "base/memory/weak_ptr.h" |
| 57 #include "base/process/process.h" | 57 #include "base/process/process.h" |
| 58 #include "base/synchronization/lock.h" | |
| 59 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" | 58 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" |
| 60 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 59 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
| 61 #include "content/common/content_export.h" | 60 #include "content/common/content_export.h" |
| 62 #include "content/common/media/video_capture.h" | 61 #include "content/common/media/video_capture.h" |
| 63 #include "media/video/capture/video_capture.h" | 62 #include "media/video/capture/video_capture.h" |
| 64 #include "media/video/capture/video_capture_device.h" | 63 #include "media/video/capture/video_capture_device.h" |
| 65 #include "media/video/capture/video_capture_types.h" | 64 #include "media/video/capture/video_capture_types.h" |
| 66 | 65 |
| 67 namespace content { | 66 namespace content { |
| 68 class VideoCaptureBufferPool; | 67 class VideoCaptureBufferPool; |
| 69 | 68 |
| 70 class CONTENT_EXPORT VideoCaptureController { | 69 class CONTENT_EXPORT VideoCaptureController { |
| 71 public: | 70 public: |
| 72 VideoCaptureController(); | 71 VideoCaptureController(); |
| 73 virtual ~VideoCaptureController(); | 72 virtual ~VideoCaptureController(); |
| 74 | 73 |
| 75 base::WeakPtr<VideoCaptureController> GetWeakPtr(); | 74 base::WeakPtr<VideoCaptureController> GetWeakPtr(); |
| 76 | 75 |
| 77 // Return a new VideoCaptureDeviceClient to forward capture events to this | 76 // Return a new VideoCaptureDeviceClient to forward capture events to this |
| 78 // instance. | 77 // instance. |
| 79 scoped_ptr<media::VideoCaptureDevice::Client> NewDeviceClient(); | 78 scoped_ptr<media::VideoCaptureDevice::Client> NewDeviceClient(); |
| 80 | 79 |
| 81 // Start video capturing and try to use the resolution specified in | 80 // Start video capturing and try to use the resolution specified in |params|. |
| 82 // |params|. | 81 // Buffers will be shared to the client as necessary. The client will continue |
| 83 // When capturing starts, the |event_handler| will receive an OnFrameInfo() | 82 // to receive frames from the device until RemoveClient() is called. |
| 84 // call informing it of the resolution that was actually picked by the device. | |
| 85 void AddClient(const VideoCaptureControllerID& id, | 83 void AddClient(const VideoCaptureControllerID& id, |
| 86 VideoCaptureControllerEventHandler* event_handler, | 84 VideoCaptureControllerEventHandler* event_handler, |
| 87 base::ProcessHandle render_process, | 85 base::ProcessHandle render_process, |
| 88 const media::VideoCaptureParams& params); | 86 const media::VideoCaptureParams& params); |
| 89 | 87 |
| 90 // Stop video capture. This will take back all buffers held by by | 88 // Stop video capture. This will take back all buffers held by by |
| 91 // |event_handler|, and |event_handler| shouldn't use those buffers any more. | 89 // |event_handler|, and |event_handler| shouldn't use those buffers any more. |
| 92 // Returns the session_id of the stopped client, or | 90 // Returns the session_id of the stopped client, or |
| 93 // kInvalidMediaCaptureSessionId if the indicated client was not registered. | 91 // kInvalidMediaCaptureSessionId if the indicated client was not registered. |
| 94 int RemoveClient(const VideoCaptureControllerID& id, | 92 int RemoveClient(const VideoCaptureControllerID& id, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 108 | 106 |
| 109 private: | 107 private: |
| 110 class VideoCaptureDeviceClient; | 108 class VideoCaptureDeviceClient; |
| 111 | 109 |
| 112 struct ControllerClient; | 110 struct ControllerClient; |
| 113 typedef std::list<ControllerClient*> ControllerClients; | 111 typedef std::list<ControllerClient*> ControllerClients; |
| 114 | 112 |
| 115 // Worker functions on IO thread. Called by the VideoCaptureDeviceClient. | 113 // Worker functions on IO thread. Called by the VideoCaptureDeviceClient. |
| 116 void DoIncomingCapturedFrameOnIOThread( | 114 void DoIncomingCapturedFrameOnIOThread( |
| 117 const scoped_refptr<media::VideoFrame>& captured_frame, | 115 const scoped_refptr<media::VideoFrame>& captured_frame, |
| 116 int frame_rate, |
| 118 base::Time timestamp); | 117 base::Time timestamp); |
| 119 void DoFrameInfoOnIOThread( | |
| 120 const media::VideoCaptureCapability& frame_info, | |
| 121 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool); | |
| 122 void DoFrameInfoChangedOnIOThread(const media::VideoCaptureCapability& info); | |
| 123 void DoErrorOnIOThread(); | 118 void DoErrorOnIOThread(); |
| 124 void DoDeviceStoppedOnIOThread(); | 119 void DoDeviceStoppedOnIOThread(); |
| 125 | 120 void DoBufferDestroyedOnIOThread(int buffer_id_to_drop); |
| 126 // Send frame info and init buffers to |client|. | |
| 127 void SendFrameInfoAndBuffers(ControllerClient* client); | |
| 128 | 121 |
| 129 // Find a client of |id| and |handler| in |clients|. | 122 // Find a client of |id| and |handler| in |clients|. |
| 130 ControllerClient* FindClient( | 123 ControllerClient* FindClient( |
| 131 const VideoCaptureControllerID& id, | 124 const VideoCaptureControllerID& id, |
| 132 VideoCaptureControllerEventHandler* handler, | 125 VideoCaptureControllerEventHandler* handler, |
| 133 const ControllerClients& clients); | 126 const ControllerClients& clients); |
| 134 | 127 |
| 135 // Find a client of |session_id| in |clients|. | 128 // Find a client of |session_id| in |clients|. |
| 136 ControllerClient* FindClient( | 129 ControllerClient* FindClient( |
| 137 int session_id, | 130 int session_id, |
| 138 const ControllerClients& clients); | 131 const ControllerClients& clients); |
| 139 | 132 |
| 140 // The pool of shared-memory buffers used for capturing. | 133 // The pool of shared-memory buffers used for capturing. |
| 141 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 134 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
| 142 | 135 |
| 143 // All clients served by this controller. | 136 // All clients served by this controller. |
| 144 ControllerClients controller_clients_; | 137 ControllerClients controller_clients_; |
| 145 | 138 |
| 146 // The parameter that currently used for the capturing. | |
| 147 media::VideoCaptureParams current_params_; | |
| 148 | |
| 149 // Tracks the current frame format. | |
| 150 media::VideoCaptureCapability frame_info_; | |
| 151 | |
| 152 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing | 139 // Takes on only the states 'STARTED' and 'ERROR'. 'ERROR' is an absorbing |
| 153 // state which stops the flow of data to clients. | 140 // state which stops the flow of data to clients. |
| 154 VideoCaptureState state_; | 141 VideoCaptureState state_; |
| 155 | 142 |
| 156 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; | 143 base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_; |
| 157 | 144 |
| 158 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); | 145 DISALLOW_COPY_AND_ASSIGN(VideoCaptureController); |
| 159 }; | 146 }; |
| 160 | 147 |
| 161 } // namespace content | 148 } // namespace content |
| 162 | 149 |
| 163 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ | 150 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_CONTROLLER_H_ |
| OLD | NEW |