MythTV  master
rtppacketbuffer.cpp
Go to the documentation of this file.
1 /* -*- Mode: c++ -*-
2  * RTPPacketBuffer
3  * Copyright (c) 2012 Digital Nirvana, Inc.
4  * Distributed as part of MythTV under GPL v2 and later.
5  */
6 
7 #include <algorithm>
8 
9 #include "rtppacketbuffer.h"
10 #include "rtpdatapacket.h"
11 #include "rtpfecpacket.h"
12 
14 {
15  RTPDataPacket packet(udp_packet);
16 
17  uint key = packet.GetSequenceNumber();
18 
19  bool large_was_seen_recently = m_largeSequenceNumberSeenRecently > 0;
21  (key > (1U<<15)) ? 500 : m_largeSequenceNumberSeenRecently - 1;
24 
26  {
27  if (key < 500)
28  key += 1ULL<<16;
29  }
30  else if (large_was_seen_recently)
31  {
32  m_currentSequence += 1ULL<<16;
33  }
34 
35  key += m_currentSequence;
36 
37 /*
38  LOG(VB_RECORD, LOG_DEBUG, QString("Pushing %1 as %2 (lr %3)")
39  .arg(packet.GetSequenceNumber()).arg(key)
40  .arg(m_largeSequenceNumberSeenRecently));
41 */
42 
43  m_unorderedPackets[key] = packet;
44 
45  // TODO pushing packets onto the ordered list should be based on
46  // the bitrate and the M+N of the FEC.. but for now...
47  const int kHighWaterMark = 500;
48  const int kLowWaterMark = 100;
49  if (m_unorderedPackets.size() > kHighWaterMark)
50  {
51  while (m_unorderedPackets.size() > kLowWaterMark)
52  {
53  QMap<uint64_t, RTPDataPacket>::iterator it =
54  m_unorderedPackets.begin();
55 /*
56  LOG(VB_RECORD, LOG_DEBUG, QString("Popping %1 as %2")
57  .arg((*it).GetSequenceNumber()).arg(it.key()));
58 */
59  m_available_packets.push_back(*it);
60  m_unorderedPackets.erase(it);
61  }
62  }
63 }
64 
66  const UDPPacket &packet, uint fec_stream_num)
67 {
68  (void) fec_stream_num;
69  // TODO IMPLEMENT
70  // for now just free the packet for immediate reuse
71  FreePacket(packet);
72 }
rtpdatapacket.h
PacketBuffer::FreePacket
void FreePacket(const UDPPacket &packet)
Frees an RTPDataPacket returned by PopDataPacket.
Definition: packetbuffer.cpp:56
RTPPacketBuffer::PushDataPacket
void PushDataPacket(const UDPPacket &udp_packet) override
Adds RFC 3550 RTP data packet.
Definition: rtppacketbuffer.cpp:13
RTPPacketBuffer::m_largeSequenceNumberSeenRecently
int m_largeSequenceNumberSeenRecently
Definition: rtppacketbuffer.h:28
RTPPacketBuffer::PushFECPacket
void PushFECPacket(const UDPPacket &packet, unsigned int fec_stream_num) override
Adds SMPTE 2022 Forward Error Correction Stream packet.
Definition: rtppacketbuffer.cpp:65
RTPPacketBuffer::m_unorderedPackets
QMap< uint64_t, RTPDataPacket > m_unorderedPackets
The key is the RTP sequence number + sequence if applicable.
Definition: rtppacketbuffer.h:32
PacketBuffer::m_available_packets
QList< UDPPacket > m_available_packets
Ordered list of available packets.
Definition: packetbuffer.h:53
uint
unsigned int uint
Definition: compat.h:140
rtppacketbuffer.h
RTPDataPacket::GetSequenceNumber
uint GetSequenceNumber(void) const
Definition: rtpdatapacket.h:95
RTPDataPacket
RTP Data Packet.
Definition: rtpdatapacket.h:30
UDPPacket
UDP Packet.
Definition: udppacket.h:20
rtpfecpacket.h
RTPPacketBuffer::m_currentSequence
uint64_t m_currentSequence
Definition: rtppacketbuffer.h:29