Skip to content

Commit ea28bc7

Browse files
borinearkq
andcommitted
Fix bluealsactl monitor after changes in 0d488c7
Closes #729 Co-authored-by: Arkadiusz Bokowy <[email protected]>
1 parent 04e8277 commit ea28bc7

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

src/bluealsactl/cmd-monitor.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,21 @@ static dbus_bool_t monitor_dbus_message_iter_get_pcm_props_cb(const char *key,
9595
}
9696
else if (monitor_properties_set[PROPERTY_VOLUME].enabled &&
9797
strcmp(key, monitor_properties_set[PROPERTY_VOLUME].name) == 0) {
98-
if (type != (type_expected = DBUS_TYPE_UINT16))
98+
if (type != (type_expected = DBUS_TYPE_ARRAY))
9999
goto fail;
100-
dbus_uint16_t volume;
101-
dbus_message_iter_get_basic(&variant, &volume);
102-
printf("PropertyChanged %s Volume 0x%.4X\n", path, volume);
100+
101+
DBusMessageIter iter;
102+
uint8_t *data;
103+
int len;
104+
105+
dbus_message_iter_recurse(&variant, &iter);
106+
dbus_message_iter_get_fixed_array(&iter, &data, &len);
107+
108+
printf("PropertyChanged %s Volume", path);
109+
for (size_t i = 0; i < (size_t)len; i++)
110+
printf(" %u%s", data[i] & 0x7f, data[i] & 0x80 ? "(M)" : "");
111+
printf("\n");
112+
103113
}
104114

105115
return TRUE;

test/mock/mock-bluez.c

+13
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,15 @@ int mock_bluez_device_profile_new_connection(const char *device_path,
297297
return 0;
298298
}
299299

300+
static gboolean mock_bluez_media_transport_fuzz(void *userdata) {
301+
MockBluezMediaTransport1 *transport = userdata;
302+
/* Pseudo-random hash based on the device path to simulate different values. */
303+
unsigned int hash = g_str_hash(mock_bluez_media_transport1_get_device(transport));
304+
mock_bluez_media_transport1_set_delay(transport, hash % 2777);
305+
mock_bluez_media_transport1_set_volume(transport, hash % 101);
306+
return G_SOURCE_REMOVE;
307+
}
308+
300309
static void mock_bluez_media_endpoint_set_configuration_finish(GObject *source,
301310
GAsyncResult *result, G_GNUC_UNUSED void *userdata) {
302311
MockBluezMediaEndpoint1 *endpoint = MOCK_BLUEZ_MEDIA_ENDPOINT1(source);
@@ -343,6 +352,10 @@ int mock_bluez_device_media_set_configuration(const char *device_path,
343352
if (strcmp(uuid, BT_UUID_A2DP_SINK) == 0)
344353
mock_bluez_media_transport1_set_state(transport, "pending");
345354

355+
/* If fuzzing is enabled, update some properties after slight delay. */
356+
if (mock_fuzzing_ms)
357+
g_timeout_add(mock_fuzzing_ms, mock_bluez_media_transport_fuzz, transport);
358+
346359
rv = 0;
347360
break;
348361
}

test/test-alsa-ctl.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,15 @@ CK_START_TEST(test_notifications) {
535535

536536
/* Processed events:
537537
* - 0 removes; 2 new elems (12:34:... A2DP)
538+
* - 4 updates per new A2DP (updated delay and volume)
538539
* - 2 removes; 4 new elems (12:34:... A2DP, 23:45:... A2DP)
540+
* - 4 updates per new A2DP (updated delay and volume)
539541
* - 4 removes; 7 new elems (2x A2DP, SCO playback, battery)
540542
* - 7 removes; 9 new elems (2x A2DP, SCO playback/capture, battery)
541543
* - 4 updates per codec (SCO codec updates if codec selection is supported)
542544
*/
543-
size_t expected_events = (0 + 2) + (2 + 4) + (4 + 7) + (7 + 9) + events_update_codec;
545+
size_t expected_events =
546+
(0 + 2) + 4 + (2 + 4) + 4 + (4 + 7) + (7 + 9) + events_update_codec;
544547

545548
/* XXX: It is possible that the battery element (RFCOMM D-Bus path) will not
546549
* be exported in time. In such case, the number of events will be less

test/test-utils-ctl.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,12 @@ CK_START_TEST(test_monitor) {
408408
ck_assert_ptr_ne(strstr(output,
409409
"Device: /org/bluez/hci11/dev_23_45_67_89_AB_CD"), NULL);
410410

411-
#if ENABLE_MSBC
412411
/* notifications for property changed */
412+
ck_assert_ptr_ne(strstr(output,
413+
"PropertyChanged /org/bluealsa/hci11/dev_12_34_56_78_9A_BC/a2dpsrc/sink Volume 54 54"), NULL);
414+
ck_assert_ptr_ne(strstr(output,
415+
"PropertyChanged /org/bluealsa/hci11/dev_23_45_67_89_AB_CD/a2dpsrc/sink Volume 84 84"), NULL);
416+
#if ENABLE_MSBC
413417
ck_assert_ptr_ne(strstr(output,
414418
"PropertyChanged /org/bluealsa/hci11/dev_12_34_56_78_9A_BC/hfpag/sink Codec CVSD"), NULL);
415419
ck_assert_ptr_ne(strstr(output,

0 commit comments

Comments
 (0)