blob: 929fc2130e04f941c1861a905de392a62b6b2413 [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001 /**
2 * @file bdIMADpj.h
3 * @brief bdSound IMproved Audio Device for PJSIP.
4 */
5
6/**
7 * @defgroup bd_IMAD bdIMADpj bdSound IMproved Audio Device for PJSIP.
8 * @ingroup audio_device_api
9 *
10 * <b>bdSound IMproved Audio Device</b> is a multiplatform audio interface
11 * created to integrate in <b>PJSIP</b> library with no effort.
12 * \n Porting <b>bdIMADpj</b> across the main operating systems is
13 * straightforward, without the need of change a single line of code.
14 *
15 * - <b>Features</b>
16 * - Echo cancellation (Full Duplex)
17 * - Noise reduction
18 * - Automatic Gain Control
19 * - Audio Enhancement
20 *
21 * - <b>Supported operating systems</b>
22 * - Windows
23 * - Android
24 * - MacOS X
25 * - iOS
26 * - Linux / Alsa
27 *
28 * - <b>Supported platforms</b>
29 * - x86
30 * - x64
31 * - ARM Cortex-A8/A9/A15 with NEON
32 *
33 * Visit <a href="http:/www.bdsound.com" target="new">bdSound</a> for updated
34 * features, supported operating systems and platforms.
35 *
36 * <b>Using PJSIP with bdIMAD audio device</b>
37 *
38 * - <b>Integration</b>
39 * \n Using <b>bdIMAD</b> within <b>PJSIP</b> is simple:
40 * -# Request for bdIMADpj library to
41 * <a href="http:/www.bdsound.com" target="new">bdSound</a>:
42 * bdSound will provide instruction to integrate the library depending on
43 * the platform / O.S. / toolchain;
44 * -# Add the <code>bdimad_dev.c</code> file to
45 * <code>pjmedia/src/pjmedia-audiodev</code> folder;
46 * -# Enable the bdIMAD audio device defining the periferal in the
47 * <code>pj/config_site.h</code> and disabling all other devices:
48 * <pre>
49 * #define PJMEDIA_AUDIO_DEV_HAS_BDIMAD 1
50 * </pre>
51 *
52 * - <b>Usage</b>
53 * \n There are only a couple of things the customer have to pay attention on
54 * §when using bdIMAD library.
55 *
56 * - <b>Initialization</b>
57 * \n Since the bdIMAD library provide itself the echo cancellation
58 * and the latency management, is necessary to disable these features
59 * in the PJSIP librariy applications.
60 * \n For example in PJSUA sample application there is the need
61 * to provide the following commands:
62 * <pre>
63 * --ec-tail=0
64 * --no-vad
65 * --capture-lat=0
66 * --playback-lat=0
67 * </pre>
68 *
69 * - <b>Supported set capability</b>
70 * - <code>PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING</code>
71 * \n Setting speaker volume.
72 * - <code>PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING</code>
73 * \n Setting michrophone volume.
74 * - <code>PJMEDIA_AUD_DEV_CAP_EC</code>
75 * \n Enable/disable echo cancellation.
76 *
77 * For additional information visit
78 * <a href="http:/www.bdsound.com" target="new">www.bdsound.com</a>
79 * or write to info@bdsound.com
80 *
81 * @author bdSound
82 * @version 1.0.1
83 * @copyright 2012 bdSound srl. All rights reserved.
84 *
85 */
86
87/**
88 * @defgroup groupFunction Functions
89 * @ingroup bd_IMAD
90 *
91 * Functions defined in bdIMAD.
92 */
93
94/**
95 * @defgroup groupCallback Callbacks
96 * @ingroup bd_IMAD
97 *
98 * Callbacks defined in bdIMAD.
99 */
100
101/**
102 * @defgroup groupStructEnum Structs and Enums
103 * @ingroup bd_IMAD
104 *
105 * Struct and Enum defined in bdIMAD.
106 */
107
108#ifndef BD_IMAD_PJ_H__
109#define BD_IMAD_PJ_H__
110
111/**
112 * @brief Macro for Windows DLL Support.
113 */
114
115#ifdef _BDIMADPJ_EXPORTDLL
116 #ifdef WIN32
117 #define BDIMADPJ_API __declspec(dllexport)
118 #else
119 #define BDIMADPJ_API __attribute__((visibility("default")))
120 #endif
121#else
122 #define BDIMADPJ_API
123#endif
124
125#define BD_IMAD_CAPTURE_DEVICES 1
126#define BD_IMAD_PLAYBACK_DEVICES 0
127#define BD_IMAD_DIAGNOSTIC_ENABLE 1
128#define BD_IMAD_DIAGNOSTIC_DISABLE 0
129
130#define BD_IMAD_BITS_X_SAMPLE 16 /**< Bits per sample */
131
132typedef void* bdIMADpj;
133
134/**
135 * @addtogroup groupCallback
136 * @{
137 */
138
139/**
140 * @brief Callback used to fill the playback buffer of bdIMAD.
141 * The function is called by bdIMAD each time are required sample to be played.
142 * @param[in] *buffer pointer to the buffer with the audio
143 * samples to be played(short type).
144 * @param[in] nSamples number of samples required.
145 * @param[in] user_data pointer to the user data structure
146 * defined in the bdIMADpj_Setting_t
147 * structure.
148 * @return none.
149 */
150
151typedef int (* cb_fillPlayBackB_t) (void *buffer, int nSamples,
152 void *user_data);
153
154/**
155 * @brief Callback used to retrive the caputre buffer of bdIMAD. The function
156 * is called by bdIMAD each time processed mic samples are available.
157 * @param[out] *buffer pointer to the buffer with the audio
158 * samples to download(short type).
159 * @param[in] nSamples number of samples processed to download.
160 * @param[in] user_data pointer to the user data structure
161 * defined in the MainSet structure.
162 * @return none.
163 */
164
165typedef void (* cb_emptyCaptureB_t) (void *buffer, int nSamples,
166 void *user_data);
167/**
168 * @}
169 */
170
171/**
172 * @addtogroup groupStructEnum
173 * @{
174 */
175
176/**
177 * @brief Error status returned by some functions in the library.
178 */
179
180typedef enum bdIMADpj_Status{
181 /**< No error. */
182 BD_PJ_OK = 0,
183 /**< Watch bdIMADpj_Warnings_t structure to find the warnings. */
184 BD_PJ_WARN_BDIMAD_WARNING_ASSERTED = 1,
185 /**< Error not identified. */
186 BD_PJ_ERROR_GENERIC = 2,
187 /**< The pointer passed is NULL. */
188 BD_PJ_ERROR_NULL_POINTER = 3,
189 /**< Allocation procedure failed. */
190 BD_PJ_ERROR_ALLOCATION = 4,
191 /**< The parameter is not existent or the set/get function is not active. */
192 BD_PJ_ERROR_PARAMETER_NOT_FOUND = 5,
193 /**< No capture device found. */
194 BD_PJ_ERROR_IMAD_NONE_CAPTURE_DEV = 10,
195 /**< No play device found. */
196 BD_PJ_ERROR_IMAD_NONE_PLAY_DEV = 11,
197 /**< Frame size not allowed. */
198 BD_PJ_ERROR_IMAD_FRAME_SIZE = 12,
199 /**< Sample frequency not allowed. */
200 BD_PJ_ERROR_IMAD_SAMPLE_FREQ = 13,
201 /**< Samples missing. */
202 BD_PJ_ERROR_IMAD_MISSING_SAMPLES = 14,
203 /**< Device list is empty. */
204 BD_PJ_ERROR_IMAD_DEVICE_LIST_EMPTY = 15,
205 /**< Library not authorized, entering demo mode. */
206 BD_PJ_ERROR_IMAD_LIB_NOT_AUTHORIZED = 16,
207 /**< The input channel memory has not been allocated. */
208 BD_PJ_ERROR_IMAD_INPUT_CH_NOT_ALLOCATED = 17,
209 /**< The library has expired, entering demo mode. */
210 BD_PJ_ERROR_IMAD_LICENSE_EXPIRED = 18,
211 /**< Open of capture device failed. */
212 BD_PJ_ERROR_IMAD_OPEN_CAPTURE_DEV_FAILED = 19,
213 /**< Open of play device failed. */
214 BD_PJ_ERROR_IMAD_OPEN_PLAY_DEV_FAILED = 20,
215 /**< Start of play device failed. */
216 BD_PJ_ERROR_IMAD_START_PLAY_DEV_FAILED = 21,
217 /**< Start of capture device failed. */
218 BD_PJ_ERROR_IMAD_START_CAPTURE_DEV_FAILED = 22,
219 /**< Start of time process failed. */
220 BD_PJ_ERROR_IMAD_START_TIME_PROCESS_FAILED = 23,
221 /**< Start of thread process failed. */
222 BD_PJ_ERROR_IMAD_THREAD_PROCESS_FAILED = 24,
223 /**< No volume control available. */
224 BD_PJ_ERROR_IMAD_NO_VOL_CONTROL_AVAILABLE = 25,
225} bdIMADpj_Status;
226
227/**
228 * @brief Parameter to pass to set and get parameter functions.
229 *
230 * For each enumeration are defined the data type and the supported operations
231 * on that parameter (set and get).
232 */
233
234typedef enum bdIMADpj_Parameter{
235 /**< int* \n set/get \n 1 enable / 0 disable echo cancellation. */
236 BD_PARAM_IMAD_PJ_AEC_ENABLE = 1,
237 /**< int* \n set/get \n 1 enable / 0 disable microphone control
238 * (when possible). */
239 BD_PARAM_IMAD_PJ_MIC_CONTROL_ENABLE = 2,
240 /**< int* \n set/get \n 1 ebable / 0 disable noise reduction. */
241 BD_PARAM_IMAD_PJ_NOISE_REDUCTION_ENABLE = 3,
242 /**< int* \n set \n number of channel to reset. Used to reset
243 * the input channel statistics. To be used when the same channel
244 * is assigned to another partecipant. */
245 BD_PARAM_IMAD_PJ_RESET_STATISTIC_IN_CH = 4,
246 /**< float* \n set/get \n 0.0f -> 1.0f volume of
247 * the microphone(when possible). */
248 BD_PARAM_IMAD_PJ_MIC_VOLUME = 5,
249 /**< int* \n set/get \n 0 mute / 1 not mute on microphone
250 * (when possible). */
251 BD_PARAM_IMAD_PJ_MIC_MUTE = 6,
252 /**< float* \n set/get \n 0.0f -> 1.0f volume of the speaker. */
253 BD_PARAM_IMAD_PJ_SPK_VOLUME = 7,
254 /**< int* \n set/get \n 0 mute / 1 not mute on speaker. */
255 BD_PARAM_IMAD_PJ_SPK_MUTE = 8,
256} bdIMADpj_Parameter;
257
258
259/**
260 * @brief Instance structure for the information regarding the aec engine.
261 */
262
263typedef struct bdIMADpj_Setting_t{
264 /**< Sample frequency (8kHz or 16kHz). */
265 int SamplingFrequency;
266 /**< Audio buffer managed by the aec bdIMAD functions.
267 * (from 16ms to 80ms, 16ms recommended). */
268 int FrameSize_ms;
269 /**< Points to the validation functions in the validation library. */
270 void *validate;
271 /**< Points to the the callback function used for filling
272 * the playback buffer of bdIMAD. */
273 cb_fillPlayBackB_t cb_fillPlayBackBuffer;
274 /**< Points to user data to pass to the callback. */
275 void *cb_fillPlayBackBuffer_user_data;
276 /**< Points to the callback function used for retreive the processed
277 * audio present in the capture buffer of bdIMAD. */
278 cb_emptyCaptureB_t cb_emptyCaptureBuffer;
279 /**< Points to user data to pass to the callback. */
280 void *cb_emptyCaptureBuffer_user_data;
281 /**< Is a wide char pointer to the capture device name. */
282 wchar_t *CaptureDevice;
283 /**< Is a wide char pointer to the play device name. */
284 wchar_t *PlayDevice;
285 /**< True to enable diagnostic, false to disable. */
286 int DiagnosticEnable;
287 /**< Directory which will contains the files generated for diagnostic. */
288 wchar_t *DiagnosticFolderPath;
289 /**< Is an auxiliary settings pointer used internally by bdIMAD. */
290 void *bdIMADwr_SettingsData;
291} bdIMADpj_Setting_t;
292
293/**
294 * @brief Instance structure for the warnings generated by the initialization
295 * functions.
296 */
297
298typedef struct bdIMADpj_Warnings_t{
299 /**< The capture device indicated can't be opened, has been selected
300 * the default capture device. */
301 int DefaultCaptureDeviceAutomaticallySelected;
302 /**< The capture device opened has not volume control. */
303 int CaptureDeviceWithoutVolumeControl;
304 /**< The play device indicated can't be opened, has been selected
305 * the default play device. */
306 int DefaultPlayDeviceAutomaticallySelected;
307 /**< The number of channel requested is out of range. The number of
308 * channel opened is equal to the maximum. */
309 int NumberOfChannelsOutOfRange;
310 /**< The diagnostic files could not be saved. */
311 int DiagnosticSaveNotAllowed;
312 /**< The nlp level requested is not allowed, it has been automatically
313 * changed to the default value. */
314 int nlpLevelChangeSettting;
315 /**< No capture device is present. Anyway the bdSES has been
316 * istantiated only for playback. */
317 int NoCaptureDevicePresent;
318 /**< The cpu is not adapt to run the aec engine, the aec has been disabled.
319 * This appens for very old cpu like pentium III. */
320 int oldCPUdetected_AECdisable;
321 /**< Windows Direct Sound error. */
322 long directSoundError;
323 /**< Windows Direct Sound volume error. */
324 long directSoundLevel;
325 /**< No play device is present. Anyway the bdSES has been istantiated
326 * only for capture. */
327 int NoPlayDevicePresent;
328} bdIMADpj_Warnings_t;
329
330/**
331 * @brief Instance structure for the library version
332 */
333
334typedef struct bdIMADpj_libVersion_t{
335 int major; /**< major version. */
336 int minor; /**< minor version. */
337 int build; /**< build number. */
338 char *name; /**< name "bdIMADpj ver.X". */
339 char *version; /**< beta, RC, release. */
340 char *buildDate; /**< build date. */
341} bdIMADpj_libVersion_t;
342
343/**
344 * @}
345 */
346
347
348
349/**
350 * @addtogroup groupFunction
351 * @{
352 */
353
354#ifdef __cplusplus
355extern "C" {
356#endif
357
358/**
359 * @brief Must be used to allocate and set to default parameter the memory
360 * for the bdIMAD.
361 *
362 * The function generate a structure bdIMADpj_Setting_t filled with the
363 * default settings.
364 * \n The user can change this settings according to the need and then
365 * launch the ::bdIMADpj_InitAEC.
366 * \n The function generate also a warning structure (::bdIMADpj_Warnings_t)
367 * that could be used in ::bdIMADpj_InitAEC to handle eventual warnings.
368 * @param[out] **ppSettings Points to the pointer of the
369 * allocated ::bdIMADpj_Setting_t.
370 * @param[out] **ppWarningMessages Points to the pointer of the
371 * allocated ::bdIMADpj_Warnings_t.
372 * @return ::BD_PJ_OK if the function has been
373 * performed successfully, otherwise return
374 * an error (refer to ::bdIMADpj_Status).
375 */
376BDIMADPJ_API bdIMADpj_Status bdIMADpj_CreateStructures(
377 bdIMADpj_Setting_t **ppSettings,
378 bdIMADpj_Warnings_t **ppWarningMessages);
379
380/**
381 * @brief Is used to free the memory for the ::bdIMADpj_Setting_t structure and
382 * ::bdIMADpj_Warnings_t structure allocated with
383 * the ::bdIMADpj_CreateStructures.
384 * @param[in] **ppSettings Pointer to a memory location filled
385 * with the address of the
386 * ::bdIMADpj_Setting_t structure to free.
387 * This address will be set to NULL.
388 * @param[in] **ppWarningMessages Pointer to a memory location filled
389 * with the address of the allocated
390 * ::bdIMADpj_Warnings_t structure to free.
391 * This address will be set to NULL.
392 * @return ::BD_PJ_OK if the function has been
393 * performed successfully, otherwise return
394 * an error (refer to ::bdIMADpj_Status).
395 */
396BDIMADPJ_API bdIMADpj_Status bdIMADpj_FreeStructures(
397 bdIMADpj_Setting_t **ppSettings,
398 bdIMADpj_Warnings_t **ppWarningMessages);
399
400/**
401 * @brief Is used to initialize the memory for bdIMAD with the settings
402 * contained in the <code>ppSettings</code>.
403 * @param[out] *pBdIMADInstance Is the pointer to the bdIMAD object.
404 * @param[in] **ppSettings Pointer to pointer to a
405 * ::bdIMADpj_Setting_t structure, filled
406 * with initialization settings to be
407 * applied to the bdIMAD.
408 * \n Note, the <code>pBdIMADInstance</code>
409 * is modified with the applied settings.
410 * @param[out] **ppWarningMessages Pointer to pointer to a
411 * ::bdIMADpj_Warnings_t sructure,
412 * which reports the warnings after the
413 * initialization.
414 * @return ::BD_PJ_OK if the function has been
415 * performed successfully, otherwise return
416 * an error (refer to ::bdIMADpj_Status).
417 * \n If the error is
418 * ::BD_PJ_WARN_BDIMAD_WARNING_ASSERTED
419 * the init has been performed with success,
420 * but with a different settings
421 * respect to the ones required.
422 * This mainly happens if the audio
423 * device opened is different to the
424 * one requested.
425 */
426BDIMADPJ_API bdIMADpj_Status bdIMADpj_InitAEC(bdIMADpj *pBdIMADInstance,
427 bdIMADpj_Setting_t **ppSettings,
428 bdIMADpj_Warnings_t **ppWarningMessages);
429
430/**
431 * @brief Is used to free the bdIMAD object pointed by the
432 * <code>pBdIMADInstance</code>.
433 * @param[in] *pBdIMADInstance Pointer to the bdIMAD object to free.
434 * @return ::BD_PJ_OK if the function has been
435 * performed successfully, otherwise return
436 * an error (refer to ::bdIMADpj_Status).
437 */
438BDIMADPJ_API bdIMADpj_Status bdIMADpj_FreeAEC(bdIMADpj *pBdIMADInstance);
439
440/**
441 * @brief Is used to make a list of capure and play devices available
442 * on the system.
443 * @param[in] captureDevice Set to 1 to get the list of capture
444 * devices. Set to 0 to get the list of
445 * play devices.
446 * @param[in] **deviceName Pointer to pointer to a wide char
447 * containing the names of capture/play
448 * devices.
449 * @return ::BD_PJ_OK if the function has been
450 * performed successfully, otherwise return
451 * an error (refer to ::bdIMADpj_Status).
452 */
453BDIMADPJ_API bdIMADpj_Status bdIMADpj_getDeviceName(int captureDevice,
454 wchar_t **deviceName);
455
456/**
457 * @brief Is used to freeze the bdIMAD, stopping the audio playback
458 * and recording.
459 * @param[in] bdIMADInstance bdIMAD object.
460 * @return ::BD_PJ_OK if the function has been
461 * performed successfully, otherwise
462 * return an error (refer to
463 * ::bdIMADpj_Status).
464 */
465BDIMADPJ_API bdIMADpj_Status bdIMADpj_stop(bdIMADpj bdIMADInstance);
466
467/**
468 * @brief Is used to put back in play the audio after it has been stopped by the
469 * ::bdIMADpj_stop functions.
470 * @param[in] bdIMADInstance bdIMAD object.
471 * @return ::BD_PJ_OK if the function has been
472 * performed successfully, otherwise
473 * return an error (refer to
474 * ::bdIMADpj_Status).
475 */
476BDIMADPJ_API bdIMADpj_Status bdIMADpj_run(bdIMADpj bdIMADInstance);
477
478/**
479 * @brief Print on a standard output the warning messages.
480 * @param[in] *pWarningMessages Pointer to the warning structure
481 * to be printed.
482 * @return ::BD_PJ_OK if the function has been
483 * performed successfully, otherwise
484 * return an error
485 * (refer to ::bdIMADpj_Status).
486 */
487BDIMADPJ_API bdIMADpj_Status bdIMADpj_DisplayWarnings(
488 bdIMADpj_Warnings_t *pWarningMessages);
489
490/**
491 * @brief Clear the warning structure after being read.
492 * @param[out] **ppWarningMessages Pointer to pointer to the warning
493 * structure to be cleared.
494 * @return ::BD_PJ_OK if the function has been
495 * performed successfully, otherwise
496 * return an error (refer to
497 * ::bdIMADpj_Status).
498 */
499BDIMADPJ_API bdIMADpj_Status bdIMADpj_ClearAllWarnings(
500 bdIMADpj_Warnings_t **ppWarningMessages);
501
502/**
503 * @brief Is used to set a parameter of the bdIMAD object pointed by the
504 * <code>pBdIMADInstance</code>.
505 * @param[in] bdIMADInstance bdIMAD object.
506 * @param[in] parameterName Indicate the parameter to set.
507 * @param[in] *pValue Is a pointer to the value to set
508 * cast to void.
509 * \n In the ::bdIMADpj_Parameter
510 * declaration is indicated the real type of
511 * the value, depending on the
512 * <code>parameterName</code>.
513 * @return ::BD_PJ_OK if the function has been
514 * performed successfully, otherwise
515 * return an error (refer to
516 * §::bdIMADpj_Status).
517 */
518BDIMADPJ_API bdIMADpj_Status bdIMADpj_setParameter(bdIMADpj bdIMADInstance,
519 bdIMADpj_Parameter parameterName, void *pValue);
520
521/**
522 * @brief Is used to get a parameter of the bdIMAD object pointed by the
523 * <code>pBdIMADInstance</code>.
524 * @param[in] bdIMADInstance bdIMAD object.
525 * @param[in] parameterName Indicate the parameter to get.
526 * @param[out] *pValue Is a pointer to the value to get cast
527 * to void. \n In the
528 * ::bdIMADpj_Parameter declaration is
529 * indicated the real type of the value,
530 * depending on the
531 * <code>parameterName</code>.
532 * @return ::BD_PJ_OK if the function has been
533 * performed successfully, otherwise return
534 * an error (refer to ::bdIMADpj_Status).
535 */
536BDIMADPJ_API bdIMADpj_Status bdIMADpj_getParameter(bdIMADpj bdIMADInstance,
537 bdIMADpj_Parameter parameterName, void *pValue);
538
539
540#ifdef __cplusplus
541}
542#endif
543/**
544 * @}
545 */
546
547#endif //BD_IMAD_PJ_H__