1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "cast/streaming/rtp_defines.h" 6 7 #include "util/osp_logging.h" 8 9 namespace openscreen { 10 namespace cast { 11 GetPayloadType(AudioCodec codec,bool use_android_rtp_hack)12RtpPayloadType GetPayloadType(AudioCodec codec, bool use_android_rtp_hack) { 13 if (use_android_rtp_hack) { 14 return codec == AudioCodec::kNotSpecified 15 ? RtpPayloadType::kAudioVarious 16 : RtpPayloadType::kAudioHackForAndroidTV; 17 } 18 19 switch (codec) { 20 case AudioCodec::kAac: 21 return RtpPayloadType::kAudioAac; 22 case AudioCodec::kOpus: 23 return RtpPayloadType::kAudioOpus; 24 case AudioCodec::kNotSpecified: 25 return RtpPayloadType::kAudioVarious; 26 default: 27 OSP_NOTREACHED(); 28 } 29 } 30 GetPayloadType(VideoCodec codec,bool use_android_rtp_hack)31RtpPayloadType GetPayloadType(VideoCodec codec, bool use_android_rtp_hack) { 32 if (use_android_rtp_hack) { 33 return codec == VideoCodec::kNotSpecified 34 ? RtpPayloadType::kVideoVarious 35 : RtpPayloadType::kVideoHackForAndroidTV; 36 } 37 switch (codec) { 38 // VP8 and VP9 share the same payload type. 39 case VideoCodec::kVp9: 40 case VideoCodec::kVp8: 41 return RtpPayloadType::kVideoVp8; 42 43 // H264 and HEVC/H265 share the same payload type. 44 case VideoCodec::kHevc: // fallthrough 45 case VideoCodec::kH264: 46 return RtpPayloadType::kVideoH264; 47 48 case VideoCodec::kAv1: 49 return RtpPayloadType::kVideoAv1; 50 51 case VideoCodec::kNotSpecified: 52 return RtpPayloadType::kVideoVarious; 53 54 default: 55 OSP_NOTREACHED(); 56 } 57 } 58 IsRtpPayloadType(uint8_t raw_byte)59bool IsRtpPayloadType(uint8_t raw_byte) { 60 switch (static_cast<RtpPayloadType>(raw_byte)) { 61 case RtpPayloadType::kAudioOpus: 62 case RtpPayloadType::kAudioAac: 63 case RtpPayloadType::kAudioPcm16: 64 case RtpPayloadType::kAudioVarious: 65 case RtpPayloadType::kVideoVp8: 66 case RtpPayloadType::kVideoH264: 67 case RtpPayloadType::kVideoVp9: 68 case RtpPayloadType::kVideoAv1: 69 case RtpPayloadType::kVideoVarious: 70 case RtpPayloadType::kAudioHackForAndroidTV: 71 // Note: RtpPayloadType::kVideoHackForAndroidTV has the same value as 72 // kAudioOpus. 73 return true; 74 75 case RtpPayloadType::kNull: 76 break; 77 } 78 return false; 79 } 80 IsRtcpPacketType(uint8_t raw_byte)81bool IsRtcpPacketType(uint8_t raw_byte) { 82 switch (static_cast<RtcpPacketType>(raw_byte)) { 83 case RtcpPacketType::kSenderReport: 84 case RtcpPacketType::kReceiverReport: 85 case RtcpPacketType::kSourceDescription: 86 case RtcpPacketType::kApplicationDefined: 87 case RtcpPacketType::kPayloadSpecific: 88 case RtcpPacketType::kExtendedReports: 89 return true; 90 91 case RtcpPacketType::kNull: 92 break; 93 } 94 return false; 95 } 96 97 } // namespace cast 98 } // namespace openscreen 99