Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / siproxd / src / rtpproxy.c
1 /*
2     Copyright (C) 2003-2005  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 <sys/types.h>
24 #include <netinet/in.h>
25
26 #include <osipparser2/osip_parser.h>
27
28 #include "siproxd.h"
29 #include "rtpproxy.h"
30 #include "log.h"
31
32 static char const ident[]="$Id: rtpproxy.c,v 1.25 2005/01/08 10:05:12 hb9xar Exp $";
33
34 /* configuration storage */
35 extern struct siproxd_config configuration;
36
37 /*
38  * initialize and create rtp_proxy
39  *
40  * RETURNS
41  *      STS_SUCCESS on success
42  */
43 int rtpproxy_init( void ) {
44   int sts=STS_FAILURE;
45
46    if (configuration.rtp_proxy_enable == 0) {
47       sts = STS_SUCCESS;
48    } else if (configuration.rtp_proxy_enable == 1) { // Relay
49       sts = rtp_relay_init ();
50    } else {
51       ERROR("CONFIG: rtp_proxy_enable has invalid value",
52             configuration.rtp_proxy_enable);
53    }
54
55    return sts;
56 }
57
58 /*
59  * start an rtp stream on the proxy
60  *
61  * RETURNS
62  *      STS_SUCCESS on success
63  *      STS_FAILURE on error
64  */
65 int rtp_start_fwd (osip_call_id_t *callid, char *client_id,
66                    int direction, int media_stream_no,
67                    struct in_addr local_ipaddr, int *local_port,
68                    struct in_addr remote_ipaddr, int remote_port) {
69   int sts=STS_FAILURE;
70
71    if (configuration.rtp_proxy_enable == 0) {
72       sts = STS_SUCCESS;
73    } else if (configuration.rtp_proxy_enable == 1) { // Relay
74       sts = rtp_relay_start_fwd (callid, client_id,
75                                  direction, media_stream_no,
76                                  local_ipaddr, local_port,
77                                  remote_ipaddr, remote_port);
78    } else {
79       ERROR("CONFIG: rtp_proxy_enable has invalid value",
80             configuration.rtp_proxy_enable);
81    }
82
83    return sts;
84 }
85
86
87 /*
88  * stop a rtp stream on the proxy
89  *
90  * RETURNS
91  *      STS_SUCCESS on success
92  *      STS_FAILURE on error
93  */
94 int rtp_stop_fwd (osip_call_id_t *callid, int direction) {
95    int sts = STS_FAILURE;
96
97    if (configuration.rtp_proxy_enable == 0) {
98       sts = STS_SUCCESS;
99    } else if (configuration.rtp_proxy_enable == 1) { // Relay
100       sts = rtp_relay_stop_fwd(0, callid, direction, 0);
101    } else {
102       ERROR("CONFIG: rtp_proxy_enable has invalid value",
103             configuration.rtp_proxy_enable);
104    }
105
106    return sts;
107 }