Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
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
"
17
#include "
roc_core/noncopyable.h
"
18
#include "
roc_packet/iwriter.h
"
19
#include "
roc_packet/packet.h
"
20
21
namespace
roc
{
22
namespace
packet
{
23
24
//! Interleaves packets to transmit them in pseudo random order.
25
class
Interleaver
:
public
IWriter
,
public
core::NonCopyable
<> {
26
public
:
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.
40
virtual
ROC_ATTR_NODISCARD
status::StatusCode
write
(
const
PacketPtr
&
packet
);
41
42
//! Send all buffered packets to output writer.
43
ROC_ATTR_NODISCARD
status::StatusCode
flush
();
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
49
private
:
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.
63
core::Array<PacketPtr>
packets_;
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_
array.h
Dynamic array.
ROC_ATTR_NODISCARD
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition
attributes.h:31
roc::core::Array
Dynamic array.
Definition
array.h:40
roc::core::IArena
Memory arena interface.
Definition
iarena.h:23
roc::core::NonCopyable
Base class for non-copyable objects.
Definition
noncopyable.h:23
roc::packet::IWriter
Packet writer interface.
Definition
iwriter.h:23
roc::packet::Interleaver::write
virtual ROC_ATTR_NODISCARD status::StatusCode write(const PacketPtr &packet)
Write next packet.
roc::packet::Interleaver::Interleaver
Interleaver(IWriter &writer, core::IArena &arena, size_t block_size)
Initialize.
roc::packet::Interleaver::block_size
size_t block_size() const
Maximum delay between writing packet and moment we get it in output in terms of packets number.
roc::packet::Interleaver::is_valid
bool is_valid() const
Check if object is successfully constructed.
roc::packet::Interleaver::flush
ROC_ATTR_NODISCARD status::StatusCode flush()
Send all buffered packets to output writer.
iarena.h
Memory arena interface.
iwriter.h
Packet writer interface.
roc::packet
Network packets and packet processing.
roc::packet::PacketPtr
core::SharedPtr< Packet > PacketPtr
Packet smart pointer.
Definition
packet.h:34
roc
Root namespace.
noncopyable.h
Non-copyable object.
packet.h
Packet.
roc::status::StatusCode
StatusCode
Status code.
Definition
status_code.h:19
roc_packet
interleaver.h
Generated by
1.17.0