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>
33 #include <sys/types.h>
40 void stophandler(int signum)
45 static char *help="usage: mrtprecv file_prefix local_port number_of_streams \n"
46 "Receives multiples rtp streams on local_port+2*k, k={0..number_of_streams}\n";
48 #define STREAMS_COUNT 1000
50 /* malloc'd in order to detect buffer overflows with efence */
51 static uint8_t* recvbuf=0;
53 int rtp2disk(RtpSession *session,uint32_t ts, int fd)
57 err=rtp_session_recv_with_ts(session,recvbuf,160,ts,&havemore);
58 if (havemore) printf("warning: havemore=%i!\n",havemore);
60 rtp_session_set_data(session,(void*)1);
61 /* to indicate that (for the application) the stream has started, so we can start
64 if (session->user_data != NULL) {
65 size_t ret = write(fd,recvbuf,err);
73 int main(int argc, char *argv[])
75 RtpSession *session[STREAMS_COUNT];
77 int filefd[STREAMS_COUNT];
89 channels=atoi(argv[3]);
96 ortp_scheduler_init();
99 recvbuf=ortp_malloc(160);
101 for (i=0;i<channels;i++){
103 session[i]=rtp_session_new(RTP_SESSION_RECVONLY);
104 rtp_session_set_scheduling_mode(session[i],1);
105 rtp_session_set_blocking_mode(session[i],0);
106 rtp_session_set_local_addr(session[i],"0.0.0.0",port);
107 rtp_session_set_payload_type(session[i],0);
108 rtp_session_enable_adaptive_jitter_compensation(session[i], TRUE);
109 rtp_session_set_recv_buf_size(session[i],256);
113 filename=ortp_malloc(strlen(argv[1])+15);
114 for (i=0;i<channels;i++){
115 sprintf(filename,"%s%4.4d.dat",argv[1],i);
117 filefd[i]=open(filename,O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
119 filefd[i]=open(filename,_O_BINARY | O_WRONLY | O_CREAT | O_TRUNC);
121 if (filefd[i]<0) ortp_error("Could not open %s for writing: %s",filename,strerror(errno));
123 signal(SIGINT,stophandler);
125 set=session_set_new();
130 for (k=0;k<channels;k++){
131 /* add the session to the set */
132 session_set_set(set,session[k]);
133 //printf("session_set_set %d\n", k);
135 /* and then suspend the process by selecting() */
136 k=session_set_select(set,NULL,NULL);
137 if (k==0) printf("warning: session_set_select() is returning 0...\n");
138 for (k=0;k<channels;k++){
139 if (session_set_is_set(set,session[k])){
140 rtp2disk(session[k],user_ts,filefd[k]);
141 //printf("session_set_is_set %d\n", k);
143 //printf("warning: session %i is not set !\n",k);
149 for (i=0;i<channels;i++){
151 rtp_session_destroy(session[i]);
153 session_set_destroy(set);
156 ortp_global_stats_display();