| 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 | |
| 12 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_ | 11 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_ |
| 13 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_ | 12 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_ |
| 14 | 13 |
| 14 #include "webrtc/base/basictypes.h" |
| 15 #include "webrtc/base/buffer.h" | 15 #include "webrtc/base/buffer.h" |
| 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | |
| 17 | 16 |
| 18 namespace webrtc { | 17 namespace webrtc { |
| 19 namespace rtcp { | 18 namespace rtcp { |
| 20 // Class for building RTCP packets. | 19 // Class for building RTCP packets. |
| 21 // | 20 // |
| 22 // Example: | 21 // Example: |
| 23 // ReportBlock report_block; | 22 // ReportBlock report_block; |
| 24 // report_block.To(234); | 23 // report_block.To(234); |
| 25 // report_block.WithFractionLost(10); | 24 // report_block.WithFractionLost(10); |
| 26 // | 25 // |
| (...skipping 12 matching lines...) Expand all Loading... |
| 39 // rtc::Buffer packet = fir.Build(); // Returns a RawPacket holding | 38 // rtc::Buffer packet = fir.Build(); // Returns a RawPacket holding |
| 40 // // the built rtcp packet. | 39 // // the built rtcp packet. |
| 41 // | 40 // |
| 42 // CompoundPacket compound; // Builds a compound RTCP packet with | 41 // CompoundPacket compound; // Builds a compound RTCP packet with |
| 43 // compound.Append(&rr); // a receiver report, report block | 42 // compound.Append(&rr); // a receiver report, report block |
| 44 // compound.Append(&fir); // and fir message. | 43 // compound.Append(&fir); // and fir message. |
| 45 // rtc::Buffer packet = compound.Build(); | 44 // rtc::Buffer packet = compound.Build(); |
| 46 | 45 |
| 47 class RtcpPacket { | 46 class RtcpPacket { |
| 48 public: | 47 public: |
| 49 virtual ~RtcpPacket() {} | |
| 50 | |
| 51 // Callback used to signal that an RTCP packet is ready. Note that this may | 48 // Callback used to signal that an RTCP packet is ready. Note that this may |
| 52 // not contain all data in this RtcpPacket; if a packet cannot fit in | 49 // not contain all data in this RtcpPacket; if a packet cannot fit in |
| 53 // max_length bytes, it will be fragmented and multiple calls to this | 50 // max_length bytes, it will be fragmented and multiple calls to this |
| 54 // callback will be made. | 51 // callback will be made. |
| 55 class PacketReadyCallback { | 52 class PacketReadyCallback { |
| 56 public: | 53 public: |
| 54 virtual void OnPacketReady(uint8_t* data, size_t length) = 0; |
| 55 |
| 56 protected: |
| 57 PacketReadyCallback() {} | 57 PacketReadyCallback() {} |
| 58 virtual ~PacketReadyCallback() {} | 58 virtual ~PacketReadyCallback() {} |
| 59 | |
| 60 virtual void OnPacketReady(uint8_t* data, size_t length) = 0; | |
| 61 }; | 59 }; |
| 62 | 60 |
| 63 // Convenience method mostly used for test. Max length of IP_PACKET_SIZE is | 61 virtual ~RtcpPacket() {} |
| 64 // used, will cause assertion error if fragmentation occurs. | 62 |
| 63 // Convenience method mostly used for test. Creates packet without |
| 64 // fragmentation using BlockLength() to allocate big enough buffer. |
| 65 rtc::Buffer Build() const; | 65 rtc::Buffer Build() const; |
| 66 | 66 |
| 67 // Returns true if call to Create succeeded. A buffer of size | |
| 68 // IP_PACKET_SIZE will be allocated and reused between calls to callback. | |
| 69 bool Build(PacketReadyCallback* callback) const; | |
| 70 | |
| 71 // Returns true if call to Create succeeded. Provided buffer reference | 67 // Returns true if call to Create succeeded. Provided buffer reference |
| 72 // will be used for all calls to callback. | 68 // will be used for all calls to callback. |
| 73 bool BuildExternalBuffer(uint8_t* buffer, | 69 bool BuildExternalBuffer(uint8_t* buffer, |
| 74 size_t max_length, | 70 size_t max_length, |
| 75 PacketReadyCallback* callback) const; | 71 PacketReadyCallback* callback) const; |
| 76 | 72 |
| 77 // Size of this packet in bytes (including headers). | 73 // Size of this packet in bytes (including headers). |
| 78 virtual size_t BlockLength() const = 0; | 74 virtual size_t BlockLength() const = 0; |
| 79 | 75 |
| 80 // Creates packet in the given buffer at the given position. | 76 // Creates packet in the given buffer at the given position. |
| 81 // Calls PacketReadyCallback::OnPacketReady if remaining buffer is too small | 77 // Calls PacketReadyCallback::OnPacketReady if remaining buffer is too small |
| 82 // and assume buffer can be reused after OnPacketReady returns. | 78 // and assume buffer can be reused after OnPacketReady returns. |
| 83 virtual bool Create(uint8_t* packet, | 79 virtual bool Create(uint8_t* packet, |
| 84 size_t* index, | 80 size_t* index, |
| 85 size_t max_length, | 81 size_t max_length, |
| 86 PacketReadyCallback* callback) const = 0; | 82 PacketReadyCallback* callback) const = 0; |
| 87 | 83 |
| 88 protected: | 84 protected: |
| 85 // Size of the rtcp common header. |
| 86 static constexpr size_t kHeaderLength = 4; |
| 89 RtcpPacket() {} | 87 RtcpPacket() {} |
| 90 | 88 |
| 91 static void CreateHeader(uint8_t count_or_format, | 89 static void CreateHeader(uint8_t count_or_format, |
| 92 uint8_t packet_type, | 90 uint8_t packet_type, |
| 93 size_t block_length, // Size in 32bit words - 1. | 91 size_t block_length, // Payload size in 32bit words. |
| 94 uint8_t* buffer, | 92 uint8_t* buffer, |
| 95 size_t* pos); | 93 size_t* pos); |
| 96 | 94 |
| 97 bool OnBufferFull(uint8_t* packet, | 95 bool OnBufferFull(uint8_t* packet, |
| 98 size_t* index, | 96 size_t* index, |
| 99 RtcpPacket::PacketReadyCallback* callback) const; | 97 PacketReadyCallback* callback) const; |
| 100 | 98 // Size of the rtcp packet as written in header. |
| 101 size_t HeaderLength() const; | 99 size_t HeaderLength() const; |
| 102 | |
| 103 static const size_t kHeaderLength = 4; | |
| 104 }; | 100 }; |
| 105 } // namespace rtcp | 101 } // namespace rtcp |
| 106 } // namespace webrtc | 102 } // namespace webrtc |
| 107 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_ | 103 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_H_ |
| OLD | NEW |