~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/libjingle/talk/session/phone/devicemanager.h

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_DEVICEMANAGER_H_
 
29
#define TALK_SESSION_PHONE_DEVICEMANAGER_H_
 
30
 
 
31
#include <string>
 
32
#include <vector>
 
33
 
 
34
#include "talk/base/scoped_ptr.h"
 
35
#include "talk/base/sigslot.h"
 
36
#include "talk/base/stringencode.h"
 
37
 
 
38
namespace cricket {
 
39
 
 
40
// Used to represent an audio or video capture or render device.
 
41
struct Device {
 
42
  Device() {}
 
43
  Device(const std::string& first, int second)
 
44
      : name(first),
 
45
        id(talk_base::ToString(second)) {
 
46
  }
 
47
  Device(const std::string& first, const std::string& second)
 
48
      : name(first), id(second) {}
 
49
 
 
50
  std::string name;
 
51
  std::string id;
 
52
};
 
53
 
 
54
// DeviceManagerInterface - interface to manage the audio and
 
55
// video devices on the system.
 
56
class DeviceManagerInterface {
 
57
 public:
 
58
  virtual ~DeviceManagerInterface() { }
 
59
 
 
60
  // Initialization
 
61
  virtual bool Init() = 0;
 
62
  virtual void Terminate() = 0;
 
63
 
 
64
  // Capabilities
 
65
  virtual int GetCapabilities() = 0;
 
66
 
 
67
  // Device enumeration
 
68
  virtual bool GetAudioInputDevices(std::vector<Device>* devices) = 0;
 
69
  virtual bool GetAudioOutputDevices(std::vector<Device>* devices) = 0;
 
70
 
 
71
  virtual bool GetAudioInputDevice(const std::string& name, Device* out) = 0;
 
72
  virtual bool GetAudioOutputDevice(const std::string& name, Device* out) = 0;
 
73
 
 
74
  virtual bool GetVideoCaptureDevices(std::vector<Device>* devs) = 0;
 
75
  virtual bool GetVideoCaptureDevice(const std::string& name, Device* out) = 0;
 
76
 
 
77
  sigslot::signal0<> SignalDevicesChange;
 
78
 
 
79
  static const char kDefaultDeviceName[];
 
80
};
 
81
 
 
82
class DeviceWatcher {
 
83
 public:
 
84
  explicit DeviceWatcher(DeviceManagerInterface* dm) {}
 
85
  virtual ~DeviceWatcher() {}
 
86
  virtual bool Start() { return true; }
 
87
  virtual void Stop() {}
 
88
};
 
89
 
 
90
class DeviceManagerFactory {
 
91
 public:
 
92
  static DeviceManagerInterface* Create();
 
93
 private:
 
94
  DeviceManagerFactory();
 
95
};
 
96
 
 
97
class DeviceManager : public DeviceManagerInterface {
 
98
 public:
 
99
  DeviceManager();
 
100
  virtual ~DeviceManager();
 
101
 
 
102
  // Initialization
 
103
  virtual bool Init();
 
104
  virtual void Terminate();
 
105
 
 
106
  // Capabilities
 
107
  virtual int GetCapabilities();
 
108
 
 
109
  // Device enumeration
 
110
  virtual bool GetAudioInputDevices(std::vector<Device>* devices);
 
111
  virtual bool GetAudioOutputDevices(std::vector<Device>* devices);
 
112
 
 
113
  virtual bool GetAudioInputDevice(const std::string& name, Device* out);
 
114
  virtual bool GetAudioOutputDevice(const std::string& name, Device* out);
 
115
 
 
116
  virtual bool GetVideoCaptureDevices(std::vector<Device>* devs);
 
117
  virtual bool GetVideoCaptureDevice(const std::string& name, Device* out);
 
118
 
 
119
  // The exclusion_list MUST be a NULL terminated list.
 
120
  static bool FilterDevices(std::vector<Device>* devices,
 
121
      const char* const exclusion_list[]);
 
122
  bool initialized() const { return initialized_; }
 
123
 
 
124
 protected:
 
125
  virtual bool GetAudioDevices(bool input, std::vector<Device>* devs);
 
126
  virtual bool GetAudioDevice(bool is_input, const std::string& name,
 
127
                              Device* out);
 
128
  virtual bool GetDefaultVideoCaptureDevice(Device* device);
 
129
 
 
130
  void set_initialized(bool initialized) { initialized_ = initialized; }
 
131
 
 
132
  void set_watcher(DeviceWatcher* watcher) { watcher_.reset(watcher); }
 
133
  DeviceWatcher* watcher() { return watcher_.get(); }
 
134
 
 
135
 private:
 
136
  // The exclusion_list MUST be a NULL terminated list.
 
137
  static bool ShouldDeviceBeIgnored(const std::string& device_name,
 
138
      const char* const exclusion_list[]);
 
139
  bool initialized_;
 
140
  talk_base::scoped_ptr<DeviceWatcher> watcher_;
 
141
};
 
142
 
 
143
}  // namespace cricket
 
144
 
 
145
#endif  // TALK_SESSION_PHONE_DEVICEMANAGER_H_