Commit db771a00 authored by Éloi Bail's avatar Éloi Bail

rtp: ensure to synchronously update seq number

When bitrate is changed, new RTP session created must rely
on RTP sequence of previous RTP session in order to provide
continous sequence numbers.
This patchset ensures to keep last RTP sequence updated correctly
ensuring that no new packet will be sent when bitrate change is performed.

Issue: #80058
Change-Id: Ia7fbecd19aa0ec648327307de3ce3f8eace163a0
Signed-off-by: Guillaume Roguez's avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent 549fd8fc
......@@ -382,7 +382,14 @@ AudioRtpSession::startSender()
if (sender_)
RING_WARN("Restarting audio sender");
// be sure to not send any packets before saving last RTP seq value
socketPair_->stopSendOp();
if (sender_)
initSeqVal_ = sender_->getLastSeqValue() + 1;
try {
sender_.reset();
socketPair_->stopSendOp(false);
sender_.reset(new AudioSender(callID_, getRemoteRtpUri(), send_,
*socketPair_, initSeqVal_));
} catch (const MediaEncoderException &e) {
......@@ -395,9 +402,6 @@ void
AudioRtpSession::restartSender()
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
// continue on last sequence number
initSeqVal_ = sender_->getLastSeqValue() + 1;
startSender();
}
......
......@@ -260,6 +260,12 @@ SocketPair::interrupt()
cv_.notify_all();
}
void
SocketPair::stopSendOp(bool state)
{
noWrite_ = state;
}
void
SocketPair::closeSockets()
{
......@@ -463,10 +469,15 @@ SocketPair::writeData(uint8_t* buf, int buf_size)
if (ret < 0)
return ret;
if (noWrite_)
return buf_size;
return sendto(fd, reinterpret_cast<const char*>(buf), buf_size, 0,
reinterpret_cast<sockaddr*>(&dest_addr), dest_addr_len);
}
if (noWrite_)
return buf_size;
// IceSocket
if (isRTCP)
return rtcp_sock_->send(buf, buf_size);
......
......@@ -93,6 +93,8 @@ class SocketPair {
void createSRTP(const char* out_suite, const char* out_params,
const char* in_suite, const char* in_params);
void stopSendOp(bool state = true);
private:
NON_COPYABLE(SocketPair);
......@@ -119,6 +121,7 @@ class SocketPair {
sockaddr_storage rtcpDestAddr_;
socklen_t rtcpDestAddrLen_;
std::atomic_bool interrupted_ {false};
std::atomic_bool noWrite_ {false};
std::unique_ptr<SRTPProtoContext> srtpContext_;
};
......
......@@ -89,11 +89,16 @@ void VideoRtpSession::startSender()
}
}
// be sure to not send any packets before saving last RTP seq value
socketPair_->stopSendOp();
if (sender_)
initSeqVal_ = sender_->getLastSeqValue() + 1;
try {
sender_.reset(
new VideoSender(getRemoteRtpUri(), localVideoParams_,
send_, *socketPair_, initSeqVal_)
);
sender_.reset();
socketPair_->stopSendOp(false);
sender_.reset(new VideoSender(getRemoteRtpUri(), localVideoParams_,
send_, *socketPair_, initSeqVal_));
} catch (const MediaEncoderException &e) {
RING_ERR("%s", e.what());
send_.enabled = false;
......@@ -106,8 +111,6 @@ VideoRtpSession::restartSender()
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
// continue on last sequence number
initSeqVal_ = sender_->getLastSeqValue() + 1;
startSender();
if (sender_) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment