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

« back to all changes in this revision

Viewing changes to console/sipomatic.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:
19
19
 
20
20
#include <signal.h>
21
21
#include "sipomatic.h"
 
22
#include <eXosip.h>
22
23
 
23
24
 
24
25
int run_cond=1;
25
26
 
26
27
Sipomatic sipomatic;
27
28
 
28
 
static char *num2str(int a)
29
 
{
30
 
        char *p=smalloc(10);
31
 
        snprintf(p,10,"%i",a);
32
 
        return p;
33
 
}
34
 
 
 
29
int sipomatic_accept_audio_offer(sdp_context_t *ctx,sdp_payload_t *payload);
 
30
int sipomatic_accept_video_offer(sdp_context_t *ctx,sdp_payload_t *payload);
 
31
 
 
32
 
 
33
sdp_handler_t sipomatic_sdp_handler={
 
34
        sipomatic_accept_audio_offer,   /*from remote sdp */
 
35
        sipomatic_accept_video_offer,
 
36
        NULL,
 
37
        NULL,
 
38
        NULL,
 
39
        NULL,
 
40
};
35
41
 
36
42
void stop_handler(int signum)
37
43
{
38
44
        run_cond=0;
39
45
}
40
46
 
41
 
int invite_accepted_cb(OsipDialog *call,transaction_t *trn, sip_t *msg,void *p2)
42
 
{
43
 
        /* we should never be here since sipomatic is unable to to make invites*/
44
 
        return(0);
45
 
}
46
 
 
47
 
int bye_cb(OsipDialog *dialog,transaction_t *trn, sip_t *msg,void *p2)
48
 
{
49
 
        /* get the call */
50
 
        Call *call=(Call*)dialog->data;
51
 
        sipomatic_lock(&sipomatic);
52
 
        if ( sipomatic_check_call(&sipomatic,call))
53
 
                call->state=CALL_STATE_FINISHED;
54
 
        sipomatic_unlock(&sipomatic);
55
 
        return(0);
56
 
}
57
 
 
58
 
int invite_cb(OsipDialog *dialog,transaction_t *trn, sip_t *sipmsg,void *p2)
59
 
{
60
 
        /* we have just received an invite, so wait two seconds, then accept it*/
61
 
        char *p;
 
47
void sipomatic_process_event(Sipomatic *obj,eXosip_event_t *ev)
 
48
{
62
49
        Call *call;
63
 
        
64
 
        from_2char(sipmsg->from,&p);
65
 
        g_message("Contacted by %s.\n",p);
66
 
        sfree(p);
67
 
        call=call_new(dialog);
68
 
        call->current_trn=trn;
69
 
        call->root=&sipomatic;
70
 
        sipomatic_lock(&sipomatic);
71
 
        sipomatic.calls=g_list_append(sipomatic.calls,call);
72
 
        sipomatic_unlock(&sipomatic);
73
 
        return(0);
 
50
        switch(ev->type){
 
51
                case EXOSIP_CALL_NEW:
 
52
                        call_new(obj,ev->did,ev->sdp_body);
 
53
                        break;
 
54
                case EXOSIP_CALL_CLOSED:
 
55
                case EXOSIP_CALL_CANCELLED:
 
56
                        call=sipomatic_find_call(obj,ev->did);
 
57
                        if (call==NULL){
 
58
                                ms_warning("Could not find call with did %i !",ev->did);
 
59
                        }
 
60
                        call_release(call);
 
61
                        call_destroy(call);
 
62
                        break;
 
63
                case EXOSIP_IN_SUBSCRIPTION_NEW:
 
64
                        ms_message("Receving new incoming subscription.");
 
65
                        eXosip_notify_accept_subscribe(ev->did,200,EXOSIP_SUBCRSTATE_ACTIVE,EXOSIP_NOTIFY_ONLINE);
 
66
                        break;
 
67
                default:
 
68
                        break;
 
69
        }
 
70
        eXosip_event_free(ev);
74
71
}
75
72
 
76
 
gint endoffile_cb(MSFilter *f,gint ev,gpointer arg,gpointer data)
77
 
{
78
 
        Call*call=(Call*)data;
 
73
 
 
74
void endoffile_cb(void *ud, unsigned int ev,void * arg){
 
75
        Call*call=(Call*)ud;
79
76
        call->eof=1;
80
77
}
81
78
 
82
79
void call_accept(Call *call)
83
80
{
84
 
        SdpContext *ctx;
85
 
        int status;
86
 
        OsipDialog *dialog=call->dialog;
87
 
        CallParams *callparams;
 
81
        sdp_context_t *ctx;
88
82
        PayloadType *payload;
89
 
        gchar *hellofile;
90
 
        
91
 
        ctx=SDP_CONTEXT(osip_dialog_get_body_context(dialog,"application/sdp",0));
92
 
        callparams=(CallParams*)BODY_CONTEXT(ctx)->data;
93
 
        status=sdp_context_get_negociation_status(ctx);
94
 
        if (status!=200){
95
 
                g_message("Error during sdp negociation, cannot accept call.\n");
96
 
                osip_dialog_respond(dialog,call->current_trn,SDP_CONTEXT(ctx)->negoc_status);
97
 
                call->state=CALL_STATE_FINISHED;
98
 
                return;
99
 
        }
100
 
        payload=rtp_profile_get_payload(callparams->profile,callparams->pt);
 
83
        char *hellofile;
 
84
        static int call_count=0;        
 
85
        char record_file[250];
 
86
        sprintf(record_file,"/tmp/sipomatic%i.wav",call_count);
 
87
 
 
88
        ctx=call->sdpc;
 
89
        payload=rtp_profile_get_payload(call->profile,call->audio.pt);
101
90
        if (strcmp(payload->mime_type,"telephone-event")==0){
102
91
                /* telephone-event is not enough to accept a call */
103
 
                g_message("Cannot accept call with only telephone-event.\n");
104
 
                osip_dialog_respond(dialog,call->current_trn,415);
 
92
                ms_message("Cannot accept call with only telephone-event.\n");
 
93
                eXosip_answer_call(call->did,415,NULL);
105
94
                call->state=CALL_STATE_FINISHED;
106
95
                return;
107
96
        }
108
97
        if (payload->clock_rate==16000){
109
98
                hellofile=call->root->file_path16000hz;
110
99
        }else hellofile=call->root->file_path8000hz;
111
 
        osip_dialog_accept_invite(dialog,call->current_trn);
112
 
        call->audio_stream=audio_stream_start_with_files(callparams->profile,callparams->localport,
113
 
                                callparams->remaddr,callparams->remoteport,callparams->pt,20,hellofile,"/dev/null",NULL);
114
 
        g_timer_reset(call->timer);
 
100
        eXosip_answer_call_with_body(call->did,200,"application/sdp",call->sdpc->answerstr);
 
101
        call->audio_stream=audio_stream_start_with_files(call->profile,call->audio.localport,
 
102
                                call->audio.remaddr,call->audio.remoteport,call->audio.pt,20,hellofile,record_file);
 
103
        call_count++;
 
104
#ifdef VIDEO_ENABLED
 
105
        if (call->video.remoteport!=0){
 
106
                call->video_stream=video_stream_send_only_start(call->profile,call->video.localport,call->video.remaddr,
 
107
                                                                                        call->video.remoteport,call->video.pt,"/dev/video0");
 
108
        }
 
109
#endif
 
110
        call->time=time(NULL);
115
111
        call->state=CALL_STATE_RUNNING;
116
 
        call->params=callparams;
117
 
        ms_filter_set_notify_func(call->audio_stream->soundread,endoffile_cb,(gpointer)call);
118
 
}
119
 
 
120
 
 
121
 
int faillure_cb(OsipDialog *call,transaction_t *trn, sip_t *msg,void *p2)
122
 
{
123
 
        return(0);
124
 
}
125
 
 
126
 
 
127
 
int payload_is_supported(SdpPayload *payload,RtpProfile *local_profile,RtpProfile *dialog_profile)
 
112
        ms_filter_set_notify_callback(call->audio_stream->soundread,endoffile_cb,(void*)call);
 
113
}
 
114
 
 
115
 
 
116
PayloadType * sipomatic_payload_is_supported(sdp_payload_t *payload,RtpProfile *local_profile,RtpProfile *dialog_profile)
128
117
{
129
118
        int localpt;
130
119
        if (payload->a_rtpmap!=NULL){
131
120
                localpt=rtp_profile_get_payload_number_from_rtpmap(local_profile,payload->a_rtpmap);
132
121
        }else{
133
122
                localpt=payload->pt;
134
 
                g_warning("payload has no rtpmap.");
 
123
                ms_warning("payload has no rtpmap.");
135
124
        }
136
125
        
137
126
        if (localpt>=0){
138
 
 
139
127
                /* this payload is supported in our local rtp profile, so add it to the dialog rtp
140
128
                profile */
141
129
                PayloadType *rtppayload;
142
130
                rtppayload=rtp_profile_get_payload(local_profile,localpt);
143
 
                if (rtppayload==NULL) return 0;
 
131
                if (rtppayload==NULL) return NULL;
 
132
                /*check if we have the appropriate coder/decoder for this payload */
 
133
                if (strcmp(rtppayload->mime_type,"telephone-event")!=0) {
 
134
                        if (!ms_filter_codec_supported(rtppayload->mime_type)) {
 
135
                                ms_message("Codec %s is not supported.", rtppayload->mime_type);
 
136
                                return NULL;
 
137
                        }
 
138
                }
144
139
                rtppayload=payload_type_clone(rtppayload);
145
140
                rtp_profile_set_payload(dialog_profile,payload->pt,rtppayload);
146
141
                /* add to the rtp payload type some other parameters (bandwidth) */
147
142
                if (payload->b_as_bandwidth!=0) rtppayload->normal_bitrate=payload->b_as_bandwidth*1000;
148
 
                return 1;
 
143
                if (payload->a_fmtp!=NULL)
 
144
                        payload_type_set_send_fmtp(rtppayload,payload->a_fmtp);
 
145
                if (strcasecmp(rtppayload->mime_type,"iLBC")==0){
 
146
                        /*default to 30 ms mode */
 
147
                        payload->a_fmtp="ptime=30";
 
148
                        payload_type_set_recv_fmtp(rtppayload,payload->a_fmtp);
 
149
                }
 
150
                return rtppayload;
149
151
        }
150
 
        return 0;
 
152
        return NULL;
151
153
}
152
 
int accept_audio_offer(SdpHandler *sdph,SdpContext *ctx,SdpPayload *payload)
 
154
 
 
155
int sipomatic_accept_audio_offer(sdp_context_t *ctx,sdp_payload_t *payload)
153
156
{
154
157
        static int audioport=8000;
155
 
        OsipDialog *dialog=BODY_CONTEXT(ctx)->dialog;
156
 
        CallParams *callparams;
157
 
        int supported;
158
 
        if (BODY_CONTEXT(ctx)->data!=NULL){
159
 
                callparams=(CallParams *) BODY_CONTEXT(ctx)->data;
160
 
        }else{
161
 
                callparams=call_params_new();
162
 
                BODY_CONTEXT(ctx)->data=(void*)callparams;
163
 
        }
 
158
        Call *call=(Call*)sdp_context_get_user_pointer(ctx);
 
159
        PayloadType *supported;
 
160
        struct stream_params *params=&call->audio;
164
161
        
165
162
        /* see if this codec is supported in our local rtp profile*/
166
 
        supported=payload_is_supported(payload,&av_profile,callparams->profile);
167
 
        if (!supported) {
168
 
                g_message("Refusing codec %i (%s)",payload->pt,payload->a_rtpmap);
 
163
        supported=sipomatic_payload_is_supported(payload,&av_profile,call->profile);
 
164
        if (supported==NULL) {
 
165
                ms_message("Refusing codec %i (%s)",payload->pt,payload->a_rtpmap);
169
166
                return -1;
170
167
        }
171
 
        if (callparams->ncodecs==0){
 
168
        if (strcmp(supported->mime_type,"telephone-event")==0) return 0;
 
169
        if (params->ncodecs==0 ){
172
170
                /* this is the first codec we may accept*/
173
 
                callparams->localport=payload->localport=audioport;
174
 
                callparams->remoteport=payload->remoteport;
175
 
                callparams->line=payload->line;
176
 
                callparams->pt=payload->pt; /* remember the first payload accepted */
177
 
                callparams->remaddr=payload->c_addr;
178
 
                callparams->ncodecs++;
 
171
                params->localport=payload->localport=audioport;
 
172
                params->remoteport=payload->remoteport;
 
173
                params->line=payload->line;
 
174
                params->pt=payload->pt; /* remember the first payload accepted */
 
175
                params->remaddr=payload->c_addr;
 
176
                params->ncodecs++;
179
177
                audioport+=4;
180
178
        }else{
181
179
                /* refuse all other audio lines*/
182
 
                if(callparams->line!=payload->line) return -1;
183
 
        }
184
 
        return 0;
185
 
}
186
 
 
187
 
void sipomatic_init(Sipomatic *obj, gchar *url)
188
 
{
189
 
        MSCodecInfo *info;
190
 
        GList *elem;
191
 
        BodyHandler *sdph;
 
180
                if(params->line!=payload->line) return -1;
 
181
        }
 
182
        return 0;
 
183
}
 
184
 
 
185
int sipomatic_accept_video_offer(sdp_context_t *ctx,sdp_payload_t *payload)
 
186
{
 
187
#ifdef VIDEO_ENABLED
 
188
        static int videoport=80000;
 
189
        Call *call=(Call*)sdp_context_get_user_pointer(ctx);
 
190
        PayloadType *supported;
 
191
        struct stream_params *params=&call->video;
 
192
        
 
193
        /* see if this codec is supported in our local rtp profile*/
 
194
        supported=sipomatic_payload_is_supported(payload,&av_profile,call->profile);
 
195
        if (supported==NULL) {
 
196
                ms_message("Refusing video codec %i (%s)",payload->pt,payload->a_rtpmap);
 
197
                return -1;
 
198
        }
 
199
        if (params->ncodecs==0 ){
 
200
                /* this is the first codec we may accept*/
 
201
                params->localport=payload->localport=videoport;
 
202
                params->remoteport=payload->remoteport;
 
203
                params->line=payload->line;
 
204
                params->pt=payload->pt; /* remember the first payload accepted */
 
205
                params->remaddr=payload->c_addr;
 
206
                params->ncodecs++;
 
207
                videoport+=4;
 
208
        }else{
 
209
                /* refuse all other video lines*/
 
210
                if(params->line!=payload->line) return -1;
 
211
        }
 
212
        return 0;
 
213
#else
 
214
        return -1;
 
215
#endif
 
216
}
 
217
 
 
218
void sipomatic_init(Sipomatic *obj, char *url, bool_t ipv6)
 
219
{
 
220
        osip_uri_t *uri=NULL;
 
221
        int port=5064;
 
222
        
 
223
        eXosip_enable_ipv6(ipv6);
 
224
        
192
225
        if (url==NULL){
193
226
                url=getenv("SIPOMATIC_URL");
194
 
                if (url==NULL) url="sip:robot@0.0.0.0:5064";
195
 
        }
196
 
        g_message("Starting using url %s",url);
197
 
        obj->audio_codecs=ms_codec_get_all_audio();
198
 
        obj->lock=g_mutex_new();
 
227
                if (url==NULL){
 
228
                        if (ipv6) url="sip:robot@[::1]:5064";
 
229
                        else url="sip:robot@127.0.0.1:5064";
 
230
                }
 
231
        }
 
232
        if (url!=NULL) {
 
233
                osip_uri_init(&uri);
 
234
                if (osip_uri_parse(uri,url)==0){
 
235
                        if (uri->port!=NULL) port=atoi(uri->port);
 
236
                }else{
 
237
                        ms_warning("Invalid identity uri:%s",url);
 
238
                }       
 
239
        }
 
240
        ms_message("Starting using url %s",url);
 
241
        ms_mutex_init(&obj->lock,NULL);
199
242
        obj->calls=NULL;
200
243
        obj->acceptance_time=5;
201
244
        obj->max_call_time=300;
202
 
        obj->file_path8000hz=g_strdup_printf("%s/%s",PACKAGE_SOUND_DIR,ANNOUCE_FILE8000HZ);
203
 
        obj->file_path16000hz=g_strdup_printf("%s/%s",PACKAGE_SOUND_DIR,ANNOUCE_FILE16000HZ);
204
 
        
205
 
        /* create a user agent */
206
 
        obj->ua=osip_ua_new();
207
 
        osip_ua_set_contact(obj->ua,url);
208
 
        osip_ua_signal_connect(obj->ua,"INVITE_ACCEPTED",invite_accepted_cb);
209
 
        osip_ua_signal_connect(obj->ua,"BYE",bye_cb);
210
 
        osip_ua_signal_connect(obj->ua,"FAILLURE",faillure_cb);
211
 
        osip_ua_signal_connect(obj->ua,"INVITE",invite_cb);
212
 
        /* add sdp capabilities to the user agent */
213
 
        sdph=sdp_handler_new();
214
 
        sdp_handler_set_write_offer_fcn(SDP_HANDLER(sdph),NULL,NULL);
215
 
        sdp_handler_set_accept_offer_fcn(SDP_HANDLER(sdph),accept_audio_offer,NULL);
216
 
        sdp_handler_set_read_answer_fcn(SDP_HANDLER(sdph),NULL,NULL);
217
 
        
218
 
        osip_ua_add_body_handler(obj->ua,sdph);
219
 
        
 
245
        obj->file_path8000hz=ms_strdup_printf("%s/%s",PACKAGE_SOUND_DIR,ANNOUCE_FILE8000HZ);
 
246
        obj->file_path16000hz=ms_strdup_printf("%s/%s",PACKAGE_SOUND_DIR,ANNOUCE_FILE16000HZ);
 
247
        osip_trace_initialize(OSIP_INFO1,stdout);
 
248
        osip_trace_initialize(OSIP_INFO2,stdout);
 
249
        osip_trace_initialize(OSIP_WARNING,stdout);
 
250
        osip_trace_initialize(OSIP_ERROR,stdout);
 
251
        osip_trace_initialize(OSIP_BUG,stdout);
 
252
        osip_trace_initialize(OSIP_FATAL,stdout);
 
253
        osip_trace_enable_level(OSIP_INFO1);
 
254
        osip_trace_enable_level(OSIP_INFO2);
 
255
        osip_trace_enable_level(OSIP_WARNING);
 
256
        osip_trace_enable_level(OSIP_ERROR);
 
257
        osip_trace_enable_level(OSIP_BUG);
 
258
        osip_trace_enable_level(OSIP_FATAL);
 
259
        eXosip_init(NULL,stdout,port);
 
260
        eXosip_set_user_agent("sipomatic-" LINPHONE_VERSION "/eXosip");
220
261
}
221
262
 
222
263
void sipomatic_uninit(Sipomatic *obj)
223
264
{
224
 
        g_mutex_free(obj->lock);
225
 
        osip_ua_destroy(obj->ua);
 
265
        ms_mutex_destroy(&obj->lock);
 
266
        eXosip_quit();
226
267
}
227
268
 
228
269
void sipomatic_iterate(Sipomatic *obj)
229
270
{
230
 
        GList *elem;
 
271
        MSList *elem;
 
272
        MSList *to_be_destroyed=NULL;
231
273
        Call *call;
232
 
        gdouble time;
233
 
        sipomatic_lock(obj);
 
274
        double elapsed;
 
275
        eXosip_event_t *ev;
 
276
 
 
277
        while((ev=eXosip_event_wait(0,0))!=NULL){
 
278
                sipomatic_process_event(obj,ev);
 
279
        }
234
280
        elem=obj->calls;
235
281
        while(elem!=NULL){
236
282
                call=(Call*)elem->data;
237
 
                time=g_timer_elapsed(call->timer,NULL);
 
283
                elapsed=time(NULL)-call->time;
238
284
                switch(call->state){
239
285
                        case CALL_STATE_INIT:
240
 
                                if (time>obj->acceptance_time){
 
286
                                if (elapsed>obj->acceptance_time){
241
287
                                        call_accept(call);
242
288
                                }
243
289
                        break;
244
290
                        case CALL_STATE_RUNNING:
245
 
                                if (time>obj->max_call_time || call->eof){
 
291
                                if (elapsed>obj->max_call_time || call->eof){
246
292
                                        call_release(call);
247
 
                                        elem=obj->calls=g_list_remove(obj->calls,call);
248
 
                                        call_destroy(call);
 
293
                                        to_be_destroyed=ms_list_append(to_be_destroyed,call);
249
294
                                }
250
295
                        break;
251
 
                        case CALL_STATE_FINISHED:
252
 
                                elem=obj->calls=g_list_remove(obj->calls,call);
253
 
                                call_destroy(call);
254
 
                        break;
255
296
                }
256
 
                elem=g_list_next(elem);
257
 
        }
258
 
        sipomatic_unlock(obj);
259
 
}
260
 
 
261
 
CallParams * call_params_new(){
262
 
        CallParams *obj;
263
 
        obj=g_new0(CallParams,1);
 
297
                elem=ms_list_next(elem);
 
298
        }
 
299
        for(;to_be_destroyed!=NULL; to_be_destroyed=ms_list_next(to_be_destroyed)){
 
300
                call_destroy((Call*)to_be_destroyed->data);
 
301
        }
 
302
}
 
303
 
 
304
 
 
305
Call* sipomatic_find_call(Sipomatic *obj,int did)
 
306
{
 
307
        MSList *it;
 
308
        Call *call=NULL;
 
309
        for (it=obj->calls;it!=NULL;it=ms_list_next(it)){
 
310
                call=(Call*)it->data;
 
311
                if ( call->did==did) return call;
 
312
        }
 
313
        return call;
 
314
}
 
315
 
 
316
 
 
317
Call * call_new(Sipomatic *root, int did, char *sdp)
 
318
{
 
319
        Call *obj;
 
320
        char *sdpans;
 
321
        int status;
 
322
        sdp_context_t *sdpc=sdp_handler_create_context(&sipomatic_sdp_handler,NULL,"sipomatic");
 
323
        obj=ms_new0(Call,1);
264
324
        obj->profile=rtp_profile_new("remote");
265
 
        return obj;
266
 
}
267
 
void call_params_destroy(CallParams *obj)
268
 
{
269
 
        rtp_profile_destroy(obj->profile);
270
 
        g_free(obj);
271
 
}
272
 
 
273
 
gboolean sipomatic_check_call(Sipomatic *obj,Call *call)
274
 
{
275
 
        GList *it;
276
 
        for (it=obj->calls;it!=NULL;it=g_list_next(it)){
277
 
                if ( ((Call*)it->data)==call) return 1;
 
325
        eXosip_answer_call(did,100,NULL);
 
326
        sdp_context_set_user_pointer(sdpc,obj);
 
327
        sdpans=sdp_context_get_answer(sdpc,sdp);
 
328
        if (sdpans!=NULL){
 
329
                eXosip_answer_call(did,180,NULL);
 
330
                
 
331
        }else{
 
332
                status=sdp_context_get_status(sdpc);
 
333
                eXosip_answer_call(did,status,NULL);
 
334
                sdp_context_free(sdpc);
 
335
                rtp_profile_destroy(obj->profile);
 
336
                ms_free(obj);
 
337
                return NULL;
278
338
        }
279
 
        return 0;
280
 
}
281
 
 
282
 
Call * call_new(OsipDialog *dialog)
283
 
{
284
 
        Call *obj=g_new0(Call,1);
285
 
        obj->timer=g_timer_new();
286
 
        obj->dialog=dialog;
287
 
        dialog->data=(void*)obj;
288
 
        g_timer_start(obj->timer);
 
339
        obj->sdpc=sdpc;
 
340
        obj->did=did;
 
341
        obj->time=time(NULL);
289
342
        obj->audio_stream=NULL;
290
343
        obj->state=CALL_STATE_INIT;
291
344
        obj->eof=0;
 
345
        obj->root=root;
 
346
        root->calls=ms_list_append(root->calls,obj);
292
347
        return obj;
293
348
}
294
349
 
295
350
void call_release(Call *call)
296
351
{
297
 
        osip_dialog_bye(call->dialog);
 
352
        eXosip_terminate_call(0,call->did);
 
353
        if (call->audio_stream!=NULL) audio_stream_stop(call->audio_stream);
 
354
#ifdef VIDEO_ENABLED
 
355
        if (call->video_stream!=NULL) video_stream_send_only_stop(call->video_stream);
 
356
#endif
298
357
        call->state=CALL_STATE_FINISHED;
299
358
}
300
359
 
301
360
void call_destroy(Call *obj)
302
361
{
303
 
        if (obj->audio_stream!=NULL) audio_stream_stop(obj->audio_stream);
304
 
        g_timer_destroy(obj->timer);
305
 
        if (obj->params!=NULL) call_params_destroy(obj->params);
306
 
        g_free(obj);
 
362
        obj->root->calls=ms_list_remove(obj->root->calls,obj);
 
363
        rtp_profile_destroy(obj->profile);
 
364
        sdp_context_free(obj->sdpc);
 
365
        ms_free(obj);
307
366
}
308
367
 
309
368
void sipomatic_set_annouce_file(Sipomatic *obj, char *file)
310
369
{
311
370
        if (obj->file_path8000hz!=NULL){
312
 
                g_free(obj->file_path8000hz);
 
371
                ms_free(obj->file_path8000hz);
313
372
        }
314
 
        obj->file_path8000hz=g_strdup(file);
 
373
        obj->file_path8000hz=ms_strdup(file);
315
374
}
316
375
 
317
 
extern OsipManager *def_manager;
318
376
 
319
377
void display_help()
320
378
{
323
381
                        "sipomatic -v or --version: display version information.\n"
324
382
                        "       -u sip-url : specify the sip url sipomatic listens and answers.\n"
325
383
                        "       -f annouce-file : set the annouce file (16 bit raw format,8000Hz)\n"
326
 
                        "       -s port : set the port sipomatic uses to send its SIP answers.\n");
 
384
                        " -6 enable ipv6 network usage\n");
327
385
        exit(0);
328
386
}
329
387
 
333
391
                return argv[i];
334
392
        }
335
393
        else display_help();
 
394
        return NULL;
336
395
}
337
396
 
338
397
int main(int argc, char *argv[])
339
398
{
340
399
        int sendport=5070;
341
400
        char *file=NULL;
342
 
        gchar *url=NULL;
 
401
        char *url=NULL;
 
402
        bool_t ipv6=FALSE;
343
403
        int i;
344
404
        
345
405
        for(i=1;i<argc;i++){
368
428
                        file=getarg(argc,argv,i);
369
429
                        continue;
370
430
                }
 
431
                if (strcmp(argv[i],"-6")==0){
 
432
                        ipv6=TRUE;
 
433
                        continue;
 
434
                }
371
435
        }
372
436
        
373
437
        signal(SIGINT,stop_handler);
 
438
        ortp_init();
374
439
        ms_init();
375
 
        ms_speex_codec_init();
376
 
        ortp_init();
377
 
        ortp_set_debug_file("oRTP",NULL);
378
 
        rtp_profile_set_payload(&av_profile,115,&lpc1015);
379
 
        rtp_profile_set_payload(&av_profile,110,&speex_nb);
380
 
        rtp_profile_set_payload(&av_profile,111,&speex_wb);
381
 
        rtp_profile_set_payload(&av_profile,101,&telephone_event);
382
 
        rtp_profile_set_payload(&av_profile,116,&truespeech);
383
 
        TRACE_INITIALIZE(TRACE_LEVEL6,stdout);
384
 
        osipua_init();
385
 
        osip_manager_set_send_port(def_manager,sendport);
386
 
        sipomatic_init(&sipomatic,url);
 
440
        ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
 
441
        rtp_profile_set_payload(&av_profile,115,&payload_type_lpc1015);
 
442
        rtp_profile_set_payload(&av_profile,110,&payload_type_speex_nb);
 
443
        rtp_profile_set_payload(&av_profile,111,&payload_type_speex_wb);
 
444
        rtp_profile_set_payload(&av_profile,112,&payload_type_ilbc);
 
445
        rtp_profile_set_payload(&av_profile,101,&payload_type_telephone_event);
 
446
        rtp_profile_set_payload(&av_profile,116,&payload_type_truespeech);
 
447
        rtp_profile_set_payload(&av_profile,98,&payload_type_h263_1998);
 
448
        
 
449
        sipomatic_init(&sipomatic,url,ipv6);
387
450
        if (file!=NULL) sipomatic_set_annouce_file(&sipomatic,file);
388
451
        
389
452
        while (run_cond){