Skip to content

Commit

Permalink
Reuse BlueZ integration code for BlueALSA mock
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Apr 26, 2024
1 parent 123617d commit c6b3087
Show file tree
Hide file tree
Showing 11 changed files with 476 additions and 217 deletions.
1 change: 1 addition & 0 deletions .github/iwyu.imp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{ include: [ '<glib/gtypes.h>', private, '<glib.h>', public ] },
{ include: [ '"gobject/gclosure.h"', private, '<glib-object.h>', public ] },
{ include: [ '"gio/gdbusinterfaceskeleton.h"', private, '<gio/gio.h>', public ] },
{ include: [ '"gio/gdbusobjectmanager.h"', private, '<gio/gio.h>', public ] },
{ include: [ '"gio/gdbusobjectmanagerserver.h"', private, '<gio/gio.h>', public ] },
{ include: [ '"gio/gdbusobjectskeleton.h"', private, '<gio/gio.h>', public ] },

Expand Down
4 changes: 2 additions & 2 deletions src/asound/bluealsa-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ static void bluealsa_elem_set_name(struct bluealsa_ctl *ctl, struct ctl_elem *el
if (name != NULL) {
/* multi-device mixer - include device alias in control names */

const int name_len = strlen(name);
const size_t name_len = strlen(name);
/* max name length with reserved space for ALSA suffix */
int len = sizeof(elem->name) - 16 - 1;
char no[16] = "";
Expand All @@ -556,7 +556,7 @@ static void bluealsa_elem_set_name(struct bluealsa_ctl *ctl, struct ctl_elem *el
}

/* get the longest possible element label */
int label_max_len = sizeof(" A2DP") - 1;
size_t label_max_len = sizeof(" A2DP") - 1;
if (ctl->show_bt_transport)
label_max_len = sizeof(" SCO-HFP-AG") - 1;
if (ctl->show_vol_mode)
Expand Down
2 changes: 1 addition & 1 deletion src/asound/bluealsa-pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ static bool bluealsa_select_pcm_codec(struct bluealsa_pcm *pcm, const char *code
const char *config_hex;
/* split the given string into name and configuration components */
if ((config_hex = strchr(codec, ':')) != NULL) {
name_len = MIN(name_len, config_hex - codec);
name_len = MIN(name_len, (size_t)(config_hex - codec));
config_hex++;

size_t config_hex_len;
Expand Down
12 changes: 7 additions & 5 deletions src/bluez.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,8 +1310,9 @@ static void bluez_register(void) {
size_t i;
struct ba_adapter *a;
for (i = 0; i < ARRAYSIZE(adapters); i++)
if (adapters[i] &&
(a = ba_adapter_new(i)) != NULL) {
if (adapters[i] && (
(a = ba_adapter_lookup(i)) != NULL ||
(a = ba_adapter_new(i)) != NULL)) {

for (size_t ii = 0; ii < ARRAYSIZE(uuids); ii++)
if (uuids[ii].enabled && !uuids[ii].global && adapters_profiles[i] & uuids[ii].profile)
Expand Down Expand Up @@ -1406,8 +1407,9 @@ static void bluez_signal_interfaces_added(GDBusConnection *conn, const char *sen
g_variant_iter_free(interfaces);

struct ba_adapter *a;
if (hci_dev_id != -1 &&
(a = ba_adapter_new(hci_dev_id)) != NULL) {
if (hci_dev_id != -1 && (
(a = ba_adapter_lookup(hci_dev_id)) != NULL ||
(a = ba_adapter_new(hci_dev_id)) != NULL)) {
bluez_adapter_new(a);
}

Expand Down Expand Up @@ -1620,7 +1622,7 @@ static unsigned int bluez_bus_watch_id = 0;

/**
* Subscribe to BlueZ signals. */
void bluez_signals_subscribe(void) {
static void bluez_signals_subscribe(void) {

bluez_sig_sub_id_iface_added = g_dbus_connection_signal_subscribe(config.dbus,
BLUEZ_SERVICE, DBUS_IFACE_OBJECT_MANAGER, "InterfacesAdded", NULL, NULL,
Expand Down
4 changes: 2 additions & 2 deletions src/shared/dbus-client-pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static dbus_bool_t ba_dbus_message_iter_pcm_codec_get_props_cb(const char *key,
dbus_message_iter_recurse(&variant, &iter);
dbus_message_iter_get_fixed_array(&iter, &data, &len);

codec->data_len = MIN(len, sizeof(codec->data));
codec->data_len = MIN((size_t)len, sizeof(codec->data));
memcpy(codec->data, data, codec->data_len);

}
Expand Down Expand Up @@ -725,7 +725,7 @@ static dbus_bool_t dbus_message_iter_get_ba_pcm_props_cb(const char *key,
dbus_message_iter_recurse(&variant, &iter);
dbus_message_iter_get_fixed_array(&iter, &data, &len);

pcm->codec.data_len = MIN(len, sizeof(pcm->codec.data));
pcm->codec.data_len = MIN((size_t)len, sizeof(pcm->codec.data));
memcpy(pcm->codec.data, data, pcm->codec.data_len);

}
Expand Down
Loading

0 comments on commit c6b3087

Please sign in to comment.