Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
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 source ID identifying packet stream.
22typedef uint32_t source_t;
23
24//! Audio packet timestamp.
25typedef uint32_t timestamp_t;
26
27//! Audio packet timestamps difference.
28typedef int32_t timestamp_diff_t;
29
30//! Compute difference between two timestamps.
32 return timestamp_diff_t(a - b);
33}
34
35//! Check if a is before b taking possible wrap into account.
37 return timestamp_diff(a, b) < 0;
38}
39
40//! Check if a is before or equal to b taking possible wrap into account.
42 return timestamp_diff(a, b) <= 0;
43}
44
45//! Packet sequence number in packet stream.
46typedef uint16_t seqnum_t;
47
48//! Packet sequence numbers difference.
49typedef int16_t seqnum_diff_t;
50
51//! Compute difference between two seqnums.
53 return seqnum_diff_t(a - b);
54}
55
56//! Check if a is before b taking possible wrap into account.
57inline bool seqnum_lt(seqnum_t a, seqnum_t b) {
58 return seqnum_diff(a, b) < 0;
59}
60
61//! Check if a is before or equal to b taking possible wrap into account.
62inline bool seqnum_le(seqnum_t a, seqnum_t b) {
63 return seqnum_diff(a, b) <= 0;
64}
65
66//! FEC block number in a packet stream.
67typedef uint16_t blknum_t;
68
69//! FEC block numbers difference.
70typedef int16_t blknum_diff_t;
71
72//! Compute difference between two FEC block numbers.
74 return blknum_diff_t(a - b);
75}
76
77//! Check if a is before b taking possible wrap into account.
78inline bool blknum_lt(blknum_t a, blknum_t b) {
79 return blknum_diff(a, b) < 0;
80}
81
82//! Check if a is before or equal to b taking possible wrap into account.
83inline bool blknum_le(blknum_t a, blknum_t b) {
84 return blknum_diff(a, b) <= 0;
85}
86
87//! NTP timestamp.
88//! @remarks
89//! Highest 32 bits - seconds since NTP epoch, lowest 32 bits - fractions of a second.
90//! NTP epoch starts from January 1, 1900.
91typedef uint64_t ntp_timestamp_t;
92
93//! Bitmask of channels present in audio packet.
94typedef uint32_t channel_mask_t;
95
96//! Compute number of channels in mask.
97inline size_t num_channels(channel_mask_t ch_mask) {
98 size_t n_ch = 0;
99 for (; ch_mask != 0; ch_mask >>= 1) {
100 if (ch_mask & 1) {
101 n_ch++;
102 }
103 }
104 return n_ch;
105}
106
107} // namespace packet
108} // namespace roc
109
110#endif // ROC_PACKET_UNITS_H_
blknum_diff_t blknum_diff(blknum_t a, blknum_t b)
Compute difference between two FEC block numbers.
Definition units.h:73
uint32_t source_t
Packet source ID identifying packet stream.
Definition units.h:22
int16_t seqnum_diff_t
Packet sequence numbers difference.
Definition units.h:49
bool seqnum_le(seqnum_t a, seqnum_t b)
Check if a is before or equal to b taking possible wrap into account.
Definition units.h:62
seqnum_diff_t seqnum_diff(seqnum_t a, seqnum_t b)
Compute difference between two seqnums.
Definition units.h:52
int16_t blknum_diff_t
FEC block numbers difference.
Definition units.h:70
bool timestamp_lt(timestamp_t a, timestamp_t b)
Check if a is before b taking possible wrap into account.
Definition units.h:36
bool blknum_le(blknum_t a, blknum_t b)
Check if a is before or equal to b taking possible wrap into account.
Definition units.h:83
uint16_t seqnum_t
Packet sequence number in packet stream.
Definition units.h:46
uint32_t timestamp_t
Audio packet timestamp.
Definition units.h:25
size_t num_channels(channel_mask_t ch_mask)
Compute number of channels in mask.
Definition units.h:97
bool seqnum_lt(seqnum_t a, seqnum_t b)
Check if a is before b taking possible wrap into account.
Definition units.h:57
uint32_t channel_mask_t
Bitmask of channels present in audio packet.
Definition units.h:94
uint16_t blknum_t
FEC block number in a packet stream.
Definition units.h:67
bool blknum_lt(blknum_t a, blknum_t b)
Check if a is before b taking possible wrap into account.
Definition units.h:78
timestamp_diff_t timestamp_diff(timestamp_t a, timestamp_t b)
Compute difference between two timestamps.
Definition units.h:31
int32_t timestamp_diff_t
Audio packet timestamps difference.
Definition units.h:28
uint64_t ntp_timestamp_t
NTP timestamp.
Definition units.h:91
bool timestamp_le(timestamp_t a, timestamp_t b)
Check if a is before or equal to b taking possible wrap into account.
Definition units.h:41
Root namespace.
Commonly used types and functions.
Time definitions.