Minor fixes and refactoring for RtpTransport until the Demux.

This change fixes some inefficiencies and quirks in the code that
originates in RtpTransport leading up to the demux.

This work is in preparation for more refactoring of the Demux stage
onwards.

Bug: webrtc:10297
Change-Id: I7b8f00134657d62c722939618a55a91a2b6040bd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128220
Commit-Queue: Amit Hilbuch <amithi@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Seth Hampson <shampson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27185}
This commit is contained in:
Amit Hilbuch
2019-03-18 12:33:43 -07:00
committed by Commit Bot
parent 342989d498
commit edd2054562
8 changed files with 113 additions and 69 deletions

View File

@ -11,6 +11,8 @@
#ifndef MEDIA_BASE_RTP_UTILS_H_
#define MEDIA_BASE_RTP_UTILS_H_
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "rtc_base/byte_order.h"
#include "rtc_base/system/rtc_export.h"
@ -41,6 +43,12 @@ enum RtcpTypes {
kRtcpTypePSFB = 206, // Payload-specific Feedback message payload type.
};
enum class RtpPacketType {
kRtp,
kRtcp,
kUnknown,
};
bool GetRtpPayloadType(const void* data, size_t len, int* value);
bool GetRtpSeqNum(const void* data, size_t len, int* value);
bool GetRtpTimestamp(const void* data, size_t len, uint32_t* value);
@ -54,19 +62,19 @@ bool SetRtpSsrc(void* data, size_t len, uint32_t value);
// Assumes version 2, no padding, no extensions, no csrcs.
bool SetRtpHeader(void* data, size_t len, const RtpHeader& header);
bool IsRtpPacket(const void* data, size_t len);
bool IsRtpPacket(rtc::ArrayView<const char> packet);
bool IsRtcpPacket(const char* data, size_t len);
bool IsRtcpPacket(rtc::ArrayView<const char> packet);
// Checks the packet header to determine if it can be an RTP or RTCP packet.
RtpPacketType InferRtpPacketType(rtc::ArrayView<const char> packet);
// True if |payload type| is 0-127.
bool IsValidRtpPayloadType(int payload_type);
// True if |size| is appropriate for the indicated packet type.
bool IsValidRtpRtcpPacketSize(bool rtcp, size_t size);
bool IsValidRtpPacketSize(RtpPacketType packet_type, size_t size);
// TODO(zstein): Consider using an enum instead of a bool to differentiate
// between RTP and RTCP.
// Returns "RTCP" or "RTP" according to |rtcp|.
const char* RtpRtcpStringLiteral(bool rtcp);
// Returns "RTCP", "RTP" or "Unknown" according to |packet_type|.
absl::string_view RtpPacketTypeToString(RtpPacketType packet_type);
// Verifies that a packet has a valid RTP header.
bool RTC_EXPORT ValidateRtpHeader(const uint8_t* rtp,