I wrote a simple test code using sofia_sip to make a voip call. However, 
when I execute the code, it is hang there ' entering main loop
for processing of messages'. 

   I suspect I made some some mistakes when using the nua_invite function. In 
my makecall() function,  I called nua_invite like this:

int makecall(char const *name, char const *url)

{
   //create operation context, operation handle, etc..

    nua_invite(op, NUTAG_URL (url),  SOATAG_ADDRESS('0.0.0.0:8000'), 
NUTAG_EARLY_MEDIA (1), TAG_END ());

  
}



then I called makecall like this: 
makecall("star03", URL_STRING_MAKE("sip:136.222.222.64"));

    Anyone can give me some hints on how to fix the bug? 

   Thanks for your kind help!

BR,
Xing


/****   the complete code 
****************************************************************************/
/* include all the header files ....*/

#include <sofia-sip/su_wait.h>
#include <sofia-sip/sip.h>
#include <sofia-sip/sip_header.h>
#include <sofia-sip/tport.h>
#include <sofia-sip/nua.h>

#define SOFSIP_USE_GLIB_EVENT_LOOP 1

void event_callback(nua_event_t   event,
                    int           status,
                    char const   *phrase,
                    nua_t        *nua,
                    nua_magic_t  *magic,
                    nua_handle_t *nh,
                    nua_hmagic_t *hmagic,
                    sip_t const  *sip,
                    tagi_t        tags[]);


typedef struct cli_s {
     su_home_t     cli_home[1];    /*  memory home */
     su_root_t    *cli_root;       /*  Pointer to application root object */
     nua_t        *cli_nua;        /*  Pointer to nua stack object */
} cli_t ;

static cli_t cli[1] = {{{{sizeof(cli)}}}};
     
int sipinit(void)
{

    /* step: initialize glib and gstreamer */
     #if HAVE_GLIB
           g_type_init(); 
     #if HAVE_GST
     {
          guint major, minor, micro, nano;
          gst_init (NULL, NULL);
          gst_version (&major, &minor, &micro, &nano);
          g_message ("This program is linked against GStreamer %d.%d.%d\n", 
major, minor, micro);
      }
     #endif
     #endif
   
    su_home_init(cli->cli_home);
    su_init();
    cli->cli_root =su_root_create(cli);
  
     if (cli->cli_root != NULL)
      {
  
        cli->cli_nua = nua_create(cli->cli_root,
                   event_callback, 
                   cli,
           NUTAG_URL("sip:0.0.0.0:5060"), 
                   TAG_END());
      }

    return 0;
}

 /* set up a call */
int makecall(char const *name, url_string_t const *url)
 {
     nua_handle_t *op;
     sip_to_t *to;
 
     op = su_zalloc(cli->cli_home, (sizeof (nua_handle_t *)));
     if (op==NULL) 
     { printf("can not create operation context information\n");
       return 0;
     }
   
      /*Destination address */
     to = sip_to_create(NULL,url);
     if (!to) return 0;

     to->a_display=name;
     
     op = nua_handle(cli->cli_nua, NULL, SIPTAG_TO(to), TAG_END());
      printf (" create operation handle: OK\n");


    if (op==NULL)
       { printf ("can not access operation handle\n");
        return 0;
       }

   nua_invite(op, NUTAG_URL (url),
              SOATAG_ADDRESS("0.0.0.0:8000"),
              NUTAG_EARLY_MEDIA (1), TAG_END ());

     printf ("make call: OK\n");
  
     return (int) op;
}


int runsipmainloop(void)
{

       if (cli->cli_nua !=NULL)
     {
           printf("entering main loop for processing of messages\n");
       su_root_run(cli->cli_root);
           printf ("entered main loop");
        }
       return 0;
}

int sipcleanup(void)
{
     nua_destroy(cli->cli_nua);
     su_root_destroy(cli->cli_root);
     cli->cli_root=NULL;
     su_home_deinit(cli->cli_home);
     su_deinit();
     return 0;
}


/* This callback will be called by SIP stack to
 * process incoming events 
 */
void event_callback(nua_event_t   event,
                    int           status,
                    char const   *phrase,
                    nua_t        *nua,
                    nua_magic_t  *magic,
                    nua_handle_t *nh,
                    nua_hmagic_t *hmagic,
                    sip_t const  *sip,
                    tagi_t        tags[])
{   switch (event){
  case nua_i_invite:
       printf("invitation has been sent"); 
      break;

  case nua_i_active:
     printf("receive invitation");  
    break;

  case nua_r_invite:
     printf("responseinvitation");  
     break;

  default:
    printf("unkown event");

  }
}

int main()
{
  sipinit();
  makecall("star03", URL_STRING_MAKE("sip:136.222.222.64"));
  runsipmainloop();
  sipcleanup();
  return 0;
} 




_________________________________________________________________
Stay in touch when you're away with Windows Live Messenger.
http://www.windowslive.com/messenger/overview.html?ocid=TXT_TAGLM_WL_messenger2_072008
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel

Reply via email to