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