Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
sdes_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/sdes_traverser.h
10 //! @brief Sdes enums.
11 
12 #ifndef ROC_RTCP_SDES_TRAVERSER_H_
13 #define ROC_RTCP_SDES_TRAVERSER_H_
14 
15 #include "roc_core/slice.h"
16 #include "roc_core/stddefs.h"
17 #include "roc_packet/units.h"
18 #include "roc_rtcp/headers.h"
19 #include "roc_rtcp/sdes.h"
20 
21 namespace roc {
22 namespace rtcp {
23 
24 //! SDES packet traverer.
26 public:
27  //! Packet iterator.
28  class Iterator {
29  public:
30  //! Iterator state.
31  enum State {
32  BEGIN, //!< Iterator created.
33  CHUNK, //!< SDES chunk.
34  ITEM, //!< SDES item.
35  END //!< Parsed whole packet.
36  };
37 
38  //! Advance iterator.
40 
41  //! Get SDES chunk.
42  //! @pre Can be used if next() returned CHUNK.
43  SdesChunk chunk() const;
44 
45  //! Get SDES item.
46  //! Item is valid only until next() call.
47  //! @pre Can be used if next() returned ITEM.
48  SdesItem item() const;
49 
50  private:
51  friend class SdesTraverser;
52 
53  explicit Iterator(const SdesTraverser& traverser);
54  void parse_chunk_();
55  void parse_item_();
56 
57  const SdesTraverser& traverser_;
58 
59  State state_;
61  uint8_t* pcur_;
62  size_t cur_chunk_;
63 
64  packet::stream_source_t parsed_ssrc_;
65  header::SdesItemType parsed_item_type_;
66  char parsed_item_text_[header::SdesItemHeader::MaxTextLen + 1];
67  };
68 
69  //! Initialize traverser.
70  //! It will parse and iterate provided buffer.
71  explicit SdesTraverser(const core::Slice<uint8_t>& data);
72 
73  //! Parse packet from buffer.
74  bool parse();
75 
76  //! Construct iterator.
77  //! @pre Can be used if parse() returned true.
78  Iterator iter() const;
79 
80  //! Get number of SDES chunks in packet.
81  size_t chunks_count() const;
82 
83 private:
84  const core::Slice<uint8_t> data_;
85  bool parsed_;
86  size_t packet_len_;
87  size_t chunks_count_;
88 };
89 
90 } // namespace rtcp
91 } // namespace roc
92 
93 #endif // ROC_RTCP_SDES_TRAVERSER_H_
State next()
Advance iterator.
SdesChunk chunk() const
Get SDES chunk.
SdesItem item() const
Get SDES item. Item is valid only until next() call.
SDES packet traverer.
size_t chunks_count() const
Get number of SDES chunks in packet.
bool parse()
Parse packet from buffer.
SdesTraverser(const core::Slice< uint8_t > &data)
Initialize traverser. It will parse and iterate provided buffer.
Iterator iter() const
Construct iterator.
static const size_t MaxTextLen
Get maximum allowed item text length.
Definition: headers.h:741
uint32_t stream_source_t
Packet stream identifier.
Definition: units.h:27
Root namespace.
RTCP headers.
SdesItemType
SDES item type.
Definition: headers.h:676
SDES elements.
Slice.
Commonly used types and functions.
Parsed SDES chunk.
Definition: sdes.h:23
Parsed SDES item.
Definition: sdes.h:33
Various units used in packets.