Skip to content

Commit a910191

Browse files
committed
Bug 1894137 - RTCRtpEncodingParameters.codec handling;r=dbaker,bwc
Differential Revision: https://phabricator.services.mozilla.com/D250589
1 parent 53169b1 commit a910191

File tree

3 files changed

+428
-7
lines changed

3 files changed

+428
-7
lines changed

dom/media/webrtc/jsapi/PeerConnectionImpl.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,38 @@ already_AddRefed<RTCRtpTransceiver> PeerConnectionImpl::AddTransceiver(
809809

810810
auto& sendEncodings = init.mSendEncodings;
811811

812+
// See https://www.w3.org/TR/webrtc/#dom-rtcrtpsender-setparameters step 11
813+
// Also see https://bugzilla.mozilla.org/show_bug.cgi?id=1968828
814+
auto getCapabilitiesResult = dom::Nullable<dom::RTCRtpCapabilities>();
815+
GetCapabilities(aKind, getCapabilitiesResult, sdp::Direction::kSend);
816+
MOZ_ASSERT(!getCapabilitiesResult.IsNull());
817+
if (NS_WARN_IF(getCapabilitiesResult.IsNull())) {
818+
aRv.Throw(NS_ERROR_FAILURE);
819+
return nullptr;
820+
}
821+
const auto& codecs = getCapabilitiesResult.Value().mCodecs;
822+
for (const auto& encoding : sendEncodings) {
823+
bool found = false;
824+
if (encoding.mCodec.WasPassed()) {
825+
for (const auto& codec : codecs) {
826+
if (DoesCodecParameterMatchCodec(encoding.mCodec.Value(), codec)) {
827+
found = true;
828+
break;
829+
}
830+
}
831+
if (!found) {
832+
const auto mime = NS_LossyConvertUTF16toASCII(encoding.mCodec.Value().mMimeType);
833+
std::stringstream ss;
834+
ss << "Codec " << mime
835+
<< " does not match any codec "
836+
"in GetCapabilities";
837+
nsCString errorStr(ss.str().c_str());
838+
aRv.ThrowOperationError(errorStr);
839+
return nullptr;
840+
}
841+
}
842+
}
843+
812844
// CheckAndRectifyEncodings covers these six:
813845
// If any encoding contains a rid member whose value does not conform to the
814846
// grammar requirements specified in Section 10 of [RFC8851], throw a
@@ -828,8 +860,12 @@ already_AddRefed<RTCRtpTransceiver> PeerConnectionImpl::AddTransceiver(
828860
// Verify that the value of each maxFramerate member in sendEncodings that is
829861
// defined is greater than 0.0. If one of the maxFramerate values does not
830862
// meet this requirement, throw a RangeError.
831-
RTCRtpSender::CheckAndRectifyEncodings(sendEncodings,
832-
*type == SdpMediaSection::kVideo, aRv);
863+
864+
RTCRtpSender::CheckAndRectifyEncodings(
865+
sendEncodings, *type == SdpMediaSection::kVideo,
866+
// No codecs until after negotiation
867+
Optional<Sequence<RTCRtpCodecParameters>>(), false, false,
868+
MatchGetCapabilities::NO, aRv);
833869
if (aRv.Failed()) {
834870
return nullptr;
835871
}

0 commit comments

Comments
 (0)