]> sjero.net Git - linphone/blob - linphone/oRTP/src/tests/rtpsend_stupid.c
80db79a28ebcbaaca0316382b73e13a0b348c26a
[linphone] / linphone / oRTP / src / tests / rtpsend_stupid.c
1   /*
2   The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) 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 <signal.h>
22 #include <stdlib.h>
23
24 #ifndef _WIN32 
25 #include <sys/types.h>
26 #include <sys/time.h>
27 #include <stdio.h>
28 #endif
29 /*defined in library, but not declared in public headers (this method is only useful for tests)*/
30 extern int __rtp_session_sendm_with_ts(RtpSession *session, mblk_t *packet, uint32_t packet_ts, uint32_t send_ts);
31
32 int runcond=1;
33
34 void stophandler(int signum)
35 {
36         runcond=0;
37 }
38
39 static char *help="usage: rtpsend       filename dest_ip4addr dest_port [ --with-clockslide <value> ] [ --with-ptime <milliseconds>]\n";
40
41 int main(int argc, char *argv[])
42 {
43         RtpSession *session;
44         unsigned char buffer[160];
45         int i;
46         FILE *infile;
47         char *ssrc;
48         uint32_t packet_ts=0,send_ts=0;
49         uint32_t send_ts_inc=160;
50         int clockslide=0;
51         int jitter=0;
52         if (argc<4){
53                 printf("%s",help);
54                 return -1;
55         }
56         for(i=4;i<argc;i++){
57                 if (strcmp(argv[i],"--with-clockslide")==0){
58                         i++;
59                         if (i>=argc) {
60                                 printf("%s",help);
61                                 return -1;
62                         }
63                         clockslide=atoi(argv[i]);
64                         ortp_message("Using clockslide of %i milisecond every 50 packets.",clockslide);
65                 }else if (strcmp(argv[i],"--with-ptime")==0){
66                         ortp_message("Ptime related jitter will be added to outgoing stream.");
67                         i++;
68                         if (i>=argc) {
69                                 printf("%s",help);
70                                 return -1;
71                         }
72                         jitter=atoi(argv[i]);
73                         send_ts_inc=jitter*8;
74                 }
75         }
76         
77         ortp_init();
78         ortp_scheduler_init();
79         ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
80         session=rtp_session_new(RTP_SESSION_SENDONLY);  
81         
82         rtp_session_set_scheduling_mode(session,1);
83         rtp_session_set_blocking_mode(session,1);
84         rtp_session_set_connected_mode(session,TRUE);
85         rtp_session_set_remote_addr(session,argv[2],atoi(argv[3]));
86         rtp_session_set_payload_type(session,0);
87         
88         ssrc=getenv("SSRC");
89         if (ssrc!=NULL) {
90                 printf("using SSRC=%i.\n",atoi(ssrc));
91                 rtp_session_set_ssrc(session,atoi(ssrc));
92         }
93                 
94         #ifndef _WIN32
95         infile=fopen(argv[1],"r");
96         #else
97         infile=fopen(argv[1],"rb");
98         #endif
99
100         if (infile==NULL) {
101                 perror("Cannot open file");
102                 return -1;
103         }
104
105         signal(SIGINT,stophandler);
106         while( ((i=fread(buffer,1,160,infile))>0) && (runcond) )
107         {
108                 mblk_t *m=rtp_session_create_packet(session,RTP_FIXED_HEADER_SIZE,buffer,i);
109                 __rtp_session_sendm_with_ts(session,m,packet_ts,send_ts);
110                 packet_ts+=160;
111                 if ((send_ts+send_ts_inc)<=packet_ts){
112                         send_ts+=send_ts_inc;
113                 }
114                 if (clockslide!=0 && send_ts%(160*50)==0){
115                         ortp_message("Clock sliding of %i miliseconds now",clockslide);
116                         rtp_session_make_time_distorsion(session,clockslide);
117                 }
118         }
119
120         fclose(infile);
121         rtp_session_destroy(session);
122         ortp_exit();
123         ortp_global_stats_display();
124
125         return 0;
126 }