Skip to content
Snippets Groups Projects
Commit 18a8429f authored by Sébastien Blin's avatar Sébastien Blin
Browse files

audioinput: do not use getAvailableData()

In a conference, we don't want to wait on all tracks
because if a participant is in hold, the sound will
be cut for all participants.

This patch force the mix to occurs for every frame
even if there is no data.

Change-Id: I6ed4c50f771356f4a4cb642f4213a4865567eb8f
Gitlab: #273
parent 5af73248
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "smartools.h" #include "smartools.h"
#include <future> #include <future>
#include <chrono>
#include <memory> #include <memory>
namespace jami { namespace jami {
...@@ -51,6 +50,7 @@ AudioInput::AudioInput(const std::string& id) : ...@@ -51,6 +50,7 @@ AudioInput::AudioInput(const std::string& id) :
[] {}) [] {})
{ {
JAMI_DBG() << "Creating audio input with id: " << id; JAMI_DBG() << "Creating audio input with id: " << id;
wakeUp_ = std::chrono::high_resolution_clock::now() + MS_PER_PACKET;
loop_.start(); loop_.start();
} }
...@@ -120,8 +120,13 @@ AudioInput::readFromDevice() ...@@ -120,8 +120,13 @@ AudioInput::readFromDevice()
return; return;
} }
if (not mainBuffer.waitForDataAvailable(id_, MS_PER_PACKET)) // Note: read for device is called in an audio thread and we don't
return; // want to have a loop which takes 100% of the CPU.
// Here, we basically want to mix available data without any glitch
// and even if one buffer doesn't have audio data (call in hold,
// connections issues, etc). So mix every MS_PER_PACKET
std::this_thread::sleep_until(wakeUp_);
wakeUp_ += MS_PER_PACKET;
auto samples = mainBuffer.getData(id_); auto samples = mainBuffer.getData(id_);
if (not samples) if (not samples)
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <atomic> #include <atomic>
#include <future> #include <future>
#include <mutex> #include <mutex>
#include <chrono>
#include "audio/audiobuffer.h" #include "audio/audiobuffer.h"
#include "media_device.h" #include "media_device.h"
...@@ -99,6 +100,8 @@ private: ...@@ -99,6 +100,8 @@ private:
ThreadLoop loop_; ThreadLoop loop_;
void process(); void process();
std::chrono::time_point<std::chrono::high_resolution_clock> wakeUp_;
}; };
} // namespace jami } // namespace jami
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment