multiplex: Fix bug when using pull_frame

This commit is contained in:
Heikki Tampio 2023-07-07 08:08:02 +03:00
parent 3c15f0ef31
commit 8e60377657
1 changed files with 22 additions and 23 deletions

View File

@ -182,15 +182,8 @@ rtp_error_t uvgrtp::reception_flow::install_receive_hook(
return RTP_INVALID_VALUE; return RTP_INVALID_VALUE;
// ssrc 0 is used when streams are not multiplexed into a single socket // ssrc 0 is used when streams are not multiplexed into a single socket
if (hooks_.find(remote_ssrc) == hooks_.end()) { receive_pkt_hook new_hook = { arg, hook };
receive_pkt_hook new_hook = { arg, hook }; hooks_[remote_ssrc] = new_hook;
hooks_[remote_ssrc] = new_hook;
}
else {
receive_pkt_hook new_hook = { arg, hook };
hooks_.erase(remote_ssrc);
hooks_.insert({remote_ssrc, new_hook});
}
return RTP_OK; return RTP_OK;
} }
@ -204,10 +197,12 @@ uvgrtp::frame::rtp_frame *uvgrtp::reception_flow::pull_frame()
if (should_stop_) if (should_stop_)
return nullptr; return nullptr;
uvgrtp::frame::rtp_frame* frame = nullptr;
frames_mtx_.lock(); frames_mtx_.lock();
auto frame = frames_.front(); if (!frames_.empty()) {
frames_.erase(frames_.begin()); frame = frames_.front();
frames_.erase(frames_.begin());
}
frames_mtx_.unlock(); frames_mtx_.unlock();
return frame; return frame;
@ -226,10 +221,12 @@ uvgrtp::frame::rtp_frame *uvgrtp::reception_flow::pull_frame(ssize_t timeout_ms)
if (should_stop_ || frames_.empty()) if (should_stop_ || frames_.empty())
return nullptr; return nullptr;
uvgrtp::frame::rtp_frame* frame = nullptr;
frames_mtx_.lock(); frames_mtx_.lock();
auto frame = frames_.front(); if (!frames_.empty()) {
frames_.pop_front(); frame = frames_.front();
frames_.pop_front();
}
frames_mtx_.unlock(); frames_mtx_.unlock();
return frame; return frame;
@ -725,13 +722,15 @@ rtp_error_t uvgrtp::reception_flow::update_remote_ssrc(uint32_t old_remote_ssrc,
{ {
std::lock_guard<std::mutex> hlg(hooks_mutex_); std::lock_guard<std::mutex> hlg(hooks_mutex_);
std::lock_guard<std::mutex> halg(handlers_mutex_); std::lock_guard<std::mutex> halg(handlers_mutex_);
if (packet_handlers_.find(old_remote_ssrc) != packet_handlers_.end()) {
handler handlers = packet_handlers_[old_remote_ssrc]; handler handlers = packet_handlers_[old_remote_ssrc];
packet_handlers_.erase(old_remote_ssrc); packet_handlers_.erase(old_remote_ssrc);
packet_handlers_.insert({new_remote_ssrc, handlers}); packet_handlers_.insert({new_remote_ssrc, handlers});
}
receive_pkt_hook hook = hooks_[old_remote_ssrc]; if (hooks_.find(old_remote_ssrc) != hooks_.end()) {
hooks_.erase(old_remote_ssrc); receive_pkt_hook hook = hooks_[old_remote_ssrc];
hooks_.insert({new_remote_ssrc, hook}); hooks_.erase(old_remote_ssrc);
hooks_.insert({new_remote_ssrc, hook});
}
return RTP_OK; return RTP_OK;
} }