Index: webrtc/modules/rtp_rtcp/source/sample_rtcp_parser2.h |
diff --git a/webrtc/modules/rtp_rtcp/source/sample_rtcp_parser2.h b/webrtc/modules/rtp_rtcp/source/sample_rtcp_parser2.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d26fa9e6ab2b4fa96440e714c78a820248b1bc6d |
--- /dev/null |
+++ b/webrtc/modules/rtp_rtcp/source/sample_rtcp_parser2.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_SAMPLE_RTCP_PARSER2_H_ |
+#define WEBRTC_MODULES_RTP_RTCP_SOURCE_SAMPLE_RTCP_PARSER2_H_ |
+ |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/parsing_container.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" |
+ |
+namespace webrtc { |
+namespace rtcp { |
+/* Parser that rely on ParsingContainer that wraps CommonHeader in it. */ |
+ |
+class Parser2 { |
+ public: |
+ void Parse(const uint8_t* buffer, size_t length) { |
+ for (const auto& header : ParsingContainer(buffer, length)) { |
+ ParseIndividual(header); |
+ } |
+ } |
+ |
+ protected: |
+ virtual ~Parser2() {} |
+ virtual void HandleApp(const App&) {} |
+ virtual void HandleBye(const Bye&) {} |
+ virtual void HandlePli(const Pli&) {} |
+ virtual void HandleUnknown(const CommonHeader&) {} |
+ virtual void HandleInvalid() {} |
+ |
+ private: |
+ inline void HandleParsed(const App& app) { HandleApp(app); } |
+ inline void HandleParsed(const Bye& bye) { HandleBye(bye); } |
+ inline void HandleParsed(const Pli& pli) { HandlePli(pli); } |
+ |
+ template <typename TypedPacket> |
+ void HandleUnparsed(const CommonHeader& packet) { |
+ TypedPacket parsed; |
+ if (!parsed.Parse(packet)) |
+ HandleInvalid(); |
+ else |
+ HandleParsed(parsed); |
+ } |
+ |
+ void ParseIndividual(const CommonHeader& header) { |
+ switch (header.type()) { |
+ case App::kPacketType: |
+ HandleUnparsed<App>(header); |
+ break; |
+ case Bye::kPacketType: |
+ HandleUnparsed<Bye>(header); |
+ break; |
+ case Psfb::kPacketType: |
+ switch (header.fmt()) { |
+ case Pli::kFeedbackMessageType: |
+ HandleUnparsed<Pli>(header); |
+ break; |
+ default: |
+ HandleUnknown(header); |
+ break; |
+ } |
+ break; |
+ default: |
+ HandleUnknown(header); |
+ break; |
+ } |
+ } |
+}; |
+} // namespace rtcp |
+} // namespace webrtc |
+#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_SAMPLE_RTCP_PARSER2_H_ |