1
/* $Id: config.h 4150 2012-06-01 04:29:56Z ming $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
20
#ifndef __PJMEDIA_AUDIODEV_CONFIG_H__
21
#define __PJMEDIA_AUDIODEV_CONFIG_H__
25
* @brief Audio config.
27
#include <pjmedia/types.h>
34
* @defgroup audio_device_api Audio Device API
35
* @brief PJMEDIA audio device abstraction API.
39
* @defgroup s1_audio_device_config Compile time configurations
40
* @ingroup audio_device_api
41
* @brief Compile time configurations
46
* This setting controls whether PortAudio support should be included.
48
* By default it is enabled except on Windows platforms (including
49
* Windows Mobile) and Symbian.
51
#ifndef PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO
52
# if (defined(PJ_WIN32) && PJ_WIN32!=0) || \
53
(defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0)
54
# define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 0
56
# define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 1
61
* This setting controls whether BlackBerry 10 (BB10) audio support
64
#ifndef PJMEDIA_AUDIO_DEV_HAS_BB10
65
# define PJMEDIA_AUDIO_DEV_HAS_BB10 0
69
* This setting controls whether native ALSA support should be included.
71
#ifndef PJMEDIA_AUDIO_DEV_HAS_ALSA
72
# define PJMEDIA_AUDIO_DEV_HAS_ALSA 0
77
* This setting controls whether null audio support should be included.
79
#ifndef PJMEDIA_AUDIO_DEV_HAS_NULL_AUDIO
80
# define PJMEDIA_AUDIO_DEV_HAS_NULL_AUDIO 0
85
* This setting controls whether coreaudio support should be included.
87
#ifndef PJMEDIA_AUDIO_DEV_HAS_COREAUDIO
88
# define PJMEDIA_AUDIO_DEV_HAS_COREAUDIO 0
93
* This setting controls whether WMME support should be included.
95
#ifndef PJMEDIA_AUDIO_DEV_HAS_WMME
96
# define PJMEDIA_AUDIO_DEV_HAS_WMME 1
101
* This setting controls whether Symbian APS support should be included.
103
#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_APS
104
# define PJMEDIA_AUDIO_DEV_HAS_SYMB_APS 0
109
* This setting controls whether Symbian APS should perform codec
110
* detection in its factory initalization. Note that codec detection
111
* may take few seconds and detecting more codecs will take more time.
112
* Possible values are:
113
* - 0: no codec detection, all APS codec (AMR-NB, G.711, G.729, and
114
* iLBC) will be assumed as supported.
115
* - 1: minimal codec detection, i.e: only detect for AMR-NB and G.711,
116
* (G.729 and iLBC are considered to be supported/unsupported when
117
* G.711 is supported/unsupported).
118
* - 2: full codec detection, i.e: detect AMR-NB, G.711, G.729, and iLBC.
120
* Default: 1 (minimal codec detection)
122
#ifndef PJMEDIA_AUDIO_DEV_SYMB_APS_DETECTS_CODEC
123
# define PJMEDIA_AUDIO_DEV_SYMB_APS_DETECTS_CODEC 1
128
* This setting controls whether Symbian VAS support should be included.
130
#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS
131
# define PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS 0
135
* This setting controls Symbian VAS version to be used. Currently, valid
136
* values are only 1 (for VAS 1.0) and 2 (for VAS 2.0).
138
* Default: 1 (VAS version 1.0)
140
#ifndef PJMEDIA_AUDIO_DEV_SYMB_VAS_VERSION
141
# define PJMEDIA_AUDIO_DEV_SYMB_VAS_VERSION 1
146
* This setting controls whether Symbian audio (using built-in multimedia
147
* framework) support should be included.
149
#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA
150
# define PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA PJ_SYMBIAN
155
* This setting controls whether the Symbian audio with built-in multimedia
156
* framework backend should be started synchronously. Note that synchronous
157
* start will block the application/UI, e.g: about 40ms for each direction
158
* on N95. While asynchronous start may cause invalid value (always zero)
159
* returned in input/output volume query, if the query is performed when
160
* the internal start procedure is not completely finished.
164
#ifndef PJMEDIA_AUDIO_DEV_MDA_USE_SYNC_START
165
# define PJMEDIA_AUDIO_DEV_MDA_USE_SYNC_START 1
170
* This setting controls whether the Audio Device API should support
171
* device implementation that is based on the old sound device API
174
* Enable this API if:
175
* - you have implemented your own sound device using the old sound
176
* device API (sound.h), and
177
* - you wish to be able to use your sound device implementation
178
* using the new Audio Device API.
180
* Please see http://trac.pjsip.org/repos/wiki/Audio_Dev_API for more
183
#ifndef PJMEDIA_AUDIO_DEV_HAS_LEGACY_DEVICE
184
# define PJMEDIA_AUDIO_DEV_HAS_LEGACY_DEVICE 0
195
#endif /* __PJMEDIA_AUDIODEV_CONFIG_H__ */
198
--------------------- DOCUMENTATION FOLLOWS ---------------------------
202
* @addtogroup audio_device_api Audio Device API
205
PJMEDIA Audio Device API is a cross-platform audio API appropriate for use with
206
VoIP applications and many other types of audio streaming applications.
208
The API abstracts many different audio API's on various platforms, such as:
209
- PortAudio back-end for Win32, Windows Mobile, Linux, Unix, dan MacOS X.
210
- native WMME audio for Win32 and Windows Mobile devices
211
- native Symbian audio streaming/multimedia framework (MMF) implementation
212
- native Nokia Audio Proxy Server (APS) implementation
213
- null-audio implementation
214
- and more to be implemented in the future
216
The Audio Device API/library is an evolution from PJMEDIA @ref PJMED_SND and
217
contains many enhancements:
219
- Forward compatibility:
221
The new API has been designed to be extensible, it will support new API's as
222
well as new features that may be introduced in the future without breaking
223
compatibility with applications that use this API as well as compatibility
224
with existing device implementations.
226
- Device capabilities:
228
At the heart of the API is device capabilities management, where all possible
229
audio capabilities of audio devices should be able to be handled in a generic
230
manner. With this framework, new capabilities that may be discovered in the
231
future can be handled in manner without breaking existing applications.
235
The device capabilities framework enables applications to use and control
236
audio features built-in in the device, such as:
239
- audio routing (e.g. to earpiece or loudspeaker),
245
Some audio devices such as Nokia/Symbian Audio Proxy Server (APS) and Nokia
246
VoIP Audio Services (VAS) support built-in hardware audio codecs (e.g. G.729,
247
iLBC, and AMR), and application can use the sound device in encoded mode to
248
make use of these hardware codecs.
252
The new API supports multiple audio backends (called factories or drivers in
253
the code) to be active simultaneously, and audio backends may be added or
254
removed during run-time.
257
@section using Overview on using the API
259
@subsection getting_started Getting started
261
-# <b>Configure the application's project settings</b>.\n
265
#include <pjmedia_audiodev.h>\endcode\n
266
And add <b>pjmedia-audiodev</b> library to your application link
268
-# <b>Compile time settings</b>.\n
269
Use the compile time settings to enable or
270
disable specific audio drivers. For more information, please see
271
\ref s1_audio_device_config.
272
-# <b>API initialization and cleaning up</b>.\n
273
Before anything else, application must initialize the API by calling:
275
pjmedia_aud_subsys_init(pf);\endcode\n
276
And add this in the application cleanup sequence
278
pjmedia_aud_subsys_shutdown();\endcode
280
@subsection devices Working with devices
282
-# The following code prints the list of audio devices detected
286
pjmedia_aud_dev_index dev_idx;
289
dev_count = pjmedia_aud_dev_count();
290
printf("Got %d audio devices\n", dev_count);
292
for (dev_idx=0; dev_idx<dev_count; ++i) {
293
pjmedia_aud_dev_info info;
295
status = pjmedia_aud_dev_get_info(dev_idx, &info);
296
printf("%d. %s (in=%d, out=%d)\n",
298
info.input_count, info.output_count);
301
-# Info: The #PJMEDIA_AUD_DEFAULT_CAPTURE_DEV and #PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV
302
constants are used to denote default capture and playback devices
304
-# Info: You may save the device and driver's name in your application
305
setting, for example to specify the prefered devices to be
306
used by your application. You can then retrieve the device index
307
for the device by calling:
309
const char *drv_name = "WMME";
310
const char *dev_name = "Wave mapper";
311
pjmedia_aud_dev_index dev_idx;
313
status = pjmedia_aud_dev_lookup(drv_name, dev_name, &dev_idx);
314
if (status==PJ_SUCCESS)
315
printf("Device index is %d\n", dev_idx);
318
@subsection caps Device capabilities
320
Capabilities are encoded as #pjmedia_aud_dev_cap enumeration. Please see
321
#pjmedia_aud_dev_cap enumeration for more information.
323
-# The following snippet prints the capabilities supported by the device:
325
pjmedia_aud_dev_info info;
328
status = pjmedia_aud_dev_get_info(PJMEDIA_AUD_DEFAULT_CAPTURE_DEV, &info);
329
if (status == PJ_SUCCESS) {
331
// Enumerate capability bits
332
printf("Device capabilities: ");
333
for (i=0; i<32; ++i) {
334
if (info.caps & (1 << i))
335
printf("%s ", pjmedia_aud_dev_cap_name(1 << i, NULL));
339
-# Info: You can set the device settings when opening audio stream by setting
340
the flags and the appropriate setting in #pjmedia_aud_param when calling
341
#pjmedia_aud_stream_create()\n
342
-# Info: Once the audio stream is running, you can retrieve or change the stream
343
setting by specifying the capability in #pjmedia_aud_stream_get_cap()
344
and #pjmedia_aud_stream_set_cap() respectively.
347
@subsection creating_stream Creating audio streams
349
The audio stream enables audio streaming to capture device, playback device,
352
-# It is recommended to initialize the #pjmedia_aud_param with its default
353
values before using it:
355
pjmedia_aud_param param;
356
pjmedia_aud_dev_index dev_idx;
359
dev_idx = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
360
status = pjmedia_aud_dev_default_param(dev_idx, ¶m);
362
-# Configure the mandatory parameters:
364
param.dir = PJMEDIA_DIR_CAPTURE_PLAYBACK;
365
param.rec_id = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
366
param.play_id = PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV;
367
param.clock_rate = 8000;
368
param.channel_count = 1;
369
param.samples_per_frame = 160;
370
param.bits_per_sample = 16;
372
-# If you want the audio stream to use the device's built-in codec, specify
373
the codec in the #pjmedia_aud_param. You must make sure that the codec
374
is supported by the device, by looking at its supported format list in
375
the #pjmedia_aud_dev_info.\n
376
The snippet below sets the audio stream to use G.711 ULAW encoding:
380
// Make sure Ulaw is supported
381
if ((info.caps & PJMEDIA_AUD_DEV_CAP_EXT_FORMAT) == 0)
382
error("Device does not support extended formats");
383
for (i = 0; i < info.ext_fmt_cnt; ++i) {
384
if (info.ext_fmt[i].id == PJMEDIA_FORMAT_ULAW)
387
if (i == info.ext_fmt_cnt)
388
error("Device does not support Ulaw format");
391
param.flags |= PJMEDIA_AUD_DEV_CAP_EXT_FORMAT;
392
param.ext_fmt.id = PJMEDIA_FORMAT_ULAW;
393
param.ext_fmt.bitrate = 64000;
394
param.ext_fmt.vad = PJ_FALSE;
396
-# Note that if non-PCM format is configured on the audio stream, the
397
capture and/or playback functions (#pjmedia_aud_rec_cb and
398
#pjmedia_aud_play_cb respectively) will report the audio frame as
399
#pjmedia_frame_ext structure instead of the #pjmedia_frame.
400
-# Optionally configure other device's capabilities. The following snippet
401
shows how to enable echo cancellation on the device (note that this
402
snippet may not be necessary since the setting may have been enabled
403
when calling #pjmedia_aud_dev_default_param() above):
405
if (info.caps & PJMEDIA_AUD_DEV_CAP_EC) {
406
param.flags |= PJMEDIA_AUD_DEV_CAP_EC;
407
param.ec_enabled = PJ_TRUE;
410
-# Open the audio stream, specifying the capture and/or playback callback
413
pjmedia_aud_stream *stream;
415
status = pjmedia_aud_stream_create(¶m, &rec_cb, &play_cb,
419
@subsection working_with_stream Working with audio streams
421
-# To start the audio stream:
423
status = pjmedia_aud_stream_start(stream);
427
status = pjmedia_aud_stream_stop(stream);
429
And to destroy the stream:
431
status = pjmedia_aud_stream_destroy(stream);
433
-# Info: The following shows how to retrieve the capability value of the
434
stream (in this case, the current output volume setting).
436
// Volume setting is an unsigned integer showing the level in percent.
438
status = pjmedia_aud_stream_get_cap(stream,
439
PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,
442
-# Info: And following shows how to modify the capability value of the
443
stream (in this case, the current output volume setting).
445
// Volume setting is an unsigned integer showing the level in percent.
447
status = pjmedia_aud_stream_set_cap(stream,
448
PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,