Пример #1
0
static pj_status_t transport_get_info(pjmedia_transport *tp,
				      pjmedia_transport_info *info)
{
    struct transport_ice *tp_ice = (struct transport_ice*)tp;
    pj_ice_sess_cand cand;
    pj_status_t status;

    pj_bzero(&info->sock_info, sizeof(info->sock_info));
    info->sock_info.rtp_sock = info->sock_info.rtcp_sock = PJ_INVALID_SOCKET;

    /* Get RTP default address */
    status = pj_ice_strans_get_def_cand(tp_ice->ice_st, 1, &cand);
    if (status != PJ_SUCCESS)
	return status;

    pj_sockaddr_cp(&info->sock_info.rtp_addr_name, &cand.addr);

    /* Get RTCP default address */
    if (tp_ice->comp_cnt > 1) {
	status = pj_ice_strans_get_def_cand(tp_ice->ice_st, 2, &cand);
	if (status != PJ_SUCCESS)
	    return status;

	pj_sockaddr_cp(&info->sock_info.rtcp_addr_name, &cand.addr);
    }

    /* Set remote address originating RTP & RTCP if this transport has 
     * ICE activated or received any packets.
     */
    if (tp_ice->use_ice || tp_ice->rtp_src_cnt) {
	info->src_rtp_name  = tp_ice->rtp_src_addr;
	info->src_rtcp_name = tp_ice->rtcp_src_addr;
    }

    return PJ_SUCCESS;
}
Пример #2
0
static int extract_sdp_to_xml(struct ice_trans_s* icetrans,char buffer[], unsigned maxlen, ice_option_t opt, char *usrid)
{
    char *p = buffer;
    unsigned comp;
    int printed;
    pj_str_t local_ufrag, local_pwd;
    pj_status_t status;

    //Me: add

    PRINT(" <registerPeer>");
    PRINT("<device> <uniqueId>%s</uniqueId> </device>", usrid);



    /* Write "dummy" SDP v=, o=, s=, and t= lines */
    // Me: comment
    //PRINT("v=0\no=- 3414953978 3414953978 IN IP4 localhost\ns=ice\nt=0 0\n");

    /* Get ufrag and pwd from current session */
    pj_ice_strans_get_ufrag_pwd(icetrans->icest, &local_ufrag, &local_pwd,
                                NULL, NULL);


    /* Write the a=ice-ufrag and a=ice-pwd attributes */
    // Me: comment
    //PRINT("a=ice-ufrag:%.*s\na=ice-pwd:%.*s\n",
    //      (int)local_ufrag.slen,
    //      local_ufrag.ptr,
    //      (int)local_pwd.slen,
    //      local_pwd.ptr);

    PRINT("<ufrag>%.*s</ufrag> <pwd>%.*s</pwd>",
          (int)local_ufrag.slen,
          local_ufrag.ptr,
          (int)local_pwd.slen,
          local_pwd.ptr);


    PRINT(" <candidateList>");

    /* Write each component */
    for (comp=0; comp<opt.comp_cnt; ++comp) {
        unsigned j, cand_cnt;
        pj_ice_sess_cand cand[PJ_ICE_ST_MAX_CAND];
        char ipaddr[PJ_INET6_ADDRSTRLEN];

        /* Get default candidate for the component */
        status = pj_ice_strans_get_def_cand(icetrans->icest, comp+1, &cand[0]);
        if (status != PJ_SUCCESS)
            return -status;

        /* Write the default address */
        if (comp==0) {
            /* For component 1, default address is in m= and c= lines */
            // Me: comment
            // PRINT("m=audio %d RTP/AVP 0\n"
            //      "c=IN IP4 %s\n",
            //      (int)pj_sockaddr_get_port(&cand[0].addr),
            //      pj_sockaddr_print(&cand[0].addr, ipaddr,
            //                        sizeof(ipaddr), 0));

            PRINT("<comp_1> <port>%d</port>"
                  "<ip>%s</ip> </comp_1>",
                  (int)pj_sockaddr_get_port(&cand[0].addr),
                  pj_sockaddr_print(&cand[0].addr, ipaddr,
                                    sizeof(ipaddr), 0));

        } else if (comp==1) {
            /* For component 2, default address is in a=rtcp line */
            //Me: comment
            //PRINT("a=rtcp:%d IN IP4 %s\n",
            //      (int)pj_sockaddr_get_port(&cand[0].addr),
            //      pj_sockaddr_print(&cand[0].addr, ipaddr,
            //                        sizeof(ipaddr), 0));
        } else {
            /* For other components, we'll just invent this.. */
            // Me: comment
            //PRINT("a=Xice-defcand:%d IN IP4 %s\n",
            //      (int)pj_sockaddr_get_port(&cand[0].addr),
            //      pj_sockaddr_print(&cand[0].addr, ipaddr,
            //                        sizeof(ipaddr), 0));
        }

        /* Enumerate all candidates for this component */
        cand_cnt = PJ_ARRAY_SIZE(cand);
        status = pj_ice_strans_enum_cands(icetrans->icest, comp+1,
                                          &cand_cnt, cand);
        if (status != PJ_SUCCESS)
            return -status;

        /* And encode the candidates as SDP */
        //const int buffer_xml_len = 2048;
        //char buffer_xml[buffer_xml_len];
        for (j=0; j<cand_cnt; ++j) {
            printed = print_cand_to_xml(p, maxlen - (unsigned)(p-buffer), &cand[j]);
            if (printed < 0)
                return -PJ_ETOOSMALL;
         //   printed = print_cand_to_xml(p, maxlen - (unsigned)(p-buffer), &cand[j]);
         //   if (printed < 0)
          //      return -PJ_ETOOSMALL;
            p += printed;
        }
    }
    PRINT("</candidateList>");

    PRINT(" </registerPeer>");

    if (p == buffer+maxlen)
        return -PJ_ETOOSMALL;

    *p = '\0';

    //printf("DEBUGGGGGG: %s \n", (p - buffer);
    return (int)(p - buffer);
}
Пример #3
0
/* 
 * Encode ICE information in SDP.
 */
static int encode_session(char buffer[], unsigned maxlen)
{
    char *p = buffer;
    unsigned comp;
    int printed;
    pj_str_t local_ufrag, local_pwd;
    pj_status_t status;

    /* Write "dummy" SDP v=, o=, s=, and t= lines */
    PRINT("v=0\no=- 3414953978 3414953978 IN IP4 localhost\ns=ice\nt=0 0\n", 
	  0, 0, 0, 0, 0, 0);

    /* Get ufrag and pwd from current session */
    pj_ice_strans_get_ufrag_pwd(icedemo.icest, &local_ufrag, &local_pwd,
				NULL, NULL);

    /* Write the a=ice-ufrag and a=ice-pwd attributes */
    PRINT("a=ice-ufrag:%.*s\na=ice-pwd:%.*s\n",
	   (int)local_ufrag.slen,
	   local_ufrag.ptr,
	   (int)local_pwd.slen,
	   local_pwd.ptr, 
	   0, 0);

    /* Write each component */
    for (comp=0; comp<icedemo.opt.comp_cnt; ++comp) {
	unsigned j, cand_cnt;
	pj_ice_sess_cand cand[PJ_ICE_ST_MAX_CAND];
	char ipaddr[PJ_INET6_ADDRSTRLEN];

	/* Get default candidate for the component */
	status = pj_ice_strans_get_def_cand(icedemo.icest, comp+1, &cand[0]);
	if (status != PJ_SUCCESS)
	    return -status;

	/* Write the default address */
	if (comp==0) {
	    /* For component 1, default address is in m= and c= lines */
	    PRINT("m=audio %d RTP/AVP 0\n"
		  "c=IN IP4 %s\n",
		  (int)pj_sockaddr_get_port(&cand[0].addr),
		  pj_sockaddr_print(&cand[0].addr, ipaddr,
				    sizeof(ipaddr), 0),
		  0, 0, 0, 0);
	} else if (comp==1) {
	    /* For component 2, default address is in a=rtcp line */
	    PRINT("a=rtcp:%d IN IP4 %s\n",
		  (int)pj_sockaddr_get_port(&cand[0].addr),
		  pj_sockaddr_print(&cand[0].addr, ipaddr,
				    sizeof(ipaddr), 0),
		  0, 0, 0, 0);
	} else {
	    /* For other components, we'll just invent this.. */
	    PRINT("a=Xice-defcand:%d IN IP4 %s\n",
		  (int)pj_sockaddr_get_port(&cand[0].addr),
		  pj_sockaddr_print(&cand[0].addr, ipaddr,
				    sizeof(ipaddr), 0),
		  0, 0, 0, 0);
	}

	/* Enumerate all candidates for this component */
	status = pj_ice_strans_enum_cands(icedemo.icest, comp+1,
					  &cand_cnt, cand);
	if (status != PJ_SUCCESS)
	    return -status;

	/* And encode the candidates as SDP */
	for (j=0; j<cand_cnt; ++j) {
	    printed = print_cand(p, maxlen - (p-buffer), &cand[j]);
	    if (printed < 0)
		return -PJ_ETOOSMALL;
	    p += printed;
	}
    }

    if (p == buffer+maxlen)
	return -PJ_ETOOSMALL;

    *p = '\0';
    return p - buffer;
}
Пример #4
0
int krx_ice_start_session(krx_ice* k) {

  pj_status_t r;

  if(!k) { return - 1; } 
  if(!k->ice_st) { return -2; } 

  if(pj_ice_strans_has_sess(k->ice_st)) {
    printf("Error: ice already has a session.\n");
    return -3;
  }

  
  r = pj_ice_strans_init_ice(k->ice_st, PJ_ICE_SESS_ROLE_CONTROLLED, NULL, NULL);
  if(r != PJ_SUCCESS) {
    printf("Error: cannot initialize an ice session.\n");
    return -4;
  }

  /* this is where we can create an sdp */
  char sdp_buf[8096] = { 0 } ;
  sprintf(sdp_buf,
          "v=0\n" 
          "o=- 123456789 34234324 IN IP4 localhost\n"    /* - [identifier] [session version] IN IP4 localhost */
          "s=krx_ice\n"                                  /* software */
          "t=0 0\n"                                      /* start, ending time */
          "a=ice-ufrag:%s\n"
          "a=ice-pwd:%s\n"
          ,
          k->ice_ufrag,
          k->ice_pwd
  );

  /* write each component */
  for(int i = 0; i < k->ncomp; ++i) {

    pj_ice_sess_cand cand[PJ_ICE_ST_MAX_CAND] = { 0 } ;
    char ipaddr[PJ_INET6_ADDRSTRLEN] = { 0 } ;

    /* get default candidate for component, note that compoments start numbering from 1, not zero. */
    r = pj_ice_strans_get_def_cand(k->ice_st, 1, &cand[0]);
    if(r != PJ_SUCCESS) {
      printf("Error: cannot retrieve default candidate for component: %d\n", i+1);
      continue;
    }

    if(i == 0) {
      int offset = strlen(sdp_buf);
      sprintf(sdp_buf + offset, 
              "m=video %d RTP/SAVPF 120\n"
              "c=IN IP4 %s\n"
              ,
              (int)pj_sockaddr_get_port(&cand[0].addr),
              pj_sockaddr_print(&cand[0].addr, ipaddr, sizeof(ipaddr), 0)              
      );

      /* print all candidates */
      unsigned num_cands = PJ_ARRAY_SIZE(cand);
      printf("Found number of candidates: %d\n", num_cands);      

      // (ice_st && ice_st->ice && comp_id && comp_id <= ice_st->comp_cnt && count && cand),
      printf("ice: %p\n", k->ice_st);
      r = pj_ice_strans_enum_cands(k->ice_st, i + 1, &num_cands, cand);
      if(r != PJ_SUCCESS) {
        printf("Error: cannot retrieve candidates.\n");
        exit(1);
      }


#if 1

      for(int j = 0; j < num_cands; ++j) {
        int offset = strlen(sdp_buf);
        char* start_addr = sdp_buf + offset;
        krx_ice_candidate_to_string(sdp_buf, sizeof(sdp_buf)-offset, &cand[j]);
        char* end_addr = sdp_buf + strlen(sdp_buf);
        printf("--------\n%s\n--------------\n", sdp_buf);
      }

      offset = strlen(sdp_buf);
      char* start_addr = sdp_buf + offset;
      krx_ice_candidate_to_string(sdp_buf + offset, sizeof(sdp_buf)-offset, &cand[1]);
      char* end_addr = sdp_buf + strlen(sdp_buf);
#endif
    }


  }


  printf("SDP: %s\n", sdp_buf);
          

  r = pj_ice_strans_init_ice(k->ice_st, PJ_ICE_SESS_ROLE_CONTROLLED, NULL, NULL);
  CHECK_PJ_STATUS(r, "Error: cannot init ice session.\n", -4);

  return 0;
}