From f1234c9cce6a6eeb14fe4e835da461348fbca6f3 Mon Sep 17 00:00:00 2001 From: "Byron Campen [:bwc]" Date: Wed, 4 Jan 2023 21:23:20 +0000 Subject: [PATCH] Bug 1808053: Throw if a non-rejected answer msection contains no codec in common with offer. r=mjf Differential Revision: https://phabricator.services.mozilla.com/D165993 --- dom/media/webrtc/jsep/JsepSessionImpl.cpp | 14 ++++++++++++-- dom/media/webrtc/jsep/JsepTrack.cpp | 11 ++++++++--- dom/media/webrtc/jsep/JsepTrack.h | 6 +++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/dom/media/webrtc/jsep/JsepSessionImpl.cpp b/dom/media/webrtc/jsep/JsepSessionImpl.cpp index 732834c523d7..754de9c8fc5b 100644 --- a/dom/media/webrtc/jsep/JsepSessionImpl.cpp +++ b/dom/media/webrtc/jsep/JsepSessionImpl.cpp @@ -1172,11 +1172,21 @@ nsresult JsepSessionImpl::MakeNegotiatedTransceiver( NS_ENSURE_SUCCESS(rv, rv); transceiver->mSendTrack.SetActive(sending); - transceiver->mSendTrack.Negotiate(answer, remote, local); + rv = transceiver->mSendTrack.Negotiate(answer, remote, local); + if (NS_FAILED(rv)) { + JSEP_SET_ERROR("Answer had no codecs in common with offer in m-section " + << local.GetLevel()); + return rv; + } JsepTrack& recvTrack = transceiver->mRecvTrack; recvTrack.SetActive(receiving); - recvTrack.Negotiate(answer, remote, local); + rv = recvTrack.Negotiate(answer, remote, local); + if (NS_FAILED(rv)) { + JSEP_SET_ERROR("Answer had no codecs in common with offer in m-section " + << local.GetLevel()); + return rv; + } if (transceiver->HasBundleLevel() && recvTrack.GetSsrcs().empty() && recvTrack.GetMediaType() != SdpMediaSection::kApplication) { diff --git a/dom/media/webrtc/jsep/JsepTrack.cpp b/dom/media/webrtc/jsep/JsepTrack.cpp index f1e0301fdd90..d6715f8d5611 100644 --- a/dom/media/webrtc/jsep/JsepTrack.cpp +++ b/dom/media/webrtc/jsep/JsepTrack.cpp @@ -576,12 +576,16 @@ std::vector> JsepTrack::NegotiateCodecs( return negotiatedCodecs; } -void JsepTrack::Negotiate(const SdpMediaSection& answer, - const SdpMediaSection& remote, - const SdpMediaSection& local) { +nsresult JsepTrack::Negotiate(const SdpMediaSection& answer, + const SdpMediaSection& remote, + const SdpMediaSection& local) { std::vector> negotiatedCodecs = NegotiateCodecs(remote, &answer != &remote, SomeRef(local)); + if (negotiatedCodecs.empty()) { + return NS_ERROR_FAILURE; + } + UniquePtr negotiatedDetails = MakeUnique(); @@ -603,6 +607,7 @@ void JsepTrack::Negotiate(const SdpMediaSection& answer, mInHaveRemote = false; mNegotiatedDetails = std::move(negotiatedDetails); + return NS_OK; } // When doing bundle, if all else fails we can try to figure out which m-line a diff --git a/dom/media/webrtc/jsep/JsepTrack.h b/dom/media/webrtc/jsep/JsepTrack.h index 32c2bb13eb31..5fe3c9724c5f 100644 --- a/dom/media/webrtc/jsep/JsepTrack.h +++ b/dom/media/webrtc/jsep/JsepTrack.h @@ -200,9 +200,9 @@ class JsepTrack { SsrcGenerator& ssrcGenerator, SdpMediaSection* answer); - virtual void Negotiate(const SdpMediaSection& answer, - const SdpMediaSection& remote, - const SdpMediaSection& local); + virtual nsresult Negotiate(const SdpMediaSection& answer, + const SdpMediaSection& remote, + const SdpMediaSection& local); static void SetUniquePayloadTypes(std::vector& tracks); virtual void GetNegotiatedPayloadTypes( std::vector* payloadTypes) const;