Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
21namespace roc {
22namespace rtcp {
23
24//! SDES packet traverer.
26public:
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 //! Check if there were any parsing errors.
42 bool error() const;
43
44 //! Get SDES chunk.
45 //! @pre Can be used if next() returned CHUNK.
47
48 //! Get SDES item.
49 //! Item is valid only until next() call.
50 //! @pre Can be used if next() returned ITEM.
52
53 private:
54 friend class SdesTraverser;
55
56 explicit Iterator(const SdesTraverser& traverser);
57 void next_element_();
58 void parse_chunk_();
59 void parse_item_();
60
61 const SdesTraverser& traverser_;
62
63 State state_;
64 const core::Slice<uint8_t> buf_;
65 size_t cur_pos_;
66 size_t cur_chunk_;
67 const header::SdesItemHeader* cur_item_header_;
68 size_t cur_item_len_;
69 bool error_;
70
71 packet::stream_source_t parsed_ssrc_;
72 header::SdesItemType parsed_item_type_;
73 char parsed_item_text_[header::MaxTextLen + 1];
74 };
75
76 //! Initialize traverser.
77 //! It will parse and iterate provided buffer.
78 explicit SdesTraverser(const core::Slice<uint8_t>& buf);
79
80 //! Parse packet from buffer.
81 bool parse();
82
83 //! Construct iterator.
84 //! @pre Can be used if parse() returned true.
85 Iterator iter() const;
86
87 //! Get number of SDES chunks in packet.
88 size_t chunks_count() const;
89
90private:
92 bool parsed_;
93 size_t chunks_count_;
94};
95
96} // namespace rtcp
97} // namespace roc
98
99#endif // ROC_RTCP_SDES_TRAVERSER_H_
Shared ownership intrusive pointer.
Definition shared_ptr.h:32
State next()
Advance iterator.
SdesItem get_item() const
Get SDES item. Item is valid only until next() call.
bool error() const
Check if there were any parsing errors.
SdesChunk get_chunk() const
Get SDES chunk.
SDES packet traverer.
size_t chunks_count() const
Get number of SDES chunks in packet.
SdesTraverser(const core::Slice< uint8_t > &buf)
Initialize traverser. It will parse and iterate provided buffer.
bool parse()
Parse packet from buffer.
Iterator iter() const
Construct iterator.
uint32_t stream_source_t
Packet stream identifier.
Definition units.h:27
Root namespace.
RTCP headers.
SdesItemType
SDES item type.
Definition headers.h:725
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.