Moves locking outside function in RtpSender.

This CL moves the action of acquiring the lock outside
UpdateTransportSequenceNumber. This prepares for an upcoming CL where
the lock is used outside this call at the call sites and avoids the lock-unlock
overhead that would otherwise occur.

Also removing the const declaration as it modifies the state of
transport_sequence_number_allocator_.

Bug: webrtc:9796
Change-Id: I0bd4a0fd2fdbf6291867eb913690c61269eab8c5
Reviewed-on: https://webrtc-review.googlesource.com/c/102684
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25068}
This commit is contained in:
Sebastian Jansson
2018-10-09 18:27:36 +02:00
committed by Commit Bot
parent 789f459a06
commit 30e2d6ee00
2 changed files with 24 additions and 9 deletions

View File

@ -619,10 +619,13 @@ size_t RTPSender::SendPadData(size_t bytes,
PacketOptions options; PacketOptions options;
// Padding packets are never retransmissions. // Padding packets are never retransmissions.
options.is_retransmit = false; options.is_retransmit = false;
bool has_transport_seq_num = bool has_transport_seq_num;
UpdateTransportSequenceNumber(&padding_packet, &options.packet_id); {
rtc::CritScope lock(&send_critsect_);
has_transport_seq_num =
UpdateTransportSequenceNumber(&padding_packet, &options.packet_id);
}
padding_packet.SetPadding(padding_bytes_in_packet, &random_); padding_packet.SetPadding(padding_bytes_in_packet, &random_);
if (has_transport_seq_num) { if (has_transport_seq_num) {
AddPacketToTransportFeedback(options.packet_id, padding_packet, AddPacketToTransportFeedback(options.packet_id, padding_packet,
pacing_info); pacing_info);
@ -838,7 +841,13 @@ bool RTPSender::PrepareAndSendPacket(std::unique_ptr<RtpPacketToSend> packet,
// E.g. RTPSender::TrySendRedundantPayloads calls PrepareAndSendPacket with // E.g. RTPSender::TrySendRedundantPayloads calls PrepareAndSendPacket with
// send_over_rtx = true but is_retransmit = false. // send_over_rtx = true but is_retransmit = false.
options.is_retransmit = is_retransmit || send_over_rtx; options.is_retransmit = is_retransmit || send_over_rtx;
if (UpdateTransportSequenceNumber(packet_to_send, &options.packet_id)) { bool has_transport_seq_num;
{
rtc::CritScope lock(&send_critsect_);
has_transport_seq_num =
UpdateTransportSequenceNumber(packet_to_send, &options.packet_id);
}
if (has_transport_seq_num) {
AddPacketToTransportFeedback(options.packet_id, *packet_to_send, AddPacketToTransportFeedback(options.packet_id, *packet_to_send,
pacing_info); pacing_info);
} }
@ -971,7 +980,14 @@ bool RTPSender::SendToNetwork(std::unique_ptr<RtpPacketToSend> packet,
PacketOptions options; PacketOptions options;
options.is_retransmit = false; options.is_retransmit = false;
if (UpdateTransportSequenceNumber(packet.get(), &options.packet_id)) {
bool has_transport_seq_num;
{
rtc::CritScope lock(&send_critsect_);
has_transport_seq_num =
UpdateTransportSequenceNumber(packet.get(), &options.packet_id);
}
if (has_transport_seq_num) {
AddPacketToTransportFeedback(options.packet_id, *packet.get(), AddPacketToTransportFeedback(options.packet_id, *packet.get(),
PacedPacketInfo()); PacedPacketInfo());
} }
@ -1181,10 +1197,9 @@ bool RTPSender::AssignSequenceNumber(RtpPacketToSend* packet) {
} }
bool RTPSender::UpdateTransportSequenceNumber(RtpPacketToSend* packet, bool RTPSender::UpdateTransportSequenceNumber(RtpPacketToSend* packet,
int* packet_id) const { int* packet_id) {
RTC_DCHECK(packet); RTC_DCHECK(packet);
RTC_DCHECK(packet_id); RTC_DCHECK(packet_id);
rtc::CritScope lock(&send_critsect_);
if (!rtp_header_extension_map_.IsRegistered(TransportSequenceNumber::kId)) if (!rtp_header_extension_map_.IsRegistered(TransportSequenceNumber::kId))
return false; return false;

View File

@ -247,8 +247,8 @@ class RTPSender {
int64_t capture_time_ms, int64_t capture_time_ms,
uint32_t ssrc); uint32_t ssrc);
bool UpdateTransportSequenceNumber(RtpPacketToSend* packet, bool UpdateTransportSequenceNumber(RtpPacketToSend* packet, int* packet_id)
int* packet_id) const; RTC_EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
void UpdateRtpStats(const RtpPacketToSend& packet, void UpdateRtpStats(const RtpPacketToSend& packet,
bool is_rtx, bool is_rtx,