| 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 |
| 11 | #ifndef MEDIA_BASE_RTP_UTILS_H_ |
| 12 | #define MEDIA_BASE_RTP_UTILS_H_ |
| 13 |
| 14 | #include "absl/strings/string_view.h" |
| 15 | #include "api/array_view.h" |
| 16 | #include "rtc_base/byte_order.h" |
| 17 | #include "rtc_base/system/rtc_export.h" |
| 18 |
| 19 | namespace rtc { |
| 20 | struct PacketTimeUpdateParams; |
| 21 | } // namespace rtc |
| 22 |
| 23 | namespace cricket { |
| 24 |
| 25 | const size_t kMinRtpPacketLen = 12; |
| 26 | const size_t kMaxRtpPacketLen = 2048; |
| 27 | const size_t kMinRtcpPacketLen = 4; |
| 28 |
| 29 | enum RtcpTypes { |
| 30 | kRtcpTypeSR = 200, // Sender report payload type. |
| 31 | kRtcpTypeRR = 201, // Receiver report payload type. |
| 32 | kRtcpTypeSDES = 202, // SDES payload type. |
| 33 | kRtcpTypeBye = 203, // BYE payload type. |
| 34 | kRtcpTypeApp = 204, // APP payload type. |
| 35 | kRtcpTypeRTPFB = 205, // Transport layer Feedback message payload type. |
| 36 | kRtcpTypePSFB = 206, // Payload-specific Feedback message payload type. |
| 37 | }; |
| 38 |
| 39 | enum class RtpPacketType { |
| 40 | kRtp, |
| 41 | kRtcp, |
| 42 | kUnknown, |
| 43 | }; |
| 44 |
| 45 | bool GetRtcpType(const void* data, size_t len, int* value); |
| 46 | bool GetRtcpSsrc(const void* data, size_t len, uint32_t* value); |
| 47 |
| 48 | // Checks the packet header to determine if it can be an RTP or RTCP packet. |
| 49 | RtpPacketType InferRtpPacketType(rtc::ArrayView<const char> packet); |
| 50 | // True if |payload type| is 0-127. |
| 51 | bool IsValidRtpPayloadType(int payload_type); |
| 52 |
| 53 | // True if `size` is appropriate for the indicated packet type. |
| 54 | bool IsValidRtpPacketSize(RtpPacketType packet_type, size_t size); |
| 55 |
| 56 | // Returns "RTCP", "RTP" or "Unknown" according to `packet_type`. |
| 57 | absl::string_view RtpPacketTypeToString(RtpPacketType packet_type); |
| 58 |
| 59 | // Verifies that a packet has a valid RTP header. |
| 60 | bool RTC_EXPORT ValidateRtpHeader(const uint8_t* rtp, |
| 61 | size_t length, |
| 62 | size_t* header_length); |
| 63 |
| 64 | // Helper method which updates the absolute send time extension if present. |
| 65 | bool UpdateRtpAbsSendTimeExtension(uint8_t* rtp, |
| 66 | size_t length, |
| 67 | int extension_id, |
| 68 | uint64_t time_us); |
| 69 |
| 70 | // Applies specified `options` to the packet. It updates the absolute send time |
| 71 | // extension header if it is present present then updates HMAC. |
| 72 | bool RTC_EXPORT |
| 73 | ApplyPacketOptions(uint8_t* data, |
| 74 | size_t length, |
| 75 | const rtc::PacketTimeUpdateParams& packet_time_params, |
| 76 | uint64_t time_us); |
| 77 |
| 78 | } // namespace cricket |
| 79 |
| 80 | #endif // MEDIA_BASE_RTP_UTILS_H_ |
| 81 |