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

Unified Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet/parsing_container.h

Issue 1555683002: [Draft] RTCP Parser sketched. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: fix RtcpParser* tests Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/rtp_rtcp/source/rtcp_packet/parsing_container.h
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/parsing_container.h b/webrtc/modules/rtp_rtcp/source/rtcp_packet/parsing_container.h
new file mode 100644
index 0000000000000000000000000000000000000000..e93edf5cbd0434e25c822bd78e17806578fdaaa4
--- /dev/null
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/parsing_container.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ *
+ */
+
+#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_PARSING_CONTAINER_H_
+#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_PARSING_CONTAINER_H_
+
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
+
+namespace webrtc {
+namespace rtcp {
+/* ParsingContainer, with help of ParsingPacket class make raw buffer
+ look like container of Packets, i.e. foreach loop can be used on this class
+ Used in Sample2 only.
+*/
+
+class ParsingContainer {
+ public:
+ class value_type : public CommonHeader {
+ public:
+ bool valid() const { return valid_; }
+ bool Parse(const uint8_t* buffer, size_t length) {
+ return valid_ = CommonHeader::Parse(buffer, length);
+ }
+
+ private:
+ bool valid_ = false;
+ };
+
+ class const_iterator {
+ public:
+ const_iterator(const uint8_t* buffer, size_t length)
+ : buffer_end_(buffer + length) {
+ packet_.Parse(buffer, length);
+ }
+ bool operator==(const const_iterator& other) {
+ if (!packet_.valid() && !other.packet_.valid())
+ // All invalid headers are the same.
+ return true;
+ return
+ packet_.valid() == other.packet_.valid() &&
+ packet_.payload() == other.packet_.payload();
+ }
+ bool operator!=(const const_iterator& other) { return !(*this == other); }
+ const_iterator& operator++() {
+ if (!packet_.valid()) {
+ packet_.Parse(buffer_end_, 0);
+ } else {
+ const uint8_t* next_packet = packet_.NextPacket();
+ packet_.Parse(next_packet, buffer_end_ - next_packet);
+ }
+ return *this;
+ }
+ const value_type& operator*() const { return packet_; }
+ const value_type* operator->() const { return &packet_; }
+
+ private:
+ value_type packet_;
+ const uint8_t* buffer_end_;
+ };
+ ParsingContainer(const uint8_t* buffer, size_t length)
+ : begin_(buffer), length_(length) {}
+ const_iterator begin() const { return const_iterator(begin_, length_); }
+ const_iterator end() const { return const_iterator(begin_ + length_, 0); }
+
+ private:
+ const uint8_t* begin_ = nullptr;
+ const size_t length_ = 0;
+};
+
+} // namespace rtcp
+} // namespace webrtc
+#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_PARSING_CONTAINER_H_
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.cc ('k') | webrtc/modules/rtp_rtcp/source/sample_parser_unittest1.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698