Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: media/video/capture/video_capture_device.h

Issue 48113011: Remove media::VideoFrame from media::VideoCaptureDevice::Client interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: ffdbaeb83 Trybot failures. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 int id() const { return id_; }
129 void* data() const { return data_; }
130 size_t size() const { return size_; }
131
132 protected:
133 friend class base::RefCountedThreadSafe<Buffer>;
134
135 Buffer(int id, void* data, size_t size)
136 : id_(id), data_(data), size_(size) {}
137 virtual ~Buffer() {}
138
139 const int id_;
140 void* const data_;
141 const size_t size_;
142 };
143
123 virtual ~Client() {} 144 virtual ~Client() {}
124 145
125 // Reserve an output buffer into which a video frame can be captured 146 // Reserve an output buffer into which contents can be captured directly.
126 // directly. If all buffers are currently busy, returns NULL. 147 // The returned Buffer will always be allocated with a memory size suitable
148 // for holding a packed video frame of |format| format, of |dimensions|
149 // dimensions. It is permissible for |dimensions| to be zero; in which
150 // case the returned Buffer does not guarantee memory backing, but functions
151 // as a reservation for external input for the purposes of buffer
152 // throttling.
127 // 153 //
128 // The returned VideoFrames will always be allocated with a YV12 format and 154 // The output buffer stays reserved for use until the Buffer object is
129 // have dimensions matching |size|. It is the VideoCaptureDevice's 155 // destroyed.
130 // responsibility to obey whatever stride and memory layout are indicated on 156 virtual scoped_refptr<Buffer> ReserveOutputBuffer(
131 // the returned VideoFrame object. 157 media::VideoFrame::Format format,
132 // 158 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 159
140 // Captured a new video frame as a raw buffer. The size, color format, and 160 // 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 161 // 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 162 // OnFrameInfo(). |data| must be packed, with no padding between rows and/or
143 // color planes. 163 // color planes.
144 // 164 //
145 // This method will try to reserve an output buffer and copy from |data| 165 // 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 166 // into the output buffer. If no output buffer is available, the frame will
147 // be silently dropped. 167 // be silently dropped.
148 virtual void OnIncomingCapturedFrame( 168 virtual void OnIncomingCapturedFrame(
149 const uint8* data, 169 const uint8* data,
150 int length, 170 int length,
151 base::Time timestamp, 171 base::Time timestamp,
152 int rotation, // Clockwise. 172 int rotation, // Clockwise.
153 bool flip_vert, 173 bool flip_vert,
154 bool flip_horiz, 174 bool flip_horiz,
155 const VideoCaptureCapability& frame_info) = 0; 175 const VideoCaptureCapability& frame_info) = 0;
156 176
157 // Captured a new video frame, held in a VideoFrame container. 177 // Captured a new video frame, held in |buffer|.
158 // 178 //
159 // If |frame| was created via the ReserveOutputBuffer() mechanism, then the 179 // As the frame is backed by a reservation returned by
160 // frame delivery is guaranteed (it will not be silently dropped), and 180 // ReserveOutputBuffer(), delivery is guaranteed and will require no
161 // delivery will require no additional copies in the browser process. For 181 // additional copies in the browser process. |dimensions| indicates the
162 // such frames, the VideoCaptureDevice's reservation on the output buffer 182 // frame width and height of the buffer contents; this is assumed to be of
163 // ends immediately. The VideoCaptureDevice may not read or write the 183 // |format| format and tightly packed.
164 // underlying memory afterwards, and it should release its references to 184 virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer,
165 // |frame| as soon as possible, to allow buffer reuse. 185 media::VideoFrame::Format format,
166 // 186 const gfx::Size& dimensions,
167 // If |frame| was NOT created via ReserveOutputBuffer(), then this method 187 base::Time timestamp,
168 // will try to reserve an output buffer and copy from |frame| into the 188 int frame_rate) = 0;
169 // output buffer. If no output buffer is available, the frame will be
170 // silently dropped. |frame| must be allocated as RGB32, YV12 or I420, and
171 // the size must match that specified by an earlier call to OnFrameInfo().
172 virtual void OnIncomingCapturedVideoFrame(
173 const scoped_refptr<media::VideoFrame>& frame,
174 base::Time timestamp,
175 int frame_rate) = 0;
176 189
177 // An error has occurred that cannot be handled and VideoCaptureDevice must 190 // An error has occurred that cannot be handled and VideoCaptureDevice must
178 // be StopAndDeAllocate()-ed. 191 // be StopAndDeAllocate()-ed.
179 virtual void OnError() = 0; 192 virtual void OnError() = 0;
180 }; 193 };
181 194
182 // Creates a VideoCaptureDevice object. 195 // Creates a VideoCaptureDevice object.
183 // Return NULL if the hardware is not available. 196 // Return NULL if the hardware is not available.
184 static VideoCaptureDevice* Create(const Name& device_name); 197 static VideoCaptureDevice* Create(const Name& device_name);
185 virtual ~VideoCaptureDevice(); 198 virtual ~VideoCaptureDevice();
(...skipping 26 matching lines...) Expand all
212 // If deallocation is done asynchronously, then the device implementation must 225 // If deallocation is done asynchronously, then the device implementation must
213 // ensure that a subsequent AllocateAndStart() operation targeting the same ID 226 // ensure that a subsequent AllocateAndStart() operation targeting the same ID
214 // would be sequenced through the same task runner, so that deallocation 227 // would be sequenced through the same task runner, so that deallocation
215 // happens first. 228 // happens first.
216 virtual void StopAndDeAllocate() = 0; 229 virtual void StopAndDeAllocate() = 0;
217 }; 230 };
218 231
219 } // namespace media 232 } // namespace media
220 233
221 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ 234 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_
OLDNEW
« no previous file with comments | « media/video/capture/linux/video_capture_device_linux.cc ('k') | media/video/capture/video_capture_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698