10e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// libjingle
20e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// Copyright 2004 Google Inc.
30e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//
40e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// Redistribution and use in source and binary forms, with or without
50e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// modification, are permitted provided that the following conditions are met:
60e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//
70e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//  1. Redistributions of source code must retain the above copyright notice,
80e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//     this list of conditions and the following disclaimer.
90e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//  2. Redistributions in binary form must reproduce the above copyright notice,
100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//     this list of conditions and the following disclaimer in the documentation
110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//     and/or other materials provided with the distribution.
120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//  3. The name of the author may not be used to endorse or promote products
130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//     derived from this software without specific prior written permission.
140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org//
150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#ifndef TALK_SESSION_PHONE_FAKEWEBRTCDEVICEINFO_H_
270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#define TALK_SESSION_PHONE_FAKEWEBRTCDEVICEINFO_H_
280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include <vector>
300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/media/webrtc/webrtcvideocapturer.h"
32cf81adffe15fa8ea0f333432e41f6d504148f18abuildbot@webrtc.org#include "webrtc/base/stringutils.h"
330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
340e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// Fake class for mocking out webrtc::VideoCaptureModule::DeviceInfo.
350e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass FakeWebRtcDeviceInfo : public webrtc::VideoCaptureModule::DeviceInfo {
360e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org public:
370e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  struct Device {
380e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    Device(const std::string& n, const std::string& i) : name(n), id(i) {}
390e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    std::string name;
400e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    std::string id;
410e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    std::string product;
420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    std::vector<webrtc::VideoCaptureCapability> caps;
430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  };
440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  FakeWebRtcDeviceInfo() {}
450e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void AddDevice(const std::string& device_name, const std::string& device_id) {
460e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    devices_.push_back(Device(device_name, device_id));
470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void AddCapability(const std::string& device_id,
490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                     const webrtc::VideoCaptureCapability& cap) {
500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    Device* dev = GetDeviceById(
510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        reinterpret_cast<const char*>(device_id.c_str()));
520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    if (!dev) return;
530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    dev->caps.push_back(cap);
540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
550e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual uint32_t NumberOfDevices() {
561a04b881e0ef480802fb01b4fbe9bcd5388d2c69henrike@webrtc.org    return static_cast<int>(devices_.size());
570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
580e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual int32_t GetDeviceName(uint32_t device_num,
590e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                char* device_name,
600e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                uint32_t device_name_len,
610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                char* device_id,
620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                uint32_t device_id_len,
630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                char* product_id,
640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                uint32_t product_id_len) {
650e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    Device* dev = GetDeviceByIndex(device_num);
660e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    if (!dev) return -1;
672a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org    rtc::strcpyn(reinterpret_cast<char*>(device_name), device_name_len,
680e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                       dev->name.c_str());
692a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org    rtc::strcpyn(reinterpret_cast<char*>(device_id), device_id_len,
700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                       dev->id.c_str());
710e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    if (product_id) {
722a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org      rtc::strcpyn(reinterpret_cast<char*>(product_id), product_id_len,
730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                         dev->product.c_str());
740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    }
750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return 0;
760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual int32_t NumberOfCapabilities(const char* device_id) {
780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    Device* dev = GetDeviceById(device_id);
790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    if (!dev) return -1;
801a04b881e0ef480802fb01b4fbe9bcd5388d2c69henrike@webrtc.org    return static_cast<int32_t>(dev->caps.size());
810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
820e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual int32_t GetCapability(const char* device_id,
830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                const uint32_t device_cap_num,
840e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                webrtc::VideoCaptureCapability& cap) {
850e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    Device* dev = GetDeviceById(device_id);
860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    if (!dev) return -1;
870e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    if (device_cap_num >= dev->caps.size()) return -1;
880e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    cap = dev->caps[device_cap_num];
890e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return 0;
900e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
910e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual int32_t GetOrientation(const char* device_id,
920e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                 webrtc::VideoCaptureRotation& rotation) {
930e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return -1;  // not implemented
940e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
950e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual int32_t GetBestMatchedCapability(
960e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      const char* device_id,
970e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      const webrtc::VideoCaptureCapability& requested,
980e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      webrtc::VideoCaptureCapability& resulting) {
990e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return -1;  // not implemented
1000e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
1010e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual int32_t DisplayCaptureSettingsDialogBox(
1020e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      const char* device_id, const char* dialog_title,
1030e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      void* parent, uint32_t x, uint32_t y) {
1040e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return -1;  // not implemented
1050e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
1060e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1070e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  Device* GetDeviceByIndex(size_t num) {
1080e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return (num < devices_.size()) ? &devices_[num] : NULL;
1090e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
1100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  Device* GetDeviceById(const char* device_id) {
1110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    for (size_t i = 0; i < devices_.size(); ++i) {
1120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      if (devices_[i].id == reinterpret_cast<const char*>(device_id)) {
1130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org        return &devices_[i];
1140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      }
1150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    }
1160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return NULL;
1170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
1180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org private:
1200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::vector<Device> devices_;
1210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org};
1220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#endif  // TALK_SESSION_PHONE_FAKEWEBRTCDEVICEINFO_H_
124