1
/* $Id: audiodev.h 4243 2012-08-31 11:42:17Z nanang $ */
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_AUDIODEV_H__
21
#define __PJMEDIA_AUDIODEV_AUDIODEV_H__
25
* @brief Audio device API.
27
#include <pjmedia-audiodev/config.h>
28
#include <pjmedia-audiodev/errno.h>
29
#include <pjmedia/format.h>
30
#include <pjmedia/frame.h>
31
#include <pjmedia/types.h>
38
* @defgroup s2_audio_device_reference Audio Device API Reference
39
* @ingroup audio_device_api
40
* @brief API Reference
45
* Type for device index.
47
typedef pj_int32_t pjmedia_aud_dev_index;
50
* Device index constants.
55
* Constant to denote default capture device
57
PJMEDIA_AUD_DEFAULT_CAPTURE_DEV = -1,
60
* Constant to denote default playback device
62
PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV = -2,
65
* Constant to denote invalid device index.
67
PJMEDIA_AUD_INVALID_DEV = -3
72
* This enumeration identifies various audio device capabilities. These audio
73
* capabilities indicates what features are supported by the underlying
74
* audio device implementation.
76
* Applications get these capabilities in the #pjmedia_aud_dev_info structure.
78
* Application can also set the specific features/capabilities when opening
79
* the audio stream by setting the \a flags member of #pjmedia_aud_param
82
* Once audio stream is running, application can also retrieve or set some
83
* specific audio capability, by using #pjmedia_aud_stream_get_cap() and
84
* #pjmedia_aud_stream_set_cap() and specifying the desired capability. The
85
* value of the capability is specified as pointer, and application needs to
86
* supply the pointer with the correct value, according to the documentation
87
* of each of the capability.
89
typedef enum pjmedia_aud_dev_cap
92
* Support for audio formats other than PCM. The value of this capability
93
* is represented by #pjmedia_format structure.
95
PJMEDIA_AUD_DEV_CAP_EXT_FORMAT = 1,
98
* Support for audio input latency control or query. The value of this
99
* capability is an unsigned integer containing milliseconds value of
102
PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY = 2,
105
* Support for audio output latency control or query. The value of this
106
* capability is an unsigned integer containing milliseconds value of
109
PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY = 4,
112
* Support for setting/retrieving the audio input device volume level.
113
* The value of this capability is an unsigned integer representing
114
* the input audio volume setting in percent.
116
PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING = 8,
119
* Support for setting/retrieving the audio output device volume level.
120
* The value of this capability is an unsigned integer representing
121
* the output audio volume setting in percent.
123
PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING = 16,
126
* Support for monitoring the current audio input signal volume.
127
* The value of this capability is an unsigned integer representing
128
* the audio volume in percent.
130
PJMEDIA_AUD_DEV_CAP_INPUT_SIGNAL_METER = 32,
133
* Support for monitoring the current audio output signal volume.
134
* The value of this capability is an unsigned integer representing
135
* the audio volume in percent.
137
PJMEDIA_AUD_DEV_CAP_OUTPUT_SIGNAL_METER = 64,
140
* Support for audio input routing. The value of this capability is an
141
* integer containing #pjmedia_aud_dev_route enumeration.
143
PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE = 128,
146
* Support for audio output routing (e.g. loudspeaker vs earpiece). The
147
* value of this capability is an integer containing #pjmedia_aud_dev_route
150
PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE = 256,
153
* The audio device has echo cancellation feature. The value of this
154
* capability is a pj_bool_t containing boolean PJ_TRUE or PJ_FALSE.
156
PJMEDIA_AUD_DEV_CAP_EC = 512,
159
* The audio device supports setting echo cancellation fail length. The
160
* value of this capability is an unsigned integer representing the
161
* echo tail in milliseconds.
163
PJMEDIA_AUD_DEV_CAP_EC_TAIL = 1024,
166
* The audio device has voice activity detection feature. The value
167
* of this capability is a pj_bool_t containing boolean PJ_TRUE or
170
PJMEDIA_AUD_DEV_CAP_VAD = 2048,
173
* The audio device has comfort noise generation feature. The value
174
* of this capability is a pj_bool_t containing boolean PJ_TRUE or
177
PJMEDIA_AUD_DEV_CAP_CNG = 4096,
180
* The audio device has packet loss concealment feature. The value
181
* of this capability is a pj_bool_t containing boolean PJ_TRUE or
184
PJMEDIA_AUD_DEV_CAP_PLC = 8192,
189
PJMEDIA_AUD_DEV_CAP_MAX = 16384
191
} pjmedia_aud_dev_cap;
195
* This enumeration describes audio routing setting.
197
typedef enum pjmedia_aud_dev_route
199
/** Default route. */
200
PJMEDIA_AUD_DEV_ROUTE_DEFAULT = 0,
202
/** Route to loudspeaker */
203
PJMEDIA_AUD_DEV_ROUTE_LOUDSPEAKER = 1,
205
/** Route to earpiece */
206
PJMEDIA_AUD_DEV_ROUTE_EARPIECE = 2,
208
/** Route to paired Bluetooth device */
209
PJMEDIA_AUD_DEV_ROUTE_BLUETOOTH = 4
211
} pjmedia_aud_dev_route;
215
* Device information structure returned by #pjmedia_aud_dev_get_info().
217
typedef struct pjmedia_aud_dev_info
225
* Maximum number of input channels supported by this device. If the
226
* value is zero, the device does not support input operation (i.e.
227
* it is a playback only device).
229
unsigned input_count;
232
* Maximum number of output channels supported by this device. If the
233
* value is zero, the device does not support output operation (i.e.
234
* it is an input only device).
236
unsigned output_count;
239
* Default sampling rate.
241
unsigned default_samples_per_sec;
244
* The underlying driver name
249
* Device capabilities, as bitmask combination of #pjmedia_aud_dev_cap.
254
* Supported audio device routes, as bitmask combination of
255
* #pjmedia_aud_dev_route. The value may be zero if the device
256
* does not support audio routing.
261
* Number of audio formats supported by this device. The value may be
262
* zero if the device does not support non-PCM format.
264
unsigned ext_fmt_cnt;
267
* Array of supported extended audio formats
269
pjmedia_format ext_fmt[8];
272
} pjmedia_aud_dev_info;
276
* This callback is called by player stream when it needs additional data
277
* to be played by the device. Application must fill in the whole of output
278
* buffer with audio samples.
280
* The frame argument contains the following values:
281
* - timestamp Playback timestamp, in samples.
282
* - buf Buffer to be filled out by application.
283
* - size The size requested in bytes, which will be equal to
284
* the size of one whole packet.
286
* @param user_data User data associated with the stream.
287
* @param frame Audio frame, which buffer is to be filled in by
290
* @return Returning non-PJ_SUCCESS will cause the audio stream
293
typedef pj_status_t (*pjmedia_aud_play_cb)(void *user_data,
294
pjmedia_frame *frame);
297
* This callback is called by recorder stream when it has captured the whole
298
* packet worth of audio samples.
300
* @param user_data User data associated with the stream.
301
* @param frame Captured frame.
303
* @return Returning non-PJ_SUCCESS will cause the audio stream
306
typedef pj_status_t (*pjmedia_aud_rec_cb)(void *user_data,
307
pjmedia_frame *frame);
310
* This structure specifies the parameters to open the audio stream.
312
typedef struct pjmedia_aud_param
315
* The audio direction. This setting is mandatory.
320
* The audio recorder device ID. This setting is mandatory if the audio
321
* direction includes input/capture direction.
323
pjmedia_aud_dev_index rec_id;
326
* The audio playback device ID. This setting is mandatory if the audio
327
* direction includes output/playback direction.
329
pjmedia_aud_dev_index play_id;
332
* Clock rate/sampling rate. This setting is mandatory.
337
* Number of channels. This setting is mandatory.
339
unsigned channel_count;
342
* Number of samples per frame. This setting is mandatory.
344
unsigned samples_per_frame;
347
* Number of bits per sample. This setting is mandatory.
349
unsigned bits_per_sample;
352
* This flags specifies which of the optional settings are valid in this
353
* structure. The flags is bitmask combination of pjmedia_aud_dev_cap.
358
* Set the audio format. This setting is optional, and will only be used
359
* if PJMEDIA_AUD_DEV_CAP_EXT_FORMAT is set in the flags.
361
pjmedia_format ext_fmt;
364
* Input latency, in milliseconds. This setting is optional, and will
365
* only be used if PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY is set in the flags.
367
unsigned input_latency_ms;
370
* Input latency, in milliseconds. This setting is optional, and will
371
* only be used if PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY is set in the flags.
373
unsigned output_latency_ms;
376
* Input volume setting, in percent. This setting is optional, and will
377
* only be used if PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING is set in
383
* Output volume setting, in percent. This setting is optional, and will
384
* only be used if PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING is set in
390
* Set the audio input route. This setting is optional, and will only be
391
* used if PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE is set in the flags.
393
pjmedia_aud_dev_route input_route;
396
* Set the audio output route. This setting is optional, and will only be
397
* used if PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE is set in the flags.
399
pjmedia_aud_dev_route output_route;
402
* Enable/disable echo canceller, if the device supports it. This setting
403
* is optional, and will only be used if PJMEDIA_AUD_DEV_CAP_EC is set in
406
pj_bool_t ec_enabled;
409
* Set echo canceller tail length in milliseconds, if the device supports
410
* it. This setting is optional, and will only be used if
411
* PJMEDIA_AUD_DEV_CAP_EC_TAIL is set in the flags.
416
* Enable/disable PLC. This setting is optional, and will only be used
417
* if PJMEDIA_AUD_DEV_CAP_PLC is set in the flags.
419
pj_bool_t plc_enabled;
422
* Enable/disable CNG. This setting is optional, and will only be used
423
* if PJMEDIA_AUD_DEV_CAP_CNG is set in the flags.
425
pj_bool_t cng_enabled;
428
* Enable/disable VAD. This setting is optional, and will only be used
429
* if PJMEDIA_AUD_DEV_CAP_VAD is set in the flags.
431
pj_bool_t vad_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;
442
/* typedef for factory creation function */
443
typedef pjmedia_aud_dev_factory*
444
(*pjmedia_aud_dev_factory_create_func_ptr)(pj_pool_factory*);
448
* Get string info for the specified capability.
450
* @param cap The capability ID.
451
* @param p_desc Optional pointer which will be filled with longer
452
* description about the capability.
454
* @return Capability name.
456
PJ_DECL(const char*) pjmedia_aud_dev_cap_name(pjmedia_aud_dev_cap cap,
457
const char **p_desc);
461
* Set a capability field value in #pjmedia_aud_param structure. This will
462
* also set the flags field for the specified capability in the structure.
464
* @param param The structure.
465
* @param cap The audio capability which value is to be set.
466
* @param pval Pointer to value. Please see the type of value to
467
* be supplied in the pjmedia_aud_dev_cap documentation.
469
* @return PJ_SUCCESS on successful operation or the appropriate
472
PJ_DECL(pj_status_t) pjmedia_aud_param_set_cap(pjmedia_aud_param *param,
473
pjmedia_aud_dev_cap cap,
478
* Get a capability field value from #pjmedia_aud_param structure. This
479
* function will return PJMEDIA_EAUD_INVCAP error if the flag for that
480
* capability is not set in the flags field in the structure.
482
* @param param The structure.
483
* @param cap The audio capability which value is to be retrieved.
484
* @param pval Pointer to value. Please see the type of value to
485
* be supplied in the pjmedia_aud_dev_cap documentation.
487
* @return PJ_SUCCESS on successful operation or the appropriate
490
PJ_DECL(pj_status_t) pjmedia_aud_param_get_cap(const pjmedia_aud_param *param,
491
pjmedia_aud_dev_cap cap,
495
* Initialize the audio subsystem. This will register all supported audio
496
* device factories to the audio subsystem. This function may be called
497
* more than once, but each call to this function must have the
498
* corresponding #pjmedia_aud_subsys_shutdown() call.
500
* @param pf The pool factory.
502
* @return PJ_SUCCESS on successful operation or the appropriate
505
PJ_DECL(pj_status_t) pjmedia_aud_subsys_init(pj_pool_factory *pf);
509
* Get the pool factory registered to the audio subsystem.
511
* @return The pool factory.
513
PJ_DECL(pj_pool_factory*) pjmedia_aud_subsys_get_pool_factory(void);
517
* Shutdown the audio subsystem. This will destroy all audio device factories
518
* registered in the audio subsystem. Note that currently opened audio streams
519
* may or may not be closed, depending on the implementation of the audio
522
* @return PJ_SUCCESS on successful operation or the appropriate
525
PJ_DECL(pj_status_t) pjmedia_aud_subsys_shutdown(void);
529
* Register a supported audio device factory to the audio subsystem. This
530
* function can only be called after calling #pjmedia_aud_subsys_init().
532
* @param adf The audio device factory.
534
* @return PJ_SUCCESS on successful operation or the appropriate
538
pjmedia_aud_register_factory(pjmedia_aud_dev_factory_create_func_ptr adf);
542
* Unregister an audio device factory from the audio subsystem. This
543
* function can only be called after calling #pjmedia_aud_subsys_init().
544
* Devices from this factory will be unlisted. If a device from this factory
545
* is currently in use, then the behavior is undefined.
547
* @param adf The audio device factory.
549
* @return PJ_SUCCESS on successful operation or the appropriate
553
pjmedia_aud_unregister_factory(pjmedia_aud_dev_factory_create_func_ptr adf);
557
* Refresh the list of sound devices installed in the system. This function
558
* will only refresh the list of audio device so all active audio streams will
559
* be unaffected. After refreshing the device list, application MUST make sure
560
* to update all index references to audio devices (i.e. all variables of type
561
* pjmedia_aud_dev_index) before calling any function that accepts audio device
562
* index as its parameter.
564
* @return PJ_SUCCESS on successful operation or the appropriate
567
PJ_DECL(pj_status_t) pjmedia_aud_dev_refresh(void);
571
* Get the number of sound devices installed in the system.
573
* @return The number of sound devices installed in the system.
575
PJ_DECL(unsigned) pjmedia_aud_dev_count(void);
579
* Get device information.
581
* @param id The audio device ID.
582
* @param info The device information which will be filled in by this
583
* function once it returns successfully.
585
* @return PJ_SUCCESS on successful operation or the appropriate
588
PJ_DECL(pj_status_t) pjmedia_aud_dev_get_info(pjmedia_aud_dev_index id,
589
pjmedia_aud_dev_info *info);
593
* Lookup device index based on the driver and device name.
595
* @param drv_name The driver name.
596
* @param dev_name The device name.
597
* @param id Pointer to store the returned device ID.
599
* @return PJ_SUCCESS if the device can be found.
601
PJ_DECL(pj_status_t) pjmedia_aud_dev_lookup(const char *drv_name,
602
const char *dev_name,
603
pjmedia_aud_dev_index *id);
607
* Initialize the audio device parameters with default values for the
610
* @param id The audio device ID.
611
* @param param The audio device parameters which will be initialized
612
* by this function once it returns successfully.
614
* @return PJ_SUCCESS on successful operation or the appropriate
617
PJ_DECL(pj_status_t) pjmedia_aud_dev_default_param(pjmedia_aud_dev_index id,
618
pjmedia_aud_param *param);
622
* Open audio stream object using the specified parameters.
624
* @param param Sound device parameters to be used for the stream.
625
* @param rec_cb Callback to be called on every input frame captured.
626
* @param play_cb Callback to be called everytime the sound device needs
627
* audio frames to be played back.
628
* @param user_data Arbitrary user data, which will be given back in the
630
* @param p_strm Pointer to receive the audio stream.
632
* @return PJ_SUCCESS on successful operation or the appropriate
635
PJ_DECL(pj_status_t) pjmedia_aud_stream_create(const pjmedia_aud_param *param,
636
pjmedia_aud_rec_cb rec_cb,
637
pjmedia_aud_play_cb play_cb,
639
pjmedia_aud_stream **p_strm);
642
* Get the running parameters for the specified audio stream.
644
* @param strm The audio stream.
645
* @param param Audio stream parameters to be filled in by this
646
* function once it returns successfully.
648
* @return PJ_SUCCESS on successful operation or the appropriate
651
PJ_DECL(pj_status_t) pjmedia_aud_stream_get_param(pjmedia_aud_stream *strm,
652
pjmedia_aud_param *param);
655
* Get the value of a specific capability of the audio stream.
657
* @param strm The audio stream.
658
* @param cap The audio capability which value is to be retrieved.
659
* @param value Pointer to value to be filled in by this function
660
* once it returns successfully. Please see the type
661
* of value to be supplied in the pjmedia_aud_dev_cap
664
* @return PJ_SUCCESS on successful operation or the appropriate
667
PJ_DECL(pj_status_t) pjmedia_aud_stream_get_cap(pjmedia_aud_stream *strm,
668
pjmedia_aud_dev_cap cap,
672
* Set the value of a specific capability of the audio stream.
674
* @param strm The audio stream.
675
* @param cap The audio capability which value is to be set.
676
* @param value Pointer to value. Please see the type of value to
677
* be supplied in the pjmedia_aud_dev_cap documentation.
679
* @return PJ_SUCCESS on successful operation or the appropriate
682
PJ_DECL(pj_status_t) pjmedia_aud_stream_set_cap(pjmedia_aud_stream *strm,
683
pjmedia_aud_dev_cap cap,
689
* @param strm The audio stream.
691
* @return PJ_SUCCESS on successful operation or the appropriate
694
PJ_DECL(pj_status_t) pjmedia_aud_stream_start(pjmedia_aud_stream *strm);
699
* @param strm The audio stream.
701
* @return PJ_SUCCESS on successful operation or the appropriate
704
PJ_DECL(pj_status_t) pjmedia_aud_stream_stop(pjmedia_aud_stream *strm);
707
* Destroy the stream.
709
* @param strm The audio stream.
711
* @return PJ_SUCCESS on successful operation or the appropriate
714
PJ_DECL(pj_status_t) pjmedia_aud_stream_destroy(pjmedia_aud_stream *strm);
724
#endif /* __PJMEDIA_AUDIODEV_AUDIODEV_H__ */