Implements method on RtpPacket to extract extension.

Removing extension will be used in DatagramDtlsAdaptor to remove transport sequence number to avoid having both datagram and RTP feedback loops. The sequence number will be stored in temporary map and used to re-create RTCP fdeedback packed when we receive datagram ACK. It would enable integration of Datagram transport without any changes in the upper layers of RTP stack. Note that Datagram adaptor changes will be implemented in a separate changelist.

In this change:
- Implement method to remove extension by rebuilding entire packet without given extension type.
- Fails if extension is not registered or not set.
- Unit test

Bug: webrtc:9719
Change-Id: I9d3811d5d97fadde5a294d5da643b2ebc6a8196e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/145100
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Bjorn Mellem <mellem@webrtc.org>
Commit-Queue: Anton Sukhanov <sukhanov@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28530}
This commit is contained in:
Anton Sukhanov
2019-07-09 13:04:07 -07:00
committed by Commit Bot
parent ca5f21e293
commit ff25b873bf
3 changed files with 170 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#ifndef MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_
#define MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_
#include <string>
#include <vector>
#include "absl/types/optional.h"
@ -38,6 +39,9 @@ class RtpPacket {
RtpPacket& operator=(const RtpPacket&) = default;
// Parse and copy given buffer into Packet.
// Does not require extension map to be registered (map is only required to
// read or allocate extensions in methods GetExtension, AllocateExtension,
// etc.)
bool Parse(const uint8_t* buffer, size_t size);
bool Parse(rtc::ArrayView<const uint8_t> packet);
@ -89,6 +93,12 @@ class RtpPacket {
// which are modified after FEC protection is generated.
void CopyAndZeroMutableExtensions(rtc::ArrayView<uint8_t> buffer) const;
// Removes extension of given |type|, returns false is extension was not
// registered in packet's extension map or not present in the packet. Only
// extension that should be removed must be registered, other extensions may
// not be registered and will be preserved as is.
bool RemoveExtension(ExtensionType type);
// Writes csrc list. Assumes:
// a) There is enough room left in buffer.
// b) Extension headers, payload or padding data has not already been added.
@ -134,6 +144,9 @@ class RtpPacket {
bool SetPadding(size_t padding_size);
// Returns debug string of RTP packet (without detailed extension info).
std::string ToString() const;
private:
struct ExtensionInfo {
explicit ExtensionInfo(uint8_t id) : ExtensionInfo(id, 0, 0) {}
@ -168,6 +181,7 @@ class RtpPacket {
uint8_t* WriteAt(size_t offset) { return buffer_.data() + offset; }
void WriteAt(size_t offset, uint8_t byte) { buffer_.data()[offset] = byte; }
const uint8_t* ReadAt(size_t offset) const { return buffer_.data() + offset; }
// Header.
bool marker_;