mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-18 06:20:14 +00:00
source-mirror: Fix out-of-order playback of audio
On highly parallel systems (> 4 Threads) audio had a chance of being played back out of order, causing it to jitter. This queue should help eliminate the issue entirely. Fixes #111
This commit is contained in:
parent
8f4313d8e8
commit
d6c903a3bd
2 changed files with 21 additions and 12 deletions
|
@ -249,16 +249,23 @@ void source::mirror::mirror_instance::on_audio(std::shared_ptr<obs_source_t>, co
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> ul(_audio_queue_lock);
|
||||
_audio_queue.emplace(audio, detected_layout);
|
||||
}
|
||||
|
||||
// Create a clone of the audio data and push it to the thread pool.
|
||||
get_global_threadpool()->push(
|
||||
std::bind(&source::mirror::mirror_instance::audio_output, this, std::placeholders::_1),
|
||||
std::make_shared<mirror_audio_data>(audio, detected_layout));
|
||||
std::bind(&source::mirror::mirror_instance::audio_output, this, std::placeholders::_1), nullptr);
|
||||
}
|
||||
|
||||
void source::mirror::mirror_instance::audio_output(std::shared_ptr<void> data)
|
||||
{
|
||||
std::shared_ptr<mirror_audio_data> mad = std::static_pointer_cast<mirror_audio_data>(data);
|
||||
obs_source_output_audio(_self, &mad->osa);
|
||||
std::unique_lock<std::mutex> ul(_audio_queue_lock);
|
||||
while (_audio_queue.size() > 0) {
|
||||
obs_source_output_audio(_self, &((_audio_queue.front()).osa));
|
||||
_audio_queue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<mirror::mirror_factory> mirror::mirror_factory::factory_instance;
|
||||
|
|
|
@ -61,6 +61,8 @@ namespace source::mirror {
|
|||
// Audio
|
||||
bool _audio_enabled;
|
||||
speaker_layout _audio_layout;
|
||||
std::mutex _audio_queue_lock;
|
||||
std::queue<mirror_audio_data> _audio_queue;
|
||||
|
||||
public:
|
||||
mirror_instance(obs_data_t* settings, obs_source_t* self);
|
||||
|
|
Loading…
Reference in a new issue