aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cubeb_pulse.c
diff options
context:
space:
mode:
authorDan Glastonbury <[email protected]>2017-05-15 11:23:13 +1000
committerDan Glastonbury <[email protected]>2017-08-29 19:05:30 +1000
commit2160942fe6a69245d2af971e3e9599c832b9dd9b (patch)
treea5c2fa2cf36cf5f1e75252819fdec4fafc2c4314 /src/cubeb_pulse.c
parent8b17b0e9dafcc710215d98f370deae988f78c2dc (diff)
downloadcubeb-2160942fe6a69245d2af971e3e9599c832b9dd9b.tar.gz
cubeb-2160942fe6a69245d2af971e3e9599c832b9dd9b.zip
pulse: Implement interning device ids.
Diffstat (limited to 'src/cubeb_pulse.c')
-rw-r--r--src/cubeb_pulse.c68
1 files changed, 62 insertions, 6 deletions
diff --git a/src/cubeb_pulse.c b/src/cubeb_pulse.c
index b4d3e19..21f3a89 100644
--- a/src/cubeb_pulse.c
+++ b/src/cubeb_pulse.c
@@ -13,7 +13,7 @@
#include "cubeb/cubeb.h"
#include "cubeb-internal.h"
#include "cubeb_mixer.h"
-#include "cubeb_utils.h"
+#include "cubeb_strings.h"
#include <stdio.h>
#ifdef DISABLE_LIBPULSE_DLOPEN
@@ -102,6 +102,7 @@ struct cubeb {
int error;
cubeb_device_collection_changed_callback collection_changed_callback;
void * collection_changed_user_ptr;
+ cubeb_strings * device_ids;
};
struct cubeb_stream {
@@ -127,6 +128,24 @@ enum cork_state {
NOTIFY = 1 << 1
};
+static int
+intern_device_id(cubeb * ctx, char const ** id)
+{
+ char const * interned;
+
+ assert(ctx);
+ assert(id);
+
+ interned = cubeb_strings_intern(ctx->device_ids, *id);
+ if (!interned) {
+ return CUBEB_ERROR;
+ }
+
+ *id = interned;
+
+ return CUBEB_OK;
+}
+
static void
sink_info_callback(pa_context * context, const pa_sink_info * info, int eol, void * u)
{
@@ -608,6 +627,10 @@ pulse_init(cubeb ** context, char const * context_name)
ctx->ops = &pulse_ops;
ctx->libpulse = libpulse;
+ if (cubeb_strings_init(&ctx->device_ids) != CUBEB_OK) {
+ pulse_destroy(ctx);
+ return CUBEB_ERROR;
+ }
ctx->mainloop = WRAP(pa_threaded_mainloop_new)();
ctx->default_sink_info = NULL;
@@ -717,6 +740,10 @@ pulse_destroy(cubeb * ctx)
WRAP(pa_threaded_mainloop_free)(ctx->mainloop);
}
+ if (ctx->device_ids) {
+ cubeb_strings_destroy(ctx->device_ids);
+ }
+
if (ctx->libpulse) {
dlclose(ctx->libpulse);
}
@@ -1203,18 +1230,25 @@ pulse_sink_info_cb(pa_context * context, const pa_sink_info * info,
{
pulse_dev_list_data * list_data = user_data;
cubeb_device_info * devinfo;
- const char * prop;
+ char const * prop = NULL;
+ char const * device_id = NULL;
(void)context;
if (eol || info == NULL)
return;
+ device_id = info->name;
+ if (intern_device_id(list_data->context, &device_id) != CUBEB_OK) {
+ assert(false);
+ return;
+ }
+
pulse_ensure_dev_list_data_list_size(list_data);
devinfo = &list_data->devinfo[list_data->count];
memset(devinfo, 0, sizeof(cubeb_device_info));
- devinfo->device_id = strdup(info->name);
+ devinfo->device_id = device_id;
devinfo->devid = (cubeb_devid) devinfo->device_id;
devinfo->friendly_name = strdup(info->description);
prop = WRAP(pa_proplist_gets)(info->proplist, "sysfs.path");
@@ -1265,18 +1299,25 @@ pulse_source_info_cb(pa_context * context, const pa_source_info * info,
{
pulse_dev_list_data * list_data = user_data;
cubeb_device_info * devinfo;
- const char * prop;
+ char const * prop = NULL;
+ char const * device_id = NULL;
(void)context;
if (eol)
return;
+ device_id = info->name;
+ if (intern_device_id(list_data->context, &device_id) != CUBEB_OK) {
+ assert(false);
+ return;
+ }
+
pulse_ensure_dev_list_data_list_size(list_data);
devinfo = &list_data->devinfo[list_data->count];
memset(devinfo, 0, sizeof(cubeb_device_info));
- devinfo->device_id = strdup(info->name);
+ devinfo->device_id = device_id;
devinfo->devid = (cubeb_devid) devinfo->device_id;
devinfo->friendly_name = strdup(info->description);
prop = WRAP(pa_proplist_gets)(info->proplist, "sysfs.path");
@@ -1365,6 +1406,21 @@ pulse_enumerate_devices(cubeb * context, cubeb_device_type type,
}
static int
+pulse_device_collection_destroy(cubeb * ctx, cubeb_device_collection * collection)
+{
+ size_t n;
+
+ for (n = 0; n < collection->count; n++) {
+ free((void *) collection->device[n].friendly_name);
+ free((void *) collection->device[n].vendor_name);
+ free((void *) collection->device[n].group_id);
+ }
+
+ free(collection->device);
+ return CUBEB_OK;
+}
+
+static int
pulse_stream_get_current_device(cubeb_stream * stm, cubeb_device ** const device)
{
#if PA_CHECK_VERSION(0, 9, 8)
@@ -1493,7 +1549,7 @@ static struct cubeb_ops const pulse_ops = {
.get_preferred_sample_rate = pulse_get_preferred_sample_rate,
.get_preferred_channel_layout = pulse_get_preferred_channel_layout,
.enumerate_devices = pulse_enumerate_devices,
- .device_collection_destroy = cubeb_utils_default_device_collection_destroy,
+ .device_collection_destroy = pulse_device_collection_destroy,
.destroy = pulse_destroy,
.stream_init = pulse_stream_init,
.stream_destroy = pulse_stream_destroy,