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 23 matching lines...) Expand all Loading... |
34 // VideoCaptureDevice::GetDeviceNames to do this for you and if you need to | 34 // VideoCaptureDevice::GetDeviceNames to do this for you and if you need to |
35 // cache your own copy of a name, you can do so via the copy constructor. | 35 // cache your own copy of a name, you can do so via the copy constructor. |
36 // The reason for this is that a device name might contain platform specific | 36 // The reason for this is that a device name might contain platform specific |
37 // settings that are relevant only to the platform specific implementation of | 37 // settings that are relevant only to the platform specific implementation of |
38 // VideoCaptureDevice::Create. | 38 // VideoCaptureDevice::Create. |
39 class MEDIA_EXPORT Name { | 39 class MEDIA_EXPORT Name { |
40 public: | 40 public: |
41 Name(); | 41 Name(); |
42 Name(const std::string& name, const std::string& id); | 42 Name(const std::string& name, const std::string& id); |
43 | 43 |
44 #if defined(OS_WIN) | 44 #if defined(OS_LINUX) |
| 45 // Linux/CrOS targets Capture Api type: it can only be set on construction. |
| 46 enum CaptureApiType { |
| 47 V4L2_SINGLE_PLANE, |
| 48 V4L2_MULTI_PLANE, |
| 49 API_TYPE_UNKNOWN |
| 50 }; |
| 51 #elif defined(OS_WIN) |
45 // Windows targets Capture Api type: it can only be set on construction. | 52 // Windows targets Capture Api type: it can only be set on construction. |
46 enum CaptureApiType { | 53 enum CaptureApiType { |
47 MEDIA_FOUNDATION, | 54 MEDIA_FOUNDATION, |
48 DIRECT_SHOW, | 55 DIRECT_SHOW, |
49 DIRECT_SHOW_WDM_CROSSBAR, | 56 DIRECT_SHOW_WDM_CROSSBAR, |
50 API_TYPE_UNKNOWN | 57 API_TYPE_UNKNOWN |
51 }; | 58 }; |
52 #endif | 59 #elif defined(OS_MACOSX) |
53 #if defined(OS_MACOSX) | |
54 // Mac targets Capture Api type: it can only be set on construction. | 60 // Mac targets Capture Api type: it can only be set on construction. |
55 enum CaptureApiType { | 61 enum CaptureApiType { |
56 AVFOUNDATION, | 62 AVFOUNDATION, |
57 QTKIT, | 63 QTKIT, |
58 DECKLINK, | 64 DECKLINK, |
59 API_TYPE_UNKNOWN | 65 API_TYPE_UNKNOWN |
60 }; | 66 }; |
61 // For AVFoundation Api, identify devices that are built-in or USB. | 67 // For AVFoundation Api, identify devices that are built-in or USB. |
62 enum TransportType { | 68 enum TransportType { |
63 USB_OR_BUILT_IN, | 69 USB_OR_BUILT_IN, |
64 OTHER_TRANSPORT | 70 OTHER_TRANSPORT |
65 }; | 71 }; |
66 #endif | 72 #endif |
67 #if defined(OS_WIN) || defined(OS_MACOSX) | 73 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
68 Name(const std::string& name, | 74 Name(const std::string& name, |
69 const std::string& id, | 75 const std::string& id, |
70 const CaptureApiType api_type); | 76 const CaptureApiType api_type); |
71 #endif | 77 #endif |
72 #if defined(OS_MACOSX) | 78 #if defined(OS_MACOSX) |
73 Name(const std::string& name, | 79 Name(const std::string& name, |
74 const std::string& id, | 80 const std::string& id, |
75 const CaptureApiType api_type, | 81 const CaptureApiType api_type, |
76 const TransportType transport_type); | 82 const TransportType transport_type); |
77 #endif | 83 #endif |
(...skipping 17 matching lines...) Expand all Loading... |
95 // These operators are needed due to storing the name in an STL container. | 101 // These operators are needed due to storing the name in an STL container. |
96 // In the shared build, all methods from the STL container will be exported | 102 // In the shared build, all methods from the STL container will be exported |
97 // so even though they're not used, they're still depended upon. | 103 // so even though they're not used, they're still depended upon. |
98 bool operator==(const Name& other) const { | 104 bool operator==(const Name& other) const { |
99 return other.id() == unique_id_; | 105 return other.id() == unique_id_; |
100 } | 106 } |
101 bool operator<(const Name& other) const { | 107 bool operator<(const Name& other) const { |
102 return unique_id_ < other.id(); | 108 return unique_id_ < other.id(); |
103 } | 109 } |
104 | 110 |
105 #if defined(OS_WIN) || defined(OS_MACOSX) | 111 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
106 CaptureApiType capture_api_type() const { | 112 CaptureApiType capture_api_type() const { |
107 return capture_api_class_.capture_api_type(); | 113 return capture_api_class_.capture_api_type(); |
108 } | 114 } |
109 const char* GetCaptureApiTypeString() const; | 115 const char* GetCaptureApiTypeString() const; |
110 #endif | 116 #endif |
111 #if defined(OS_WIN) | 117 #if defined(OS_WIN) |
112 // Certain devices need an ID different from the |unique_id_| for | 118 // Certain devices need an ID different from the |unique_id_| for |
113 // capabilities retrieval. | 119 // capabilities retrieval. |
114 const std::string& capabilities_id() const { | 120 const std::string& capabilities_id() const { |
115 return capabilities_id_; | 121 return capabilities_id_; |
(...skipping 10 matching lines...) Expand all Loading... |
126 return is_blacklisted_; | 132 return is_blacklisted_; |
127 } | 133 } |
128 void set_is_blacklisted(bool is_blacklisted) { | 134 void set_is_blacklisted(bool is_blacklisted) { |
129 is_blacklisted_ = is_blacklisted; | 135 is_blacklisted_ = is_blacklisted; |
130 } | 136 } |
131 #endif // if defined(OS_WIN) | 137 #endif // if defined(OS_WIN) |
132 | 138 |
133 private: | 139 private: |
134 std::string device_name_; | 140 std::string device_name_; |
135 std::string unique_id_; | 141 std::string unique_id_; |
136 #if defined(OS_WIN) || defined(OS_MACOSX) | 142 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
137 // This class wraps the CaptureApiType to give it a by default value if not | 143 // This class wraps the CaptureApiType to give it a by default value if not |
138 // initialized. | 144 // initialized. |
139 class CaptureApiClass { | 145 class CaptureApiClass { |
140 public: | 146 public: |
141 CaptureApiClass(): capture_api_type_(API_TYPE_UNKNOWN) {} | 147 CaptureApiClass(): capture_api_type_(API_TYPE_UNKNOWN) {} |
142 CaptureApiClass(const CaptureApiType api_type) | 148 CaptureApiClass(const CaptureApiType api_type) |
143 : capture_api_type_(api_type) {} | 149 : capture_api_type_(api_type) {} |
144 CaptureApiType capture_api_type() const { | 150 CaptureApiType capture_api_type() const { |
145 DCHECK_NE(capture_api_type_, API_TYPE_UNKNOWN); | 151 DCHECK_NE(capture_api_type_, API_TYPE_UNKNOWN); |
146 return capture_api_type_; | 152 return capture_api_type_; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 194 |
189 // Captured a new video frame, data for which is pointed to by |data|. | 195 // Captured a new video frame, data for which is pointed to by |data|. |
190 // | 196 // |
191 // The format of the frame is described by |frame_format|, and is assumed to | 197 // The format of the frame is described by |frame_format|, and is assumed to |
192 // be tightly packed. This method will try to reserve an output buffer and | 198 // be tightly packed. This method will try to reserve an output buffer and |
193 // copy from |data| into the output buffer. If no output buffer is | 199 // copy from |data| into the output buffer. If no output buffer is |
194 // available, the frame will be silently dropped. | 200 // available, the frame will be silently dropped. |
195 virtual void OnIncomingCapturedData(const uint8* data, | 201 virtual void OnIncomingCapturedData(const uint8* data, |
196 int length, | 202 int length, |
197 const VideoCaptureFormat& frame_format, | 203 const VideoCaptureFormat& frame_format, |
198 int rotation, // Clockwise. | 204 int clockwise_rotation, |
199 const base::TimeTicks& timestamp) = 0; | 205 const base::TimeTicks& timestamp) = 0; |
200 | 206 |
| 207 // Captured a 3 planar YUV frame. Planes are possibly disjoint. |
| 208 // |frame_format| must indicate I420. |
| 209 virtual void OnIncomingCapturedYuvData( |
| 210 const uint8* y_data, |
| 211 const uint8* u_data, |
| 212 const uint8* v_data, |
| 213 size_t y_stride, |
| 214 size_t u_stride, |
| 215 size_t v_stride, |
| 216 const VideoCaptureFormat& frame_format, |
| 217 int clockwise_rotation, |
| 218 const base::TimeTicks& timestamp) = 0; |
| 219 |
201 // Reserve an output buffer into which contents can be captured directly. | 220 // Reserve an output buffer into which contents can be captured directly. |
202 // The returned Buffer will always be allocated with a memory size suitable | 221 // The returned Buffer will always be allocated with a memory size suitable |
203 // for holding a packed video frame with pixels of |format| format, of | 222 // for holding a packed video frame with pixels of |format| format, of |
204 // |dimensions| frame dimensions. It is permissible for |dimensions| to be | 223 // |dimensions| frame dimensions. It is permissible for |dimensions| to be |
205 // zero; in which case the returned Buffer does not guarantee memory | 224 // zero; in which case the returned Buffer does not guarantee memory |
206 // backing, but functions as a reservation for external input for the | 225 // backing, but functions as a reservation for external input for the |
207 // purposes of buffer throttling. | 226 // purposes of buffer throttling. |
208 // | 227 // |
209 // The output buffer stays reserved for use until the Buffer object is | 228 // The output buffer stays reserved for use until the Buffer object is |
210 // destroyed. | 229 // destroyed. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 int GetPowerLineFrequencyForLocation() const; | 275 int GetPowerLineFrequencyForLocation() const; |
257 | 276 |
258 protected: | 277 protected: |
259 static const int kPowerLine50Hz = 50; | 278 static const int kPowerLine50Hz = 50; |
260 static const int kPowerLine60Hz = 60; | 279 static const int kPowerLine60Hz = 60; |
261 }; | 280 }; |
262 | 281 |
263 } // namespace media | 282 } // namespace media |
264 | 283 |
265 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ | 284 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ |
OLD | NEW |