MythTV  master
rtpdatapacket.h
Go to the documentation of this file.
1 /* -*- Mode: c++ -*-
2  * Copyright (c) 2012 Digital Nirvana, Inc.
3  * Distributed as part of MythTV under GPL v2 and later.
4  */
5 
6 #ifndef _RTP_DATA_PACKET_H_
7 #define _RTP_DATA_PACKET_H_
8 
9 #include <arpa/inet.h> // for ntohs()/ntohl()
10 
11 #include "udppacket.h"
12 #include "mythlogging.h"
13 
14 #ifdef _MSC_VER
15 # include <WinSock2.h>
16 #endif
17 
30 class RTPDataPacket : public UDPPacket
31 {
32  public:
34  explicit RTPDataPacket(const UDPPacket &o) : UDPPacket(o), m_off(0) { }
35  explicit RTPDataPacket(uint64_t key) : UDPPacket(key), m_off(0) { }
36  RTPDataPacket(void) : UDPPacket(0ULL), m_off(0) { }
37 
39  {
41  m_off = rhs.m_off;
42  return *this;
43  }
44 
45  bool IsValid(void) const override // UDPPacket
46  {
47  if (m_data.size() < 12)
48  {
49  return false;
50  }
51  if (2 != GetVersion())
52  {
53  LOG(VB_GENERAL, LOG_INFO, QString("Version incorrect %1")
54  .arg(GetVersion()));
55  return false;
56  }
57 
58  int off = 12 + 4 * GetCSRCCount();
59  if (off > m_data.size())
60  {
61  LOG(VB_GENERAL, LOG_INFO, QString("off %1 > sz %2")
62  .arg(off).arg(m_data.size()));
63  return false;
64  }
65  if (HasExtension())
66  {
67  uint ext_size = m_data[off+2] << 8 | m_data[off+3];
68  off += 4 * (1 + ext_size);
69  }
70  if (off > m_data.size())
71  {
72  LOG(VB_GENERAL, LOG_INFO, QString("off + ext %1 > sz %2")
73  .arg(off).arg(m_data.size()));
74  return false;
75  }
76  m_off = off;
77 
78  return true;
79  }
80 
81  uint GetVersion(void) const { return (m_data[0] >> 6) & 0x3; }
82  bool HasPadding(void) const { return (m_data[0] >> 5) & 0x1; }
83  bool HasExtension(void) const { return (m_data[0] >> 4) & 0x1; }
84  uint GetCSRCCount(void) const { return m_data[0] & 0xf; }
85 
86  enum {
93  };
94 
95  uint GetPayloadType(void) const
96  {
97  return m_data[1] & 0x7f;
98  }
99 
101  {
102  return ntohs(*reinterpret_cast<const uint16_t*>(m_data.data()+2));
103  }
104 
105  uint GetTimeStamp(void) const
106  {
107  return ntohl(*reinterpret_cast<const uint32_t*>(m_data.data()+4));
108  }
109 
111  {
112  return ntohl(*reinterpret_cast<const uint32_t*>(m_data.data()+8));
113  }
114 
116  {
117  const uint32_t tmp =
118  *reinterpret_cast<const uint32_t*>(m_data.data() + 12 + 4 * i);
119  return ntohl(tmp);
120  }
121 
122  uint GetPayloadOffset(void) const { return m_off; }
123 
124  uint GetPaddingSize(void) const
125  {
126  if (!HasPadding())
127  return 0;
128  return m_data[m_data.size()-1];
129  }
130 
131  protected:
132  mutable uint m_off;
133 };
134 
135 #endif // _RTP_DATA_PACKET_H_
uint GetCSRCCount(void) const
Definition: rtpdatapacket.h:84
uint GetTimeStamp(void) const
RTPDataPacket(const UDPPacket &o)
Definition: rtpdatapacket.h:34
UDPPacket & operator=(const UDPPacket &rhs)
Definition: udppacket.h:28
uint GetVersion(void) const
Definition: rtpdatapacket.h:81
UDP Packet.
Definition: udppacket.h:20
uint GetSynchronizationSource(void) const
uint GetSequenceNumber(void) const
uint GetPayloadType(void) const
Definition: rtpdatapacket.h:95
unsigned int uint
Definition: compat.h:140
uint GetContributingSource(uint i) const
RTPDataPacket & operator=(const RTPDataPacket &rhs)
Definition: rtpdatapacket.h:38
static guint32 * tmp
Definition: goom_core.c:35
RTP Data Packet.
Definition: rtpdatapacket.h:30
uint GetPaddingSize(void) const
bool HasPadding(void) const
Definition: rtpdatapacket.h:82
RTPDataPacket(void)
Definition: rtpdatapacket.h:36
bool HasExtension(void) const
Definition: rtpdatapacket.h:83
RTPDataPacket(const RTPDataPacket &o)
Definition: rtpdatapacket.h:33
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
QByteArray m_data
Definition: udppacket.h:47
bool IsValid(void) const override
IsValid() must return true before any data access methods are called, other than GetDataReference() a...
Definition: rtpdatapacket.h:45
uint GetPayloadOffset(void) const
RTPDataPacket(uint64_t key)
Definition: rtpdatapacket.h:35