2 The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) 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
21 #include <ortp/ortp.h>
27 #include <sys/types.h>
32 void stop_handler(int signum)
37 void ssrc_cb(RtpSession *session)
39 printf("hey, the ssrc has changed !\n");
42 static char *help="usage: rtprecv filename loc_port [--format format] [--soundcard] [--noadapt] [--with-jitter <milliseconds>]\n";
47 #if defined(__hpux) && HAVE_SYS_AUDIO_H
49 #include <sys/audio.h>
51 int sound_init(int format)
54 fd=open("/dev/audio",O_WRONLY);
56 perror("Can't open /dev/audio");
59 ioctl(fd,AUDIO_RESET,0);
60 ioctl(fd,AUDIO_SET_SAMPLE_RATE,8000);
61 ioctl(fd,AUDIO_SET_CHANNELS,1);
63 ioctl(fd,AUDIO_SET_DATA_FORMAT,AUDIO_FORMAT_ULAW);
64 else ioctl(fd,AUDIO_SET_DATA_FORMAT,AUDIO_FORMAT_ALAW);
68 int sound_init(int format)
74 int main(int argc, char*argv[])
77 unsigned char buffer[160];
80 int stream_received=0;
96 local_port=atoi(argv[2]);
103 if (strcmp(argv[i],"--noadapt")==0) adapt=FALSE;
104 if (strcmp(argv[i],"--format")==0){
107 if (strcmp(argv[i],"mulaw")==0){
110 if (strcmp(argv[i],"alaw")==0){
113 printf("Unsupported format %s\n",argv[i]);
118 else if (strcmp(argv[i],"--soundcard")==0){
121 else if (strcmp(argv[i],"--with-jitter")==0){
124 jittcomp=atoi(argv[i]);
125 printf("Using a jitter buffer of %i milliseconds.\n",jittcomp);
130 outfile=fopen(argv[1],"wb");
132 perror("Cannot open file for writing");
138 sound_fd=sound_init(format);
142 ortp_scheduler_init();
143 ortp_set_log_level_mask(ORTP_DEBUG|ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
144 signal(SIGINT,stop_handler);
145 session=rtp_session_new(RTP_SESSION_RECVONLY);
146 rtp_session_set_scheduling_mode(session,1);
147 rtp_session_set_blocking_mode(session,1);
148 rtp_session_set_local_addr(session,"0.0.0.0",atoi(argv[2]));
149 rtp_session_set_connected_mode(session,TRUE);
150 rtp_session_set_symmetric_rtp(session,TRUE);
151 rtp_session_enable_adaptive_jitter_compensation(session,adapt);
152 rtp_session_set_jitter_compensation(session,jittcomp);
153 rtp_session_set_payload_type(session,0);
154 rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)ssrc_cb,0);
155 rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)rtp_session_reset,0);
161 err=rtp_session_recv_with_ts(session,buffer,160,ts,&have_more);
162 if (err>0) stream_received=1;
163 /* this is to avoid to write to disk some silence before the first RTP packet is returned*/
164 if ((stream_received) && (err>0)) {
165 size_t ret = fwrite(buffer,1,err,outfile);
167 ret = write(sound_fd,buffer,err);
171 //ortp_message("Receiving packet.");
174 rtp_session_destroy(session);
177 ortp_global_stats_display();