OLD | NEW |
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> | |
16 | |
17 #include "webrtc/base/buffer.h" | 15 #include "webrtc/base/buffer.h" |
18 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
19 #include "webrtc/typedefs.h" | |
20 | 17 |
21 namespace webrtc { | 18 namespace webrtc { |
22 namespace rtcp { | 19 namespace rtcp { |
23 | |
24 static const int kCommonFbFmtLength = 12; | |
25 | |
26 // Class for building RTCP packets. | 20 // Class for building RTCP packets. |
27 // | 21 // |
28 // Example: | 22 // Example: |
29 // ReportBlock report_block; | 23 // ReportBlock report_block; |
30 // report_block.To(234); | 24 // report_block.To(234); |
31 // report_block.WithFractionLost(10); | 25 // report_block.WithFractionLost(10); |
32 // | 26 // |
33 // ReceiverReport rr; | 27 // ReceiverReport rr; |
34 // rr.From(123); | 28 // rr.From(123); |
35 // rr.WithReportBlock(report_block); | 29 // rr.WithReportBlock(report_block); |
36 // | 30 // |
37 // Fir fir; | 31 // Fir fir; |
38 // fir.From(123); | 32 // fir.From(123); |
39 // fir.WithRequestTo(234, 56); | 33 // fir.WithRequestTo(234, 56); |
40 // | 34 // |
41 // size_t length = 0; // Builds an intra frame request | 35 // size_t length = 0; // Builds an intra frame request |
42 // uint8_t packet[kPacketSize]; // with sequence number 56. | 36 // uint8_t packet[kPacketSize]; // with sequence number 56. |
43 // fir.Build(packet, &length, kPacketSize); | 37 // fir.Build(packet, &length, kPacketSize); |
44 // | 38 // |
45 // rtc::Buffer packet = fir.Build(); // Returns a RawPacket holding | 39 // rtc::Buffer packet = fir.Build(); // Returns a RawPacket holding |
46 // // the built rtcp packet. | 40 // // the built rtcp packet. |
47 // | 41 // |
48 // rr.Append(&fir); // Builds a compound RTCP packet with | 42 // CompoundPacket compound; // Builds a compound RTCP packet with |
49 // rtc::Buffer packet = rr.Build(); // a receiver report, report block | 43 // compound.Append(&rr); // a receiver report, report block |
50 // // and fir message. | 44 // compound.Append(&fir); // and fir message. |
| 45 // rtc::Buffer packet = compound.Build(); |
51 | 46 |
52 class RtcpPacket { | 47 class RtcpPacket { |
53 public: | 48 public: |
54 virtual ~RtcpPacket() {} | 49 virtual ~RtcpPacket() {} |
55 | 50 |
56 void Append(RtcpPacket* packet); | |
57 | |
58 // Callback used to signal that an RTCP packet is ready. Note that this may | 51 // Callback used to signal that an RTCP packet is ready. Note that this may |
59 // not contain all data in this RtcpPacket; if a packet cannot fit in | 52 // not contain all data in this RtcpPacket; if a packet cannot fit in |
60 // max_length bytes, it will be fragmented and multiple calls to this | 53 // max_length bytes, it will be fragmented and multiple calls to this |
61 // callback will be made. | 54 // callback will be made. |
62 class PacketReadyCallback { | 55 class PacketReadyCallback { |
63 public: | 56 public: |
64 PacketReadyCallback() {} | 57 PacketReadyCallback() {} |
65 virtual ~PacketReadyCallback() {} | 58 virtual ~PacketReadyCallback() {} |
66 | 59 |
67 virtual void OnPacketReady(uint8_t* data, size_t length) = 0; | 60 virtual void OnPacketReady(uint8_t* data, size_t length) = 0; |
68 }; | 61 }; |
69 | 62 |
70 // Convenience method mostly used for test. Max length of IP_PACKET_SIZE is | 63 // Convenience method mostly used for test. Max length of IP_PACKET_SIZE is |
71 // used, will cause assertion error if fragmentation occurs. | 64 // used, will cause assertion error if fragmentation occurs. |
72 rtc::Buffer Build() const; | 65 rtc::Buffer Build() const; |
73 | 66 |
74 // Returns true if all calls to Create succeeded. A buffer of size | 67 // Returns true if call to Create succeeded. A buffer of size |
75 // IP_PACKET_SIZE will be allocated and reused between calls to callback. | 68 // IP_PACKET_SIZE will be allocated and reused between calls to callback. |
76 bool Build(PacketReadyCallback* callback) const; | 69 bool Build(PacketReadyCallback* callback) const; |
77 | 70 |
78 // Returns true if all calls to Create succeeded. Provided buffer reference | 71 // Returns true if call to Create succeeded. Provided buffer reference |
79 // will be used for all calls to callback. | 72 // will be used for all calls to callback. |
80 bool BuildExternalBuffer(uint8_t* buffer, | 73 bool BuildExternalBuffer(uint8_t* buffer, |
81 size_t max_length, | 74 size_t max_length, |
82 PacketReadyCallback* callback) const; | 75 PacketReadyCallback* callback) const; |
83 | 76 |
84 // Size of this packet in bytes (including headers, excluding nested packets). | 77 // Size of this packet in bytes (including headers). |
85 virtual size_t BlockLength() const = 0; | 78 virtual size_t BlockLength() const = 0; |
86 | 79 |
87 protected: | 80 // Creates packet in the given buffer at the given position. |
88 RtcpPacket() {} | 81 // Calls PacketReadyCallback::OnPacketReady if remaining buffer is too small |
89 | 82 // and assume buffer can be reused after OnPacketReady returns. |
90 virtual bool Create(uint8_t* packet, | 83 virtual bool Create(uint8_t* packet, |
91 size_t* index, | 84 size_t* index, |
92 size_t max_length, | 85 size_t max_length, |
93 PacketReadyCallback* callback) const = 0; | 86 PacketReadyCallback* callback) const = 0; |
94 | 87 |
| 88 protected: |
| 89 RtcpPacket() {} |
| 90 |
95 static void CreateHeader(uint8_t count_or_format, | 91 static void CreateHeader(uint8_t count_or_format, |
96 uint8_t packet_type, | 92 uint8_t packet_type, |
97 size_t block_length, // Size in 32bit words - 1. | 93 size_t block_length, // Size in 32bit words - 1. |
98 uint8_t* buffer, | 94 uint8_t* buffer, |
99 size_t* pos); | 95 size_t* pos); |
100 | 96 |
101 bool OnBufferFull(uint8_t* packet, | 97 bool OnBufferFull(uint8_t* packet, |
102 size_t* index, | 98 size_t* index, |
103 RtcpPacket::PacketReadyCallback* callback) const; | 99 RtcpPacket::PacketReadyCallback* callback) const; |
104 | 100 |
105 size_t HeaderLength() const; | 101 size_t HeaderLength() const; |
106 | 102 |
107 static const size_t kHeaderLength = 4; | 103 static const size_t kHeaderLength = 4; |
108 std::vector<RtcpPacket*> appended_packets_; | |
109 | |
110 private: | |
111 bool CreateAndAddAppended(uint8_t* packet, | |
112 size_t* index, | |
113 size_t max_length, | |
114 PacketReadyCallback* callback) const; | |
115 }; | 104 }; |
116 } // namespace rtcp | 105 } // namespace rtcp |
117 } // namespace webrtc | 106 } // namespace webrtc |
118 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_ | 107 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_ |
OLD | NEW |