blob: 51a5b8e50cb7d09aa2283bf9eeb7b706de55f53a [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_
12#define MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
Steve Antone78bcb92017-10-31 09:53:08 -070014#include <string>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "media/engine/webrtcvideocapturer.h"
18#include "rtc_base/stringutils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019
20// Fake class for mocking out webrtc::VideoCaptureModule::DeviceInfo.
21class FakeWebRtcDeviceInfo : public webrtc::VideoCaptureModule::DeviceInfo {
22 public:
23 struct Device {
24 Device(const std::string& n, const std::string& i) : name(n), id(i) {}
25 std::string name;
26 std::string id;
27 std::string product;
28 std::vector<webrtc::VideoCaptureCapability> caps;
29 };
30 FakeWebRtcDeviceInfo() {}
31 void AddDevice(const std::string& device_name, const std::string& device_id) {
32 devices_.push_back(Device(device_name, device_id));
33 }
34 void AddCapability(const std::string& device_id,
35 const webrtc::VideoCaptureCapability& cap) {
36 Device* dev = GetDeviceById(
37 reinterpret_cast<const char*>(device_id.c_str()));
38 if (!dev) return;
39 dev->caps.push_back(cap);
40 }
41 virtual uint32_t NumberOfDevices() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +000042 return static_cast<int>(devices_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043 }
44 virtual int32_t GetDeviceName(uint32_t device_num,
45 char* device_name,
46 uint32_t device_name_len,
47 char* device_id,
48 uint32_t device_id_len,
49 char* product_id,
50 uint32_t product_id_len) {
51 Device* dev = GetDeviceByIndex(device_num);
52 if (!dev) return -1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000053 rtc::strcpyn(reinterpret_cast<char*>(device_name), device_name_len,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054 dev->name.c_str());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000055 rtc::strcpyn(reinterpret_cast<char*>(device_id), device_id_len,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056 dev->id.c_str());
57 if (product_id) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000058 rtc::strcpyn(reinterpret_cast<char*>(product_id), product_id_len,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059 dev->product.c_str());
60 }
61 return 0;
62 }
63 virtual int32_t NumberOfCapabilities(const char* device_id) {
64 Device* dev = GetDeviceById(device_id);
65 if (!dev) return -1;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +000066 return static_cast<int32_t>(dev->caps.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067 }
68 virtual int32_t GetCapability(const char* device_id,
69 const uint32_t device_cap_num,
70 webrtc::VideoCaptureCapability& cap) {
71 Device* dev = GetDeviceById(device_id);
72 if (!dev) return -1;
73 if (device_cap_num >= dev->caps.size()) return -1;
74 cap = dev->caps[device_cap_num];
75 return 0;
76 }
77 virtual int32_t GetOrientation(const char* device_id,
guoweis@webrtc.org5a7dc392015-02-13 14:31:26 +000078 webrtc::VideoRotation& rotation) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 return -1; // not implemented
80 }
81 virtual int32_t GetBestMatchedCapability(
82 const char* device_id,
83 const webrtc::VideoCaptureCapability& requested,
84 webrtc::VideoCaptureCapability& resulting) {
85 return -1; // not implemented
86 }
87 virtual int32_t DisplayCaptureSettingsDialogBox(
88 const char* device_id, const char* dialog_title,
89 void* parent, uint32_t x, uint32_t y) {
90 return -1; // not implemented
91 }
92
93 Device* GetDeviceByIndex(size_t num) {
94 return (num < devices_.size()) ? &devices_[num] : NULL;
95 }
96 Device* GetDeviceById(const char* device_id) {
97 for (size_t i = 0; i < devices_.size(); ++i) {
98 if (devices_[i].id == reinterpret_cast<const char*>(device_id)) {
99 return &devices_[i];
100 }
101 }
102 return NULL;
103 }
104
105 private:
106 std::vector<Device> devices_;
107};
108
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200109#endif // MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_