Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
xr_traverser.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_rtcp/xr_traverser.h
10 //! @brief XR Traverser.
11 
12 #ifndef ROC_RTCP_XR_TRAVERSER_H_
13 #define ROC_RTCP_XR_TRAVERSER_H_
14 
15 #include "roc_core/slice.h"
16 #include "roc_core/stddefs.h"
17 #include "roc_rtcp/headers.h"
18 
19 namespace roc {
20 namespace rtcp {
21 
22 //! XR packet traverser.
23 class XrTraverser {
24 public:
25  //! Packet iterator.
26  class Iterator {
27  public:
28  //! Iterator state.
29  enum State {
30  BEGIN, //!< Iterator created.
31  RRTR_BLOCK, //!< RRTR block (receiver reference time).
32  DLRR_BLOCK, //!< DLRR block (delay since last receiver report).
33  MEASUREMENT_INFO_BLOCK, //!< Measurement information block.
34  DELAY_METRICS_BLOCK, //!< Delay metrics block.
35  QUEUE_METRICS_BLOCK, //!< Queue metrics block.
36  END //!< Parsed whole packet.
37  };
38 
39  //! Advance iterator.
41 
42  //! Check if there were any parsing errors.
43  bool error() const;
44 
45  //! Get RRTR block (receiver reference time).
46  //! @pre Can be used if next() returned RRTR_BLOCK.
47  const header::XrRrtrBlock& get_rrtr() const;
48 
49  //! Get DLRR block (delay since last receiver report).
50  //! @pre Can be used if next() returned DLRR_BLOCK.
51  const header::XrDlrrBlock& get_dlrr() const;
52 
53  //! Get measurement info block.
54  //! @pre Can be used if next() returned RRTR_MEASUREMENT_INFO_BLOCK
56 
57  //! Get delay metrics block.
58  //! @pre Can be used if next() returned DELAY_METRICS_BLOCK
60 
61  //! Get queue metrics block.
62  //! @pre Can be used if next() returned QUEUE_METRICS_BLOCK
64 
65  private:
66  friend class XrTraverser;
67 
68  explicit Iterator(const XrTraverser& traverser);
69  void next_block_();
70  bool check_rrtr_();
71  bool check_dlrr_();
72  bool check_measurement_info_();
73  bool check_delay_metrics_();
74  bool check_queue_metrics_();
75 
76  State state_;
77  const core::Slice<uint8_t> buf_;
78  size_t cur_pos_;
79  const header::XrBlockHeader* cur_blk_header_;
80  size_t cur_blk_len_;
81  bool error_;
82  };
83 
84  //! Initialize traverser.
85  //! It will parse and iterate provided buffer.
86  explicit XrTraverser(const core::Slice<uint8_t>& buf);
87 
88  //! Parse packet from buffer.
89  bool parse();
90 
91  //! Construct iterator.
92  //! @pre Can be used if parse() returned true.
93  Iterator iter() const;
94 
95  //! Get number of XR blocks in packet.
96  size_t blocks_count() const;
97 
98  //! Get XR packet.
99  const header::XrPacket& packet() const;
100 
101 private:
103  bool parsed_;
104  size_t blocks_count_;
105 };
106 
107 } // namespace rtcp
108 } // namespace roc
109 
110 #endif // ROC_RTCP_XR_TRAVERSER_H_
State next()
Advance iterator.
const header::XrMeasurementInfoBlock & get_measurement_info() const
Get measurement info block.
bool error() const
Check if there were any parsing errors.
const header::XrDelayMetricsBlock & get_delay_metrics() const
Get delay metrics block.
@ DLRR_BLOCK
DLRR block (delay since last receiver report).
Definition: xr_traverser.h:32
@ DELAY_METRICS_BLOCK
Delay metrics block.
Definition: xr_traverser.h:34
@ RRTR_BLOCK
RRTR block (receiver reference time).
Definition: xr_traverser.h:31
@ END
Parsed whole packet.
Definition: xr_traverser.h:36
@ MEASUREMENT_INFO_BLOCK
Measurement information block.
Definition: xr_traverser.h:33
@ QUEUE_METRICS_BLOCK
Queue metrics block.
Definition: xr_traverser.h:35
const header::XrQueueMetricsBlock & get_queue_metrics() const
Get queue metrics block.
const header::XrDlrrBlock & get_dlrr() const
Get DLRR block (delay since last receiver report).
const header::XrRrtrBlock & get_rrtr() const
Get RRTR block (receiver reference time).
XR packet traverser.
Definition: xr_traverser.h:23
const header::XrPacket & packet() const
Get XR packet.
bool parse()
Parse packet from buffer.
size_t blocks_count() const
Get number of XR blocks in packet.
Iterator iter() const
Construct iterator.
XrTraverser(const core::Slice< uint8_t > &buf)
Initialize traverser. It will parse and iterate provided buffer.
XR Delay Metrics Block.
Definition: headers.h:1515
XR DLRR Report block.
Definition: headers.h:1303
XR Measurement Info Report Block.
Definition: headers.h:1373
RTCP Extended Report Packet.
Definition: headers.h:1035
XR Queue Metrics Block.
Definition: headers.h:1668
XR Receiver Reference Time Report block.
Definition: headers.h:1174
Root namespace.
RTCP headers.
Slice.
Commonly used types and functions.