~ubuntu-branches/ubuntu/quantal/linphone/quantal

« back to all changes in this revision

Viewing changes to oRTP/src/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.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
 
        char *buffer;
51
 
        int packet_size=160;
52
 
        int ts_inc=160;
53
 
        int i;
54
 
        FILE *infile;
55
 
        char *ssrc;
56
 
        gint port;
57
 
        guint32 user_ts=0;
58
 
        gint 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=g_malloc(packet_size);
111
 
        ortp_init();
112
 
        ortp_scheduler_init();
113
 
        printf("scheduler initialized\n");
114
 
        ortp_set_debug_file("oRTP",stdout);
115
 
        ssrc=getenv("SSRC");
116
 
        port=atoi(argv[3]);
117
 
        for (i=0;i<channels;i++){
118
 
                printf("channel %d\n", i);
119
 
                session[i]=rtp_session_new(RTP_SESSION_SENDONLY);       
120
 
                rtp_session_set_scheduling_mode(session[i],1);
121
 
                rtp_session_set_blocking_mode(session[i],0);
122
 
                rtp_session_set_remote_addr(session[i],argv[2],port);
123
 
                rtp_session_set_payload_type(session[i],0);
124
 
                if (ssrc!=NULL) rtp_session_set_ssrc(session[i],atoi(ssrc));
125
 
                port+=2;
126
 
        }
127
 
        
128
 
        #ifndef _WIN32
129
 
        infile=fopen(argv[1],"r");
130
 
        #else
131
 
        infile=fopen(argv[1],"rb");
132
 
        #endif
133
 
        if (infile==NULL) {
134
 
                perror("Cannot open file");
135
 
                return -1;
136
 
        }
137
 
        printf("open file\n");
138
 
        signal(SIGINT,stophandler);
139
 
        /* create a set */
140
 
        set=session_set_new();
141
 
        printf("session set\n");
142
 
        while( ((i=fread(buffer,1,packet_size,infile))>0) && (runcond) )
143
 
        {
144
 
                int k;
145
 
                //g_message("Sending packet.");
146
 
                for (k=0;k<channels;k++){       
147
 
                        /* add the session to the set */
148
 
                        session_set_set(set,session[k]);
149
 
                        printf("session set set %d\n", k);
150
 
                }
151
 
                /* and then suspend the process by selecting() */
152
 
                session_set_select(NULL,set,NULL);
153
 
                printf("session set select\n");
154
 
                for (k=0;k<channels;k++){
155
 
                        printf("---\n");
156
 
                        /* this is stupid to do this test, because all session work the same way,
157
 
                        as the same user_ts is used for all sessions, here. */
158
 
                        if (session_set_is_set(set,session[k])){
159
 
                                printf("session set is set %d\n", k);
160
 
                                rtp_session_send_with_ts(session[k],buffer,i,user_ts);
161
 
                                //g_message("packet sended !");
162
 
                        }
163
 
                }
164
 
                user_ts+=ts_inc;
165
 
        }
166
 
        fclose(infile);
167
 
        printf("close file\n");
168
 
        /*sleep a little to wait last packets to be sent */
169
 
        #ifndef _WIN32
170
 
        sleep(1);
171
 
        #else
172
 
        Sleep(1);
173
 
        #endif
174
 
        for (i=0;i<channels;i++)
175
 
                rtp_session_destroy(session[i]);
176
 
        session_set_destroy(set);
177
 
        g_free(buffer);
178
 
        ortp_exit();
179
 
        ortp_global_stats_display();
180
 
        return 0;
181
 
}
182