• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BUILDER_H_
6 #define CAST_STREAMING_SENDER_REPORT_BUILDER_H_
7 
8 #include <stdint.h>
9 
10 #include <utility>
11 
12 #include "absl/types/span.h"
13 #include "cast/streaming/rtcp_common.h"
14 #include "cast/streaming/rtcp_session.h"
15 #include "cast/streaming/rtp_defines.h"
16 #include "platform/api/time.h"
17 
18 namespace openscreen {
19 namespace cast {
20 
21 // Builds RTCP packets containing one Sender Report.
22 class SenderReportBuilder {
23  public:
24   explicit SenderReportBuilder(RtcpSession* session);
25   ~SenderReportBuilder();
26 
27   // Serializes the given |sender_report| as a RTCP packet and writes it to
28   // |buffer| (which must be kRequiredBufferSize in size). Returns the subspan
29   // of |buffer| that contains the result and a StatusReportId the receiver
30   // might use in its own reports to reference this specific report.
31   std::pair<absl::Span<uint8_t>, StatusReportId> BuildPacket(
32       const RtcpSenderReport& sender_report,
33       absl::Span<uint8_t> buffer) const;
34 
35   // Returns the approximate reference time from a recently-built Sender Report,
36   // based on the given |report_id| and maximum possible reference time.
37   Clock::time_point GetRecentReportTime(StatusReportId report_id,
38                                         Clock::time_point on_or_before) const;
39 
40   // The required size (in bytes) of the buffer passed to BuildPacket().
41   static constexpr int kRequiredBufferSize =
42       kRtcpCommonHeaderSize + kRtcpSenderReportSize + kRtcpReportBlockSize;
43 
44  private:
45   RtcpSession* const session_;
46 };
47 
48 }  // namespace cast
49 }  // namespace openscreen
50 
51 #endif  // CAST_STREAMING_SENDER_REPORT_BUILDER_H_
52