Skip to content

Commit

Permalink
Fix bluealsactl monitor after changes in 0d488c7
Browse files Browse the repository at this point in the history
Closes #729
  • Loading branch information
borine authored and arkq committed Sep 15, 2024
1 parent 04e8277 commit e9da8aa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/bluealsa-dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ static bool bluealsa_pcm_set_property(const char *property, GVariant *value,
const int level = ba_transport_pcm_volume_range_to_level(volume[i] & 0x7F, volume_max);

debug("Setting volume [ch=%zu]: %u [%.2f dB] [%c]",
i, volume[i] & 0x7F, 0.01 * level, muted ? 'x' : ' ');
i, volume[i] & 0x7F, 0.01 * level, muted ? 'M' : ' ');
ba_transport_pcm_volume_set(&pcm->volume[i], &level, &muted, NULL);

}
Expand Down
19 changes: 15 additions & 4 deletions src/bluealsactl/cmd-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <getopt.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -95,11 +96,21 @@ static dbus_bool_t monitor_dbus_message_iter_get_pcm_props_cb(const char *key,
}
else if (monitor_properties_set[PROPERTY_VOLUME].enabled &&
strcmp(key, monitor_properties_set[PROPERTY_VOLUME].name) == 0) {
if (type != (type_expected = DBUS_TYPE_UINT16))
if (type != (type_expected = DBUS_TYPE_ARRAY))
goto fail;
dbus_uint16_t volume;
dbus_message_iter_get_basic(&variant, &volume);
printf("PropertyChanged %s Volume 0x%.4X\n", path, volume);

DBusMessageIter iter;
uint8_t *data;
int len;

dbus_message_iter_recurse(&variant, &iter);
dbus_message_iter_get_fixed_array(&iter, &data, &len);

printf("PropertyChanged %s Volume", path);
for (size_t i = 0; i < (size_t)len; i++)
printf(" %u%s", data[i] & 0x7f, data[i] & 0x80 ? "[M]" : "");
printf("\n");

}

return TRUE;
Expand Down
13 changes: 13 additions & 0 deletions test/mock/mock-bluez.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ int mock_bluez_device_profile_new_connection(const char *device_path,
return 0;
}

static gboolean mock_bluez_media_transport_fuzz(void *userdata) {
MockBluezMediaTransport1 *transport = userdata;
/* Pseudo-random hash based on the device path to simulate different values. */
unsigned int hash = g_str_hash(mock_bluez_media_transport1_get_device(transport));
mock_bluez_media_transport1_set_delay(transport, hash % 2777);
mock_bluez_media_transport1_set_volume(transport, hash % 101);
return G_SOURCE_REMOVE;
}

static void mock_bluez_media_endpoint_set_configuration_finish(GObject *source,
GAsyncResult *result, G_GNUC_UNUSED void *userdata) {
MockBluezMediaEndpoint1 *endpoint = MOCK_BLUEZ_MEDIA_ENDPOINT1(source);
Expand Down Expand Up @@ -343,6 +352,10 @@ int mock_bluez_device_media_set_configuration(const char *device_path,
if (strcmp(uuid, BT_UUID_A2DP_SINK) == 0)
mock_bluez_media_transport1_set_state(transport, "pending");

/* If fuzzing is enabled, update some properties after slight delay. */
if (mock_fuzzing_ms)
g_timeout_add(mock_fuzzing_ms, mock_bluez_media_transport_fuzz, transport);

rv = 0;
break;
}
Expand Down
5 changes: 4 additions & 1 deletion test/test-alsa-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,15 @@ CK_START_TEST(test_notifications) {

/* Processed events:
* - 0 removes; 2 new elems (12:34:... A2DP)
* - 4 updates per new A2DP (updated delay and volume)
* - 2 removes; 4 new elems (12:34:... A2DP, 23:45:... A2DP)
* - 4 updates per new A2DP (updated delay and volume)
* - 4 removes; 7 new elems (2x A2DP, SCO playback, battery)
* - 7 removes; 9 new elems (2x A2DP, SCO playback/capture, battery)
* - 4 updates per codec (SCO codec updates if codec selection is supported)
*/
size_t expected_events = (0 + 2) + (2 + 4) + (4 + 7) + (7 + 9) + events_update_codec;
size_t expected_events =
(0 + 2) + 4 + (2 + 4) + 4 + (4 + 7) + (7 + 9) + events_update_codec;

/* XXX: It is possible that the battery element (RFCOMM D-Bus path) will not
* be exported in time. In such case, the number of events will be less
Expand Down
6 changes: 5 additions & 1 deletion test/test-utils-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,12 @@ CK_START_TEST(test_monitor) {
ck_assert_ptr_ne(strstr(output,
"Device: /org/bluez/hci11/dev_23_45_67_89_AB_CD"), NULL);

#if ENABLE_MSBC
/* notifications for property changed */
ck_assert_ptr_ne(strstr(output,
"PropertyChanged /org/bluealsa/hci11/dev_12_34_56_78_9A_BC/a2dpsrc/sink Volume 54 54"), NULL);
ck_assert_ptr_ne(strstr(output,
"PropertyChanged /org/bluealsa/hci11/dev_23_45_67_89_AB_CD/a2dpsrc/sink Volume 84 84"), NULL);
#if ENABLE_MSBC
ck_assert_ptr_ne(strstr(output,
"PropertyChanged /org/bluealsa/hci11/dev_12_34_56_78_9A_BC/hfpag/sink Codec CVSD"), NULL);
ck_assert_ptr_ne(strstr(output,
Expand Down

0 comments on commit e9da8aa

Please sign in to comment.