blob: 38f9810e6b5bca2c60b7fd2b30085e9bdf4aa0b5 [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * 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.
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00009 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000010
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010011#ifndef WEBRTC_MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_
12#define WEBRTC_MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
14#include <vector>
15
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010016#include "webrtc/media/engine/webrtcvideocapturer.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020017#include "webrtc/rtc_base/stringutils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018
19// Fake class for mocking out webrtc::VideoCaptureModule::DeviceInfo.
20class 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() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +000041 return static_cast<int>(devices_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042 }
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;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000052 rtc::strcpyn(reinterpret_cast<char*>(device_name), device_name_len,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053 dev->name.c_str());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000054 rtc::strcpyn(reinterpret_cast<char*>(device_id), device_id_len,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055 dev->id.c_str());
56 if (product_id) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000057 rtc::strcpyn(reinterpret_cast<char*>(product_id), product_id_len,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058 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;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +000065 return static_cast<int32_t>(dev->caps.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 }
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,
guoweis@webrtc.org5a7dc392015-02-13 14:31:26 +000077 webrtc::VideoRotation& rotation) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 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
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +0100108#endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_