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

Co-authored-by: Arkadiusz Bokowy <arkadiusz.bokowy@gmail.com>
  • Loading branch information
borine and arkq committed Sep 15, 2024
1 parent 04e8277 commit ea28bc7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/bluealsactl/cmd-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,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 ea28bc7

Please sign in to comment.