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