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