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

« back to all changes in this revision

Viewing changes to protocols/jabber/libjingle/talk/sound/pulseaudiosoundsystem.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--2010, 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_SOUND_PULSEAUDIOSOUNDSYSTEM_H_
 
29
#define TALK_SOUND_PULSEAUDIOSOUNDSYSTEM_H_
 
30
 
 
31
#ifdef HAVE_LIBPULSE
 
32
 
 
33
// For the flag enums, which can't be forward-declared.
 
34
#include <pulse/def.h>
 
35
 
 
36
#include "talk/base/constructormagic.h"
 
37
#include "talk/sound/pulseaudiosymboltable.h"
 
38
#include "talk/sound/soundsysteminterface.h"
 
39
 
 
40
struct pa_context;
 
41
struct pa_operation;
 
42
struct pa_sample_spec;
 
43
struct pa_server_info;
 
44
struct pa_sink_info;
 
45
struct pa_source_info;
 
46
struct pa_stream;
 
47
struct pa_threaded_mainloop;
 
48
 
 
49
namespace cricket {
 
50
 
 
51
class PulseAudioInputStream;
 
52
class PulseAudioOutputStream;
 
53
class PulseAudioStream;
 
54
 
 
55
// Sound system implementation for PulseAudio, a cross-platform sound server
 
56
// (but commonly used only on Linux, which is the only platform we support
 
57
// it on).
 
58
// Init(), Terminate(), and the destructor should never be invoked concurrently,
 
59
// but all other methods are thread-safe.
 
60
class PulseAudioSoundSystem : public SoundSystemInterface {
 
61
  friend class PulseAudioInputStream;
 
62
  friend class PulseAudioOutputStream;
 
63
  friend class PulseAudioStream;
 
64
 public:
 
65
  static SoundSystemInterface *Create() {
 
66
    return new PulseAudioSoundSystem();
 
67
  }
 
68
 
 
69
  PulseAudioSoundSystem();
 
70
 
 
71
  virtual ~PulseAudioSoundSystem();
 
72
 
 
73
  virtual bool Init();
 
74
  virtual void Terminate();
 
75
 
 
76
  virtual bool EnumeratePlaybackDevices(SoundDeviceLocatorList *devices);
 
77
  virtual bool EnumerateCaptureDevices(SoundDeviceLocatorList *devices);
 
78
 
 
79
  virtual bool GetDefaultPlaybackDevice(SoundDeviceLocator **device);
 
80
  virtual bool GetDefaultCaptureDevice(SoundDeviceLocator **device);
 
81
 
 
82
  virtual SoundOutputStreamInterface *OpenPlaybackDevice(
 
83
      const SoundDeviceLocator *device,
 
84
      const OpenParams &params);
 
85
  virtual SoundInputStreamInterface *OpenCaptureDevice(
 
86
      const SoundDeviceLocator *device,
 
87
      const OpenParams &params);
 
88
 
 
89
  virtual const char *GetName() const;
 
90
 
 
91
 private:
 
92
  bool IsInitialized();
 
93
 
 
94
  static void ConnectToPulseCallbackThunk(pa_context *context, void *userdata);
 
95
 
 
96
  void OnConnectToPulseCallback(pa_context *context, bool *connect_done);
 
97
 
 
98
  bool ConnectToPulse(pa_context *context);
 
99
 
 
100
  pa_context *CreateNewConnection();
 
101
 
 
102
  template <typename InfoStruct>
 
103
  bool EnumerateDevices(SoundDeviceLocatorList *devices,
 
104
                        pa_operation *(*enumerate_fn)(
 
105
                            pa_context *c,
 
106
                            void (*callback_fn)(
 
107
                                pa_context *c,
 
108
                                const InfoStruct *i,
 
109
                                int eol,
 
110
                                void *userdata),
 
111
                            void *userdata),
 
112
                        void (*callback_fn)(
 
113
                            pa_context *c,
 
114
                            const InfoStruct *i,
 
115
                            int eol,
 
116
                            void *userdata));
 
117
 
 
118
  static void EnumeratePlaybackDevicesCallbackThunk(pa_context *unused,
 
119
                                                    const pa_sink_info *info,
 
120
                                                    int eol,
 
121
                                                    void *userdata);
 
122
 
 
123
  static void EnumerateCaptureDevicesCallbackThunk(pa_context *unused,
 
124
                                                   const pa_source_info *info,
 
125
                                                   int eol,
 
126
                                                   void *userdata);
 
127
 
 
128
  void OnEnumeratePlaybackDevicesCallback(
 
129
      SoundDeviceLocatorList *devices,
 
130
      const pa_sink_info *info,
 
131
      int eol);
 
132
 
 
133
  void OnEnumerateCaptureDevicesCallback(
 
134
      SoundDeviceLocatorList *devices,
 
135
      const pa_source_info *info,
 
136
      int eol);
 
137
 
 
138
  template <const char *(pa_server_info::*field)>
 
139
  static void GetDefaultDeviceCallbackThunk(
 
140
      pa_context *unused,
 
141
      const pa_server_info *info,
 
142
      void *userdata);
 
143
 
 
144
  template <const char *(pa_server_info::*field)>
 
145
  void OnGetDefaultDeviceCallback(
 
146
      const pa_server_info *info,
 
147
      SoundDeviceLocator **device);
 
148
 
 
149
  template <const char *(pa_server_info::*field)>
 
150
  bool GetDefaultDevice(SoundDeviceLocator **device);
 
151
 
 
152
  static void StreamStateChangedCallbackThunk(pa_stream *stream,
 
153
                                              void *userdata);
 
154
 
 
155
  void OnStreamStateChangedCallback(pa_stream *stream);
 
156
 
 
157
  template <typename StreamInterface>
 
158
  StreamInterface *OpenDevice(
 
159
      const SoundDeviceLocator *device,
 
160
      const OpenParams &params,
 
161
      const char *stream_name,
 
162
      StreamInterface *(PulseAudioSoundSystem::*connect_fn)(
 
163
          pa_stream *stream,
 
164
          const char *dev,
 
165
          int flags,
 
166
          pa_stream_flags_t pa_flags,
 
167
          int latency,
 
168
          const pa_sample_spec &spec));
 
169
 
 
170
  SoundOutputStreamInterface *ConnectOutputStream(
 
171
      pa_stream *stream,
 
172
      const char *dev,
 
173
      int flags,
 
174
      pa_stream_flags_t pa_flags,
 
175
      int latency,
 
176
      const pa_sample_spec &spec);
 
177
 
 
178
  SoundInputStreamInterface *ConnectInputStream(
 
179
      pa_stream *stream,
 
180
      const char *dev,
 
181
      int flags,
 
182
      pa_stream_flags_t pa_flags,
 
183
      int latency,
 
184
      const pa_sample_spec &spec);
 
185
 
 
186
  bool FinishOperation(pa_operation *op);
 
187
 
 
188
  void Lock();
 
189
  void Unlock();
 
190
  void Wait();
 
191
  void Signal();
 
192
 
 
193
  const char *LastError();
 
194
 
 
195
  pa_threaded_mainloop *mainloop_;
 
196
  pa_context *context_;
 
197
  PulseAudioSymbolTable symbol_table_;
 
198
 
 
199
  DISALLOW_COPY_AND_ASSIGN(PulseAudioSoundSystem);
 
200
};
 
201
 
 
202
}  // namespace cricket
 
203
 
 
204
#endif  // HAVE_LIBPULSE
 
205
 
 
206
#endif  // TALK_SOUND_PULSEAUDIOSOUNDSYSTEM_H_