MythTV master
packetbuffer.cpp
Go to the documentation of this file.
1/* -*- Mode: c++ -*-
2 * PacketBuffer
3 * Copyright (c) 2012 Digital Nirvana, Inc.
4 * Distributed as part of MythTV under GPL v2 and later.
5 */
6
7#include <cstdint>
8
9// MythTV headers
11#include "packetbuffer.h"
12
13PacketBuffer::PacketBuffer(unsigned int bitrate) :
14 m_bitrate(bitrate),
15 m_next_empty_packet_key(static_cast<uint64_t>(MythRandom()) << 32)
16{
17}
18
20{
21 return !m_available_packets.empty();
22}
23
25{
26 if (m_available_packets.empty())
27 return UDPPacket(0);
28
29 UDPPacket packet(m_available_packets.front());
30 m_available_packets.pop_front();
31
32 return packet;
33}
34
36{
37 QMap<uint64_t, UDPPacket>::iterator it = m_empty_packets.begin();
38 if (it == m_empty_packets.end())
39 {
41 }
42
43 // NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
44 UDPPacket packet(*it);
45 m_empty_packets.erase(it);
46
47 return packet;
48}
49
51{
52 static constexpr uint64_t k_mask_upper_32 = ~((UINT64_C(1) << (64 - 32)) - 1);
53 uint64_t top = packet.GetKey() & k_mask_upper_32;
54 if (top == (m_next_empty_packet_key & k_mask_upper_32))
55 m_empty_packets[packet.GetKey()] = packet;
56}
UDPPacket PopDataPacket(void)
Fetches a data packet for processing.
UDPPacket GetEmptyPacket(void)
Gets a packet for use in PushDataPacket/PushFECPacket.
QList< UDPPacket > m_available_packets
Ordered list of available packets.
Definition: packetbuffer.h:55
PacketBuffer(unsigned int bitrate)
void FreePacket(const UDPPacket &packet)
Frees an RTPDataPacket returned by PopDataPacket.
bool HasAvailablePacket(void) const
Returns true if there are ordered packets ready for processing.
uint64_t m_next_empty_packet_key
Packets key to use for next empty packet.
Definition: packetbuffer.h:49
QMap< uint64_t, UDPPacket > m_empty_packets
Packets ready for reuse.
Definition: packetbuffer.h:52
UDP Packet.
Definition: udppacket.h:21
uint64_t GetKey(void) const
Definition: udppacket.h:34
Convenience inline random number generator functions.
uint32_t MythRandom()
generate 32 random bits
Definition: mythrandom.h:20