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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/sample_rtcp_parser1.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 unified diff | Download patch
OLDNEW
(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_SAMPLE_RTCP_PARSER1_H_
13 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_SAMPLE_RTCP_PARSER1_H_
14
15 #include "webrtc/base/checks.h"
16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h"
17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h"
18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
19 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h"
20
21 namespace webrtc {
22 namespace rtcp {
23 /* Parser with callback with a function per packet type */
24
25 class Parser1 {
26 public:
27 class Handler {
28 public:
29 virtual bool HandleApp(const App&) { return false; }
30 virtual bool HandleBye(const Bye&) { return false; }
31 virtual bool HandlePli(const Pli&) { return false; }
32 virtual void HandleUnknown(const CommonHeader&) {}
33 virtual void HandleInvalid() {}
34
35 protected:
36 virtual ~Handler() = default;
37 };
38
39 static void Parse(const uint8_t* buffer, size_t length, Handler* handler) {
40 RTC_DCHECK(handler);
41 const uint8_t* const buffer_end = buffer + length;
42 CommonHeader header;
43 for (const uint8_t* next_packet = buffer;
44 RTC_DCHECK(next_packet <= buffer_end), next_packet != buffer_end;
45 next_packet = header.NextPacket()) {
46 if (!header.Parse(next_packet, buffer_end - next_packet)) {
47 handler->HandleInvalid();
48 break;
49 }
50 ParseIndividual(header, handler);
51 }
52 }
53
54 private:
55 inline static bool HandleParsed(const App& app, Handler* handler) {
56 return handler->HandleApp(app);
57 }
58 inline static bool HandleParsed(const Bye& bye, Handler* handler) {
59 return handler->HandleBye(bye);
60 }
61 inline static bool HandleParsed(const Pli& pli, Handler* handler) {
62 return handler->HandlePli(pli);
63 }
64
65 template <typename TypedPacket>
66 static void HandleUnparsed(const CommonHeader& packet, Handler* handler) {
67 TypedPacket parsed;
68 if (!parsed.Parse(packet) || !HandleParsed(parsed, handler))
69 handler->HandleUnknown(packet);
70 }
71
72 static void ParseIndividual(const CommonHeader& header, Handler* handler) {
73 switch (header.type()) {
74 case App::kPacketType:
75 HandleUnparsed<App>(header, handler);
76 break;
77 case Bye::kPacketType:
78 HandleUnparsed<Bye>(header, handler);
79 break;
80 case Psfb::kPacketType:
81 switch (header.fmt()) {
82 case Pli::kFeedbackMessageType:
83 HandleUnparsed<Pli>(header, handler);
84 break;
85 default:
86 handler->HandleUnknown(header);
87 break;
88 }
89 break;
90 default:
91 handler->HandleUnknown(header);
92 break;
93 }
94 }
95 };
96 } // namespace rtcp
97 } // namespace webrtc
98 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_SAMPLE_RTCP_PARSER1_H_
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/sample_parser_unittest4.cc ('k') | webrtc/modules/rtp_rtcp/source/sample_rtcp_parser2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698