diff options
author | Johannes Kron <kron@webrtc.org> | 2020-03-29 22:17:00 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-03-29 21:03:27 +0000 |
commit | 3e98368ec5f8161fff9c02148675256a81a235fd (patch) | |
tree | daeae1bb99ed550efa76b803d3c63001fa5f9be9 /pc/media_session.cc | |
parent | 8e1824a0d12f6a9806fed9e99b1138cb3ea19eb6 (diff) | |
download | webrtc-3e98368ec5f8161fff9c02148675256a81a235fd.tar.gz |
Reland "Distinguish between send and receive codecs"
This reverts commit 8e8b36a94a7a7a1fd0f8093979a406afa56e18c1.
Reason for revert: The CL has been improved with the following changes,
- Fixed negotiation of send/receive only clients.
- Handles the implicit assumption that any H264 decoder also can
decode H264 constraint baseline.
Original change's description:
> Distinguish between send and receive codecs
>
> Even though send and receive codecs may be the same, they might have
> different support in HW. Distinguish between send and receive codecs
> to be able to keep track of which codecs have HW support.
>
> Bug: chromium:1029737
> Change-Id: Id119560becadfe0aaf861c892a6485f1c2eb378d
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/165763
> Commit-Queue: Johannes Kron <kron@webrtc.org>
> Reviewed-by: Steve Anton <steveanton@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#30284}
Change-Id: I834ed48ee78d04922c73e2836165e476925e1cc5
Bug: chromium:1029737
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168605
Commit-Queue: Johannes Kron <kron@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Johannes Kron <kron@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30932}
Diffstat (limited to 'pc/media_session.cc')
-rw-r--r-- | pc/media_session.cc | 170 |
1 files changed, 137 insertions, 33 deletions
diff --git a/pc/media_session.cc b/pc/media_session.cc index 2f57e61d08..a9c523d430 100644 --- a/pc/media_session.cc +++ b/pc/media_session.cc @@ -1367,11 +1367,13 @@ MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( channel_manager->GetSupportedAudioReceiveCodecs(&audio_recv_codecs_); audio_rtp_extensions_ = channel_manager->GetDefaultEnabledAudioRtpHeaderExtensions(); - channel_manager->GetSupportedVideoCodecs(&video_codecs_); + channel_manager->GetSupportedVideoSendCodecs(&video_send_codecs_); + channel_manager->GetSupportedVideoReceiveCodecs(&video_recv_codecs_); video_rtp_extensions_ = channel_manager->GetDefaultEnabledVideoRtpHeaderExtensions(); channel_manager->GetSupportedDataCodecs(&rtp_data_codecs_); ComputeAudioCodecsIntersectionAndUnion(); + ComputeVideoCodecsIntersectionAndUnion(); } const AudioCodecs& MediaSessionDescriptionFactory::audio_sendrecv_codecs() @@ -1395,6 +1397,27 @@ void MediaSessionDescriptionFactory::set_audio_codecs( ComputeAudioCodecsIntersectionAndUnion(); } +const VideoCodecs& MediaSessionDescriptionFactory::video_sendrecv_codecs() + const { + return video_sendrecv_codecs_; +} + +const VideoCodecs& MediaSessionDescriptionFactory::video_send_codecs() const { + return video_send_codecs_; +} + +const VideoCodecs& MediaSessionDescriptionFactory::video_recv_codecs() const { + return video_recv_codecs_; +} + +void MediaSessionDescriptionFactory::set_video_codecs( + const VideoCodecs& send_codecs, + const VideoCodecs& recv_codecs) { + video_send_codecs_ = send_codecs; + video_recv_codecs_ = recv_codecs; + ComputeVideoCodecsIntersectionAndUnion(); +} + static void RemoveUnifiedPlanExtensions(RtpHeaderExtensions* extensions) { RTC_DCHECK(extensions); @@ -1777,6 +1800,43 @@ const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForAnswer( } } +const VideoCodecs& MediaSessionDescriptionFactory::GetVideoCodecsForOffer( + const RtpTransceiverDirection& direction) const { + switch (direction) { + // If stream is inactive - generate list as if sendrecv. + case RtpTransceiverDirection::kSendRecv: + case RtpTransceiverDirection::kInactive: + return video_sendrecv_codecs_; + case RtpTransceiverDirection::kSendOnly: + return video_send_codecs_; + case RtpTransceiverDirection::kRecvOnly: + return video_recv_codecs_; + case RtpTransceiverDirection::kStopped: + RTC_NOTREACHED(); + return video_sendrecv_codecs_; + } +} + +const VideoCodecs& MediaSessionDescriptionFactory::GetVideoCodecsForAnswer( + const RtpTransceiverDirection& offer, + const RtpTransceiverDirection& answer) const { + switch (answer) { + // For inactive and sendrecv answers, generate lists as if we were to accept + // the offer's direction. See RFC 3264 Section 6.1. + case RtpTransceiverDirection::kSendRecv: + case RtpTransceiverDirection::kInactive: + return GetVideoCodecsForOffer( + webrtc::RtpTransceiverDirectionReversed(offer)); + case RtpTransceiverDirection::kSendOnly: + return video_send_codecs_; + case RtpTransceiverDirection::kRecvOnly: + return video_recv_codecs_; + case RtpTransceiverDirection::kStopped: + RTC_NOTREACHED(); + return video_sendrecv_codecs_; + } +} + void MergeCodecsFromDescription( const std::vector<const ContentInfo*>& current_active_contents, AudioCodecs* audio_codecs, @@ -1824,7 +1884,7 @@ void MediaSessionDescriptionFactory::GetCodecsForOffer( // Add our codecs that are not in the current description. MergeCodecs<AudioCodec>(all_audio_codecs_, audio_codecs, &used_pltypes); - MergeCodecs<VideoCodec>(video_codecs_, video_codecs, &used_pltypes); + MergeCodecs<VideoCodec>(all_video_codecs_, video_codecs, &used_pltypes); MergeCodecs<DataCodec>(rtp_data_codecs_, rtp_data_codecs, &used_pltypes); } @@ -1872,7 +1932,7 @@ void MediaSessionDescriptionFactory::GetCodecsForAnswer( if (!FindMatchingCodec<VideoCodec>(video->codecs(), filtered_offered_video_codecs, offered_video_codec, nullptr) && - FindMatchingCodec<VideoCodec>(video->codecs(), video_codecs_, + FindMatchingCodec<VideoCodec>(video->codecs(), all_video_codecs_, offered_video_codec, nullptr)) { filtered_offered_video_codecs.push_back(offered_video_codec); } @@ -2079,7 +2139,7 @@ bool MediaSessionDescriptionFactory::AddAudioContentForOffer( IsDtlsActive(current_content, current_description) ? cricket::SEC_DISABLED : secure(); - std::unique_ptr<AudioContentDescription> audio(new AudioContentDescription()); + auto audio = std::make_unique<AudioContentDescription>(); std::vector<std::string> crypto_suites; GetSupportedAudioSdesCryptoSuiteNames(session_options.crypto_options, &crypto_suites); @@ -2107,6 +2167,8 @@ bool MediaSessionDescriptionFactory::AddAudioContentForOffer( return true; } +// TODO(kron): This function is very similar to AddAudioContentForOffer. +// Refactor to reuse shared code. bool MediaSessionDescriptionFactory::AddVideoContentForOffer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, @@ -2117,14 +2179,10 @@ bool MediaSessionDescriptionFactory::AddVideoContentForOffer( StreamParamsVec* current_streams, SessionDescription* desc, IceCredentialsIterator* ice_credentials) const { - cricket::SecurePolicy sdes_policy = - IsDtlsActive(current_content, current_description) ? cricket::SEC_DISABLED - : secure(); - - std::unique_ptr<VideoContentDescription> video(new VideoContentDescription()); - std::vector<std::string> crypto_suites; - GetSupportedVideoSdesCryptoSuiteNames(session_options.crypto_options, - &crypto_suites); + // Filter video_codecs (which includes all codecs, with correctly remapped + // payload types) based on transceiver direction. + const VideoCodecs& supported_video_codecs = + GetVideoCodecsForOffer(media_description_options.direction); VideoCodecs filtered_codecs; @@ -2132,7 +2190,7 @@ bool MediaSessionDescriptionFactory::AddVideoContentForOffer( // Add the codecs from the current transceiver's codec preferences. // They override any existing codecs from previous negotiations. filtered_codecs = MatchCodecPreference( - media_description_options.codec_preferences, video_codecs_); + media_description_options.codec_preferences, supported_video_codecs); } else { // Add the codecs from current content if it exists and is not rejected nor // recycled. @@ -2150,11 +2208,11 @@ bool MediaSessionDescriptionFactory::AddVideoContentForOffer( } // Add other supported video codecs. VideoCodec found_codec; - for (const VideoCodec& codec : video_codecs_) { - if (FindMatchingCodec<VideoCodec>(video_codecs_, video_codecs, codec, - &found_codec) && - !FindMatchingCodec<VideoCodec>(video_codecs_, filtered_codecs, codec, - nullptr)) { + for (const VideoCodec& codec : supported_video_codecs) { + if (FindMatchingCodec<VideoCodec>(supported_video_codecs, video_codecs, + codec, &found_codec) && + !FindMatchingCodec<VideoCodec>(supported_video_codecs, + filtered_codecs, codec, nullptr)) { // Use the |found_codec| from |video_codecs| because it has the // correctly mapped payload type. filtered_codecs.push_back(found_codec); @@ -2170,6 +2228,13 @@ bool MediaSessionDescriptionFactory::AddVideoContentForOffer( } } + cricket::SecurePolicy sdes_policy = + IsDtlsActive(current_content, current_description) ? cricket::SEC_DISABLED + : secure(); + auto video = std::make_unique<VideoContentDescription>(); + std::vector<std::string> crypto_suites; + GetSupportedVideoSdesCryptoSuiteNames(session_options.crypto_options, + &crypto_suites); if (!CreateMediaContentOffer(media_description_options, session_options, filtered_codecs, sdes_policy, GetCryptos(current_content), crypto_suites, @@ -2192,6 +2257,7 @@ bool MediaSessionDescriptionFactory::AddVideoContentForOffer( current_description, desc, ice_credentials)) { return false; } + return true; } @@ -2203,8 +2269,7 @@ bool MediaSessionDescriptionFactory::AddSctpDataContentForOffer( StreamParamsVec* current_streams, SessionDescription* desc, IceCredentialsIterator* ice_credentials) const { - std::unique_ptr<SctpDataContentDescription> data( - new SctpDataContentDescription()); + auto data = std::make_unique<SctpDataContentDescription>(); bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); @@ -2250,8 +2315,7 @@ bool MediaSessionDescriptionFactory::AddRtpDataContentForOffer( StreamParamsVec* current_streams, SessionDescription* desc, IceCredentialsIterator* ice_credentials) const { - std::unique_ptr<RtpDataContentDescription> data( - new RtpDataContentDescription()); + auto data = std::make_unique<RtpDataContentDescription>(); bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); cricket::SecurePolicy sdes_policy = @@ -2391,8 +2455,7 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( bool bundle_enabled = offer_description->HasGroup(GROUP_TYPE_BUNDLE) && session_options.bundle_enabled; - std::unique_ptr<AudioContentDescription> audio_answer( - new AudioContentDescription()); + auto audio_answer = std::make_unique<AudioContentDescription>(); // Do not require or create SDES cryptos if DTLS is used. cricket::SecurePolicy sdes_policy = audio_transport->secure() ? cricket::SEC_DISABLED : secure(); @@ -2432,6 +2495,8 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( return true; } +// TODO(kron): This function is very similar to AddAudioContentForAnswer. +// Refactor to reuse shared code. bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( const MediaDescriptionOptions& media_description_options, const MediaSessionOptions& session_options, @@ -2456,11 +2521,20 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( return false; } + // Pick codecs based on the requested communications direction in the offer + // and the selected direction in the answer. + // Note these will be filtered one final time in CreateMediaContentAnswer. + auto wants_rtd = media_description_options.direction; + auto offer_rtd = offer_video_description->direction(); + auto answer_rtd = NegotiateRtpTransceiverDirection(offer_rtd, wants_rtd); + VideoCodecs supported_video_codecs = + GetVideoCodecsForAnswer(offer_rtd, answer_rtd); + VideoCodecs filtered_codecs; if (!media_description_options.codec_preferences.empty()) { filtered_codecs = MatchCodecPreference( - media_description_options.codec_preferences, video_codecs_); + media_description_options.codec_preferences, supported_video_codecs); } else { // Add the codecs from current content if it exists and is not rejected nor // recycled. @@ -2477,11 +2551,11 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( } } // Add other supported video codecs. - for (const VideoCodec& codec : video_codecs_) { - if (FindMatchingCodec<VideoCodec>(video_codecs_, video_codecs, codec, - nullptr) && - !FindMatchingCodec<VideoCodec>(video_codecs_, filtered_codecs, codec, - nullptr)) { + for (const VideoCodec& codec : supported_video_codecs) { + if (FindMatchingCodec<VideoCodec>(supported_video_codecs, video_codecs, + codec, nullptr) && + !FindMatchingCodec<VideoCodec>(supported_video_codecs, + filtered_codecs, codec, nullptr)) { // We should use the local codec with local parameters and the codec id // would be correctly mapped in |NegotiateCodecs|. filtered_codecs.push_back(codec); @@ -2499,9 +2573,7 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( bool bundle_enabled = offer_description->HasGroup(GROUP_TYPE_BUNDLE) && session_options.bundle_enabled; - - std::unique_ptr<VideoContentDescription> video_answer( - new VideoContentDescription()); + auto video_answer = std::make_unique<VideoContentDescription>(); // Do not require or create SDES cryptos if DTLS is used. cricket::SecurePolicy sdes_policy = video_transport->secure() ? cricket::SEC_DISABLED : secure(); @@ -2671,6 +2743,38 @@ void MediaSessionDescriptionFactory::ComputeAudioCodecsIntersectionAndUnion() { &audio_sendrecv_codecs_, true); } +void MediaSessionDescriptionFactory::ComputeVideoCodecsIntersectionAndUnion() { + video_sendrecv_codecs_.clear(); + all_video_codecs_.clear(); + // Compute the video codecs union. + for (const VideoCodec& send : video_send_codecs_) { + all_video_codecs_.push_back(send); + if (!FindMatchingCodec<VideoCodec>(video_send_codecs_, video_recv_codecs_, + send, nullptr)) { + // TODO(kron): This check is violated by the unit test: + // MediaSessionDescriptionFactoryTest.RtxWithoutApt + // Remove either the test or the check. + + // It doesn't make sense to have an RTX codec we support sending but not + // receiving. + // RTC_DCHECK(!IsRtxCodec(send)); + } + } + for (const VideoCodec& recv : video_recv_codecs_) { + if (!FindMatchingCodec<VideoCodec>(video_recv_codecs_, video_send_codecs_, + recv, nullptr)) { + all_video_codecs_.push_back(recv); + } + } + // Use NegotiateCodecs to merge our codec lists, since the operation is + // essentially the same. Put send_codecs as the offered_codecs, which is the + // order we'd like to follow. The reasoning is that encoding is usually more + // expensive than decoding, and prioritizing a codec in the send list probably + // means it's a codec we can handle efficiently. + NegotiateCodecs(video_recv_codecs_, video_send_codecs_, + &video_sendrecv_codecs_, true); +} + bool IsMediaContent(const ContentInfo* content) { return (content && (content->type == MediaProtocolType::kRtp || content->type == MediaProtocolType::kSctp)); |