Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
interleaver.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 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_packet/interleaver.h
10//! @brief Interleaves packets before transmit.
11
12#ifndef ROC_PACKET_INTERLEAVER_H_
13#define ROC_PACKET_INTERLEAVER_H_
14
15#include "roc_core/array.h"
16#include "roc_core/iarena.h"
18#include "roc_packet/iwriter.h"
19#include "roc_packet/packet.h"
20
21namespace roc {
22namespace packet {
23
24//! Interleaves packets to transmit them in pseudo random order.
25class Interleaver : public IWriter, public core::NonCopyable<> {
26public:
27 //! Initialize.
28 //! @remarks
29 //! Interleaver reorders packets passed to write() and writes
30 //! them to @p output.
31 Interleaver(IWriter& writer, core::IArena& arena, size_t block_size);
32
33 //! Check if object is successfully constructed.
34 bool is_valid() const;
35
36 //! Write next packet.
37 //! @remarks
38 //! Packets are written to internal buffer. Buffered packets are
39 //! then reordered and sent to output writer.
41
42 //! Send all buffered packets to output writer.
44
45 //! Maximum delay between writing packet and moment we get it in output
46 //! in terms of packets number.
47 size_t block_size() const;
48
49private:
50 //! Initialize tx_seq_ to a new randomized sequence.
51 void reinit_seq_();
52
53 // Output writer.
54 IWriter& writer_;
55
56 // Number of packets in block.
57 size_t block_size_;
58
59 // Output sequence.
60 core::Array<size_t> send_seq_;
61
62 // Delay line.
64
65 size_t next_2_put_;
66 size_t next_2_send_;
67
68 bool valid_;
69};
70
71} // namespace packet
72} // namespace roc
73
74#endif // ROC_PACKET_INTERLEAVER_H_
Dynamic array.
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition attributes.h:31
Memory arena interface.
Definition iarena.h:23
Base class for non-copyable objects.
Definition noncopyable.h:23
Packet writer interface.
Definition iwriter.h:23
Interleaves packets to transmit them in pseudo random order.
Definition interleaver.h:25
Interleaver(IWriter &writer, core::IArena &arena, size_t block_size)
Initialize.
size_t block_size() const
Maximum delay between writing packet and moment we get it in output in terms of packets number.
status::StatusCode flush()
Send all buffered packets to output writer.
bool is_valid() const
Check if object is successfully constructed.
virtual status::StatusCode write(const PacketPtr &packet)
Write next packet.
Memory arena interface.
Packet writer interface.
StatusCode
Status code.
Definition status_code.h:19
Root namespace.
Non-copyable object.
Packet.