2 // Copyright 2004 Google Inc.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
7 // 1. Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 // 2. Redistributions in binary form must reproduce the above copyright notice,
10 // this list of conditions and the following disclaimer in the documentation
11 // and/or other materials provided with the distribution.
12 // 3. The name of the author may not be used to endorse or promote products
13 // derived from this software without specific prior written permission.
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef TALK_SESSION_PHONE_FAKEWEBRTCDEVICEINFO_H_
27 #define TALK_SESSION_PHONE_FAKEWEBRTCDEVICEINFO_H_
31 #include "talk/media/webrtc/webrtcvideocapturer.h"
32 #include "webrtc/base/stringutils.h"
34 // Fake class for mocking out webrtc::VideoCaptureModule::DeviceInfo.
35 class FakeWebRtcDeviceInfo : public webrtc::VideoCaptureModule::DeviceInfo {
38 Device(const std::string& n, const std::string& i) : name(n), id(i) {}
42 std::vector<webrtc::VideoCaptureCapability> caps;
44 FakeWebRtcDeviceInfo() {}
45 void AddDevice(const std::string& device_name, const std::string& device_id) {
46 devices_.push_back(Device(device_name, device_id));
48 void AddCapability(const std::string& device_id,
49 const webrtc::VideoCaptureCapability& cap) {
50 Device* dev = GetDeviceById(
51 reinterpret_cast<const char*>(device_id.c_str()));
53 dev->caps.push_back(cap);
55 virtual uint32_t NumberOfDevices() {
56 return static_cast<int>(devices_.size());
58 virtual int32_t GetDeviceName(uint32_t device_num,
60 uint32_t device_name_len,
62 uint32_t device_id_len,
64 uint32_t product_id_len) {
65 Device* dev = GetDeviceByIndex(device_num);
67 rtc::strcpyn(reinterpret_cast<char*>(device_name), device_name_len,
69 rtc::strcpyn(reinterpret_cast<char*>(device_id), device_id_len,
72 rtc::strcpyn(reinterpret_cast<char*>(product_id), product_id_len,
73 dev->product.c_str());
77 virtual int32_t NumberOfCapabilities(const char* device_id) {
78 Device* dev = GetDeviceById(device_id);
80 return static_cast<int32_t>(dev->caps.size());
82 virtual int32_t GetCapability(const char* device_id,
83 const uint32_t device_cap_num,
84 webrtc::VideoCaptureCapability& cap) {
85 Device* dev = GetDeviceById(device_id);
87 if (device_cap_num >= dev->caps.size()) return -1;
88 cap = dev->caps[device_cap_num];
91 virtual int32_t GetOrientation(const char* device_id,
92 webrtc::VideoCaptureRotation& rotation) {
93 return -1; // not implemented
95 virtual int32_t GetBestMatchedCapability(
96 const char* device_id,
97 const webrtc::VideoCaptureCapability& requested,
98 webrtc::VideoCaptureCapability& resulting) {
99 return -1; // not implemented
101 virtual int32_t DisplayCaptureSettingsDialogBox(
102 const char* device_id, const char* dialog_title,
103 void* parent, uint32_t x, uint32_t y) {
104 return -1; // not implemented
107 Device* GetDeviceByIndex(size_t num) {
108 return (num < devices_.size()) ? &devices_[num] : NULL;
110 Device* GetDeviceById(const char* device_id) {
111 for (size_t i = 0; i < devices_.size(); ++i) {
112 if (devices_[i].id == reinterpret_cast<const char*>(device_id)) {
120 std::vector<Device> devices_;
123 #endif // TALK_SESSION_PHONE_FAKEWEBRTCDEVICEINFO_H_