15f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org/*
25f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * libjingle
35f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * Copyright 2004 Google Inc.
45f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org *
55f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * Redistribution and use in source and binary forms, with or without
65f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * modification, are permitted provided that the following conditions are met:
75f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org *
85f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org *  1. Redistributions of source code must retain the above copyright notice,
95f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org *     this list of conditions and the following disclaimer.
105f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org *  2. Redistributions in binary form must reproduce the above copyright notice,
115f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org *     this list of conditions and the following disclaimer in the documentation
125f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org *     and/or other materials provided with the distribution.
135f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org *  3. The name of the author may not be used to endorse or promote products
145f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org *     derived from this software without specific prior written permission.
155f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org *
165f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
175f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
185f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
195f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
215f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
225f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
235f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
245f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
255f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org */
2728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
2828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#ifndef TALK_SESSION_PHONE_FAKEWEBRTCDEVICEINFO_H_
2928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#define TALK_SESSION_PHONE_FAKEWEBRTCDEVICEINFO_H_
3028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
3128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include <vector>
3228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
3328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/media/webrtc/webrtcvideocapturer.h"
34a09a99950ec40aef6421e4ba35eee7196b7a6e68buildbot@webrtc.org#include "webrtc/base/stringutils.h"
3528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
3628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// Fake class for mocking out webrtc::VideoCaptureModule::DeviceInfo.
3728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgclass FakeWebRtcDeviceInfo : public webrtc::VideoCaptureModule::DeviceInfo {
3828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org public:
3928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  struct Device {
4028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    Device(const std::string& n, const std::string& i) : name(n), id(i) {}
4128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    std::string name;
4228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    std::string id;
4328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    std::string product;
4428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    std::vector<webrtc::VideoCaptureCapability> caps;
4528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  };
4628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  FakeWebRtcDeviceInfo() {}
4728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  void AddDevice(const std::string& device_name, const std::string& device_id) {
4828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    devices_.push_back(Device(device_name, device_id));
4928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
5028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  void AddCapability(const std::string& device_id,
5128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                     const webrtc::VideoCaptureCapability& cap) {
5228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    Device* dev = GetDeviceById(
5328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org        reinterpret_cast<const char*>(device_id.c_str()));
5428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    if (!dev) return;
5528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    dev->caps.push_back(cap);
5628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
5728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual uint32_t NumberOfDevices() {
5828654cbc2256230c978f41cbaf550bc2e9c2f2dbhenrike@webrtc.org    return static_cast<int>(devices_.size());
5928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
6028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual int32_t GetDeviceName(uint32_t device_num,
6128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                char* device_name,
6228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                uint32_t device_name_len,
6328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                char* device_id,
6428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                uint32_t device_id_len,
6528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                char* product_id,
6628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                uint32_t product_id_len) {
6728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    Device* dev = GetDeviceByIndex(device_num);
6828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    if (!dev) return -1;
69d4e598d57aed714a599444a7eab5e8fdde52a950buildbot@webrtc.org    rtc::strcpyn(reinterpret_cast<char*>(device_name), device_name_len,
7028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                       dev->name.c_str());
71d4e598d57aed714a599444a7eab5e8fdde52a950buildbot@webrtc.org    rtc::strcpyn(reinterpret_cast<char*>(device_id), device_id_len,
7228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                       dev->id.c_str());
7328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    if (product_id) {
74d4e598d57aed714a599444a7eab5e8fdde52a950buildbot@webrtc.org      rtc::strcpyn(reinterpret_cast<char*>(product_id), product_id_len,
7528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                         dev->product.c_str());
7628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    }
7728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    return 0;
7828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
7928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual int32_t NumberOfCapabilities(const char* device_id) {
8028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    Device* dev = GetDeviceById(device_id);
8128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    if (!dev) return -1;
8228654cbc2256230c978f41cbaf550bc2e9c2f2dbhenrike@webrtc.org    return static_cast<int32_t>(dev->caps.size());
8328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
8428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual int32_t GetCapability(const char* device_id,
8528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                const uint32_t device_cap_num,
8628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                webrtc::VideoCaptureCapability& cap) {
8728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    Device* dev = GetDeviceById(device_id);
8828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    if (!dev) return -1;
8928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    if (device_cap_num >= dev->caps.size()) return -1;
9028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    cap = dev->caps[device_cap_num];
9128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    return 0;
9228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
9328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual int32_t GetOrientation(const char* device_id,
945a7dc39277999cbfa0da053da5eacc7fee5cd307guoweis@webrtc.org                                 webrtc::VideoRotation& rotation) {
9528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    return -1;  // not implemented
9628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
9728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual int32_t GetBestMatchedCapability(
9828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      const char* device_id,
9928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      const webrtc::VideoCaptureCapability& requested,
10028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      webrtc::VideoCaptureCapability& resulting) {
10128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    return -1;  // not implemented
10228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
10328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual int32_t DisplayCaptureSettingsDialogBox(
10428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      const char* device_id, const char* dialog_title,
10528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      void* parent, uint32_t x, uint32_t y) {
10628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    return -1;  // not implemented
10728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
10828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
10928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  Device* GetDeviceByIndex(size_t num) {
11028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    return (num < devices_.size()) ? &devices_[num] : NULL;
11128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
11228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  Device* GetDeviceById(const char* device_id) {
11328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    for (size_t i = 0; i < devices_.size(); ++i) {
11428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      if (devices_[i].id == reinterpret_cast<const char*>(device_id)) {
11528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org        return &devices_[i];
11628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      }
11728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    }
11828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    return NULL;
11928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
12028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
12128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org private:
12228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<Device> devices_;
12328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org};
12428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
12528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#endif  // TALK_SESSION_PHONE_FAKEWEBRTCDEVICEINFO_H_
126