Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
rtp.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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/rtp.h
10 //! @brief RTP packet.
11 
12 #ifndef ROC_PACKET_RTP_H_
13 #define ROC_PACKET_RTP_H_
14 
15 #include "roc_core/slice.h"
16 #include "roc_core/stddefs.h"
17 #include "roc_core/time.h"
18 #include "roc_packet/units.h"
19 
20 namespace roc {
21 namespace packet {
22 
23 //! RTP packet.
24 struct RTP {
25  //! Packet source ID identifying packet stream ("src").
26  //! @remarks
27  //! Sequence numbers and timestamp are numbered independently inside
28  //! different packet streams.
30 
31  //! Packet sequence number in packet stream ("sn").
32  //! @remarks
33  //! Packets are numbered sequentaly in every stream, starting from some
34  //! random value. May overflow.
36 
37  //! Packet stream timestamp ("sts").
38  //! @remarks
39  //! Describes position of the first sample using abstract stream clock.
40  //! This clock belongs to sender and has sample rate of the stream.
41  //! For example, if sender is 44100Hz audio card, then stream timestamp
42  //! is incremented by one each generated sample, and it happens 44100
43  //! times per second, according to audio card clock.
44  //! This timestamp corresponds to "timestamp" field of RTP packet.
45  //! Just like seqnum, it starts from random value and may overflow.
47 
48  //! Packet duration ("dur").
49  //! @remarks
50  //! Duration is measured in the same units as timestamp.
51  //! Duration is not stored directly in RTP header. It is calculated
52  //! from packet size.
54 
55  //! Packet capture timestamp ("cts").
56  //! @remarks
57  //! Describes capture time of the first sample using local Unix-time clock.
58  //! This clock belongs to local system, no matter if we're on sender or receiver.
59  //! On sender, capture timestamp is assigned to the system time of sender when
60  //! the first sample in the packet was captured.
61  //! On receiver, capture timestamp is assigned an estimation of the same
62  //! value, converted to receiver system clock, i.e. the system time of receiver
63  //! when the first sample in the packet was captured on sender.
64  //! This field does not directly correspond to anything inside RTP packet.
65  //! Instead, receiver deduces this value based on "timestamp" field from RTP
66  //! packet, current NTP time, and mapping of NTP timestamps to RTP timestamps
67  //! retrieved via RTCP.
69 
70  //! Packet marker bit ("m").
71  //! @remarks
72  //! Marker bit meaning depends on packet type.
73  bool marker;
74 
75  //! Packet payload type ("pt").
76  unsigned int payload_type;
77 
78  //! Packet header.
80 
81  //! Packet payload.
82  //! @remarks
83  //! Doesn't include RTP headers and padding.
85 
86  //! Packet padding.
87  //! @remarks
88  //! Not included in header and payload, but affects overall packet size.
90 
91  //! Construct zero RTP packet.
92  RTP();
93 
94  //! Determine packet order.
95  int compare(const RTP&) const;
96 };
97 
98 } // namespace packet
99 } // namespace roc
100 
101 #endif // ROC_PACKET_RTP_H_
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
uint32_t stream_source_t
Packet stream identifier.
Definition: units.h:27
uint16_t seqnum_t
Packet sequence number.
Definition: units.h:64
uint32_t stream_timestamp_t
Packet stream timestamp.
Definition: units.h:36
Root namespace.
Slice.
Commonly used types and functions.
RTP packet.
Definition: rtp.h:24
RTP()
Construct zero RTP packet.
core::nanoseconds_t capture_timestamp
Packet capture timestamp ("cts").
Definition: rtp.h:68
unsigned int payload_type
Packet payload type ("pt").
Definition: rtp.h:76
bool marker
Packet marker bit ("m").
Definition: rtp.h:73
stream_timestamp_t duration
Packet duration ("dur").
Definition: rtp.h:53
seqnum_t seqnum
Packet sequence number in packet stream ("sn").
Definition: rtp.h:35
core::Slice< uint8_t > header
Packet header.
Definition: rtp.h:79
int compare(const RTP &) const
Determine packet order.
stream_source_t source
Packet source ID identifying packet stream ("src").
Definition: rtp.h:29
core::Slice< uint8_t > payload
Packet payload.
Definition: rtp.h:84
stream_timestamp_t stream_timestamp
Packet stream timestamp ("sts").
Definition: rtp.h:46
core::Slice< uint8_t > padding
Packet padding.
Definition: rtp.h:89
Time definitions.
Various units used in packets.