1
/* $Id: audiodev.h 2506 2009-03-12 18:11:37Z bennylp $ */
3
* Copyright (C) 2008-2009 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
* Additional permission under GNU GPL version 3 section 7:
22
* If you modify this program, or any covered work, by linking or
23
* combining it with the OpenSSL project's OpenSSL library (or a
24
* modified version of that library), containing parts covered by the
25
* terms of the OpenSSL or SSLeay licenses, Teluu Inc. (http://www.teluu.com)
26
* grants you additional permission to convey the resulting work.
27
* Corresponding Source for a non-source form of such a combination
28
* shall include the source code for the parts of OpenSSL used as well
29
* as that of the covered work.
31
#ifndef __PJMEDIA_AUDIODEV_AUDIODEV_H__
32
#define __PJMEDIA_AUDIODEV_AUDIODEV_H__
36
* @brief Audio device API.
38
#include <pjmedia-audiodev/config.h>
39
#include <pjmedia-audiodev/errno.h>
40
#include <pjmedia/types.h>
47
* @defgroup s2_audio_device_reference Audio Device API Reference
48
* @ingroup audio_device_api
49
* @brief API Reference
54
* Type for device index.
56
typedef pj_int32_t pjmedia_aud_dev_index;
59
* Device index constants.
64
* Constant to denote default capture device
66
PJMEDIA_AUD_DEFAULT_CAPTURE_DEV = -1,
69
* Constant to denote default playback device
71
PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV = -2,
74
* Constant to denote invalid device index.
76
PJMEDIA_AUD_INVALID_DEV = -3
81
* This enumeration identifies various audio device capabilities. These audio
82
* capabilities indicates what features are supported by the underlying
83
* audio device implementation.
85
* Applications get these capabilities in the #pjmedia_aud_dev_info structure.
87
* Application can also set the specific features/capabilities when opening
88
* the audio stream by setting the \a flags member of #pjmedia_aud_param
91
* Once audio stream is running, application can also retrieve or set some
92
* specific audio capability, by using #pjmedia_aud_stream_get_cap() and
93
* #pjmedia_aud_stream_set_cap() and specifying the desired capability. The
94
* value of the capability is specified as pointer, and application needs to
95
* supply the pointer with the correct value, according to the documentation
96
* of each of the capability.
98
typedef enum pjmedia_aud_dev_cap
101
* Support for audio formats other than PCM. The value of this capability
102
* is represented by #pjmedia_format structure.
104
PJMEDIA_AUD_DEV_CAP_EXT_FORMAT = 1,
107
* Support for audio input latency control or query. The value of this
108
* capability is an unsigned integer containing milliseconds value of
111
PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY = 2,
114
* Support for audio output latency control or query. The value of this
115
* capability is an unsigned integer containing milliseconds value of
118
PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY = 4,
121
* Support for setting/retrieving the audio input device volume level.
122
* The value of this capability is an unsigned integer representing
123
* the input audio volume setting in percent.
125
PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING = 8,
128
* Support for setting/retrieving the audio output device volume level.
129
* The value of this capability is an unsigned integer representing
130
* the output audio volume setting in percent.
132
PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING = 16,
135
* Support for monitoring the current audio input signal volume.
136
* The value of this capability is an unsigned integer representing
137
* the audio volume in percent.
139
PJMEDIA_AUD_DEV_CAP_INPUT_SIGNAL_METER = 32,
142
* Support for monitoring the current audio output signal volume.
143
* The value of this capability is an unsigned integer representing
144
* the audio volume in percent.
146
PJMEDIA_AUD_DEV_CAP_OUTPUT_SIGNAL_METER = 64,
149
* Support for audio input routing. The value of this capability is an
150
* integer containing #pjmedia_aud_dev_route enumeration.
152
PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE = 128,
155
* Support for audio output routing (e.g. loudspeaker vs earpiece). The
156
* value of this capability is an integer containing #pjmedia_aud_dev_route
159
PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE = 256,
162
* The audio device has echo cancellation feature. The value of this
163
* capability is a pj_bool_t containing boolean PJ_TRUE or PJ_FALSE.
165
PJMEDIA_AUD_DEV_CAP_EC = 512,
168
* The audio device supports setting echo cancellation fail length. The
169
* value of this capability is an unsigned integer representing the
170
* echo tail in milliseconds.
172
PJMEDIA_AUD_DEV_CAP_EC_TAIL = 1024,
175
* The audio device has voice activity detection feature. The value
176
* of this capability is a pj_bool_t containing boolean PJ_TRUE or
179
PJMEDIA_AUD_DEV_CAP_VAD = 2048,
182
* The audio device has comfort noise generation feature. The value
183
* of this capability is a pj_bool_t containing boolean PJ_TRUE or
186
PJMEDIA_AUD_DEV_CAP_CNG = 4096,
189
* The audio device has packet loss concealment feature. The value
190
* of this capability is a pj_bool_t containing boolean PJ_TRUE or
193
PJMEDIA_AUD_DEV_CAP_PLC = 8192,
198
PJMEDIA_AUD_DEV_CAP_MAX = 16384
200
} pjmedia_aud_dev_cap;
204
* This enumeration describes audio routing setting.
206
typedef enum pjmedia_aud_dev_route
208
/** Default route. */
209
PJMEDIA_AUD_DEV_ROUTE_DEFAULT = 0,
211
/** Route to loudspeaker */
212
PJMEDIA_AUD_DEV_ROUTE_LOUDSPEAKER = 1,
214
/** Route to earpiece */
215
PJMEDIA_AUD_DEV_ROUTE_EARPIECE = 2
217
} pjmedia_aud_dev_route;
221
* Device information structure returned by #pjmedia_aud_dev_get_info().
223
typedef struct pjmedia_aud_dev_info
231
* Maximum number of input channels supported by this device. If the
232
* value is zero, the device does not support input operation (i.e.
233
* it is a playback only device).
235
unsigned input_count;
238
* Maximum number of output channels supported by this device. If the
239
* value is zero, the device does not support output operation (i.e.
240
* it is an input only device).
242
unsigned output_count;
245
* Default sampling rate.
247
unsigned default_samples_per_sec;
250
* The underlying driver name
255
* Device capabilities, as bitmask combination of #pjmedia_aud_dev_cap.
260
* Supported audio device routes, as bitmask combination of
261
* #pjmedia_aud_dev_route. The value may be zero if the device
262
* does not support audio routing.
267
* Number of audio formats supported by this device. The value may be
268
* zero if the device does not support non-PCM format.
270
unsigned ext_fmt_cnt;
273
* Array of supported extended audio formats
275
pjmedia_format ext_fmt[8];
278
} pjmedia_aud_dev_info;
282
* This callback is called by player stream when it needs additional data
283
* to be played by the device. Application must fill in the whole of output
284
* buffer with audio samples.
286
* The frame argument contains the following values:
287
* - timestamp Playback timestamp, in samples.
288
* - buf Buffer to be filled out by application.
289
* - size The size requested in bytes, which will be equal to
290
* the size of one whole packet.
292
* @param user_data User data associated with the stream.
293
* @param frame Audio frame, which buffer is to be filled in by
296
* @return Returning non-PJ_SUCCESS will cause the audio stream
299
typedef pj_status_t (*pjmedia_aud_play_cb)(void *user_data,
300
pjmedia_frame *frame);
303
* This callback is called by recorder stream when it has captured the whole
304
* packet worth of audio samples.
306
* @param user_data User data associated with the stream.
307
* @param frame Captured frame.
309
* @return Returning non-PJ_SUCCESS will cause the audio stream
312
typedef pj_status_t (*pjmedia_aud_rec_cb)(void *user_data,
313
pjmedia_frame *frame);
316
* This structure specifies the parameters to open the audio stream.
318
typedef struct pjmedia_aud_param
321
* The audio direction. This setting is mandatory.
326
* The audio recorder device ID. This setting is mandatory if the audio
327
* direction includes input/capture direction.
329
pjmedia_aud_dev_index rec_id;
332
* The audio playback device ID. This setting is mandatory if the audio
333
* direction includes output/playback direction.
335
pjmedia_aud_dev_index play_id;
338
* Clock rate/sampling rate. This setting is mandatory.
343
* Number of channels. This setting is mandatory.
345
unsigned channel_count;
348
* Number of samples per frame. This setting is mandatory.
350
unsigned samples_per_frame;
353
* Number of bits per sample. This setting is mandatory.
355
unsigned bits_per_sample;
358
* This flags specifies which of the optional settings are valid in this
359
* structure. The flags is bitmask combination of pjmedia_aud_dev_cap.
364
* Set the audio format. This setting is optional, and will only be used
365
* if PJMEDIA_AUD_DEV_CAP_EXT_FORMAT is set in the flags.
367
pjmedia_format ext_fmt;
370
* Input latency, in milliseconds. This setting is optional, and will
371
* only be used if PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY is set in the flags.
373
unsigned input_latency_ms;
376
* Input latency, in milliseconds. This setting is optional, and will
377
* only be used if PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY is set in the flags.
379
unsigned output_latency_ms;
382
* Input volume setting, in percent. This setting is optional, and will
383
* only be used if PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING is set in
389
* Output volume setting, in percent. This setting is optional, and will
390
* only be used if PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING is set in
396
* Set the audio input route. This setting is optional, and will only be
397
* used if PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE is set in the flags.
399
pjmedia_aud_dev_route input_route;
402
* Set the audio output route. This setting is optional, and will only be
403
* used if PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE is set in the flags.
405
pjmedia_aud_dev_route output_route;
408
* Enable/disable echo canceller, if the device supports it. This setting
409
* is optional, and will only be used if PJMEDIA_AUD_DEV_CAP_EC is set in
412
pj_bool_t ec_enabled;
415
* Set echo canceller tail length in milliseconds, if the device supports
416
* it. This setting is optional, and will only be used if
417
* PJMEDIA_AUD_DEV_CAP_EC_TAIL is set in the flags.
422
* Enable/disable PLC. This setting is optional, and will only be used
423
* if PJMEDIA_AUD_DEV_CAP_PLC is set in the flags.
425
pj_bool_t plc_enabled;
428
* Enable/disable CNG. This setting is optional, and will only be used
429
* if PJMEDIA_AUD_DEV_CAP_CNG is set in the flags.
431
pj_bool_t cng_enabled;
436
/** Forward declaration for pjmedia_aud_stream */
437
typedef struct pjmedia_aud_stream pjmedia_aud_stream;
439
/** Forward declaration for audio device factory */
440
typedef struct pjmedia_aud_dev_factory pjmedia_aud_dev_factory;
443
* Get string info for the specified capability.
445
* @param cap The capability ID.
446
* @param p_desc Optional pointer which will be filled with longer
447
* description about the capability.
449
* @return Capability name.
451
PJ_DECL(const char*) pjmedia_aud_dev_cap_name(pjmedia_aud_dev_cap cap,
452
const char **p_desc);
456
* Set a capability field value in #pjmedia_aud_param structure. This will
457
* also set the flags field for the specified capability in the structure.
459
* @param param The structure.
460
* @param cap The audio capability which value is to be set.
461
* @param value Pointer to value. Please see the type of value to
462
* be supplied in the pjmedia_aud_dev_cap documentation.
464
* @return PJ_SUCCESS on successful operation or the appropriate
467
PJ_DECL(pj_status_t) pjmedia_aud_param_set_cap(pjmedia_aud_param *param,
468
pjmedia_aud_dev_cap cap,
473
* Get a capability field value from #pjmedia_aud_param structure. This
474
* function will return PJMEDIA_EAUD_INVCAP error if the flag for that
475
* capability is not set in the flags field in the structure.
477
* @param param The structure.
478
* @param cap The audio capability which value is to be retrieved.
479
* @param value Pointer to value. Please see the type of value to
480
* be supplied in the pjmedia_aud_dev_cap documentation.
482
* @return PJ_SUCCESS on successful operation or the appropriate
485
PJ_DECL(pj_status_t) pjmedia_aud_param_get_cap(const pjmedia_aud_param *param,
486
pjmedia_aud_dev_cap cap,
490
* Initialize the audio subsystem. This will register all supported audio
491
* device factories to the audio subsystem. This function may be called
492
* more than once, but each call to this function must have the
493
* corresponding #pjmedia_aud_subsys_shutdown() call.
495
* @param pf The pool factory.
497
* @return PJ_SUCCESS on successful operation or the appropriate
500
PJ_DECL(pj_status_t) pjmedia_aud_subsys_init(pj_pool_factory *pf);
504
* Get the pool factory registered to the audio subsystem.
506
* @return The pool factory.
508
PJ_DECL(pj_pool_factory*) pjmedia_aud_subsys_get_pool_factory(void);
512
* Shutdown the audio subsystem. This will destroy all audio device factories
513
* registered in the audio subsystem. Note that currently opened audio streams
514
* may or may not be closed, depending on the implementation of the audio
517
* @return PJ_SUCCESS on successful operation or the appropriate
520
PJ_DECL(pj_status_t) pjmedia_aud_subsys_shutdown(void);
524
* Get the number of sound devices installed in the system.
526
* @return The number of sound devices installed in the system.
528
PJ_DECL(unsigned) pjmedia_aud_dev_count(void);
532
* Get device information.
534
* @param id The audio device ID.
535
* @param info The device information which will be filled in by this
536
* function once it returns successfully.
538
* @return PJ_SUCCESS on successful operation or the appropriate
541
PJ_DECL(pj_status_t) pjmedia_aud_dev_get_info(pjmedia_aud_dev_index id,
542
pjmedia_aud_dev_info *info);
546
* Lookup device index based on the driver and device name.
548
* @param drv_name The driver name.
549
* @param dev_name The device name.
550
* @param id Pointer to store the returned device ID.
552
* @return PJ_SUCCESS if the device can be found.
554
PJ_DECL(pj_status_t) pjmedia_aud_dev_lookup(const char *drv_name,
555
const char *dev_name,
556
pjmedia_aud_dev_index *id);
560
* Initialize the audio device parameters with default values for the
563
* @param id The audio device ID.
564
* @param param The audio device parameters which will be initialized
565
* by this function once it returns successfully.
567
* @return PJ_SUCCESS on successful operation or the appropriate
570
PJ_DECL(pj_status_t) pjmedia_aud_dev_default_param(pjmedia_aud_dev_index id,
571
pjmedia_aud_param *param);
575
* Open audio stream object using the specified parameters.
577
* @param param Sound device parameters to be used for the stream.
578
* @param rec_cb Callback to be called on every input frame captured.
579
* @param play_cb Callback to be called everytime the sound device needs
580
* audio frames to be played back.
581
* @param user_data Arbitrary user data, which will be given back in the
583
* @param p_strm Pointer to receive the audio stream.
585
* @return PJ_SUCCESS on successful operation or the appropriate
588
PJ_DECL(pj_status_t) pjmedia_aud_stream_create(const pjmedia_aud_param *param,
589
pjmedia_aud_rec_cb rec_cb,
590
pjmedia_aud_play_cb play_cb,
592
pjmedia_aud_stream **p_strm);
595
* Get the running parameters for the specified audio stream.
597
* @param strm The audio stream.
598
* @param param Audio stream parameters to be filled in by this
599
* function once it returns successfully.
601
* @return PJ_SUCCESS on successful operation or the appropriate
604
PJ_DECL(pj_status_t) pjmedia_aud_stream_get_param(pjmedia_aud_stream *strm,
605
pjmedia_aud_param *param);
608
* Get the value of a specific capability of the audio stream.
610
* @param strm The audio stream.
611
* @param cap The audio capability which value is to be retrieved.
612
* @param value Pointer to value to be filled in by this function
613
* once it returns successfully. Please see the type
614
* of value to be supplied in the pjmedia_aud_dev_cap
617
* @return PJ_SUCCESS on successful operation or the appropriate
620
PJ_DECL(pj_status_t) pjmedia_aud_stream_get_cap(pjmedia_aud_stream *strm,
621
pjmedia_aud_dev_cap cap,
625
* Set the value of a specific capability of the audio stream.
627
* @param strm The audio stream.
628
* @param cap The audio capability which value is to be set.
629
* @param value Pointer to value. Please see the type of value to
630
* be supplied in the pjmedia_aud_dev_cap documentation.
632
* @return PJ_SUCCESS on successful operation or the appropriate
635
PJ_DECL(pj_status_t) pjmedia_aud_stream_set_cap(pjmedia_aud_stream *strm,
636
pjmedia_aud_dev_cap cap,
642
* @param strm The audio stream.
644
* @return PJ_SUCCESS on successful operation or the appropriate
647
PJ_DECL(pj_status_t) pjmedia_aud_stream_start(pjmedia_aud_stream *strm);
652
* @param strm The audio stream.
654
* @return PJ_SUCCESS on successful operation or the appropriate
657
PJ_DECL(pj_status_t) pjmedia_aud_stream_stop(pjmedia_aud_stream *strm);
660
* Destroy the stream.
662
* @param strm The audio stream.
664
* @return PJ_SUCCESS on successful operation or the appropriate
667
PJ_DECL(pj_status_t) pjmedia_aud_stream_destroy(pjmedia_aud_stream *strm);
677
#endif /* __PJMEDIA_AUDIODEV_AUDIODEV_H__ */