Discussion:
[pjsip] Connection on a Multicast channel with PJSIP
Lele
2017-07-10 07:47:27 UTC
Permalink
Hi guys,

With Pjsip I'm trying to connect with a multicast channel/ipAddress (I
should receive and transmit audio on defined idAddress).

According with streamutil.c I have wrote the following c++ function but It's
not working:



pj_status_t ApplicationCore::multicastConnection() {



intLogger->log(InternalLogger::LOG_INFO, "MULTICAST CONNECTION");



pjmedia_stream **p_stream;

pjmedia_endpt *med_endpt;

pj_caching_pool cp;

pj_status_t status;

pjmedia_stream *stream = NULL;

pj_uint16_t local_port = 3000;

const pjmedia_codec_info *codec_info;

const pj_sockaddr_in *rem_addr;



/* 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);

PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);



pjmedia_stream_info info;

pjmedia_transport *transport = NULL;



//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.rx_pt = codec_info->pt;

info.ssrc = pj_rand();



pj_memcpy(&info.rem_addr, rem_addr, sizeof(pj_sockaddr_in));



//239.0.0.1 multicast channel

const pj_str_t multicastAddrIpv4 = pj_str("239.0.0.1");

status = pj_sockaddr_in_init(&info.rem_addr.ipv4, &multicastAddrIpv4,
0);

if(status != PJ_SUCCESS) {

intLogger->log(InternalLogger::LOG_CRITICAL, "initialize IPv4
socket address failed");

return status;

}



//Create media transport

status = pjmedia_transport_udp_create(med_endpt, NULL, local_port, 0,
&transport);

if(status != PJ_SUCCESS) {

intLogger->log(InternalLogger::LOG_CRITICAL, "pjmedia transport udp
create failed");

return status;

}



status = pjmedia_stream_create( med_endpt, pool, &info, transport,
NULL, p_stream);



if (status != PJ_SUCCESS) {

intLogger->log(InternalLogger::LOG_CRITICAL, "error creating
stream");

pjmedia_transport_close(transport);

return status;

}



//Start streaming

pjmedia_stream_start(stream);



return PJ_SUCCESS;

}



How can I implement this function in the right mode? Thanks in advice.



Best Regards

LL

Loading...