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 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_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::FactoryAllocation<PacketFactory> >,
37 public core::ListNode,
38 public core::MpscQueueNode {
40
41public:
42 //! Constructor.
44
45 //! Packet flags.
46 enum {
47 FlagUDP = (1 << 0), //!< Packet contains UDP header.
48 FlagRTP = (1 << 1), //!< Packet contains RTP header.
49 FlagFEC = (1 << 2), //!< Packet contains FEC header.
50 FlagRTCP = (1 << 3), //!< Packet contains RTCP compound packet.
51 FlagAudio = (1 << 4), //!< Packet contains audio samples.
52 FlagRepair = (1 << 5), //!< Packet contains repair FEC symbols.
53 FlagControl = (1 << 6), //!< Packet contains control message.
54 FlagComposed = (1 << 7), //!< Packet is already composed.
55 FlagRestored = (1 << 8) //!< Packet was restored using FEC decoder.
56 };
57
58 //! Add flags.
59 void add_flags(unsigned flags);
60
61 //! Get flags.
62 unsigned flags() const;
63
64 //! UDP packet.
65 const UDP* udp() const;
66
67 //! UDP packet.
68 UDP* udp();
69
70 //! RTP packet.
71 const RTP* rtp() const;
72
73 //! RTP packet.
74 RTP* rtp();
75
76 //! FEC packet.
77 const FEC* fec() const;
78
79 //! FEC packet.
80 FEC* fec();
81
82 //! RTCP packet.
83 const RTCP* rtcp() const;
84
85 //! RTCP packet.
87
88 //! Get packet data.
89 const core::Slice<uint8_t>& data() const;
90
91 //! Set packet data.
93
94 //! Return packet stream identifier.
95 //! @remarks
96 //! The returning value depends on packet type. For some packet types, may
97 //! be always zero.
99
100 //! Get the timestamp of the first sample in packet.
101 //! @remarks
102 //! Timestamp units depend on packet type. For some packet types, may
103 //! be always zero.
105
106 //! Get the timestamp of the last sample in packet plus one.
107 //! @remarks
108 //! Timestamp units depend on packet type. For some packet types, may
109 //! be always zero.
111
112 //! Determine packet order.
113 //! @returns
114 //! * -1 if this packet precedes @p other packet
115 //! * 0 if this packet has the same position as @p other packet
116 //! * +1 if this packet succeeds @p other packet
117 int compare(const Packet& other) const;
118
119 //! Print packet to stderr.
120 void print(int flags) const {
122 }
123
124 //! Get pointer to packet from a pointer to its UDP part.
126 return ROC_CONTAINER_OF(udp, Packet, udp_);
127 }
128
129private:
130 unsigned flags_;
131
132 UDP udp_;
133 RTP rtp_;
134 FEC fec_;
135 RTCP rtcp_;
136
138};
139
140} // namespace packet
141} // namespace roc
142
143#endif // ROC_PACKET_PACKET_H_
Base class for list element.
Definition: list_node.h:26
Base class for reference counted object.
Definition: ref_counted.h:39
Shared ownership intrusive pointer.
Definition: shared_ptr.h:32
Slice.
Definition: slice.h:54
FEC * fec()
FEC packet.
const RTCP * rtcp() const
RTCP packet.
void print(int flags) const
Print packet to stderr.
Definition: packet.h:120
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.
Packet(PacketFactory &)
Constructor.
const core::Slice< uint8_t > & data() const
Get packet data.
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:125
@ FlagRestored
Packet was restored using FEC decoder.
Definition: packet.h:55
@ FlagRTCP
Packet contains RTCP compound packet.
Definition: packet.h:50
@ FlagRepair
Packet contains repair FEC symbols.
Definition: packet.h:52
@ FlagControl
Packet contains control message.
Definition: packet.h:53
@ FlagRTP
Packet contains RTP header.
Definition: packet.h:48
@ FlagAudio
Packet contains audio samples.
Definition: packet.h:51
@ FlagComposed
Packet is already composed.
Definition: packet.h:54
@ FlagUDP
Packet contains UDP header.
Definition: packet.h:47
@ FlagFEC
Packet contains FEC header.
Definition: packet.h:49
RTCP * rtcp()
RTCP packet.
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.
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:27
MpscQueue 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:33
uint32_t timestamp_t
Audio packet timestamp.
Definition: units.h:25
void print_packet(const Packet &packet, int flags)
Print packet to stderr.
Root namespace.
Packet factory.
Base class for reference counted object.
Print packet to console.
RTCP compound packet.
RTP packet.
Shared ownership intrusive pointer.
FECFRAME packet.
Definition: fec.h:35
RTCP compound packet.
Definition: rtcp.h:22
RTP packet.
Definition: rtp.h:23
UDP packet.
Definition: udp.h:25
UDP packet.