mirror of
https://github.com/jambonz/freeswitch-modules.git
synced 2026-01-25 02:08:27 +00:00
fix deadlock bug
This commit is contained in:
1 parent
14297ce3a6
commit
07dddd0094
1 file changed
+18
-4
+18
-4
@@ -26,12 +26,20 @@ void Track::onPlayDone(bool hasError, const std::string& errMsg) {
|
|||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Track::onPlayDone %s\n", _trackName.c_str());
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Track::onPlayDone %s\n", _trackName.c_str());
|
||||||
|
|
||||||
if (!_stopping) {
|
if (!_stopping) {
|
||||||
|
std::shared_ptr<AudioProducer> apDone, apNext; // to retain a ref so the ap is not destroyed while under lock below -- avoid deadlock
|
||||||
|
|
||||||
if (hasError) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "onPlayDone: error: %s\n", errMsg.c_str());
|
if (hasError) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "onPlayDone: error: %s\n", errMsg.c_str());
|
||||||
std::lock_guard<std::mutex> lock(_mutex);
|
{
|
||||||
_apQueue.pop();
|
std::lock_guard<std::mutex> lock(_mutex);
|
||||||
if (!_apQueue.empty()) {
|
if (!_apQueue.empty()) {
|
||||||
|
apDone = _apQueue.front();
|
||||||
|
_apQueue.pop();
|
||||||
|
}
|
||||||
|
if (!_apQueue.empty()) apNext = _apQueue.front();
|
||||||
|
}
|
||||||
|
if (apNext) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "onPlayDone: starting queued audio on track %s\n", _trackName.c_str());
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "onPlayDone: starting queued audio on track %s\n", _trackName.c_str());
|
||||||
_apQueue.front()->start(std::bind(&Track::onPlayDone, this, std::placeholders::_1, std::placeholders::_2));
|
apNext->start(std::bind(&Track::onPlayDone, this, std::placeholders::_1, std::placeholders::_2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -50,11 +58,17 @@ void Track::queueFileAudio(const std::string& path, int gain, bool loop) {
|
|||||||
_apQueue.push(ap);
|
_apQueue.push(ap);
|
||||||
startIt = _apQueue.size() == 1;
|
startIt = _apQueue.size() == 1;
|
||||||
}
|
}
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||||
|
"queueFileAudio: queue file %s on track %s\n", _trackName.c_str(), path.c_str());
|
||||||
|
|
||||||
if (startIt) {
|
if (startIt) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||||
|
"queueFileAudio: track %s starting queued file as none are in progress\n", _trackName.c_str());
|
||||||
try {
|
try {
|
||||||
ap->start(std::bind(&Track::onPlayDone, this, std::placeholders::_1, std::placeholders::_2));
|
ap->start(std::bind(&Track::onPlayDone, this, std::placeholders::_1, std::placeholders::_2));
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||||
|
"queueFileAudio: track %s error starting %s: %s\n", _trackName.c_str(), path.c_str(), e.what());
|
||||||
onPlayDone(true, e.what());
|
onPlayDone(true, e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user