1 // Copyright (C) 2001-2015 Federico Montesino Pouzols <fedemp@altern.org>.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // ccRTP. If you copy code from other releases into a copy of GNU
28 // ccRTP, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU ccRTP, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37
46
47 NAMESPACE_COMMONCPP
48
49 #if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
52 #else
55 #endif
56
57 timeval
59 {
60 struct timeval t;
62 t.tv_usec = (uint32)((((double)lsw) * 1000000.0) / ((uint32)(~0)));
63 return t;
64 }
65
66 uint32
68 {
69 const uint32 f = 65536;
70 uint32 result = t.tv_sec * f;
71 result += (t.tv_usec << 12) / 125000 * 2; // * (4096 / 125000) * 2
72 return result;
73 }
74
75 timeval
77 {
78 timeval result;
79 result.tv_sec = to % 1000000;
80 result.tv_usec = to / 1000000;
81 return result;
82 }
83
85 rtcpSendBuffer(new unsigned char[mtu]()), rtcpRecvBuffer(new unsigned char[mtu]()),
86 pathMTU(mtu)
87 {
88 }
89
91 {
92 #ifdef CCXX_EXCEPTIONS
93 try {
94 #endif
96 #ifdef CCXX_EXCEPTIONS
97 } catch (...) {}
98 try {
99 #endif
101 #ifdef CCXX_EXCEPTIONS
102 } catch (...) {}
103 #endif
104 }
105
106 bool
108 {
109 // Note that the first packet in the compount --in order to
110 // detect possibly misaddressed RTP packets-- is more
111 // thoroughly checked than the following. This mask checks the
112 // first packet's version, padding (must be zero) and type
113 // (must be SR or RR).
117 return false;
118 }
119
120 // this checks that every packet in the compound is tagged
121 // with version == CCRTP_VERSION, and the length of the compound
122 // packet matches the addition of the packets lenghts
123 uint32 pointer = 0;
125 do {
128 pointer += (ntohs(pkt->
fh.
length)+1) << 2;
130
131 if ( pointer != len )
132 return false;
133
134 return true;
135 }
136
137 END_NAMESPACE
138
unsigned char * rtcpSendBuffer
NAMESPACE_COMMONCPP const uint32 NTP_EPOCH_OFFSET
const uint8 CCRTP_VERSION
RTP protocol version supported.
bool checkCompoundRTCPHeader(size_t len)
Perform RTCP compound packet header validity check as specified in draft-ietv-avt-rtp-new.
uint32 microtimeout_t
Time interval expressed in microseconds.
static const uint16 RTCP_VALID_VALUE
Declaration of ccRTP internal stuff.
Struct representing general RTCP packet headers as they are sent through the network.
uint32 timevalIntervalTo65536(timeval &t)
Convert a time interval, expressed as a timeval, into a 32-bit time interval expressed in units of 1/...
unsigned char * rtcpRecvBuffer
uint16 length
number of 32-bit words in the packet (minus one).
RTCPCompoundHandler(uint16 mtu=defaultPathMTU)
timeval microtimeout2Timeval(microtimeout_t to)
Convert a time interval, expressed as a microtimeout_t (number of microseconds), into a timeval value...
timeval NTP2Timeval(uint32 msw, uint32 lsw)
Convert a NTP timestamp, expressed as two 32-bit long words, into a timeval value.
static const uint16 RTCP_VALID_MASK
unsigned char version
Version, currently 2.
RTCPFixedHeader fh
Fixed RTCP header.