1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CAST_STREAMING_SENDER_REPORT_PARSER_H_
6 #define CAST_STREAMING_SENDER_REPORT_PARSER_H_
7 
8 #include "absl/types/optional.h"
9 #include "absl/types/span.h"
10 #include "cast/streaming/rtcp_common.h"
11 #include "cast/streaming/rtcp_session.h"
12 #include "cast/streaming/rtp_defines.h"
13 #include "cast/streaming/rtp_time.h"
14 
15 namespace openscreen {
16 namespace cast {
17 
18 // Parses RTCP packets from a Sender to extract Sender Reports. Ignores anything
19 // else, since that is all a Receiver would be interested in.
20 class SenderReportParser {
21  public:
22   // Returned by Parse(), to also separately expose the StatusReportId. The
23   // report ID isn't included in the common RtcpSenderReport struct because it's
24   // not an input to SenderReportBuilder (it is generated by the builder).
25   struct SenderReportWithId : public RtcpSenderReport {
26     SenderReportWithId();
27     ~SenderReportWithId();
28 
29     StatusReportId report_id{};
30   };
31 
32   explicit SenderReportParser(RtcpSession* session);
33   ~SenderReportParser();
34 
35   // Parses the RTCP |packet|, and returns a parsed sender report if the packet
36   // contained one. Returns nullopt if the data is corrupt or the packet did not
37   // contain a sender report.
38   absl::optional<SenderReportWithId> Parse(absl::Span<const uint8_t> packet);
39 
40  private:
41   RtcpSession* const session_;
42 
43   // Tracks the recently-parsed RTP timestamps so that the truncated values can
44   // be re-expanded into full-form.
45   RtpTimeTicks last_parsed_rtp_timestamp_;
46 };
47 
48 }  // namespace cast
49 }  // namespace openscreen
50 
51 #endif  // CAST_STREAMING_SENDER_REPORT_PARSER_H_
52