1 /*
2  * The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) implementation with additional features.
3  * Copyright (C) 2017 Belledonne Communications SARL
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19 
20 #ifndef UTILS_H
21 #define UTILS_H
22 
23 #include "ortp/event.h"
24 #include "ortp/rtpsession.h"
25 #if HAVE_STDATOMIC_H
26 #include <stdatomic.h>
27 #endif
28 
29 void ortp_init_logger(void);
30 void ortp_uninit_logger(void);
31 
32 struct datab {
33 	unsigned char *db_base;
34 	unsigned char *db_lim;
35 	void (*db_freefn)(void*);
36 #if HAVE_STDATOMIC_H
37 	atomic_int db_ref;
38 #else
39 	int db_ref;
40 #endif
41 };
42 
43 #define OList bctbx_list_t
44 
45 
46 #define o_list_next(elem) ((elem)->next)
47 #define o_list_prev(elem) ((elem)->prev)
48 
49 #define o_list_append bctbx_list_append
50 #define o_list_prepend bctbx_list_prepend
51 #define o_list_remove bctbx_list_remove
52 #define o_list_free bctbx_list_free
53 #define o_list_remove_link bctbx_list_erase_link
54 #define o_list_free_with_data bctbx_list_free_with_data
55 
56 
57 #define ORTP_POINTER_TO_INT(p) ((int)(intptr_t)(p))
58 #define ORTP_INT_TO_POINTER(i) ((void *)(intptr_t)(i))
59 
60 
61 typedef struct _dwsplit_t{
62 #ifdef ORTP_BIGENDIAN
63 	uint16_t hi;
64 	uint16_t lo;
65 #else
66 	uint16_t lo;
67 	uint16_t hi;
68 #endif
69 } dwsplit_t;
70 
71 typedef union{
72 	dwsplit_t split;
73 	uint32_t one;
74 } poly32_t;
75 
76 #ifdef ORTP_BIGENDIAN
77 #define hton24(x) (x)
78 #else
79 #define hton24(x) ((( (x) & 0x00ff0000) >>16) | (( (x) & 0x000000ff) <<16) | ( (x) & 0x0000ff00) )
80 #endif
81 #define ntoh24(x) hton24(x)
82 
83 #if defined(_WIN32) || defined(_WIN32_WCE)
84 #define is_would_block_error(errnum)	(errnum==WSAEWOULDBLOCK)
85 #else
86 #define is_would_block_error(errnum)	(errnum==EWOULDBLOCK || errnum==EAGAIN)
87 #endif
88 
89 void ortp_ev_queue_put(OrtpEvQueue *q, OrtpEvent *ev);
90 
91 uint64_t ortp_timeval_to_ntp(const struct timeval *tv);
92 
93 int _ortp_sendto(ortp_socket_t sockfd, mblk_t *m, int flags, const struct sockaddr *destaddr, socklen_t destlen);
94 void _rtp_session_release_sockets(RtpSession *session, bool_t release_transports);
95 #endif
96