Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
packet.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/packet.h
10//! @brief Packet.
11
12#ifndef ROC_PACKET_PACKET_H_
13#define ROC_PACKET_PACKET_H_
14
15#include "roc_core/list_node.h"
19#include "roc_core/shared_ptr.h"
20#include "roc_core/slab_pool.h"
21#include "roc_packet/fec.h"
23#include "roc_packet/rtcp.h"
24#include "roc_packet/rtp.h"
25#include "roc_packet/udp.h"
26
27namespace roc {
28namespace packet {
29
30class Packet;
31
32//! Packet smart pointer.
34
35//! Packet.
36class Packet : public core::RefCounted<Packet, core::PoolAllocation>,
37 public core::ListNode,
38 public core::MpscQueueNode {
39public:
40 //! Constructor.
41 explicit Packet(core::IPool& packet_pool);
42
43 //! Packet flags.
44 enum {
45 FlagUDP = (1 << 0), //!< Packet contains UDP header.
46 FlagRTP = (1 << 1), //!< Packet contains RTP header.
47 FlagFEC = (1 << 2), //!< Packet contains FEC header.
48 FlagRTCP = (1 << 3), //!< Packet contains RTCP compound packet.
49 FlagAudio = (1 << 4), //!< Packet contains audio samples.
50 FlagRepair = (1 << 5), //!< Packet contains repair FEC symbols.
51 FlagControl = (1 << 6), //!< Packet contains control message.
52 FlagPrepared = (1 << 7), //!< Packet was prepared for composing.
53 FlagComposed = (1 << 8), //!< Packet was composed.
54 FlagRestored = (1 << 9) //!< Packet was restored using FEC decoder.
55 };
56
57 //! Add flags.
58 void add_flags(unsigned flags);
59
60 //! Check specific flag.
61 bool has_flags(unsigned flags) const;
62
63 //! Get flags.
64 unsigned flags() const;
65
66 //! UDP packet.
67 const UDP* udp() const;
68
69 //! UDP packet.
70 UDP* udp();
71
72 //! RTP packet.
73 const RTP* rtp() const;
74
75 //! RTP packet.
76 RTP* rtp();
77
78 //! FEC packet.
79 const FEC* fec() const;
80
81 //! FEC packet.
82 FEC* fec();
83
84 //! RTCP packet.
85 const RTCP* rtcp() const;
86
87 //! RTCP packet.
89
90 //! Get packet data.
91 const core::Slice<uint8_t>& data() const;
92
93 //! Set packet data.
95
96 //! Return packet stream identifier.
97 //! @remarks
98 //! The returning value depends on packet type. For some packet types, may
99 //! be always zero.
101
102 //! Get the timestamp of the first sample in packet.
103 //! @remarks
104 //! Timestamp units depend on packet type. For some packet types, may
105 //! be always zero.
107
108 //! Get the timestamp of the last sample in packet plus one.
109 //! @remarks
110 //! Timestamp units depend on packet type. For some packet types, may
111 //! be always zero.
113
114 //! Determine packet order.
115 //! @returns
116 //! * -1 if this packet precedes @p other packet
117 //! * 0 if this packet has the same position as @p other packet
118 //! * +1 if this packet succeeds @p other packet
119 int compare(const Packet& other) const;
120
121 //! Print packet to stderr.
122 void print(int flags) const {
124 }
125
126 //! Get pointer to packet from a pointer to its UDP part.
128 return ROC_CONTAINER_OF(udp, Packet, udp_);
129 }
130
131private:
132 unsigned flags_;
133
134 UDP udp_;
135 RTP rtp_;
136 FEC fec_;
137 RTCP rtcp_;
138
140};
141
142} // namespace packet
143} // namespace roc
144
145#endif // ROC_PACKET_PACKET_H_
Memory pool interface.
Definition: ipool.h:23
Base class for list element.
Definition: list_node.h:26
Base class for object with reference counter.
Definition: ref_counted.h:40
FEC * fec()
FEC packet.
const RTCP * rtcp() const
RTCP packet.
void print(int flags) const
Print packet to stderr.
Definition: packet.h:122
const UDP * udp() const
UDP packet.
const RTP * rtp() const
RTP packet.
stream_source_t source() const
Return packet stream identifier.
UDP * udp()
UDP packet.
const FEC * fec() const
FEC packet.
RTP * rtp()
RTP packet.
int compare(const Packet &other) const
Determine packet order.
unsigned flags() const
Get flags.
Packet(core::IPool &packet_pool)
Constructor.
stream_timestamp_t end() const
Get the timestamp of the last sample in packet plus one.
const core::Slice< uint8_t > & data() const
Get packet data.
@ FlagRestored
Packet was restored using FEC decoder.
Definition: packet.h:54
@ FlagPrepared
Packet was prepared for composing.
Definition: packet.h:52
@ FlagRTCP
Packet contains RTCP compound packet.
Definition: packet.h:48
@ FlagRepair
Packet contains repair FEC symbols.
Definition: packet.h:50
@ FlagControl
Packet contains control message.
Definition: packet.h:51
@ FlagRTP
Packet contains RTP header.
Definition: packet.h:46
@ FlagAudio
Packet contains audio samples.
Definition: packet.h:49
@ FlagComposed
Packet was composed.
Definition: packet.h:53
@ FlagUDP
Packet contains UDP header.
Definition: packet.h:45
@ FlagFEC
Packet contains FEC header.
Definition: packet.h:47
void set_data(const core::Slice< uint8_t > &data)
Set packet data.
static Packet * container_of(UDP *udp)
Get pointer to packet from a pointer to its UDP part.
Definition: packet.h:127
stream_timestamp_t begin() const
Get the timestamp of the first sample in packet.
RTCP * rtcp()
RTCP packet.
bool has_flags(unsigned flags) const
Check specific flag.
void add_flags(unsigned flags)
Add flags.
FEC packet.
Linked list node.
Helper macros.
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
Definition: macro_helpers.h:37
MpscQueue node.
uint32_t stream_source_t
Packet stream identifier.
Definition: units.h:27
core::SharedPtr< Packet > PacketPtr
Packet smart pointer.
Definition: packet.h:33
uint32_t stream_timestamp_t
Packet stream timestamp.
Definition: units.h:36
void print_packet(const Packet &packet, int flags)
Print packet to stderr.
Root namespace.
Base class for object with reference counter.
Print packet to console.
RTCP compound packet.
RTP packet.
Shared ownership intrusive pointer.
Memory pool.
FECFRAME packet.
Definition: fec.h:35
RTCP compound packet.
Definition: rtcp.h:22
RTP packet.
Definition: rtp.h:24
UDP packet.
Definition: udp.h:25
UDP packet.