12024
|
1 /*
|
|
2 The mediastreamer library aims at providing modular media processing and I/O
|
|
3 for linphone, but also for any telephony application.
|
|
4 Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
|
|
5
|
|
6 This library is free software; you can redistribute it and/or
|
|
7 modify it under the terms of the GNU Lesser General Public
|
|
8 License as published by the Free Software Foundation; either
|
|
9 version 2.1 of the License, or (at your option) any later version.
|
|
10
|
|
11 This library 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 GNU
|
|
14 Lesser General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU Lesser General Public
|
|
17 License along with this library; if not, write to the Free Software
|
|
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 */
|
|
20
|
|
21 #include "mediastream.h"
|
|
22
|
|
23 #include <signal.h>
|
|
24 #include <sys/types.h>
|
|
25 #include <unistd.h>
|
|
26 #include <stdio.h>
|
|
27 #include <stdlib.h>
|
|
28 #include <string.h>
|
|
29
|
|
30 static int cond=1;
|
|
31
|
|
32 void stop_handler(int signum)
|
|
33 {
|
|
34 cond--;
|
|
35 if (cond<0) exit(-1);
|
|
36 }
|
|
37
|
|
38 void parse_addr(gchar *addr, char **ip, int *port)
|
|
39 {
|
|
40 char *semicolon;
|
|
41 gint iplen;
|
|
42
|
|
43 *ip=NULL;
|
|
44 *port=0;
|
|
45 semicolon=strchr(addr,':');
|
|
46 if (semicolon==NULL) return;
|
|
47 iplen=semicolon-addr;
|
|
48 *ip=g_malloc(iplen+1);
|
|
49 strncpy(*ip,addr,iplen);
|
|
50 (*ip)[iplen]='\0';
|
|
51 *port=atoi(semicolon+1);
|
|
52 }
|
|
53
|
|
54 char *usage="mediastream --local <port> --remote <ip:port> --payload <payload type>\n";
|
|
55 void run_media_streams(gint localport, gchar *remote_ip, gint remoteport, gint payload);
|
|
56
|
|
57 int main(int argc, char * argv[])
|
|
58 {
|
|
59 gint i;
|
|
60 gint localport=0,remoteport=0,payload=0;
|
|
61 gchar *ip;
|
|
62 gchar *tmp;
|
|
63
|
|
64 /*create the rtp session */
|
|
65 ortp_init();
|
|
66 ortp_set_debug_file("oRTP",NULL);
|
|
67 rtp_profile_set_payload(&av_profile,115,&lpc1015);
|
|
68 rtp_profile_set_payload(&av_profile,110,&speex_nb);
|
|
69
|
|
70 if (argc<4) {
|
|
71 printf(usage);
|
|
72 return -1;
|
|
73 }
|
|
74 for (i=1;i<argc;i++){
|
|
75 if (strcmp(argv[i],"--local")==0){
|
|
76 i++;
|
|
77 localport=atoi(argv[i]);
|
|
78 }else if (strcmp(argv[i],"--remote")==0){
|
|
79 i++;
|
|
80 parse_addr(argv[i],&ip,&remoteport);
|
|
81 if (ip==NULL) {
|
|
82 printf(usage);
|
|
83 return -1;
|
|
84 }
|
|
85 printf("Remote addr: ip=%s port=%i\n",ip,remoteport);
|
|
86 }else if (strcmp(argv[i],"--payload")==0){
|
|
87 i++;
|
|
88 payload=atoi(argv[i]);
|
|
89 }
|
|
90 }
|
|
91 tmp=getenv("defcard");
|
|
92 if (tmp!=NULL) audio_stream_set_default_card(atoi(tmp));
|
|
93 run_media_streams(localport,ip,remoteport,payload);
|
|
94 return 0;
|
|
95 }
|
|
96
|
|
97 void run_media_streams(gint localport, gchar *remote_ip, gint remoteport, gint payload)
|
|
98 {
|
|
99 AudioStream *audio;
|
|
100 ms_init();
|
|
101 ms_speex_codec_init();
|
|
102 signal(SIGINT,stop_handler);
|
|
103
|
|
104 audio=audio_stream_start(&av_profile,localport,remote_ip,remoteport,payload,250);
|
|
105 while(cond)
|
|
106 {
|
|
107 /* sleep until we receive SIGINT */
|
|
108 sleep(1);
|
|
109 }
|
|
110
|
|
111 printf("stoping all...\n");
|
|
112
|
|
113 audio_stream_stop(audio);
|
|
114 }
|