From 1ccd3442f33b536e0525731e1bac572c0bf16b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Tue, 31 Mar 2020 21:04:50 -0400 Subject: [PATCH] opensl: bring back mutex Change-Id: Iede9cf73b9f55e5aaa1e6d60da30362475656362 --- src/media/audio/opensl/audio_player.cpp | 2 ++ src/media/audio/opensl/audio_player.h | 1 + src/media/audio/opensl/opensllayer.cpp | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/media/audio/opensl/audio_player.cpp b/src/media/audio/opensl/audio_player.cpp index b80394e5f4..dfd7b3be5e 100644 --- a/src/media/audio/opensl/audio_player.cpp +++ b/src/media/audio/opensl/audio_player.cpp @@ -40,6 +40,8 @@ void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *ctx) { (static_cast<AudioPlayer *>(ctx))->processSLCallback(bq); } void AudioPlayer::processSLCallback(SLAndroidSimpleBufferQueueItf bq) { + std::lock_guard<std::mutex> lk(m_); + // retrieve the finished device buf and put onto the free queue // so recorder could re-use it sample_buf *buf; diff --git a/src/media/audio/opensl/audio_player.h b/src/media/audio/opensl/audio_player.h index 0e9383c896..7fc470b8c6 100644 --- a/src/media/audio/opensl/audio_player.h +++ b/src/media/audio/opensl/audio_player.h @@ -58,6 +58,7 @@ public: void registerCallback(EngineCallback cb) {callback_ = cb;} size_t dbgGetDevBufCount(); + std::mutex m_; std::atomic_bool waiting_ {false}; }; diff --git a/src/media/audio/opensl/opensllayer.cpp b/src/media/audio/opensl/opensllayer.cpp index 445b0603f5..3a58dc63b5 100644 --- a/src/media/audio/opensl/opensllayer.cpp +++ b/src/media/audio/opensl/opensllayer.cpp @@ -302,14 +302,14 @@ OpenSLLayer::startAudioPlayback() while (player_ || ringtone_) { playCv.wait_for(lck, std::chrono::seconds(1)); if (player_ && player_->waiting_) { - //std::lock_guard<std::mutex> lk(player_->m_); + std::lock_guard<std::mutex> lk(player_->m_); engineServicePlay(false); auto n = playBufQueue_.size(); if (n >= PLAY_KICKSTART_BUFFER_COUNT) player_->playAudioBuffers(n); } if (ringtone_ && ringtone_->waiting_) { - //std::lock_guard<std::mutex> lk(ringtone_->m_); + std::lock_guard<std::mutex> lk(ringtone_->m_); engineServiceRing(false); auto n = ringBufQueue_.size(); if (n >= PLAY_KICKSTART_BUFFER_COUNT) -- GitLab