Index: webrtc/call/call.cc |
diff --git a/webrtc/call/call.cc b/webrtc/call/call.cc |
index e21b0762fe8429f21b87b38916c5c5b772ddb119..919bec54f713a2e6e91c8375b980e9420f2adafe 100644 |
--- a/webrtc/call/call.cc |
+++ b/webrtc/call/call.cc |
@@ -60,34 +60,6 @@ namespace webrtc { |
const int Call::Config::kDefaultStartBitrateBps = 300000; |
-namespace { |
- |
-// TODO(nisse): This really begs for a shared context struct. |
-bool UseSendSideBwe(const std::vector<RtpExtension>& extensions, |
- bool transport_cc) { |
- if (!transport_cc) |
- return false; |
- for (const auto& extension : extensions) { |
- if (extension.uri == RtpExtension::kTransportSequenceNumberUri) |
- return true; |
- } |
- return false; |
-} |
- |
-bool UseSendSideBwe(const VideoReceiveStream::Config& config) { |
- return UseSendSideBwe(config.rtp.extensions, config.rtp.transport_cc); |
-} |
- |
-bool UseSendSideBwe(const AudioReceiveStream::Config& config) { |
- return UseSendSideBwe(config.rtp.extensions, config.rtp.transport_cc); |
-} |
- |
-bool UseSendSideBwe(const FlexfecReceiveStream::Config& config) { |
- return UseSendSideBwe(config.rtp_header_extensions, config.transport_cc); |
-} |
- |
-} // namespace |
- |
namespace internal { |
class Call : public webrtc::Call, |
@@ -172,12 +144,8 @@ class Call : public webrtc::Call, |
EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
void NotifyBweOfReceivedPacket(const RtpPacketReceived& packet, |
- MediaType media_type) |
- SHARED_LOCKS_REQUIRED(receive_crit_); |
- |
- rtc::Optional<RtpPacketReceived> ParseRtpPacket(const uint8_t* packet, |
- size_t length, |
- const PacketTime& packet_time) |
+ MediaType media_type, |
+ bool use_send_side_bwe) |
SHARED_LOCKS_REQUIRED(receive_crit_); |
void UpdateSendHistograms() EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); |
@@ -218,30 +186,6 @@ class Call : public webrtc::Call, |
std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ |
GUARDED_BY(receive_crit_); |
- // This extra map is used for receive processing which is |
- // independent of media type. |
- |
- // TODO(nisse): In the RTP transport refactoring, we should have a |
- // single mapping from ssrc to a more abstract receive stream, with |
- // accessor methods for all configuration we need at this level. |
- struct ReceiveRtpConfig { |
- ReceiveRtpConfig() = default; // Needed by std::map |
- ReceiveRtpConfig(const std::vector<RtpExtension>& extensions, |
- bool use_send_side_bwe) |
- : extensions(extensions), use_send_side_bwe(use_send_side_bwe) {} |
- |
- // Registered RTP header extensions for each stream. Note that RTP header |
- // extensions are negotiated per track ("m= line") in the SDP, but we have |
- // no notion of tracks at the Call level. We therefore store the RTP header |
- // extensions per SSRC instead, which leads to some storage overhead. |
- RtpHeaderExtensionMap extensions; |
- // Set if both RTP extension the RTCP feedback message needed for |
- // send side BWE are negotiated. |
- bool use_send_side_bwe = false; |
- }; |
- std::map<uint32_t, ReceiveRtpConfig> receive_rtp_config_ |
- GUARDED_BY(receive_crit_); |
- |
std::unique_ptr<RWLockWrapper> send_crit_; |
// Audio and Video send streams are owned by the client that creates them. |
std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_); |
@@ -395,29 +339,6 @@ Call::~Call() { |
Trace::ReturnTrace(); |
} |
-rtc::Optional<RtpPacketReceived> Call::ParseRtpPacket( |
- const uint8_t* packet, |
- size_t length, |
- const PacketTime& packet_time) { |
- RtpPacketReceived parsed_packet; |
- if (!parsed_packet.Parse(packet, length)) |
- return rtc::Optional<RtpPacketReceived>(); |
- |
- auto it = receive_rtp_config_.find(parsed_packet.Ssrc()); |
- if (it != receive_rtp_config_.end()) |
- parsed_packet.IdentifyExtensions(it->second.extensions); |
- |
- int64_t arrival_time_ms; |
- if (packet_time.timestamp != -1) { |
- arrival_time_ms = (packet_time.timestamp + 500) / 1000; |
- } else { |
- arrival_time_ms = clock_->TimeInMilliseconds(); |
- } |
- parsed_packet.set_arrival_time_ms(arrival_time_ms); |
- |
- return rtc::Optional<RtpPacketReceived>(std::move(parsed_packet)); |
-} |
- |
void Call::UpdateHistograms() { |
RTC_HISTOGRAM_COUNTS_100000( |
"WebRTC.Call.LifetimeInSeconds", |
@@ -561,8 +482,6 @@ webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( |
RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
audio_receive_ssrcs_.end()); |
audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
- receive_rtp_config_[config.rtp.remote_ssrc] = |
- ReceiveRtpConfig(config.rtp.extensions, UseSendSideBwe(config)); |
ConfigureSync(config.sync_group); |
} |
@@ -589,7 +508,8 @@ void Call::DestroyAudioReceiveStream( |
WriteLockScoped write_lock(*receive_crit_); |
const AudioReceiveStream::Config& config = audio_receive_stream->config(); |
uint32_t ssrc = config.rtp.remote_ssrc; |
- congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config)) |
+ congestion_controller_->GetRemoteBitrateEstimator( |
+ audio_receive_stream->rtp_config().use_send_side_bwe) |
->RemoveStream(ssrc); |
size_t num_deleted = audio_receive_ssrcs_.erase(ssrc); |
RTC_DCHECK(num_deleted == 1); |
@@ -600,7 +520,6 @@ void Call::DestroyAudioReceiveStream( |
sync_stream_mapping_.erase(it); |
ConfigureSync(sync_group); |
} |
- receive_rtp_config_.erase(ssrc); |
} |
UpdateAggregateNetworkState(); |
delete audio_receive_stream; |
@@ -693,8 +612,6 @@ webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( |
call_stats_.get(), &remb_); |
const webrtc::VideoReceiveStream::Config& config = receive_stream->config(); |
- ReceiveRtpConfig receive_config(config.rtp.extensions, |
- UseSendSideBwe(config)); |
{ |
WriteLockScoped write_lock(*receive_crit_); |
RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
@@ -702,13 +619,7 @@ webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( |
video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
if (config.rtp.rtx_ssrc) { |
video_receive_ssrcs_[config.rtp.rtx_ssrc] = receive_stream; |
- // We record identical config for the rtx stream as for the main |
- // stream. Since the transport_cc negotiation is per payload |
- // type, we may get an incorrect value for the rtx stream, but |
- // that is unlikely to matter in practice. |
- receive_rtp_config_[config.rtp.rtx_ssrc] = receive_config; |
} |
- receive_rtp_config_[config.rtp.remote_ssrc] = receive_config; |
video_receive_streams_.insert(receive_stream); |
ConfigureSync(config.sync_group); |
} |
@@ -734,7 +645,6 @@ void Call::DestroyVideoReceiveStream( |
if (receive_stream_impl != nullptr) |
RTC_DCHECK(receive_stream_impl == it->second); |
receive_stream_impl = it->second; |
- receive_rtp_config_.erase(it->first); |
it = video_receive_ssrcs_.erase(it); |
} else { |
++it; |
@@ -746,7 +656,8 @@ void Call::DestroyVideoReceiveStream( |
} |
const VideoReceiveStream::Config& config = receive_stream_impl->config(); |
- congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config)) |
+ congestion_controller_->GetRemoteBitrateEstimator( |
+ receive_stream_impl->rtp_config().use_send_side_bwe) |
->RemoveStream(config.rtp.remote_ssrc); |
UpdateAggregateNetworkState(); |
@@ -776,11 +687,6 @@ FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( |
RTC_DCHECK(flexfec_receive_ssrcs_protection_.find(config.remote_ssrc) == |
flexfec_receive_ssrcs_protection_.end()); |
flexfec_receive_ssrcs_protection_[config.remote_ssrc] = receive_stream; |
- |
- RTC_DCHECK(receive_rtp_config_.find(config.remote_ssrc) == |
- receive_rtp_config_.end()); |
- receive_rtp_config_[config.remote_ssrc] = |
- ReceiveRtpConfig(config.rtp_header_extensions, UseSendSideBwe(config)); |
} |
// TODO(brandtr): Store config in RtcEventLog here. |
@@ -803,7 +709,6 @@ void Call::DestroyFlexfecReceiveStream(FlexfecReceiveStream* receive_stream) { |
const FlexfecReceiveStream::Config& config = |
receive_stream_impl->GetConfig(); |
uint32_t ssrc = config.remote_ssrc; |
- receive_rtp_config_.erase(ssrc); |
// Remove all SSRCs pointing to the FlexfecReceiveStreamImpl to be |
// destroyed. |
@@ -822,7 +727,8 @@ void Call::DestroyFlexfecReceiveStream(FlexfecReceiveStream* receive_stream) { |
++media_it; |
} |
- congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config)) |
+ congestion_controller_->GetRemoteBitrateEstimator( |
+ receive_stream_impl->rtp_config().use_send_side_bwe) |
->RemoveStream(ssrc); |
flexfec_receive_streams_.erase(receive_stream_impl); |
@@ -1180,69 +1086,71 @@ PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type, |
const PacketTime& packet_time) { |
TRACE_EVENT0("webrtc", "Call::DeliverRtp"); |
- ReadLockScoped read_lock(*receive_crit_); |
- // TODO(nisse): We should parse the RTP header only here, and pass |
- // on parsed_packet to the receive streams. |
- rtc::Optional<RtpPacketReceived> parsed_packet = |
- ParseRtpPacket(packet, length, packet_time); |
- |
- if (!parsed_packet) |
+ RtpPacketReceived parsed_packet; |
+ if (!parsed_packet.Parse(packet, length)) |
return DELIVERY_PACKET_ERROR; |
+ uint32_t ssrc = parsed_packet.Ssrc(); |
- NotifyBweOfReceivedPacket(*parsed_packet, media_type); |
+ ReadLockScoped read_lock(*receive_crit_); |
- uint32_t ssrc = parsed_packet->Ssrc(); |
+ // Look up receiver, so we can parse extensions properly. |
+ RtpPacketReceiver* receiver = nullptr; |
+ bool pass_to_flexfec = false; |
if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) { |
auto it = audio_receive_ssrcs_.find(ssrc); |
if (it != audio_receive_ssrcs_.end()) { |
received_bytes_per_second_counter_.Add(static_cast<int>(length)); |
received_audio_bytes_per_second_counter_.Add(static_cast<int>(length)); |
- auto status = it->second->DeliverRtp(packet, length, packet_time) |
- ? DELIVERY_OK |
- : DELIVERY_PACKET_ERROR; |
- if (status == DELIVERY_OK) |
- event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); |
- return status; |
+ receiver = it->second; |
} |
} |
- if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
+ if (!receiver && |
+ (media_type == MediaType::ANY || media_type == MediaType::VIDEO)) { |
auto it = video_receive_ssrcs_.find(ssrc); |
if (it != video_receive_ssrcs_.end()) { |
received_bytes_per_second_counter_.Add(static_cast<int>(length)); |
received_video_bytes_per_second_counter_.Add(static_cast<int>(length)); |
- // TODO(brandtr): Notify the BWE of received media packets here. |
- auto status = it->second->DeliverRtp(packet, length, packet_time) |
- ? DELIVERY_OK |
- : DELIVERY_PACKET_ERROR; |
- // Deliver media packets to FlexFEC subsystem. RTP header extensions need |
- // not be parsed, as FlexFEC is oblivious to the semantic meaning of the |
- // packet contents beyond the 12 byte RTP base header. The BWE is fed |
- // information about these media packets from the regular media pipeline. |
- if (parsed_packet) { |
- auto it_bounds = flexfec_receive_ssrcs_media_.equal_range(ssrc); |
- for (auto it = it_bounds.first; it != it_bounds.second; ++it) |
- it->second->AddAndProcessReceivedPacket(*parsed_packet); |
+ receiver = it->second; |
+ pass_to_flexfec = true; |
+ } else { |
+ auto it = flexfec_receive_ssrcs_protection_.find(ssrc); |
+ if (it != flexfec_receive_ssrcs_protection_.end()) { |
+ receiver = it->second; |
+ // TODO(nisse): Update received_bytes_per_second_counter_ ? |
} |
- if (status == DELIVERY_OK) |
- event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); |
- return status; |
} |
} |
- if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
- auto it = flexfec_receive_ssrcs_protection_.find(ssrc); |
- if (it != flexfec_receive_ssrcs_protection_.end()) { |
- if (parsed_packet) { |
- auto status = it->second->AddAndProcessReceivedPacket(*parsed_packet) |
- ? DELIVERY_OK |
- : DELIVERY_PACKET_ERROR; |
- if (status == DELIVERY_OK) |
- event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); |
- return status; |
- } |
- } |
+ if (!receiver) |
+ return DELIVERY_UNKNOWN_SSRC; |
+ |
+ parsed_packet.IdentifyExtensions(receiver->rtp_config().extensions); |
+ int64_t arrival_time_ms; |
+ if (packet_time.timestamp != -1) { |
+ arrival_time_ms = (packet_time.timestamp + 500) / 1000; |
+ } else { |
+ arrival_time_ms = clock_->TimeInMilliseconds(); |
+ } |
+ parsed_packet.set_arrival_time_ms(arrival_time_ms); |
+ |
+ NotifyBweOfReceivedPacket(parsed_packet, media_type, |
+ receiver->rtp_config().use_send_side_bwe); |
+ |
+ bool success = receiver->OnRtpPacket(parsed_packet); |
+ if (success) |
+ event_log_->LogRtpHeader(kIncomingPacket, media_type, packet, length); |
+ |
+ if (pass_to_flexfec) { |
+ // Deliver media packets to FlexFEC subsystem. RTP header extensions need |
+ // not be parsed, as FlexFEC is oblivious to the semantic meaning of the |
+ // packet contents beyond the 12 byte RTP base header. The BWE is fed |
+ // information about these media packets from the regular media pipeline. |
+ auto it_bounds = flexfec_receive_ssrcs_media_.equal_range(ssrc); |
+ for (auto it = it_bounds.first; it != it_bounds.second; ++it) |
+ it->second->OnRtpPacket(parsed_packet); |
} |
- return DELIVERY_UNKNOWN_SSRC; |
+ |
+ return success ? DELIVERY_OK : DELIVERY_PACKET_ERROR; |
} |
PacketReceiver::DeliveryStatus Call::DeliverPacket( |
@@ -1272,11 +1180,8 @@ bool Call::OnRecoveredPacket(const uint8_t* packet, size_t length) { |
} |
void Call::NotifyBweOfReceivedPacket(const RtpPacketReceived& packet, |
- MediaType media_type) { |
- auto it = receive_rtp_config_.find(packet.Ssrc()); |
- bool use_send_side_bwe = |
- (it != receive_rtp_config_.end()) && it->second.use_send_side_bwe; |
- |
+ MediaType media_type, |
+ bool use_send_side_bwe) { |
RTPHeader header; |
packet.GetHeader(&header); |