8 #define STREAMS_COUNT 1000
12 static char *help="usage: mrtprecv file_prefix local_port number_of_streams \n"
13 "Receives multiples rtp streams on local_port+2*k, k={0..number_of_streams}\n";
20 printf("====================================\n");
21 printf("Author : Simon Morlat =\n");
22 printf("Porting : Yann STEPHAN =\n");
23 printf("====================================\n");
25 memset(&strBuffer, 0x0, sizeof(strBuffer));
27 sprintf((char *) &strBuffer, "= RTPReceiver V1.0 - Date : %s - %s\n", __DATE__, __TIME__);
30 printf("====================================\n");
33 BOOL ctrlHandlerFunction(DWORD fdwCtrlType)
37 // Handle the CTRL+C signal.
38 // CTRL+CLOSE: confirm that the user wants to exit.
40 case CTRL_CLOSE_EVENT:
41 case CTRL_BREAK_EVENT:
42 case CTRL_LOGOFF_EVENT:
43 case CTRL_SHUTDOWN_EVENT:
52 int rtp2disk(RtpSession *session,uint32_t ts, FILE * fd)
59 err=rtp_session_recv_with_ts(session,buffer,160,ts,&havemore);
62 printf("==> Warning: havemore=1!\n");
66 rtp_session_set_data(session,(void*)1);
67 /* to indicate that (for the application) the stream has started, so we can start
71 if (session->user_data != NULL)
73 fwrite(&buffer,1,160, fd);
79 int GetSystemInformation()
81 SYSTEM_INFO SystemInfo;
83 GetSystemInfo(&SystemInfo);
85 return SystemInfo.dwNumberOfProcessors;
88 int __cdecl main(int argc, char *argv[])
90 RtpSession * session[STREAMS_COUNT];
91 FILE * filefd[STREAMS_COUNT];
100 int nSchedulerCPU = 2;
102 char strFilename[MAX_PATH];
112 channels=atoi(argv[3]);
118 // Now it's time to use the power of multiple CPUs
119 nCPUCount = GetSystemInformation();
121 printf("==> # of CPU detected : %d\n", nCPUCount);
124 ortp_scheduler_init();
133 /* if (ortp_bind_scheduler_to_cpu(nSchedulerCPU) != -1)
135 printf("==> Scheduler has been binded to CPU %d\n", nSchedulerCPU);
139 printf("==> Scheduler still binded to CPU 1\n");
146 for (i=0;i<channels;i++)
148 session[i]=rtp_session_new(RTP_SESSION_RECVONLY);
149 rtp_session_set_scheduling_mode(session[i],1);
150 rtp_session_set_blocking_mode(session[i],0);
151 rtp_session_set_local_addr(session[i],"0.0.0.0",port);
152 rtp_session_set_send_payload_type(session[i],0);
153 rtp_session_enable_adaptive_jitter_compensation(session[i], TRUE);
154 rtp_session_set_recv_buf_size(session[i],256);
158 memset(strFilename, 0x0, sizeof(strFilename));
160 for (i=0;i<channels;i++)
162 sprintf(strFilename,"%s%4.4d.dat",argv[1],i);
164 filefd[i]=fopen(strFilename, "wb");
168 printf("Could not open %s for writing: %s",strFilename,strerror(errno));
172 // =============== INSTALL THE CONTROL HANDLER ===============
173 if (SetConsoleCtrlHandler( (PHANDLER_ROUTINE) ctrlHandlerFunction, TRUE) == 0)
175 printf("==> Cannot handle the CTRL-C...\n");
179 set=session_set_new();
180 printf("==> RTP Receiver started\n");
182 while(m_bExit == FALSE)
186 for (k=0;k<channels;k++){
187 /* add the session to the set */
188 session_set_set(set,session[k]);
189 //printf("session_set_set %d\n", k);
191 /* and then suspend the process by selecting() */
192 k=session_set_select(set,NULL,NULL);
193 //printf("session_set_select\n");
196 printf("==> Warning: session_set_select() is returning 0...\n");
199 for (k=0;k<channels;k++){
200 if (session_set_is_set(set,session[k]))
202 rtp2disk(session[k],user_ts,filefd[k]);
203 //printf("==> Session_set_is_set %d\n", k);
207 //printf("warning: session %i is not set !\n",k);
213 printf("==> Exiting\n");
215 for (i=0;i<channels;i++)
218 rtp_session_destroy(session[i]);
220 session_set_destroy(set);
224 ortp_global_stats_display();
226 printf("Waiting for exit : ");
228 for (i = 0; i < 4*5; i++)