diff --git a/include/cubeb/cubeb.h b/include/cubeb/cubeb.h index 29d5a3b1e..28fb2d821 100644 --- a/include/cubeb/cubeb.h +++ b/include/cubeb/cubeb.h @@ -285,12 +285,6 @@ typedef struct { WASAPI backend; others should use cubeb_set_input_processing_params. */ } cubeb_stream_params; -/** Audio device description */ -typedef struct { - char * output_name; /**< The name of the output device */ - char * input_name; /**< The name of the input device */ -} cubeb_device; - /** Stream states signaled via state_callback. */ typedef enum { CUBEB_STATE_STARTED, /**< Stream started. */ @@ -670,17 +664,6 @@ cubeb_stream_set_volume(cubeb_stream * stream, float volume); CUBEB_EXPORT int cubeb_stream_set_name(cubeb_stream * stream, char const * stream_name); -/** Get the current output device for this stream. - @param stm the stream for which to query the current output device - @param device a pointer in which the current output device will be stored. - @retval CUBEB_OK in case of success - @retval CUBEB_ERROR_INVALID_PARAMETER if either stm, device or count are - invalid pointers - @retval CUBEB_ERROR_NOT_SUPPORTED */ -CUBEB_EXPORT int -cubeb_stream_get_current_device(cubeb_stream * stm, - cubeb_device ** const device); - /** Set input mute state for this stream. Some platforms notify the user when an application is accessing audio input. When all inputs are muted they can prove to the user that the application is not actively capturing any input. @@ -705,15 +688,6 @@ CUBEB_EXPORT int cubeb_stream_set_input_processing_params(cubeb_stream * stream, cubeb_input_processing_params params); -/** Destroy a cubeb_device structure. - @param stream the stream passed in cubeb_stream_get_current_device - @param devices the devices to destroy - @retval CUBEB_OK in case of success - @retval CUBEB_ERROR_INVALID_PARAMETER if devices is an invalid pointer - @retval CUBEB_ERROR_NOT_SUPPORTED */ -CUBEB_EXPORT int -cubeb_stream_device_destroy(cubeb_stream * stream, cubeb_device * devices); - /** Set a callback to be notified when the output device changes. @param stream the stream for which to set the callback. @param device_changed_callback a function called whenever the device has diff --git a/src/cubeb-internal.h b/src/cubeb-internal.h index 8357cdc7e..61628c383 100644 --- a/src/cubeb-internal.h +++ b/src/cubeb-internal.h @@ -62,12 +62,9 @@ struct cubeb_ops { int (*stream_get_input_latency)(cubeb_stream * stream, uint32_t * latency); int (*stream_set_volume)(cubeb_stream * stream, float volumes); int (*stream_set_name)(cubeb_stream * stream, char const * stream_name); - int (*stream_get_current_device)(cubeb_stream * stream, - cubeb_device ** const device); int (*stream_set_input_mute)(cubeb_stream * stream, int mute); int (*stream_set_input_processing_params)( cubeb_stream * stream, cubeb_input_processing_params params); - int (*stream_device_destroy)(cubeb_stream * stream, cubeb_device * device); int (*stream_register_device_changed_callback)( cubeb_stream * stream, cubeb_device_changed_callback device_changed_callback); diff --git a/src/cubeb.c b/src/cubeb.c index 0511ad98d..061755746 100644 --- a/src/cubeb.c +++ b/src/cubeb.c @@ -557,21 +557,6 @@ cubeb_stream_set_name(cubeb_stream * stream, char const * stream_name) return stream->context->ops->stream_set_name(stream, stream_name); } -int -cubeb_stream_get_current_device(cubeb_stream * stream, - cubeb_device ** const device) -{ - if (!stream || !device) { - return CUBEB_ERROR_INVALID_PARAMETER; - } - - if (!stream->context->ops->stream_get_current_device) { - return CUBEB_ERROR_NOT_SUPPORTED; - } - - return stream->context->ops->stream_get_current_device(stream, device); -} - int cubeb_stream_set_input_mute(cubeb_stream * stream, int mute) { @@ -602,20 +587,6 @@ cubeb_stream_set_input_processing_params(cubeb_stream * stream, params); } -int -cubeb_stream_device_destroy(cubeb_stream * stream, cubeb_device * device) -{ - if (!stream || !device) { - return CUBEB_ERROR_INVALID_PARAMETER; - } - - if (!stream->context->ops->stream_device_destroy) { - return CUBEB_ERROR_NOT_SUPPORTED; - } - - return stream->context->ops->stream_device_destroy(stream, device); -} - int cubeb_stream_register_device_changed_callback( cubeb_stream * stream, diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp index ed1ad2005..d91d71cfa 100644 --- a/src/cubeb_aaudio.cpp +++ b/src/cubeb_aaudio.cpp @@ -1954,10 +1954,8 @@ const static struct cubeb_ops aaudio_ops = { /*.stream_get_input_latency =*/aaudio_stream_get_input_latency, /*.stream_set_volume =*/aaudio_stream_set_volume, /*.stream_set_name =*/nullptr, - /*.stream_get_current_device =*/nullptr, /*.stream_set_input_mute =*/nullptr, /*.stream_set_input_processing_params =*/nullptr, - /*.stream_device_destroy =*/nullptr, /*.stream_register_device_changed_callback =*/nullptr, /*.register_device_collection_changed =*/nullptr}; diff --git a/src/cubeb_alsa.c b/src/cubeb_alsa.c index f114f27d7..5126fd35b 100644 --- a/src/cubeb_alsa.c +++ b/src/cubeb_alsa.c @@ -1485,9 +1485,7 @@ static struct cubeb_ops const alsa_ops = { .stream_get_input_latency = NULL, .stream_set_volume = alsa_stream_set_volume, .stream_set_name = NULL, - .stream_get_current_device = NULL, .stream_set_input_mute = NULL, .stream_set_input_processing_params = NULL, - .stream_device_destroy = NULL, .stream_register_device_changed_callback = NULL, .register_device_collection_changed = NULL}; diff --git a/src/cubeb_audiotrack.c b/src/cubeb_audiotrack.c index 84ccfb80a..0437075e0 100644 --- a/src/cubeb_audiotrack.c +++ b/src/cubeb_audiotrack.c @@ -467,9 +467,7 @@ static struct cubeb_ops const audiotrack_ops = { .stream_get_input_latency = NULL, .stream_set_volume = audiotrack_stream_set_volume, .stream_set_name = NULL, - .stream_get_current_device = NULL, .stream_set_input_mute = NULL, .stream_set_input_processing_params = NULL, - .stream_device_destroy = NULL, .stream_register_device_changed_callback = NULL, .register_device_collection_changed = NULL}; diff --git a/src/cubeb_audiounit.cpp b/src/cubeb_audiounit.cpp index d823e80ff..abdee7c9f 100644 --- a/src/cubeb_audiounit.cpp +++ b/src/cubeb_audiounit.cpp @@ -3067,109 +3067,6 @@ audiounit_stream_set_volume(cubeb_stream * stm, float volume) return CUBEB_OK; } -unique_ptr -convert_uint32_into_string(UInt32 data) -{ - // Simply create an empty string if no data. - size_t size = data == 0 ? 0 : 4; // 4 bytes for uint32. - auto str = unique_ptr{new char[size + 1]}; // + 1 for '\0'. - str[size] = '\0'; - if (size < 4) { - return str; - } - - // Reverse 0xWXYZ into 0xZYXW. - str[0] = (char)(data >> 24); - str[1] = (char)(data >> 16); - str[2] = (char)(data >> 8); - str[3] = (char)(data); - return str; -} - -int -audiounit_get_default_device_datasource(cubeb_device_type type, UInt32 * data) -{ - AudioDeviceID id = audiounit_get_default_device_id(type); - if (id == kAudioObjectUnknown) { - return CUBEB_ERROR; - } - - UInt32 size = sizeof(*data); - /* This fails with some USB headsets (e.g., Plantronic .Audio 628). */ - OSStatus r = AudioObjectGetPropertyData( - id, - type == CUBEB_DEVICE_TYPE_INPUT ? &INPUT_DATA_SOURCE_PROPERTY_ADDRESS - : &OUTPUT_DATA_SOURCE_PROPERTY_ADDRESS, - 0, NULL, &size, data); - if (r != noErr) { - *data = 0; - } - - return CUBEB_OK; -} - -int -audiounit_get_default_device_name(cubeb_stream * stm, - cubeb_device * const device, - cubeb_device_type type) -{ - assert(stm); - assert(device); - - UInt32 data; - int r = audiounit_get_default_device_datasource(type, &data); - if (r != CUBEB_OK) { - return r; - } - char ** name = type == CUBEB_DEVICE_TYPE_INPUT ? &device->input_name - : &device->output_name; - *name = convert_uint32_into_string(data).release(); - if (!strlen(*name)) { // empty string. - LOG("(%p) name of %s device is empty!", stm, - type == CUBEB_DEVICE_TYPE_INPUT ? "input" : "output"); - } - return CUBEB_OK; -} - -int -audiounit_stream_get_current_device(cubeb_stream * stm, - cubeb_device ** const device) -{ -#if TARGET_OS_IPHONE - // TODO - return CUBEB_ERROR_NOT_SUPPORTED; -#else - *device = new cubeb_device; - if (!*device) { - return CUBEB_ERROR; - } - PodZero(*device, 1); - - int r = - audiounit_get_default_device_name(stm, *device, CUBEB_DEVICE_TYPE_OUTPUT); - if (r != CUBEB_OK) { - return r; - } - - r = audiounit_get_default_device_name(stm, *device, CUBEB_DEVICE_TYPE_INPUT); - if (r != CUBEB_OK) { - return r; - } - - return CUBEB_OK; -#endif -} - -int -audiounit_stream_device_destroy(cubeb_stream * /* stream */, - cubeb_device * device) -{ - delete[] device->output_name; - delete[] device->input_name; - delete device; - return CUBEB_OK; -} - int audiounit_stream_register_device_changed_callback( cubeb_stream * stream, @@ -3698,10 +3595,8 @@ cubeb_ops const audiounit_ops = { /*.stream_get_input_latency =*/NULL, /*.stream_set_volume =*/audiounit_stream_set_volume, /*.stream_set_name =*/NULL, - /*.stream_get_current_device =*/audiounit_stream_get_current_device, /*.stream_set_input_mute =*/NULL, /*.stream_set_input_processing_params =*/NULL, - /*.stream_device_destroy =*/audiounit_stream_device_destroy, /*.stream_register_device_changed_callback =*/ audiounit_stream_register_device_changed_callback, /*.register_device_collection_changed =*/ diff --git a/src/cubeb_jack.cpp b/src/cubeb_jack.cpp index b417078fc..9c3de6010 100644 --- a/src/cubeb_jack.cpp +++ b/src/cubeb_jack.cpp @@ -124,11 +124,6 @@ cbjack_deinterleave_playback_refill_float(cubeb_stream * stream, float ** bufs_in, float ** bufs_out, jack_nframes_t nframes); static int -cbjack_stream_device_destroy(cubeb_stream * stream, cubeb_device * device); -static int -cbjack_stream_get_current_device(cubeb_stream * stm, - cubeb_device ** const device); -static int cbjack_enumerate_devices(cubeb * context, cubeb_device_type type, cubeb_device_collection * collection); static int @@ -173,10 +168,8 @@ static struct cubeb_ops const cbjack_ops = { .stream_get_input_latency = NULL, .stream_set_volume = cbjack_stream_set_volume, .stream_set_name = NULL, - .stream_get_current_device = cbjack_stream_get_current_device, .stream_set_input_mute = NULL, .stream_set_input_processing_params = NULL, - .stream_device_destroy = cbjack_stream_device_destroy, .stream_register_device_changed_callback = NULL, .register_device_collection_changed = NULL}; @@ -1073,43 +1066,6 @@ cbjack_stream_set_volume(cubeb_stream * stm, float volume) return CUBEB_OK; } -static int -cbjack_stream_get_current_device(cubeb_stream * stm, - cubeb_device ** const device) -{ - *device = (cubeb_device *)calloc(1, sizeof(cubeb_device)); - if (*device == NULL) - return CUBEB_ERROR; - - const char * j_in = JACK_DEFAULT_IN; - const char * j_out = JACK_DEFAULT_OUT; - const char * empty = ""; - - if (stm->devs == DUPLEX) { - (*device)->input_name = strdup(j_in); - (*device)->output_name = strdup(j_out); - } else if (stm->devs == IN_ONLY) { - (*device)->input_name = strdup(j_in); - (*device)->output_name = strdup(empty); - } else if (stm->devs == OUT_ONLY) { - (*device)->input_name = strdup(empty); - (*device)->output_name = strdup(j_out); - } - - return CUBEB_OK; -} - -static int -cbjack_stream_device_destroy(cubeb_stream * /*stream*/, cubeb_device * device) -{ - if (device->input_name) - free(device->input_name); - if (device->output_name) - free(device->output_name); - free(device); - return CUBEB_OK; -} - static int cbjack_enumerate_devices(cubeb * context, cubeb_device_type type, cubeb_device_collection * collection) diff --git a/src/cubeb_kai.c b/src/cubeb_kai.c index 4bc6c7afa..7b5477827 100644 --- a/src/cubeb_kai.c +++ b/src/cubeb_kai.c @@ -364,9 +364,7 @@ static struct cubeb_ops const kai_ops = { /*.stream_get_input_latency = */ NULL, /*.stream_set_volume =*/kai_stream_set_volume, /*.stream_set_name =*/NULL, - /*.stream_get_current_device =*/NULL, /*.stream_set_input_mute =*/NULL, /*.stream_set_input_processing_params =*/NULL, - /*.stream_device_destroy =*/NULL, /*.stream_register_device_changed_callback=*/NULL, /*.register_device_collection_changed=*/NULL}; diff --git a/src/cubeb_opensl.cpp b/src/cubeb_opensl.cpp index aad4d6f9f..c4deb7043 100644 --- a/src/cubeb_opensl.cpp +++ b/src/cubeb_opensl.cpp @@ -1950,9 +1950,7 @@ struct cubeb_ops const opensl_ops = { .stream_get_input_latency = nullptr, .stream_set_volume = opensl_stream_set_volume, .stream_set_name = nullptr, - .stream_get_current_device = nullptr, .stream_set_input_mute = nullptr, .stream_set_input_processing_params = nullptr, - .stream_device_destroy = nullptr, .stream_register_device_changed_callback = nullptr, .register_device_collection_changed = nullptr}; diff --git a/src/cubeb_oss.c b/src/cubeb_oss.c index 3d09ba4db..430ba5c16 100644 --- a/src/cubeb_oss.c +++ b/src/cubeb_oss.c @@ -1305,30 +1305,6 @@ oss_stream_set_volume(cubeb_stream * stream, float volume) return CUBEB_OK; } -static int -oss_get_current_device(cubeb_stream * stream, cubeb_device ** const device) -{ - *device = calloc(1, sizeof(cubeb_device)); - if (*device == NULL) { - return CUBEB_ERROR; - } - (*device)->input_name = - stream->record.fd != -1 ? strdup(stream->record.name) : NULL; - (*device)->output_name = - stream->play.fd != -1 ? strdup(stream->play.name) : NULL; - return CUBEB_OK; -} - -static int -oss_stream_device_destroy(cubeb_stream * stream, cubeb_device * device) -{ - (void)stream; - free(device->input_name); - free(device->output_name); - free(device); - return CUBEB_OK; -} - static struct cubeb_ops const oss_ops = { .init = oss_init, .get_backend_id = oss_get_backend_id, @@ -1348,9 +1324,7 @@ static struct cubeb_ops const oss_ops = { .stream_get_input_latency = NULL, .stream_set_volume = oss_stream_set_volume, .stream_set_name = NULL, - .stream_get_current_device = oss_get_current_device, .stream_set_input_mute = NULL, .stream_set_input_processing_params = NULL, - .stream_device_destroy = oss_stream_device_destroy, .stream_register_device_changed_callback = NULL, .register_device_collection_changed = NULL}; diff --git a/src/cubeb_pulse.c b/src/cubeb_pulse.c index c761487e4..b1cb62ab1 100644 --- a/src/cubeb_pulse.c +++ b/src/cubeb_pulse.c @@ -1525,41 +1525,6 @@ pulse_device_collection_destroy(cubeb * ctx, return CUBEB_OK; } -static int -pulse_stream_get_current_device(cubeb_stream * stm, - cubeb_device ** const device) -{ -#if PA_CHECK_VERSION(0, 9, 8) - *device = calloc(1, sizeof(cubeb_device)); - if (*device == NULL) - return CUBEB_ERROR; - - if (stm->input_stream) { - const char * name = WRAP(pa_stream_get_device_name)(stm->input_stream); - (*device)->input_name = (name == NULL) ? NULL : strdup(name); - } - - if (stm->output_stream) { - const char * name = WRAP(pa_stream_get_device_name)(stm->output_stream); - (*device)->output_name = (name == NULL) ? NULL : strdup(name); - } - - return CUBEB_OK; -#else - return CUBEB_ERROR_NOT_SUPPORTED; -#endif -} - -static int -pulse_stream_device_destroy(cubeb_stream * stream, cubeb_device * device) -{ - (void)stream; - free(device->input_name); - free(device->output_name); - free(device); - return CUBEB_OK; -} - static void pulse_subscribe_callback(pa_context * ctx, pa_subscription_event_type_t t, uint32_t index, void * userdata) @@ -1703,10 +1668,8 @@ static struct cubeb_ops const pulse_ops = { .stream_get_input_latency = NULL, .stream_set_volume = pulse_stream_set_volume, .stream_set_name = pulse_stream_set_name, - .stream_get_current_device = pulse_stream_get_current_device, .stream_set_input_mute = NULL, .stream_set_input_processing_params = NULL, - .stream_device_destroy = pulse_stream_device_destroy, .stream_register_device_changed_callback = NULL, .register_device_collection_changed = pulse_register_device_collection_changed}; diff --git a/src/cubeb_sndio.c b/src/cubeb_sndio.c index cd295bff5..f0d4fbe17 100644 --- a/src/cubeb_sndio.c +++ b/src/cubeb_sndio.c @@ -679,9 +679,7 @@ static struct cubeb_ops const sndio_ops = { .stream_get_latency = sndio_stream_get_latency, .stream_set_volume = sndio_stream_set_volume, .stream_set_name = NULL, - .stream_get_current_device = NULL, .stream_set_input_mute = NULL, .stream_set_input_processing_params = NULL, - .stream_device_destroy = NULL, .stream_register_device_changed_callback = NULL, .register_device_collection_changed = NULL}; diff --git a/src/cubeb_sun.c b/src/cubeb_sun.c index cae9eefe2..d60a1c99a 100644 --- a/src/cubeb_sun.c +++ b/src/cubeb_sun.c @@ -689,30 +689,6 @@ sun_stream_set_volume(cubeb_stream * stream, float volume) return CUBEB_OK; } -static int -sun_get_current_device(cubeb_stream * stream, cubeb_device ** const device) -{ - *device = calloc(1, sizeof(cubeb_device)); - if (*device == NULL) { - return CUBEB_ERROR; - } - (*device)->input_name = - stream->record.fd != -1 ? strdup(stream->record.name) : NULL; - (*device)->output_name = - stream->play.fd != -1 ? strdup(stream->play.name) : NULL; - return CUBEB_OK; -} - -static int -sun_stream_device_destroy(cubeb_stream * stream, cubeb_device * device) -{ - (void)stream; - free(device->input_name); - free(device->output_name); - free(device); - return CUBEB_OK; -} - static struct cubeb_ops const sun_ops = { .init = sun_init, .get_backend_id = sun_get_backend_id, @@ -732,9 +708,7 @@ static struct cubeb_ops const sun_ops = { .stream_get_input_latency = NULL, .stream_set_volume = sun_stream_set_volume, .stream_set_name = NULL, - .stream_get_current_device = sun_get_current_device, .stream_set_input_mute = NULL, .stream_set_input_processing_params = NULL, - .stream_device_destroy = sun_stream_device_destroy, .stream_register_device_changed_callback = NULL, .register_device_collection_changed = NULL}; diff --git a/src/cubeb_wasapi.cpp b/src/cubeb_wasapi.cpp index 78b5b5082..01c569a34 100644 --- a/src/cubeb_wasapi.cpp +++ b/src/cubeb_wasapi.cpp @@ -3625,10 +3625,8 @@ cubeb_ops const wasapi_ops = { /*.stream_get_input_latency =*/wasapi_stream_get_input_latency, /*.stream_set_volume =*/wasapi_stream_set_volume, /*.stream_set_name =*/NULL, - /*.stream_get_current_device =*/NULL, /*.stream_set_input_mute =*/NULL, /*.stream_set_input_processing_params =*/wasapi_set_input_processing_params, - /*.stream_device_destroy =*/NULL, /*.stream_register_device_changed_callback =*/NULL, /*.register_device_collection_changed =*/ wasapi_register_device_collection_changed, diff --git a/src/cubeb_winmm.c b/src/cubeb_winmm.c index b2234a9b5..f07013098 100644 --- a/src/cubeb_winmm.c +++ b/src/cubeb_winmm.c @@ -1205,9 +1205,7 @@ static struct cubeb_ops const winmm_ops = { /*.stream_get_input_latency = */ NULL, /*.stream_set_volume =*/winmm_stream_set_volume, /*.stream_set_name =*/NULL, - /*.stream_get_current_device =*/NULL, /*.stream_set_input_mute =*/NULL, /*.stream_set_input_processing_params =*/NULL, - /*.stream_device_destroy =*/NULL, /*.stream_register_device_changed_callback=*/NULL, /*.register_device_collection_changed =*/NULL}; diff --git a/test/test_devices.cpp b/test/test_devices.cpp index d0eab2da6..33e38a2dc 100644 --- a/test/test_devices.cpp +++ b/test/test_devices.cpp @@ -213,52 +213,3 @@ TEST(cubeb, enumerate_devices) cubeb_stream_destroy(stream); } - -TEST(cubeb, stream_get_current_device) -{ - cubeb * ctx = NULL; - int r = common_init(&ctx, "Cubeb audio test"); - ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library"; - - std::unique_ptr cleanup_cubeb_at_exit( - ctx, cubeb_destroy); - - fprintf(stdout, "Getting current devices for backend %s\n", - cubeb_get_backend_id(ctx)); - - if (!can_run_audio_input_test(ctx)) { - return; - } - - cubeb_stream * stream = NULL; - cubeb_stream_params input_params; - cubeb_stream_params output_params; - - input_params.format = output_params.format = CUBEB_SAMPLE_FLOAT32NE; - input_params.rate = output_params.rate = 48000; - input_params.channels = output_params.channels = 1; - input_params.layout = output_params.layout = CUBEB_LAYOUT_MONO; - input_params.prefs = output_params.prefs = CUBEB_STREAM_PREF_NONE; - - r = cubeb_stream_init(ctx, &stream, "Cubeb duplex", NULL, &input_params, NULL, - &output_params, 1024, data_cb_duplex, state_cb_duplex, - nullptr); - ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream"; - std::unique_ptr - cleanup_stream_at_exit(stream, cubeb_stream_destroy); - - cubeb_device * device; - r = cubeb_stream_get_current_device(stream, &device); - if (r == CUBEB_ERROR_NOT_SUPPORTED) { - fprintf(stderr, "Getting current device is not supported" - " for this backend, skipping this test.\n"); - return; - } - ASSERT_EQ(r, CUBEB_OK) << "Error getting current devices"; - - fprintf(stdout, "Current output device: %s\n", device->output_name); - fprintf(stdout, "Current input device: %s\n", device->input_name); - - r = cubeb_stream_device_destroy(stream, device); - ASSERT_EQ(r, CUBEB_OK) << "Error destroying current devices"; -}