blob: eaf368d93f9d7bc98f46d5b050e4b05265f0a88c [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 */
27#include <pjmedia/port.h>
28#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.
47 */
48#ifndef PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO
49# define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 0
50#endif
51
52
53/**
54 * This setting controls whether WMME support should be included.
55 */
56#ifndef PJMEDIA_AUDIO_DEV_HAS_WMME
57# define PJMEDIA_AUDIO_DEV_HAS_WMME 1
58#endif
59
60
61/**
Nanang Izzuddina940b362009-02-23 13:53:30 +000062 * This setting controls whether Symbian APS support should be included.
63 */
64#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_APS
65# define PJMEDIA_AUDIO_DEV_HAS_SYMB_APS 0
66#endif
67
68
69/**
70 * This setting controls whether Symbian audio (using built-in multimedia
71 * framework) support should be included.
72 */
73#ifndef PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA
74# define PJMEDIA_AUDIO_DEV_HAS_SYMB_MDA 0
75#endif
76
77/**
Benny Prijono2058f472009-02-22 17:15:34 +000078 * @}
79 */
80
81PJ_END_DECL
82
83
84#endif /* __PJMEDIA_AUDIODEV_CONFIG_H__ */
85
86/*
87 --------------------- DOCUMENTATION FOLLOWS ---------------------------
88 */
89
90/**
91 * @addtogroup audio_device_api Audio Device API
92 * @{
93
94PJMEDIA Audio Device API is a cross-platform audio API appropriate for use with
95VoIP applications and many other types of audio streaming applications.
96
97The API abstracts many different audio API's on various platforms, such as:
98 - PortAudio back-end for Win32, Windows Mobile, Linux, Unix, dan MacOS X.
99 - native WMME audio for Win32 and Windows Mobile devices
100 - native Symbian audio streaming/multimedia framework (MMF) implementation
101 - native Nokia Audio Proxy Server (APS) implementation
102 - null-audio implementation
103 - and more to be implemented in the future
104
105The Audio Device API/library is an evolution from PJMEDIA @ref PJMED_SND and
106contains many enhancements:
107
108 - Forward compatibility:
109\n
110 The new API has been designed to be extensible, it will support new API's as
111 well as new features that may be introduced in the future without breaking
112 compatibility with applications that use this API as well as compatibility
113 with existing device implementations.
114
115 - Device capabilities:
116\n
117 At the heart of the API is device capabilities management, where all possible
118 audio capabilities of audio devices should be able to be handled in a generic
119 manner. With this framework, new capabilities that may be discovered in the
120 future can be handled in manner without breaking existing applications.
121
122 - Built-in features:
123\n
Benny Prijonoeef2a872009-02-23 09:55:52 +0000124 The device capabilities framework enables applications to use and control
125 audio features built-in in the device, such as:
Benny Prijono2058f472009-02-22 17:15:34 +0000126 - echo cancellation,
127 - built-in codecs,
Benny Prijonoeef2a872009-02-23 09:55:52 +0000128 - audio routing (e.g. to earpiece or loudspeaker),
129 - volume control,
130 - etc.
Benny Prijono2058f472009-02-22 17:15:34 +0000131
132 - Codec support:
133\n
134 Some audio devices such as Nokia/Symbian Audio Proxy Server (APS) and Nokia
135 VoIP Audio Services (VAS) support built-in hardware audio codecs (e.g. G.729,
136 iLBC, and AMR), and application can use the sound device in encoded mode to
137 make use of these hardware codecs.
138
139 - Multiple backends:
140\n
141 The new API supports multiple audio backends (called factories or drivers in
142 the code) to be active simultaneously, and audio backends may be added or
143 removed during run-time.
Benny Prijonoeef2a872009-02-23 09:55:52 +0000144
145
146@section using Overview on using the API
147
148@subsection getting_started Getting started
149
150 -# <b>Configure the application's project settings</b>.\n
151 Add the following
152 include:
153 \code
154 #include <pjmedia_audiodev.h>\endcode\n
155 And add <b>pjmedia-audiodev</b> library to your application link
156 specifications.\n
157 -# <b>Compile time settings</b>.\n
158 Use the compile time settings to enable or
159 disable specific audio drivers. For more information, please see
160 \ref s1_audio_device_config.
161 -# <b>API initialization and cleaning up</b>.\n
162 Before anything else, application must initialize the API by calling:
163 \code
164 pjmedia_aud_subsys_init(pf);\endcode\n
165 And add this in the application cleanup sequence
166 \code
167 pjmedia_aud_subsys_shutdown();\endcode
168
169@subsection devices Working with devices
170
171 -# The following code prints the list of audio devices detected
172 in the system.
173 \code
174 int dev_count;
175 pjmedia_aud_dev_index dev_idx;
176 pj_status_t status;
177
178 dev_count = pjmedia_aud_dev_count();
179 printf("Got %d audio devices\n", dev_count);
180
181 for (dev_idx=0; dev_idx<dev_count; ++i) {
182 pjmedia_aud_dev_info info;
183
184 status = pjmedia_aud_dev_get_info(dev_idx, &info);
185 printf("%d. %s (in=%d, out=%d)\n",
186 dev_idx, info.name,
187 info.input_count, info.output_count);
188 }
189 \endcode\n
190 -# Info: The #PJMEDIA_AUD_DEFAULT_CAPTURE_DEV and #PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV
191 constants are used to denote default capture and playback devices
192 respectively.
193 -# Info: You may save the device and driver's name in your application
194 setting, for example to specify the prefered devices to be
195 used by your application. You can then retrieve the device index
196 for the device by calling:
197 \code
198 const char *drv_name = "WMME";
199 const char *dev_name = "Wave mapper";
200 pjmedia_aud_dev_index dev_idx;
201
202 status = pjmedia_aud_dev_lookup(drv_name, dev_name, &dev_idx);
203 if (status==PJ_SUCCESS)
204 printf("Device index is %d\n", dev_idx);
205 \endcode
206
207@subsection caps Device capabilities
208
209Capabilities are encoded as #pjmedia_aud_dev_cap enumeration. Please see
210#pjmedia_aud_dev_cap enumeration for more information.
211
212 -# The following snippet prints the capabilities supported by the device:
213 \code
214 pjmedia_aud_dev_info info;
215 pj_status_t status;
216
217 status = pjmedia_aud_dev_get_info(PJMEDIA_AUD_DEFAULT_CAPTURE_DEV, &info);
218 if (status == PJ_SUCCESS) {
219 unsigned i;
220 // Enumerate capability bits
221 printf("Device capabilities: ");
222 for (i=0; i<32; ++i) {
223 if (info.caps & (1 << i))
224 printf("%s ", pjmedia_aud_dev_cap_name(1 << i, NULL));
225 }
226 }
227 \endcode\n
228 -# Info: You can set the device settings when opening audio stream by setting
229 the flags and the appropriate setting in #pjmedia_aud_param when calling
230 #pjmedia_aud_stream_create()\n
231 -# Info: Once the audio stream is running, you can retrieve or change the stream
232 setting by specifying the capability in #pjmedia_aud_stream_get_cap()
233 and #pjmedia_aud_stream_set_cap() respectively.
234
235
236@subsection creating_stream Creating audio streams
237
238The audio stream enables audio streaming to capture device, playback device,
239or both.
240
241 -# It is recommended to initialize the #pjmedia_aud_param with its default
242 values before using it:
243 \code
244 pjmedia_aud_param param;
245 pjmedia_aud_dev_index dev_idx;
246 pj_status_t status;
247
248 dev_idx = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
249 status = pjmedia_aud_dev_default_param(dev_idx, &param);
250 \endcode\n
251 -# Configure the mandatory parameters:
252 \code
253 param.dir = PJMEDIA_DIR_CAPTURE_PLAYBACK;
254 param.rec_id = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV;
255 param.play_id = PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV;
256 param.clock_rate = 8000;
257 param.channel_count = 1;
258 param.samples_per_frame = 160;
259 param.bits_per_sample = 16;
260 \endcode\n
261 -# If you want the audio stream to use the device's built-in codec, specify
262 the codec in the #pjmedia_aud_param. You must make sure that the codec
263 is supported by the device, by looking at its supported format list in
264 the #pjmedia_aud_dev_info.\n
265 The snippet below sets the audio stream to use G.711 ULAW encoding:
266 \code
267 unsigned i;
268
269 // Make sure Ulaw is supported
270 if ((info.caps & PJMEDIA_AUD_DEV_CAP_EXT_FORMAT) == 0)
271 error("Device does not support extended formats");
272 for (i = 0; i < info.ext_fmt_cnt; ++i) {
273 if (info.ext_fmt[i].id == PJMEDIA_FORMAT_ULAW)
274 break;
275 }
276 if (i == info.ext_fmt_cnt)
277 error("Device does not support Ulaw format");
278
279 // Set Ulaw format
280 param.flags |= PJMEDIA_AUD_DEV_CAP_EXT_FORMAT;
281 param.ext_fmt.id = PJMEDIA_FORMAT_ULAW;
282 param.ext_fmt.bitrate = 64000;
283 param.ext_fmt.vad = PJ_FALSE;
284 \endcode\n
285 -# Note that if non-PCM format is configured on the audio stream, the
286 capture and/or playback functions (#pjmedia_aud_rec_cb and
287 #pjmedia_aud_play_cb respectively) will report the audio frame as
288 #pjmedia_frame_ext structure instead of the #pjmedia_frame.
289 -# Optionally configure other device's capabilities. The following snippet
290 shows how to enable echo cancellation on the device (note that this
291 snippet may not be necessary since the setting may have been enabled
292 when calling #pjmedia_aud_dev_default_param() above):
293 \code
294 if (info.caps & PJMEDIA_AUD_DEV_CAP_EC) {
295 param.flags |= PJMEDIA_AUD_DEV_CAP_EC;
296 param.ec_enabled = PJ_TRUE;
297 }
298 \endcode
299 -# Open the audio stream, specifying the capture and/or playback callback
300 functions:
301 \code
302 pjmedia_aud_stream *stream;
303
304 status = pjmedia_aud_stream_create(&param, &rec_cb, &play_cb,
305 user_data, &stream);
306 \endcode
307
308@subsection working_with_stream Working with audio streams
309
310 -# To start the audio stream:
311 \code
312 status = pjmedia_aud_stream_start(stream);
313 \endcode\n
314 To stop the stream:
315 \code
316 status = pjmedia_aud_stream_stop(stream);
317 \endcode\n
318 And to destroy the stream:
319 \code
320 status = pjmedia_aud_stream_destroy(stream);
321 \endcode\n
322 -# Info: The following shows how to retrieve the capability value of the
323 stream (in this case, the current output volume setting).
324 \code
325 // Volume setting is an unsigned integer showing the level in percent.
326 unsigned vol;
327 status = pjmedia_aud_stream_get_cap(stream,
328 PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,
329 &vol);
330 \endcode
331 -# Info: And following shows how to modify the capability value of the
332 stream (in this case, the current output volume setting).
333 \code
334 // Volume setting is an unsigned integer showing the level in percent.
335 unsigned vol = 50;
336 status = pjmedia_aud_stream_set_cap(stream,
337 PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,
338 &vol);
339 \endcode
340
341
342*/
343
Benny Prijono2058f472009-02-22 17:15:34 +0000344
345/**
346 * @}
347 */
348