Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_packet.h

Issue 1945773002: RtpPacketHistory rewritten to use RtpPacket class. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_ 10 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_
11 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_ 11 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_
12 12
13 #include <vector> 13 #include <vector>
14 14
15 #include "webrtc/base/basictypes.h" 15 #include "webrtc/base/basictypes.h"
16 #include "webrtc/base/buffer.h" 16 #include "webrtc/base/copyonwritebuffer.h"
17 #include "webrtc/base/constructormagic.h"
18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
19 18
20 namespace webrtc { 19 namespace webrtc {
21 struct RTPHeader; 20 struct RTPHeader;
22 class RtpHeaderExtensionMap; 21 class RtpHeaderExtensionMap;
23 class Random; 22 class Random;
24 23
25 namespace rtp { 24 namespace rtp {
26 class Packet { 25 class Packet {
27 public: 26 public:
28 using ExtensionType = RTPExtensionType; 27 using ExtensionType = RTPExtensionType;
29 using ExtensionManager = RtpHeaderExtensionMap; 28 using ExtensionManager = RtpHeaderExtensionMap;
30 static constexpr size_t kMaxExtensionHeaders = 14; 29 static constexpr size_t kMaxExtensionHeaders = 14;
31 30
32 // Parse and copy given buffer into Packet. 31 // Parse and copy given buffer into Packet.
33 bool Parse(const uint8_t* buffer, size_t size); 32 bool Parse(const uint8_t* buffer, size_t size);
34 33
35 // Parse and move given buffer into Packet. 34 // Parse and move given buffer into Packet.
36 bool Parse(rtc::Buffer packet); 35 bool Parse(rtc::CopyOnWriteBuffer packet);
37 36
38 // Maps parsed extensions to their types to allow use of GetExtension. 37 // Maps parsed extensions to their types to allow use of GetExtension.
39 // Used after parsing when |extensions| can't be provided until base rtp 38 // Used after parsing when |extensions| can't be provided until base rtp
40 // header is parsed. 39 // header is parsed.
41 void IdentifyExtensions(const ExtensionManager* extensions); 40 void IdentifyExtensions(const ExtensionManager* extensions);
42 41
43 // Header. 42 // Header.
44 bool Marker() const; 43 bool Marker() const;
45 uint8_t PayloadType() const; 44 uint8_t PayloadType() const;
46 uint16_t SequenceNumber() const; 45 uint16_t SequenceNumber() const;
47 uint32_t Timestamp() const; 46 uint32_t Timestamp() const;
48 uint32_t Ssrc() const; 47 uint32_t Ssrc() const;
49 std::vector<uint32_t> Csrcs() const; 48 std::vector<uint32_t> Csrcs() const;
50 49
51 // TODO(danilchap): Remove this function when all code update to use RtpPacket 50 // TODO(danilchap): Remove this function when all code update to use RtpPacket
52 // directly. Function is there just for easier backward compatibilty. 51 // directly. Function is there just for easier backward compatibilty.
53 void GetHeader(RTPHeader* header) const; 52 void GetHeader(RTPHeader* header) const;
54 53
55 size_t headers_size() const; 54 size_t headers_size() const;
56 55
57 // Payload. 56 // Payload.
58 size_t payload_size() const; 57 size_t payload_size() const;
59 size_t padding_size() const; 58 size_t padding_size() const;
60 const uint8_t* payload() const; 59 const uint8_t* payload() const;
61 60
62 // Buffer. 61 // Buffer.
62 rtc::CopyOnWriteBuffer Buffer() const;
63 size_t capacity() const; 63 size_t capacity() const;
64 size_t size() const; 64 size_t size() const;
65 const uint8_t* data() const; 65 const uint8_t* data() const;
66 size_t FreeCapacity() const; 66 size_t FreeCapacity() const;
67 size_t MaxPayloadSize() const; 67 size_t MaxPayloadSize() const;
68 68
69 // Reset fields and buffer. 69 // Reset fields and buffer.
70 void Clear(); 70 void Clear();
71 71
72 // Header setters. 72 // Header setters.
73 void CopyHeader(const Packet& packet); 73 void CopyHeaderFrom(const Packet& packet);
74 void SetMarker(bool marker_bit); 74 void SetMarker(bool marker_bit);
75 void SetPayloadType(uint8_t payload_type); 75 void SetPayloadType(uint8_t payload_type);
76 void SetSequenceNumber(uint16_t seq_no); 76 void SetSequenceNumber(uint16_t seq_no);
77 void SetTimestamp(uint32_t timestamp); 77 void SetTimestamp(uint32_t timestamp);
78 void SetSsrc(uint32_t ssrc); 78 void SetSsrc(uint32_t ssrc);
79 79
80 // Writes csrc list. Assumes: 80 // Writes csrc list. Assumes:
81 // a) There is enough room left in buffer. 81 // a) There is enough room left in buffer.
82 // b) Extension headers, payload or padding data has not already been added. 82 // b) Extension headers, payload or padding data has not already been added.
83 void SetCsrcs(const std::vector<uint32_t>& csrcs); 83 void SetCsrcs(const std::vector<uint32_t>& csrcs);
(...skipping 12 matching lines...) Expand all
96 uint8_t* AllocatePayload(size_t size_bytes); 96 uint8_t* AllocatePayload(size_t size_bytes);
97 void SetPayloadSize(size_t size_bytes); 97 void SetPayloadSize(size_t size_bytes);
98 bool SetPadding(uint8_t size_bytes, Random* random); 98 bool SetPadding(uint8_t size_bytes, Random* random);
99 99
100 protected: 100 protected:
101 // |extensions| required for SetExtension/ReserveExtension functions during 101 // |extensions| required for SetExtension/ReserveExtension functions during
102 // packet creating and used if available in Parse function. 102 // packet creating and used if available in Parse function.
103 // Adding and getting extensions will fail until |extensions| is 103 // Adding and getting extensions will fail until |extensions| is
104 // provided via constructor or IdentifyExtensions function. 104 // provided via constructor or IdentifyExtensions function.
105 explicit Packet(const ExtensionManager* extensions); 105 explicit Packet(const ExtensionManager* extensions);
106 Packet(const Packet&) = default;
106 Packet(const ExtensionManager* extensions, size_t capacity); 107 Packet(const ExtensionManager* extensions, size_t capacity);
107 virtual ~Packet(); 108 virtual ~Packet();
108 109
110 Packet& operator=(const Packet&) = default;
111
109 private: 112 private:
110 struct ExtensionInfo { 113 struct ExtensionInfo {
111 ExtensionType type; 114 ExtensionType type;
112 uint16_t offset; 115 uint16_t offset;
113 uint8_t length; 116 uint8_t length;
114 }; 117 };
115 118
116 // Helper function for Parse. Fill header fields using data in given buffer, 119 // Helper function for Parse. Fill header fields using data in given buffer,
117 // but does not touch packet own buffer, leaving packet in invalid state. 120 // but does not touch packet own buffer, leaving packet in invalid state.
118 bool ParseBuffer(const uint8_t* buffer, size_t size); 121 bool ParseBuffer(const uint8_t* buffer, size_t size);
(...skipping 26 matching lines...) Expand all
145 uint8_t padding_size_; 148 uint8_t padding_size_;
146 uint16_t sequence_number_; 149 uint16_t sequence_number_;
147 uint32_t timestamp_; 150 uint32_t timestamp_;
148 uint32_t ssrc_; 151 uint32_t ssrc_;
149 size_t payload_offset_; // Match header size with csrcs and extensions. 152 size_t payload_offset_; // Match header size with csrcs and extensions.
150 size_t payload_size_; 153 size_t payload_size_;
151 154
152 uint8_t num_extensions_ = 0; 155 uint8_t num_extensions_ = 0;
153 ExtensionInfo extension_entries_[kMaxExtensionHeaders]; 156 ExtensionInfo extension_entries_[kMaxExtensionHeaders];
154 uint16_t extensions_size_ = 0; // Unaligned. 157 uint16_t extensions_size_ = 0; // Unaligned.
155 rtc::Buffer buffer_; 158 rtc::CopyOnWriteBuffer buffer_;
156 159
157 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Packet); 160 Packet() = delete;
158 }; 161 };
159 162
160 template <typename Extension, typename... Values> 163 template <typename Extension, typename... Values>
161 bool Packet::GetExtension(Values... values) const { 164 bool Packet::GetExtension(Values... values) const {
162 uint16_t offset = 0; 165 uint16_t offset = 0;
163 if (!FindExtension(Extension::kId, Extension::kValueSizeBytes, &offset)) 166 if (!FindExtension(Extension::kId, Extension::kValueSizeBytes, &offset))
164 return false; 167 return false;
165 return Extension::Parse(data() + offset, values...); 168 return Extension::Parse(data() + offset, values...);
166 } 169 }
167 170
(...skipping 10 matching lines...) Expand all
178 uint16_t offset = 0; 181 uint16_t offset = 0;
179 if (!AllocateExtension(Extension::kId, Extension::kValueSizeBytes, &offset)) 182 if (!AllocateExtension(Extension::kId, Extension::kValueSizeBytes, &offset))
180 return false; 183 return false;
181 memset(WriteAt(offset), 0, Extension::kValueSizeBytes); 184 memset(WriteAt(offset), 0, Extension::kValueSizeBytes);
182 return true; 185 return true;
183 } 186 }
184 } // namespace rtp 187 } // namespace rtp
185 } // namespace webrtc 188 } // namespace webrtc
186 189
187 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_ 190 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_PACKET_H_
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc ('k') | webrtc/modules/rtp_rtcp/source/rtp_packet.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698