soundd: don't loop controls unresponsive sound infinitely (#22839)

* soundd: don't loop controls unresponsive sound infinitely

* update tests

* actually fix
This commit is contained in:
Adeeb Shihadeh
2021-11-09 16:58:21 -08:00
committed by GitHub
parent 2621e5301d
commit 445a5aaca4
6 changed files with 39 additions and 31 deletions
+13 -7
View File
@@ -11,8 +11,6 @@ public:
for (auto i = sounds.constBegin(); i != sounds.constEnd(); ++i) {
QObject::connect(i.value().first, &QSoundEffect::playingChanged, [=, s = i.value().first, a = i.key()]() {
if (s->isPlaying()) {
bool repeat = a == AudibleAlert::CHIME_WARNING_REPEAT || a == AudibleAlert::CHIME_WARNING2_REPEAT;
REQUIRE((s->loopsRemaining() == repeat ? QSoundEffect::Infinite : 1));
sound_stats[a].first++;
} else {
sound_stats[a].second++;
@@ -40,23 +38,31 @@ void controls_thread(int loop_cnt) {
}
}
}
// send no alert sound
for (int j = 0; j < 1000 / DT_CTRL; ++j) {
MessageBuilder msg;
msg.initEvent().initControlsState();
pm.send("controlsState", msg);
QThread::msleep(DT_CTRL);
}
QThread::currentThread()->quit();
}
TEST_CASE("test sound") {
TEST_CASE("test soundd") {
QEventLoop loop;
TestSound test_sound;
const int test_loop_cnt = 2;
QThread t;
QObject::connect(&t, &QThread::started, [=]() { controls_thread(test_loop_cnt); });
QObject::connect(&t, &QThread::finished, [&]() { loop.quit(); });
t.start();
loop.exec();
for (auto [play, stop] : test_sound.sound_stats) {
for (const AudibleAlert alert : test_sound.sound_stats.keys()) {
auto [play, stop] = test_sound.sound_stats[alert];
REQUIRE(play == test_loop_cnt);
REQUIRE(stop == test_loop_cnt);
}
+2 -2
View File
@@ -20,9 +20,9 @@ SOUNDS = {
AudibleAlert.chimeError: 173,
AudibleAlert.chimePrompt: 173,
AudibleAlert.chimeWarning1: 163,
AudibleAlert.chimeWarning2: 216,
AudibleAlert.chimeWarning2Repeat: 470,
AudibleAlert.chimeWarningRepeat: 468,
AudibleAlert.chimeWarningRepeatInfinite: 468,
AudibleAlert.chimeWarning2RepeatInfinite: 470,
}
def get_total_writes():