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