streamutil wrapper verification

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

 



Hi,
can someone tell me if the following code is missing anything to make it
work for wince, thanks in advance

static pj_caching_pool cp;
    static pjmedia_endpt *med_endpt;
   static pj_pool_t *pool;
  static  pjmedia_port *rec_file_port = NULL, *play_file_port = NULL;
  static  pjmedia_master_port *master_port = NULL;
  static  pjmedia_snd_port *snd_port = NULL;
  static  pjmedia_stream *stream = NULL;
  static  pjmedia_port *stream_port;
  static  char tmp[10];
  static  pj_status_t status;
  /* Default values */
    static  const pjmedia_codec_info *codec_info;
    static pjmedia_dir dir = PJMEDIA_DIR_DECODING;
    static pj_sockaddr_in remote_addr;
    static pj_uint16_t local_port = 4000;
    static char *codec_id = NULL;



extern "C" RTPMobileDLL_API void Start()
{
  /* Start streaming */
pjmedia_stream_start(stream);
}
extern "C" RTPMobileDLL_API void Stop()
{
  pjmedia_snd_port_destroy( snd_port );
}
static pj_status_t create_stream( pj_pool_t *pool,
      pjmedia_endpt *med_endpt,
      const pjmedia_codec_info *codec_info,
      pjmedia_dir dir,
      pj_uint16_t local_port,
      const pj_sockaddr_in *rem_addr,
      pjmedia_stream **p_stream )
{
    pjmedia_stream_info info;
    pjmedia_transport *transport;
    pj_status_t status;

    /* Reset stream info. */
    pj_bzero(&info, sizeof(info));

    /* Initialize stream info formats */
    info.type = PJMEDIA_TYPE_AUDIO;
    info.dir = dir;
    pj_memcpy(&info.fmt, codec_info, sizeof(pjmedia_codec_info));
    info.tx_pt = codec_info->pt;
    info.ssrc = pj_rand();

    /* Copy remote address */
    pj_memcpy(&info.rem_addr, rem_addr, sizeof(pj_sockaddr_in));

    /* Create media transport */
    status = pjmedia_transport_udp_create(med_endpt, NULL, local_port,
       0, &transport);
    if (status != PJ_SUCCESS)
 return status;

    /* Now that the stream info is initialized, we can create the
     * stream.
     */
    status = pjmedia_stream_create( med_endpt, pool, &info,
        transport, NULL, p_stream);
    if (status != PJ_SUCCESS) {
  OnError(TEXT("Error creating pjsua"), status);
 pjmedia_transport_media_stop(transport);
 pjmedia_transport_close(transport);
 return status;
    }

    return PJ_SUCCESS;
}
/* Register all codecs */
static pj_status_t init_codecs(pjmedia_endpt *med_endpt)
{
    pj_status_t status;
    /* To suppress warning about unused var when all codecs are disabled */
    PJ_UNUSED_ARG(status);
#if defined(PJMEDIA_HAS_G711_CODEC) && PJMEDIA_HAS_G711_CODEC!=0
    status = pjmedia_codec_g711_init(med_endpt);
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
#endif
#if defined(PJMEDIA_HAS_GSM_CODEC) && PJMEDIA_HAS_GSM_CODEC!=0
    status = pjmedia_codec_gsm_init(med_endpt);
    if(status!=PJ_SUCCESS)
//OnError(TEXT("GSM codec is not available"), status);
#endif
#if defined(PJMEDIA_HAS_SPEEX_CODEC) && PJMEDIA_HAS_SPEEX_CODEC!=0
    status = pjmedia_codec_speex_init(med_endpt, 0, -1, -1);
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
#endif
#if defined(PJMEDIA_HAS_L16_CODEC) && PJMEDIA_HAS_L16_CODEC!=0
    status = pjmedia_codec_l16_init(med_endpt, 0);
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
#endif
    return PJ_SUCCESS;
}
static void OnError(const wchar_t *title, pj_status_t status)
{
    char errmsg[PJ_ERR_MSG_SIZE];
    PJ_DECL_UNICODE_TEMP_BUF(werrmsg, PJ_ERR_MSG_SIZE);
    pj_strerror(status, errmsg, sizeof(errmsg));

    MessageBox(NULL, PJ_STRING_TO_NATIVE(errmsg, werrmsg, PJ_ERR_MSG_SIZE),
        title, MB_OK);
}
extern "C" RTPMobileDLL_API  bool OnInitStack(char* destIPAddress, char*
destPortNum,char* recevingPort, char* codec )
{

   pj_bzero(&remote_addr, sizeof(remote_addr));
 /* init PJLIB : */
    status = pj_init();
 if(status!=PJ_SUCCESS){
    OnError(TEXT("could not initialize PJLib"), status);
 return false;
 }


if (status != PJ_SUCCESS) {
 OnError(TEXT("could not initialize socket"), status);
 return false;
}
   /* Must create a pool factory before we can allocate any memory. */
    pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
    /*
     * Initialize media endpoint.
     * This will implicitly initialize PJMEDIA too.
     */
    status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt);
 //   status = PJ_SUCCESS;
if (status != PJ_SUCCESS) {
 OnError(TEXT("could not initialize PJMedia"), status);
 return false;
    }
    /* Create memory pool for application purpose */
    pool = pj_pool_create( &cp.factory,     /* pool factory     */
      "app",     /* pool name.     */
      1000,     /* init size     */
      1000,     /* increment size     */
      NULL      /* callback on error    */
      );

    /* Register all supported codecs */
    status = init_codecs(med_endpt);

    if (status != PJ_SUCCESS)
 OnError(TEXT("could not initialize codecs"), status);

//Assign codec
 codec_id = codec;
 unsigned count = 1;
 pj_str_t str_codec_id = pj_str(codec_id);
 pjmedia_codec_mgr *codec_mgr = pjmedia_endpt_get_codec_mgr(med_endpt);
 status = pjmedia_codec_mgr_find_codecs_by_id( codec_mgr,
            &str_codec_id, &count,
            &codec_info, NULL);
 // pjmedia_codec_mgr_get_codec_info(
pjmedia_endpt_get_codec_mgr(med_endpt),0, &codec_info);

 if (status != PJ_SUCCESS) {
     OnError(TEXT("Error: unable to find codec \n"),status);
     return false;
 }
 //Initialize sockets
  pj_str_t ip = pj_str(destIPAddress);
 pj_uint16_t port = (pj_uint16_t) atoi(destPortNum);
local_port = (pj_uint16_t) atoi(recevingPort);
 status = pj_sockaddr_in_init(&remote_addr, &ip, port);

  dir = PJMEDIA_DIR_ENCODING_DECODING;
  status = create_stream(pool, med_endpt, codec_info, dir, local_port,
   &remote_addr, &stream);
  /* Get the port interface of the stream */
  if (status != PJ_SUCCESS){
   OnError(TEXT("could not create stream"), status);
   return false;
    }
  status = pjmedia_stream_get_port( stream, &stream_port);
  if (status != PJ_SUCCESS){
   OnError(TEXT("could not get stream port"), status);
   return FALSE;
    }

  status = pjmedia_snd_port_create(pool, -1, -1,
   stream_port->info.clock_rate,
   stream_port->info.channel_count,
   stream_port->info.samples_per_frame,
   stream_port->info.bits_per_sample,
   0, &snd_port);
  if (status != PJ_SUCCESS){
   OnError(TEXT("Unable to create sound port"), status);
   return false;
    }
  /* Connect sound port to stream */
  status = pjmedia_snd_port_connect( snd_port, stream_port );
  if (status != PJ_SUCCESS){
   OnError(TEXT("Unable to connect sound port to stream"), status);
   return false;
    }



    return true;
}

Anass Kartit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20090317/ad3a3f20/attachment-0001.html>


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux