~ubuntu-branches/ubuntu/vivid/linphone/vivid

« back to all changes in this revision

Viewing changes to oRTP/src/tests/mrtpsend.c

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-11-15 10:34:50 UTC
  • mfrom: (1.2.1 upstream) (2.1.8 feisty)
  • Revision ID: james.westby@ubuntu.com-20061115103450-qgafwcks2lkhctlj
* New upstream release.
* Enable video support.
* Fix mismatched #endif in mscommon.h, closes: #398307.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
  /*
 
2
  The oRTP LinPhone RTP library intends to provide basics for a RTP 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
/* this program shows how to send streams in paralel using the SessionSet api 
 
21
        and two threads only. */
 
22
 
 
23
#include <ortp/ortp.h>
 
24
#include <signal.h>
 
25
#include <stdlib.h>
 
26
#include <stdio.h>
 
27
 
 
28
#ifndef _WIN32 
 
29
#include <sys/types.h>
 
30
#include <sys/time.h>
 
31
#endif
 
32
 
 
33
 
 
34
int runcond=1;
 
35
 
 
36
void stophandler(int signum)
 
37
{
 
38
        runcond=0;
 
39
}
 
40
 
 
41
static char *help="usage: mrtpsend      filename ip port nstreams [--packet-size size] [--ts-inc value]\n";
 
42
 
 
43
#define STREAMS_COUNT 1000
 
44
 
 
45
 
 
46
 
 
47
int main(int argc, char *argv[])
 
48
{
 
49
        RtpSession *session[STREAMS_COUNT];
 
50
        unsigned char *buffer;
 
51
        int packet_size=160;
 
52
        int ts_inc=160;
 
53
        int i;
 
54
        FILE *infile;
 
55
        char *ssrc;
 
56
        int port;
 
57
        uint32_t user_ts=0;
 
58
        int channels;
 
59
        SessionSet *set;
 
60
        
 
61
        if (argc<5){
 
62
                printf(help);
 
63
                return -1;
 
64
        }
 
65
        
 
66
        channels=atoi(argv[4]);
 
67
        if (channels==0){
 
68
                printf(help);
 
69
                return -1;
 
70
        }
 
71
        
 
72
        /* look at command line options */
 
73
        for (i=5;i<argc;i++)
 
74
        {
 
75
                if (strcmp(argv[i],"--packet-size")==0)
 
76
                {
 
77
                        if ( i+1 < argc ){
 
78
                                packet_size=atoi(argv[i+1]);
 
79
                        }
 
80
                        else {
 
81
                                printf(help);
 
82
                                return -1;
 
83
                        }
 
84
                        if (packet_size==0) {
 
85
                                printf("Packet size can't be %s.\n",argv[i+1]);
 
86
                                return -1;
 
87
                        }
 
88
                        i+=1;
 
89
                        
 
90
                }
 
91
                else if (strcmp(argv[i],"--ts-inc")==0)
 
92
                {
 
93
                        if ( i+1 < argc ){
 
94
                                ts_inc=atoi(argv[i+1]);
 
95
                        }
 
96
                        else {
 
97
                                printf(help);
 
98
                                return -1;
 
99
                        }
 
100
                        if (ts_inc==0) {
 
101
                                printf("Timestanp increment can't be %s.\n",argv[i+1]);
 
102
                                return -1;
 
103
                        }
 
104
                        i+=1;
 
105
                        
 
106
                }
 
107
        }
 
108
        printf("Timestamp increment will be %i\n",ts_inc);
 
109
        printf("Packet size will be %i\n",packet_size);
 
110
        buffer=ortp_malloc(packet_size);
 
111
        ortp_init();
 
112
        ortp_scheduler_init();
 
113
        printf("scheduler initialized\n");
 
114
        ssrc=getenv("SSRC");
 
115
        port=atoi(argv[3]);
 
116
        for (i=0;i<channels;i++){
 
117
                printf("channel %d\n", i);
 
118
                session[i]=rtp_session_new(RTP_SESSION_SENDONLY);       
 
119
                rtp_session_set_scheduling_mode(session[i],1);
 
120
                rtp_session_set_blocking_mode(session[i],0);
 
121
                rtp_session_set_remote_addr(session[i],argv[2],port);
 
122
                rtp_session_set_payload_type(session[i],0);
 
123
                if (ssrc!=NULL) rtp_session_set_ssrc(session[i],atoi(ssrc));
 
124
                port+=2;
 
125
        }
 
126
        
 
127
        #ifndef _WIN32
 
128
        infile=fopen(argv[1],"r");
 
129
        #else
 
130
        infile=fopen(argv[1],"rb");
 
131
        #endif
 
132
        if (infile==NULL) {
 
133
                perror("Cannot open file");
 
134
                return -1;
 
135
        }
 
136
        printf("open file\n");
 
137
        signal(SIGINT,stophandler);
 
138
        /* create a set */
 
139
        set=session_set_new();
 
140
        while( ((i=fread(buffer,1,packet_size,infile))>0) && (runcond) )
 
141
        {
 
142
                int k;
 
143
                //ortp_message("Sending packet.");
 
144
                for (k=0;k<channels;k++){       
 
145
                        /* add the session to the set */
 
146
                        session_set_set(set,session[k]);
 
147
                }
 
148
                /* and then suspend the process by selecting() */
 
149
                session_set_select(NULL,set,NULL);
 
150
                for (k=0;k<channels;k++){
 
151
                        /* this is stupid to do this test, because all session work the same way,
 
152
                        as the same user_ts is used for all sessions, here. */
 
153
                        if (session_set_is_set(set,session[k])){
 
154
                                rtp_session_send_with_ts(session[k],buffer,i,user_ts);
 
155
                                //ortp_message("packet sended !");
 
156
                        }
 
157
                }
 
158
                user_ts+=ts_inc;
 
159
        }
 
160
        fclose(infile);
 
161
        printf("close file\n");
 
162
        /*sleep a little to wait last packets to be sent */
 
163
        #ifndef _WIN32
 
164
        sleep(1);
 
165
        #else
 
166
        Sleep(1);
 
167
        #endif
 
168
        for (i=0;i<channels;i++)
 
169
                rtp_session_destroy(session[i]);
 
170
        session_set_destroy(set);
 
171
        ortp_free(buffer);
 
172
        ortp_exit();
 
173
        ortp_global_stats_display();
 
174
        return 0;
 
175
}