Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 1 | /* $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 | */ |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 20 | #ifndef __PJMEDIA_AUDIODEV_AUDIODEV_H__ |
| 21 | #define __PJMEDIA_AUDIODEV_AUDIODEV_H__ |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * @file audiodev.h |
| 25 | * @brief Audio device API. |
| 26 | */ |
Benny Prijono | 2058f47 | 2009-02-22 17:15:34 +0000 | [diff] [blame] | 27 | #include <pjmedia-audiodev/config.h> |
Benny Prijono | 8eeab0b | 2009-03-04 19:00:28 +0000 | [diff] [blame] | 28 | #include <pjmedia-audiodev/errno.h> |
Benny Prijono | 64f9138 | 2009-03-05 18:02:28 +0000 | [diff] [blame] | 29 | #include <pjmedia/types.h> |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 30 | #include <pj/pool.h> |
| 31 | |
| 32 | |
| 33 | PJ_BEGIN_DECL |
| 34 | |
| 35 | /** |
Benny Prijono | 2058f47 | 2009-02-22 17:15:34 +0000 | [diff] [blame] | 36 | * @defgroup s2_audio_device_reference Audio Device API Reference |
| 37 | * @ingroup audio_device_api |
| 38 | * @brief API Reference |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 39 | * @{ |
| 40 | */ |
| 41 | |
Sauw Ming | 8fd1693 | 2010-05-05 04:23:27 +0000 | [diff] [blame] | 42 | /** |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 43 | * Type for device index. |
| 44 | */ |
| 45 | typedef pj_int32_t pjmedia_aud_dev_index; |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 46 | |
Benny Prijono | 96e74f3 | 2009-02-22 12:00:12 +0000 | [diff] [blame] | 47 | /** |
| 48 | * Device index constants. |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 49 | */ |
Benny Prijono | 96e74f3 | 2009-02-22 12:00:12 +0000 | [diff] [blame] | 50 | enum |
| 51 | { |
| 52 | /** |
| 53 | * Constant to denote default capture device |
| 54 | */ |
| 55 | PJMEDIA_AUD_DEFAULT_CAPTURE_DEV = -1, |
| 56 | |
| 57 | /** |
| 58 | * Constant to denote default playback device |
| 59 | */ |
| 60 | PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV = -2, |
| 61 | |
| 62 | /** |
| 63 | * Constant to denote invalid device index. |
| 64 | */ |
| 65 | PJMEDIA_AUD_INVALID_DEV = -3 |
| 66 | }; |
| 67 | |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 68 | |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 69 | /** |
| 70 | * This enumeration identifies various audio device capabilities. These audio |
| 71 | * capabilities indicates what features are supported by the underlying |
| 72 | * audio device implementation. |
| 73 | * |
| 74 | * Applications get these capabilities in the #pjmedia_aud_dev_info structure. |
| 75 | * |
| 76 | * Application can also set the specific features/capabilities when opening |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 77 | * the audio stream by setting the \a flags member of #pjmedia_aud_param |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 78 | * structure. |
| 79 | * |
| 80 | * Once audio stream is running, application can also retrieve or set some |
| 81 | * specific audio capability, by using #pjmedia_aud_stream_get_cap() and |
| 82 | * #pjmedia_aud_stream_set_cap() and specifying the desired capability. The |
| 83 | * value of the capability is specified as pointer, and application needs to |
| 84 | * supply the pointer with the correct value, according to the documentation |
| 85 | * of each of the capability. |
| 86 | */ |
| 87 | typedef enum pjmedia_aud_dev_cap |
| 88 | { |
| 89 | /** |
| 90 | * Support for audio formats other than PCM. The value of this capability |
| 91 | * is represented by #pjmedia_format structure. |
| 92 | */ |
| 93 | PJMEDIA_AUD_DEV_CAP_EXT_FORMAT = 1, |
| 94 | |
| 95 | /** |
| 96 | * Support for audio input latency control or query. The value of this |
| 97 | * capability is an unsigned integer containing milliseconds value of |
| 98 | * the latency. |
| 99 | */ |
| 100 | PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY = 2, |
| 101 | |
| 102 | /** |
| 103 | * Support for audio output latency control or query. The value of this |
| 104 | * capability is an unsigned integer containing milliseconds value of |
| 105 | * the latency. |
| 106 | */ |
| 107 | PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY = 4, |
| 108 | |
| 109 | /** |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 110 | * Support for setting/retrieving the audio input device volume level. |
| 111 | * The value of this capability is an unsigned integer representing |
| 112 | * the input audio volume setting in percent. |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 113 | */ |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 114 | PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING = 8, |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 115 | |
| 116 | /** |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 117 | * Support for setting/retrieving the audio output device volume level. |
| 118 | * The value of this capability is an unsigned integer representing |
| 119 | * the output audio volume setting in percent. |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 120 | */ |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 121 | PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING = 16, |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 122 | |
| 123 | /** |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 124 | * Support for monitoring the current audio input signal volume. |
| 125 | * The value of this capability is an unsigned integer representing |
| 126 | * the audio volume in percent. |
| 127 | */ |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 128 | PJMEDIA_AUD_DEV_CAP_INPUT_SIGNAL_METER = 32, |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * Support for monitoring the current audio output signal volume. |
| 132 | * The value of this capability is an unsigned integer representing |
| 133 | * the audio volume in percent. |
| 134 | */ |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 135 | PJMEDIA_AUD_DEV_CAP_OUTPUT_SIGNAL_METER = 64, |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * Support for audio input routing. The value of this capability is an |
| 139 | * integer containing #pjmedia_aud_dev_route enumeration. |
| 140 | */ |
| 141 | PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE = 128, |
| 142 | |
| 143 | /** |
| 144 | * Support for audio output routing (e.g. loudspeaker vs earpiece). The |
| 145 | * value of this capability is an integer containing #pjmedia_aud_dev_route |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 146 | * enumeration. |
| 147 | */ |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 148 | PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE = 256, |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 149 | |
| 150 | /** |
| 151 | * The audio device has echo cancellation feature. The value of this |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 152 | * capability is a pj_bool_t containing boolean PJ_TRUE or PJ_FALSE. |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 153 | */ |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 154 | PJMEDIA_AUD_DEV_CAP_EC = 512, |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 155 | |
| 156 | /** |
| 157 | * The audio device supports setting echo cancellation fail length. The |
| 158 | * value of this capability is an unsigned integer representing the |
| 159 | * echo tail in milliseconds. |
| 160 | */ |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 161 | PJMEDIA_AUD_DEV_CAP_EC_TAIL = 1024, |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * The audio device has voice activity detection feature. The value |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 165 | * of this capability is a pj_bool_t containing boolean PJ_TRUE or |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 166 | * PJ_FALSE. |
| 167 | */ |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 168 | PJMEDIA_AUD_DEV_CAP_VAD = 2048, |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 169 | |
| 170 | /** |
| 171 | * The audio device has comfort noise generation feature. The value |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 172 | * of this capability is a pj_bool_t containing boolean PJ_TRUE or |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 173 | * PJ_FALSE. |
| 174 | */ |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 175 | PJMEDIA_AUD_DEV_CAP_CNG = 4096, |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 176 | |
| 177 | /** |
| 178 | * The audio device has packet loss concealment feature. The value |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 179 | * of this capability is a pj_bool_t containing boolean PJ_TRUE or |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 180 | * PJ_FALSE. |
| 181 | */ |
Benny Prijono | 7a38000 | 2009-03-09 12:55:29 +0000 | [diff] [blame] | 182 | PJMEDIA_AUD_DEV_CAP_PLC = 8192, |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 183 | |
Benny Prijono | 7a38000 | 2009-03-09 12:55:29 +0000 | [diff] [blame] | 184 | /** |
| 185 | * End of capability |
| 186 | */ |
| 187 | PJMEDIA_AUD_DEV_CAP_MAX = 16384 |
| 188 | |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 189 | } pjmedia_aud_dev_cap; |
| 190 | |
| 191 | |
| 192 | /** |
| 193 | * This enumeration describes audio routing setting. |
| 194 | */ |
| 195 | typedef enum pjmedia_aud_dev_route |
| 196 | { |
| 197 | /** Default route. */ |
| 198 | PJMEDIA_AUD_DEV_ROUTE_DEFAULT = 0, |
| 199 | |
| 200 | /** Route to loudspeaker */ |
| 201 | PJMEDIA_AUD_DEV_ROUTE_LOUDSPEAKER = 1, |
| 202 | |
| 203 | /** Route to earpiece */ |
Sauw Ming | 55a73cd | 2010-05-17 12:51:06 +0000 | [diff] [blame] | 204 | PJMEDIA_AUD_DEV_ROUTE_EARPIECE = 2, |
| 205 | |
| 206 | /** Route to paired Bluetooth device */ |
| 207 | PJMEDIA_AUD_DEV_ROUTE_BLUETOOTH = 4 |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 208 | |
| 209 | } pjmedia_aud_dev_route; |
| 210 | |
| 211 | |
| 212 | /** |
Benny Prijono | 2058f47 | 2009-02-22 17:15:34 +0000 | [diff] [blame] | 213 | * Device information structure returned by #pjmedia_aud_dev_get_info(). |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 214 | */ |
| 215 | typedef struct pjmedia_aud_dev_info |
| 216 | { |
| 217 | /** |
| 218 | * The device name |
| 219 | */ |
| 220 | char name[64]; |
| 221 | |
| 222 | /** |
| 223 | * Maximum number of input channels supported by this device. If the |
| 224 | * value is zero, the device does not support input operation (i.e. |
| 225 | * it is a playback only device). |
| 226 | */ |
| 227 | unsigned input_count; |
| 228 | |
| 229 | /** |
| 230 | * Maximum number of output channels supported by this device. If the |
| 231 | * value is zero, the device does not support output operation (i.e. |
| 232 | * it is an input only device). |
| 233 | */ |
| 234 | unsigned output_count; |
| 235 | |
| 236 | /** |
| 237 | * Default sampling rate. |
| 238 | */ |
| 239 | unsigned default_samples_per_sec; |
| 240 | |
| 241 | /** |
| 242 | * The underlying driver name |
| 243 | */ |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 244 | char driver[32]; |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 245 | |
| 246 | /** |
| 247 | * Device capabilities, as bitmask combination of #pjmedia_aud_dev_cap. |
| 248 | */ |
| 249 | unsigned caps; |
| 250 | |
| 251 | /** |
| 252 | * Supported audio device routes, as bitmask combination of |
| 253 | * #pjmedia_aud_dev_route. The value may be zero if the device |
| 254 | * does not support audio routing. |
| 255 | */ |
| 256 | unsigned routes; |
| 257 | |
| 258 | /** |
| 259 | * Number of audio formats supported by this device. The value may be |
| 260 | * zero if the device does not support non-PCM format. |
| 261 | */ |
| 262 | unsigned ext_fmt_cnt; |
| 263 | |
| 264 | /** |
| 265 | * Array of supported extended audio formats |
| 266 | */ |
| 267 | pjmedia_format ext_fmt[8]; |
| 268 | |
| 269 | |
| 270 | } pjmedia_aud_dev_info; |
| 271 | |
| 272 | |
| 273 | /** |
| 274 | * This callback is called by player stream when it needs additional data |
| 275 | * to be played by the device. Application must fill in the whole of output |
| 276 | * buffer with audio samples. |
| 277 | * |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 278 | * The frame argument contains the following values: |
| 279 | * - timestamp Playback timestamp, in samples. |
| 280 | * - buf Buffer to be filled out by application. |
| 281 | * - size The size requested in bytes, which will be equal to |
| 282 | * the size of one whole packet. |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 283 | * |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 284 | * @param user_data User data associated with the stream. |
| 285 | * @param frame Audio frame, which buffer is to be filled in by |
| 286 | * the application. |
| 287 | * |
| 288 | * @return Returning non-PJ_SUCCESS will cause the audio stream |
| 289 | * to stop |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 290 | */ |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 291 | typedef pj_status_t (*pjmedia_aud_play_cb)(void *user_data, |
| 292 | pjmedia_frame *frame); |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 293 | |
| 294 | /** |
| 295 | * This callback is called by recorder stream when it has captured the whole |
| 296 | * packet worth of audio samples. |
| 297 | * |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 298 | * @param user_data User data associated with the stream. |
| 299 | * @param frame Captured frame. |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 300 | * |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 301 | * @return Returning non-PJ_SUCCESS will cause the audio stream |
| 302 | * to stop |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 303 | */ |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 304 | typedef pj_status_t (*pjmedia_aud_rec_cb)(void *user_data, |
| 305 | pjmedia_frame *frame); |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 306 | |
| 307 | /** |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 308 | * This structure specifies the parameters to open the audio stream. |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 309 | */ |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 310 | typedef struct pjmedia_aud_param |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 311 | { |
| 312 | /** |
| 313 | * The audio direction. This setting is mandatory. |
| 314 | */ |
| 315 | pjmedia_dir dir; |
| 316 | |
| 317 | /** |
| 318 | * The audio recorder device ID. This setting is mandatory if the audio |
| 319 | * direction includes input/capture direction. |
| 320 | */ |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 321 | pjmedia_aud_dev_index rec_id; |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 322 | |
| 323 | /** |
| 324 | * The audio playback device ID. This setting is mandatory if the audio |
| 325 | * direction includes output/playback direction. |
| 326 | */ |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 327 | pjmedia_aud_dev_index play_id; |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 328 | |
| 329 | /** |
| 330 | * Clock rate/sampling rate. This setting is mandatory. |
| 331 | */ |
| 332 | unsigned clock_rate; |
| 333 | |
| 334 | /** |
| 335 | * Number of channels. This setting is mandatory. |
| 336 | */ |
| 337 | unsigned channel_count; |
| 338 | |
| 339 | /** |
| 340 | * Number of samples per frame. This setting is mandatory. |
| 341 | */ |
| 342 | unsigned samples_per_frame; |
| 343 | |
| 344 | /** |
| 345 | * Number of bits per sample. This setting is mandatory. |
| 346 | */ |
| 347 | unsigned bits_per_sample; |
| 348 | |
| 349 | /** |
| 350 | * This flags specifies which of the optional settings are valid in this |
| 351 | * structure. The flags is bitmask combination of pjmedia_aud_dev_cap. |
| 352 | */ |
| 353 | unsigned flags; |
| 354 | |
| 355 | /** |
| 356 | * Set the audio format. This setting is optional, and will only be used |
| 357 | * if PJMEDIA_AUD_DEV_CAP_EXT_FORMAT is set in the flags. |
| 358 | */ |
| 359 | pjmedia_format ext_fmt; |
| 360 | |
| 361 | /** |
| 362 | * Input latency, in milliseconds. This setting is optional, and will |
| 363 | * only be used if PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY is set in the flags. |
| 364 | */ |
| 365 | unsigned input_latency_ms; |
| 366 | |
| 367 | /** |
| 368 | * Input latency, in milliseconds. This setting is optional, and will |
| 369 | * only be used if PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY is set in the flags. |
| 370 | */ |
| 371 | unsigned output_latency_ms; |
| 372 | |
Benny Prijono | 7a38000 | 2009-03-09 12:55:29 +0000 | [diff] [blame] | 373 | /** |
| 374 | * Input volume setting, in percent. This setting is optional, and will |
| 375 | * only be used if PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING is set in |
| 376 | * the flags. |
| 377 | */ |
| 378 | unsigned input_vol; |
| 379 | |
| 380 | /** |
| 381 | * Output volume setting, in percent. This setting is optional, and will |
| 382 | * only be used if PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING is set in |
| 383 | * the flags. |
| 384 | */ |
| 385 | unsigned output_vol; |
| 386 | |
| 387 | /** |
| 388 | * Set the audio input route. This setting is optional, and will only be |
| 389 | * used if PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE is set in the flags. |
| 390 | */ |
| 391 | pjmedia_aud_dev_route input_route; |
| 392 | |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 393 | /** |
Benny Prijono | 598b01d | 2009-02-18 13:55:03 +0000 | [diff] [blame] | 394 | * Set the audio output route. This setting is optional, and will only be |
| 395 | * used if PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE is set in the flags. |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 396 | */ |
Benny Prijono | 7a38000 | 2009-03-09 12:55:29 +0000 | [diff] [blame] | 397 | pjmedia_aud_dev_route output_route; |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 398 | |
| 399 | /** |
| 400 | * Enable/disable echo canceller, if the device supports it. This setting |
| 401 | * is optional, and will only be used if PJMEDIA_AUD_DEV_CAP_EC is set in |
| 402 | * the flags. |
| 403 | */ |
| 404 | pj_bool_t ec_enabled; |
| 405 | |
| 406 | /** |
| 407 | * Set echo canceller tail length in milliseconds, if the device supports |
| 408 | * it. This setting is optional, and will only be used if |
| 409 | * PJMEDIA_AUD_DEV_CAP_EC_TAIL is set in the flags. |
| 410 | */ |
| 411 | unsigned ec_tail_ms; |
| 412 | |
| 413 | /** |
| 414 | * Enable/disable PLC. This setting is optional, and will only be used |
| 415 | * if PJMEDIA_AUD_DEV_CAP_PLC is set in the flags. |
| 416 | */ |
| 417 | pj_bool_t plc_enabled; |
| 418 | |
| 419 | /** |
| 420 | * Enable/disable CNG. This setting is optional, and will only be used |
| 421 | * if PJMEDIA_AUD_DEV_CAP_CNG is set in the flags. |
| 422 | */ |
| 423 | pj_bool_t cng_enabled; |
| 424 | |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 425 | } pjmedia_aud_param; |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 426 | |
| 427 | |
| 428 | /** Forward declaration for pjmedia_aud_stream */ |
| 429 | typedef struct pjmedia_aud_stream pjmedia_aud_stream; |
| 430 | |
| 431 | /** Forward declaration for audio device factory */ |
| 432 | typedef struct pjmedia_aud_dev_factory pjmedia_aud_dev_factory; |
| 433 | |
Sauw Ming | 8fd1693 | 2010-05-05 04:23:27 +0000 | [diff] [blame] | 434 | /* typedef for factory creation function */ |
| 435 | typedef pjmedia_aud_dev_factory* |
| 436 | (*pjmedia_aud_dev_factory_create_func_ptr)(pj_pool_factory*); |
| 437 | |
| 438 | |
Benny Prijono | 7a38000 | 2009-03-09 12:55:29 +0000 | [diff] [blame] | 439 | /** |
| 440 | * Get string info for the specified capability. |
| 441 | * |
| 442 | * @param cap The capability ID. |
| 443 | * @param p_desc Optional pointer which will be filled with longer |
| 444 | * description about the capability. |
| 445 | * |
| 446 | * @return Capability name. |
| 447 | */ |
| 448 | PJ_DECL(const char*) pjmedia_aud_dev_cap_name(pjmedia_aud_dev_cap cap, |
| 449 | const char **p_desc); |
| 450 | |
| 451 | |
| 452 | /** |
| 453 | * Set a capability field value in #pjmedia_aud_param structure. This will |
| 454 | * also set the flags field for the specified capability in the structure. |
| 455 | * |
| 456 | * @param param The structure. |
| 457 | * @param cap The audio capability which value is to be set. |
| 458 | * @param value Pointer to value. Please see the type of value to |
| 459 | * be supplied in the pjmedia_aud_dev_cap documentation. |
| 460 | * |
| 461 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 462 | * error code. |
| 463 | */ |
| 464 | PJ_DECL(pj_status_t) pjmedia_aud_param_set_cap(pjmedia_aud_param *param, |
| 465 | pjmedia_aud_dev_cap cap, |
| 466 | const void *pval); |
| 467 | |
| 468 | |
| 469 | /** |
| 470 | * Get a capability field value from #pjmedia_aud_param structure. This |
| 471 | * function will return PJMEDIA_EAUD_INVCAP error if the flag for that |
| 472 | * capability is not set in the flags field in the structure. |
| 473 | * |
| 474 | * @param param The structure. |
| 475 | * @param cap The audio capability which value is to be retrieved. |
| 476 | * @param value Pointer to value. Please see the type of value to |
| 477 | * be supplied in the pjmedia_aud_dev_cap documentation. |
| 478 | * |
| 479 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 480 | * error code. |
| 481 | */ |
| 482 | PJ_DECL(pj_status_t) pjmedia_aud_param_get_cap(const pjmedia_aud_param *param, |
| 483 | pjmedia_aud_dev_cap cap, |
| 484 | void *pval); |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 485 | |
| 486 | /** |
| 487 | * Initialize the audio subsystem. This will register all supported audio |
| 488 | * device factories to the audio subsystem. This function may be called |
| 489 | * more than once, but each call to this function must have the |
| 490 | * corresponding #pjmedia_aud_subsys_shutdown() call. |
| 491 | * |
| 492 | * @param pf The pool factory. |
| 493 | * |
| 494 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 495 | * error code. |
| 496 | */ |
| 497 | PJ_DECL(pj_status_t) pjmedia_aud_subsys_init(pj_pool_factory *pf); |
| 498 | |
| 499 | |
| 500 | /** |
Benny Prijono | e3ebd55 | 2009-02-18 20:14:15 +0000 | [diff] [blame] | 501 | * Get the pool factory registered to the audio subsystem. |
| 502 | * |
| 503 | * @return The pool factory. |
| 504 | */ |
| 505 | PJ_DECL(pj_pool_factory*) pjmedia_aud_subsys_get_pool_factory(void); |
| 506 | |
| 507 | |
| 508 | /** |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 509 | * Shutdown the audio subsystem. This will destroy all audio device factories |
| 510 | * registered in the audio subsystem. Note that currently opened audio streams |
| 511 | * may or may not be closed, depending on the implementation of the audio |
| 512 | * device factories. |
| 513 | * |
| 514 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 515 | * error code. |
| 516 | */ |
| 517 | PJ_DECL(pj_status_t) pjmedia_aud_subsys_shutdown(void); |
| 518 | |
| 519 | |
| 520 | /** |
Sauw Ming | 8fd1693 | 2010-05-05 04:23:27 +0000 | [diff] [blame] | 521 | * Register a supported audio device factory to the audio subsystem. This |
| 522 | * function can only be called after calling #pjmedia_aud_subsys_init(). |
| 523 | * |
| 524 | * @param adf The audio device factory. |
| 525 | * |
| 526 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 527 | * error code. |
| 528 | */ |
| 529 | PJ_DECL(pj_status_t) |
| 530 | pjmedia_aud_register_factory(pjmedia_aud_dev_factory_create_func_ptr adf); |
| 531 | |
| 532 | |
| 533 | /** |
| 534 | * Unregister an audio device factory from the audio subsystem. This |
| 535 | * function can only be called after calling #pjmedia_aud_subsys_init(). |
| 536 | * Devices from this factory will be unlisted. If a device from this factory |
| 537 | * is currently in use, then the behavior is undefined. |
| 538 | * |
| 539 | * @param adf The audio device factory. |
| 540 | * |
| 541 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 542 | * error code. |
| 543 | */ |
| 544 | PJ_DECL(pj_status_t) |
| 545 | pjmedia_aud_unregister_factory(pjmedia_aud_dev_factory_create_func_ptr adf); |
| 546 | |
| 547 | |
| 548 | /** |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 549 | * Get the number of sound devices installed in the system. |
| 550 | * |
| 551 | * @return The number of sound devices installed in the system. |
| 552 | */ |
| 553 | PJ_DECL(unsigned) pjmedia_aud_dev_count(void); |
| 554 | |
| 555 | |
| 556 | /** |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 557 | * Get device information. |
| 558 | * |
| 559 | * @param id The audio device ID. |
| 560 | * @param info The device information which will be filled in by this |
| 561 | * function once it returns successfully. |
| 562 | * |
| 563 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 564 | * error code. |
| 565 | */ |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 566 | PJ_DECL(pj_status_t) pjmedia_aud_dev_get_info(pjmedia_aud_dev_index id, |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 567 | pjmedia_aud_dev_info *info); |
| 568 | |
| 569 | |
| 570 | /** |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 571 | * Lookup device index based on the driver and device name. |
| 572 | * |
| 573 | * @param drv_name The driver name. |
| 574 | * @param dev_name The device name. |
Benny Prijono | 2058f47 | 2009-02-22 17:15:34 +0000 | [diff] [blame] | 575 | * @param id Pointer to store the returned device ID. |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 576 | * |
| 577 | * @return PJ_SUCCESS if the device can be found. |
| 578 | */ |
| 579 | PJ_DECL(pj_status_t) pjmedia_aud_dev_lookup(const char *drv_name, |
| 580 | const char *dev_name, |
| 581 | pjmedia_aud_dev_index *id); |
| 582 | |
| 583 | |
| 584 | /** |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 585 | * Initialize the audio device parameters with default values for the |
| 586 | * specified device. |
| 587 | * |
| 588 | * @param id The audio device ID. |
| 589 | * @param param The audio device parameters which will be initialized |
| 590 | * by this function once it returns successfully. |
| 591 | * |
| 592 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 593 | * error code. |
| 594 | */ |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 595 | PJ_DECL(pj_status_t) pjmedia_aud_dev_default_param(pjmedia_aud_dev_index id, |
| 596 | pjmedia_aud_param *param); |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 597 | |
| 598 | |
| 599 | /** |
| 600 | * Open audio stream object using the specified parameters. |
| 601 | * |
| 602 | * @param param Sound device parameters to be used for the stream. |
| 603 | * @param rec_cb Callback to be called on every input frame captured. |
| 604 | * @param play_cb Callback to be called everytime the sound device needs |
| 605 | * audio frames to be played back. |
| 606 | * @param user_data Arbitrary user data, which will be given back in the |
| 607 | * callbacks. |
Benny Prijono | 2058f47 | 2009-02-22 17:15:34 +0000 | [diff] [blame] | 608 | * @param p_strm Pointer to receive the audio stream. |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 609 | * |
| 610 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 611 | * error code. |
| 612 | */ |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 613 | PJ_DECL(pj_status_t) pjmedia_aud_stream_create(const pjmedia_aud_param *param, |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 614 | pjmedia_aud_rec_cb rec_cb, |
| 615 | pjmedia_aud_play_cb play_cb, |
| 616 | void *user_data, |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 617 | pjmedia_aud_stream **p_strm); |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 618 | |
| 619 | /** |
| 620 | * Get the running parameters for the specified audio stream. |
| 621 | * |
| 622 | * @param strm The audio stream. |
| 623 | * @param param Audio stream parameters to be filled in by this |
| 624 | * function once it returns successfully. |
| 625 | * |
| 626 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 627 | * error code. |
| 628 | */ |
| 629 | PJ_DECL(pj_status_t) pjmedia_aud_stream_get_param(pjmedia_aud_stream *strm, |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 630 | pjmedia_aud_param *param); |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 631 | |
| 632 | /** |
| 633 | * Get the value of a specific capability of the audio stream. |
| 634 | * |
| 635 | * @param strm The audio stream. |
| 636 | * @param cap The audio capability which value is to be retrieved. |
| 637 | * @param value Pointer to value to be filled in by this function |
Benny Prijono | 7a38000 | 2009-03-09 12:55:29 +0000 | [diff] [blame] | 638 | * once it returns successfully. Please see the type |
| 639 | * of value to be supplied in the pjmedia_aud_dev_cap |
| 640 | * documentation. |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 641 | * |
| 642 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 643 | * error code. |
| 644 | */ |
| 645 | PJ_DECL(pj_status_t) pjmedia_aud_stream_get_cap(pjmedia_aud_stream *strm, |
| 646 | pjmedia_aud_dev_cap cap, |
| 647 | void *value); |
| 648 | |
| 649 | /** |
| 650 | * Set the value of a specific capability of the audio stream. |
| 651 | * |
| 652 | * @param strm The audio stream. |
| 653 | * @param cap The audio capability which value is to be set. |
Benny Prijono | 7a38000 | 2009-03-09 12:55:29 +0000 | [diff] [blame] | 654 | * @param value Pointer to value. Please see the type of value to |
| 655 | * be supplied in the pjmedia_aud_dev_cap documentation. |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 656 | * |
| 657 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 658 | * error code. |
| 659 | */ |
| 660 | PJ_DECL(pj_status_t) pjmedia_aud_stream_set_cap(pjmedia_aud_stream *strm, |
| 661 | pjmedia_aud_dev_cap cap, |
| 662 | const void *value); |
| 663 | |
| 664 | /** |
| 665 | * Start the stream. |
| 666 | * |
| 667 | * @param strm The audio stream. |
| 668 | * |
| 669 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 670 | * error code. |
| 671 | */ |
| 672 | PJ_DECL(pj_status_t) pjmedia_aud_stream_start(pjmedia_aud_stream *strm); |
| 673 | |
| 674 | /** |
| 675 | * Stop the stream. |
| 676 | * |
| 677 | * @param strm The audio stream. |
| 678 | * |
| 679 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 680 | * error code. |
| 681 | */ |
| 682 | PJ_DECL(pj_status_t) pjmedia_aud_stream_stop(pjmedia_aud_stream *strm); |
| 683 | |
| 684 | /** |
| 685 | * Destroy the stream. |
| 686 | * |
| 687 | * @param strm The audio stream. |
| 688 | * |
| 689 | * @return PJ_SUCCESS on successful operation or the appropriate |
| 690 | * error code. |
| 691 | */ |
| 692 | PJ_DECL(pj_status_t) pjmedia_aud_stream_destroy(pjmedia_aud_stream *strm); |
| 693 | |
| 694 | |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 695 | /** |
Benny Prijono | 2058f47 | 2009-02-22 17:15:34 +0000 | [diff] [blame] | 696 | * @} |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 697 | */ |
| 698 | |
| 699 | PJ_END_DECL |
| 700 | |
| 701 | |
Benny Prijono | 10454dc | 2009-02-21 14:21:59 +0000 | [diff] [blame] | 702 | #endif /* __PJMEDIA_AUDIODEV_AUDIODEV_H__ */ |
Benny Prijono | 2cd64f8 | 2009-02-17 19:57:48 +0000 | [diff] [blame] | 703 | |