1 /*
2 Copyright (C) 2003-2009 Thomas Ries <tries@gmx.net>
3
4 This file is part of Siproxd.
5
6 Siproxd is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 Siproxd is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Siproxd; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include "config.h"
22
23 #include <unistd.h>
24 #include <sys/types.h>
25 #include <netinet/in.h>
26
27 #include <osipparser2/osip_parser.h>
28
29 #include "siproxd.h"
30 #include "rtpproxy.h"
31 #include "log.h"
32
33 static char const ident[]="$Id: rtpproxy.c 533 2015-12-16 17:45:17Z hb9xar $";
34
35 /* configuration storage */
36 extern struct siproxd_config configuration;
37
38 /*
39 * initialize and create rtp_proxy
40 *
41 * RETURNS
42 * STS_SUCCESS on success
43 */
rtpproxy_init(void)44 int rtpproxy_init( void ) {
45 int sts=STS_FAILURE;
46
47 if (configuration.rtp_proxy_enable == 0) {
48 sts = STS_SUCCESS;
49 } else if (configuration.rtp_proxy_enable == 1) { // Relay
50 sts = rtp_relay_init ();
51 if ((configuration.rtp_output_dejitter < 0) ||
52 (configuration.rtp_output_dejitter > DEJITTERLIMIT)) {
53 ERROR("CONFIG: rtp_output_dejitter has invalid value %i [0 .. %i]",
54 configuration.rtp_output_dejitter, DEJITTERLIMIT) ;
55 }
56 if ((configuration.rtp_input_dejitter < 0) ||
57 (configuration.rtp_input_dejitter > DEJITTERLIMIT)) {
58 ERROR("CONFIG: rtp_input_dejitter has invalid value %i [0 .. %i]",
59 configuration.rtp_input_dejitter, DEJITTERLIMIT) ;
60 }
61 } else {
62 ERROR("CONFIG: rtp_proxy_enable has invalid value: %d",
63 configuration.rtp_proxy_enable);
64 }
65
66 return sts;
67 }
68
69 /*
70 * start an rtp stream on the proxy
71 *
72 * RETURNS
73 * STS_SUCCESS on success
74 * STS_FAILURE on error
75 */
rtp_start_fwd(osip_call_id_t * callid,client_id_t client_id,int direction,int call_direction,int media_stream_no,struct in_addr local_ipaddr,int * local_port,struct in_addr remote_ipaddr,int remote_port,int isrtp)76 int rtp_start_fwd (osip_call_id_t *callid, client_id_t client_id,
77 int direction, int call_direction, int media_stream_no,
78 struct in_addr local_ipaddr, int *local_port,
79 struct in_addr remote_ipaddr, int remote_port,
80 int isrtp) {
81 int sts=STS_FAILURE;
82 int dejitter=0;
83
84 if (configuration.rtp_proxy_enable == 0) {
85 sts = STS_SUCCESS;
86 } else if (configuration.rtp_proxy_enable == 1) { // Relay
87 if (isrtp) {
88 if (direction == DIR_OUTGOING) {
89 dejitter = configuration.rtp_output_dejitter;
90 } else {
91 dejitter = configuration.rtp_input_dejitter;
92 }
93 }
94 sts = rtp_relay_start_fwd (callid, client_id,
95 direction, call_direction, media_stream_no,
96 local_ipaddr, local_port,
97 remote_ipaddr, remote_port, dejitter);
98 } else {
99 ERROR("CONFIG: rtp_proxy_enable has invalid value: %d",
100 configuration.rtp_proxy_enable);
101 }
102
103 return sts;
104 }
105
106
107 /*
108 * stop a rtp stream on the proxy
109 *
110 * RETURNS
111 * STS_SUCCESS on success
112 * STS_FAILURE on error
113 */
rtp_stop_fwd(osip_call_id_t * callid,int direction)114 int rtp_stop_fwd (osip_call_id_t *callid, int direction) {
115 int sts = STS_FAILURE;
116
117 if (configuration.rtp_proxy_enable == 0) {
118 sts = STS_SUCCESS;
119 } else if (configuration.rtp_proxy_enable == 1) { // Relay
120 sts = rtp_relay_stop_fwd(callid, direction, -1, LOCK_FDSET);
121 } else {
122 ERROR("CONFIG: rtp_proxy_enable has invalid value: %d",
123 configuration.rtp_proxy_enable);
124 }
125
126 return sts;
127 }
128