2 The oRTP LinPhone RTP library intends to provide basics for a RTP stack.
3 Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
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.
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.
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
20 /* this program shows how to receive streams in paralel using the SessionSet api
21 and two threads only. */
23 #include <ortp/ortp.h>
30 #include <sys/types.h>
40 #include <ortp/telephonyevents.h>
44 void stophandler(int signum)
49 static int dtmf_tab[16]={'0','1','2','3','4','5','6','7','8','9','*','#','A','B','C','D'};
51 static int *p_channel_id;
55 static char *help="usage: tevmrtprecv file_prefix local_port number_of_streams \n"
56 "Receives multiples rtp streams with telephone events on local_port+2*k, k={0..number_of_streams}\n";
58 #define STREAMS_COUNT 1000
61 void recv_tev_cb(RtpSession *session,int type,long user_data)
63 //printf("Receiving telephony event:%i\n",type);
64 if (type<16) printf("This is dtmf %c on channel %d\n",dtmf_tab[type],*(int *)user_data);
68 int rtp2disk(RtpSession *session,uint32_t ts, int fd)
70 unsigned char buffer[160];
73 err=rtp_session_recv_with_ts(session,buffer,160,ts,&havemore);
75 rtp_session_set_data(session,(void*)1);
76 /* to indicate that (for the application) the stream has started, so we can start
79 if (session->user_data != NULL) {
80 size_t ret = write(fd,buffer,err);
88 int main(int argc, char *argv[])
90 RtpSession *session[STREAMS_COUNT];
92 int filefd[STREAMS_COUNT];
104 channels=atoi(argv[3]);
111 ortp_scheduler_init();
113 /* set the telephony event payload type to 96 in the av profile.*/
114 rtp_profile_set_payload(&av_profile,96,&payload_type_telephone_event);
117 p_channel_id = (int *)ortp_malloc(channels*sizeof(int));
118 for (i=0;i<channels;i++){
119 session[i]=rtp_session_new(RTP_SESSION_RECVONLY);
120 rtp_session_set_scheduling_mode(session[i],1);
121 rtp_session_set_blocking_mode(session[i],0);
123 rtp_session_set_local_addr(session[i],"0.0.0.0",port);
124 rtp_session_set_recv_payload_type(session[i],0);
125 rtp_session_set_recv_buf_size(session[i],256);
128 /* register for telephony events */
129 rtp_session_signal_connect(session[i],"telephone-event",(RtpCallback)recv_tev_cb,(long)&p_channel_id[i]);
134 filename=ortp_malloc(strlen(argv[1])+8);
135 for (i=0;i<channels;i++){
136 sprintf(filename,"%s%4.4d.dat",argv[1],i);
138 filefd[i]=open(filename,O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
140 filefd[i]=open(filename,_O_BINARY | O_WRONLY | O_CREAT | O_TRUNC);
142 if (filefd[i]<0) ortp_error("Could not open %s for writing: %s",filename,strerror(errno));
144 signal(SIGINT,stophandler);
146 set=session_set_new();
151 for (k=0;k<channels;k++){
152 /* add the session to the set */
153 session_set_set(set,session[k]);
156 /* and then suspend the process by selecting() */
157 session_set_select(set,NULL,NULL);
158 for (k=0;k<channels;k++){
159 if (session_set_is_set(set,session[k])){
160 rtp2disk(session[k],user_ts,filefd[k]);
165 for (i=0;i<channels;i++){
167 rtp_session_destroy(session[i]);
169 session_set_destroy(set);
170 ortp_free(p_channel_id);
173 ortp_global_stats_display();