Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
packet.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Roc 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/helpers.h"
16#include "roc_core/list_node.h"
17#include "roc_core/pool.h"
18#include "roc_core/refcnt.h"
19#include "roc_core/shared_ptr.h"
20#include "roc_packet/fec.h"
21#include "roc_packet/print.h"
22#include "roc_packet/rtp.h"
23#include "roc_packet/udp.h"
24
25namespace roc {
26namespace packet {
27
28class PacketPool;
29class Packet;
30
31//! Packet smart pointer.
33
34//! Packet.
35class Packet : public core::RefCnt<Packet>, public core::ListNode {
36public:
37 //! Constructor.
38 explicit Packet(PacketPool&);
39
40 //! Packet flags.
41 enum {
42 FlagUDP = (1 << 0), //!< Packet contains UDP header.
43 FlagRTP = (1 << 1), //!< Packet contains RTP header.
44 FlagFEC = (1 << 2), //!< Packet contains FEC header.
45 FlagAudio = (1 << 3), //!< Packet contains audio samples.
46 FlagRepair = (1 << 4), //!< Packet contains repair FEC symbols.
47 FlagComposed = (1 << 5), //!< Packet is already composed.
48 FlagRestored = (1 << 6) //!< Packet was restored using FEC decoder.
49 };
50
51 //! Add flags.
52 void add_flags(unsigned flags);
53
54 //! Get flags.
55 unsigned flags() const;
56
57 //! UDP packet.
58 const UDP* udp() const;
59
60 //! UDP packet.
61 UDP* udp();
62
63 //! RTP packet.
64 const RTP* rtp() const;
65
66 //! RTP packet.
67 RTP* rtp();
68
69 //! FEC packet.
70 const FEC* fec() const;
71
72 //! FEC packet.
73 FEC* fec();
74
75 //! Get packet data.
76 const core::Slice<uint8_t>& data() const;
77
78 //! Set packet data.
80
81 //! Return packet stream identifier.
82 //! @remarks
83 //! The returning value depends on packet type. For some packet types, may
84 //! be always zero.
86
87 //! Get the timestamp of the first sample in packet.
88 //! @remarks
89 //! Timestamp units depend on packet type. For some packet types, may
90 //! be always zero.
92
93 //! Get the timestamp of the last sample in packet plus one.
94 //! @remarks
95 //! Timestamp units depend on packet type. For some packet types, may
96 //! be always zero.
98
99 //! Determine packet order.
100 //! @returns
101 //! * -1 if this packet precedes @p other packet
102 //! * 0 if this packet has the same position as @p other packet
103 //! * +1 if this packet succeeds @p other packet
104 int compare(const Packet& other) const;
105
106 //! Print packet to stderr.
107 void print(int flags) const {
108 packet::print(*this, flags);
109 }
110
111 //! Get pointer to packet from a pointer to its UDP part.
113 return ROC_CONTAINER_OF(udp, Packet, udp_);
114 }
115
116private:
117 friend class core::RefCnt<Packet>;
118
119 void destroy();
120
121 PacketPool& pool_;
122
123 unsigned flags_;
124
125 UDP udp_;
126 RTP rtp_;
127 FEC fec_;
128
130};
131
132} // namespace packet
133} // namespace roc
134
135#endif // ROC_PACKET_PACKET_H_
Base class for list element.
Definition: list_node.h:26
Base class for reference countable objects.
Definition: refcnt.h:25
Shared ownership intrusive pointer.
Definition: shared_ptr.h:28
Slice.
Definition: slice.h:23
@ FlagRestored
Packet was restored using FEC decoder.
Definition: packet.h:48
@ FlagRepair
Packet contains repair FEC symbols.
Definition: packet.h:46
@ FlagRTP
Packet contains RTP header.
Definition: packet.h:43
@ FlagAudio
Packet contains audio samples.
Definition: packet.h:45
@ FlagComposed
Packet is already composed.
Definition: packet.h:47
@ FlagUDP
Packet contains UDP header.
Definition: packet.h:42
@ FlagFEC
Packet contains FEC header.
Definition: packet.h:44
FEC * fec()
FEC packet.
void print(int flags) const
Print packet to stderr.
Definition: packet.h:107
timestamp_t end() const
Get the timestamp of the last sample in packet plus one.
const UDP * udp() const
UDP packet.
const RTP * rtp() const
RTP packet.
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.
const core::Slice< uint8_t > & data() const
Get packet data.
void set_data(const core::Slice< uint8_t > &data)
Set packet data.
Packet(PacketPool &)
Constructor.
static Packet * container_of(UDP *udp)
Get pointer to packet from a pointer to its UDP part.
Definition: packet.h:112
timestamp_t begin() const
Get the timestamp of the first sample in packet.
source_t source() const
Return packet stream identifier.
void add_flags(unsigned flags)
Add flags.
FEC packet.
Compile time helpers.
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
Definition: helpers.h:19
Linked list node.
uint32_t source_t
Packet source ID identifying packet stream.
Definition: units.h:22
core::SharedPtr< Packet > PacketPtr
Packet smart pointer.
Definition: packet.h:32
uint32_t timestamp_t
Audio packet timestamp.
Definition: units.h:46
void print(const Packet &packet, int flags)
Print packet to stderr.
Root namespace.
Pool.
Print packet to stdout.
Base class for reference countable objects.
RTP packet.
Shared ownership intrusive pointer.
FECFRAME packet.
Definition: fec.h:35
RTP packet.
Definition: rtp.h:23
UDP packet.
Definition: udp.h:25
UDP packet.