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

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

Issue 1696203002: [rtp_rtcp] rtc::scoped_ptr<rtcp::RawPacket> replaced with rtc::Buffer (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 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) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 */ 10 */
11 11
12 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_ 12 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_
13 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_ 13 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_
14 14
15 #include <vector> 15 #include <vector>
16 16
17 #include "webrtc/base/scoped_ptr.h" 17 #include "webrtc/base/buffer.h"
18 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" 18 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
19 #include "webrtc/typedefs.h" 19 #include "webrtc/typedefs.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 namespace rtcp { 22 namespace rtcp {
23 23
24 static const int kCommonFbFmtLength = 12; 24 static const int kCommonFbFmtLength = 12;
25 25
26 class RawPacket;
27
28 // Class for building RTCP packets. 26 // Class for building RTCP packets.
29 // 27 //
30 // Example: 28 // Example:
31 // ReportBlock report_block; 29 // ReportBlock report_block;
32 // report_block.To(234) 30 // report_block.To(234);
33 // report_block.FractionLost(10); 31 // report_block.WithFractionLost(10);
34 // 32 //
35 // ReceiverReport rr; 33 // ReceiverReport rr;
36 // rr.From(123); 34 // rr.From(123);
37 // rr.WithReportBlock(&report_block) 35 // rr.WithReportBlock(report_block);
38 // 36 //
39 // Fir fir; 37 // Fir fir;
40 // fir.From(123); 38 // fir.From(123);
41 // fir.WithRequestTo(234, 56); 39 // fir.WithRequestTo(234, 56);
42 // 40 //
43 // size_t length = 0; // Builds an intra frame request 41 // size_t length = 0; // Builds an intra frame request
44 // uint8_t packet[kPacketSize]; // with sequence number 56. 42 // uint8_t packet[kPacketSize]; // with sequence number 56.
45 // fir.Build(packet, &length, kPacketSize); 43 // fir.Build(packet, &length, kPacketSize);
46 // 44 //
47 // RawPacket packet = fir.Build(); // Returns a RawPacket holding 45 // rtc::Buffer packet = fir.Build(); // Returns a RawPacket holding
48 // // the built rtcp packet. 46 // // the built rtcp packet.
49 // 47 //
50 // rr.Append(&fir) // Builds a compound RTCP packet with 48 // rr.Append(&fir); // Builds a compound RTCP packet with
51 // RawPacket packet = rr.Build(); // a receiver report, report block 49 // rtc::Buffer packet = rr.Build(); // a receiver report, report block
52 // // and fir message. 50 // // and fir message.
53 51
54 class RtcpPacket { 52 class RtcpPacket {
55 public: 53 public:
56 virtual ~RtcpPacket() {} 54 virtual ~RtcpPacket() {}
57 55
58 void Append(RtcpPacket* packet); 56 void Append(RtcpPacket* packet);
59 57
60 // Callback used to signal that an RTCP packet is ready. Note that this may 58 // Callback used to signal that an RTCP packet is ready. Note that this may
61 // not contain all data in this RtcpPacket; if a packet cannot fit in 59 // not contain all data in this RtcpPacket; if a packet cannot fit in
62 // max_length bytes, it will be fragmented and multiple calls to this 60 // max_length bytes, it will be fragmented and multiple calls to this
63 // callback will be made. 61 // callback will be made.
64 class PacketReadyCallback { 62 class PacketReadyCallback {
65 public: 63 public:
66 PacketReadyCallback() {} 64 PacketReadyCallback() {}
67 virtual ~PacketReadyCallback() {} 65 virtual ~PacketReadyCallback() {}
68 66
69 virtual void OnPacketReady(uint8_t* data, size_t length) = 0; 67 virtual void OnPacketReady(uint8_t* data, size_t length) = 0;
70 }; 68 };
71 69
72 // Convenience method mostly used for test. Max length of IP_PACKET_SIZE is 70 // Convenience method mostly used for test. Max length of IP_PACKET_SIZE is
73 // used, will cause assertion error if fragmentation occurs. 71 // used, will cause assertion error if fragmentation occurs.
74 rtc::scoped_ptr<RawPacket> Build() const; 72 rtc::Buffer Build() const;
75 73
76 // Returns true if all calls to Create succeeded. A buffer of size 74 // Returns true if all calls to Create succeeded. A buffer of size
77 // IP_PACKET_SIZE will be allocated and reused between calls to callback. 75 // IP_PACKET_SIZE will be allocated and reused between calls to callback.
78 bool Build(PacketReadyCallback* callback) const; 76 bool Build(PacketReadyCallback* callback) const;
79 77
80 // Returns true if all calls to Create succeeded. Provided buffer reference 78 // Returns true if all calls to Create succeeded. Provided buffer reference
81 // will be used for all calls to callback. 79 // will be used for all calls to callback.
82 bool BuildExternalBuffer(uint8_t* buffer, 80 bool BuildExternalBuffer(uint8_t* buffer,
83 size_t max_length, 81 size_t max_length,
84 PacketReadyCallback* callback) const; 82 PacketReadyCallback* callback) const;
(...skipping 23 matching lines...) Expand all
108 106
109 static const size_t kHeaderLength = 4; 107 static const size_t kHeaderLength = 4;
110 std::vector<RtcpPacket*> appended_packets_; 108 std::vector<RtcpPacket*> appended_packets_;
111 109
112 private: 110 private:
113 bool CreateAndAddAppended(uint8_t* packet, 111 bool CreateAndAddAppended(uint8_t* packet,
114 size_t* index, 112 size_t* index,
115 size_t max_length, 113 size_t max_length,
116 PacketReadyCallback* callback) const; 114 PacketReadyCallback* callback) const;
117 }; 115 };
118
119 // Class holding a RTCP packet.
120 //
121 // Takes a built rtcp packet.
122 // RawPacket raw_packet(buffer, length);
123 //
124 // To access the raw packet:
125 // raw_packet.Buffer(); - pointer to the raw packet
126 // raw_packet.BufferLength(); - the length of the raw packet
127
128 class RawPacket {
129 public:
130 explicit RawPacket(size_t buffer_length);
131 RawPacket(const uint8_t* packet, size_t packet_length);
132
133 const uint8_t* Buffer() const;
134 uint8_t* MutableBuffer();
135 size_t BufferLength() const;
136 size_t Length() const;
137 void SetLength(size_t length);
138
139 private:
140 const size_t buffer_length_;
141 size_t length_;
142 rtc::scoped_ptr<uint8_t[]> buffer_;
143 };
144
145 } // namespace rtcp 116 } // namespace rtcp
146 } // namespace webrtc 117 } // namespace webrtc
147 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_ 118 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698