Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
sorted_queue.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/sorted_queue.h
10
//! @brief Sorted packet queue.
11
12
#ifndef ROC_PACKET_SORTED_QUEUE_H_
13
#define ROC_PACKET_SORTED_QUEUE_H_
14
15
#include "
roc_core/list.h
"
16
#include "
roc_core/noncopyable.h
"
17
#include "
roc_packet/ireader.h
"
18
#include "
roc_packet/iwriter.h
"
19
#include "
roc_packet/packet.h
"
20
21
namespace
roc
{
22
namespace
packet
{
23
24
//! Sorted packet queue.
25
//! @remarks
26
//! Packets order is determined by Packet::compare() method.
27
class
SortedQueue
:
public
IWriter
,
public
IReader
,
public
core::NonCopyable
<> {
28
public
:
29
//! Construct empty queue.
30
//! @remarks
31
//! If @p max_size is non-zero, it specifies maximum number of packets in queue.
32
explicit
SortedQueue
(
size_t
max_size);
33
34
//! Add packet to the queue.
35
//! @remarks
36
//! - if the maximum queue size is reached, packet is dropped
37
//! - if packet is equal to another packet in the queue, it is dropped
38
//! - otherwise, packet is inserted into the queue, keeping the queue sorted
39
virtual
ROC_ATTR_NODISCARD
status::StatusCode
write
(
const
PacketPtr
&
packet
);
40
41
//! Read next packet.
42
//!
43
//! @remarks
44
//! Removes returned packet from the queue.
45
virtual
ROC_ATTR_NODISCARD
status::StatusCode
read
(
PacketPtr
&
packet
);
46
47
//! Get number of packets in queue.
48
size_t
size
()
const
;
49
50
//! Get first packet in the queue.
51
//! @returns
52
//! the first packet in the queue or null if there are no packets
53
//! @remarks
54
//! Returned packet is not removed from the queue.
55
PacketPtr
head
()
const
;
56
57
//! Get last packet in the queue.
58
//! @returns
59
//! the last packet in the queue or null if there are no packets
60
//! @remarks
61
//! Returned packet is not removed from the queue.
62
PacketPtr
tail
()
const
;
63
64
//! Get the latest packet that were ever added to the queue.
65
//! @remarks
66
//! Returns null if the queue never had any packets. Otherwise, returns
67
//! the latest (by sorting order) ever added packet, even if that packet is not
68
//! currently in the queue. Returned packet is not removed from the queue if
69
//! it's still there.
70
PacketPtr
latest
()
const
;
71
72
private
:
73
core::List<Packet>
list_;
74
PacketPtr
latest_;
75
const
size_t
max_size_;
76
};
77
78
}
// namespace packet
79
}
// namespace roc
80
81
#endif
// ROC_PACKET_SORTED_QUEUE_H_
ROC_ATTR_NODISCARD
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition
attributes.h:31
roc::core::List
Intrusive doubly-linked list.
Definition
list.h:40
roc::core::NonCopyable
Base class for non-copyable objects.
Definition
noncopyable.h:23
roc::packet::IReader
Packet reader interface.
Definition
ireader.h:23
roc::packet::IWriter
Packet writer interface.
Definition
iwriter.h:23
roc::packet::SortedQueue::read
virtual ROC_ATTR_NODISCARD status::StatusCode read(PacketPtr &packet)
Read next packet.
roc::packet::SortedQueue::latest
PacketPtr latest() const
Get the latest packet that were ever added to the queue.
roc::packet::SortedQueue::tail
PacketPtr tail() const
Get last packet in the queue.
roc::packet::SortedQueue::head
PacketPtr head() const
Get first packet in the queue.
roc::packet::SortedQueue::write
virtual ROC_ATTR_NODISCARD status::StatusCode write(const PacketPtr &packet)
Add packet to the queue.
roc::packet::SortedQueue::SortedQueue
SortedQueue(size_t max_size)
Construct empty queue.
roc::packet::SortedQueue::size
size_t size() const
Get number of packets in queue.
ireader.h
Packet reader interface.
iwriter.h
Packet writer interface.
list.h
Intrusive doubly-linked list.
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
sorted_queue.h
Generated by
1.17.0