Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
units.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/units.h
10//! @brief Various units used in packets.
11
12#ifndef ROC_PACKET_UNITS_H_
13#define ROC_PACKET_UNITS_H_
14
15#include "roc_core/stddefs.h"
16#include "roc_core/time.h"
17
18namespace roc {
19namespace packet {
20
21//! Packet stream identifier.
22//! @remarks
23//! Identifies packet stream within session.
24//! Unique only within one session.
25//! For example, audio packet stream and repair (FEC) packet stream
26//! usually have different source identifiers.
27typedef uint32_t stream_source_t;
28
29//! Packet stream timestamp.
30//! @remarks
31//! Defines position of packet contents (e.g. audio chunk) within stream.
32//! Starts from unspecified value and can wrap.
33//! Measured in sender's clock domain and clock rate.
34//! For PCM audio, stream timestamp is incremented by one every N samples,
35//! where N is the number of channels.
36typedef uint32_t stream_timestamp_t;
37
38//! Packet stream timestamp delta.
39//! @remarks
40//! Signed version of stream_timestamp_t.
42
43//! Compute difference between two timestamps.
45 const stream_timestamp_t b) {
46 return stream_timestamp_diff_t(a - b);
47}
48
49//! Check if `a` is before `b`, taking possible wrap into account.
51 return stream_timestamp_diff(a, b) < 0;
52}
53
54//! Check if `a` is before or equal to `b`, taking possible wrap into account.
56 return stream_timestamp_diff(a, b) <= 0;
57}
58
59//! Packet sequence number.
60//! @remarks
61//! Defines position of packet within stream.
62//! Starts from unspecified value and can wrap.
63//! Incremented by one each packet.
64typedef uint16_t seqnum_t;
65
66//! Packet sequence number delta.
67//! @remarks
68//! Signed version of seqnum_t.
69typedef int16_t seqnum_diff_t;
70
71//! Compute difference between two seqnums.
72inline seqnum_diff_t seqnum_diff(const seqnum_t a, const seqnum_t b) {
73 return seqnum_diff_t(a - b);
74}
75
76//! Check if `a` is before `b`, taking possible wrap into account.
77inline bool seqnum_lt(const seqnum_t a, const seqnum_t b) {
78 return seqnum_diff(a, b) < 0;
79}
80
81//! Check if `a` is before or equal to `b`, taking possible wrap into account.
82inline bool seqnum_le(const seqnum_t a, const seqnum_t b) {
83 return seqnum_diff(a, b) <= 0;
84}
85
86//! FEC packet block number.
87//! @remarks
88//! Defines position of FEC packet block within stream.
89//! Starts from unspecified value and can wrap.
90//! Incremented by one each block.
91typedef uint16_t blknum_t;
92
93//! FEC packet block number delta.
94//! @remarks
95//! Signed version of blknum_t.
96typedef int16_t blknum_diff_t;
97
98//! Compute difference between two FEC packet block numbers.
99inline blknum_diff_t blknum_diff(const blknum_t a, const blknum_t b) {
100 return blknum_diff_t(a - b);
101}
102
103//! Check if `a` is before `b`, taking possible wrap into account.
104inline bool blknum_lt(const blknum_t a, const blknum_t b) {
105 return blknum_diff(a, b) < 0;
106}
107
108//! Check if `a` is before or equal to `b`, taking possible wrap into account.
109inline bool blknum_le(const blknum_t a, const blknum_t b) {
110 return blknum_diff(a, b) <= 0;
111}
112
113} // namespace packet
114} // namespace roc
115
116#endif // ROC_PACKET_UNITS_H_
seqnum_diff_t seqnum_diff(const seqnum_t a, const seqnum_t b)
Compute difference between two seqnums.
Definition: units.h:72
bool seqnum_le(const seqnum_t a, const seqnum_t b)
Check if a is before or equal to b, taking possible wrap into account.
Definition: units.h:82
int16_t seqnum_diff_t
Packet sequence number delta.
Definition: units.h:69
int16_t blknum_diff_t
FEC packet block number delta.
Definition: units.h:96
uint32_t stream_source_t
Packet stream identifier.
Definition: units.h:27
stream_timestamp_diff_t stream_timestamp_diff(const stream_timestamp_t a, const stream_timestamp_t b)
Compute difference between two timestamps.
Definition: units.h:44
bool stream_timestamp_le(const stream_timestamp_t a, const stream_timestamp_t b)
Check if a is before or equal to b, taking possible wrap into account.
Definition: units.h:55
bool seqnum_lt(const seqnum_t a, const seqnum_t b)
Check if a is before b, taking possible wrap into account.
Definition: units.h:77
uint16_t seqnum_t
Packet sequence number.
Definition: units.h:64
uint16_t blknum_t
FEC packet block number.
Definition: units.h:91
blknum_diff_t blknum_diff(const blknum_t a, const blknum_t b)
Compute difference between two FEC packet block numbers.
Definition: units.h:99
uint32_t stream_timestamp_t
Packet stream timestamp.
Definition: units.h:36
bool blknum_le(const blknum_t a, const blknum_t b)
Check if a is before or equal to b, taking possible wrap into account.
Definition: units.h:109
bool stream_timestamp_lt(const stream_timestamp_t a, const stream_timestamp_t b)
Check if a is before b, taking possible wrap into account.
Definition: units.h:50
bool blknum_lt(const blknum_t a, const blknum_t b)
Check if a is before b, taking possible wrap into account.
Definition: units.h:104
int32_t stream_timestamp_diff_t
Packet stream timestamp delta.
Definition: units.h:41
Root namespace.
Commonly used types and functions.
Time definitions.