blob: a248f6a79a013c66d29dd378df411a28c396f17d [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001// Copyright (C) 2001-2005 Federico Montesino Pouzols <fedemp@altern.org>.
Alexandre Lisionddd731e2014-01-31 11:50:08 -05002//
Emeric Vigier2f625822012-08-06 11:09:52 -04003// 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.
Alexandre Lisionddd731e2014-01-31 11:50:08 -05007//
Emeric Vigier2f625822012-08-06 11:09:52 -04008// 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.
Alexandre Lisionddd731e2014-01-31 11:50:08 -050012//
Emeric Vigier2f625822012-08-06 11:09:52 -040013// You should have received a copy of the GNU General Public License
Alexandre Lisionddd731e2014-01-31 11:50:08 -050014// along with this program; if not, write to the Free Software
Emeric Vigier2f625822012-08-06 11:09:52 -040015// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Alexandre Lisionddd731e2014-01-31 11:50:08 -050016//
Emeric Vigier2f625822012-08-06 11:09:52 -040017// 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
Alexandre Lisionddd731e2014-01-31 11:50:08 -050022// the GNU General Public License. This exception does not however
Emeric Vigier2f625822012-08-06 11:09:52 -040023// invalidate any other reasons why the executable file might be covered by
Alexandre Lisionddd731e2014-01-31 11:50:08 -050024// the GNU General Public License.
Emeric Vigier2f625822012-08-06 11:09:52 -040025//
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
Alexandre Lisionddd731e2014-01-31 11:50:08 -050038#ifndef CCXX_RTP_BASE_H_
Emeric Vigier2f625822012-08-06 11:09:52 -040039#define CCXX_RTP_BASE_H_
40
Alexandre Lisionddd731e2014-01-31 11:50:08 -050041#ifndef CCXX_SOCKET_H_
42#include <commoncpp/config.h>
43#include <commoncpp/socket.h>
44#include <commoncpp/udp.h>
Emeric Vigier2f625822012-08-06 11:09:52 -040045#endif
46
Alexandre Lisionddd731e2014-01-31 11:50:08 -050047#ifndef CCXX_PACKING
Emeric Vigier2f625822012-08-06 11:09:52 -040048#if defined(__GNUC__)
49#define CCXX_PACKED
50#elif !defined(__hpux) && !defined(_AIX)
Alexandre Lisionddd731e2014-01-31 11:50:08 -050051#define CCXX_PACKED
52#endif
Emeric Vigier2f625822012-08-06 11:09:52 -040053#endif
54
Alexandre Lisionddd731e2014-01-31 11:50:08 -050055NAMESPACE_COMMONCPP
Emeric Vigier2f625822012-08-06 11:09:52 -040056
Alexandre Lisionddd731e2014-01-31 11:50:08 -050057/**
58 * @file base.h
Emeric Vigier2f625822012-08-06 11:09:52 -040059 *
60 * @short Base elements for RTP stacks: constants, types and global
61 * functions.
62 **/
63
64/// RTP protocol version supported.
65const uint8 CCRTP_VERSION = 2;
66
67/// Time interval expressed in microseconds.
68typedef uint32 microtimeout_t;
69
70/// Time interval expressed in nanoseconds.
71typedef uint32 nanotimeout_t;
72
73/**
74 * Convert a time interval, expressed as a microtimeout_t (number of
75 * microseconds), into a timeval value.
76 *
77 * @param to time interval, in microseconds.
78 * @return the same time interval, as a timeval value.
79 **/
Alexandre Lisionddd731e2014-01-31 11:50:08 -050080__EXPORT timeval
Emeric Vigier2f625822012-08-06 11:09:52 -040081microtimeout2Timeval(microtimeout_t to);
82
83/**
84 * Convert a time interval, expressed as a timeval value into a
85 * microseconds counter.
86 *
87 * @param t time, as a timeval.
88 * @return the same time, as a microseconds counter.
89 **/
90inline microtimeout_t
91timeval2microtimeout(const timeval& t)
92{ return ((t.tv_sec * 1000000ul) + t.tv_usec); }
93
94/**
95 * Convert a time interval, expressed as the difference between two
96 * timeval values (t1-t2), into a microseconds counter.
97 *
98 * @param t1 First timeval.
99 * @param t2 Second timeval.
100 * @return difference between t1 and t2, in microseconds.
101 **/
102inline microtimeout_t
103timevalDiff2microtimeout(const timeval& t1, const timeval& t2)
104{
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500105 return ((t1.tv_sec - t2.tv_sec) * 1000000ul) +
106 (t1.tv_usec - t2.tv_usec);
Emeric Vigier2f625822012-08-06 11:09:52 -0400107}
108
109/// registered default RTP data transport port
110const tpport_t DefaultRTPDataPort = 5004;
111
112/// registered default RTCP transport port
113const tpport_t DefaultRTCPPort = 5005;
114
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500115END_NAMESPACE
Emeric Vigier2f625822012-08-06 11:09:52 -0400116
117#endif // ndef CCXX_RTP_BASE_H_
118
119/** EMACS **
120 * Local variables:
121 * mode: c++
122 * c-basic-offset: 8
123 * End:
124 */