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 12 matching lines...) Expand all Loading... |
23 #include "base/files/file.h" | 23 #include "base/files/file.h" |
24 #include "base/logging.h" | 24 #include "base/logging.h" |
25 #include "base/memory/ref_counted.h" | 25 #include "base/memory/ref_counted.h" |
26 #include "base/single_thread_task_runner.h" | 26 #include "base/single_thread_task_runner.h" |
27 #include "base/time/time.h" | 27 #include "base/time/time.h" |
28 #include "build/build_config.h" | 28 #include "build/build_config.h" |
29 #include "media/base/video_capture_types.h" | 29 #include "media/base/video_capture_types.h" |
30 #include "media/base/video_frame.h" | 30 #include "media/base/video_frame.h" |
31 #include "media/capture/capture_export.h" | 31 #include "media/capture/capture_export.h" |
32 #include "media/capture/video/scoped_result_callback.h" | 32 #include "media/capture/video/scoped_result_callback.h" |
| 33 #include "media/capture/video/video_capture_device_descriptor.h" |
33 #include "media/mojo/interfaces/image_capture.mojom.h" | 34 #include "media/mojo/interfaces/image_capture.mojom.h" |
34 #include "mojo/public/cpp/bindings/array.h" | 35 #include "mojo/public/cpp/bindings/array.h" |
35 #include "ui/gfx/gpu_memory_buffer.h" | 36 #include "ui/gfx/gpu_memory_buffer.h" |
36 | 37 |
37 namespace tracked_objects { | 38 namespace tracked_objects { |
38 class Location; | 39 class Location; |
39 } // namespace tracked_objects | 40 } // namespace tracked_objects |
40 | 41 |
41 namespace media { | 42 namespace media { |
42 | 43 |
43 class CAPTURE_EXPORT VideoCaptureDevice { | 44 class CAPTURE_EXPORT VideoCaptureDevice { |
44 public: | 45 public: |
45 // Represents a capture device name and ID. | |
46 // You should not create an instance of this class directly by e.g. setting | |
47 // various properties directly. Instead use | |
48 // VideoCaptureDevice::GetDeviceNames to do this for you and if you need to | |
49 // cache your own copy of a name, you can do so via the copy constructor. | |
50 // The reason for this is that a device name might contain platform specific | |
51 // settings that are relevant only to the platform specific implementation of | |
52 // VideoCaptureDevice::Create. | |
53 class CAPTURE_EXPORT Name { | |
54 public: | |
55 Name(); | |
56 Name(const std::string& name, const std::string& id); | |
57 | |
58 #if defined(OS_LINUX) | |
59 // Linux/CrOS targets Capture Api type: it can only be set on construction. | |
60 enum CaptureApiType { | |
61 V4L2_SINGLE_PLANE, | |
62 API_TYPE_UNKNOWN | |
63 }; | |
64 #elif defined(OS_WIN) | |
65 // Windows targets Capture Api type: it can only be set on construction. | |
66 enum CaptureApiType { MEDIA_FOUNDATION, DIRECT_SHOW, API_TYPE_UNKNOWN }; | |
67 #elif defined(OS_MACOSX) | |
68 // Mac targets Capture Api type: it can only be set on construction. | |
69 enum CaptureApiType { AVFOUNDATION, DECKLINK, API_TYPE_UNKNOWN }; | |
70 // For AVFoundation Api, identify devices that are built-in or USB. | |
71 enum TransportType { USB_OR_BUILT_IN, OTHER_TRANSPORT }; | |
72 #elif defined(OS_ANDROID) | |
73 // Android targets Capture Api type: it can only be set on construction. | |
74 // Automatically generated enum to interface with Java world. | |
75 // | |
76 // A Java counterpart will be generated for this enum. | |
77 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.media | |
78 enum CaptureApiType { | |
79 API1, | |
80 API2_LEGACY, | |
81 API2_FULL, | |
82 API2_LIMITED, | |
83 TANGO, | |
84 API_TYPE_UNKNOWN | |
85 }; | |
86 #endif | |
87 | |
88 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ | |
89 defined(OS_ANDROID) | |
90 Name(const std::string& name, | |
91 const std::string& id, | |
92 const CaptureApiType api_type); | |
93 #endif | |
94 #if defined(OS_MACOSX) | |
95 Name(const std::string& name, | |
96 const std::string& id, | |
97 const CaptureApiType api_type, | |
98 const TransportType transport_type); | |
99 #endif | |
100 Name(const Name& other); | |
101 ~Name(); | |
102 | |
103 // Friendly name of a device | |
104 const std::string& name() const { return device_name_; } | |
105 | |
106 // Unique name of a device. Even if there are multiple devices with the same | |
107 // friendly name connected to the computer this will be unique. | |
108 const std::string& id() const { return unique_id_; } | |
109 | |
110 // The unique hardware model identifier of the capture device. Returns | |
111 // "[vid]:[pid]" when a USB device is detected, otherwise "". | |
112 // The implementation of this method is platform-dependent. | |
113 const std::string GetModel() const; | |
114 | |
115 // Friendly name of a device, plus the model identifier in parentheses. | |
116 const std::string GetNameAndModel() const; | |
117 | |
118 // These operators are needed due to storing the name in an STL container. | |
119 // In the shared build, all methods from the STL container will be exported | |
120 // so even though they're not used, they're still depended upon. | |
121 bool operator==(const Name& other) const { | |
122 return other.id() == unique_id_; | |
123 } | |
124 bool operator<(const Name& other) const { return unique_id_ < other.id(); } | |
125 | |
126 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ | |
127 defined(OS_ANDROID) | |
128 CaptureApiType capture_api_type() const { | |
129 return capture_api_class_.capture_api_type(); | |
130 } | |
131 const char* GetCaptureApiTypeString() const; | |
132 #endif | |
133 #if defined(OS_WIN) | |
134 // Certain devices need an ID different from the |unique_id_| for | |
135 // capabilities retrieval. | |
136 const std::string& capabilities_id() const { return capabilities_id_; } | |
137 void set_capabilities_id(const std::string& id) { capabilities_id_ = id; } | |
138 #endif // if defined(OS_WIN) | |
139 #if defined(OS_MACOSX) | |
140 TransportType transport_type() const { return transport_type_; } | |
141 #endif // if defined(OS_MACOSX) | |
142 | |
143 private: | |
144 std::string device_name_; | |
145 std::string unique_id_; | |
146 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ | |
147 defined(OS_ANDROID) | |
148 // This class wraps the CaptureApiType to give it a by default value if not | |
149 // initialized. | |
150 class CaptureApiClass { | |
151 public: | |
152 CaptureApiClass() : capture_api_type_(API_TYPE_UNKNOWN) {} | |
153 CaptureApiClass(const CaptureApiType api_type) | |
154 : capture_api_type_(api_type) {} | |
155 CaptureApiType capture_api_type() const { | |
156 DCHECK_NE(capture_api_type_, API_TYPE_UNKNOWN); | |
157 return capture_api_type_; | |
158 } | |
159 | |
160 private: | |
161 CaptureApiType capture_api_type_; | |
162 }; | |
163 | |
164 CaptureApiClass capture_api_class_; | |
165 #endif | |
166 #if defined(OS_WIN) | |
167 // ID used for capabilities retrieval. By default is equal to |unique_id|. | |
168 std::string capabilities_id_; | |
169 #endif | |
170 #if defined(OS_MACOSX) | |
171 TransportType transport_type_; | |
172 #endif | |
173 // Allow generated copy constructor and assignment. | |
174 }; | |
175 | |
176 // Manages a list of Name entries. | |
177 typedef std::list<Name> Names; | |
178 | 46 |
179 // Interface defining the methods that clients of VideoCapture must have. It | 47 // Interface defining the methods that clients of VideoCapture must have. It |
180 // is actually two-in-one: clients may implement OnIncomingCapturedData() or | 48 // is actually two-in-one: clients may implement OnIncomingCapturedData() or |
181 // ReserveOutputBuffer() + OnIncomingCapturedVideoFrame(), or all of them. | 49 // ReserveOutputBuffer() + OnIncomingCapturedVideoFrame(), or all of them. |
182 // All clients must implement OnError(). | 50 // All clients must implement OnError(). |
183 class CAPTURE_EXPORT Client { | 51 class CAPTURE_EXPORT Client { |
184 public: | 52 public: |
185 // Memory buffer returned by Client::ReserveOutputBuffer(). | 53 // Memory buffer returned by Client::ReserveOutputBuffer(). |
186 class CAPTURE_EXPORT Buffer { | 54 class CAPTURE_EXPORT Buffer { |
187 public: | 55 public: |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 204 |
337 private: | 205 private: |
338 // Gets the power line frequency from the current system time zone if this is | 206 // Gets the power line frequency from the current system time zone if this is |
339 // defined, otherwise returns 0. | 207 // defined, otherwise returns 0. |
340 PowerLineFrequency GetPowerLineFrequencyForLocation() const; | 208 PowerLineFrequency GetPowerLineFrequencyForLocation() const; |
341 }; | 209 }; |
342 | 210 |
343 } // namespace media | 211 } // namespace media |
344 | 212 |
345 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_H_ | 213 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_DEVICE_H_ |
OLD | NEW |