]> sjero.net Git - linphone/blob - linphone/oRTP/src/tests/tevrtprecv.c
d5ef8c10aca8266038fde8eeef2a42550b6fa1fb
[linphone] / linphone / oRTP / src / tests / tevrtprecv.c
1 /*
2   The oRTP LinPhone RTP library intends to provide basics for a RTP stack.
3   Copyright (C) 2001  Simon MORLAT simon.morlat@linphone.org
4
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9
10   This library 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 GNU
13   Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20 #include <ortp/ortp.h>
21 #include <ortp/telephonyevents.h>
22 #include <signal.h>
23 #include <stdlib.h>
24 #include <assert.h>
25 #include <sys/types.h>
26 #ifndef _WIN32
27 #include <sys/time.h>
28 #else
29 #include <time.h>
30 #endif
31 #include <stdio.h>
32
33 int runcond=1;
34
35 static int dtmf_tab[16]={'0','1','2','3','4','5','6','7','8','9','*','#','A','B','C','D'};
36
37 void stophandler(int signum)
38 {
39         runcond=0;
40 }
41
42 static char *help="usage: test_tevrecv  filename loc_port\n";
43
44 int dtmf_count=0;
45
46 void recv_tev_cb(RtpSession *session,int type,long user_data)
47 {
48         printf("Receiving telephony event:%i\n",type);
49         if (type<16) printf("This is dtmf %c\n",dtmf_tab[type]);
50         dtmf_count++;
51 }
52
53 int main(int argc, char *argv[])
54 {
55         RtpSession *session;
56         unsigned char buffer[160];
57         int err;
58         FILE *outfile;
59         uint32_t ts=0;
60         int have_more;
61
62         if (argc<3){
63                 printf("%s",help);
64                 return -1;
65         }
66
67         ortp_init();
68         ortp_scheduler_init();
69         
70         /* set the telephony event payload type to 96 in the av profile.*/
71         rtp_profile_set_payload(&av_profile,96,&payload_type_telephone_event);
72         
73         session=rtp_session_new(RTP_SESSION_RECVONLY);  
74         
75         rtp_session_set_scheduling_mode(session,1);
76         rtp_session_set_blocking_mode(session,1);
77         rtp_session_set_local_addr(session,"0.0.0.0",atoi(argv[2]));
78         rtp_session_set_payload_type(session,0);
79         
80         /* register for telephony events */
81         rtp_session_signal_connect(session,"telephone-event",(RtpCallback)recv_tev_cb,0);
82                 
83         outfile=fopen(argv[1],"wb");
84         if (outfile==NULL) {
85                 perror("Cannot open file");
86                 return -1;
87         }
88         signal(SIGINT,stophandler);
89         while(runcond)
90         {
91                 have_more=1;
92                 while (have_more){
93                         err=rtp_session_recv_with_ts(session,buffer,160,ts,&have_more);
94                         if (err>0) {
95                                 size_t ret = fwrite(buffer,1,err,outfile);
96                                 assert( ret == err );
97                         }
98                 }
99                 ts+=160;
100                 //ortp_message("Receiving packet.");
101         }
102         fclose(outfile);
103         rtp_session_destroy(session);
104         ortp_exit();
105         ortp_global_stats_display();
106         printf("Total dtmf events received: %i\n",dtmf_count);
107         return 0;
108 }