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 <stdint.h> 11 #include <stdlib.h> 12 #include "cubeb_export.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"); 35 int rv; 36 uint32_t rate; 37 uint32_t latency_frames; 38 uint64_t ts; 39 40 rv = cubeb_get_min_latency(app_ctx, &output_params, &latency_frames); 41 if (rv != CUBEB_OK) { 42 fprintf(stderr, "Could not get minimum latency"); 43 return rv; 44 } 45 46 rv = cubeb_get_preferred_sample_rate(app_ctx, output_params, &rate); 47 if (rv != CUBEB_OK) { 48 fprintf(stderr, "Could not get preferred sample-rate"); 49 return rv; 50 } 51 52 cubeb_stream_params output_params; 53 output_params.format = CUBEB_SAMPLE_FLOAT32NE; 54 output_params.rate = rate; 55 output_params.channels = 2; 56 57 cubeb_stream_params input_params; 58 output_params.format = CUBEB_SAMPLE_FLOAT32NE; 59 output_params.rate = rate; 60 output_params.channels = 1; 61 62 cubeb_stream * stm; 63 rv = cubeb_stream_init(app_ctx, &stm, "Example Stream 1", 64 NULL, input_params, 65 NULL, output_params, 66 latency_frames, 67 data_cb, state_cb, 68 NULL); 69 if (rv != CUBEB_OK) { 70 fprintf(stderr, "Could not open the stream"); 71 return rv; 72 } 73 74 rv = cubeb_stream_start(stm); 75 if (rv != CUBEB_OK) { 76 fprintf(stderr, "Could not start the stream"); 77 return rv; 78 } 79 for (;;) { 80 cubeb_stream_get_position(stm, &ts); 81 printf("time=%llu\n", ts); 82 sleep(1); 83 } 84 rv = cubeb_stream_stop(stm); 85 if (rv != CUBEB_OK) { 86 fprintf(stderr, "Could not stop the stream"); 87 return rv; 88 } 89 90 cubeb_stream_destroy(stm); 91 cubeb_destroy(app_ctx); 92 @endcode 93 94 @code 95 long data_cb(cubeb_stream * stm, void * user, 96 void * input_buffer, void * output_buffer, long nframes) 97 { 98 float * in = input_buffer; 99 float * out = output_buffer; 100 101 for (i = 0; i < nframes; ++i) { 102 for (c = 0; c < 2; ++c) { 103 buf[i][c] = in[i]; 104 } 105 } 106 return nframes; 107 } 108 @endcode 109 110 @code 111 void state_cb(cubeb_stream * stm, void * user, cubeb_state state) 112 { 113 printf("state=%d\n", state); 114 } 115 @endcode 116 */ 117 118 /** @file 119 The <tt>libcubeb</tt> C API. */ 120 121 typedef struct cubeb cubeb; /**< Opaque handle referencing the application state. */ 122 typedef struct cubeb_stream cubeb_stream; /**< Opaque handle referencing the stream state. */ 123 124 /** Sample format enumeration. */ 125 typedef enum { 126 /**< Little endian 16-bit signed PCM. */ 127 CUBEB_SAMPLE_S16LE, 128 /**< Big endian 16-bit signed PCM. */ 129 CUBEB_SAMPLE_S16BE, 130 /**< Little endian 32-bit IEEE floating point PCM. */ 131 CUBEB_SAMPLE_FLOAT32LE, 132 /**< Big endian 32-bit IEEE floating point PCM. */ 133 CUBEB_SAMPLE_FLOAT32BE, 134 #if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) 135 /**< Native endian 16-bit signed PCM. */ 136 CUBEB_SAMPLE_S16NE = CUBEB_SAMPLE_S16BE, 137 /**< Native endian 32-bit IEEE floating point PCM. */ 138 CUBEB_SAMPLE_FLOAT32NE = CUBEB_SAMPLE_FLOAT32BE 139 #else 140 /**< Native endian 16-bit signed PCM. */ 141 CUBEB_SAMPLE_S16NE = CUBEB_SAMPLE_S16LE, 142 /**< Native endian 32-bit IEEE floating point PCM. */ 143 CUBEB_SAMPLE_FLOAT32NE = CUBEB_SAMPLE_FLOAT32LE 144 #endif 145 } cubeb_sample_format; 146 147 /** An opaque handle used to refer a particular input or output device 148 * across calls. */ 149 typedef void const * cubeb_devid; 150 151 /** Level (verbosity) of logging for a particular cubeb context. */ 152 typedef enum { 153 CUBEB_LOG_DISABLED = 0, /** < Logging disabled */ 154 CUBEB_LOG_NORMAL = 1, /**< Logging lifetime operation (creation/destruction). */ 155 CUBEB_LOG_VERBOSE = 2, /**< Verbose logging of callbacks, can have performance implications. */ 156 } cubeb_log_level; 157 158 /** SMPTE channel layout (also known as wave order) 159 * DUAL-MONO L R 160 * DUAL-MONO-LFE L R LFE 161 * MONO M 162 * MONO-LFE M LFE 163 * STEREO L R 164 * STEREO-LFE L R LFE 165 * 3F L R C 166 * 3F-LFE L R C LFE 167 * 2F1 L R S 168 * 2F1-LFE L R LFE S 169 * 3F1 L R C S 170 * 3F1-LFE L R C LFE S 171 * 2F2 L R LS RS 172 * 2F2-LFE L R LFE LS RS 173 * 3F2 L R C LS RS 174 * 3F2-LFE L R C LFE LS RS 175 * 3F3R-LFE L R C LFE RC LS RS 176 * 3F4-LFE L R C LFE RLS RRS LS RS 177 * 178 * The abbreviation of channel name is defined in following table: 179 * Abbr Channel name 180 * --------------------------- 181 * M Mono 182 * L Left 183 * R Right 184 * C Center 185 * LS Left Surround 186 * RS Right Surround 187 * RLS Rear Left Surround 188 * RC Rear Center 189 * RRS Rear Right Surround 190 * LFE Low Frequency Effects 191 */ 192 193 typedef enum { 194 CUBEB_LAYOUT_UNDEFINED, // Indicate the speaker's layout is undefined. 195 CUBEB_LAYOUT_DUAL_MONO, 196 CUBEB_LAYOUT_DUAL_MONO_LFE, 197 CUBEB_LAYOUT_MONO, 198 CUBEB_LAYOUT_MONO_LFE, 199 CUBEB_LAYOUT_STEREO, 200 CUBEB_LAYOUT_STEREO_LFE, 201 CUBEB_LAYOUT_3F, 202 CUBEB_LAYOUT_3F_LFE, 203 CUBEB_LAYOUT_2F1, 204 CUBEB_LAYOUT_2F1_LFE, 205 CUBEB_LAYOUT_3F1, 206 CUBEB_LAYOUT_3F1_LFE, 207 CUBEB_LAYOUT_2F2, 208 CUBEB_LAYOUT_2F2_LFE, 209 CUBEB_LAYOUT_3F2, 210 CUBEB_LAYOUT_3F2_LFE, 211 CUBEB_LAYOUT_3F3R_LFE, 212 CUBEB_LAYOUT_3F4_LFE, 213 CUBEB_LAYOUT_MAX 214 } cubeb_channel_layout; 215 216 /** Stream format initialization parameters. */ 217 typedef struct { 218 cubeb_sample_format format; /**< Requested sample format. One of 219 #cubeb_sample_format. */ 220 uint32_t rate; /**< Requested sample rate. Valid range is [1000, 192000]. */ 221 uint32_t channels; /**< Requested channel count. Valid range is [1, 8]. */ 222 cubeb_channel_layout layout; /**< Requested channel layout. This must be consistent with the provided channels. */ 223 } cubeb_stream_params; 224 225 /** Audio device description */ 226 typedef struct { 227 char * output_name; /**< The name of the output device */ 228 char * input_name; /**< The name of the input device */ 229 } cubeb_device; 230 231 /** Stream states signaled via state_callback. */ 232 typedef enum { 233 CUBEB_STATE_STARTED, /**< Stream started. */ 234 CUBEB_STATE_STOPPED, /**< Stream stopped. */ 235 CUBEB_STATE_DRAINED, /**< Stream drained. */ 236 CUBEB_STATE_ERROR /**< Stream disabled due to error. */ 237 } cubeb_state; 238 239 /** Result code enumeration. */ 240 enum { 241 CUBEB_OK = 0, /**< Success. */ 242 CUBEB_ERROR = -1, /**< Unclassified error. */ 243 CUBEB_ERROR_INVALID_FORMAT = -2, /**< Unsupported #cubeb_stream_params requested. */ 244 CUBEB_ERROR_INVALID_PARAMETER = -3, /**< Invalid parameter specified. */ 245 CUBEB_ERROR_NOT_SUPPORTED = -4, /**< Optional function not implemented in current backend. */ 246 CUBEB_ERROR_DEVICE_UNAVAILABLE = -5 /**< Device specified by #cubeb_devid not available. */ 247 }; 248 249 /** 250 * Whether a particular device is an input device (e.g. a microphone), or an 251 * output device (e.g. headphones). */ 252 typedef enum { 253 CUBEB_DEVICE_TYPE_UNKNOWN, 254 CUBEB_DEVICE_TYPE_INPUT, 255 CUBEB_DEVICE_TYPE_OUTPUT 256 } cubeb_device_type; 257 258 /** 259 * The state of a device. 260 */ 261 typedef enum { 262 CUBEB_DEVICE_STATE_DISABLED, /**< The device has been disabled at the system level. */ 263 CUBEB_DEVICE_STATE_UNPLUGGED, /**< The device is enabled, but nothing is plugged into it. */ 264 CUBEB_DEVICE_STATE_ENABLED /**< The device is enabled. */ 265 } cubeb_device_state; 266 267 /** 268 * Architecture specific sample type. 269 */ 270 typedef enum { 271 CUBEB_DEVICE_FMT_S16LE = 0x0010, /**< 16-bit integers, Little Endian. */ 272 CUBEB_DEVICE_FMT_S16BE = 0x0020, /**< 16-bit integers, Big Endian. */ 273 CUBEB_DEVICE_FMT_F32LE = 0x1000, /**< 32-bit floating point, Little Endian. */ 274 CUBEB_DEVICE_FMT_F32BE = 0x2000 /**< 32-bit floating point, Big Endian. */ 275 } cubeb_device_fmt; 276 277 #if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) 278 /** 16-bit integers, native endianess, when on a Big Endian environment. */ 279 #define CUBEB_DEVICE_FMT_S16NE CUBEB_DEVICE_FMT_S16BE 280 /** 32-bit floating points, native endianess, when on a Big Endian environment. */ 281 #define CUBEB_DEVICE_FMT_F32NE CUBEB_DEVICE_FMT_F32BE 282 #else 283 /** 16-bit integers, native endianess, when on a Little Endian environment. */ 284 #define CUBEB_DEVICE_FMT_S16NE CUBEB_DEVICE_FMT_S16LE 285 /** 32-bit floating points, native endianess, when on a Little Endian 286 * environment. */ 287 #define CUBEB_DEVICE_FMT_F32NE CUBEB_DEVICE_FMT_F32LE 288 #endif 289 /** All the 16-bit integers types. */ 290 #define CUBEB_DEVICE_FMT_S16_MASK (CUBEB_DEVICE_FMT_S16LE | CUBEB_DEVICE_FMT_S16BE) 291 /** All the 32-bit floating points types. */ 292 #define CUBEB_DEVICE_FMT_F32_MASK (CUBEB_DEVICE_FMT_F32LE | CUBEB_DEVICE_FMT_F32BE) 293 /** All the device formats types. */ 294 #define CUBEB_DEVICE_FMT_ALL (CUBEB_DEVICE_FMT_S16_MASK | CUBEB_DEVICE_FMT_F32_MASK) 295 296 /** Channel type for a `cubeb_stream`. Depending on the backend and platform 297 * used, this can control inter-stream interruption, ducking, and volume 298 * control. 299 */ 300 typedef enum { 301 CUBEB_DEVICE_PREF_NONE = 0x00, 302 CUBEB_DEVICE_PREF_MULTIMEDIA = 0x01, 303 CUBEB_DEVICE_PREF_VOICE = 0x02, 304 CUBEB_DEVICE_PREF_NOTIFICATION = 0x04, 305 CUBEB_DEVICE_PREF_ALL = 0x0F 306 } cubeb_device_pref; 307 308 /** This structure holds the characteristics 309 * of an input or output audio device. It is obtained using 310 * `cubeb_enumerate_devices`, which returns these structures via 311 * `cubeb_device_collection` and must be destroyed via 312 * `cubeb_device_collection_destroy`. */ 313 typedef struct { 314 cubeb_devid devid; /**< Device identifier handle. */ 315 char const * device_id; /**< Device identifier which might be presented in a UI. */ 316 char const * friendly_name; /**< Friendly device name which might be presented in a UI. */ 317 char const * group_id; /**< Two devices have the same group identifier if they belong to the same physical device; for example a headset and microphone. */ 318 char const * vendor_name; /**< Optional vendor name, may be NULL. */ 319 320 cubeb_device_type type; /**< Type of device (Input/Output). */ 321 cubeb_device_state state; /**< State of device disabled/enabled/unplugged. */ 322 cubeb_device_pref preferred;/**< Preferred device. */ 323 324 cubeb_device_fmt format; /**< Sample format supported. */ 325 cubeb_device_fmt default_format; /**< The default sample format for this device. */ 326 uint32_t max_channels; /**< Channels. */ 327 uint32_t default_rate; /**< Default/Preferred sample rate. */ 328 uint32_t max_rate; /**< Maximum sample rate supported. */ 329 uint32_t min_rate; /**< Minimum sample rate supported. */ 330 331 uint32_t latency_lo; /**< Lowest possible latency in frames. */ 332 uint32_t latency_hi; /**< Higest possible latency in frames. */ 333 } cubeb_device_info; 334 335 /** Device collection. 336 * Returned by `cubeb_enumerate_devices` and destroyed by 337 * `cubeb_device_collection_destroy`. */ 338 typedef struct { 339 cubeb_device_info * device; /**< Array of pointers to device info. */ 340 size_t count; /**< Device count in collection. */ 341 } cubeb_device_collection; 342 343 /** User supplied data callback. 344 - Calling other cubeb functions from this callback is unsafe. 345 - The code in the callback should be non-blocking. 346 - Returning less than the number of frames this callback asks for or 347 provides puts the stream in drain mode. This callback will not be called 348 again, and the state callback will be called with CUBEB_STATE_DRAINED when 349 all the frames have been output. 350 @param stream The stream for which this callback fired. 351 @param user_ptr The pointer passed to cubeb_stream_init. 352 @param input_buffer A pointer containing the input data, or nullptr 353 if this is an output-only stream. 354 @param output_buffer A pointer to a buffer to be filled with audio samples, 355 or nullptr if this is an input-only stream. 356 @param nframes The number of frames of the two buffer. 357 @retval Number of frames written to the output buffer. If this number is 358 less than nframes, then the stream will start to drain. 359 @retval CUBEB_ERROR on error, in which case the data callback will stop 360 and the stream will enter a shutdown state. */ 361 typedef long (* cubeb_data_callback)(cubeb_stream * stream, 362 void * user_ptr, 363 void const * input_buffer, 364 void * output_buffer, 365 long nframes); 366 367 /** User supplied state callback. 368 @param stream The stream for this this callback fired. 369 @param user_ptr The pointer passed to cubeb_stream_init. 370 @param state The new state of the stream. */ 371 typedef void (* cubeb_state_callback)(cubeb_stream * stream, 372 void * user_ptr, 373 cubeb_state state); 374 375 /** 376 * User supplied callback called when the underlying device changed. 377 * @param user The pointer passed to cubeb_stream_init. */ 378 typedef void (* cubeb_device_changed_callback)(void * user_ptr); 379 380 /** 381 * User supplied callback called when the underlying device collection changed. 382 * @param context A pointer to the cubeb context. 383 * @param user_ptr The pointer passed to cubeb_register_device_collection_changed. */ 384 typedef void (* cubeb_device_collection_changed_callback)(cubeb * context, 385 void * user_ptr); 386 387 /** User supplied callback called when a message needs logging. */ 388 typedef void (* cubeb_log_callback)(char const * fmt, ...); 389 390 /** Initialize an application context. This will perform any library or 391 application scoped initialization. 392 @param context A out param where an opaque pointer to the application 393 context will be returned. 394 @param context_name A name for the context. Depending on the platform this 395 can appear in different locations. 396 @param backend_name The name of the cubeb backend user desires to select. 397 Accepted values self-documented in cubeb.c: init_oneshot 398 If NULL, a default ordering is used for backend choice. 399 A valid choice overrides all other possible backends, 400 so long as the backend was included at compile time. 401 @retval CUBEB_OK in case of success. 402 @retval CUBEB_ERROR in case of error, for example because the host 403 has no audio hardware. */ 404 CUBEB_EXPORT int cubeb_init(cubeb ** context, char const * context_name, 405 char const * backend_name); 406 407 /** Get a read-only string identifying this context's current backend. 408 @param context A pointer to the cubeb context. 409 @retval Read-only string identifying current backend. */ 410 CUBEB_EXPORT char const * cubeb_get_backend_id(cubeb * context); 411 412 /** Get the maximum possible number of channels. 413 @param context A pointer to the cubeb context. 414 @param max_channels The maximum number of channels. 415 @retval CUBEB_OK 416 @retval CUBEB_ERROR_INVALID_PARAMETER 417 @retval CUBEB_ERROR_NOT_SUPPORTED 418 @retval CUBEB_ERROR */ 419 CUBEB_EXPORT int cubeb_get_max_channel_count(cubeb * context, uint32_t * max_channels); 420 421 /** Get the minimal latency value, in frames, that is guaranteed to work 422 when creating a stream for the specified sample rate. This is platform, 423 hardware and backend dependent. 424 @param context A pointer to the cubeb context. 425 @param params On some backends, the minimum achievable latency depends on 426 the characteristics of the stream. 427 @param latency_frames The latency value, in frames, to pass to 428 cubeb_stream_init. 429 @retval CUBEB_OK 430 @retval CUBEB_ERROR_INVALID_PARAMETER 431 @retval CUBEB_ERROR_NOT_SUPPORTED */ 432 CUBEB_EXPORT int cubeb_get_min_latency(cubeb * context, 433 cubeb_stream_params * params, 434 uint32_t * latency_frames); 435 436 /** Get the preferred sample rate for this backend: this is hardware and 437 platform dependent, and can avoid resampling, and/or trigger fastpaths. 438 @param context A pointer to the cubeb context. 439 @param rate The samplerate (in Hz) the current configuration prefers. 440 @retval CUBEB_OK 441 @retval CUBEB_ERROR_INVALID_PARAMETER 442 @retval CUBEB_ERROR_NOT_SUPPORTED */ 443 CUBEB_EXPORT int cubeb_get_preferred_sample_rate(cubeb * context, uint32_t * rate); 444 445 /** Get the preferred layout for this backend: this is hardware and 446 platform dependent. 447 @param context A pointer to the cubeb context. 448 @param layout The layout of the current speaker configuration. 449 @retval CUBEB_OK 450 @retval CUBEB_ERROR_INVALID_PARAMETER 451 @retval CUBEB_ERROR_NOT_SUPPORTED */ 452 CUBEB_EXPORT int cubeb_get_preferred_channel_layout(cubeb * context, cubeb_channel_layout * layout); 453 454 /** Destroy an application context. This must be called after all stream have 455 * been destroyed. 456 @param context A pointer to the cubeb context.*/ 457 CUBEB_EXPORT void cubeb_destroy(cubeb * context); 458 459 /** Initialize a stream associated with the supplied application context. 460 @param context A pointer to the cubeb context. 461 @param stream An out parameter to be filled with the an opaque pointer to a 462 cubeb stream. 463 @param stream_name A name for this stream. 464 @param input_device Device for the input side of the stream. If NULL the 465 default input device is used. 466 @param input_stream_params Parameters for the input side of the stream, or 467 NULL if this stream is output only. 468 @param output_device Device for the output side of the stream. If NULL the 469 default output device is used. 470 @param output_stream_params Parameters for the output side of the stream, or 471 NULL if this stream is input only. 472 @param latency_frames Stream latency in frames. Valid range 473 is [1, 96000]. 474 @param data_callback Will be called to preroll data before playback is 475 started by cubeb_stream_start. 476 @param state_callback A pointer to a state callback. 477 @param user_ptr A pointer that will be passed to the callbacks. This pointer 478 must outlive the life time of the stream. 479 @retval CUBEB_OK 480 @retval CUBEB_ERROR 481 @retval CUBEB_ERROR_INVALID_FORMAT 482 @retval CUBEB_ERROR_DEVICE_UNAVAILABLE */ 483 CUBEB_EXPORT int cubeb_stream_init(cubeb * context, 484 cubeb_stream ** stream, 485 char const * stream_name, 486 cubeb_devid input_device, 487 cubeb_stream_params * input_stream_params, 488 cubeb_devid output_device, 489 cubeb_stream_params * output_stream_params, 490 uint32_t latency_frames, 491 cubeb_data_callback data_callback, 492 cubeb_state_callback state_callback, 493 void * user_ptr); 494 495 /** Destroy a stream. `cubeb_stream_stop` MUST be called before destroying a 496 stream. 497 @param stream The stream to destroy. */ 498 CUBEB_EXPORT void cubeb_stream_destroy(cubeb_stream * stream); 499 500 /** Start playback. 501 @param stream 502 @retval CUBEB_OK 503 @retval CUBEB_ERROR */ 504 CUBEB_EXPORT int cubeb_stream_start(cubeb_stream * stream); 505 506 /** Stop playback. 507 @param stream 508 @retval CUBEB_OK 509 @retval CUBEB_ERROR */ 510 CUBEB_EXPORT int cubeb_stream_stop(cubeb_stream * stream); 511 512 /** Reset stream to the default device. 513 @param stream 514 @retval CUBEB_OK 515 @retval CUBEB_ERROR_INVALID_PARAMETER 516 @retval CUBEB_ERROR_NOT_SUPPORTED 517 @retval CUBEB_ERROR */ 518 CUBEB_EXPORT int cubeb_stream_reset_default_device(cubeb_stream * stream); 519 520 /** Get the current stream playback position. 521 @param stream 522 @param position Playback position in frames. 523 @retval CUBEB_OK 524 @retval CUBEB_ERROR */ 525 CUBEB_EXPORT int cubeb_stream_get_position(cubeb_stream * stream, uint64_t * position); 526 527 /** Get the latency for this stream, in frames. This is the number of frames 528 between the time cubeb acquires the data in the callback and the listener 529 can hear the sound. 530 @param stream 531 @param latency Current approximate stream latency in frames. 532 @retval CUBEB_OK 533 @retval CUBEB_ERROR_NOT_SUPPORTED 534 @retval CUBEB_ERROR */ 535 CUBEB_EXPORT int cubeb_stream_get_latency(cubeb_stream * stream, uint32_t * latency); 536 537 /** Set the volume for a stream. 538 @param stream the stream for which to adjust the volume. 539 @param volume a float between 0.0 (muted) and 1.0 (maximum volume) 540 @retval CUBEB_OK 541 @retval CUBEB_ERROR_INVALID_PARAMETER volume is outside [0.0, 1.0] or 542 stream is an invalid pointer 543 @retval CUBEB_ERROR_NOT_SUPPORTED */ 544 CUBEB_EXPORT int cubeb_stream_set_volume(cubeb_stream * stream, float volume); 545 546 /** If the stream is stereo, set the left/right panning. If the stream is mono, 547 this has no effect. 548 @param stream the stream for which to change the panning 549 @param panning a number from -1.0 to 1.0. -1.0 means that the stream is 550 fully mixed in the left channel, 1.0 means the stream is fully 551 mixed in the right channel. 0.0 is equal power in the right and 552 left channel (default). 553 @retval CUBEB_OK 554 @retval CUBEB_ERROR_INVALID_PARAMETER if stream is null or if panning is 555 outside the [-1.0, 1.0] range. 556 @retval CUBEB_ERROR_NOT_SUPPORTED 557 @retval CUBEB_ERROR stream is not mono nor stereo */ 558 CUBEB_EXPORT int cubeb_stream_set_panning(cubeb_stream * stream, float panning); 559 560 /** Get the current output device for this stream. 561 @param stm the stream for which to query the current output device 562 @param device a pointer in which the current output device will be stored. 563 @retval CUBEB_OK in case of success 564 @retval CUBEB_ERROR_INVALID_PARAMETER if either stm, device or count are 565 invalid pointers 566 @retval CUBEB_ERROR_NOT_SUPPORTED */ 567 CUBEB_EXPORT int cubeb_stream_get_current_device(cubeb_stream * stm, 568 cubeb_device ** const device); 569 570 /** Destroy a cubeb_device structure. 571 @param stream the stream passed in cubeb_stream_get_current_device 572 @param devices the devices to destroy 573 @retval CUBEB_OK in case of success 574 @retval CUBEB_ERROR_INVALID_PARAMETER if devices is an invalid pointer 575 @retval CUBEB_ERROR_NOT_SUPPORTED */ 576 CUBEB_EXPORT int cubeb_stream_device_destroy(cubeb_stream * stream, 577 cubeb_device * devices); 578 579 /** Set a callback to be notified when the output device changes. 580 @param stream the stream for which to set the callback. 581 @param device_changed_callback a function called whenever the device has 582 changed. Passing NULL allow to unregister a function 583 @retval CUBEB_OK 584 @retval CUBEB_ERROR_INVALID_PARAMETER if either stream or 585 device_changed_callback are invalid pointers. 586 @retval CUBEB_ERROR_NOT_SUPPORTED */ 587 CUBEB_EXPORT int cubeb_stream_register_device_changed_callback(cubeb_stream * stream, 588 cubeb_device_changed_callback device_changed_callback); 589 590 /** Returns enumerated devices. 591 @param context 592 @param devtype device type to include 593 @param collection output collection. Must be destroyed with cubeb_device_collection_destroy 594 @retval CUBEB_OK in case of success 595 @retval CUBEB_ERROR_INVALID_PARAMETER if collection is an invalid pointer 596 @retval CUBEB_ERROR_NOT_SUPPORTED */ 597 CUBEB_EXPORT int cubeb_enumerate_devices(cubeb * context, 598 cubeb_device_type devtype, 599 cubeb_device_collection * collection); 600 601 /** Destroy a cubeb_device_collection, and its `cubeb_device_info`. 602 @param context 603 @param collection collection to destroy 604 @retval CUBEB_OK 605 @retval CUBEB_ERROR_INVALID_PARAMETER if collection is an invalid pointer */ 606 CUBEB_EXPORT int cubeb_device_collection_destroy(cubeb * context, 607 cubeb_device_collection * collection); 608 609 /** Registers a callback which is called when the system detects 610 a new device or a device is removed. 611 @param context 612 @param devtype device type to include 613 @param callback a function called whenever the system device list changes. 614 Passing NULL allow to unregister a function 615 @param user_ptr pointer to user specified data which will be present in 616 subsequent callbacks. 617 @retval CUBEB_ERROR_NOT_SUPPORTED */ 618 CUBEB_EXPORT int cubeb_register_device_collection_changed(cubeb * context, 619 cubeb_device_type devtype, 620 cubeb_device_collection_changed_callback callback, 621 void * user_ptr); 622 623 /** Set a callback to be called with a message. 624 @param log_level CUBEB_LOG_VERBOSE, CUBEB_LOG_NORMAL. 625 @param log_callback A function called with a message when there is 626 something to log. Pass NULL to unregister. 627 @retval CUBEB_OK in case of success. 628 @retval CUBEB_ERROR_INVALID_PARAMETER if either context or log_callback are 629 invalid pointers, or if level is not 630 in cubeb_log_level. */ 631 CUBEB_EXPORT int cubeb_set_log_callback(cubeb_log_level log_level, 632 cubeb_log_callback log_callback); 633 634 #if defined(__cplusplus) 635 } 636 #endif 637 638 #endif /* CUBEB_c2f983e9_c96f_e71c_72c3_bbf62992a382 */ 639