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_nextEmptyPacketKey(static_cast<uint64_t>(MythRandom()) << 32)
16{
17}
18
20{
21 return !m_availablePackets.empty();
22}
23
25{
26 if (m_availablePackets.empty())
27 return UDPPacket(0);
28
29 UDPPacket packet(m_availablePackets.front());
30 m_availablePackets.pop_front();
31
32 return packet;
33}
34
36{
37 QMap<uint64_t, UDPPacket>::iterator it = m_emptyPackets.begin();
38 if (it == m_emptyPackets.end())
39 {
41 }
42
43 // NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
44 UDPPacket packet(*it);
45 m_emptyPackets.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_nextEmptyPacketKey & k_mask_upper_32))
55 m_emptyPackets[packet.GetKey()] = packet;
56}
QMap< uint64_t, UDPPacket > m_emptyPackets
Packets ready for reuse.
Definition: packetbuffer.h:52
UDPPacket PopDataPacket(void)
Fetches a data packet for processing.
QList< UDPPacket > m_availablePackets
Ordered list of available packets.
Definition: packetbuffer.h:55
uint64_t m_nextEmptyPacketKey
Packets key to use for next empty packet.
Definition: packetbuffer.h:49
UDPPacket GetEmptyPacket(void)
Gets a packet for use in PushDataPacket/PushFECPacket.
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.
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