OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 * |
| 10 */ |
| 11 |
| 12 #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_PARSING_CONTAINER_H_ |
| 13 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_PARSING_CONTAINER_H_ |
| 14 |
| 15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
| 16 |
| 17 namespace webrtc { |
| 18 namespace rtcp { |
| 19 /* ParsingContainer, with help of ParsingPacket class make raw buffer |
| 20 look like container of Packets, i.e. foreach loop can be used on this class |
| 21 Used in Sample2 only. |
| 22 */ |
| 23 |
| 24 class ParsingContainer { |
| 25 public: |
| 26 class value_type : public CommonHeader { |
| 27 public: |
| 28 bool valid() const { return valid_; } |
| 29 bool Parse(const uint8_t* buffer, size_t length) { |
| 30 return valid_ = CommonHeader::Parse(buffer, length); |
| 31 } |
| 32 |
| 33 private: |
| 34 bool valid_ = false; |
| 35 }; |
| 36 |
| 37 class const_iterator { |
| 38 public: |
| 39 const_iterator(const uint8_t* buffer, size_t length) |
| 40 : buffer_end_(buffer + length) { |
| 41 packet_.Parse(buffer, length); |
| 42 } |
| 43 bool operator==(const const_iterator& other) { |
| 44 if (!packet_.valid() && !other.packet_.valid()) |
| 45 // All invalid headers are the same. |
| 46 return true; |
| 47 return |
| 48 packet_.valid() == other.packet_.valid() && |
| 49 packet_.payload() == other.packet_.payload(); |
| 50 } |
| 51 bool operator!=(const const_iterator& other) { return !(*this == other); } |
| 52 const_iterator& operator++() { |
| 53 if (!packet_.valid()) { |
| 54 packet_.Parse(buffer_end_, 0); |
| 55 } else { |
| 56 const uint8_t* next_packet = packet_.NextPacket(); |
| 57 packet_.Parse(next_packet, buffer_end_ - next_packet); |
| 58 } |
| 59 return *this; |
| 60 } |
| 61 const value_type& operator*() const { return packet_; } |
| 62 const value_type* operator->() const { return &packet_; } |
| 63 |
| 64 private: |
| 65 value_type packet_; |
| 66 const uint8_t* buffer_end_; |
| 67 }; |
| 68 ParsingContainer(const uint8_t* buffer, size_t length) |
| 69 : begin_(buffer), length_(length) {} |
| 70 const_iterator begin() const { return const_iterator(begin_, length_); } |
| 71 const_iterator end() const { return const_iterator(begin_ + length_, 0); } |
| 72 |
| 73 private: |
| 74 const uint8_t* begin_ = nullptr; |
| 75 const size_t length_ = 0; |
| 76 }; |
| 77 |
| 78 } // namespace rtcp |
| 79 } // namespace webrtc |
| 80 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_PARSING_CONTAINER_H_ |
OLD | NEW |