15976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// libjingle
25976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Copyright 2004 Google Inc.
35976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org//
45976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Redistribution and use in source and binary forms, with or without
55976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// modification, are permitted provided that the following conditions are met:
65976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org//
75976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org//  1. Redistributions of source code must retain the above copyright notice,
85976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org//     this list of conditions and the following disclaimer.
95976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org//  2. Redistributions in binary form must reproduce the above copyright notice,
105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org//     this list of conditions and the following disclaimer in the documentation
115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org//     and/or other materials provided with the distribution.
125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org//  3. The name of the author may not be used to endorse or promote products
135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org//     derived from this software without specific prior written permission.
145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org//
155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#ifndef TALK_SESSION_PHONE_FAKEWEBRTCDEVICEINFO_H_
275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#define TALK_SESSION_PHONE_FAKEWEBRTCDEVICEINFO_H_
285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <vector>
305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/stringutils.h"
325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/media/webrtc/webrtcvideocapturer.h"
335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Fake class for mocking out webrtc::VideoCaptureModule::DeviceInfo.
355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass FakeWebRtcDeviceInfo : public webrtc::VideoCaptureModule::DeviceInfo {
365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org public:
375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  struct Device {
385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    Device(const std::string& n, const std::string& i) : name(n), id(i) {}
395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    std::string name;
405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    std::string id;
415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    std::string product;
425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    std::vector<webrtc::VideoCaptureCapability> caps;
435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  };
445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  FakeWebRtcDeviceInfo() {}
455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void AddDevice(const std::string& device_name, const std::string& device_id) {
465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    devices_.push_back(Device(device_name, device_id));
475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void AddCapability(const std::string& device_id,
495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                     const webrtc::VideoCaptureCapability& cap) {
505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    Device* dev = GetDeviceById(
515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org        reinterpret_cast<const char*>(device_id.c_str()));
525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    if (!dev) return;
535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    dev->caps.push_back(cap);
545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual uint32_t NumberOfDevices() {
56b30f5947ff2af0e3b77751bacec5dc7350c4dcd6sergeyu@chromium.org    return static_cast<int>(devices_.size());
575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual int32_t GetDeviceName(uint32_t device_num,
595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                                char* device_name,
605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                                uint32_t device_name_len,
615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                                char* device_id,
625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                                uint32_t device_id_len,
635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                                char* product_id,
645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                                uint32_t product_id_len) {
655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    Device* dev = GetDeviceByIndex(device_num);
665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    if (!dev) return -1;
675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    talk_base::strcpyn(reinterpret_cast<char*>(device_name), device_name_len,
685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                       dev->name.c_str());
695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    talk_base::strcpyn(reinterpret_cast<char*>(device_id), device_id_len,
705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                       dev->id.c_str());
715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    if (product_id) {
725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org      talk_base::strcpyn(reinterpret_cast<char*>(product_id), product_id_len,
735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                         dev->product.c_str());
745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    }
755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return 0;
765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual int32_t NumberOfCapabilities(const char* device_id) {
785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    Device* dev = GetDeviceById(device_id);
795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    if (!dev) return -1;
80b30f5947ff2af0e3b77751bacec5dc7350c4dcd6sergeyu@chromium.org    return static_cast<int32_t>(dev->caps.size());
815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual int32_t GetCapability(const char* device_id,
835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                                const uint32_t device_cap_num,
845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                                webrtc::VideoCaptureCapability& cap) {
855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    Device* dev = GetDeviceById(device_id);
865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    if (!dev) return -1;
875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    if (device_cap_num >= dev->caps.size()) return -1;
885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    cap = dev->caps[device_cap_num];
895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return 0;
905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual int32_t GetOrientation(const char* device_id,
925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                                 webrtc::VideoCaptureRotation& rotation) {
935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return -1;  // not implemented
945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual int32_t GetBestMatchedCapability(
965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org      const char* device_id,
975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org      const webrtc::VideoCaptureCapability& requested,
985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org      webrtc::VideoCaptureCapability& resulting) {
995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return -1;  // not implemented
1005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual int32_t DisplayCaptureSettingsDialogBox(
1025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org      const char* device_id, const char* dialog_title,
1035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org      void* parent, uint32_t x, uint32_t y) {
1045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return -1;  // not implemented
1055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  Device* GetDeviceByIndex(size_t num) {
1085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return (num < devices_.size()) ? &devices_[num] : NULL;
1095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  Device* GetDeviceById(const char* device_id) {
1115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    for (size_t i = 0; i < devices_.size(); ++i) {
1125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org      if (devices_[i].id == reinterpret_cast<const char*>(device_id)) {
1135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org        return &devices_[i];
1145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org      }
1155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    }
1165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return NULL;
1175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org private:
1205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  std::vector<Device> devices_;
1215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org};
1225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif  // TALK_SESSION_PHONE_FAKEWEBRTCDEVICEINFO_H_
124