Chromium Code Reviews| 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 // VideoCaptureDevice is the abstract base class for realizing video capture | 5 // VideoCaptureDevice is the abstract base class for realizing video capture |
| 6 // device support in Chromium. It provides the interface for OS dependent | 6 // device support in Chromium. It provides the interface for OS dependent |
| 7 // implementations. | 7 // implementations. |
| 8 // The class is created and functions are invoked on a thread owned by | 8 // The class is created and functions are invoked on a thread owned by |
| 9 // VideoCaptureManager. Capturing is done on other threads, depending on the OS | 9 // VideoCaptureManager. Capturing is done on other threads, depending on the OS |
| 10 // specific implementation. | 10 // specific implementation. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 : public NON_EXPORTED_BASE(std::list<Name>) { | 113 : public NON_EXPORTED_BASE(std::list<Name>) { |
| 114 public: | 114 public: |
| 115 // Returns NULL if no entry was found by that ID. | 115 // Returns NULL if no entry was found by that ID. |
| 116 Name* FindById(const std::string& id); | 116 Name* FindById(const std::string& id); |
| 117 | 117 |
| 118 // Allow generated copy constructor and assignment. | 118 // Allow generated copy constructor and assignment. |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 class MEDIA_EXPORT EventHandler { | 121 class MEDIA_EXPORT EventHandler { |
| 122 public: | 122 public: |
| 123 virtual ~EventHandler() {} | |
| 123 | 124 |
| 124 // Reserve an output buffer into which a video frame can be captured | 125 // Reserve an output buffer into which a video frame can be captured |
| 125 // directly. If all buffers are currently busy, returns NULL. | 126 // directly. If all buffers are currently busy, returns NULL. |
| 126 // | 127 // |
| 127 // The returned VideoFrames will always be allocated with a YV12 format. The | 128 // The returned VideoFrames will always be allocated with a YV12 format. The |
| 128 // size will match that specified by an earlier call to OnFrameInfo. It is | 129 // size will match that specified by an earlier call to OnFrameInfo. It is |
| 129 // the VideoCaptureDevice's responsibility to obey whatever stride and | 130 // the VideoCaptureDevice's responsibility to obey whatever stride and |
| 130 // memory layout are indicated on the returned VideoFrame object. | 131 // memory layout are indicated on the returned VideoFrame object. |
| 131 // | 132 // |
| 132 // The output buffer stays reserved for use by the calling | 133 // The output buffer stays reserved for use by the calling |
| 133 // VideoCaptureDevice until either the last reference to the VideoFrame is | 134 // VideoCaptureDevice until either the last reference to the VideoFrame is |
| 134 // released, or until the buffer is passed back to the EventHandler's | 135 // released, or until the buffer is passed back to the EventHandler's |
| 135 // OnIncomingCapturedFrame() method. | 136 // OnIncomingCapturedFrame() method. |
| 136 // | |
| 137 // Threading note: After VideoCaptureDevice::DeAllocate() occurs, the | |
| 138 // VideoCaptureDevice is not permitted to make any additional calls through | |
| 139 // its EventHandler. However, any VideoFrames returned from the EventHandler | |
| 140 // DO remain valid after DeAllocate(). The VideoCaptureDevice must still | |
| 141 // eventually release them, but it may do so later -- e.g., after a queued | |
| 142 // capture operation completes. | |
| 143 virtual scoped_refptr<media::VideoFrame> ReserveOutputBuffer() = 0; | 137 virtual scoped_refptr<media::VideoFrame> ReserveOutputBuffer() = 0; |
| 144 | 138 |
| 145 // Captured a new video frame as a raw buffer. The size, color format, and | 139 // Captured a new video frame as a raw buffer. The size, color format, and |
| 146 // layout are taken from the parameters specified by an earlier call to | 140 // layout are taken from the parameters specified by an earlier call to |
| 147 // OnFrameInfo(). |data| must be packed, with no padding between rows and/or | 141 // OnFrameInfo(). |data| must be packed, with no padding between rows and/or |
| 148 // color planes. | 142 // color planes. |
| 149 // | 143 // |
| 150 // This method will try to reserve an output buffer and copy from |data| | 144 // This method will try to reserve an output buffer and copy from |data| |
| 151 // into the output buffer. If no output buffer is available, the frame will | 145 // into the output buffer. If no output buffer is available, the frame will |
| 152 // be silently dropped. | 146 // be silently dropped. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 173 // silently dropped. |frame| must be allocated as RGB32, YV12 or I420, and | 167 // silently dropped. |frame| must be allocated as RGB32, YV12 or I420, and |
| 174 // the size must match that specified by an earlier call to OnFrameInfo(). | 168 // the size must match that specified by an earlier call to OnFrameInfo(). |
| 175 virtual void OnIncomingCapturedVideoFrame( | 169 virtual void OnIncomingCapturedVideoFrame( |
| 176 const scoped_refptr<media::VideoFrame>& frame, | 170 const scoped_refptr<media::VideoFrame>& frame, |
| 177 base::Time timestamp) = 0; | 171 base::Time timestamp) = 0; |
| 178 | 172 |
| 179 // An error has occurred that cannot be handled and VideoCaptureDevice must | 173 // An error has occurred that cannot be handled and VideoCaptureDevice must |
| 180 // be DeAllocate()-ed. | 174 // be DeAllocate()-ed. |
| 181 virtual void OnError() = 0; | 175 virtual void OnError() = 0; |
| 182 | 176 |
| 183 // Called when VideoCaptureDevice::Allocate() has been called to inform of | 177 // Called when VideoCaptureDevice::AllocateAndStart() has been called to |
| 184 // the resulting frame size. | 178 // inform of the resulting frame size. |
| 185 virtual void OnFrameInfo(const VideoCaptureCapability& info) = 0; | 179 virtual void OnFrameInfo(const VideoCaptureCapability& info) = 0; |
| 186 | 180 |
| 187 // Called when the native resolution of VideoCaptureDevice has been changed | 181 // Called when the native resolution of VideoCaptureDevice has been changed |
| 188 // and it needs to inform its client of the new frame size. | 182 // and it needs to inform its client of the new frame size. |
| 189 virtual void OnFrameInfoChanged(const VideoCaptureCapability& info) {}; | 183 virtual void OnFrameInfoChanged(const VideoCaptureCapability& info) {}; |
| 190 | |
| 191 protected: | |
| 192 virtual ~EventHandler() {} | |
| 193 }; | 184 }; |
| 194 // Creates a VideoCaptureDevice object. | 185 // Creates a VideoCaptureDevice object. |
| 195 // Return NULL if the hardware is not available. | 186 // Return NULL if the hardware is not available. |
| 196 static VideoCaptureDevice* Create(const Name& device_name); | 187 static VideoCaptureDevice* Create(const Name& device_name); |
| 197 virtual ~VideoCaptureDevice() {} | 188 virtual ~VideoCaptureDevice(); |
| 198 | 189 |
| 199 // Gets the names of all video capture devices connected to this computer. | 190 // Gets the names of all video capture devices connected to this computer. |
| 200 static void GetDeviceNames(Names* device_names); | 191 static void GetDeviceNames(Names* device_names); |
| 201 | 192 |
| 202 // Prepare the camera for use. After this function has been called no other | 193 // Prepare the camera for use. After this function has been called no other |
| 203 // applications can use the camera. On completion EventHandler::OnFrameInfo() | 194 // applications can use the camera. On completion EventHandler::OnFrameInfo() |
| 204 // is called informing of the resulting resolution and frame rate. | 195 // is called informing of the resulting resolution and frame rate. |
| 196 // StopAndDeAllocate() must be called before the object is deleted. | |
| 197 virtual void AllocateAndStart( | |
| 198 const VideoCaptureCapability& capture_format, | |
| 199 scoped_ptr<EventHandler> client) = 0; | |
| 200 | |
| 201 // Deallocates the camera, possibly asynchronously. | |
| 202 // | |
| 203 // This call requires the device to do the following things, eventually: put | |
| 204 // camera hardware into a state where other applications could use it, free | |
| 205 // the memory associated with capture, and delete the |client| pointer passed | |
| 206 // into AllocateAndStart. | |
| 207 // | |
| 208 // If deallocation is done asynchronously, then the device implementation must | |
| 209 // ensure that a subsequent AllocateAndStart() operation targeting the same ID | |
| 210 // would be sequenced through the same task runner, so that deallocation | |
| 211 // happens first. | |
| 212 // | |
| 213 // Upon this call, the |client| pointer passed into AllocateAndStart() remains | |
| 214 // valid but enters a lame state where it is detached from any consumer, and | |
|
Ami GONE FROM CHROMIUM
2013/09/14 00:32:24
I don't understand how this can be useful. Two pa
ncarter (slow)
2013/09/14 01:29:31
It remains valid in that it's not illegal for stuf
| |
| 215 // frames are silently dropped. | |
| 216 virtual void StopAndDeAllocate() = 0; | |
| 217 }; | |
| 218 | |
| 219 // VideoCaptureDevice1 is a bridge to an older API against which | |
| 220 // VideoCaptureDevices were implemented. Differences between VideoCaptureDevice | |
| 221 // (new style) and VideoCaptureDevice1 (old style) are as follows: | |
| 222 // | |
| 223 // [1] The Stop+DeAllocate calls are merged in the new style. | |
| 224 // [2] The Allocate+Start calls are merged in the new style. | |
| 225 // [3] New style devices own their EventHandler* pointers, allowing handlers to | |
| 226 // remain valid even after the device is stopped. Whereas old style devices | |
| 227 // may not dereference their handlers after DeAllocate(). | |
| 228 // [4] device_name() is eliminated from the new-style interface. | |
| 229 // | |
| 230 // TODO(nick): Remove this bridge class. It exists to enable incremental | |
| 231 // migration to an alternative VideoCaptureDevice API. | |
| 232 class MEDIA_EXPORT VideoCaptureDevice1 : public VideoCaptureDevice { | |
| 233 public: | |
| 234 VideoCaptureDevice1(); | |
| 235 virtual ~VideoCaptureDevice1(); | |
| 236 | |
| 237 // VideoCaptureDevice implementation. | |
| 238 virtual void AllocateAndStart( | |
| 239 const VideoCaptureCapability& capture_format, | |
| 240 scoped_ptr<EventHandler> client) OVERRIDE; | |
| 241 virtual void StopAndDeAllocate() OVERRIDE; | |
| 242 | |
| 243 // Prepare the camera for use. After this function has been called no other | |
| 244 // applications can use the camera. On completion EventHandler::OnFrameInfo() | |
| 245 // is called informing of the resulting resolution and frame rate. | |
| 205 // DeAllocate() must be called before this function can be called again and | 246 // DeAllocate() must be called before this function can be called again and |
| 206 // before the object is deleted. | 247 // before the object is deleted. |
| 207 virtual void Allocate(const VideoCaptureCapability& capture_format, | 248 virtual void Allocate(const VideoCaptureCapability& capture_format, |
| 208 EventHandler* observer) = 0; | 249 EventHandler* client) = 0; |
| 209 | 250 |
| 210 // Start capturing video frames. Allocate must be called before this function. | 251 // Start capturing video frames. Allocate must be called before this function. |
| 211 virtual void Start() = 0; | 252 virtual void Start() = 0; |
| 212 | 253 |
| 213 // Stop capturing video frames. | 254 // Stop capturing video frames. |
| 214 virtual void Stop() = 0; | 255 virtual void Stop() = 0; |
| 215 | 256 |
| 216 // Deallocates the camera. This means other applications can use it. After | 257 // Deallocates the camera. This means other applications can use it. After |
| 217 // this function has been called the capture device is reset to the state it | 258 // this function has been called the capture device is reset to the state it |
| 218 // was when created. After DeAllocate() is called, the VideoCaptureDevice is | 259 // was when created. After DeAllocate() is called, the VideoCaptureDevice is |
| 219 // not permitted to make any additional calls to its EventHandler. | 260 // not permitted to make any additional calls to its EventHandler. |
| 220 virtual void DeAllocate() = 0; | 261 virtual void DeAllocate() = 0; |
| 221 | 262 |
| 222 // Get the name of the capture device. | 263 // Get the name of the capture device. |
| 223 virtual const Name& device_name() = 0; | 264 virtual const Name& device_name() = 0; |
| 265 | |
| 266 private: | |
| 267 // The device client which proxies device events to the controller. | |
| 268 scoped_ptr<EventHandler> client_; | |
| 224 }; | 269 }; |
| 225 | 270 |
| 226 } // namespace media | 271 } // namespace media |
| 227 | 272 |
| 228 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ | 273 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ |
| OLD | NEW |