1
/* $Id: config.h 4537 2013-06-19 06:47:43Z riza $ */
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_WIN64) && PJ_WIN64!=0) || \
54
(defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0)
55
# define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 0
57
# define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 1
62
* This setting controls whether Android OpenSL audio support should be
65
#ifndef PJMEDIA_AUDIO_DEV_HAS_OPENSL
66
# define PJMEDIA_AUDIO_DEV_HAS_OPENSL 0
70
* This setting controls whether Android JNI audio support should be
73
#ifndef PJMEDIA_AUDIO_DEV_HAS_ANDROID_JNI
74
# define PJMEDIA_AUDIO_DEV_HAS_ANDROID_JNI 0
78
* This setting controls whether BlackBerry 10 (BB10) audio support
81
#ifndef PJMEDIA_AUDIO_DEV_HAS_BB10
82
# define PJMEDIA_AUDIO_DEV_HAS_BB10 0
86
* This setting controls whether native ALSA support should be included.
88
#ifndef PJMEDIA_AUDIO_DEV_HAS_ALSA
89
# define PJMEDIA_AUDIO_DEV_HAS_ALSA 0
94
* This setting controls whether null audio support should be included.
96
#ifndef PJMEDIA_AUDIO_DEV_HAS_NULL_AUDIO
97
# define PJMEDIA_AUDIO_DEV_HAS_NULL_AUDIO 0
102
* This setting controls whether coreaudio support should be included.
104
#ifndef PJMEDIA_AUDIO_DEV_HAS_COREAUDIO
105
# define PJMEDIA_AUDIO_DEV_HAS_COREAUDIO 0
110
* This setting controls whether WMME support should be included.
112
#ifndef PJMEDIA_AUDIO_DEV_HAS_WMME
113
# define PJMEDIA_AUDIO_DEV_HAS_WMME 1
118
* This setting controls whether BDIMAD support should be included.
120
#ifndef PJMEDIA_AUDIO_DEV_HAS_BDIMAD
121
# define PJMEDIA_AUDIO_DEV_HAS_BDIMAD 0
126
* This setting controls whether Symbian APS support should be included.
128
#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_APS
129
# define PJMEDIA_AUDIO_DEV_HAS_SYMB_APS 0
134
* This setting controls whether Symbian APS should perform codec
135
* detection in its factory initalization. Note that codec detection
136
* may take few seconds and detecting more codecs will take more time.
137
* Possible values are:
138
* - 0: no codec detection, all APS codec (AMR-NB, G.711, G.729, and
139
* iLBC) will be assumed as supported.
140
* - 1: minimal codec detection, i.e: only detect for AMR-NB and G.711,
141
* (G.729 and iLBC are considered to be supported/unsupported when
142
* G.711 is supported/unsupported).
143
* - 2: full codec detection, i.e: detect AMR-NB, G.711, G.729, and iLBC.
145
* Default: 1 (minimal codec detection)
147
#ifndef PJMEDIA_AUDIO_DEV_SYMB_APS_DETECTS_CODEC
148
# define PJMEDIA_AUDIO_DEV_SYMB_APS_DETECTS_CODEC 1
153
* This setting controls whether Symbian VAS support should be included.
155
#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS
156
# define PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS 0
160
* This setting controls Symbian VAS version to be used. Currently, valid
161
* values are only 1 (for VAS 1.0) and 2 (for VAS 2.0).
163
* Default: 1 (VAS version 1.0)
165
#ifndef PJMEDIA_AUDIO_DEV_SYMB_VAS_VERSION
166
# define PJMEDIA_AUDIO_DEV_SYMB_VAS_VERSION 1
171
* This setting controls whether Symbian audio (using built-in multimedia
172
* framework) support should be included.
174
#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA
175
# define PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA PJ_SYMBIAN
180
* This setting controls whether the Symbian audio with built-in multimedia
181
* framework backend should be started synchronously. Note that synchronous
182
* start will block the application/UI, e.g: about 40ms for each direction
183
* on N95. While asynchronous start may cause invalid value (always zero)
184
* returned in input/output volume query, if the query is performed when
185
* the internal start procedure is not completely finished.
189
#ifndef PJMEDIA_AUDIO_DEV_MDA_USE_SYNC_START
190
# define PJMEDIA_AUDIO_DEV_MDA_USE_SYNC_START 1
195
* This setting controls whether the Audio Device API should support
196
* device implementation that is based on the old sound device API
199
* Enable this API if:
200
* - you have implemented your own sound device using the old sound
201
* device API (sound.h), and
202
* - you wish to be able to use your sound device implementation
203
* using the new Audio Device API.
205
* Please see http://trac.pjsip.org/repos/wiki/Audio_Dev_API for more
208
#ifndef PJMEDIA_AUDIO_DEV_HAS_LEGACY_DEVICE
209
# define PJMEDIA_AUDIO_DEV_HAS_LEGACY_DEVICE 0
220
#endif /* __PJMEDIA_AUDIODEV_CONFIG_H__ */
223
--------------------- DOCUMENTATION FOLLOWS ---------------------------
227
* @addtogroup audio_device_api Audio Device API
230
PJMEDIA Audio Device API is a cross-platform audio API appropriate for use with
231
VoIP applications and many other types of audio streaming applications.
233
The API abstracts many different audio API's on various platforms, such as:
234
- PortAudio back-end for Win32, Windows Mobile, Linux, Unix, dan MacOS X.
235
- native WMME audio for Win32 and Windows Mobile devices
236
- native Symbian audio streaming/multimedia framework (MMF) implementation
237
- native Nokia Audio Proxy Server (APS) implementation
238
- null-audio implementation
239
- and more to be implemented in the future
241
The Audio Device API/library is an evolution from PJMEDIA @ref PJMED_SND and
242
contains many enhancements:
244
- Forward compatibility:
246
The new API has been designed to be extensible, it will support new API's as
247
well as new features that may be introduced in the future without breaking
248
compatibility with applications that use this API as well as compatibility
249
with existing device implementations.
251
- Device capabilities:
253
At the heart of the API is device capabilities management, where all possible
254
audio capabilities of audio devices should be able to be handled in a generic
255
manner. With this framework, new capabilities that may be discovered in the
256
future can be handled in manner without breaking existing applications.
260
The device capabilities framework enables applications to use and control
261
audio features built-in in the device, such as:
264
- audio routing (e.g. to earpiece or loudspeaker),
270
Some audio devices such as Nokia/Symbian Audio Proxy Server (APS) and Nokia
271
VoIP Audio Services (VAS) support built-in hardware audio codecs (e.g. G.729,
272
iLBC, and AMR), and application can use the sound device in encoded mode to
273
make use of these hardware codecs.
277
The new API supports multiple audio backends (called factories or drivers in
278
the code) to be active simultaneously, and audio backends may be added or
279
removed during run-time.
282
@section using Overview on using the API
284
@subsection getting_started Getting started
286
-# <b>Configure the application's project settings</b>.\n
290
#include <pjmedia_audiodev.h>\endcode\n
291
And add <b>pjmedia-audiodev</b> library to your application link
293
-# <b>Compile time settings</b>.\n
294
Use the compile time settings to enable or
295
disable specific audio drivers. For more information, please see
296
\ref s1_audio_device_config.
297
-# <b>API initialization and cleaning up</b>.\n
298
Before anything else, application must initialize the API by calling:
300
pjmedia_aud_subsys_init(pf);\endcode\n
301
And add this in the application cleanup sequence
303
pjmedia_aud_subsys_shutdown();\endcode
305
@subsection devices Working with devices
307
-# The following code prints the list of audio devices detected
311
pjmedia_aud_dev_index dev_idx;
314
dev_count = pjmedia_aud_dev_count();
315
printf("Got %d audio devices\n", dev_count);
317
for (dev_idx=0; dev_idx<dev_count; ++i) {
318
pjmedia_aud_dev_info info;
320
status = pjmedia_aud_dev_get_info(dev_idx, &info);
321
printf("%d. %s (in=%d, out=%d)\n",
323
info.input_count, info.output_count);
326
-# Info: The #PJMEDIA_AUD_DEFAULT_CAPTURE_DEV and #PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV
327
constants are used to denote default capture and playback devices
329
-# Info: You may save the device and driver's name in your application
330
setting, for example to specify the prefered devices to be
331
used by your application. You can then retrieve the device index
332
for the device by calling:
334
const char *drv_name = "WMME";
335
const char *dev_name = "Wave mapper";
336
pjmedia_aud_dev_index dev_idx;
338
status = pjmedia_aud_dev_lookup(drv_name, dev_name, &dev_idx);
339
if (status==PJ_SUCCESS)
340
printf("Device index is %d\n", dev_idx);
343
@subsection caps Device capabilities
345
Capabilities are encoded as #pjmedia_aud_dev_cap enumeration. Please see
346
#pjmedia_aud_dev_cap enumeration for more information.
348
-# The following snippet prints the capabilities supported by the device:
350
pjmedia_aud_dev_info info;
353
status = pjmedia_aud_dev_get_info(PJMEDIA_AUD_DEFAULT_CAPTURE_DEV, &info);
354
if (status == PJ_SUCCESS) {
356
// Enumerate capability bits
357
printf("Device capabilities: ");
358
for (i=0; i<32; ++i) {
359
if (info.caps & (1 << i))
360
printf("%s ", pjmedia_aud_dev_cap_name(1 << i, NULL));
364
-# Info: You can set the device settings when opening audio stream by setting
365
the flags and the appropriate setting in #pjmedia_aud_param when calling
366
#pjmedia_aud_stream_create()\n
367
-# Info: Once the audio stream is running, you can retrieve or change the stream
368
setting by specifying the capability in #pjmedia_aud_stream_get_cap()
369
and #pjmedia_aud_stream_set_cap() respectively.
372
@subsection creating_stream Creating audio streams
374
The audio stream enables audio streaming to capture device, playback device,
377
-# It is recommended to initialize the #pjmedia_aud_param with its default
378
values before using it:
380
pjmedia_aud_param param;
381
pjmedia_aud_dev_index dev_idx;
384
dev_idx = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
385
status = pjmedia_aud_dev_default_param(dev_idx, ¶m);
387
-# Configure the mandatory parameters:
389
param.dir = PJMEDIA_DIR_CAPTURE_PLAYBACK;
390
param.rec_id = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
391
param.play_id = PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV;
392
param.clock_rate = 8000;
393
param.channel_count = 1;
394
param.samples_per_frame = 160;
395
param.bits_per_sample = 16;
397
-# If you want the audio stream to use the device's built-in codec, specify
398
the codec in the #pjmedia_aud_param. You must make sure that the codec
399
is supported by the device, by looking at its supported format list in
400
the #pjmedia_aud_dev_info.\n
401
The snippet below sets the audio stream to use G.711 ULAW encoding:
405
// Make sure Ulaw is supported
406
if ((info.caps & PJMEDIA_AUD_DEV_CAP_EXT_FORMAT) == 0)
407
error("Device does not support extended formats");
408
for (i = 0; i < info.ext_fmt_cnt; ++i) {
409
if (info.ext_fmt[i].id == PJMEDIA_FORMAT_ULAW)
412
if (i == info.ext_fmt_cnt)
413
error("Device does not support Ulaw format");
416
param.flags |= PJMEDIA_AUD_DEV_CAP_EXT_FORMAT;
417
param.ext_fmt.id = PJMEDIA_FORMAT_ULAW;
418
param.ext_fmt.bitrate = 64000;
419
param.ext_fmt.vad = PJ_FALSE;
421
-# Note that if non-PCM format is configured on the audio stream, the
422
capture and/or playback functions (#pjmedia_aud_rec_cb and
423
#pjmedia_aud_play_cb respectively) will report the audio frame as
424
#pjmedia_frame_ext structure instead of the #pjmedia_frame.
425
-# Optionally configure other device's capabilities. The following snippet
426
shows how to enable echo cancellation on the device (note that this
427
snippet may not be necessary since the setting may have been enabled
428
when calling #pjmedia_aud_dev_default_param() above):
430
if (info.caps & PJMEDIA_AUD_DEV_CAP_EC) {
431
param.flags |= PJMEDIA_AUD_DEV_CAP_EC;
432
param.ec_enabled = PJ_TRUE;
435
-# Open the audio stream, specifying the capture and/or playback callback
438
pjmedia_aud_stream *stream;
440
status = pjmedia_aud_stream_create(¶m, &rec_cb, &play_cb,
444
@subsection working_with_stream Working with audio streams
446
-# To start the audio stream:
448
status = pjmedia_aud_stream_start(stream);
452
status = pjmedia_aud_stream_stop(stream);
454
And to destroy the stream:
456
status = pjmedia_aud_stream_destroy(stream);
458
-# Info: The following shows how to retrieve the capability value of the
459
stream (in this case, the current output volume setting).
461
// Volume setting is an unsigned integer showing the level in percent.
463
status = pjmedia_aud_stream_get_cap(stream,
464
PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,
467
-# Info: And following shows how to modify the capability value of the
468
stream (in this case, the current output volume setting).
470
// Volume setting is an unsigned integer showing the level in percent.
472
status = pjmedia_aud_stream_set_cap(stream,
473
PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,