Refactor to remove direct memory dependency on kMaxId

When two-byte header extensions are enabled, kMaxId will change from 15
to 255. This CL is a refactor to remove the direct dependency between
memory allocation and kMaxId.

Bug: webrtc:7990
Change-Id: I38974a9c705eb6a0fdba9038a7d909861587d98d
Reviewed-on: https://webrtc-review.googlesource.com/101580
Commit-Queue: Johannes Kron <kron@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24801}
This commit is contained in:
Johannes Kron
2018-09-24 14:50:48 +02:00
committed by Commit Bot
parent 3a9731ff2f
commit c5744b8b21
5 changed files with 89 additions and 58 deletions

View File

@ -13,11 +13,11 @@
#include <vector>
#include "api/array_view.h"
#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "rtc_base/copyonwritebuffer.h"
namespace webrtc {
class RtpHeaderExtensionMap;
class Random;
class RtpPacket {
@ -114,15 +114,26 @@ class RtpPacket {
private:
struct ExtensionInfo {
ExtensionType type;
uint16_t offset;
explicit ExtensionInfo(uint8_t id) : ExtensionInfo(id, 0, 0) {}
ExtensionInfo(uint8_t id, uint8_t length, uint16_t offset)
: id(id), length(length), offset(offset) {}
uint8_t id;
uint8_t length;
uint16_t offset;
};
// Helper function for Parse. Fill header fields using data in given buffer,
// but does not touch packet own buffer, leaving packet in invalid state.
bool ParseBuffer(const uint8_t* buffer, size_t size);
// Returns pointer to extension info for a given id. Returns nullptr if not
// found.
const ExtensionInfo* FindExtensionInfo(int id) const;
// Returns reference to extension info for a given id. Creates a new entry
// with the specified id if not found.
ExtensionInfo& FindOrCreateExtensionInfo(int id);
// Find an extension |type|.
// Returns view of the raw extension or empty view on failure.
rtc::ArrayView<const uint8_t> FindExtension(ExtensionType type) const;
@ -148,7 +159,8 @@ class RtpPacket {
size_t payload_offset_; // Match header size with csrcs and extensions.
size_t payload_size_;
ExtensionInfo extension_entries_[kMaxExtensionHeaders];
ExtensionManager extensions_;
std::vector<ExtensionInfo> extension_entries_;
size_t extensions_size_ = 0; // Unaligned.
rtc::CopyOnWriteBuffer buffer_;
};