| 1 |
/* |
| 2 |
* Copyright © 2011 Mozilla Foundation |
| 3 |
* |
| 4 |
* This program is made available under an ISC-style license. See the |
| 5 |
* accompanying file LICENSE for details. |
| 6 |
*/ |
| 7 |
#if !defined(CUBEB_c2f983e9_c96f_e71c_72c3_bbf62992a382) |
| 8 |
#define CUBEB_c2f983e9_c96f_e71c_72c3_bbf62992a382 |
| 9 |
|
| 10 |
#include "cubeb_export.h" |
| 11 |
#include <stdint.h> |
| 12 |
#include <stdlib.h> |
| 13 |
|
| 14 |
#if defined(__cplusplus) |
| 15 |
extern "C" { |
| 16 |
#endif |
| 17 |
|
| 18 |
/** @mainpage |
| 19 |
|
| 20 |
@section intro Introduction |
| 21 |
|
| 22 |
This is the documentation for the <tt>libcubeb</tt> C API. |
| 23 |
<tt>libcubeb</tt> is a callback-based audio API library allowing the |
| 24 |
authoring of portable multiplatform audio playback and recording. |
| 25 |
|
| 26 |
@section example Example code |
| 27 |
|
| 28 |
This example shows how to create a duplex stream that pipes the microphone |
| 29 |
to the speakers, with minimal latency and the proper sample-rate for the |
| 30 |
platform. |
| 31 |
|
| 32 |
@code |
| 33 |
cubeb * app_ctx; |
| 34 |
cubeb_init(&app_ctx, "Example Application", NULL); |
| 35 |
int rv; |
| 36 |
uint32_t rate; |
| 37 |
uint32_t latency_frames; |
| 38 |
uint64_t ts; |
| 39 |
|
| 40 |
rv = cubeb_get_preferred_sample_rate(app_ctx, &rate); |
| 41 |
if (rv != CUBEB_OK) { |
| 42 |
fprintf(stderr, "Could not get preferred sample-rate"); |
| 43 |
return rv; |
| 44 |
} |
| 45 |
|
| 46 |
cubeb_stream_params output_params; |
| 47 |
output_params.format = CUBEB_SAMPLE_FLOAT32NE; |
| 48 |
output_params.rate = rate; |
| 49 |
output_params.channels = 2; |
| 50 |
output_params.layout = CUBEB_LAYOUT_UNDEFINED; |
| 51 |
output_params.prefs = CUBEB_STREAM_PREF_NONE; |
| 52 |
|
| 53 |
rv = cubeb_get_min_latency(app_ctx, &output_params, &latency_frames); |
| 54 |
if (rv != CUBEB_OK) { |
| 55 |
fprintf(stderr, "Could not get minimum latency"); |
| 56 |
return rv; |
| 57 |
} |
| 58 |
|
| 59 |
cubeb_stream_params input_params; |
| 60 |
input_params.format = CUBEB_SAMPLE_FLOAT32NE; |
| 61 |
input_params.rate = rate; |
| 62 |
input_params.channels = 1; |
| 63 |
input_params.layout = CUBEB_LAYOUT_UNDEFINED; |
| 64 |
input_params.prefs = CUBEB_STREAM_PREF_NONE; |
| 65 |
|
| 66 |
cubeb_stream * stm; |
| 67 |
rv = cubeb_stream_init(app_ctx, &stm, "Example Stream 1", |
| 68 |
NULL, &input_params, |
| 69 |
NULL, &output_params, |
| 70 |
latency_frames, |
| 71 |
data_cb, state_cb, |
| 72 |
NULL); |
| 73 |
if (rv != CUBEB_OK) { |
| 74 |
fprintf(stderr, "Could not open the stream"); |
| 75 |
return rv; |
| 76 |
} |
| 77 |
|
| 78 |
rv = cubeb_stream_start(stm); |
| 79 |
if (rv != CUBEB_OK) { |
| 80 |
fprintf(stderr, "Could not start the stream"); |
| 81 |
return rv; |
| 82 |
} |
| 83 |
for (;;) { |
| 84 |
cubeb_stream_get_position(stm, &ts); |
| 85 |
printf("time=%llu\n", ts); |
| 86 |
sleep(1); |
| 87 |
} |
| 88 |
rv = cubeb_stream_stop(stm); |
| 89 |
if (rv != CUBEB_OK) { |
| 90 |
fprintf(stderr, "Could not stop the stream"); |
| 91 |
return rv; |
| 92 |
} |
| 93 |
|
| 94 |
cubeb_stream_destroy(stm); |
| 95 |
cubeb_destroy(app_ctx); |
| 96 |
@endcode |
| 97 |
|
| 98 |
@code |
| 99 |
long data_cb(cubeb_stream * stm, void * user, |
| 100 |
const void * input_buffer, void * output_buffer, long nframes) |
| 101 |
{ |
| 102 |
const float * in = input_buffer; |
| 103 |
float * out = output_buffer; |
| 104 |
|
| 105 |
for (int i = 0; i < nframes; ++i) { |
| 106 |
for (int c = 0; c < 2; ++c) { |
| 107 |
out[2 * i + c] = in[i]; |
| 108 |
} |
| 109 |
} |
| 110 |
return nframes; |
| 111 |
} |
| 112 |
@endcode |
| 113 |
|
| 114 |
@code |
| 115 |
void state_cb(cubeb_stream * stm, void * user, cubeb_state state) |
| 116 |
{ |
| 117 |
printf("state=%d\n", state); |
| 118 |
} |
| 119 |
@endcode |
| 120 |
*/ |
| 121 |
|
| 122 |
/** @file |
| 123 |
The <tt>libcubeb</tt> C API. */ |
| 124 |
|
| 125 |
typedef struct cubeb |
| 126 |
cubeb; /**< Opaque handle referencing the application state. */ |
| 127 |
typedef struct cubeb_stream |
| 128 |
cubeb_stream; /**< Opaque handle referencing the stream state. */ |
| 129 |
|
| 130 |
/** Sample format enumeration. */ |
| 131 |
typedef enum { |
| 132 |
/**< Little endian 16-bit signed PCM. */ |
| 133 |
CUBEB_SAMPLE_S16LE, |
| 134 |
/**< Big endian 16-bit signed PCM. */ |
| 135 |
CUBEB_SAMPLE_S16BE, |
| 136 |
/**< Little endian 32-bit IEEE floating point PCM. */ |
| 137 |
CUBEB_SAMPLE_FLOAT32LE, |
| 138 |
/**< Big endian 32-bit IEEE floating point PCM. */ |
| 139 |
CUBEB_SAMPLE_FLOAT32BE, |
| 140 |
#if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) |
| 141 |
/**< Native endian 16-bit signed PCM. */ |
| 142 |
CUBEB_SAMPLE_S16NE = CUBEB_SAMPLE_S16BE, |
| 143 |
/**< Native endian 32-bit IEEE floating point PCM. */ |
| 144 |
CUBEB_SAMPLE_FLOAT32NE = CUBEB_SAMPLE_FLOAT32BE |
| 145 |
#else |
| 146 |
/**< Native endian 16-bit signed PCM. */ |
| 147 |
CUBEB_SAMPLE_S16NE = CUBEB_SAMPLE_S16LE, |
| 148 |
/**< Native endian 32-bit IEEE floating point PCM. */ |
| 149 |
CUBEB_SAMPLE_FLOAT32NE = CUBEB_SAMPLE_FLOAT32LE |
| 150 |
#endif |
| 151 |
} cubeb_sample_format; |
| 152 |
|
| 153 |
/** An opaque handle used to refer a particular input or output device |
| 154 |
* across calls. */ |
| 155 |
typedef void const * cubeb_devid; |
| 156 |
|
| 157 |
/** Level (verbosity) of logging for a particular cubeb context. */ |
| 158 |
typedef enum { |
| 159 |
CUBEB_LOG_DISABLED = 0, /** < Logging disabled */ |
| 160 |
CUBEB_LOG_NORMAL = |
| 161 |
1, /**< Logging lifetime operation (creation/destruction). */ |
| 162 |
CUBEB_LOG_VERBOSE = 2, /**< Verbose logging of callbacks, can have performance |
| 163 |
implications. */ |
| 164 |
} cubeb_log_level; |
| 165 |
|
| 166 |
/// A single channel position, to be used in a bitmask. |
| 167 |
typedef enum { |
| 168 |
CHANNEL_UNKNOWN = 0, |
| 169 |
CHANNEL_FRONT_LEFT = 1 << 0, |
| 170 |
CHANNEL_FRONT_RIGHT = 1 << 1, |
| 171 |
CHANNEL_FRONT_CENTER = 1 << 2, |
| 172 |
CHANNEL_LOW_FREQUENCY = 1 << 3, |
| 173 |
CHANNEL_BACK_LEFT = 1 << 4, |
| 174 |
CHANNEL_BACK_RIGHT = 1 << 5, |
| 175 |
CHANNEL_FRONT_LEFT_OF_CENTER = 1 << 6, |
| 176 |
CHANNEL_FRONT_RIGHT_OF_CENTER = 1 << 7, |
| 177 |
CHANNEL_BACK_CENTER = 1 << 8, |
| 178 |
CHANNEL_SIDE_LEFT = 1 << 9, |
| 179 |
CHANNEL_SIDE_RIGHT = 1 << 10, |
| 180 |
CHANNEL_TOP_CENTER = 1 << 11, |
| 181 |
CHANNEL_TOP_FRONT_LEFT = 1 << 12, |
| 182 |
CHANNEL_TOP_FRONT_CENTER = 1 << 13, |
| 183 |
CHANNEL_TOP_FRONT_RIGHT = 1 << 14, |
| 184 |
CHANNEL_TOP_BACK_LEFT = 1 << 15, |
| 185 |
CHANNEL_TOP_BACK_CENTER = 1 << 16, |
| 186 |
CHANNEL_TOP_BACK_RIGHT = 1 << 17 |
| 187 |
} cubeb_channel; |
| 188 |
|
| 189 |
/// A bitmask representing the channel layout of a cubeb stream. This is |
| 190 |
/// bit-compatible with WAVEFORMATEXENSIBLE and in the same order as the SMPTE |
| 191 |
/// ordering. |
| 192 |
typedef uint32_t cubeb_channel_layout; |
| 193 |
// Some common layout definitions. |
| 194 |
enum { |
| 195 |
CUBEB_LAYOUT_UNDEFINED = 0, // Indicate the speaker's layout is undefined. |
| 196 |
CUBEB_LAYOUT_MONO = CHANNEL_FRONT_CENTER, |
| 197 |
CUBEB_LAYOUT_MONO_LFE = CUBEB_LAYOUT_MONO | CHANNEL_LOW_FREQUENCY, |
| 198 |
CUBEB_LAYOUT_STEREO = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT, |
| 199 |
CUBEB_LAYOUT_STEREO_LFE = CUBEB_LAYOUT_STEREO | CHANNEL_LOW_FREQUENCY, |
| 200 |
CUBEB_LAYOUT_3F = |
| 201 |
CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | CHANNEL_FRONT_CENTER, |
| 202 |
CUBEB_LAYOUT_3F_LFE = CUBEB_LAYOUT_3F | CHANNEL_LOW_FREQUENCY, |
| 203 |
CUBEB_LAYOUT_2F1 = |
| 204 |
CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | CHANNEL_BACK_CENTER, |
| 205 |
CUBEB_LAYOUT_2F1_LFE = CUBEB_LAYOUT_2F1 | CHANNEL_LOW_FREQUENCY, |
| 206 |
CUBEB_LAYOUT_3F1 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | |
| 207 |
CHANNEL_FRONT_CENTER | CHANNEL_BACK_CENTER, |
| 208 |
CUBEB_LAYOUT_3F1_LFE = CUBEB_LAYOUT_3F1 | CHANNEL_LOW_FREQUENCY, |
| 209 |
CUBEB_LAYOUT_2F2 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | |
| 210 |
CHANNEL_SIDE_LEFT | CHANNEL_SIDE_RIGHT, |
| 211 |
CUBEB_LAYOUT_2F2_LFE = CUBEB_LAYOUT_2F2 | CHANNEL_LOW_FREQUENCY, |
| 212 |
CUBEB_LAYOUT_QUAD = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | |
| 213 |
CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT, |
| 214 |
CUBEB_LAYOUT_QUAD_LFE = CUBEB_LAYOUT_QUAD | CHANNEL_LOW_FREQUENCY, |
| 215 |
CUBEB_LAYOUT_3F2 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | |
| 216 |
CHANNEL_FRONT_CENTER | CHANNEL_SIDE_LEFT | |
| 217 |
CHANNEL_SIDE_RIGHT, |
| 218 |
CUBEB_LAYOUT_3F2_LFE = CUBEB_LAYOUT_3F2 | CHANNEL_LOW_FREQUENCY, |
| 219 |
CUBEB_LAYOUT_3F2_BACK = CUBEB_LAYOUT_QUAD | CHANNEL_FRONT_CENTER, |
| 220 |
CUBEB_LAYOUT_3F2_LFE_BACK = CUBEB_LAYOUT_3F2_BACK | CHANNEL_LOW_FREQUENCY, |
| 221 |
CUBEB_LAYOUT_3F3R_LFE = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | |
| 222 |
CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | |
| 223 |
CHANNEL_BACK_CENTER | CHANNEL_SIDE_LEFT | |
| 224 |
CHANNEL_SIDE_RIGHT, |
| 225 |
CUBEB_LAYOUT_3F4_LFE = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | |
| 226 |
CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | |
| 227 |
CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT | |
| 228 |
CHANNEL_SIDE_LEFT | CHANNEL_SIDE_RIGHT, |
| 229 |
}; |
| 230 |
|
| 231 |
/** Miscellaneous stream preferences. */ |
| 232 |
typedef enum { |
| 233 |
CUBEB_STREAM_PREF_NONE = 0x00, /**< No stream preferences are requested. */ |
| 234 |
CUBEB_STREAM_PREF_LOOPBACK = |
| 235 |
0x01, /**< Request a loopback stream. Should be |
| 236 |
specified on the input params and an |
| 237 |
output device to loopback from should |
| 238 |
be passed in place of an input device. */ |
| 239 |
CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING = 0x02, /**< Disable switching |
| 240 |
default device on OS |
| 241 |
changes. */ |
| 242 |
CUBEB_STREAM_PREF_VOICE = |
| 243 |
0x04, /**< This stream is going to transport voice data. |
| 244 |
Depending on the backend and platform, this can |
| 245 |
change the audio input or output devices |
| 246 |
selected, as well as the quality of the stream, |
| 247 |
for example to accomodate bluetooth SCO modes on |
| 248 |
bluetooth devices. */ |
| 249 |
CUBEB_STREAM_PREF_RAW = |
| 250 |
0x08, /**< Windows only. Bypass all signal processing |
| 251 |
except for always on APO, driver and hardware. */ |
| 252 |
CUBEB_STREAM_PREF_PERSIST = 0x10, /**< Request that the volume and mute |
| 253 |
settings should persist across restarts |
| 254 |
of the stream and/or application. This is |
| 255 |
obsolete and ignored by all backends. */ |
| 256 |
CUBEB_STREAM_PREF_JACK_NO_AUTO_CONNECT = 0x20 /**< Don't automatically try to |
| 257 |
connect ports. Only affects |
| 258 |
the jack backend. */ |
| 259 |
} cubeb_stream_prefs; |
| 260 |
|
| 261 |
/** |
| 262 |
* Input stream audio processing parameters. Only applicable with |
| 263 |
* CUBEB_STREAM_PREF_VOICE. |
| 264 |
*/ |
| 265 |
typedef enum { |
| 266 |
CUBEB_INPUT_PROCESSING_PARAM_NONE = 0x00, |
| 267 |
CUBEB_INPUT_PROCESSING_PARAM_ECHO_CANCELLATION = 0x01, |
| 268 |
CUBEB_INPUT_PROCESSING_PARAM_NOISE_SUPPRESSION = 0x02, |
| 269 |
CUBEB_INPUT_PROCESSING_PARAM_AUTOMATIC_GAIN_CONTROL = 0x04, |
| 270 |
CUBEB_INPUT_PROCESSING_PARAM_VOICE_ISOLATION = 0x08, |
| 271 |
} cubeb_input_processing_params; |
| 272 |
|
| 273 |
/** Stream format initialization parameters. */ |
| 274 |
typedef struct { |
| 275 |
cubeb_sample_format format; /**< Requested sample format. One of |
| 276 |
#cubeb_sample_format. */ |
| 277 |
uint32_t rate; /**< Requested sample rate. Valid range is [1000, 384000]. */ |
| 278 |
uint32_t channels; /**< Requested channel count. Valid range is [1, 8]. */ |
| 279 |
cubeb_channel_layout |
| 280 |
layout; /**< Requested channel layout. This must be consistent with the |
| 281 |
provided channels. CUBEB_LAYOUT_UNDEFINED if unknown */ |
| 282 |
cubeb_stream_prefs prefs; /**< Requested preferences. */ |
| 283 |
} cubeb_stream_params; |
| 284 |
|
| 285 |
/** Audio device description */ |
| 286 |
typedef struct { |
| 287 |
char * output_name; /**< The name of the output device */ |
| 288 |
char * input_name; /**< The name of the input device */ |
| 289 |
} cubeb_device; |
| 290 |
|
| 291 |
/** Stream states signaled via state_callback. */ |
| 292 |
typedef enum { |
| 293 |
CUBEB_STATE_STARTED, /**< Stream started. */ |
| 294 |
CUBEB_STATE_STOPPED, /**< Stream stopped. */ |
| 295 |
CUBEB_STATE_DRAINED, /**< Stream drained. */ |
| 296 |
CUBEB_STATE_ERROR /**< Stream disabled due to error. */ |
| 297 |
} cubeb_state; |
| 298 |
|
| 299 |
/** Result code enumeration. */ |
| 300 |
enum { |
| 301 |
CUBEB_OK = 0, /**< Success. */ |
| 302 |
CUBEB_ERROR = -1, /**< Unclassified error. */ |
| 303 |
CUBEB_ERROR_INVALID_FORMAT = |
| 304 |
-2, /**< Unsupported #cubeb_stream_params requested. */ |
| 305 |
CUBEB_ERROR_INVALID_PARAMETER = -3, /**< Invalid parameter specified. */ |
| 306 |
CUBEB_ERROR_NOT_SUPPORTED = |
| 307 |
-4, /**< Optional function not implemented in current backend. */ |
| 308 |
CUBEB_ERROR_DEVICE_UNAVAILABLE = |
| 309 |
-5 /**< Device specified by #cubeb_devid not available. */ |
| 310 |
}; |
| 311 |
|
| 312 |
/** |
| 313 |
* Whether a particular device is an input device (e.g. a microphone), or an |
| 314 |
* output device (e.g. headphones). */ |
| 315 |
typedef enum { |
| 316 |
CUBEB_DEVICE_TYPE_UNKNOWN, |
| 317 |
CUBEB_DEVICE_TYPE_INPUT, |
| 318 |
CUBEB_DEVICE_TYPE_OUTPUT |
| 319 |
} cubeb_device_type; |
| 320 |
|
| 321 |
/** |
| 322 |
* The state of a device. |
| 323 |
*/ |
| 324 |
typedef enum { |
| 325 |
CUBEB_DEVICE_STATE_DISABLED, /**< The device has been disabled at the system |
| 326 |
level. */ |
| 327 |
CUBEB_DEVICE_STATE_UNPLUGGED, /**< The device is enabled, but nothing is |
| 328 |
plugged into it. */ |
| 329 |
CUBEB_DEVICE_STATE_ENABLED /**< The device is enabled. */ |
| 330 |
} cubeb_device_state; |
| 331 |
|
| 332 |
/** |
| 333 |
* Architecture specific sample type. |
| 334 |
*/ |
| 335 |
typedef enum { |
| 336 |
CUBEB_DEVICE_FMT_S16LE = 0x0010, /**< 16-bit integers, Little Endian. */ |
| 337 |
CUBEB_DEVICE_FMT_S16BE = 0x0020, /**< 16-bit integers, Big Endian. */ |
| 338 |
CUBEB_DEVICE_FMT_F32LE = 0x1000, /**< 32-bit floating point, Little Endian. */ |
| 339 |
CUBEB_DEVICE_FMT_F32BE = 0x2000 /**< 32-bit floating point, Big Endian. */ |
| 340 |
} cubeb_device_fmt; |
| 341 |
|
| 342 |
#if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) |
| 343 |
/** 16-bit integers, native endianess, when on a Big Endian environment. */ |
| 344 |
#define CUBEB_DEVICE_FMT_S16NE CUBEB_DEVICE_FMT_S16BE |
| 345 |
/** 32-bit floating points, native endianess, when on a Big Endian environment. |
| 346 |
*/ |
| 347 |
#define CUBEB_DEVICE_FMT_F32NE CUBEB_DEVICE_FMT_F32BE |
| 348 |
#else |
| 349 |
/** 16-bit integers, native endianess, when on a Little Endian environment. */ |
| 350 |
#define CUBEB_DEVICE_FMT_S16NE CUBEB_DEVICE_FMT_S16LE |
| 351 |
/** 32-bit floating points, native endianess, when on a Little Endian |
| 352 |
* environment. */ |
| 353 |
#define CUBEB_DEVICE_FMT_F32NE CUBEB_DEVICE_FMT_F32LE |
| 354 |
#endif |
| 355 |
/** All the 16-bit integers types. */ |
| 356 |
#define CUBEB_DEVICE_FMT_S16_MASK \ |
| 357 |
(CUBEB_DEVICE_FMT_S16LE | CUBEB_DEVICE_FMT_S16BE) |
| 358 |
/** All the 32-bit floating points types. */ |
| 359 |
#define CUBEB_DEVICE_FMT_F32_MASK \ |
| 360 |
(CUBEB_DEVICE_FMT_F32LE | CUBEB_DEVICE_FMT_F32BE) |
| 361 |
/** All the device formats types. */ |
| 362 |
#define CUBEB_DEVICE_FMT_ALL \ |
| 363 |
(CUBEB_DEVICE_FMT_S16_MASK | CUBEB_DEVICE_FMT_F32_MASK) |
| 364 |
|
| 365 |
/** Channel type for a `cubeb_stream`. Depending on the backend and platform |
| 366 |
* used, this can control inter-stream interruption, ducking, and volume |
| 367 |
* control. |
| 368 |
*/ |
| 369 |
typedef enum { |
| 370 |
CUBEB_DEVICE_PREF_NONE = 0x00, |
| 371 |
CUBEB_DEVICE_PREF_MULTIMEDIA = 0x01, |
| 372 |
CUBEB_DEVICE_PREF_VOICE = 0x02, |
| 373 |
CUBEB_DEVICE_PREF_NOTIFICATION = 0x04, |
| 374 |
CUBEB_DEVICE_PREF_ALL = 0x0F |
| 375 |
} cubeb_device_pref; |
| 376 |
|
| 377 |
/** This structure holds the characteristics |
| 378 |
* of an input or output audio device. It is obtained using |
| 379 |
* `cubeb_enumerate_devices`, which returns these structures via |
| 380 |
* `cubeb_device_collection` and must be destroyed via |
| 381 |
* `cubeb_device_collection_destroy`. */ |
| 382 |
typedef struct { |
| 383 |
cubeb_devid devid; /**< Device identifier handle. */ |
| 384 |
char const * |
| 385 |
device_id; /**< Device identifier which might be presented in a UI. */ |
| 386 |
char const * friendly_name; /**< Friendly device name which might be presented |
| 387 |
in a UI. */ |
| 388 |
char const * group_id; /**< Two devices have the same group identifier if they |
| 389 |
belong to the same physical device; for example a |
| 390 |
headset and microphone. */ |
| 391 |
char const * vendor_name; /**< Optional vendor name, may be NULL. */ |
| 392 |
|
| 393 |
cubeb_device_type type; /**< Type of device (Input/Output). */ |
| 394 |
cubeb_device_state state; /**< State of device disabled/enabled/unplugged. */ |
| 395 |
cubeb_device_pref preferred; /**< Preferred device. */ |
| 396 |
|
| 397 |
cubeb_device_fmt format; /**< Sample format supported. */ |
| 398 |
cubeb_device_fmt |
| 399 |
default_format; /**< The default sample format for this device. */ |
| 400 |
uint32_t max_channels; /**< Channels. */ |
| 401 |
uint32_t default_rate; /**< Default/Preferred sample rate. */ |
| 402 |
uint32_t max_rate; /**< Maximum sample rate supported. */ |
| 403 |
uint32_t min_rate; /**< Minimum sample rate supported. */ |
| 404 |
|
| 405 |
uint32_t latency_lo; /**< Lowest possible latency in frames. */ |
| 406 |
uint32_t latency_hi; /**< Higest possible latency in frames. */ |
| 407 |
} cubeb_device_info; |
| 408 |
|
| 409 |
/** Device collection. |
| 410 |
* Returned by `cubeb_enumerate_devices` and destroyed by |
| 411 |
* `cubeb_device_collection_destroy`. */ |
| 412 |
typedef struct { |
| 413 |
cubeb_device_info * device; /**< Array of pointers to device info. */ |
| 414 |
size_t count; /**< Device count in collection. */ |
| 415 |
} cubeb_device_collection; |
| 416 |
|
| 417 |
/** User supplied data callback. |
| 418 |
- Calling other cubeb functions from this callback is unsafe. |
| 419 |
- The code in the callback should be non-blocking. |
| 420 |
- Returning less than the number of frames this callback asks for or |
| 421 |
provides puts the stream in drain mode. This callback will not be called |
| 422 |
again, and the state callback will be called with CUBEB_STATE_DRAINED when |
| 423 |
all the frames have been output. |
| 424 |
@param stream The stream for which this callback fired. |
| 425 |
@param user_ptr The pointer passed to cubeb_stream_init. |
| 426 |
@param input_buffer A pointer containing the input data, or nullptr |
| 427 |
if this is an output-only stream. |
| 428 |
@param output_buffer A pointer to a buffer to be filled with audio samples, |
| 429 |
or nullptr if this is an input-only stream. |
| 430 |
@param nframes The number of frames of the two buffer. |
| 431 |
@retval If the stream has output, this is the number of frames written to |
| 432 |
the output buffer. In this case, if this number is less than |
| 433 |
nframes then the stream will start to drain. If the stream is |
| 434 |
input only, then returning nframes indicates data has been read. |
| 435 |
In this case, a value less than nframes will result in the stream |
| 436 |
being stopped. |
| 437 |
@retval CUBEB_ERROR on error, in which case the data callback will stop |
| 438 |
and the stream will enter a shutdown state. */ |
| 439 |
typedef long (*cubeb_data_callback)(cubeb_stream * stream, void * user_ptr, |
| 440 |
void const * input_buffer, |
| 441 |
void * output_buffer, long nframes); |
| 442 |
|
| 443 |
/** User supplied state callback. |
| 444 |
@param stream The stream for this this callback fired. |
| 445 |
@param user_ptr The pointer passed to cubeb_stream_init. |
| 446 |
@param state The new state of the stream. */ |
| 447 |
typedef void (*cubeb_state_callback)(cubeb_stream * stream, void * user_ptr, |
| 448 |
cubeb_state state); |
| 449 |
|
| 450 |
/** |
| 451 |
* User supplied callback called when the underlying device changed. |
| 452 |
* @param user_ptr The pointer passed to cubeb_stream_init. */ |
| 453 |
typedef void (*cubeb_device_changed_callback)(void * user_ptr); |
| 454 |
|
| 455 |
/** |
| 456 |
* User supplied callback called when the underlying device collection changed. |
| 457 |
* @param context A pointer to the cubeb context. |
| 458 |
* @param user_ptr The pointer passed to |
| 459 |
* cubeb_register_device_collection_changed. */ |
| 460 |
typedef void (*cubeb_device_collection_changed_callback)(cubeb * context, |
| 461 |
void * user_ptr); |
| 462 |
|
| 463 |
/** User supplied callback called when a message needs logging. */ |
| 464 |
typedef void (*cubeb_log_callback)(char const * fmt, ...); |
| 465 |
|
| 466 |
/** Initialize an application context. This will perform any library or |
| 467 |
application scoped initialization. |
| 468 |
|
| 469 |
Note: On Windows platforms, COM must be initialized in MTA mode on |
| 470 |
any thread that will call the cubeb API. |
| 471 |
|
| 472 |
@param context A out param where an opaque pointer to the application |
| 473 |
context will be returned. |
| 474 |
@param context_name A name for the context. Depending on the platform this |
| 475 |
can appear in different locations. |
| 476 |
@param backend_name The name of the cubeb backend user desires to select. |
| 477 |
Accepted values self-documented in cubeb.c: init_oneshot |
| 478 |
If NULL, a default ordering is used for backend choice. |
| 479 |
A valid choice overrides all other possible backends, |
| 480 |
so long as the backend was included at compile time. |
| 481 |
@retval CUBEB_OK in case of success. |
| 482 |
@retval CUBEB_ERROR in case of error, for example because the host |
| 483 |
has no audio hardware. */ |
| 484 |
CUBEB_EXPORT int |
| 485 |
cubeb_init(cubeb ** context, char const * context_name, |
| 486 |
char const * backend_name); |
| 487 |
|
| 488 |
/** Get a read-only string identifying this context's current backend. |
| 489 |
@param context A pointer to the cubeb context. |
| 490 |
@retval Read-only string identifying current backend. */ |
| 491 |
CUBEB_EXPORT char const * |
| 492 |
cubeb_get_backend_id(cubeb * context); |
| 493 |
|
| 494 |
/** Get the maximum possible number of channels. |
| 495 |
@param context A pointer to the cubeb context. |
| 496 |
@param max_channels The maximum number of channels. |
| 497 |
@retval CUBEB_OK |
| 498 |
@retval CUBEB_ERROR_INVALID_PARAMETER |
| 499 |
@retval CUBEB_ERROR_NOT_SUPPORTED |
| 500 |
@retval CUBEB_ERROR */ |
| 501 |
CUBEB_EXPORT int |
| 502 |
cubeb_get_max_channel_count(cubeb * context, uint32_t * max_channels); |
| 503 |
|
| 504 |
/** Get the minimal latency value, in frames, that is guaranteed to work |
| 505 |
when creating a stream for the specified sample rate. This is platform, |
| 506 |
hardware and backend dependent. |
| 507 |
@param context A pointer to the cubeb context. |
| 508 |
@param params On some backends, the minimum achievable latency depends on |
| 509 |
the characteristics of the stream. |
| 510 |
@param latency_frames The latency value, in frames, to pass to |
| 511 |
cubeb_stream_init. |
| 512 |
@retval CUBEB_OK |
| 513 |
@retval CUBEB_ERROR_INVALID_PARAMETER |
| 514 |
@retval CUBEB_ERROR_NOT_SUPPORTED */ |
| 515 |
CUBEB_EXPORT int |
| 516 |
cubeb_get_min_latency(cubeb * context, cubeb_stream_params * params, |
| 517 |
uint32_t * latency_frames); |
| 518 |
|
| 519 |
/** Get the preferred sample rate for this backend: this is hardware and |
| 520 |
platform dependent, and can avoid resampling, and/or trigger fastpaths. |
| 521 |
@param context A pointer to the cubeb context. |
| 522 |
@param rate The samplerate (in Hz) the current configuration prefers. |
| 523 |
@retval CUBEB_OK |
| 524 |
@retval CUBEB_ERROR_INVALID_PARAMETER |
| 525 |
@retval CUBEB_ERROR_NOT_SUPPORTED */ |
| 526 |
CUBEB_EXPORT int |
| 527 |
cubeb_get_preferred_sample_rate(cubeb * context, uint32_t * rate); |
| 528 |
|
| 529 |
/** Get the supported input processing features for this backend. See |
| 530 |
cubeb_stream_set_input_processing for how to set them for a particular input |
| 531 |
stream. |
| 532 |
@param context A pointer to the cubeb context. |
| 533 |
@param params Out parameter for the input processing params supported by |
| 534 |
this backend. |
| 535 |
@retval CUBEB_OK |
| 536 |
@retval CUBEB_ERROR_NOT_SUPPORTED */ |
| 537 |
CUBEB_EXPORT int |
| 538 |
cubeb_get_supported_input_processing_params( |
| 539 |
cubeb * context, cubeb_input_processing_params * params); |
| 540 |
|
| 541 |
/** Destroy an application context. This must be called after all stream have |
| 542 |
* been destroyed. |
| 543 |
@param context A pointer to the cubeb context.*/ |
| 544 |
CUBEB_EXPORT void |
| 545 |
cubeb_destroy(cubeb * context); |
| 546 |
|
| 547 |
/** Initialize a stream associated with the supplied application context. |
| 548 |
@param context A pointer to the cubeb context. |
| 549 |
@param stream An out parameter to be filled with the an opaque pointer to a |
| 550 |
cubeb stream. |
| 551 |
@param stream_name A name for this stream. |
| 552 |
@param input_device Device for the input side of the stream. If NULL the |
| 553 |
default input device is used. Passing a valid |
| 554 |
cubeb_devid means the stream only ever uses that device. Passing a NULL |
| 555 |
cubeb_devid allows the stream to follow that device |
| 556 |
type's OS default. |
| 557 |
@param input_stream_params Parameters for the input side of the stream, or |
| 558 |
NULL if this stream is output only. |
| 559 |
@param output_device Device for the output side of the stream. If NULL the |
| 560 |
default output device is used. Passing a valid |
| 561 |
cubeb_devid means the stream only ever uses that device. Passing a NULL |
| 562 |
cubeb_devid allows the stream to follow that device |
| 563 |
type's OS default. |
| 564 |
@param output_stream_params Parameters for the output side of the stream, or |
| 565 |
NULL if this stream is input only. When input |
| 566 |
and output stream parameters are supplied, their |
| 567 |
rate has to be the same. |
| 568 |
@param latency_frames Stream latency in frames. Valid range |
| 569 |
is [1, 96000]. |
| 570 |
@param data_callback Will be called to preroll data before playback is |
| 571 |
started by cubeb_stream_start. |
| 572 |
@param state_callback A pointer to a state callback. |
| 573 |
@param user_ptr A pointer that will be passed to the callbacks. This pointer |
| 574 |
must outlive the life time of the stream. |
| 575 |
@retval CUBEB_OK |
| 576 |
@retval CUBEB_ERROR |
| 577 |
@retval CUBEB_ERROR_INVALID_FORMAT |
| 578 |
@retval CUBEB_ERROR_DEVICE_UNAVAILABLE */ |
| 579 |
CUBEB_EXPORT int |
| 580 |
cubeb_stream_init(cubeb * context, cubeb_stream ** stream, |
| 581 |
char const * stream_name, cubeb_devid input_device, |
| 582 |
cubeb_stream_params * input_stream_params, |
| 583 |
cubeb_devid output_device, |
| 584 |
cubeb_stream_params * output_stream_params, |
| 585 |
uint32_t latency_frames, cubeb_data_callback data_callback, |
| 586 |
cubeb_state_callback state_callback, void * user_ptr); |
| 587 |
|
| 588 |
/** Destroy a stream. `cubeb_stream_stop` MUST be called before destroying a |
| 589 |
stream. |
| 590 |
@param stream The stream to destroy. */ |
| 591 |
CUBEB_EXPORT void |
| 592 |
cubeb_stream_destroy(cubeb_stream * stream); |
| 593 |
|
| 594 |
/** Start playback. |
| 595 |
@param stream |
| 596 |
@retval CUBEB_OK |
| 597 |
@retval CUBEB_ERROR */ |
| 598 |
CUBEB_EXPORT int |
| 599 |
cubeb_stream_start(cubeb_stream * stream); |
| 600 |
|
| 601 |
/** Stop playback. |
| 602 |
@param stream |
| 603 |
@retval CUBEB_OK |
| 604 |
@retval CUBEB_ERROR */ |
| 605 |
CUBEB_EXPORT int |
| 606 |
cubeb_stream_stop(cubeb_stream * stream); |
| 607 |
|
| 608 |
/** Get the current stream playback position. |
| 609 |
@param stream |
| 610 |
@param position Playback position in frames. |
| 611 |
@retval CUBEB_OK |
| 612 |
@retval CUBEB_ERROR */ |
| 613 |
CUBEB_EXPORT int |
| 614 |
cubeb_stream_get_position(cubeb_stream * stream, uint64_t * position); |
| 615 |
|
| 616 |
/** Get the latency for this stream, in frames. This is the number of frames |
| 617 |
between the time cubeb acquires the data in the callback and the listener |
| 618 |
can hear the sound. |
| 619 |
@param stream |
| 620 |
@param latency Current approximate stream latency in frames. |
| 621 |
@retval CUBEB_OK |
| 622 |
@retval CUBEB_ERROR_NOT_SUPPORTED |
| 623 |
@retval CUBEB_ERROR */ |
| 624 |
CUBEB_EXPORT int |
| 625 |
cubeb_stream_get_latency(cubeb_stream * stream, uint32_t * latency); |
| 626 |
|
| 627 |
/** Get the input latency for this stream, in frames. This is the number of |
| 628 |
frames between the time the audio input devices records the data, and they |
| 629 |
are available in the data callback. |
| 630 |
This returns CUBEB_ERROR when the stream is output-only. |
| 631 |
@param stream |
| 632 |
@param latency Current approximate stream latency in frames. |
| 633 |
@retval CUBEB_OK |
| 634 |
@retval CUBEB_ERROR_NOT_SUPPORTED |
| 635 |
@retval CUBEB_ERROR */ |
| 636 |
CUBEB_EXPORT int |
| 637 |
cubeb_stream_get_input_latency(cubeb_stream * stream, uint32_t * latency); |
| 638 |
/** Set the volume for a stream. |
| 639 |
@param stream the stream for which to adjust the volume. |
| 640 |
@param volume a float between 0.0 (muted) and 1.0 (maximum volume) |
| 641 |
@retval CUBEB_OK |
| 642 |
@retval CUBEB_ERROR_INVALID_PARAMETER volume is outside [0.0, 1.0] or |
| 643 |
stream is an invalid pointer |
| 644 |
@retval CUBEB_ERROR_NOT_SUPPORTED */ |
| 645 |
CUBEB_EXPORT int |
| 646 |
cubeb_stream_set_volume(cubeb_stream * stream, float volume); |
| 647 |
|
| 648 |
/** Change a stream's name. |
| 649 |
@param stream the stream for which to set the name. |
| 650 |
@param stream_name the new name for the stream |
| 651 |
@retval CUBEB_OK |
| 652 |
@retval CUBEB_ERROR_INVALID_PARAMETER if any pointer is invalid |
| 653 |
@retval CUBEB_ERROR_NOT_SUPPORTED */ |
| 654 |
CUBEB_EXPORT int |
| 655 |
cubeb_stream_set_name(cubeb_stream * stream, char const * stream_name); |
| 656 |
|
| 657 |
/** Get the current output device for this stream. |
| 658 |
@param stm the stream for which to query the current output device |
| 659 |
@param device a pointer in which the current output device will be stored. |
| 660 |
@retval CUBEB_OK in case of success |
| 661 |
@retval CUBEB_ERROR_INVALID_PARAMETER if either stm, device or count are |
| 662 |
invalid pointers |
| 663 |
@retval CUBEB_ERROR_NOT_SUPPORTED */ |
| 664 |
CUBEB_EXPORT int |
| 665 |
cubeb_stream_get_current_device(cubeb_stream * stm, |
| 666 |
cubeb_device ** const device); |
| 667 |
|
| 668 |
/** Set input mute state for this stream. Some platforms notify the user when an |
| 669 |
application is accessing audio input. When all inputs are muted they can |
| 670 |
prove to the user that the application is not actively capturing any input. |
| 671 |
@param stream the stream for which to set input mute state |
| 672 |
@param muted whether the input should mute or not |
| 673 |
@retval CUBEB_OK |
| 674 |
@retval CUBEB_ERROR_INVALID_PARAMETER if this stream does not have an input |
| 675 |
device |
| 676 |
@retval CUBEB_ERROR_NOT_SUPPORTED */ |
| 677 |
CUBEB_EXPORT int |
| 678 |
cubeb_stream_set_input_mute(cubeb_stream * stream, int mute); |
| 679 |
|
| 680 |
/** Set what input processing features to enable for this stream. |
| 681 |
@param stream the stream for which to set input processing features. |
| 682 |
@param params what input processing features to use |
| 683 |
@retval CUBEB_OK |
| 684 |
@retval CUBEB_ERROR if params could not be applied |
| 685 |
@retval CUBEB_ERROR_INVALID_PARAMETER if a given param is not supported by |
| 686 |
this backend, or if this stream does not have an input device |
| 687 |
@retval CUBEB_ERROR_NOT_SUPPORTED */ |
| 688 |
CUBEB_EXPORT int |
| 689 |
cubeb_stream_set_input_processing_params(cubeb_stream * stream, |
| 690 |
cubeb_input_processing_params params); |
| 691 |
|
| 692 |
/** Destroy a cubeb_device structure. |
| 693 |
@param stream the stream passed in cubeb_stream_get_current_device |
| 694 |
@param devices the devices to destroy |
| 695 |
@retval CUBEB_OK in case of success |
| 696 |
@retval CUBEB_ERROR_INVALID_PARAMETER if devices is an invalid pointer |
| 697 |
@retval CUBEB_ERROR_NOT_SUPPORTED */ |
| 698 |
CUBEB_EXPORT int |
| 699 |
cubeb_stream_device_destroy(cubeb_stream * stream, cubeb_device * devices); |
| 700 |
|
| 701 |
/** Set a callback to be notified when the output device changes. |
| 702 |
@param stream the stream for which to set the callback. |
| 703 |
@param device_changed_callback a function called whenever the device has |
| 704 |
changed. Passing NULL allow to unregister a function |
| 705 |
@retval CUBEB_OK |
| 706 |
@retval CUBEB_ERROR_INVALID_PARAMETER if either stream or |
| 707 |
device_changed_callback are invalid pointers. |
| 708 |
@retval CUBEB_ERROR_NOT_SUPPORTED */ |
| 709 |
CUBEB_EXPORT int |
| 710 |
cubeb_stream_register_device_changed_callback( |
| 711 |
cubeb_stream * stream, |
| 712 |
cubeb_device_changed_callback device_changed_callback); |
| 713 |
|
| 714 |
/** Return the user data pointer registered with the stream with |
| 715 |
cubeb_stream_init. |
| 716 |
@param stream the stream for which to retrieve user data pointer. |
| 717 |
@retval user data pointer */ |
| 718 |
CUBEB_EXPORT void * |
| 719 |
cubeb_stream_user_ptr(cubeb_stream * stream); |
| 720 |
|
| 721 |
/** Returns enumerated devices. |
| 722 |
@param context |
| 723 |
@param devtype device type to include |
| 724 |
@param collection output collection. Must be destroyed with |
| 725 |
cubeb_device_collection_destroy |
| 726 |
@retval CUBEB_OK in case of success |
| 727 |
@retval CUBEB_ERROR_INVALID_PARAMETER if collection is an invalid pointer |
| 728 |
@retval CUBEB_ERROR_NOT_SUPPORTED */ |
| 729 |
CUBEB_EXPORT int |
| 730 |
cubeb_enumerate_devices(cubeb * context, cubeb_device_type devtype, |
| 731 |
cubeb_device_collection * collection); |
| 732 |
|
| 733 |
/** Destroy a cubeb_device_collection, and its `cubeb_device_info`. |
| 734 |
@param context |
| 735 |
@param collection collection to destroy |
| 736 |
@retval CUBEB_OK |
| 737 |
@retval CUBEB_ERROR_INVALID_PARAMETER if collection is an invalid pointer */ |
| 738 |
CUBEB_EXPORT int |
| 739 |
cubeb_device_collection_destroy(cubeb * context, |
| 740 |
cubeb_device_collection * collection); |
| 741 |
|
| 742 |
/** Registers a callback which is called when the system detects |
| 743 |
a new device or a device is removed. |
| 744 |
@param context |
| 745 |
@param devtype device type to include. Different callbacks and user pointers |
| 746 |
can be registered for each devtype. The hybrid devtype |
| 747 |
`CUBEB_DEVICE_TYPE_INPUT | CUBEB_DEVICE_TYPE_OUTPUT` is also valid |
| 748 |
and will register the provided callback and user pointer in both |
| 749 |
sides. |
| 750 |
@param callback a function called whenever the system device list changes. |
| 751 |
Passing NULL allow to unregister a function. You have to unregister |
| 752 |
first before you register a new callback. |
| 753 |
@param user_ptr pointer to user specified data which will be present in |
| 754 |
subsequent callbacks. |
| 755 |
@retval CUBEB_ERROR_NOT_SUPPORTED */ |
| 756 |
CUBEB_EXPORT int |
| 757 |
cubeb_register_device_collection_changed( |
| 758 |
cubeb * context, cubeb_device_type devtype, |
| 759 |
cubeb_device_collection_changed_callback callback, void * user_ptr); |
| 760 |
|
| 761 |
/** Set a callback to be called with a message. |
| 762 |
@param log_level CUBEB_LOG_VERBOSE, CUBEB_LOG_NORMAL. |
| 763 |
@param log_callback A function called with a message when there is |
| 764 |
something to log. Pass NULL to unregister. |
| 765 |
@retval CUBEB_OK in case of success. |
| 766 |
@retval CUBEB_ERROR_INVALID_PARAMETER if either context or log_callback are |
| 767 |
invalid pointers, or if level is not |
| 768 |
in cubeb_log_level. */ |
| 769 |
CUBEB_EXPORT int |
| 770 |
cubeb_set_log_callback(cubeb_log_level log_level, |
| 771 |
cubeb_log_callback log_callback); |
| 772 |
|
| 773 |
#if defined(__cplusplus) |
| 774 |
} |
| 775 |
#endif |
| 776 |
|
| 777 |
#endif /* CUBEB_c2f983e9_c96f_e71c_72c3_bbf62992a382 */ |