MT#59962 AmRtpAudio: setPlayoutType properly acquire the lock

Cover the whole conditioning with the lock,
because otherwise two threads competing on execution
can suddenly come across the `(m_playout_type != type)` getting
true (for both) and one of them by acquiring the lock can potentially
manage to modify that, what can actually make `(m_playout_type != type)`
not true anymore for the other thread in race condition here.

Change-Id: Ie352da10a515837efc696063837b70dc2c9a304d
master
Donat Zenichev 2 weeks ago
parent 72a5549f88
commit 7c75c8e394

@ -468,31 +468,27 @@ void AmRtpAudio::add_to_history(int16_t *buffer, unsigned int size)
void AmRtpAudio::setPlayoutType(PlayoutType type)
{
session->lockAudio();
if (m_playout_type != type)
{
if (type == ADAPTIVE_PLAYOUT) {
session->lockAudio();
m_playout_type = type;
if (fmt.get())
playout_buffer.reset(new AmAdaptivePlayout(this,getSampleRate()));
session->unlockAudio();
DBG("Adaptive playout buffer activated\n");
}
else if (type == JB_PLAYOUT) {
session->lockAudio();
m_playout_type = type;
if (fmt.get())
playout_buffer.reset(new AmJbPlayout(this,getSampleRate()));
session->unlockAudio();
DBG("Adaptive jitter buffer activated\n");
}
else {
session->lockAudio();
m_playout_type = type;
if (fmt.get())
playout_buffer.reset(new AmPlayoutBuffer(this,getSampleRate()));
session->unlockAudio();
DBG("Simple playout buffer activated\n");
}
{
if (type == ADAPTIVE_PLAYOUT) {
m_playout_type = type;
if (fmt.get())
playout_buffer.reset(new AmAdaptivePlayout(this,getSampleRate()));
DBG("Adaptive playout buffer activated\n");
}
else if (type == JB_PLAYOUT) {
m_playout_type = type;
if (fmt.get())
playout_buffer.reset(new AmJbPlayout(this,getSampleRate()));
DBG("Adaptive jitter buffer activated\n");
}
else {
m_playout_type = type;
if (fmt.get())
playout_buffer.reset(new AmPlayoutBuffer(this,getSampleRate()));
DBG("Simple playout buffer activated\n");
}
}
session->unlockAudio();
}

Loading…
Cancel
Save