Index: webrtc/modules/rtp_rtcp/source/sample_rtcp_parser1.h |
diff --git a/webrtc/modules/rtp_rtcp/source/sample_rtcp_parser1.h b/webrtc/modules/rtp_rtcp/source/sample_rtcp_parser1.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d5295af352391027ecacadff6b42755966caeda8 |
--- /dev/null |
+++ b/webrtc/modules/rtp_rtcp/source/sample_rtcp_parser1.h |
@@ -0,0 +1,98 @@ |
+/* |
+ * 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_PARSER1_H_ |
+#define WEBRTC_MODULES_RTP_RTCP_SOURCE_SAMPLE_RTCP_PARSER1_H_ |
+ |
+#include "webrtc/base/checks.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/common_header.h" |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" |
+ |
+namespace webrtc { |
+namespace rtcp { |
+/* Parser with callback with a function per packet type */ |
+ |
+class Parser1 { |
+ public: |
+ class Handler { |
+ public: |
+ virtual bool HandleApp(const App&) { return false; } |
+ virtual bool HandleBye(const Bye&) { return false; } |
+ virtual bool HandlePli(const Pli&) { return false; } |
+ virtual void HandleUnknown(const CommonHeader&) {} |
+ virtual void HandleInvalid() {} |
+ |
+ protected: |
+ virtual ~Handler() = default; |
+ }; |
+ |
+ static void Parse(const uint8_t* buffer, size_t length, Handler* handler) { |
+ RTC_DCHECK(handler); |
+ const uint8_t* const buffer_end = buffer + length; |
+ CommonHeader header; |
+ for (const uint8_t* next_packet = buffer; |
+ RTC_DCHECK(next_packet <= buffer_end), next_packet != buffer_end; |
+ next_packet = header.NextPacket()) { |
+ if (!header.Parse(next_packet, buffer_end - next_packet)) { |
+ handler->HandleInvalid(); |
+ break; |
+ } |
+ ParseIndividual(header, handler); |
+ } |
+ } |
+ |
+ private: |
+ inline static bool HandleParsed(const App& app, Handler* handler) { |
+ return handler->HandleApp(app); |
+ } |
+ inline static bool HandleParsed(const Bye& bye, Handler* handler) { |
+ return handler->HandleBye(bye); |
+ } |
+ inline static bool HandleParsed(const Pli& pli, Handler* handler) { |
+ return handler->HandlePli(pli); |
+ } |
+ |
+ template <typename TypedPacket> |
+ static void HandleUnparsed(const CommonHeader& packet, Handler* handler) { |
+ TypedPacket parsed; |
+ if (!parsed.Parse(packet) || !HandleParsed(parsed, handler)) |
+ handler->HandleUnknown(packet); |
+ } |
+ |
+ static void ParseIndividual(const CommonHeader& header, Handler* handler) { |
+ switch (header.type()) { |
+ case App::kPacketType: |
+ HandleUnparsed<App>(header, handler); |
+ break; |
+ case Bye::kPacketType: |
+ HandleUnparsed<Bye>(header, handler); |
+ break; |
+ case Psfb::kPacketType: |
+ switch (header.fmt()) { |
+ case Pli::kFeedbackMessageType: |
+ HandleUnparsed<Pli>(header, handler); |
+ break; |
+ default: |
+ handler->HandleUnknown(header); |
+ break; |
+ } |
+ break; |
+ default: |
+ handler->HandleUnknown(header); |
+ break; |
+ } |
+ } |
+}; |
+} // namespace rtcp |
+} // namespace webrtc |
+#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_SAMPLE_RTCP_PARSER1_H_ |