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

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

Issue 24133002: Make VideoCaptureController single-threaded and not ref counted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix a memory leak Created 7 years, 3 months 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 | Annotate | Revision Log
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.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // be DeAllocate()-ed. 181 // be DeAllocate()-ed.
181 virtual void OnError() = 0; 182 virtual void OnError() = 0;
182 183
183 // Called when VideoCaptureDevice::Allocate() has been called to inform of 184 // Called when VideoCaptureDevice::Allocate() has been called to inform of
184 // the resulting frame size. 185 // the resulting frame size.
185 virtual void OnFrameInfo(const VideoCaptureCapability& info) = 0; 186 virtual void OnFrameInfo(const VideoCaptureCapability& info) = 0;
186 187
187 // Called when the native resolution of VideoCaptureDevice has been changed 188 // Called when the native resolution of VideoCaptureDevice has been changed
188 // and it needs to inform its client of the new frame size. 189 // and it needs to inform its client of the new frame size.
189 virtual void OnFrameInfoChanged(const VideoCaptureCapability& info) {}; 190 virtual void OnFrameInfoChanged(const VideoCaptureCapability& info) {};
190
191 protected:
192 virtual ~EventHandler() {}
193 }; 191 };
194 // Creates a VideoCaptureDevice object. 192 // Creates a VideoCaptureDevice object.
195 // Return NULL if the hardware is not available. 193 // Return NULL if the hardware is not available.
196 static VideoCaptureDevice* Create(const Name& device_name); 194 static VideoCaptureDevice* Create(const Name& device_name);
197 virtual ~VideoCaptureDevice() {} 195 virtual ~VideoCaptureDevice();
198 196
199 // Gets the names of all video capture devices connected to this computer. 197 // Gets the names of all video capture devices connected to this computer.
200 static void GetDeviceNames(Names* device_names); 198 static void GetDeviceNames(Names* device_names);
201 199
202 // Prepare the camera for use. After this function has been called no other 200 // Prepare the camera for use. After this function has been called no other
203 // applications can use the camera. On completion EventHandler::OnFrameInfo() 201 // applications can use the camera. On completion EventHandler::OnFrameInfo()
204 // is called informing of the resulting resolution and frame rate. 202 // is called informing of the resulting resolution and frame rate.
203 // StopAndDeAllocate() must be called before the object is deleted.
204 virtual void AllocateAndStart(
205 const VideoCaptureCapability& capture_format,
206 scoped_ptr<EventHandler> observer) = 0;
207
208 // Deallocates the camera. This means other applications can use it, and that
209 // the camera could be re-acquired by another VideoCaptureDevice instance if
210 // one were to be created immediately after this call. After this call the
211 // device should free the |observer| passed into AllocateAndStart as soon as
212 // possible, but may do so asynchronously.
213 virtual void StopAndDeAllocate() = 0;
214 };
215
216 // VideoCaptureDevice1 is a bridge to an older API against which
217 // VideoCaptureDevices were implemented. Differences between VideoCaptureDevice
218 // (new style) and VideoCaptureDevice1 (old style) are as follows:
219 //
220 // [1] The Stop+DeAllocate calls are merged in the new style.
221 // [2] The Allocate+Start calls are merged in the new style.
222 // [3] New style devices own their EventHandler* pointers, allowing handlers
223 // remain valid even after the device is stopped. Whereas old style devices
Ami GONE FROM CHROMIUM 2013/09/13 21:17:59 s/remain/to remain/
ncarter (slow) 2013/09/14 00:07:24 Done.
224 // may not dereference their handlers after DeAllocate().
Ami GONE FROM CHROMIUM 2013/09/13 21:17:59 I don't follow. AFAICT from the commentary above
ncarter (slow) 2013/09/14 00:07:24 I think I figured out what was missing. I made the
225 // [4] device_name() is eliminated from the new-style interface.
226 //
227 // TODO(nick): Remove this bridge class. It exists to enable incremental
228 // migration to an alternative VideoCaptureDevice API.
229 class MEDIA_EXPORT VideoCaptureDevice1 : public VideoCaptureDevice {
230 public:
231 VideoCaptureDevice1();
232 virtual ~VideoCaptureDevice1();
233
234 // VideoCaptureDevice implementation.
235 virtual void AllocateAndStart(
236 const VideoCaptureCapability& capture_format,
237 scoped_ptr<EventHandler> client) OVERRIDE;
238 virtual void StopAndDeAllocate() OVERRIDE;
239
240 // Gets the names of all video capture devices
Ami GONE FROM CHROMIUM 2013/09/13 21:17:59 stray?
ncarter (slow) 2013/09/14 00:07:24 Done.
241 // Prepare the camera for use. After this function has been called no other
242 // applications can use the camera. On completion EventHandler::OnFrameInfo()
243 // is called informing of the resulting resolution and frame rate.
205 // DeAllocate() must be called before this function can be called again and 244 // DeAllocate() must be called before this function can be called again and
206 // before the object is deleted. 245 // before the object is deleted.
207 virtual void Allocate(const VideoCaptureCapability& capture_format, 246 virtual void Allocate(const VideoCaptureCapability& capture_format,
208 EventHandler* observer) = 0; 247 EventHandler* client) = 0;
209 248
210 // Start capturing video frames. Allocate must be called before this function. 249 // Start capturing video frames. Allocate must be called before this function.
211 virtual void Start() = 0; 250 virtual void Start() = 0;
212 251
213 // Stop capturing video frames. 252 // Stop capturing video frames.
214 virtual void Stop() = 0; 253 virtual void Stop() = 0;
215 254
216 // Deallocates the camera. This means other applications can use it. After 255 // 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 256 // 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 257 // was when created. After DeAllocate() is called, the VideoCaptureDevice is
219 // not permitted to make any additional calls to its EventHandler. 258 // not permitted to make any additional calls to its EventHandler.
220 virtual void DeAllocate() = 0; 259 virtual void DeAllocate() = 0;
221 260
222 // Get the name of the capture device. 261 // Get the name of the capture device.
223 virtual const Name& device_name() = 0; 262 virtual const Name& device_name() = 0;
263
264 private:
265 // The device client which proxies device events to the controller.
266 scoped_ptr<EventHandler> client_;
Ami GONE FROM CHROMIUM 2013/09/13 21:17:59 This thing is known as a "Handler" (by the type),
ncarter (slow) 2013/09/14 00:07:24 "Client" is right term and it might have been a mi
224 }; 267 };
225 268
226 } // namespace media 269 } // namespace media
227 270
228 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ 271 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698