From 26694c152cecf8ecf2fb82ce6a3f7eb97a3662f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Thu, 12 Nov 2020 15:08:21 -0500
Subject: [PATCH] ringbufferpool: do not return a frame if nothing is mixed

This avoid an infinite loop in pulselayer cause during a short
moment the ringbufferpool will contains two binding mixed together
with nothing being mixed. So AudioLayer::getToPlay will just
lock forever and the pulselayer will not be able to stop the
mainloop

Change-Id: Ic6e316308de6ec37f9c7525e1601e14593fd17d1
---
 src/media/audio/ringbufferpool.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/media/audio/ringbufferpool.cpp b/src/media/audio/ringbufferpool.cpp
index 21bcd8e94c..92429a7dea 100644
--- a/src/media/audio/ringbufferpool.cpp
+++ b/src/media/audio/ringbufferpool.cpp
@@ -267,20 +267,22 @@ RingBufferPool::getData(const std::string& call_id)
 
     const auto bindings = getReadBindings(call_id);
     if (not bindings)
-        return 0;
+        return {};
 
     // No mixing
     if (bindings->size() == 1)
         return (*bindings->cbegin())->get(call_id);
 
     auto mixBuffer = std::make_shared<AudioFrame>(internalAudioFormat_);
+    auto mixed = false;
     for (const auto& rbuf : *bindings) {
         if (auto b = rbuf->get(call_id)) {
+            mixed = true;
             mixBuffer->mix(*b);
         }
     }
 
-    return mixBuffer;
+    return mixed ? mixBuffer : nullptr;
 }
 
 bool
-- 
GitLab