OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #ifndef WEBRTC_MEDIA_WEBRTC_FAKEWEBRTCDEVICEINFO_H_ | |
12 #define WEBRTC_MEDIA_WEBRTC_FAKEWEBRTCDEVICEINFO_H_ | |
13 | |
14 #include <vector> | |
15 | |
16 #include "webrtc/base/stringutils.h" | |
17 #include "webrtc/media/webrtc/webrtcvideocapturer.h" | |
18 | |
19 // Fake class for mocking out webrtc::VideoCaptureModule::DeviceInfo. | |
20 class FakeWebRtcDeviceInfo : public webrtc::VideoCaptureModule::DeviceInfo { | |
21 public: | |
22 struct Device { | |
23 Device(const std::string& n, const std::string& i) : name(n), id(i) {} | |
24 std::string name; | |
25 std::string id; | |
26 std::string product; | |
27 std::vector<webrtc::VideoCaptureCapability> caps; | |
28 }; | |
29 FakeWebRtcDeviceInfo() {} | |
30 void AddDevice(const std::string& device_name, const std::string& device_id) { | |
31 devices_.push_back(Device(device_name, device_id)); | |
32 } | |
33 void AddCapability(const std::string& device_id, | |
34 const webrtc::VideoCaptureCapability& cap) { | |
35 Device* dev = GetDeviceById( | |
36 reinterpret_cast<const char*>(device_id.c_str())); | |
37 if (!dev) return; | |
38 dev->caps.push_back(cap); | |
39 } | |
40 virtual uint32_t NumberOfDevices() { | |
41 return static_cast<int>(devices_.size()); | |
42 } | |
43 virtual int32_t GetDeviceName(uint32_t device_num, | |
44 char* device_name, | |
45 uint32_t device_name_len, | |
46 char* device_id, | |
47 uint32_t device_id_len, | |
48 char* product_id, | |
49 uint32_t product_id_len) { | |
50 Device* dev = GetDeviceByIndex(device_num); | |
51 if (!dev) return -1; | |
52 rtc::strcpyn(reinterpret_cast<char*>(device_name), device_name_len, | |
53 dev->name.c_str()); | |
54 rtc::strcpyn(reinterpret_cast<char*>(device_id), device_id_len, | |
55 dev->id.c_str()); | |
56 if (product_id) { | |
57 rtc::strcpyn(reinterpret_cast<char*>(product_id), product_id_len, | |
58 dev->product.c_str()); | |
59 } | |
60 return 0; | |
61 } | |
62 virtual int32_t NumberOfCapabilities(const char* device_id) { | |
63 Device* dev = GetDeviceById(device_id); | |
64 if (!dev) return -1; | |
65 return static_cast<int32_t>(dev->caps.size()); | |
66 } | |
67 virtual int32_t GetCapability(const char* device_id, | |
68 const uint32_t device_cap_num, | |
69 webrtc::VideoCaptureCapability& cap) { | |
70 Device* dev = GetDeviceById(device_id); | |
71 if (!dev) return -1; | |
72 if (device_cap_num >= dev->caps.size()) return -1; | |
73 cap = dev->caps[device_cap_num]; | |
74 return 0; | |
75 } | |
76 virtual int32_t GetOrientation(const char* device_id, | |
77 webrtc::VideoRotation& rotation) { | |
78 return -1; // not implemented | |
79 } | |
80 virtual int32_t GetBestMatchedCapability( | |
81 const char* device_id, | |
82 const webrtc::VideoCaptureCapability& requested, | |
83 webrtc::VideoCaptureCapability& resulting) { | |
84 return -1; // not implemented | |
85 } | |
86 virtual int32_t DisplayCaptureSettingsDialogBox( | |
87 const char* device_id, const char* dialog_title, | |
88 void* parent, uint32_t x, uint32_t y) { | |
89 return -1; // not implemented | |
90 } | |
91 | |
92 Device* GetDeviceByIndex(size_t num) { | |
93 return (num < devices_.size()) ? &devices_[num] : NULL; | |
94 } | |
95 Device* GetDeviceById(const char* device_id) { | |
96 for (size_t i = 0; i < devices_.size(); ++i) { | |
97 if (devices_[i].id == reinterpret_cast<const char*>(device_id)) { | |
98 return &devices_[i]; | |
99 } | |
100 } | |
101 return NULL; | |
102 } | |
103 | |
104 private: | |
105 std::vector<Device> devices_; | |
106 }; | |
107 | |
108 #endif // WEBRTC_MEDIA_WEBRTC_FAKEWEBRTCDEVICEINFO_H_ | |
OLD | NEW |