From be2e5f78b3498858cd8694fa6d00a28ba8093f26 Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Fri, 6 Sep 2019 16:26:02 -0700 Subject: [PATCH] Make payload type demux conditional on media direction Bug: webrtc:10139 Change-Id: I6803f4325e7c34915a9ae79e3360a787a7a9df5c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/149173 Reviewed-by: Steve Anton Commit-Queue: Steve Anton Cr-Commit-Position: refs/heads/master@{#29105} --- pc/channel.cc | 58 ++++++++++++++++++++++++++++++++++++++------------- pc/channel.h | 2 ++ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/pc/channel.cc b/pc/channel.cc index caf8c93956..95be5b65fb 100644 --- a/pc/channel.cc +++ b/pc/channel.cc @@ -770,6 +770,10 @@ void BaseChannel::AddHandledPayloadType(int payload_type) { demuxer_criteria_.payload_types.insert(static_cast(payload_type)); } +void BaseChannel::ClearHandledPayloadTypes() { + demuxer_criteria_.payload_types.clear(); +} + void BaseChannel::FlushRtcpMessages_n() { // Flush all remaining RTCP messages. This should only be called in // destructor. @@ -889,13 +893,16 @@ bool VoiceChannel::SetLocalContent_w(const MediaContentDescription* content, error_desc); return false; } - for (const AudioCodec& codec : audio->codecs()) { - AddHandledPayloadType(codec.id); - } - // Need to re-register the sink to update the handled payload. - if (!RegisterRtpDemuxerSink()) { - RTC_LOG(LS_ERROR) << "Failed to set up audio demuxing."; - return false; + + if (webrtc::RtpTransceiverDirectionHasRecv(audio->direction())) { + for (const AudioCodec& codec : audio->codecs()) { + AddHandledPayloadType(codec.id); + } + // Need to re-register the sink to update the handled payload. + if (!RegisterRtpDemuxerSink()) { + RTC_LOG(LS_ERROR) << "Failed to set up audio demuxing."; + return false; + } } last_recv_params_ = recv_params; @@ -945,6 +952,16 @@ bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content, } last_send_params_ = send_params; + if (!webrtc::RtpTransceiverDirectionHasSend(content->direction())) { + RTC_DLOG(LS_VERBOSE) << "SetRemoteContent_w: remote side will not send - " + "disable payload type demuxing"; + ClearHandledPayloadTypes(); + if (!RegisterRtpDemuxerSink()) { + RTC_LOG(LS_ERROR) << "Failed to update audio demuxing."; + return false; + } + } + // TODO(pthatcher): Move remote streams into AudioRecvParameters, // and only give it to the media channel once we have a local // description too (without a local description, we won't be able to @@ -1047,13 +1064,16 @@ bool VideoChannel::SetLocalContent_w(const MediaContentDescription* content, error_desc); return false; } - for (const VideoCodec& codec : video->codecs()) { - AddHandledPayloadType(codec.id); - } - // Need to re-register the sink to update the handled payload. - if (!RegisterRtpDemuxerSink()) { - RTC_LOG(LS_ERROR) << "Failed to set up video demuxing."; - return false; + + if (webrtc::RtpTransceiverDirectionHasRecv(video->direction())) { + for (const VideoCodec& codec : video->codecs()) { + AddHandledPayloadType(codec.id); + } + // Need to re-register the sink to update the handled payload. + if (!RegisterRtpDemuxerSink()) { + RTC_LOG(LS_ERROR) << "Failed to set up video demuxing."; + return false; + } } last_recv_params_ = recv_params; @@ -1140,6 +1160,16 @@ bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, last_recv_params_ = recv_params; } + if (!webrtc::RtpTransceiverDirectionHasSend(content->direction())) { + RTC_DLOG(LS_VERBOSE) << "SetRemoteContent_w: remote side will not send - " + "disable payload type demuxing"; + ClearHandledPayloadTypes(); + if (!RegisterRtpDemuxerSink()) { + RTC_LOG(LS_ERROR) << "Failed to update video demuxing."; + return false; + } + } + // TODO(pthatcher): Move remote streams into VideoRecvParameters, // and only give it to the media channel once we have a local // description too (without a local description, we won't be able to diff --git a/pc/channel.h b/pc/channel.h index 8a75a1a5f3..5222d98eed 100644 --- a/pc/channel.h +++ b/pc/channel.h @@ -281,6 +281,8 @@ class BaseChannel : public ChannelInterface, void AddHandledPayloadType(int payload_type); + void ClearHandledPayloadTypes(); + void UpdateRtpHeaderExtensionMap( const RtpHeaderExtensions& header_extensions);