| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 bool PayloadIsCompatible(const RtpUtility::Payload& payload, | 25 bool PayloadIsCompatible(const RtpUtility::Payload& payload, |
| 26 const CodecInst& audio_codec) { | 26 const CodecInst& audio_codec) { |
| 27 if (!payload.audio) | 27 if (!payload.audio) |
| 28 return false; | 28 return false; |
| 29 if (_stricmp(payload.name, audio_codec.plname) != 0) | 29 if (_stricmp(payload.name, audio_codec.plname) != 0) |
| 30 return false; | 30 return false; |
| 31 const AudioPayload& audio_payload = payload.typeSpecific.Audio; | 31 const AudioPayload& audio_payload = payload.typeSpecific.Audio; |
| 32 const uint32_t rate = std::max(0, audio_codec.rate); | |
| 33 return audio_payload.frequency == static_cast<uint32_t>(audio_codec.plfreq) && | 32 return audio_payload.frequency == static_cast<uint32_t>(audio_codec.plfreq) && |
| 34 audio_payload.channels == audio_codec.channels && | 33 audio_payload.channels == audio_codec.channels; |
| 35 (audio_payload.rate == rate || audio_payload.rate == 0 || rate == 0); | |
| 36 } | 34 } |
| 37 | 35 |
| 38 bool PayloadIsCompatible(const RtpUtility::Payload& payload, | 36 bool PayloadIsCompatible(const RtpUtility::Payload& payload, |
| 39 const VideoCodec& video_codec) { | 37 const VideoCodec& video_codec) { |
| 40 if (payload.audio || _stricmp(payload.name, video_codec.plName) != 0) | 38 if (payload.audio || _stricmp(payload.name, video_codec.plName) != 0) |
| 41 return false; | 39 return false; |
| 42 // For H264, profiles must match as well. | 40 // For H264, profiles must match as well. |
| 43 if (video_codec.codecType == kVideoCodecH264) { | 41 if (video_codec.codecType == kVideoCodecH264) { |
| 44 return video_codec.H264().profile == | 42 return video_codec.H264().profile == |
| 45 payload.typeSpecific.Video.h264_profile; | 43 payload.typeSpecific.Video.h264_profile; |
| 46 } | 44 } |
| 47 return true; | 45 return true; |
| 48 } | 46 } |
| 49 | 47 |
| 50 RtpUtility::Payload CreatePayloadType(const CodecInst& audio_codec) { | 48 RtpUtility::Payload CreatePayloadType(const CodecInst& audio_codec) { |
| 51 RtpUtility::Payload payload; | 49 RtpUtility::Payload payload; |
| 52 payload.name[RTP_PAYLOAD_NAME_SIZE - 1] = 0; | 50 payload.name[RTP_PAYLOAD_NAME_SIZE - 1] = 0; |
| 53 strncpy(payload.name, audio_codec.plname, RTP_PAYLOAD_NAME_SIZE - 1); | 51 strncpy(payload.name, audio_codec.plname, RTP_PAYLOAD_NAME_SIZE - 1); |
| 54 RTC_DCHECK_GE(audio_codec.plfreq, 1000); | 52 RTC_DCHECK_GE(audio_codec.plfreq, 1000); |
| 55 payload.typeSpecific.Audio.frequency = audio_codec.plfreq; | 53 payload.typeSpecific.Audio.frequency = audio_codec.plfreq; |
| 56 payload.typeSpecific.Audio.channels = audio_codec.channels; | 54 payload.typeSpecific.Audio.channels = audio_codec.channels; |
| 57 payload.typeSpecific.Audio.rate = std::max(0, audio_codec.rate); | 55 payload.typeSpecific.Audio.rate = 0; |
| 58 payload.audio = true; | 56 payload.audio = true; |
| 59 return payload; | 57 return payload; |
| 60 } | 58 } |
| 61 | 59 |
| 62 RtpVideoCodecTypes ConvertToRtpVideoCodecType(VideoCodecType type) { | 60 RtpVideoCodecTypes ConvertToRtpVideoCodecType(VideoCodecType type) { |
| 63 switch (type) { | 61 switch (type) { |
| 64 case kVideoCodecVP8: | 62 case kVideoCodecVP8: |
| 65 return kRtpVideoVp8; | 63 return kRtpVideoVp8; |
| 66 case kVideoCodecVP9: | 64 case kVideoCodecVP9: |
| 67 return kRtpVideoVp9; | 65 return kRtpVideoVp9; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 if (!IsPayloadTypeValid(audio_codec.pltype)) | 125 if (!IsPayloadTypeValid(audio_codec.pltype)) |
| 128 return -1; | 126 return -1; |
| 129 | 127 |
| 130 rtc::CritScope cs(&crit_sect_); | 128 rtc::CritScope cs(&crit_sect_); |
| 131 | 129 |
| 132 auto it = payload_type_map_.find(audio_codec.pltype); | 130 auto it = payload_type_map_.find(audio_codec.pltype); |
| 133 if (it != payload_type_map_.end()) { | 131 if (it != payload_type_map_.end()) { |
| 134 // We already use this payload type. Check if it's the same as we already | 132 // We already use this payload type. Check if it's the same as we already |
| 135 // have. If same, ignore sending an error. | 133 // have. If same, ignore sending an error. |
| 136 if (PayloadIsCompatible(it->second, audio_codec)) { | 134 if (PayloadIsCompatible(it->second, audio_codec)) { |
| 137 it->second.typeSpecific.Audio.rate = std::max(0, audio_codec.rate); | 135 it->second.typeSpecific.Audio.rate = 0; |
| 138 return 0; | 136 return 0; |
| 139 } | 137 } |
| 140 LOG(LS_ERROR) << "Payload type already registered: " << audio_codec.pltype; | 138 LOG(LS_ERROR) << "Payload type already registered: " << audio_codec.pltype; |
| 141 return -1; | 139 return -1; |
| 142 } | 140 } |
| 143 | 141 |
| 144 // Audio codecs must be unique. | 142 // Audio codecs must be unique. |
| 145 DeregisterAudioCodecOrRedTypeRegardlessOfPayloadType(audio_codec); | 143 DeregisterAudioCodecOrRedTypeRegardlessOfPayloadType(audio_codec); |
| 146 | 144 |
| 147 payload_type_map_[audio_codec.pltype] = CreatePayloadType(audio_codec); | 145 payload_type_map_[audio_codec.pltype] = CreatePayloadType(audio_codec); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 const char* payload_name) const { | 386 const char* payload_name) const { |
| 389 rtc::CritScope cs(&crit_sect_); | 387 rtc::CritScope cs(&crit_sect_); |
| 390 for (const auto& it : payload_type_map_) { | 388 for (const auto& it : payload_type_map_) { |
| 391 if (_stricmp(it.second.name, payload_name) == 0) | 389 if (_stricmp(it.second.name, payload_name) == 0) |
| 392 return it.first; | 390 return it.first; |
| 393 } | 391 } |
| 394 return -1; | 392 return -1; |
| 395 } | 393 } |
| 396 | 394 |
| 397 } // namespace webrtc | 395 } // namespace webrtc |
| OLD | NEW |