Unify RTP payload type validity checking
making the UsedId generator the source of truth. BUG=webrtc:12197 Change-Id: I4318a1366f8b2e20ea5ae264232437a9006c5103 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/321120 Commit-Queue: Philipp Hancke <phancke@microsoft.com> Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#40802}
This commit is contained in:
parent
6bf2d31e71
commit
7d1aff6eed
@ -1108,6 +1108,7 @@ rtc_source_set("sdp_offer_answer") {
|
|||||||
":stream_collection",
|
":stream_collection",
|
||||||
":transceiver_list",
|
":transceiver_list",
|
||||||
":usage_pattern",
|
":usage_pattern",
|
||||||
|
":used_ids",
|
||||||
":webrtc_session_description_factory",
|
":webrtc_session_description_factory",
|
||||||
"../api:array_view",
|
"../api:array_view",
|
||||||
"../api:audio_options_api",
|
"../api:audio_options_api",
|
||||||
|
|||||||
@ -53,6 +53,7 @@
|
|||||||
#include "pc/rtp_sender_proxy.h"
|
#include "pc/rtp_sender_proxy.h"
|
||||||
#include "pc/simulcast_description.h"
|
#include "pc/simulcast_description.h"
|
||||||
#include "pc/usage_pattern.h"
|
#include "pc/usage_pattern.h"
|
||||||
|
#include "pc/used_ids.h"
|
||||||
#include "pc/webrtc_session_description_factory.h"
|
#include "pc/webrtc_session_description_factory.h"
|
||||||
#include "rtc_base/helpers.h"
|
#include "rtc_base/helpers.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
@ -120,12 +121,6 @@ const char kDefaultStreamId[] = "default";
|
|||||||
static const char kDefaultAudioSenderId[] = "defaulta0";
|
static const char kDefaultAudioSenderId[] = "defaulta0";
|
||||||
static const char kDefaultVideoSenderId[] = "defaultv0";
|
static const char kDefaultVideoSenderId[] = "defaultv0";
|
||||||
|
|
||||||
// NOTE: Duplicated from pc/used_ids.h
|
|
||||||
static const int kLastDynamicPayloadTypeLowerRange = 63;
|
|
||||||
|
|
||||||
static const int kFirstDynamicPayloadTypeUpperRange = 96;
|
|
||||||
static const int kLastDynamicPayloadTypeUpperRange = 127;
|
|
||||||
|
|
||||||
void NoteAddIceCandidateResult(int result) {
|
void NoteAddIceCandidateResult(int result) {
|
||||||
RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.AddIceCandidate", result,
|
RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.AddIceCandidate", result,
|
||||||
kAddIceCandidateMax);
|
kAddIceCandidateMax);
|
||||||
@ -574,10 +569,8 @@ RTCError ValidatePayloadTypes(const cricket::SessionDescription& description) {
|
|||||||
if (type == cricket::MEDIA_TYPE_AUDIO) {
|
if (type == cricket::MEDIA_TYPE_AUDIO) {
|
||||||
RTC_DCHECK(media_description->as_audio());
|
RTC_DCHECK(media_description->as_audio());
|
||||||
for (const auto& codec : media_description->as_audio()->codecs()) {
|
for (const auto& codec : media_description->as_audio()->codecs()) {
|
||||||
if (codec.id < 0 || codec.id > kLastDynamicPayloadTypeUpperRange ||
|
if (!cricket::UsedPayloadTypes::IsIdValid(
|
||||||
(media_description->rtcp_mux() &&
|
codec, media_description->rtcp_mux())) {
|
||||||
(codec.id > kLastDynamicPayloadTypeLowerRange &&
|
|
||||||
codec.id < kFirstDynamicPayloadTypeUpperRange))) {
|
|
||||||
LOG_AND_RETURN_ERROR(
|
LOG_AND_RETURN_ERROR(
|
||||||
RTCErrorType::INVALID_PARAMETER,
|
RTCErrorType::INVALID_PARAMETER,
|
||||||
"The media section with MID='" + content.mid() +
|
"The media section with MID='" + content.mid() +
|
||||||
@ -589,10 +582,8 @@ RTCError ValidatePayloadTypes(const cricket::SessionDescription& description) {
|
|||||||
} else if (type == cricket::MEDIA_TYPE_VIDEO) {
|
} else if (type == cricket::MEDIA_TYPE_VIDEO) {
|
||||||
RTC_DCHECK(media_description->as_video());
|
RTC_DCHECK(media_description->as_video());
|
||||||
for (const auto& codec : media_description->as_video()->codecs()) {
|
for (const auto& codec : media_description->as_video()->codecs()) {
|
||||||
if (codec.id < 0 || codec.id > kLastDynamicPayloadTypeUpperRange ||
|
if (!cricket::UsedPayloadTypes::IsIdValid(
|
||||||
(media_description->rtcp_mux() &&
|
codec, media_description->rtcp_mux())) {
|
||||||
(codec.id > kLastDynamicPayloadTypeLowerRange &&
|
|
||||||
codec.id < kFirstDynamicPayloadTypeUpperRange))) {
|
|
||||||
LOG_AND_RETURN_ERROR(
|
LOG_AND_RETURN_ERROR(
|
||||||
RTCErrorType::INVALID_PARAMETER,
|
RTCErrorType::INVALID_PARAMETER,
|
||||||
"The media section with MID='" + content.mid() +
|
"The media section with MID='" + content.mid() +
|
||||||
|
|||||||
@ -96,6 +96,16 @@ class UsedPayloadTypes : public UsedIds<Codec> {
|
|||||||
: UsedIds<Codec>(kFirstDynamicPayloadTypeLowerRange,
|
: UsedIds<Codec>(kFirstDynamicPayloadTypeLowerRange,
|
||||||
kLastDynamicPayloadTypeUpperRange) {}
|
kLastDynamicPayloadTypeUpperRange) {}
|
||||||
|
|
||||||
|
// Check if a payload type is valid. The range [64-95] is forbidden
|
||||||
|
// when rtcp-mux is used.
|
||||||
|
static bool IsIdValid(Codec codec, bool rtcp_mux) {
|
||||||
|
if (rtcp_mux && (codec.id > kLastDynamicPayloadTypeLowerRange &&
|
||||||
|
codec.id < kFirstDynamicPayloadTypeUpperRange)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return codec.id >= 0 && codec.id <= kLastDynamicPayloadTypeUpperRange;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool IsIdUsed(int new_id) override {
|
bool IsIdUsed(int new_id) override {
|
||||||
// Range marked for RTCP avoidance is "used".
|
// Range marked for RTCP avoidance is "used".
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user