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