osip-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

eXosip_event_wait needs to call twice for the OK response


From: Mostafa Farzane
Subject: eXosip_event_wait needs to call twice for the OK response
Date: Tue, 15 Jun 2021 21:00:03 +0430

I have the following code to call a Webex meeting. After sending an INVITE request, Webex replies with a TRYING, a RINGING, and an OK response.
I receive TRYING, and RINGING responses without any problem, But the problem is, for receiving the "OK" response, I have to call "eXosip_event_wait" twice. The first time it returns NULL and the second time It returns the OK response.

Any ideas?

#include <eXosip2/eXosip.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <netinet/in.h>
#include <unistd.h>
#include <string.h>

int main(int argc,char *argv[])
{
struct eXosip_t *context_eXosip;

eXosip_event_t *je;
osip_message_t *reg=NULL;
osip_message_t *invite=NULL;
osip_message_t *ack=NULL;
osip_message_t *message=NULL;

sdp_message_t *remote_sdp=NULL;
sdp_connection_t *remote_video_conn=NULL;
sdp_media_t *remote_video_media=NULL;

int call_id,dialog_id;
int i;
int flag1=1;

char tmp[4096];

// Initialize
//
struct eXosip_t *ctx;
TRACE_INITIALIZE (6, NULL);

ctx = eXosip_malloc();
if (ctx==NULL)
return -1;
i=eXosip_init(ctx);


if(i!=0)
{
printf("Couldn't initialize eXosip!\n");
return -1;
}
else
{
printf("eXosip_init successfully!\n");
}

// Bind uac its own port 15060, and perform port monitoring
i=eXosip_listen_addr(ctx, IPPROTO_TCP,NULL,15060,AF_INET,0);
if(i!=0)
{
eXosip_quit(ctx);
fprintf(stderr,"Couldn't initialize transport layer!\n");
return -1;
}

int val;
val=2;
eXosip_set_option (ctx, EXOSIP_OPT_DNS_CAPABILITIES, (void*)&val);

val=1;
eXosip_set_option (ctx, EXOSIP_OPT_USE_RPORT, (void*)&val);

val=0;
i = eXosip_set_option (ctx, EXOSIP_OPT_SET_TLS_VERIFY_CERTIFICATE, (void*)&val);

i = eXosip_call_build_initial_invite (ctx, &invite, "<sip:MEETING_NUMBER@webex.com>",
"<sip:mosi@192.168.0.115>",
NULL, // optional route header
"This is a call for a conversation");

if(i!=0)
{
printf("Initial INVITE failed!\n");
return 0;
}

    snprintf (tmp, 4096,
            "v=0\r\n"
            "o=- 1491669071 1491669071 IN IP4 192.168.0.115\r\n"
            "s=Asterisk\r\n"
            "c=IN IP4 192.168.0.115\r\n"
            "t=0 0\r\n"
            "m=audio 1234 RTP/AVP 0 101\r\n"
            "a=rtpmap:0 PCMU/8000\r\n"
            "a=rtpmap:101 telephone-event/8000\r\n"
            "a=fmtp:101 0-16\r\n"
            "a=ptime:20\r\n"
            "a=maxptime:150\r\n"
            "a=sendrecv\r\n"
            "m=video 1235 RTP/AVP 100 99\r\n"
            "a=rtpmap:100 VP8/90000\r\n"
            "a=rtpmap:99 H264/90000\r\n"
            "a=fmtp:99 profile-level-id=42801F\r\n"
            "a=sendrecv\r\n");

osip_message_set_body(invite,tmp,strlen(tmp));
osip_message_set_content_type(invite,"application/sdp");

eXosip_lock(ctx);
i=eXosip_call_send_initial_invite(ctx, invite); //invite SIP INVITE message to send
eXosip_unlock (ctx);

//Sent an INVITE message and wait for a response
flag1=1;
while(flag1)
{
je = eXosip_event_wait (ctx, 5, 0);
eXosip_lock(ctx);
eXosip_automatic_action (ctx);
eXosip_unlock(ctx);

if(je==NULL)
{
printf("No response or the time is over!\n");
continue;
}
switch(je->type) //Event types that may come
{
case EXOSIP_CALL_INVITE: // received an INVITE request
printf("a new invite received!\n");
break;
case EXOSIP_CALL_PROCEEDING: //Received 100 trying message, indicating that the request is being processed
printf("proceeding!\n");
break;
case EXOSIP_CALL_RINGING: //Received 180 Ringing response, indicating that the UAS receiving the INVITE request is ringing to the called user.
printf("ringing!\n");
printf("call_id is %d,dialog_id is %d \n",je->cid,je->did);
break;
case EXOSIP_CALL_ANSWERED: //Received 200 OK, indicating that the request has been successfully accepted, the user answers
printf("ok!connected!\n");
call_id=je->cid;
dialog_id=je->did;

remote_sdp = eXosip_get_remote_sdp(ctx, dialog_id);
remote_video_media = eXosip_get_audio_media(remote_sdp);
remote_video_conn = eXosip_get_audio_connection(remote_sdp);
if (remote_sdp == NULL) {
printf("remote sdp is empty");
}

if (remote_video_media == NULL) {
printf("####remote video media is empty\n");
}

if (remote_video_conn == NULL) {
printf("####remote video conn is empty\n");
} else {
printf(remote_video_conn->c_addr);
}
printf("call_id is %d,dialog_id is %d \n",je->cid,je->did);

// Send back ack response message
eXosip_call_build_ack(ctx, je->did,&ack);

eXosip_lock(ctx);
eXosip_call_send_ack(ctx, je->did,ack);
eXosip_unlock(ctx);
flag1=0; //launch the while loop
break;
case EXOSIP_CALL_CLOSED: //a BYE was received for this call
printf("the other sid closed!\n");
break;
case EXOSIP_CALL_ACK: //ACK received for 200ok to INVITE
printf("ACK received!\n");
break;
default: //Received another response
break;
}
eXosip_event_free(je); //Free ressource in an eXosip event
}

sleep(10);
eXosip_lock (ctx);
eXosip_call_terminate (ctx, call_id, dialog_id);
eXosip_unlock (ctx);
eXosip_quit(ctx);
return(0);
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]