Skip to content

Commit

Permalink
WIP: Add cubeb_stream_get_max_request_size API.
Browse files Browse the repository at this point in the history
This is intended to support mozilla/audioipc#124
  • Loading branch information
kinetiknz committed Nov 8, 2021
1 parent 07c352c commit af91656
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/cubeb/cubeb.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ cubeb_stream_get_latency(cubeb_stream * stream, uint32_t * latency);
@retval CUBEB_ERROR */
CUBEB_EXPORT int
cubeb_stream_get_input_latency(cubeb_stream * stream, uint32_t * latency);

/** Set the volume for a stream.
@param stream the stream for which to adjust the volume.
@param volume a float between 0.0 (muted) and 1.0 (maximum volume)
Expand Down Expand Up @@ -637,6 +638,20 @@ CUBEB_EXPORT int
cubeb_stream_get_current_device(cubeb_stream * stm,
cubeb_device ** const device);

/** Get the maximum request size for this stream in frames. This is the largest
value that will be presented or requested via `data_callback`'s `nframes`
parameter. Note: This value may change if the stream is automatically
reconfigured due to device changes. Callers of this API should use
cubeb_stream_register_device_changed_callback to monitor device changes and
requery this API after a device change.
@param stream the stream for which to retrieve max request size.
@param max_request_size the max request size in frames.
@retval CUBEB_OK
@retval CUBEB_ERROR_NOT_SUPPORTED */
CUBEB_EXPORT int
cubeb_stream_get_max_request_size(cubeb_stream * stream,
uint32_t * max_request_size);

/** Destroy a cubeb_device structure.
@param stream the stream passed in cubeb_stream_get_current_device
@param devices the devices to destroy
Expand Down
2 changes: 2 additions & 0 deletions src/cubeb-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct cubeb_ops {
int (*stream_register_device_changed_callback)(
cubeb_stream * stream,
cubeb_device_changed_callback device_changed_callback);
int (*stream_get_max_request_size)(cubeb_stream * stream,
uint32_t * max_request_size);
int (*register_device_collection_changed)(
cubeb * context, cubeb_device_type devtype,
cubeb_device_collection_changed_callback callback, void * user_ptr);
Expand Down
16 changes: 16 additions & 0 deletions src/cubeb.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,22 @@ cubeb_stream_get_current_device(cubeb_stream * stream,
return stream->context->ops->stream_get_current_device(stream, device);
}

int
cubeb_stream_get_max_request_size(cubeb_stream * stream,
uint32_t * max_request_size)
{
if (!stream || !max_request_size) {
return CUBEB_ERROR_INVALID_PARAMETER;
}

if (!stream->context->ops->stream_get_max_request_size) {
return CUBEB_ERROR_NOT_SUPPORTED;
}

return stream->context->ops->stream_get_max_request_size(stream,
max_request_size);
}

int
cubeb_stream_device_destroy(cubeb_stream * stream, cubeb_device * device)
{
Expand Down
1 change: 1 addition & 0 deletions src/cubeb_aaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,7 @@ const static struct cubeb_ops aaudio_ops = {
/*.stream_get_current_device =*/NULL,
/*.stream_device_destroy =*/NULL,
/*.stream_register_device_changed_callback =*/NULL,
/*.stream_get_max_request_size =*/NULL,
/*.register_device_collection_changed =*/NULL};

extern "C" /*static*/ int
Expand Down
1 change: 1 addition & 0 deletions src/cubeb_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1487,4 +1487,5 @@ static struct cubeb_ops const alsa_ops = {
.stream_get_current_device = NULL,
.stream_device_destroy = NULL,
.stream_register_device_changed_callback = NULL,
.stream_get_max_request_size = NULL,
.register_device_collection_changed = NULL};
1 change: 1 addition & 0 deletions src/cubeb_audiounit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3666,5 +3666,6 @@ cubeb_ops const audiounit_ops = {
/*.stream_device_destroy =*/audiounit_stream_device_destroy,
/*.stream_register_device_changed_callback =*/
audiounit_stream_register_device_changed_callback,
/*.stream_get_max_request_size = */ NULL,
/*.register_device_collection_changed =*/
audiounit_register_device_collection_changed};
1 change: 1 addition & 0 deletions src/cubeb_jack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ static struct cubeb_ops const cbjack_ops = {
.stream_get_current_device = cbjack_stream_get_current_device,
.stream_device_destroy = cbjack_stream_device_destroy,
.stream_register_device_changed_callback = NULL,
.stream_get_max_request_size = NULL,
.register_device_collection_changed = NULL};

struct cubeb_stream {
Expand Down
1 change: 1 addition & 0 deletions src/cubeb_kai.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,5 @@ static struct cubeb_ops const kai_ops = {
/*.stream_get_current_device =*/NULL,
/*.stream_device_destroy =*/NULL,
/*.stream_register_device_changed_callback=*/NULL,
/*.stream_get_max_request_size =*/NULL,
/*.register_device_collection_changed=*/NULL};
1 change: 1 addition & 0 deletions src/cubeb_opensl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1792,4 +1792,5 @@ static struct cubeb_ops const opensl_ops = {
.stream_get_current_device = NULL,
.stream_device_destroy = NULL,
.stream_register_device_changed_callback = NULL,
.stream_get_max_request_size = NULL,
.register_device_collection_changed = NULL};
1 change: 1 addition & 0 deletions src/cubeb_oss.c
Original file line number Diff line number Diff line change
Expand Up @@ -1326,4 +1326,5 @@ static struct cubeb_ops const oss_ops = {
.stream_get_current_device = oss_get_current_device,
.stream_device_destroy = oss_stream_device_destroy,
.stream_register_device_changed_callback = NULL,
.stream_get_max_request_size = NULL,
.register_device_collection_changed = NULL};
1 change: 1 addition & 0 deletions src/cubeb_pulse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1696,5 +1696,6 @@ static struct cubeb_ops const pulse_ops = {
.stream_get_current_device = pulse_stream_get_current_device,
.stream_device_destroy = pulse_stream_device_destroy,
.stream_register_device_changed_callback = NULL,
.stream_get_max_request_size = NULL,
.register_device_collection_changed =
pulse_register_device_collection_changed};
1 change: 1 addition & 0 deletions src/cubeb_sndio.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,4 +666,5 @@ static struct cubeb_ops const sndio_ops = {
.stream_get_current_device = NULL,
.stream_device_destroy = NULL,
.stream_register_device_changed_callback = NULL,
.stream_get_max_request_size = NULL,
.register_device_collection_changed = NULL};
1 change: 1 addition & 0 deletions src/cubeb_sun.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,4 +730,5 @@ static struct cubeb_ops const sun_ops = {
.stream_get_current_device = sun_get_current_device,
.stream_device_destroy = sun_stream_device_destroy,
.stream_register_device_changed_callback = NULL,
.stream_get_max_request_size = NULL,
.register_device_collection_changed = NULL};
18 changes: 18 additions & 0 deletions src/cubeb_wasapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,23 @@ wasapi_stream_set_volume(cubeb_stream * stm, float volume)
return CUBEB_OK;
}

// TODO: Need to implement stream_register_device_changed_callback.
int
wasapi_stream_get_max_request_size(cubeb_stream * stm,
uint32_t * max_request_size)
{
auto_lock lock(stm->stream_reset_lock);

if (!stm->output_client && !stm->input_client) {
return CUBEB_ERROR;
}

*max_request_size =
std::max(stm->output_buffer_frame_count, stm->input_buffer_frame_count);

return CUBEB_OK;
}

static char const *
wstr_to_utf8(LPCWSTR str)
{
Expand Down Expand Up @@ -3382,6 +3399,7 @@ cubeb_ops const wasapi_ops = {
/*.stream_get_current_device =*/NULL,
/*.stream_device_destroy =*/NULL,
/*.stream_register_device_changed_callback =*/NULL,
/*.stream_get_max_request_size =*/wasapi_stream_get_max_request_size,
/*.register_device_collection_changed =*/
wasapi_register_device_collection_changed,
};
Expand Down
1 change: 1 addition & 0 deletions src/cubeb_winmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1179,4 +1179,5 @@ static struct cubeb_ops const winmm_ops = {
/*.stream_get_current_device =*/NULL,
/*.stream_device_destroy =*/NULL,
/*.stream_register_device_changed_callback=*/NULL,
/*.stream_get_max_request_size = */ NULL,
/*.register_device_collection_changed =*/NULL};

0 comments on commit af91656

Please sign in to comment.