aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBrendan Early <[email protected]>2020-09-28 16:55:10 -0500
committerMatthew Gregan <[email protected]>2020-10-07 11:27:54 +1300
commit2e842a01f743a734e3720f817c22224af0a80298 (patch)
treeeee874571abb2024244670c6ae798da3df681dc9
parent082ba33d120d484c4d5e2404dbda69c1f7e6751b (diff)
downloadcubeb-2e842a01f743a734e3720f817c22224af0a80298.tar.gz
cubeb-2e842a01f743a734e3720f817c22224af0a80298.zip
Add method to change stream name
-rw-r--r--include/cubeb/cubeb.h8
-rw-r--r--src/cubeb-internal.h1
-rw-r--r--src/cubeb.c14
-rw-r--r--src/cubeb_pulse.c32
-rw-r--r--test/test_sanity.cpp3
5 files changed, 58 insertions, 0 deletions
diff --git a/include/cubeb/cubeb.h b/include/cubeb/cubeb.h
index f8abfce..43fff5d 100644
--- a/include/cubeb/cubeb.h
+++ b/include/cubeb/cubeb.h
@@ -584,6 +584,14 @@ CUBEB_EXPORT int cubeb_stream_get_input_latency(cubeb_stream * stream, uint32_t
@retval CUBEB_ERROR_NOT_SUPPORTED */
CUBEB_EXPORT int cubeb_stream_set_volume(cubeb_stream * stream, float volume);
+/** Change a stream's name.
+ @param stream the stream for which to set the name.
+ @param stream_name the new name for the stream
+ @retval CUBEB_OK
+ @retval CUBEB_ERROR_INVALID_PARAMETER if any pointer is invalid
+ @retval CUBEB_ERROR_NOT_SUPPORTED */
+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.
diff --git a/src/cubeb-internal.h b/src/cubeb-internal.h
index 4aee68f..9d3d1dd 100644
--- a/src/cubeb-internal.h
+++ b/src/cubeb-internal.h
@@ -65,6 +65,7 @@ struct cubeb_ops {
int (* stream_get_latency)(cubeb_stream * stream, uint32_t * latency);
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_device_destroy)(cubeb_stream * stream,
diff --git a/src/cubeb.c b/src/cubeb.c
index 751e044..8d077bd 100644
--- a/src/cubeb.c
+++ b/src/cubeb.c
@@ -448,6 +448,20 @@ cubeb_stream_set_volume(cubeb_stream * stream, float volume)
return stream->context->ops->stream_set_volume(stream, volume);
}
+int
+cubeb_stream_set_name(cubeb_stream * stream, char const * stream_name)
+{
+ if (!stream || !stream_name) {
+ return CUBEB_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!stream->context->ops->stream_set_name) {
+ return CUBEB_ERROR_NOT_SUPPORTED;
+ }
+
+ return stream->context->ops->stream_set_name(stream, stream_name);
+}
+
int cubeb_stream_get_current_device(cubeb_stream * stream,
cubeb_device ** const device)
{
diff --git a/src/cubeb_pulse.c b/src/cubeb_pulse.c
index a393b66..c7e9d1c 100644
--- a/src/cubeb_pulse.c
+++ b/src/cubeb_pulse.c
@@ -86,6 +86,7 @@
X(pa_mainloop_api_once) \
X(pa_get_library_version) \
X(pa_channel_map_init_auto) \
+ X(pa_stream_set_name) \
#define MAKE_TYPEDEF(x) static typeof(x) * cubeb_##x;
LIBPULSE_API_VISIT(MAKE_TYPEDEF);
@@ -1139,6 +1140,14 @@ volume_success(pa_context *c, int success, void *userdata)
WRAP(pa_threaded_mainloop_signal)(stream->context->mainloop, 0);
}
+static void
+rename_success(pa_stream *s, int success, void *userdata)
+{
+ cubeb_stream * stream = userdata;
+ assert(success);
+ WRAP(pa_threaded_mainloop_signal)(stream->context->mainloop, 0);
+}
+
static int
pulse_stream_set_volume(cubeb_stream * stm, float volume)
{
@@ -1183,6 +1192,28 @@ pulse_stream_set_volume(cubeb_stream * stm, float volume)
return CUBEB_OK;
}
+static int
+pulse_stream_set_name(cubeb_stream * stm, char const * stream_name)
+{
+ if (!stm || !stm->output_stream) {
+ return CUBEB_ERROR;
+ }
+
+ WRAP(pa_threaded_mainloop_lock)(stm->context->mainloop);
+
+ pa_operation * op =
+ WRAP(pa_stream_set_name)(stm->output_stream, stream_name, rename_success, stm);
+
+ if (op) {
+ operation_wait(stm->context, stm->output_stream, op);
+ WRAP(pa_operation_unref)(op);
+ }
+
+ WRAP(pa_threaded_mainloop_unlock)(stm->context->mainloop);
+
+ return CUBEB_OK;
+}
+
typedef struct {
char * default_sink_name;
char * default_source_name;
@@ -1599,6 +1630,7 @@ static struct cubeb_ops const pulse_ops = {
.stream_get_latency = pulse_stream_get_latency,
.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_device_destroy = pulse_stream_device_destroy,
.stream_register_device_changed_callback = NULL,
diff --git a/test/test_sanity.cpp b/test/test_sanity.cpp
index 91ecf9d..e1a60d0 100644
--- a/test/test_sanity.cpp
+++ b/test/test_sanity.cpp
@@ -227,6 +227,9 @@ TEST(cubeb, configure_stream)
r = cubeb_stream_set_volume(stream, 1.0f);
ASSERT_TRUE(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED);
+ r = cubeb_stream_set_name(stream, "test 2");
+ ASSERT_TRUE(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED);
+
cubeb_stream_destroy(stream);
cubeb_destroy(ctx);
}