phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 1 | /* |
phoglund@webrtc.org | 244251a | 2013-02-04 13:23:07 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/rtp_rtcp/include/rtp_payload_registry.h" |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 12 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 13 | #include <algorithm> |
| 14 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 15 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "modules/audio_coding/codecs/audio_format_conversion.h" |
| 17 | #include "rtc_base/checks.h" |
| 18 | #include "rtc_base/logging.h" |
| 19 | #include "rtc_base/stringutils.h" |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 23 | namespace { |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 24 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 25 | bool PayloadIsCompatible(const RtpUtility::Payload& payload, |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 26 | const SdpAudioFormat& audio_format) { |
| 27 | return payload.typeSpecific.is_audio() && |
| 28 | audio_format.Matches(payload.typeSpecific.audio_payload().format); |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | bool PayloadIsCompatible(const RtpUtility::Payload& payload, |
| 32 | const VideoCodec& video_codec) { |
Karl Wiberg | c856dc2 | 2017-09-28 20:13:59 +0200 | [diff] [blame] | 33 | if (!payload.typeSpecific.is_video() || |
| 34 | _stricmp(payload.name, video_codec.plName) != 0) |
magjed | e69a1a9 | 2016-11-25 10:06:31 -0800 | [diff] [blame] | 35 | return false; |
| 36 | // For H264, profiles must match as well. |
| 37 | if (video_codec.codecType == kVideoCodecH264) { |
| 38 | return video_codec.H264().profile == |
Karl Wiberg | c856dc2 | 2017-09-28 20:13:59 +0200 | [diff] [blame] | 39 | payload.typeSpecific.video_payload().h264_profile; |
magjed | e69a1a9 | 2016-11-25 10:06:31 -0800 | [diff] [blame] | 40 | } |
| 41 | return true; |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 42 | } |
| 43 | |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 44 | RtpUtility::Payload CreatePayloadType(const SdpAudioFormat& audio_format) { |
| 45 | RTC_DCHECK_GE(audio_format.clockrate_hz, 1000); |
| 46 | return {audio_format.name.c_str(), |
| 47 | PayloadUnion(AudioPayload{audio_format, 0})}; |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | RtpVideoCodecTypes ConvertToRtpVideoCodecType(VideoCodecType type) { |
| 51 | switch (type) { |
| 52 | case kVideoCodecVP8: |
| 53 | return kRtpVideoVp8; |
| 54 | case kVideoCodecVP9: |
| 55 | return kRtpVideoVp9; |
| 56 | case kVideoCodecH264: |
| 57 | return kRtpVideoH264; |
| 58 | case kVideoCodecRED: |
| 59 | case kVideoCodecULPFEC: |
| 60 | return kRtpVideoNone; |
| 61 | default: |
| 62 | return kRtpVideoGeneric; |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 66 | RtpUtility::Payload CreatePayloadType(const VideoCodec& video_codec) { |
Karl Wiberg | 83d3ec1 | 2017-09-28 19:54:38 +0200 | [diff] [blame] | 67 | VideoPayload p; |
| 68 | p.videoCodecType = ConvertToRtpVideoCodecType(video_codec.codecType); |
magjed | e69a1a9 | 2016-11-25 10:06:31 -0800 | [diff] [blame] | 69 | if (video_codec.codecType == kVideoCodecH264) |
Karl Wiberg | 83d3ec1 | 2017-09-28 19:54:38 +0200 | [diff] [blame] | 70 | p.h264_profile = video_codec.H264().profile; |
| 71 | return {video_codec.plName, PayloadUnion(p)}; |
magjed | 56124bd | 2016-11-24 09:34:46 -0800 | [diff] [blame] | 72 | } |
| 73 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 74 | bool IsPayloadTypeValid(int8_t payload_type) { |
pbos@webrtc.org | b5bf54c | 2013-04-05 13:27:38 +0000 | [diff] [blame] | 75 | assert(payload_type >= 0); |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 76 | |
| 77 | // Sanity check. |
| 78 | switch (payload_type) { |
| 79 | // Reserved payload types to avoid RTCP conflicts when marker bit is set. |
| 80 | case 64: // 192 Full INTRA-frame request. |
| 81 | case 72: // 200 Sender report. |
| 82 | case 73: // 201 Receiver report. |
| 83 | case 74: // 202 Source description. |
| 84 | case 75: // 203 Goodbye. |
| 85 | case 76: // 204 Application-defined. |
| 86 | case 77: // 205 Transport layer FB message. |
| 87 | case 78: // 206 Payload-specific FB message. |
| 88 | case 79: // 207 Extended report. |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 89 | RTC_LOG(LS_ERROR) << "Can't register invalid receiver payload type: " |
| 90 | << payload_type; |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 91 | return false; |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 92 | default: |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 93 | return true; |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 94 | } |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 95 | } |
pbos@webrtc.org | b5bf54c | 2013-04-05 13:27:38 +0000 | [diff] [blame] | 96 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 97 | } // namespace |
| 98 | |
| 99 | RTPPayloadRegistry::RTPPayloadRegistry() |
| 100 | : incoming_payload_type_(-1), |
| 101 | last_received_payload_type_(-1), |
| 102 | last_received_media_payload_type_(-1), |
| 103 | rtx_(false), |
| 104 | ssrc_rtx_(0) {} |
| 105 | |
| 106 | RTPPayloadRegistry::~RTPPayloadRegistry() = default; |
| 107 | |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 108 | void RTPPayloadRegistry::SetAudioReceivePayloads( |
| 109 | std::map<int, SdpAudioFormat> codecs) { |
| 110 | rtc::CritScope cs(&crit_sect_); |
| 111 | |
| 112 | #if RTC_DCHECK_IS_ON |
| 113 | RTC_DCHECK(!used_for_video_); |
| 114 | used_for_audio_ = true; |
| 115 | #endif |
| 116 | |
| 117 | payload_type_map_.clear(); |
| 118 | for (const auto& kv : codecs) { |
| 119 | const int& rtp_payload_type = kv.first; |
| 120 | const SdpAudioFormat& audio_format = kv.second; |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 121 | RTC_DCHECK(IsPayloadTypeValid(rtp_payload_type)); |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 122 | payload_type_map_.emplace(rtp_payload_type, |
| 123 | CreatePayloadType(audio_format)); |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | // Clear the value of last received payload type since it might mean |
| 127 | // something else now. |
| 128 | last_received_payload_type_ = -1; |
| 129 | last_received_media_payload_type_ = -1; |
| 130 | } |
| 131 | |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 132 | int32_t RTPPayloadRegistry::RegisterReceivePayload( |
| 133 | int payload_type, |
| 134 | const SdpAudioFormat& audio_format, |
| 135 | bool* created_new_payload) { |
kwiberg | b0bf93a | 2017-03-23 00:10:09 -0700 | [diff] [blame] | 136 | rtc::CritScope cs(&crit_sect_); |
| 137 | |
| 138 | #if RTC_DCHECK_IS_ON |
| 139 | RTC_DCHECK(!used_for_video_); |
| 140 | used_for_audio_ = true; |
| 141 | #endif |
| 142 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 143 | *created_new_payload = false; |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 144 | if (!IsPayloadTypeValid(payload_type)) |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 145 | return -1; |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 146 | |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 147 | const auto it = payload_type_map_.find(payload_type); |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 148 | if (it != payload_type_map_.end()) { |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 149 | // We already use this payload type. Check if it's the same as we already |
| 150 | // have. If same, ignore sending an error. |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 151 | if (PayloadIsCompatible(it->second, audio_format)) { |
Karl Wiberg | c856dc2 | 2017-09-28 20:13:59 +0200 | [diff] [blame] | 152 | it->second.typeSpecific.audio_payload().rate = 0; |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 153 | return 0; |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 154 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 155 | RTC_LOG(LS_ERROR) << "Payload type already registered: " << payload_type; |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 156 | return -1; |
| 157 | } |
| 158 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 159 | // Audio codecs must be unique. |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 160 | DeregisterAudioCodecOrRedTypeRegardlessOfPayloadType(audio_format); |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 161 | |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 162 | const auto insert_status = |
| 163 | payload_type_map_.emplace(payload_type, CreatePayloadType(audio_format)); |
Karl Wiberg | 83d3ec1 | 2017-09-28 19:54:38 +0200 | [diff] [blame] | 164 | RTC_DCHECK(insert_status.second); // Insertion succeeded. |
Minyue Li | 190c3ca | 2015-03-25 16:11:24 +0100 | [diff] [blame] | 165 | *created_new_payload = true; |
| 166 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 167 | // Successful set of payload type, clear the value of last received payload |
| 168 | // type since it might mean something else. |
| 169 | last_received_payload_type_ = -1; |
| 170 | last_received_media_payload_type_ = -1; |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | int32_t RTPPayloadRegistry::RegisterReceivePayload( |
| 175 | const VideoCodec& video_codec) { |
kwiberg | b0bf93a | 2017-03-23 00:10:09 -0700 | [diff] [blame] | 176 | rtc::CritScope cs(&crit_sect_); |
| 177 | |
| 178 | #if RTC_DCHECK_IS_ON |
| 179 | RTC_DCHECK(!used_for_audio_); |
| 180 | used_for_video_ = true; |
| 181 | #endif |
| 182 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 183 | if (!IsPayloadTypeValid(video_codec.plType)) |
| 184 | return -1; |
| 185 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 186 | auto it = payload_type_map_.find(video_codec.plType); |
| 187 | if (it != payload_type_map_.end()) { |
| 188 | // We already use this payload type. Check if it's the same as we already |
| 189 | // have. If same, ignore sending an error. |
| 190 | if (PayloadIsCompatible(it->second, video_codec)) |
| 191 | return 0; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 192 | RTC_LOG(LS_ERROR) << "Payload type already registered: " |
| 193 | << static_cast<int>(video_codec.plType); |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 194 | return -1; |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 195 | } |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 196 | |
Karl Wiberg | 83d3ec1 | 2017-09-28 19:54:38 +0200 | [diff] [blame] | 197 | const auto insert_status = payload_type_map_.emplace( |
| 198 | video_codec.plType, CreatePayloadType(video_codec)); |
| 199 | RTC_DCHECK(insert_status.second); // Insertion succeeded. |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 200 | |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 201 | // Successful set of payload type, clear the value of last received payload |
| 202 | // type since it might mean something else. |
| 203 | last_received_payload_type_ = -1; |
| 204 | last_received_media_payload_type_ = -1; |
| 205 | return 0; |
| 206 | } |
| 207 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 208 | int32_t RTPPayloadRegistry::DeRegisterReceivePayload( |
| 209 | const int8_t payload_type) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 210 | rtc::CritScope cs(&crit_sect_); |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 211 | payload_type_map_.erase(payload_type); |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
phoglund@webrtc.org | 244251a | 2013-02-04 13:23:07 +0000 | [diff] [blame] | 215 | // There can't be several codecs with the same rate, frequency and channels |
| 216 | // for audio codecs, but there can for video. |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 217 | // Always called from within a critical section. |
phoglund@webrtc.org | 244251a | 2013-02-04 13:23:07 +0000 | [diff] [blame] | 218 | void RTPPayloadRegistry::DeregisterAudioCodecOrRedTypeRegardlessOfPayloadType( |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 219 | const SdpAudioFormat& audio_format) { |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 220 | for (auto iterator = payload_type_map_.begin(); |
| 221 | iterator != payload_type_map_.end(); ++iterator) { |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 222 | if (PayloadIsCompatible(iterator->second, audio_format)) { |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 223 | // Remove old setting. |
| 224 | payload_type_map_.erase(iterator); |
| 225 | break; |
phoglund@webrtc.org | 244251a | 2013-02-04 13:23:07 +0000 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 230 | int32_t RTPPayloadRegistry::ReceivePayloadType( |
| 231 | const SdpAudioFormat& audio_format, |
| 232 | int8_t* payload_type) const { |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 233 | assert(payload_type); |
| 234 | rtc::CritScope cs(&crit_sect_); |
| 235 | |
| 236 | for (const auto& it : payload_type_map_) { |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 237 | if (PayloadIsCompatible(it.second, audio_format)) { |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 238 | *payload_type = it.first; |
| 239 | return 0; |
| 240 | } |
| 241 | } |
| 242 | return -1; |
magjed | 56124bd | 2016-11-24 09:34:46 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | int32_t RTPPayloadRegistry::ReceivePayloadType(const VideoCodec& video_codec, |
| 246 | int8_t* payload_type) const { |
andresp@webrtc.org | dc80bae | 2014-04-08 11:06:12 +0000 | [diff] [blame] | 247 | assert(payload_type); |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 248 | rtc::CritScope cs(&crit_sect_); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 249 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 250 | for (const auto& it : payload_type_map_) { |
| 251 | if (PayloadIsCompatible(it.second, video_codec)) { |
| 252 | *payload_type = it.first; |
| 253 | return 0; |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 254 | } |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 255 | } |
| 256 | return -1; |
| 257 | } |
| 258 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 259 | bool RTPPayloadRegistry::RtxEnabled() const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 260 | rtc::CritScope cs(&crit_sect_); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 261 | return rtx_; |
| 262 | } |
| 263 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 264 | bool RTPPayloadRegistry::IsRtxInternal(const RTPHeader& header) const { |
| 265 | return rtx_ && ssrc_rtx_ == header.ssrc; |
| 266 | } |
| 267 | |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 +0000 | [diff] [blame] | 268 | void RTPPayloadRegistry::SetRtxSsrc(uint32_t ssrc) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 269 | rtc::CritScope cs(&crit_sect_); |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 +0000 | [diff] [blame] | 270 | ssrc_rtx_ = ssrc; |
| 271 | rtx_ = true; |
| 272 | } |
| 273 | |
asapersson@webrtc.org | d952c40 | 2014-11-27 07:38:56 +0000 | [diff] [blame] | 274 | bool RTPPayloadRegistry::GetRtxSsrc(uint32_t* ssrc) const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 275 | rtc::CritScope cs(&crit_sect_); |
asapersson@webrtc.org | d952c40 | 2014-11-27 07:38:56 +0000 | [diff] [blame] | 276 | *ssrc = ssrc_rtx_; |
| 277 | return rtx_; |
| 278 | } |
| 279 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 280 | void RTPPayloadRegistry::SetRtxPayloadType(int payload_type, |
| 281 | int associated_payload_type) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 282 | rtc::CritScope cs(&crit_sect_); |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 283 | if (payload_type < 0) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 284 | RTC_LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type; |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 285 | return; |
| 286 | } |
| 287 | |
| 288 | rtx_payload_type_map_[payload_type] = associated_payload_type; |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 +0000 | [diff] [blame] | 289 | rtx_ = true; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | bool RTPPayloadRegistry::IsRed(const RTPHeader& header) const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 293 | rtc::CritScope cs(&crit_sect_); |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 294 | auto it = payload_type_map_.find(header.payloadType); |
| 295 | return it != payload_type_map_.end() && _stricmp(it->second.name, "red") == 0; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 296 | } |
| 297 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 298 | int RTPPayloadRegistry::GetPayloadTypeFrequency( |
| 299 | uint8_t payload_type) const { |
Karl Wiberg | 73b60b8 | 2017-09-21 15:00:58 +0200 | [diff] [blame] | 300 | const auto payload = PayloadTypeToPayload(payload_type); |
danilchap | 5c1def8 | 2015-12-10 09:51:54 -0800 | [diff] [blame] | 301 | if (!payload) { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 302 | return -1; |
| 303 | } |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 304 | rtc::CritScope cs(&crit_sect_); |
Karl Wiberg | c856dc2 | 2017-09-28 20:13:59 +0200 | [diff] [blame] | 305 | return payload->typeSpecific.is_audio() |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 306 | ? payload->typeSpecific.audio_payload().format.clockrate_hz |
Karl Wiberg | c856dc2 | 2017-09-28 20:13:59 +0200 | [diff] [blame] | 307 | : kVideoPayloadTypeFrequency; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Karl Wiberg | 73b60b8 | 2017-09-21 15:00:58 +0200 | [diff] [blame] | 310 | rtc::Optional<RtpUtility::Payload> RTPPayloadRegistry::PayloadTypeToPayload( |
danilchap | 5c1def8 | 2015-12-10 09:51:54 -0800 | [diff] [blame] | 311 | uint8_t payload_type) const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 312 | rtc::CritScope cs(&crit_sect_); |
Karl Wiberg | 73b60b8 | 2017-09-21 15:00:58 +0200 | [diff] [blame] | 313 | const auto it = payload_type_map_.find(payload_type); |
| 314 | return it == payload_type_map_.end() |
Oskar Sundbom | 3419cf9 | 2017-11-16 10:55:48 +0100 | [diff] [blame^] | 315 | ? rtc::nullopt |
Karl Wiberg | 73b60b8 | 2017-09-21 15:00:58 +0200 | [diff] [blame] | 316 | : rtc::Optional<RtpUtility::Payload>(it->second); |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 317 | } |
| 318 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 319 | void RTPPayloadRegistry::SetIncomingPayloadType(const RTPHeader& header) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 320 | rtc::CritScope cs(&crit_sect_); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 321 | if (!IsRtxInternal(header)) |
| 322 | incoming_payload_type_ = header.payloadType; |
| 323 | } |
| 324 | |
| 325 | bool RTPPayloadRegistry::ReportMediaPayloadType(uint8_t media_payload_type) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 326 | rtc::CritScope cs(&crit_sect_); |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 327 | if (last_received_media_payload_type_ == media_payload_type) { |
| 328 | // Media type unchanged. |
| 329 | return true; |
| 330 | } |
| 331 | last_received_media_payload_type_ = media_payload_type; |
| 332 | return false; |
| 333 | } |
| 334 | |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 335 | // Returns -1 if a payload with name |payload_name| is not registered. |
| 336 | int8_t RTPPayloadRegistry::GetPayloadTypeWithName( |
| 337 | const char* payload_name) const { |
| 338 | rtc::CritScope cs(&crit_sect_); |
| 339 | for (const auto& it : payload_type_map_) { |
| 340 | if (_stricmp(it.second.name, payload_name) == 0) |
| 341 | return it.first; |
phoglund@webrtc.org | 244251a | 2013-02-04 13:23:07 +0000 | [diff] [blame] | 342 | } |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 343 | return -1; |
phoglund@webrtc.org | 244251a | 2013-02-04 13:23:07 +0000 | [diff] [blame] | 344 | } |
| 345 | |
phoglund@webrtc.org | efae5d5 | 2013-01-17 16:10:45 +0000 | [diff] [blame] | 346 | } // namespace webrtc |