| 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. |
| 11 | 11 |
| 12 #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ | 12 #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ |
| 13 #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ | 13 #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ |
| 14 | 14 |
| 15 #include <list> | 15 #include <list> |
| 16 #include <string> | 16 #include <string> |
| 17 | 17 |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 20 #include "media/base/media_export.h" | 22 #include "media/base/media_export.h" |
| 21 #include "media/video/capture/video_capture_types.h" | 23 #include "media/video/capture/video_capture_types.h" |
| 22 | 24 |
| 23 namespace media { | 25 namespace media { |
| 24 | 26 |
| 25 class MEDIA_EXPORT VideoCaptureDevice { | 27 class MEDIA_EXPORT VideoCaptureDevice { |
| 26 public: | 28 public: |
| 27 // Represents a capture device name and ID. | 29 // Represents a capture device name and ID. |
| 28 // You should not create an instance of this class directly by e.g. setting | 30 // You should not create an instance of this class directly by e.g. setting |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 : public NON_EXPORTED_BASE(std::list<Name>) { | 115 : public NON_EXPORTED_BASE(std::list<Name>) { |
| 114 public: | 116 public: |
| 115 // Returns NULL if no entry was found by that ID. | 117 // Returns NULL if no entry was found by that ID. |
| 116 Name* FindById(const std::string& id); | 118 Name* FindById(const std::string& id); |
| 117 | 119 |
| 118 // Allow generated copy constructor and assignment. | 120 // Allow generated copy constructor and assignment. |
| 119 }; | 121 }; |
| 120 | 122 |
| 121 class MEDIA_EXPORT Client { | 123 class MEDIA_EXPORT Client { |
| 122 public: | 124 public: |
| 125 // Memory buffer returned by Client::ReserveOutputBuffer(). |
| 126 class Buffer : public base::RefCountedThreadSafe<Buffer> { |
| 127 public: |
| 128 void* data() const { return data_; } |
| 129 size_t size() const { return size_; } |
| 130 |
| 131 protected: |
| 132 friend class base::RefCountedThreadSafe<Buffer>; |
| 133 |
| 134 Buffer(void* data, size_t size) : data_(data), size_(size) {} |
| 135 virtual ~Buffer() {} |
| 136 |
| 137 void* const data_; |
| 138 const size_t size_; |
| 139 }; |
| 140 |
| 123 virtual ~Client() {} | 141 virtual ~Client() {} |
| 124 | 142 |
| 125 // Reserve an output buffer into which a video frame can be captured | 143 // Reserve an output buffer into which contents can be captured directly. |
| 126 // directly. If all buffers are currently busy, returns NULL. | 144 // The returned Buffer will always be allocated with a memory size suitable |
| 145 // for holding a packed video frame of |format| format, of |dimensions| |
| 146 // dimensions. It is permissible for |dimensions| to be zero; in which |
| 147 // case the returned Buffer does not guarantee memory backing, but functions |
| 148 // as a reservation for external input for the purposes of buffer |
| 149 // throttling. |
| 127 // | 150 // |
| 128 // The returned VideoFrames will always be allocated with a YV12 format and | 151 // The output buffer stays reserved for use until the Buffer object is |
| 129 // have dimensions matching |size|. It is the VideoCaptureDevice's | 152 // destroyed. |
| 130 // responsibility to obey whatever stride and memory layout are indicated on | 153 virtual scoped_refptr<Buffer> ReserveOutputBuffer( |
| 131 // the returned VideoFrame object. | 154 media::VideoFrame::Format format, |
| 132 // | 155 const gfx::Size& dimensions) = 0; |
| 133 // The output buffer stays reserved for use by the calling | |
| 134 // VideoCaptureDevice until either the last reference to the VideoFrame is | |
| 135 // released, or until the buffer is passed back to the Client's | |
| 136 // OnIncomingCapturedFrame() method. | |
| 137 virtual scoped_refptr<media::VideoFrame> ReserveOutputBuffer( | |
| 138 const gfx::Size& size) = 0; | |
| 139 | 156 |
| 140 // Captured a new video frame as a raw buffer. The size, color format, and | 157 // Captured a new video frame as a raw buffer. The size, color format, and |
| 141 // layout are taken from the parameters specified by an earlier call to | 158 // layout are taken from the parameters specified by an earlier call to |
| 142 // OnFrameInfo(). |data| must be packed, with no padding between rows and/or | 159 // OnFrameInfo(). |data| must be packed, with no padding between rows and/or |
| 143 // color planes. | 160 // color planes. |
| 144 // | 161 // |
| 145 // This method will try to reserve an output buffer and copy from |data| | 162 // This method will try to reserve an output buffer and copy from |data| |
| 146 // into the output buffer. If no output buffer is available, the frame will | 163 // into the output buffer. If no output buffer is available, the frame will |
| 147 // be silently dropped. | 164 // be silently dropped. |
| 148 virtual void OnIncomingCapturedFrame(const uint8* data, | 165 virtual void OnIncomingCapturedFrame(const uint8* data, |
| 149 int length, | 166 int length, |
| 150 base::Time timestamp, | 167 base::Time timestamp, |
| 151 int rotation, // Clockwise. | 168 int rotation, // Clockwise. |
| 152 bool flip_vert, | 169 bool flip_vert, |
| 153 bool flip_horiz) = 0; | 170 bool flip_horiz) = 0; |
| 154 | 171 |
| 155 // Captured a new video frame, held in a VideoFrame container. | 172 // Captured a new video frame, held in |buffer|. |
| 156 // | 173 // |
| 157 // If |frame| was created via the ReserveOutputBuffer() mechanism, then the | 174 // As the frame is backed by a reservation returned by |
| 158 // frame delivery is guaranteed (it will not be silently dropped), and | 175 // ReserveOutputBuffer(), delivery is guaranteed and will require no |
| 159 // delivery will require no additional copies in the browser process. For | 176 // additional copies in the browser process. |dimensions| indicates the |
| 160 // such frames, the VideoCaptureDevice's reservation on the output buffer | 177 // frame width and height of the buffer contents; this is assumed to be of |
| 161 // ends immediately. The VideoCaptureDevice may not read or write the | 178 // |format| format and tightly packed. |
| 162 // underlying memory afterwards, and it should release its references to | 179 virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer, |
| 163 // |frame| as soon as possible, to allow buffer reuse. | 180 media::VideoFrame::Format format, |
| 164 // | 181 const gfx::Size& dimensions, |
| 165 // If |frame| was NOT created via ReserveOutputBuffer(), then this method | 182 base::Time timestamp) = 0; |
| 166 // will try to reserve an output buffer and copy from |frame| into the | |
| 167 // output buffer. If no output buffer is available, the frame will be | |
| 168 // silently dropped. |frame| must be allocated as RGB32, YV12 or I420, and | |
| 169 // the size must match that specified by an earlier call to OnFrameInfo(). | |
| 170 virtual void OnIncomingCapturedVideoFrame( | |
| 171 const scoped_refptr<media::VideoFrame>& frame, | |
| 172 base::Time timestamp) = 0; | |
| 173 | 183 |
| 174 // An error has occurred that cannot be handled and VideoCaptureDevice must | 184 // An error has occurred that cannot be handled and VideoCaptureDevice must |
| 175 // be StopAndDeAllocate()-ed. | 185 // be StopAndDeAllocate()-ed. |
| 176 virtual void OnError() = 0; | 186 virtual void OnError() = 0; |
| 177 | 187 |
| 178 // Called when VideoCaptureDevice::AllocateAndStart() has been called to | 188 // Called when VideoCaptureDevice::AllocateAndStart() has been called to |
| 179 // inform of the resulting frame size. | 189 // inform of the resulting frame size. |
| 180 virtual void OnFrameInfo(const VideoCaptureCapability& info) = 0; | 190 virtual void OnFrameInfo(const VideoCaptureCapability& info) = 0; |
| 181 | 191 |
| 182 // Called when the native resolution of VideoCaptureDevice has been changed | 192 // Called when the native resolution of VideoCaptureDevice has been changed |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 // If deallocation is done asynchronously, then the device implementation must | 226 // If deallocation is done asynchronously, then the device implementation must |
| 217 // ensure that a subsequent AllocateAndStart() operation targeting the same ID | 227 // ensure that a subsequent AllocateAndStart() operation targeting the same ID |
| 218 // would be sequenced through the same task runner, so that deallocation | 228 // would be sequenced through the same task runner, so that deallocation |
| 219 // happens first. | 229 // happens first. |
| 220 virtual void StopAndDeAllocate() = 0; | 230 virtual void StopAndDeAllocate() = 0; |
| 221 }; | 231 }; |
| 222 | 232 |
| 223 } // namespace media | 233 } // namespace media |
| 224 | 234 |
| 225 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ | 235 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ |
| OLD | NEW |