blob: 937e391abb4dc2e57605dae0929022cfdbc7cfd4 [file] [log] [blame]
Benny Prijono2058f472009-02-22 17:15:34 +00001/* $Id$ */
2/*
3 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#ifndef __PJMEDIA_AUDIODEV_CONFIG_H__
21#define __PJMEDIA_AUDIODEV_CONFIG_H__
22
23/**
24 * @file audiodev.h
25 * @brief Audio device API.
26 */
Benny Prijono64f91382009-03-05 18:02:28 +000027#include <pjmedia/types.h>
Benny Prijono2058f472009-02-22 17:15:34 +000028#include <pj/pool.h>
29
30
31PJ_BEGIN_DECL
32
33/**
34 * @defgroup audio_device_api Audio Device API
35 * @brief PJMEDIA audio device abstraction API.
36 */
37
38/**
39 * @defgroup s1_audio_device_config Compile time configurations
40 * @ingroup audio_device_api
41 * @brief Compile time configurations
42 * @{
43 */
44
45/**
46 * This setting controls whether PortAudio support should be included.
Benny Prijonoa8fd3842009-10-29 09:39:17 +000047 *
48 * By default it is enabled except on Windows platforms (including
49 * Windows Mobile) and Symbian.
Benny Prijono2058f472009-02-22 17:15:34 +000050 */
51#ifndef PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO
Benny Prijonoa8fd3842009-10-29 09:39:17 +000052# if (defined(PJ_WIN32) && PJ_WIN32!=0) || \
53 (defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0)
54# define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 0
55# else
56# define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 1
57# endif
Benny Prijono2058f472009-02-22 17:15:34 +000058#endif
59
60
61/**
62 * This setting controls whether WMME support should be included.
63 */
64#ifndef PJMEDIA_AUDIO_DEV_HAS_WMME
65# define PJMEDIA_AUDIO_DEV_HAS_WMME 1
66#endif
67
68
69/**
Nanang Izzuddina940b362009-02-23 13:53:30 +000070 * This setting controls whether Symbian APS support should be included.
71 */
72#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_APS
73# define PJMEDIA_AUDIO_DEV_HAS_SYMB_APS 0
74#endif
75
76
77/**
Nanang Izzuddind687a502009-06-30 13:37:26 +000078 * This setting controls whether Symbian VAS support should be included.
79 */
80#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS
81# define PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS 0
82#endif
83
Nanang Izzuddinfc279de2009-07-14 14:33:39 +000084/**
85 * This setting controls Symbian VAS version to be used. Currently, valid
86 * values are only 1 (for VAS 1.0) and 2 (for VAS 2.0).
87 *
88 * Default: 1 (VAS version 1.0)
89 */
90#ifndef PJMEDIA_AUDIO_DEV_SYMB_VAS_VERSION
91# define PJMEDIA_AUDIO_DEV_SYMB_VAS_VERSION 1
92#endif
93
Nanang Izzuddind687a502009-06-30 13:37:26 +000094
95/**
Nanang Izzuddina940b362009-02-23 13:53:30 +000096 * This setting controls whether Symbian audio (using built-in multimedia
97 * framework) support should be included.
98 */
99#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA
Benny Prijono64f91382009-03-05 18:02:28 +0000100# define PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA PJ_SYMBIAN
Nanang Izzuddina940b362009-02-23 13:53:30 +0000101#endif
102
Benny Prijono64f91382009-03-05 18:02:28 +0000103
104/**
105 * This setting controls whether the Audio Device API should support
106 * device implementation that is based on the old sound device API
107 * (sound.h).
108 *
109 * Enable this API if:
110 * - you have implemented your own sound device using the old sound
111 * device API (sound.h), and
112 * - you wish to be able to use your sound device implementation
113 * using the new Audio Device API.
114 *
115 * Please see http://trac.pjsip.org/repos/wiki/Audio_Dev_API for more
116 * info.
117 */
118#ifndef PJMEDIA_AUDIO_DEV_HAS_LEGACY_DEVICE
119# define PJMEDIA_AUDIO_DEV_HAS_LEGACY_DEVICE 0
120#endif
121
122
Nanang Izzuddina940b362009-02-23 13:53:30 +0000123/**
Benny Prijono2058f472009-02-22 17:15:34 +0000124 * @}
125 */
126
127PJ_END_DECL
128
129
130#endif /* __PJMEDIA_AUDIODEV_CONFIG_H__ */
131
132/*
133 --------------------- DOCUMENTATION FOLLOWS ---------------------------
134 */
135
136/**
137 * @addtogroup audio_device_api Audio Device API
138 * @{
139
140PJMEDIA Audio Device API is a cross-platform audio API appropriate for use with
141VoIP applications and many other types of audio streaming applications.
142
143The API abstracts many different audio API's on various platforms, such as:
144 - PortAudio back-end for Win32, Windows Mobile, Linux, Unix, dan MacOS X.
145 - native WMME audio for Win32 and Windows Mobile devices
146 - native Symbian audio streaming/multimedia framework (MMF) implementation
147 - native Nokia Audio Proxy Server (APS) implementation
148 - null-audio implementation
149 - and more to be implemented in the future
150
151The Audio Device API/library is an evolution from PJMEDIA @ref PJMED_SND and
152contains many enhancements:
153
154 - Forward compatibility:
155\n
156 The new API has been designed to be extensible, it will support new API's as
157 well as new features that may be introduced in the future without breaking
158 compatibility with applications that use this API as well as compatibility
159 with existing device implementations.
160
161 - Device capabilities:
162\n
163 At the heart of the API is device capabilities management, where all possible
164 audio capabilities of audio devices should be able to be handled in a generic
165 manner. With this framework, new capabilities that may be discovered in the
166 future can be handled in manner without breaking existing applications.
167
168 - Built-in features:
169\n
Benny Prijonoeef2a872009-02-23 09:55:52 +0000170 The device capabilities framework enables applications to use and control
171 audio features built-in in the device, such as:
Benny Prijono2058f472009-02-22 17:15:34 +0000172 - echo cancellation,
173 - built-in codecs,
Benny Prijonoeef2a872009-02-23 09:55:52 +0000174 - audio routing (e.g. to earpiece or loudspeaker),
175 - volume control,
176 - etc.
Benny Prijono2058f472009-02-22 17:15:34 +0000177
178 - Codec support:
179\n
180 Some audio devices such as Nokia/Symbian Audio Proxy Server (APS) and Nokia
181 VoIP Audio Services (VAS) support built-in hardware audio codecs (e.g. G.729,
182 iLBC, and AMR), and application can use the sound device in encoded mode to
183 make use of these hardware codecs.
184
185 - Multiple backends:
186\n
187 The new API supports multiple audio backends (called factories or drivers in
188 the code) to be active simultaneously, and audio backends may be added or
189 removed during run-time.
Benny Prijonoeef2a872009-02-23 09:55:52 +0000190
191
192@section using Overview on using the API
193
194@subsection getting_started Getting started
195
196 -# <b>Configure the application's project settings</b>.\n
197 Add the following
198 include:
199 \code
200 #include <pjmedia_audiodev.h>\endcode\n
201 And add <b>pjmedia-audiodev</b> library to your application link
202 specifications.\n
203 -# <b>Compile time settings</b>.\n
204 Use the compile time settings to enable or
205 disable specific audio drivers. For more information, please see
206 \ref s1_audio_device_config.
207 -# <b>API initialization and cleaning up</b>.\n
208 Before anything else, application must initialize the API by calling:
209 \code
210 pjmedia_aud_subsys_init(pf);\endcode\n
211 And add this in the application cleanup sequence
212 \code
213 pjmedia_aud_subsys_shutdown();\endcode
214
215@subsection devices Working with devices
216
217 -# The following code prints the list of audio devices detected
218 in the system.
219 \code
220 int dev_count;
221 pjmedia_aud_dev_index dev_idx;
222 pj_status_t status;
223
224 dev_count = pjmedia_aud_dev_count();
225 printf("Got %d audio devices\n", dev_count);
226
227 for (dev_idx=0; dev_idx<dev_count; ++i) {
228 pjmedia_aud_dev_info info;
229
230 status = pjmedia_aud_dev_get_info(dev_idx, &info);
231 printf("%d. %s (in=%d, out=%d)\n",
232 dev_idx, info.name,
233 info.input_count, info.output_count);
234 }
235 \endcode\n
236 -# Info: The #PJMEDIA_AUD_DEFAULT_CAPTURE_DEV and #PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV
237 constants are used to denote default capture and playback devices
238 respectively.
239 -# Info: You may save the device and driver's name in your application
240 setting, for example to specify the prefered devices to be
241 used by your application. You can then retrieve the device index
242 for the device by calling:
243 \code
244 const char *drv_name = "WMME";
245 const char *dev_name = "Wave mapper";
246 pjmedia_aud_dev_index dev_idx;
247
248 status = pjmedia_aud_dev_lookup(drv_name, dev_name, &dev_idx);
249 if (status==PJ_SUCCESS)
250 printf("Device index is %d\n", dev_idx);
251 \endcode
252
253@subsection caps Device capabilities
254
255Capabilities are encoded as #pjmedia_aud_dev_cap enumeration. Please see
256#pjmedia_aud_dev_cap enumeration for more information.
257
258 -# The following snippet prints the capabilities supported by the device:
259 \code
260 pjmedia_aud_dev_info info;
261 pj_status_t status;
262
263 status = pjmedia_aud_dev_get_info(PJMEDIA_AUD_DEFAULT_CAPTURE_DEV, &info);
264 if (status == PJ_SUCCESS) {
265 unsigned i;
266 // Enumerate capability bits
267 printf("Device capabilities: ");
268 for (i=0; i<32; ++i) {
269 if (info.caps & (1 << i))
270 printf("%s ", pjmedia_aud_dev_cap_name(1 << i, NULL));
271 }
272 }
273 \endcode\n
274 -# Info: You can set the device settings when opening audio stream by setting
275 the flags and the appropriate setting in #pjmedia_aud_param when calling
276 #pjmedia_aud_stream_create()\n
277 -# Info: Once the audio stream is running, you can retrieve or change the stream
278 setting by specifying the capability in #pjmedia_aud_stream_get_cap()
279 and #pjmedia_aud_stream_set_cap() respectively.
280
281
282@subsection creating_stream Creating audio streams
283
284The audio stream enables audio streaming to capture device, playback device,
285or both.
286
287 -# It is recommended to initialize the #pjmedia_aud_param with its default
288 values before using it:
289 \code
290 pjmedia_aud_param param;
291 pjmedia_aud_dev_index dev_idx;
292 pj_status_t status;
293
294 dev_idx = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
295 status = pjmedia_aud_dev_default_param(dev_idx, &param);
296 \endcode\n
297 -# Configure the mandatory parameters:
298 \code
299 param.dir = PJMEDIA_DIR_CAPTURE_PLAYBACK;
300 param.rec_id = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
301 param.play_id = PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV;
302 param.clock_rate = 8000;
303 param.channel_count = 1;
304 param.samples_per_frame = 160;
305 param.bits_per_sample = 16;
306 \endcode\n
307 -# If you want the audio stream to use the device's built-in codec, specify
308 the codec in the #pjmedia_aud_param. You must make sure that the codec
309 is supported by the device, by looking at its supported format list in
310 the #pjmedia_aud_dev_info.\n
311 The snippet below sets the audio stream to use G.711 ULAW encoding:
312 \code
313 unsigned i;
314
315 // Make sure Ulaw is supported
316 if ((info.caps & PJMEDIA_AUD_DEV_CAP_EXT_FORMAT) == 0)
317 error("Device does not support extended formats");
318 for (i = 0; i < info.ext_fmt_cnt; ++i) {
319 if (info.ext_fmt[i].id == PJMEDIA_FORMAT_ULAW)
320 break;
321 }
322 if (i == info.ext_fmt_cnt)
323 error("Device does not support Ulaw format");
324
325 // Set Ulaw format
326 param.flags |= PJMEDIA_AUD_DEV_CAP_EXT_FORMAT;
327 param.ext_fmt.id = PJMEDIA_FORMAT_ULAW;
328 param.ext_fmt.bitrate = 64000;
329 param.ext_fmt.vad = PJ_FALSE;
330 \endcode\n
331 -# Note that if non-PCM format is configured on the audio stream, the
332 capture and/or playback functions (#pjmedia_aud_rec_cb and
333 #pjmedia_aud_play_cb respectively) will report the audio frame as
334 #pjmedia_frame_ext structure instead of the #pjmedia_frame.
335 -# Optionally configure other device's capabilities. The following snippet
336 shows how to enable echo cancellation on the device (note that this
337 snippet may not be necessary since the setting may have been enabled
338 when calling #pjmedia_aud_dev_default_param() above):
339 \code
340 if (info.caps & PJMEDIA_AUD_DEV_CAP_EC) {
341 param.flags |= PJMEDIA_AUD_DEV_CAP_EC;
342 param.ec_enabled = PJ_TRUE;
343 }
344 \endcode
345 -# Open the audio stream, specifying the capture and/or playback callback
346 functions:
347 \code
348 pjmedia_aud_stream *stream;
349
350 status = pjmedia_aud_stream_create(&param, &rec_cb, &play_cb,
351 user_data, &stream);
352 \endcode
353
354@subsection working_with_stream Working with audio streams
355
356 -# To start the audio stream:
357 \code
358 status = pjmedia_aud_stream_start(stream);
359 \endcode\n
360 To stop the stream:
361 \code
362 status = pjmedia_aud_stream_stop(stream);
363 \endcode\n
364 And to destroy the stream:
365 \code
366 status = pjmedia_aud_stream_destroy(stream);
367 \endcode\n
368 -# Info: The following shows how to retrieve the capability value of the
369 stream (in this case, the current output volume setting).
370 \code
371 // Volume setting is an unsigned integer showing the level in percent.
372 unsigned vol;
373 status = pjmedia_aud_stream_get_cap(stream,
374 PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,
375 &vol);
376 \endcode
377 -# Info: And following shows how to modify the capability value of the
378 stream (in this case, the current output volume setting).
379 \code
380 // Volume setting is an unsigned integer showing the level in percent.
381 unsigned vol = 50;
382 status = pjmedia_aud_stream_set_cap(stream,
383 PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,
384 &vol);
385 \endcode
386
387
388*/
389
Benny Prijono2058f472009-02-22 17:15:34 +0000390
391/**
392 * @}
393 */
394