Debian Codegraph @

Xpjproject/pjmedia/include/pjmedia-audiodev/config.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #ifndef __PJMEDIA_AUDIODEV_CONFIG_H__
20 #define __PJMEDIA_AUDIODEV_CONFIG_H__
21
22 /**
23 * @file config.h
24 * @brief Audio config.
25 */
26 #include <pjmedia/types.h>
27 #include <pj/pool.h>
28
29
30 PJ_BEGIN_DECL
31
32 /**
33 * @defgroup audio_device_api Audio Device API
34 * @brief PJMEDIA audio device abstraction API.
35 */
36
37 /**
38 * @defgroup s1_audio_device_config Compile time configurations
39 * @ingroup audio_device_api
40 * @brief Compile time configurations
41 * @{
42 */
43
44 /**
45 * This setting controls the maximum number of supported audio devices.
46 *
47 * Default: 64
48 */
49 #ifndef PJMEDIA_AUD_DEV_MAX_DEVS
50 # define PJMEDIA_AUD_DEV_MAX_DEVS 64
51 #endif
52
53 /**
54 * This setting controls the buffer length of audio device name.
55 *
56 * Default: 128 for Windows platforms, 64 for others
57 */
58 #ifndef PJMEDIA_AUD_DEV_INFO_NAME_LEN
59 # if (defined(PJ_WIN32) && PJ_WIN32!=0) || \
60 (defined(PJ_WIN64) && PJ_WIN64!=0)
61 # define PJMEDIA_AUD_DEV_INFO_NAME_LEN 128
62 # else
63 # define PJMEDIA_AUD_DEV_INFO_NAME_LEN 64
64 # endif
65 #endif
66
67 /**
68 * This setting controls whether PortAudio support should be included.
69 *
70 * By default it is disabled.
71 */
72 #ifndef PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO
73 # define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 0
74 #endif
75
76 /**
77 * This setting controls whether Android OpenSL audio support should be
78 * included.
79 */
80 #ifndef PJMEDIA_AUDIO_DEV_HAS_OPENSL
81 # define PJMEDIA_AUDIO_DEV_HAS_OPENSL 0
82 #endif
83
84 /**
85 * This setting controls whether Android JNI audio support should be
86 * included.
87 */
88 #ifndef PJMEDIA_AUDIO_DEV_HAS_ANDROID_JNI
89 # define PJMEDIA_AUDIO_DEV_HAS_ANDROID_JNI PJ_ANDROID
90 #endif
91
92 /**
93 * This setting controls whether Android Oboe audio support should be
94 * included.
95 */
96 #ifndef PJMEDIA_AUDIO_DEV_HAS_OBOE
97 # define PJMEDIA_AUDIO_DEV_HAS_OBOE 0
98 #endif
99
100 /**
101 * Specify wheather LowLatency is used for Oboe as performance mode.
102 * Default: 1
103 */
104 #ifndef PJMEDIA_OBOE_USE_LOWLATENCY
105 # define PJMEDIA_OBOE_USE_LOWLATENCY 1
106 #endif
107
108 /**
109 * This setting controls whether BlackBerry 10 (BB10) audio support
110 * should be included.
111 */
112 #ifndef PJMEDIA_AUDIO_DEV_HAS_BB10
113 # define PJMEDIA_AUDIO_DEV_HAS_BB10 0
114 #endif
115
116 /**
117 * This setting controls whether native ALSA support should be included.
118 */
119 #ifndef PJMEDIA_AUDIO_DEV_HAS_ALSA
120 # define PJMEDIA_AUDIO_DEV_HAS_ALSA 0
121 #endif
122
123
124 /**
125 * This setting controls whether null audio support should be included.
126 */
127 #ifndef PJMEDIA_AUDIO_DEV_HAS_NULL_AUDIO
128 # define PJMEDIA_AUDIO_DEV_HAS_NULL_AUDIO 0
129 #endif
130
131
132 /**
133 * This setting controls whether coreaudio support should be included.
134 */
135 #ifndef PJMEDIA_AUDIO_DEV_HAS_COREAUDIO
136 # define PJMEDIA_AUDIO_DEV_HAS_COREAUDIO 0
137 #endif
138
139
140 /**
141 * This setting controls whether WMME support should be included.
142 */
143 #ifndef PJMEDIA_AUDIO_DEV_HAS_WMME
144 # if (defined(PJ_WIN32_UWP) && PJ_WIN32_UWP!=0) || \
145 (defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8!=0)
146 # define PJMEDIA_AUDIO_DEV_HAS_WMME 0
147 # else
148 # define PJMEDIA_AUDIO_DEV_HAS_WMME 1
149 # endif
150 #endif
151
152
153 /**
154 * This setting controls whether Windows Audio Session API (WASAPI)
155 * support should be included.
156 */
157 #ifndef PJMEDIA_AUDIO_DEV_HAS_WASAPI
158 # if (defined(PJ_WIN32_UWP) && PJ_WIN32_UWP!=0) || \
159 (defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8!=0)
160 # define PJMEDIA_AUDIO_DEV_HAS_WASAPI 1
161 # else
162 # define PJMEDIA_AUDIO_DEV_HAS_WASAPI 0
163 # endif
164 #endif
165
166
167 /**
168 * This setting controls whether BDIMAD support should be included.
169 */
170 #ifndef PJMEDIA_AUDIO_DEV_HAS_BDIMAD
171 # define PJMEDIA_AUDIO_DEV_HAS_BDIMAD 0
172 #endif
173
174
175 /**
176 * This setting controls whether Symbian APS support should be included.
177 */
178 #ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_APS
179 # define PJMEDIA_AUDIO_DEV_HAS_SYMB_APS 0
180 #endif
181
182
183 /**
184 * This setting controls whether Symbian APS should perform codec
185 * detection in its factory initalization. Note that codec detection
186 * may take few seconds and detecting more codecs will take more time.
187 * Possible values are:
188 * - 0: no codec detection, all APS codec (AMR-NB, G.711, G.729, and
189 * iLBC) will be assumed as supported.
190 * - 1: minimal codec detection, i.e: only detect for AMR-NB and G.711,
191 * (G.729 and iLBC are considered to be supported/unsupported when
192 * G.711 is supported/unsupported).
193 * - 2: full codec detection, i.e: detect AMR-NB, G.711, G.729, and iLBC.
194 *
195 * Default: 1 (minimal codec detection)
196 */
197 #ifndef PJMEDIA_AUDIO_DEV_SYMB_APS_DETECTS_CODEC
198 # define PJMEDIA_AUDIO_DEV_SYMB_APS_DETECTS_CODEC 1
199 #endif
200
201
202 /**
203 * This setting controls whether Symbian VAS support should be included.
204 */
205 #ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS
206 # define PJMEDIA_AUDIO_DEV_HAS_SYMB_VAS 0
207 #endif
208
209 /**
210 * This setting controls Symbian VAS version to be used. Currently, valid
211 * values are only 1 (for VAS 1.0) and 2 (for VAS 2.0).
212 *
213 * Default: 1 (VAS version 1.0)
214 */
215 #ifndef PJMEDIA_AUDIO_DEV_SYMB_VAS_VERSION
216 # define PJMEDIA_AUDIO_DEV_SYMB_VAS_VERSION 1
217 #endif
218
219
220 /**
221 * This setting controls whether Symbian audio (using built-in multimedia
222 * framework) support should be included.
223 */
224 #ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA
225 # define PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA PJ_SYMBIAN
226 #endif
227
228
229 /**
230 * This setting controls whether the Symbian audio with built-in multimedia
231 * framework backend should be started synchronously. Note that synchronous
232 * start will block the application/UI, e.g: about 40ms for each direction
233 * on N95. While asynchronous start may cause invalid value (always zero)
234 * returned in input/output volume query, if the query is performed when
235 * the internal start procedure is not completely finished.
236 *
237 * Default: 1 (yes)
238 */
239 #ifndef PJMEDIA_AUDIO_DEV_MDA_USE_SYNC_START
240 # define PJMEDIA_AUDIO_DEV_MDA_USE_SYNC_START 1
241 #endif
242
243
244 /**
245 * This setting controls whether the Audio Device API should support
246 * device implementation that is based on the old sound device API
247 * (sound.h).
248 *
249 * Enable this API if:
250 * - you have implemented your own sound device using the old sound
251 * device API (sound.h), and
252 * - you wish to be able to use your sound device implementation
253 * using the new Audio Device API.
254 *
255 * Please see http://trac.pjsip.org/repos/wiki/Audio_Dev_API for more
256 * info.
257 */
258 #ifndef PJMEDIA_AUDIO_DEV_HAS_LEGACY_DEVICE
259 # define PJMEDIA_AUDIO_DEV_HAS_LEGACY_DEVICE 0
260 #endif
261
262
263 /**
264 * @}
265 */
266
267 PJ_END_DECL
268
269
270 #endif /* __PJMEDIA_AUDIODEV_CONFIG_H__ */
271
272 /*
273 --------------------- DOCUMENTATION FOLLOWS ---------------------------
274 */
275
276 /**
277 * @addtogroup audio_device_api Audio Device API
278 * @{
279
280 PJMEDIA Audio Device API is a cross-platform audio API appropriate for use with
281 VoIP applications and many other types of audio streaming applications.
282
283 The API abstracts many different audio API's on various platforms, such as:
284 - WMME audio for Windows and Windows Mobile devices
285 - Windows Audio Session API (WASAPI)
286 - CoreAudio for Mac and iPhone
287 - ALSA for Linux
288 - Android OpenSL
289 - Android JNI
290 - Android Oboe
291 - PortAudio for Windows, Windows Mobile, Linux, Unix, dan MacOS X.
292 - BDIMAP
293 - Blackberry BB10
294 - Symbian audio streaming/multimedia framework (MMF) implementation
295 - Nokia Audio Proxy Server (APS) implementation
296 - null-audio implementation
297 - and more to be implemented in the future
298
299 The Audio Device API/library is an evolution from PJMEDIA @ref PJMED_SND and
300 contains many enhancements:
301
302 - Forward compatibility:
303 \n
304 The new API has been designed to be extensible, it will support new API's as
305 well as new features that may be introduced in the future without breaking
306 compatibility with applications that use this API as well as compatibility
307 with existing device implementations.
308
309 - Device capabilities:
310 \n
311 At the heart of the API is device capabilities management, where all possible
312 audio capabilities of audio devices should be able to be handled in a generic
313 manner. With this framework, new capabilities that may be discovered in the
314 future can be handled in manner without breaking existing applications.
315
316 - Built-in features:
317 \n
318 The device capabilities framework enables applications to use and control
319 audio features built-in in the device, such as:
320 - echo cancellation,
321 - built-in codecs,
322 - audio routing (e.g. to earpiece or loudspeaker),
323 - volume control,
324 - etc.
325
326 - Codec support:
327 \n
328 Some audio devices such as Nokia/Symbian Audio Proxy Server (APS) and Nokia
329 VoIP Audio Services (VAS) support built-in hardware audio codecs (e.g. G.729,
330 iLBC, and AMR), and application can use the sound device in encoded mode to
331 make use of these hardware codecs.
332
333 - Multiple backends:
334 \n
335 The new API supports multiple audio backends (called factories or drivers in
336 the code) to be active simultaneously, and audio backends may be added or
337 removed during run-time.
338
339
340 @section using Overview on using the API
341
342 @subsection getting_started Getting started
343
344 -# <b>Configure the application's project settings</b>.\n
345 Add the following
346 include:
347 \code
348 #include <pjmedia_audiodev.h>\endcode\n
349 And add <b>pjmedia-audiodev</b> library to your application link
350 specifications.\n
351 -# <b>Compile time settings</b>.\n
352 Use the compile time settings to enable or
353 disable specific audio drivers. For more information, please see
354 \ref s1_audio_device_config.
355 -# <b>API initialization and cleaning up</b>.\n
356 Before anything else, application must initialize the API by calling:
357 \code
358 pjmedia_aud_subsys_init(pf);\endcode\n
359 And add this in the application cleanup sequence
360 \code
361 pjmedia_aud_subsys_shutdown();\endcode
362
363 @subsection devices Working with devices
364
365 -# The following code prints the list of audio devices detected
366 in the system.
367 \code
368 int dev_count;
369 pjmedia_aud_dev_index dev_idx;
370 pj_status_t status;
371
372 dev_count = pjmedia_aud_dev_count();
373 printf("Got %d audio devices\n", dev_count);
374
375 for (dev_idx=0; dev_idx<dev_count; ++i) {
376 pjmedia_aud_dev_info info;
377
378 status = pjmedia_aud_dev_get_info(dev_idx, &info);
379 printf("%d. %s (in=%d, out=%d)\n",
380 dev_idx, info.name,
381 info.input_count, info.output_count);
382 }
383 \endcode\n
384 -# Info: The #PJMEDIA_AUD_DEFAULT_CAPTURE_DEV and #PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV
385 constants are used to denote default capture and playback devices
386 respectively.
387 -# Info: You may save the device and driver's name in your application
388 setting, for example to specify the prefered devices to be
389 used by your application. You can then retrieve the device index
390 for the device by calling:
391 \code
392 const char *drv_name = "WMME";
393 const char *dev_name = "Wave mapper";
394 pjmedia_aud_dev_index dev_idx;
395
396 status = pjmedia_aud_dev_lookup(drv_name, dev_name, &dev_idx);
397 if (status==PJ_SUCCESS)
398 printf("Device index is %d\n", dev_idx);
399 \endcode
400
401 @subsection caps Device capabilities
402
403 Capabilities are encoded as #pjmedia_aud_dev_cap enumeration. Please see
404 #pjmedia_aud_dev_cap enumeration for more information.
405
406 -# The following snippet prints the capabilities supported by the device:
407 \code
408 pjmedia_aud_dev_info info;
409 pj_status_t status;
410
411 status = pjmedia_aud_dev_get_info(PJMEDIA_AUD_DEFAULT_CAPTURE_DEV, &info);
412 if (status == PJ_SUCCESS) {
413 unsigned i;
414 // Enumerate capability bits
415 printf("Device capabilities: ");
416 for (i=0; i<32; ++i) {
417 if (info.caps & (1 << i))
418 printf("%s ", pjmedia_aud_dev_cap_name(1 << i, NULL));
419 }
420 }
421 \endcode\n
422 -# Info: You can set the device settings when opening audio stream by setting
423 the flags and the appropriate setting in #pjmedia_aud_param when calling
424 #pjmedia_aud_stream_create()\n
425 -# Info: Once the audio stream is running, you can retrieve or change the stream
426 setting by specifying the capability in #pjmedia_aud_stream_get_cap()
427 and #pjmedia_aud_stream_set_cap() respectively.
428
429
430 @subsection creating_stream Creating audio streams
431
432 The audio stream enables audio streaming to capture device, playback device,
433 or both.
434
435 -# It is recommended to initialize the #pjmedia_aud_param with its default
436 values before using it:
437 \code
438 pjmedia_aud_param param;
439 pjmedia_aud_dev_index dev_idx;
440 pj_status_t status;
441
442 dev_idx = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
443 status = pjmedia_aud_dev_default_param(dev_idx, &param);
444 \endcode\n
445 -# Configure the mandatory parameters:
446 \code
447 param.dir = PJMEDIA_DIR_CAPTURE_PLAYBACK;
448 param.rec_id = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
449 param.play_id = PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV;
450 param.clock_rate = 8000;
451 param.channel_count = 1;
452 param.samples_per_frame = 160;
453 param.bits_per_sample = 16;
454 \endcode\n
455 -# If you want the audio stream to use the device's built-in codec, specify
456 the codec in the #pjmedia_aud_param. You must make sure that the codec
457 is supported by the device, by looking at its supported format list in
458 the #pjmedia_aud_dev_info.\n
459 The snippet below sets the audio stream to use G.711 ULAW encoding:
460 \code
461 unsigned i;
462
463 // Make sure Ulaw is supported
464 if ((info.caps & PJMEDIA_AUD_DEV_CAP_EXT_FORMAT) == 0)
465 error("Device does not support extended formats");
466 for (i = 0; i < info.ext_fmt_cnt; ++i) {
467 if (info.ext_fmt[i].id == PJMEDIA_FORMAT_ULAW)
468 break;
469 }
470 if (i == info.ext_fmt_cnt)
471 error("Device does not support Ulaw format");
472
473 // Set Ulaw format
474 param.flags |= PJMEDIA_AUD_DEV_CAP_EXT_FORMAT;
475 param.ext_fmt.id = PJMEDIA_FORMAT_ULAW;
476 param.ext_fmt.bitrate = 64000;
477 param.ext_fmt.vad = PJ_FALSE;
478 \endcode\n
479 -# Note that if non-PCM format is configured on the audio stream, the
480 capture and/or playback functions (#pjmedia_aud_rec_cb and
481 #pjmedia_aud_play_cb respectively) will report the audio frame as
482 #pjmedia_frame_ext structure instead of the #pjmedia_frame.
483 -# Optionally configure other device's capabilities. The following snippet
484 shows how to enable echo cancellation on the device (note that this
485 snippet may not be necessary since the setting may have been enabled
486 when calling #pjmedia_aud_dev_default_param() above):
487 \code
488 if (info.caps & PJMEDIA_AUD_DEV_CAP_EC) {
489 param.flags |= PJMEDIA_AUD_DEV_CAP_EC;
490 param.ec_enabled = PJ_TRUE;
491 }
492 \endcode
493 -# Open the audio stream, specifying the capture and/or playback callback
494 functions:
495 \code
496 pjmedia_aud_stream *stream;
497
498 status = pjmedia_aud_stream_create(&param, &rec_cb, &play_cb,
499 user_data, &stream);
500 \endcode
501
502 @subsection working_with_stream Working with audio streams
503
504 -# To start the audio stream:
505 \code
506 status = pjmedia_aud_stream_start(stream);
507 \endcode\n
508 To stop the stream:
509 \code
510 status = pjmedia_aud_stream_stop(stream);
511 \endcode\n
512 And to destroy the stream:
513 \code
514 status = pjmedia_aud_stream_destroy(stream);
515 \endcode\n
516 -# Info: The following shows how to retrieve the capability value of the
517 stream (in this case, the current output volume setting).
518 \code
519 // Volume setting is an unsigned integer showing the level in percent.
520 unsigned vol;
521 status = pjmedia_aud_stream_get_cap(stream,
522 PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,
523 &vol);
524 \endcode
525 -# Info: And following shows how to modify the capability value of the
526 stream (in this case, the current output volume setting).
527 \code
528 // Volume setting is an unsigned integer showing the level in percent.
529 unsigned vol = 50;
530 status = pjmedia_aud_stream_set_cap(stream,
531 PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,
532 &vol);
533 \endcode
534
535
536 */
537
538
539 /**
540 * @}
541 */
542