utils.h 2.43 KB
Newer Older
aymeric's avatar
aymeric committed
1
/*
2
 * Copyright (c) 2010-2019 Belledonne Communications SARL.
3
 *
4
 * This file is part of oRTP.
5
 *
6 7 8 9
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
10
 *
11 12 13 14 15 16 17
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
 */
aymeric's avatar
aymeric committed
19 20 21 22 23

#ifndef UTILS_H
#define UTILS_H

#include "ortp/event.h"
24
#include "ortp/rtpsession.h"
25 26 27
#if HAVE_STDATOMIC_H
#include <stdatomic.h>
#endif
aymeric's avatar
aymeric committed
28

29 30 31
void ortp_init_logger(void);
void ortp_uninit_logger(void);

32 33 34 35 36 37 38 39 40 41 42
struct datab {
	unsigned char *db_base;
	unsigned char *db_lim;
	void (*db_freefn)(void*);
#if HAVE_STDATOMIC_H
	atomic_int db_ref;
#else
	int db_ref;
#endif
};

43
#define OList bctbx_list_t
aymeric's avatar
aymeric committed
44 45 46


#define o_list_next(elem) ((elem)->next)
47
#define o_list_prev(elem) ((elem)->prev)
aymeric's avatar
aymeric committed
48

49 50 51 52 53 54
#define o_list_append bctbx_list_append
#define o_list_prepend bctbx_list_prepend
#define o_list_remove bctbx_list_remove
#define o_list_free bctbx_list_free
#define o_list_remove_link bctbx_list_erase_link
#define o_list_free_with_data bctbx_list_free_with_data
aymeric's avatar
aymeric committed
55 56


57 58
#define ORTP_POINTER_TO_INT(p) ((int)(intptr_t)(p))
#define ORTP_INT_TO_POINTER(i) ((void *)(intptr_t)(i))
59

aymeric's avatar
aymeric committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

typedef struct _dwsplit_t{
#ifdef ORTP_BIGENDIAN
	uint16_t hi;
	uint16_t lo;
#else
	uint16_t lo;
	uint16_t hi;
#endif
} dwsplit_t;

typedef union{
	dwsplit_t split;
	uint32_t one;
} poly32_t;

#ifdef ORTP_BIGENDIAN
#define hton24(x) (x)
#else
#define hton24(x) ((( (x) & 0x00ff0000) >>16) | (( (x) & 0x000000ff) <<16) | ( (x) & 0x0000ff00) )
#endif
#define ntoh24(x) hton24(x)

83
#if defined(_WIN32) || defined(_WIN32_WCE)
aymeric's avatar
aymeric committed
84 85 86 87 88 89 90
#define is_would_block_error(errnum)	(errnum==WSAEWOULDBLOCK)
#else
#define is_would_block_error(errnum)	(errnum==EWOULDBLOCK || errnum==EAGAIN)
#endif

void ortp_ev_queue_put(OrtpEvQueue *q, OrtpEvent *ev);

91 92
uint64_t ortp_timeval_to_ntp(const struct timeval *tv);

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);
aymeric's avatar
aymeric committed
95
#endif