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 | |
kjellander@webrtc.org | 5ad1297 | 2016-02-12 06:39:40 +0100 | [diff] [blame] | 11 | #ifndef WEBRTC_MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_ |
| 12 | #define WEBRTC_MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
| 14 | #include <vector> |
| 15 | |
kjellander@webrtc.org | 5ad1297 | 2016-02-12 06:39:40 +0100 | [diff] [blame] | 16 | #include "webrtc/media/engine/webrtcvideocapturer.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 17 | #include "webrtc/rtc_base/stringutils.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 41 | return static_cast<int>(devices_.size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 52 | rtc::strcpyn(reinterpret_cast<char*>(device_name), device_name_len, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | dev->name.c_str()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 54 | rtc::strcpyn(reinterpret_cast<char*>(device_id), device_id_len, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 55 | dev->id.c_str()); |
| 56 | if (product_id) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 57 | rtc::strcpyn(reinterpret_cast<char*>(product_id), product_id_len, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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; |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 65 | return static_cast<int32_t>(dev->caps.size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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, |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 77 | webrtc::VideoRotation& rotation) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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 | |
kjellander@webrtc.org | 5ad1297 | 2016-02-12 06:39:40 +0100 | [diff] [blame] | 108 | #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCDEVICEINFO_H_ |