blob: 5e5fa750f0cd2a2ff8e3526af3d55aa8bd544770 [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/**
Benny Prijono19a87c72010-01-27 17:22:17 +000062 * This setting controls whether native ALSA support should be included.
63 */
64#ifndef PJMEDIA_AUDIO_DEV_HAS_ALSA
65# define PJMEDIA_AUDIO_DEV_HAS_ALSA 0
66#endif
67
68
69/**
Sauw Ming60a0c9b2010-02-19 09:57:48 +000070 * This setting controls whether null audio support should be included.
71 */
72#ifndef PJMEDIA_AUDIO_DEV_HAS_NULL_AUDIO
73# define PJMEDIA_AUDIO_DEV_HAS_NULL_AUDIO 0
74#endif
75
76
77/**
Sauw Ming55a73cd2010-05-17 12:51:06 +000078 * This setting controls whether coreaudio support should be included.
79 */
80#ifndef PJMEDIA_AUDIO_DEV_HAS_COREAUDIO
Benny Prijonoc28d8452010-05-17 16:10:08 +000081# define PJMEDIA_AUDIO_DEV_HAS_COREAUDIO 0
Sauw Ming55a73cd2010-05-17 12:51:06 +000082#endif
83
84
85/**
Benny Prijono2058f472009-02-22 17:15:34 +000086 * This setting controls whether WMME support should be included.
87 */
88#ifndef PJMEDIA_AUDIO_DEV_HAS_WMME
89# define PJMEDIA_AUDIO_DEV_HAS_WMME 1
90#endif
91
92
93/**
Nanang Izzuddina940b362009-02-23 13:53:30 +000094 * This setting controls whether Symbian APS support should be included.
95 */
96#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_APS
97# define PJMEDIA_AUDIO_DEV_HAS_SYMB_APS 0
98#endif
99
100
101/**
Nanang Izzuddin0048fbd2010-04-07 13:21:31 +0000102 * This setting controls whether Symbian APS should perform codec
103 * detection in its factory initalization. Note that codec detection
104 * may take few seconds and detecting more codecs will take more time.
105 * Possible values are:
106 * - 0: no codec detection, all APS codec (AMR-NB, G.711, G.729, and
107 * iLBC) will be assumed as supported.
108 * - 1: minimal codec detection, i.e: only detect for AMR-NB and G.711,
109 * (G.729 and iLBC are considered to be supported/unsupported when
110 * G.711 is supported/unsupported).
111 * - 2: full codec detection, i.e: detect AMR-NB, G.711, G.729, and iLBC.
112 *
113 * Default: 1 (minimal codec detection)
114 */
115#ifndef PJMEDIA_AUDIO_DEV_SYMB_APS_DETECTS_CODEC
116# define PJMEDIA_AUDIO_DEV_SYMB_APS_DETECTS_CODEC 1
117#endif
118
119
120/**
Nanang Izzuddind687a502009-06-30 13:37:26 +0000121 * This setting controls whether Symbian VAS support should be included.
122 */
123#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS
124# define PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS 0
125#endif
126
Nanang Izzuddinfc279de2009-07-14 14:33:39 +0000127/**
128 * This setting controls Symbian VAS version to be used. Currently, valid
129 * values are only 1 (for VAS 1.0) and 2 (for VAS 2.0).
130 *
131 * Default: 1 (VAS version 1.0)
132 */
133#ifndef PJMEDIA_AUDIO_DEV_SYMB_VAS_VERSION
134# define PJMEDIA_AUDIO_DEV_SYMB_VAS_VERSION 1
135#endif
136
Nanang Izzuddind687a502009-06-30 13:37:26 +0000137
138/**
Nanang Izzuddina940b362009-02-23 13:53:30 +0000139 * This setting controls whether Symbian audio (using built-in multimedia
140 * framework) support should be included.
141 */
142#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA
Benny Prijono64f91382009-03-05 18:02:28 +0000143# define PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA PJ_SYMBIAN
Nanang Izzuddina940b362009-02-23 13:53:30 +0000144#endif
145
Benny Prijono64f91382009-03-05 18:02:28 +0000146
147/**
148 * This setting controls whether the Audio Device API should support
149 * device implementation that is based on the old sound device API
150 * (sound.h).
151 *
152 * Enable this API if:
153 * - you have implemented your own sound device using the old sound
154 * device API (sound.h), and
155 * - you wish to be able to use your sound device implementation
156 * using the new Audio Device API.
157 *
158 * Please see http://trac.pjsip.org/repos/wiki/Audio_Dev_API for more
159 * info.
160 */
161#ifndef PJMEDIA_AUDIO_DEV_HAS_LEGACY_DEVICE
162# define PJMEDIA_AUDIO_DEV_HAS_LEGACY_DEVICE 0
163#endif
164
165
Nanang Izzuddina940b362009-02-23 13:53:30 +0000166/**
Benny Prijono2058f472009-02-22 17:15:34 +0000167 * @}
168 */
169
170PJ_END_DECL
171
172
173#endif /* __PJMEDIA_AUDIODEV_CONFIG_H__ */
174
175/*
176 --------------------- DOCUMENTATION FOLLOWS ---------------------------
177 */
178
179/**
180 * @addtogroup audio_device_api Audio Device API
181 * @{
182
183PJMEDIA Audio Device API is a cross-platform audio API appropriate for use with
184VoIP applications and many other types of audio streaming applications.
185
186The API abstracts many different audio API's on various platforms, such as:
187 - PortAudio back-end for Win32, Windows Mobile, Linux, Unix, dan MacOS X.
188 - native WMME audio for Win32 and Windows Mobile devices
189 - native Symbian audio streaming/multimedia framework (MMF) implementation
190 - native Nokia Audio Proxy Server (APS) implementation
191 - null-audio implementation
192 - and more to be implemented in the future
193
194The Audio Device API/library is an evolution from PJMEDIA @ref PJMED_SND and
195contains many enhancements:
196
197 - Forward compatibility:
198\n
199 The new API has been designed to be extensible, it will support new API's as
200 well as new features that may be introduced in the future without breaking
201 compatibility with applications that use this API as well as compatibility
202 with existing device implementations.
203
204 - Device capabilities:
205\n
206 At the heart of the API is device capabilities management, where all possible
207 audio capabilities of audio devices should be able to be handled in a generic
208 manner. With this framework, new capabilities that may be discovered in the
209 future can be handled in manner without breaking existing applications.
210
211 - Built-in features:
212\n
Benny Prijonoeef2a872009-02-23 09:55:52 +0000213 The device capabilities framework enables applications to use and control
214 audio features built-in in the device, such as:
Benny Prijono2058f472009-02-22 17:15:34 +0000215 - echo cancellation,
216 - built-in codecs,
Benny Prijonoeef2a872009-02-23 09:55:52 +0000217 - audio routing (e.g. to earpiece or loudspeaker),
218 - volume control,
219 - etc.
Benny Prijono2058f472009-02-22 17:15:34 +0000220
221 - Codec support:
222\n
223 Some audio devices such as Nokia/Symbian Audio Proxy Server (APS) and Nokia
224 VoIP Audio Services (VAS) support built-in hardware audio codecs (e.g. G.729,
225 iLBC, and AMR), and application can use the sound device in encoded mode to
226 make use of these hardware codecs.
227
228 - Multiple backends:
229\n
230 The new API supports multiple audio backends (called factories or drivers in
231 the code) to be active simultaneously, and audio backends may be added or
232 removed during run-time.
Benny Prijonoeef2a872009-02-23 09:55:52 +0000233
234
235@section using Overview on using the API
236
237@subsection getting_started Getting started
238
239 -# <b>Configure the application's project settings</b>.\n
240 Add the following
241 include:
242 \code
243 #include <pjmedia_audiodev.h>\endcode\n
244 And add <b>pjmedia-audiodev</b> library to your application link
245 specifications.\n
246 -# <b>Compile time settings</b>.\n
247 Use the compile time settings to enable or
248 disable specific audio drivers. For more information, please see
249 \ref s1_audio_device_config.
250 -# <b>API initialization and cleaning up</b>.\n
251 Before anything else, application must initialize the API by calling:
252 \code
253 pjmedia_aud_subsys_init(pf);\endcode\n
254 And add this in the application cleanup sequence
255 \code
256 pjmedia_aud_subsys_shutdown();\endcode
257
258@subsection devices Working with devices
259
260 -# The following code prints the list of audio devices detected
261 in the system.
262 \code
263 int dev_count;
264 pjmedia_aud_dev_index dev_idx;
265 pj_status_t status;
266
267 dev_count = pjmedia_aud_dev_count();
268 printf("Got %d audio devices\n", dev_count);
269
270 for (dev_idx=0; dev_idx<dev_count; ++i) {
271 pjmedia_aud_dev_info info;
272
273 status = pjmedia_aud_dev_get_info(dev_idx, &info);
274 printf("%d. %s (in=%d, out=%d)\n",
275 dev_idx, info.name,
276 info.input_count, info.output_count);
277 }
278 \endcode\n
279 -# Info: The #PJMEDIA_AUD_DEFAULT_CAPTURE_DEV and #PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV
280 constants are used to denote default capture and playback devices
281 respectively.
282 -# Info: You may save the device and driver's name in your application
283 setting, for example to specify the prefered devices to be
284 used by your application. You can then retrieve the device index
285 for the device by calling:
286 \code
287 const char *drv_name = "WMME";
288 const char *dev_name = "Wave mapper";
289 pjmedia_aud_dev_index dev_idx;
290
291 status = pjmedia_aud_dev_lookup(drv_name, dev_name, &dev_idx);
292 if (status==PJ_SUCCESS)
293 printf("Device index is %d\n", dev_idx);
294 \endcode
295
296@subsection caps Device capabilities
297
298Capabilities are encoded as #pjmedia_aud_dev_cap enumeration. Please see
299#pjmedia_aud_dev_cap enumeration for more information.
300
301 -# The following snippet prints the capabilities supported by the device:
302 \code
303 pjmedia_aud_dev_info info;
304 pj_status_t status;
305
306 status = pjmedia_aud_dev_get_info(PJMEDIA_AUD_DEFAULT_CAPTURE_DEV, &info);
307 if (status == PJ_SUCCESS) {
308 unsigned i;
309 // Enumerate capability bits
310 printf("Device capabilities: ");
311 for (i=0; i<32; ++i) {
312 if (info.caps & (1 << i))
313 printf("%s ", pjmedia_aud_dev_cap_name(1 << i, NULL));
314 }
315 }
316 \endcode\n
317 -# Info: You can set the device settings when opening audio stream by setting
318 the flags and the appropriate setting in #pjmedia_aud_param when calling
319 #pjmedia_aud_stream_create()\n
320 -# Info: Once the audio stream is running, you can retrieve or change the stream
321 setting by specifying the capability in #pjmedia_aud_stream_get_cap()
322 and #pjmedia_aud_stream_set_cap() respectively.
323
324
325@subsection creating_stream Creating audio streams
326
327The audio stream enables audio streaming to capture device, playback device,
328or both.
329
330 -# It is recommended to initialize the #pjmedia_aud_param with its default
331 values before using it:
332 \code
333 pjmedia_aud_param param;
334 pjmedia_aud_dev_index dev_idx;
335 pj_status_t status;
336
337 dev_idx = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
338 status = pjmedia_aud_dev_default_param(dev_idx, &param);
339 \endcode\n
340 -# Configure the mandatory parameters:
341 \code
342 param.dir = PJMEDIA_DIR_CAPTURE_PLAYBACK;
343 param.rec_id = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
344 param.play_id = PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV;
345 param.clock_rate = 8000;
346 param.channel_count = 1;
347 param.samples_per_frame = 160;
348 param.bits_per_sample = 16;
349 \endcode\n
350 -# If you want the audio stream to use the device's built-in codec, specify
351 the codec in the #pjmedia_aud_param. You must make sure that the codec
352 is supported by the device, by looking at its supported format list in
353 the #pjmedia_aud_dev_info.\n
354 The snippet below sets the audio stream to use G.711 ULAW encoding:
355 \code
356 unsigned i;
357
358 // Make sure Ulaw is supported
359 if ((info.caps & PJMEDIA_AUD_DEV_CAP_EXT_FORMAT) == 0)
360 error("Device does not support extended formats");
361 for (i = 0; i < info.ext_fmt_cnt; ++i) {
362 if (info.ext_fmt[i].id == PJMEDIA_FORMAT_ULAW)
363 break;
364 }
365 if (i == info.ext_fmt_cnt)
366 error("Device does not support Ulaw format");
367
368 // Set Ulaw format
369 param.flags |= PJMEDIA_AUD_DEV_CAP_EXT_FORMAT;
370 param.ext_fmt.id = PJMEDIA_FORMAT_ULAW;
371 param.ext_fmt.bitrate = 64000;
372 param.ext_fmt.vad = PJ_FALSE;
373 \endcode\n
374 -# Note that if non-PCM format is configured on the audio stream, the
375 capture and/or playback functions (#pjmedia_aud_rec_cb and
376 #pjmedia_aud_play_cb respectively) will report the audio frame as
377 #pjmedia_frame_ext structure instead of the #pjmedia_frame.
378 -# Optionally configure other device's capabilities. The following snippet
379 shows how to enable echo cancellation on the device (note that this
380 snippet may not be necessary since the setting may have been enabled
381 when calling #pjmedia_aud_dev_default_param() above):
382 \code
383 if (info.caps & PJMEDIA_AUD_DEV_CAP_EC) {
384 param.flags |= PJMEDIA_AUD_DEV_CAP_EC;
385 param.ec_enabled = PJ_TRUE;
386 }
387 \endcode
388 -# Open the audio stream, specifying the capture and/or playback callback
389 functions:
390 \code
391 pjmedia_aud_stream *stream;
392
393 status = pjmedia_aud_stream_create(&param, &rec_cb, &play_cb,
394 user_data, &stream);
395 \endcode
396
397@subsection working_with_stream Working with audio streams
398
399 -# To start the audio stream:
400 \code
401 status = pjmedia_aud_stream_start(stream);
402 \endcode\n
403 To stop the stream:
404 \code
405 status = pjmedia_aud_stream_stop(stream);
406 \endcode\n
407 And to destroy the stream:
408 \code
409 status = pjmedia_aud_stream_destroy(stream);
410 \endcode\n
411 -# Info: The following shows how to retrieve the capability value of the
412 stream (in this case, the current output volume setting).
413 \code
414 // Volume setting is an unsigned integer showing the level in percent.
415 unsigned vol;
416 status = pjmedia_aud_stream_get_cap(stream,
417 PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,
418 &vol);
419 \endcode
420 -# Info: And following shows how to modify the capability value of the
421 stream (in this case, the current output volume setting).
422 \code
423 // Volume setting is an unsigned integer showing the level in percent.
424 unsigned vol = 50;
425 status = pjmedia_aud_stream_set_cap(stream,
426 PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,
427 &vol);
428 \endcode
429
430
431*/
432
Benny Prijono2058f472009-02-22 17:15:34 +0000433
434/**
435 * @}
436 */
437