jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 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. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 9 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_ |
| 12 | #define MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
Steve Anton | e78bcb9 | 2017-10-31 09:53:08 -0700 | [diff] [blame] | 14 | #include <string> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "media/engine/webrtcvideocapturer.h" |
| 18 | #include "rtc_base/stringutils.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 19 | |
| 20 | // Fake class for mocking out webrtc::VideoCaptureModule::DeviceInfo. |
| 21 | class 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.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 42 | return static_cast<int>(devices_.size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | } |
| 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 53 | rtc::strcpyn(reinterpret_cast<char*>(device_name), device_name_len, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 54 | dev->name.c_str()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 55 | rtc::strcpyn(reinterpret_cast<char*>(device_id), device_id_len, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | dev->id.c_str()); |
| 57 | if (product_id) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 58 | rtc::strcpyn(reinterpret_cast<char*>(product_id), product_id_len, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | 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.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 66 | return static_cast<int32_t>(dev->caps.size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | } |
| 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.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 78 | webrtc::VideoRotation& rotation) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 109 | #endif // MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_ |