mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
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
3 changed files with 16 additions and 14 deletions
|
@ -1108,6 +1108,7 @@ rtc_source_set("sdp_offer_answer") {
|
|||
":stream_collection",
|
||||
":transceiver_list",
|
||||
":usage_pattern",
|
||||
":used_ids",
|
||||
":webrtc_session_description_factory",
|
||||
"../api:array_view",
|
||||
"../api:audio_options_api",
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#include "pc/rtp_sender_proxy.h"
|
||||
#include "pc/simulcast_description.h"
|
||||
#include "pc/usage_pattern.h"
|
||||
#include "pc/used_ids.h"
|
||||
#include "pc/webrtc_session_description_factory.h"
|
||||
#include "rtc_base/helpers.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
@ -120,12 +121,6 @@ const char kDefaultStreamId[] = "default";
|
|||
static const char kDefaultAudioSenderId[] = "defaulta0";
|
||||
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) {
|
||||
RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.AddIceCandidate", result,
|
||||
kAddIceCandidateMax);
|
||||
|
@ -574,10 +569,8 @@ RTCError ValidatePayloadTypes(const cricket::SessionDescription& description) {
|
|||
if (type == cricket::MEDIA_TYPE_AUDIO) {
|
||||
RTC_DCHECK(media_description->as_audio());
|
||||
for (const auto& codec : media_description->as_audio()->codecs()) {
|
||||
if (codec.id < 0 || codec.id > kLastDynamicPayloadTypeUpperRange ||
|
||||
(media_description->rtcp_mux() &&
|
||||
(codec.id > kLastDynamicPayloadTypeLowerRange &&
|
||||
codec.id < kFirstDynamicPayloadTypeUpperRange))) {
|
||||
if (!cricket::UsedPayloadTypes::IsIdValid(
|
||||
codec, media_description->rtcp_mux())) {
|
||||
LOG_AND_RETURN_ERROR(
|
||||
RTCErrorType::INVALID_PARAMETER,
|
||||
"The media section with MID='" + content.mid() +
|
||||
|
@ -589,10 +582,8 @@ RTCError ValidatePayloadTypes(const cricket::SessionDescription& description) {
|
|||
} else if (type == cricket::MEDIA_TYPE_VIDEO) {
|
||||
RTC_DCHECK(media_description->as_video());
|
||||
for (const auto& codec : media_description->as_video()->codecs()) {
|
||||
if (codec.id < 0 || codec.id > kLastDynamicPayloadTypeUpperRange ||
|
||||
(media_description->rtcp_mux() &&
|
||||
(codec.id > kLastDynamicPayloadTypeLowerRange &&
|
||||
codec.id < kFirstDynamicPayloadTypeUpperRange))) {
|
||||
if (!cricket::UsedPayloadTypes::IsIdValid(
|
||||
codec, media_description->rtcp_mux())) {
|
||||
LOG_AND_RETURN_ERROR(
|
||||
RTCErrorType::INVALID_PARAMETER,
|
||||
"The media section with MID='" + content.mid() +
|
||||
|
|
|
@ -96,6 +96,16 @@ class UsedPayloadTypes : public UsedIds<Codec> {
|
|||
: UsedIds<Codec>(kFirstDynamicPayloadTypeLowerRange,
|
||||
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:
|
||||
bool IsIdUsed(int new_id) override {
|
||||
// Range marked for RTCP avoidance is "used".
|
||||
|
|
Loading…
Reference in a new issue