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/time.h" | 18 #include "base/time.h" |
19 #include "media/base/media_export.h" | 19 #include "media/base/media_export.h" |
20 #include "media/video/capture/video_capture_types.h" | 20 #include "media/video/capture/video_capture_types.h" |
21 #include "media/video/video_encode_types.h" | |
21 | 22 |
22 namespace media { | 23 namespace media { |
23 | 24 |
25 class EncodedBitstreamBuffer; | |
26 | |
24 class MEDIA_EXPORT VideoCaptureDevice { | 27 class MEDIA_EXPORT VideoCaptureDevice { |
25 public: | 28 public: |
26 | 29 |
27 struct Name { | 30 struct Name { |
28 // Friendly name of a device | 31 // Friendly name of a device |
29 std::string device_name; | 32 std::string device_name; |
30 | 33 |
31 // Unique name of a device. Even if there are multiple devices with the same | 34 // Unique name of a device. Even if there are multiple devices with the same |
32 // friendly name connected to the computer this will be unique. | 35 // friendly name connected to the computer this will be unique. |
33 std::string unique_id; | 36 std::string unique_id; |
34 }; | 37 }; |
35 typedef std::list<Name> Names; | 38 typedef std::list<Name> Names; |
36 | 39 |
37 class MEDIA_EXPORT EventHandler { | 40 class MEDIA_EXPORT EventHandler { |
38 public: | 41 public: |
39 | 42 |
40 // Reserve an output buffer into which a video frame can be captured | 43 // Reserve an output VideoFrame into which a video frame can be captured |
41 // directly. If all buffers are currently busy, returns NULL. | 44 // directly. If all buffers are currently busy, returns NULL. |
42 // | 45 // |
43 // The returned VideoFrames will always be allocated with a YV12 format. The | 46 // The returned VideoFrames will always be allocated with a YV12 format. The |
44 // size will match that specified by an earlier call to OnFrameInfo. It is | 47 // size will match that specified by an earlier call to OnFrameInfo. It is |
45 // the VideoCaptureDevice's responsibility to obey whatever stride and | 48 // the VideoCaptureDevice's responsibility to obey whatever stride and |
46 // memory layout are indicated on the returned VideoFrame object. | 49 // memory layout are indicated on the returned VideoFrame object. |
47 // | 50 // |
48 // The output buffer stays reserved for use by the calling | 51 // The output frame stays reserved for use by the calling |
49 // VideoCaptureDevice until either the last reference to the VideoFrame is | 52 // VideoCaptureDevice until either the last reference to the VideoFrame is |
50 // released, or until the buffer is passed back to the EventHandler's | 53 // released, or until the frame is passed back to the EventHandler's |
51 // OnIncomingCapturedFrame() method. | 54 // OnIncomingCapturedFrame() method. |
52 // | 55 // |
53 // Threading note: After VideoCaptureDevice::DeAllocate() occurs, the | 56 // Threading note: After VideoCaptureDevice::DeAllocate() occurs, the |
54 // VideoCaptureDevice is not permitted to make any additional calls through | 57 // VideoCaptureDevice is not permitted to make any additional calls through |
55 // its EventHandler. However, any VideoFrames returned from the EventHandler | 58 // its EventHandler. However, any VideoFrames returned from the EventHandler |
56 // DO remain valid after DeAllocate(). The VideoCaptureDevice must still | 59 // DO remain valid after DeAllocate(). The VideoCaptureDevice must still |
57 // eventually release them, but it may do so later -- e.g., after a queued | 60 // eventually release them, but it may do so later -- e.g., after a queued |
58 // capture operation completes. | 61 // capture operation completes. |
59 virtual scoped_refptr<media::VideoFrame> ReserveOutputBuffer() = 0; | 62 virtual scoped_refptr<media::VideoFrame> ReserveOutputVideoFrame() = 0; |
63 | |
64 // Reserve an output EncodedBitstreamBuffer into which an encoded video | |
65 // frame can be captured directly. If all buffers are currently busy, | |
66 // returns NULL. Semantics for reservation and threading are same as with | |
67 // ReserveOutputVideoFrame(). | |
Ami GONE FROM CHROMIUM
2013/06/18 18:35:55
TODO to drop this & point to EVS->VEA crbug?
sheu
2013/08/22 22:40:31
Done.
| |
68 virtual scoped_refptr<media::EncodedBitstreamBuffer> | |
69 ReserveOutputEncodedBitstreamBuffer() = 0; | |
60 | 70 |
61 // Captured a new video frame as a raw buffer. The size, color format, and | 71 // Captured a new video frame as a raw buffer. The size, color format, and |
62 // layout are taken from the parameters specified by an earlier call to | 72 // layout are taken from the parameters specified by an earlier call to |
63 // OnFrameInfo(). |data| must be packed, with no padding between rows and/or | 73 // OnFrameInfo(). |data| must be packed, with no padding between rows and/or |
64 // color planes. | 74 // color planes. |
65 // | 75 // |
66 // This method will try to reserve an output buffer and copy from |data| | 76 // This method will try to reserve an output buffer and copy from |data| |
67 // into the output buffer. If no output buffer is available, the frame will | 77 // into the output buffer. If no output buffer is available, the frame will |
68 // be silently dropped. | 78 // be silently dropped. |
69 virtual void OnIncomingCapturedFrame(const uint8* data, | 79 virtual void OnIncomingCapturedFrame(const uint8* data, |
(...skipping 15 matching lines...) Expand all Loading... | |
85 // | 95 // |
86 // If |frame| was NOT created via ReserveOutputBuffer(), then this method | 96 // If |frame| was NOT created via ReserveOutputBuffer(), then this method |
87 // will try to reserve an output buffer and copy from |frame| into the | 97 // will try to reserve an output buffer and copy from |frame| into the |
88 // output buffer. If no output buffer is available, the frame will be | 98 // output buffer. If no output buffer is available, the frame will be |
89 // silently dropped. |frame| must be allocated as RGB32, YV12 or I420, and | 99 // silently dropped. |frame| must be allocated as RGB32, YV12 or I420, and |
90 // the size must match that specified by an earlier call to OnFrameInfo(). | 100 // the size must match that specified by an earlier call to OnFrameInfo(). |
91 virtual void OnIncomingCapturedVideoFrame( | 101 virtual void OnIncomingCapturedVideoFrame( |
92 const scoped_refptr<media::VideoFrame>& frame, | 102 const scoped_refptr<media::VideoFrame>& frame, |
93 base::Time timestamp) = 0; | 103 base::Time timestamp) = 0; |
94 | 104 |
105 virtual void OnIncomingCapturedEncodedBitstreamBuffer( | |
106 const scoped_refptr<media::EncodedBitstreamBuffer>& buffer, | |
107 size_t data_size, | |
108 base::Time timestamp) = 0; | |
109 | |
95 // An error has occurred that cannot be handled and VideoCaptureDevice must | 110 // An error has occurred that cannot be handled and VideoCaptureDevice must |
96 // be DeAllocate()-ed. | 111 // be DeAllocate()-ed. |
97 virtual void OnError() = 0; | 112 virtual void OnError() = 0; |
98 | 113 |
99 // Called when VideoCaptureDevice::Allocate() has been called to inform of | 114 // Called when VideoCaptureDevice::Allocate() has been called to inform of |
100 // the resulting frame size. | 115 // the resulting frame size, for unencoded capture. |
101 virtual void OnFrameInfo(const VideoCaptureCapability& info) = 0; | 116 virtual void OnFrameInfo(const VideoCaptureCapability& info) = 0; |
102 | 117 |
118 // As above, but for encoded capture. | |
119 virtual void OnEncodedFrameInfo( | |
120 const media::VideoEncodingParameters& info) = 0; | |
121 | |
122 // Called when the EncodedVideoBitstream's encoding parameters has changed | |
123 // during runtime, to inform client of new parameters. Valid only for | |
124 // capture devices exporting an EncodedVideoBitstream. | |
125 virtual void OnBitstreamConfigChanged( | |
126 const media::RuntimeVideoEncodingParameters& parameters) = 0; | |
127 | |
103 protected: | 128 protected: |
104 virtual ~EventHandler() {} | 129 virtual ~EventHandler() {} |
105 }; | 130 }; |
106 // Creates a VideoCaptureDevice object. | 131 // Creates a VideoCaptureDevice object. |
107 // Return NULL if the hardware is not available. | 132 // Return NULL if the hardware is not available. |
108 static VideoCaptureDevice* Create(const Name& device_name); | 133 static VideoCaptureDevice* Create(const Name& device_name); |
109 virtual ~VideoCaptureDevice() {} | 134 virtual ~VideoCaptureDevice() {} |
110 | 135 |
111 // Gets the names of all video capture devices connected to this computer. | 136 // Gets the names of all video capture devices connected to this computer. |
112 static void GetDeviceNames(Names* device_names); | 137 static void GetDeviceNames(Names* device_names); |
113 | 138 |
139 // Gets the encoding capablities of this capture device, if any. | |
140 virtual media::VideoEncodingCapabilities GetEncodingCapabilities() = 0; | |
141 | |
142 // Attempts to configure the encoded bitstream output of this device, if any. | |
143 virtual void TryConfigureEncodedBitstream( | |
144 const media::RuntimeVideoEncodingParameters& params) = 0; | |
Ami GONE FROM CHROMIUM
2013/06/18 18:35:55
I think the majority of files & lines in this CL w
sheu
2013/08/22 22:40:31
I thought we tried to keep interfaces pure virtual
| |
145 | |
114 // Prepare the camera for use. After this function has been called no other | 146 // Prepare the camera for use. After this function has been called no other |
115 // applications can use the camera. On completion EventHandler::OnFrameInfo() | 147 // applications can use the camera. On completion EventHandler::OnFrameInfo() |
116 // is called informing of the resulting resolution and frame rate. | 148 // is called informing of the resulting resolution and frame rate. |
117 // DeAllocate() must be called before this function can be called again and | 149 // DeAllocate() must be called before this function can be called again and |
118 // before the object is deleted. | 150 // before the object is deleted. |
119 virtual void Allocate(int width, | 151 virtual void Allocate(int width, |
120 int height, | 152 int height, |
121 int frame_rate, | 153 int frame_rate, |
122 EventHandler* observer) = 0; | 154 EventHandler* observer) = 0; |
123 | 155 |
124 // Start capturing video frames. Allocate must be called before this function. | 156 // Start capturing video frames. Allocate must be called before this function. |
125 virtual void Start() = 0; | 157 virtual void Start() = 0; |
126 | 158 |
127 // Stop capturing video frames. | 159 // Stop capturing video frames. |
128 virtual void Stop() = 0; | 160 virtual void Stop() = 0; |
129 | 161 |
130 // Deallocates the camera. This means other applications can use it. After | 162 // Deallocates the camera. This means other applications can use it. After |
131 // this function has been called the capture device is reset to the state it | 163 // this function has been called the capture device is reset to the state it |
132 // was when created. After DeAllocate() is called, the VideoCaptureDevice is | 164 // was when created. After DeAllocate() is called, the VideoCaptureDevice is |
133 // not permitted to make any additional calls to its EventHandler. | 165 // not permitted to make any additional calls to its EventHandler. |
134 virtual void DeAllocate() = 0; | 166 virtual void DeAllocate() = 0; |
135 | 167 |
136 // Get the name of the capture device. | 168 // Get the name of the capture device. |
137 virtual const Name& device_name() = 0; | 169 virtual const Name& device_name() = 0; |
138 }; | 170 }; |
139 | 171 |
140 } // namespace media | 172 } // namespace media |
141 | 173 |
142 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ | 174 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ |
OLD | NEW |