Unlock the RtcpHandler lock before calling the handler

This commit is contained in:
Staz M
2021-01-24 20:56:40 -05:00
parent ce7bd9f4d0
commit c639174f39

View File

@ -64,7 +64,9 @@ bool Track::send(message_variant data) {
std::shared_lock lock(mRtcpHandlerMutex); std::shared_lock lock(mRtcpHandlerMutex);
if (mRtcpHandler) { if (mRtcpHandler) {
message = mRtcpHandler->outgoing(message); auto copy = mRtcpHandler;
lock.unlock();
message = copy->outgoing(message);
if (!message) if (!message)
return false; return false;
} }
@ -125,7 +127,9 @@ void Track::incoming(message_ptr message) {
std::shared_lock lock(mRtcpHandlerMutex); std::shared_lock lock(mRtcpHandlerMutex);
if (mRtcpHandler) { if (mRtcpHandler) {
message = mRtcpHandler->incoming(message); auto copy = mRtcpHandler;
lock.unlock();
message = copy->incoming(message);
if (!message) if (!message)
return; return;
} }
@ -163,14 +167,20 @@ bool Track::outgoing([[maybe_unused]] message_ptr message) {
void Track::setRtcpHandler(std::shared_ptr<RtcpHandler> handler) { void Track::setRtcpHandler(std::shared_ptr<RtcpHandler> handler) {
std::unique_lock lock(mRtcpHandlerMutex); std::unique_lock lock(mRtcpHandlerMutex);
mRtcpHandler = std::move(handler); mRtcpHandler = std::move(handler);
if (mRtcpHandler) if (mRtcpHandler) {
mRtcpHandler->onOutgoing(std::bind(&Track::outgoing, this, std::placeholders::_1)); auto copy = mRtcpHandler;
lock.unlock();
copy->onOutgoing(std::bind(&Track::outgoing, this, std::placeholders::_1));
}
} }
bool Track::requestKeyframe() { bool Track::requestKeyframe() {
std::shared_lock lock(mRtcpHandlerMutex); std::shared_lock lock(mRtcpHandlerMutex);
if (mRtcpHandler) if (mRtcpHandler) {
return mRtcpHandler->requestKeyframe(); auto copy = mRtcpHandler;
lock.unlock();
return copy->requestKeyframe();
}
return false; return false;
} }