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

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

Issue 1699043002: [rtp_rtcp] RtcpPacket::Buffer() returns rtc::Buffer instead of scoped_ptr<RawPacket> (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
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/rtcp_packet.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/buffer.h"
17 #include "webrtc/base/scoped_ptr.h" 18 #include "webrtc/base/scoped_ptr.h"
18 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" 19 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
19 #include "webrtc/typedefs.h" 20 #include "webrtc/typedefs.h"
20 21
21 namespace webrtc { 22 namespace webrtc {
22 namespace rtcp { 23 namespace rtcp {
24 // TODO(danilchap): Remove RawPacket when all tests will be updated
25 // to use rtc::Buffer directly
26 class RawPacket : rtc::Buffer {
27 public:
28 RawPacket() {}
29 RawPacket(rtc::Buffer&& buffer) : rtc::Buffer(buffer) {} // NOLINT
30 const uint8_t* Buffer() const { return data(); }
31 uint8_t* MutableBuffer() { return data(); }
32 size_t Length() const { return size(); }
33 };
34 } // namespace rtcp
35 } // namespace webrtc
23 36
24 static const int kCommonFbFmtLength = 12; 37 // TODO(danilchap): Remove this horrible template specialization when all tests
38 // will be updated to use rtc::Buffer directly.
39 // Template is specialized to make current code compile and work like before,
40 // it is not designed to match what proper scoped_ptr do.
41 template<>
42 class ::rtc::scoped_ptr<webrtc::rtcp::RawPacket> : webrtc::rtcp::RawPacket {
43 public:
44 scoped_ptr() {}
45 scoped_ptr(rtc::Buffer&& buffer) : RawPacket(std::move(buffer)) {} // NOLINT
46 webrtc::rtcp::RawPacket* get() { return this; }
47 webrtc::rtcp::RawPacket& operator*() { return *this; }
48 webrtc::rtcp::RawPacket* operator->() { return this; }
49 };
25 50
26 class RawPacket; 51 namespace webrtc {
27 52 namespace rtcp {
28 // Class for building RTCP packets. 53 // Class for building RTCP packets.
29 // 54 //
30 // Example: 55 // Example:
31 // ReportBlock report_block; 56 // ReportBlock report_block;
32 // report_block.To(234) 57 // report_block.To(234)
33 // report_block.FractionLost(10); 58 // report_block.FractionLost(10);
34 // 59 //
35 // ReceiverReport rr; 60 // ReceiverReport rr;
36 // rr.From(123); 61 // rr.From(123);
37 // rr.WithReportBlock(&report_block) 62 // rr.WithReportBlock(&report_block)
38 // 63 //
39 // Fir fir; 64 // Fir fir;
40 // fir.From(123); 65 // fir.From(123);
41 // fir.WithRequestTo(234, 56); 66 // fir.WithRequestTo(234, 56);
42 // 67 //
43 // size_t length = 0; // Builds an intra frame request 68 // size_t length = 0; // Builds an intra frame request
44 // uint8_t packet[kPacketSize]; // with sequence number 56. 69 // uint8_t packet[kPacketSize]; // with sequence number 56.
45 // fir.Build(packet, &length, kPacketSize); 70 // fir.Build(packet, &length, kPacketSize);
46 // 71 //
47 // RawPacket packet = fir.Build(); // Returns a RawPacket holding 72 // rtc::Buffer packet = fir.Build(); // Returns a RawPacket holding
48 // // the built rtcp packet. 73 // // the built rtcp packet.
49 // 74 //
50 // rr.Append(&fir) // Builds a compound RTCP packet with 75 // rr.Append(&fir) // Builds a compound RTCP packet with
51 // RawPacket packet = rr.Build(); // a receiver report, report block 76 // rtc::Buffer packet = rr.Build(); // a receiver report, report block
52 // // and fir message. 77 // // and fir message.
53 78
54 class RtcpPacket { 79 class RtcpPacket {
55 public: 80 public:
56 virtual ~RtcpPacket() {} 81 virtual ~RtcpPacket() {}
57 82
58 void Append(RtcpPacket* packet); 83 void Append(RtcpPacket* packet);
59 84
60 // Callback used to signal that an RTCP packet is ready. Note that this may 85 // 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 86 // 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 87 // max_length bytes, it will be fragmented and multiple calls to this
63 // callback will be made. 88 // callback will be made.
64 class PacketReadyCallback { 89 class PacketReadyCallback {
65 public: 90 public:
66 PacketReadyCallback() {} 91 PacketReadyCallback() {}
67 virtual ~PacketReadyCallback() {} 92 virtual ~PacketReadyCallback() {}
68 93
69 virtual void OnPacketReady(uint8_t* data, size_t length) = 0; 94 virtual void OnPacketReady(uint8_t* data, size_t length) = 0;
70 }; 95 };
71 96
72 // Convenience method mostly used for test. Max length of IP_PACKET_SIZE is 97 // Convenience method mostly used for test. Max length of IP_PACKET_SIZE is
73 // used, will cause assertion error if fragmentation occurs. 98 // used, will cause assertion error if fragmentation occurs.
74 rtc::scoped_ptr<RawPacket> Build() const; 99 rtc::Buffer Build() const;
75 100
76 // Returns true if all calls to Create succeeded. A buffer of size 101 // 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. 102 // IP_PACKET_SIZE will be allocated and reused between calls to callback.
78 bool Build(PacketReadyCallback* callback) const; 103 bool Build(PacketReadyCallback* callback) const;
79 104
80 // Returns true if all calls to Create succeeded. Provided buffer reference 105 // Returns true if all calls to Create succeeded. Provided buffer reference
81 // will be used for all calls to callback. 106 // will be used for all calls to callback.
82 bool BuildExternalBuffer(uint8_t* buffer, 107 bool BuildExternalBuffer(uint8_t* buffer,
83 size_t max_length, 108 size_t max_length,
84 PacketReadyCallback* callback) const; 109 PacketReadyCallback* callback) const;
(...skipping 23 matching lines...) Expand all
108 133
109 static const size_t kHeaderLength = 4; 134 static const size_t kHeaderLength = 4;
110 std::vector<RtcpPacket*> appended_packets_; 135 std::vector<RtcpPacket*> appended_packets_;
111 136
112 private: 137 private:
113 bool CreateAndAddAppended(uint8_t* packet, 138 bool CreateAndAddAppended(uint8_t* packet,
114 size_t* index, 139 size_t* index,
115 size_t max_length, 140 size_t max_length,
116 PacketReadyCallback* callback) const; 141 PacketReadyCallback* callback) const;
117 }; 142 };
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 143 } // namespace rtcp
146 } // namespace webrtc 144 } // namespace webrtc
147 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_ 145 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/rtcp_packet.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698