blob: a162f46ceaee6fef4139014e0769308ca044e2f2 [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001// Copyright (C) 2001-2005 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
38#ifndef CCXX_RTP_BASE_H_
39#define CCXX_RTP_BASE_H_
40
41#ifndef CCXX_SOCKET_H_
42#include <cc++/config.h>
43#include <cc++/socket.h>
44#endif
45
46#ifndef CCXX_PACKING
47#if defined(__GNUC__)
48#define CCXX_PACKED
49#elif !defined(__hpux) && !defined(_AIX)
50#define CCXX_PACKED
51#endif
52#endif
53
54#ifdef CCXX_NAMESPACES
55namespace ost {
56#endif
57
58/**
59 * @file base.h
60 *
61 * @short Base elements for RTP stacks: constants, types and global
62 * functions.
63 **/
64
65/// RTP protocol version supported.
66const uint8 CCRTP_VERSION = 2;
67
68/// Time interval expressed in microseconds.
69typedef uint32 microtimeout_t;
70
71/// Time interval expressed in nanoseconds.
72typedef uint32 nanotimeout_t;
73
74/**
75 * Convert a time interval, expressed as a microtimeout_t (number of
76 * microseconds), into a timeval value.
77 *
78 * @param to time interval, in microseconds.
79 * @return the same time interval, as a timeval value.
80 **/
81__EXPORT timeval
82microtimeout2Timeval(microtimeout_t to);
83
84/**
85 * Convert a time interval, expressed as a timeval value into a
86 * microseconds counter.
87 *
88 * @param t time, as a timeval.
89 * @return the same time, as a microseconds counter.
90 **/
91inline microtimeout_t
92timeval2microtimeout(const timeval& t)
93{ return ((t.tv_sec * 1000000ul) + t.tv_usec); }
94
95/**
96 * Convert a time interval, expressed as the difference between two
97 * timeval values (t1-t2), into a microseconds counter.
98 *
99 * @param t1 First timeval.
100 * @param t2 Second timeval.
101 * @return difference between t1 and t2, in microseconds.
102 **/
103inline microtimeout_t
104timevalDiff2microtimeout(const timeval& t1, const timeval& t2)
105{
106 return ((t1.tv_sec - t2.tv_sec) * 1000000ul) +
107 (t1.tv_usec - t2.tv_usec);
108}
109
110/// registered default RTP data transport port
111const tpport_t DefaultRTPDataPort = 5004;
112
113/// registered default RTCP transport port
114const tpport_t DefaultRTCPPort = 5005;
115
116#ifndef HAVE_GETTIMEOFDAY
117#ifdef WIN32
118__EXPORT int
119gettimeofday(struct timeval *tv_, void *tz_);
120#endif
121#endif
122
123#ifdef CCXX_NAMESPACES
124}
125#endif
126
127#endif // ndef CCXX_RTP_BASE_H_
128
129/** EMACS **
130 * Local variables:
131 * mode: c++
132 * c-basic-offset: 8
133 * End:
134 */