本文整理汇总了C++中pj_pool_alloc函数的典型用法代码示例。如果您正苦于以下问题:C++ pj_pool_alloc函数的具体用法?C++ pj_pool_alloc怎么用?C++ pj_pool_alloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pj_pool_alloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: compliance_test_2
/*
* Repeated connect/accept on the same listener socket.
*/
static int compliance_test_2(pj_bool_t allow_concur)
{
#if defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0
enum { MAX_PAIR = 1, TEST_LOOP = 2 };
#else
enum { MAX_PAIR = 4, TEST_LOOP = 2 };
#endif
struct listener
{
pj_sock_t sock;
pj_ioqueue_key_t *key;
pj_sockaddr_in addr;
int addr_len;
} listener;
struct server
{
pj_sock_t sock;
pj_ioqueue_key_t *key;
pj_sockaddr_in local_addr;
pj_sockaddr_in rem_addr;
int rem_addr_len;
pj_ioqueue_op_key_t accept_op;
} server[MAX_PAIR];
struct client
{
pj_sock_t sock;
pj_ioqueue_key_t *key;
} client[MAX_PAIR];
pj_pool_t *pool = NULL;
char *send_buf, *recv_buf;
pj_ioqueue_t *ioque = NULL;
int i, bufsize = BUF_MIN_SIZE;
int status;
int test_loop, pending_op = 0;
pj_timestamp t_elapsed;
pj_str_t s;
pj_status_t rc;
listener.sock = PJ_INVALID_SOCKET;
listener.key = NULL;
for (i=0; i<MAX_PAIR; ++i) {
server[i].sock = PJ_INVALID_SOCKET;
server[i].key = NULL;
}
for (i=0; i<MAX_PAIR; ++i) {
client[i].sock = PJ_INVALID_SOCKET;
client[i].key = NULL;
}
// Create pool.
pool = pj_pool_create(mem, NULL, POOL_SIZE, 4000, NULL);
// Create I/O Queue.
rc = pj_ioqueue_create(pool, PJ_IOQUEUE_MAX_HANDLES, &ioque);
if (rc != PJ_SUCCESS) {
app_perror("...ERROR in pj_ioqueue_create()", rc);
return -10;
}
// Concurrency
rc = pj_ioqueue_set_default_concurrency(ioque, allow_concur);
if (rc != PJ_SUCCESS) {
app_perror("...ERROR in pj_ioqueue_set_default_concurrency()", rc);
return -11;
}
// Allocate buffers for send and receive.
send_buf = (char*)pj_pool_alloc(pool, bufsize);
recv_buf = (char*)pj_pool_alloc(pool, bufsize);
// Create listener socket
rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &listener.sock);
if (rc != PJ_SUCCESS) {
app_perror("...error creating socket", rc);
status=-20; goto on_error;
}
// Bind listener socket.
pj_sockaddr_in_init(&listener.addr, 0, 0);
if ((rc=pj_sock_bind(listener.sock, &listener.addr, sizeof(listener.addr))) != 0 ) {
app_perror("...bind error", rc);
status=-30; goto on_error;
}
// Get listener address.
listener.addr_len = sizeof(listener.addr);
rc = pj_sock_getsockname(listener.sock, &listener.addr, &listener.addr_len);
if (rc != PJ_SUCCESS) {
app_perror("...ERROR in pj_sock_getsockname()", rc);
//.........这里部分代码省略.........
开发者ID:avble,项目名称:natClientEx,代码行数:101,代码来源:ioq_tcp.c
示例2: bb10_open_capture
//.........这里部分代码省略.........
snd_mixer_group_t group;
snd_pcm_channel_params_t pp;
snd_pcm_channel_setup_t setup;
if (param->rec_id < 0 || param->rec_id >= stream->af->dev_cnt)
return PJMEDIA_EAUD_INVDEV;
PJ_ASSERT_RETURN(param->bits_per_sample == 16, PJMEDIA_EAUD_SAMPFORMAT);
if ((ret=audio_manager_snd_pcm_open_name(AUDIO_TYPE_VIDEO_CHAT,
&stream->ca_pcm,
&stream->ca_audio_manager_handle,
(char*)"voice",
SND_PCM_OPEN_CAPTURE)) < 0)
{
TRACE_((THIS_FILE, "audio_manager_snd_pcm_open_name ret = %d", ret));
return PJMEDIA_EAUD_SYSERR;
}
/* Required call from January 2013 gold OS release */
snd_pcm_plugin_set_disable (stream->ca_pcm, PLUGIN_DISABLE_MMAP);
/* Required call from January 2013 gold OS release */
snd_pcm_plugin_set_enable(stream->ca_pcm, PLUGIN_ROUTING);
/* sample reads the capabilities of the capture */
memset (&pi, 0, sizeof (pi));
pi.channel = SND_PCM_CHANNEL_CAPTURE;
if ((ret = snd_pcm_plugin_info (stream->ca_pcm, &pi)) < 0) {
TRACE_((THIS_FILE, "snd_pcm_plugin_info ret = %d", ret));
return PJMEDIA_EAUD_SYSERR;
}
/* Request the VoIP parameters
* These parameters are different to waverec sample
*/
memset (&pp, 0, sizeof (pp));
/* Blocking read */
pp.mode = SND_PCM_MODE_BLOCK;
pp.channel = SND_PCM_CHANNEL_CAPTURE;
pp.start_mode = SND_PCM_START_FULL;
/* Auto-recover from errors */
pp.stop_mode = SND_PCM_STOP_ROLLOVER;
pp.buf.block.frag_size = param->samples_per_frame * param->bits_per_sample / 8;
/* From January 2013 gold OS release. RIM recommend these for capture */
pp.buf.block.frags_max = 3;
pp.buf.block.frags_min = 1;
pp.format.interleave = 1;
pp.format.rate = param->clock_rate;
pp.format.voices = param->channel_count;
pp.format.format = get_alsa_pcm_fmt(param);
/* make the request */
if ((ret = snd_pcm_plugin_params (stream->ca_pcm, &pp)) < 0) {
TRACE_((THIS_FILE, "snd_pcm_plugin_params ret = %d", ret));
return PJMEDIA_EAUD_SYSERR;
}
/* Again based on the sample */
memset (&setup, 0, sizeof (setup));
memset (&group, 0, sizeof (group));
setup.channel = SND_PCM_CHANNEL_CAPTURE;
setup.mixer_gid = &group.gid;
if ((ret = snd_pcm_plugin_setup (stream->ca_pcm, &setup)) < 0) {
TRACE_((THIS_FILE, "snd_pcm_plugin_setup ret = %d", ret));
return PJMEDIA_EAUD_SYSERR;
}
frame_size = setup.buf.block.frag_size;
if (group.gid.name[0] == 0) {
} else {
}
frame_size = setup.buf.block.frag_size;
PJ_UNUSED_ARG(frame_size); /* Warning about unused var */
/* Set clock rate */
rate = param->clock_rate;
stream->ca_frames = (unsigned long) param->samples_per_frame /
param->channel_count;
/* Set the sound device buffer size and latency */
if (param->flags & PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY) {
tmp_buf_size = rate * param->input_latency_ms / 1000;
} else {
tmp_buf_size = rate * PJMEDIA_SND_DEFAULT_REC_LATENCY / 1000;
}
stream->param.input_latency_ms = tmp_buf_size * 1000 / rate;
/* Set our buffer */
stream->ca_buf_size = stream->ca_frames * param->channel_count *
param->bits_per_sample / 8;
stream->ca_buf = (char *)pj_pool_alloc (stream->pool, stream->ca_buf_size);
TRACE_((THIS_FILE, "bb10_open_capture: ca_frames = %d clock = %d",
stream->ca_frames, param->clock_rate));
return PJ_SUCCESS;
}
开发者ID:acatighera,项目名称:python-sipsimple,代码行数:101,代码来源:bb10_dev.c
示例3: open_stream
/*
* Open stream.
*/
static pj_status_t open_stream( pjmedia_dir dir,
int rec_id,
int play_id,
unsigned clock_rate,
unsigned channel_count,
unsigned samples_per_frame,
unsigned bits_per_sample,
pjmedia_snd_rec_cb rec_cb,
pjmedia_snd_play_cb play_cb,
void *user_data,
pjmedia_snd_stream **p_snd_strm)
{
pj_pool_t *pool;
pjmedia_snd_stream *strm;
pj_status_t status;
/* Make sure sound subsystem has been initialized with
* pjmedia_snd_init()
*/
PJ_ASSERT_RETURN( pool_factory != NULL, PJ_EINVALIDOP );
/* Can only support 16bits per sample */
PJ_ASSERT_RETURN(bits_per_sample == BITS_PER_SAMPLE, PJ_EINVAL);
/* Create and Initialize stream descriptor */
pool = pj_pool_create(pool_factory, "dsound-dev", 1000, 1000, NULL);
PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
strm = pj_pool_zalloc(pool, sizeof(pjmedia_snd_stream));
strm->dir = dir;
strm->play_id = play_id;
strm->rec_id = rec_id;
strm->pool = pool;
strm->rec_cb = rec_cb;
strm->play_cb = play_cb;
strm->user_data = user_data;
strm->clock_rate = clock_rate;
strm->samples_per_frame = samples_per_frame;
strm->bits_per_sample = bits_per_sample;
strm->channel_count = channel_count;
strm->buffer = pj_pool_alloc(pool, samples_per_frame * BYTES_PER_SAMPLE);
if (!strm->buffer) {
pj_pool_release(pool);
return PJ_ENOMEM;
}
/*
* Create event for stopping the worker thread.
*/
strm->thread_quit_event = CreateEvent(NULL, FALSE, FALSE, NULL);
if (strm->thread_quit_event == NULL) {
status = pj_get_os_error();
pj_pool_release(pool);
return status;
}
/* Create player stream */
if (dir & PJMEDIA_DIR_PLAYBACK) {
unsigned buffer_count;
/* Calculate buffer count, in frame unit */
buffer_count = clock_rate * snd_output_latency / samples_per_frame /
1000;
/* There must always be one more buffer than required for the latency */
buffer_count += 1;
if (buffer_count < MIN_PACKET_BUFFER_COUNT)
buffer_count = MIN_PACKET_BUFFER_COUNT;
if (buffer_count > MAX_PACKET_BUFFER_COUNT)
buffer_count = MAX_PACKET_BUFFER_COUNT;
status = init_player_stream( &strm->play_strm, play_id, clock_rate,
channel_count, samples_per_frame,
buffer_count );
if (status != PJ_SUCCESS) {
pjmedia_snd_stream_close(strm);
return status;
}
}
/* Create capture stream */
if (dir & PJMEDIA_DIR_CAPTURE) {
unsigned buffer_count;
/* Calculate buffer count, in frame unit */
buffer_count = clock_rate * snd_input_latency / samples_per_frame /
1000;
if (buffer_count < MIN_PACKET_BUFFER_COUNT)
buffer_count = MIN_PACKET_BUFFER_COUNT;
if (buffer_count > MAX_PACKET_BUFFER_COUNT)
buffer_count = MAX_PACKET_BUFFER_COUNT;
status = init_capture_stream( &strm->rec_strm, rec_id, clock_rate,
channel_count, samples_per_frame,
buffer_count);
if (status != PJ_SUCCESS) {
pjmedia_snd_stream_close(strm);
//.........这里部分代码省略.........
开发者ID:deveck,项目名称:Deveck.TAM,代码行数:101,代码来源:dsound.c
示例4: im_on_rx_request
/*
* Handler to receive incoming MESSAGE
*/
static pj_bool_t im_on_rx_request(pjsip_rx_data *rdata)
{
pj_str_t from, to;
pjsip_accept_hdr *accept_hdr;
pjsip_msg *msg;
pj_status_t status;
msg = rdata->msg_info.msg;
/* Only want to handle MESSAGE requests. */
if (pjsip_method_cmp(&msg->line.req.method, &pjsip_message_method) != 0) {
return PJ_FALSE;
}
/* Should not have any transaction attached to rdata. */
PJ_ASSERT_RETURN(pjsip_rdata_get_tsx(rdata)==NULL, PJ_FALSE);
/* Should not have any dialog attached to rdata. */
PJ_ASSERT_RETURN(pjsip_rdata_get_dlg(rdata)==NULL, PJ_FALSE);
/* Check if we can accept the message. */
if (!pjsua_im_accept_pager(rdata, &accept_hdr)) {
pjsip_hdr hdr_list;
pj_list_init(&hdr_list);
pj_list_push_back(&hdr_list, accept_hdr);
pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata,
PJSIP_SC_NOT_ACCEPTABLE_HERE, NULL,
&hdr_list, NULL);
return PJ_TRUE;
}
/* Respond with 200 first, so that remote doesn't retransmit in case
* the UI takes too long to process the message.
*/
status = pjsip_endpt_respond( pjsua_var.endpt, NULL, rdata, 200, NULL,
NULL, NULL, NULL);
/* For the source URI, we use Contact header if present, since
* Contact header contains the port number information. If this is
* not available, then use From header.
*/
from.ptr = (char*)pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE);
from.slen = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR,
rdata->msg_info.from->uri,
from.ptr, PJSIP_MAX_URL_SIZE);
if (from.slen < 1)
from = pj_str("<--URI is too long-->");
/* Build the To text. */
to.ptr = (char*) pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE);
to.slen = pjsip_uri_print( PJSIP_URI_IN_FROMTO_HDR,
rdata->msg_info.to->uri,
to.ptr, PJSIP_MAX_URL_SIZE);
if (to.slen < 1)
to = pj_str("<--URI is too long-->");
/* Process pager. */
pjsua_im_process_pager(-1, &from, &to, rdata);
/* Done. */
return PJ_TRUE;
}
开发者ID:CryptoCall,项目名称:pjsip,代码行数:69,代码来源:pjsua_im.c
示例5: factory_create_streamBDIMAD
static pj_status_t factory_create_streamBDIMAD(pjmedia_aud_dev_factory *f,
const pjmedia_aud_param *param,
pjmedia_aud_rec_cb rec_cb,
pjmedia_aud_play_cb play_cb,
void *user_data,
pjmedia_aud_stream **p_aud_strm)
{
struct bd_factory *wf = (struct bd_factory*)f;
pj_pool_t *pool;
struct bd_stream *strm;
pj_uint8_t silence_char;
pj_status_t status;
switch (param->ext_fmt.id) {
case PJMEDIA_FORMAT_L16:
silence_char = '\0';
break;
default:
return PJMEDIA_EAUD_BADFORMAT;
}
/* Create and Initialize stream descriptor */
pool = pj_pool_create(wf->pf, "BDIMAD_STREAM", 1000, 1000, NULL);
PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
strm = PJ_POOL_ZALLOC_T(pool, struct bd_stream);
pj_memcpy(&strm->param, param, sizeof(*param));
strm->pool = pool;
strm->rec_cb = rec_cb;
strm->play_cb = play_cb;
strm->user_data = user_data;
strm->fmt_id = (pjmedia_format_id)param->ext_fmt.id;
strm->silence_char = silence_char;
strm->channel_count = param->channel_count;
strm->samples_per_frame = param->samples_per_frame;
if (param->dir & PJMEDIA_DIR_CAPTURE_PLAYBACK) {
status = init_streams(wf, strm, param);
if (status != PJ_SUCCESS) {
stream_destroyBDIMAD(&strm->base);
return status;
}
} else {
stream_destroyBDIMAD(&strm->base);
return PJMEDIA_EAUD_ERR;
}
strm->rec_buf = (pj_int16_t*)pj_pool_alloc(pool,
strm->bytes_per_frame);
if (!strm->rec_buf) {
pj_pool_release(pool);
return PJ_ENOMEM;
}
strm->rec_buf_count = 0;
strm->play_buf = (pj_int16_t*)pj_pool_alloc(pool,
strm->bytes_per_frame);
if (!strm->play_buf) {
pj_pool_release(pool);
return PJ_ENOMEM;
}
strm->play_buf_count = 0;
/* Apply the remaining settings */
if(param->flags & PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING) {
stream_set_capBDIMAD(&strm->base,
PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING,
¶m->output_vol);
}
if(param->flags & PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING) {
stream_set_capBDIMAD(&strm->base,
PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING,
¶m->input_vol);
}
if(param->flags & PJMEDIA_AUD_DEV_CAP_EC) {
stream_set_capBDIMAD(&strm->base,
PJMEDIA_AUD_DEV_CAP_EC,
¶m->ec_enabled);
}
strm->base.op = &stream_op;
*p_aud_strm = &strm->base;
return PJ_SUCCESS;
}
开发者ID:ClearwaterCore,项目名称:pjsip-upstream,代码行数:86,代码来源:bdimad_dev.c
示例6: create_bidir_stream
/* Internal: Create both player and recorder stream */
static pj_status_t create_bidir_stream(struct pa_aud_factory *pa,
const pjmedia_aud_param *param,
pjmedia_aud_rec_cb rec_cb,
pjmedia_aud_play_cb play_cb,
void *user_data,
pjmedia_aud_stream **p_snd_strm)
{
pj_pool_t *pool;
pjmedia_aud_dev_index rec_id, play_id;
struct pa_aud_stream *stream;
PaStream *paStream = NULL;
PaStreamParameters inputParam;
PaStreamParameters outputParam;
int sampleFormat;
const PaDeviceInfo *paRecDevInfo = NULL;
const PaDeviceInfo *paPlayDevInfo = NULL;
const PaHostApiInfo *paRecHostApiInfo = NULL;
const PaHostApiInfo *paPlayHostApiInfo = NULL;
const PaStreamInfo *paSI;
unsigned paFrames, paRate, paInputLatency, paOutputLatency;
PaError err;
PJ_ASSERT_RETURN(play_cb && rec_cb && p_snd_strm, PJ_EINVAL);
rec_id = param->rec_id;
if (rec_id < 0) {
rec_id = pa_get_default_input_dev(param->channel_count);
if (rec_id < 0) {
/* No such device. */
return PJMEDIA_EAUD_NODEFDEV;
}
}
paRecDevInfo = Pa_GetDeviceInfo(rec_id);
if (!paRecDevInfo) {
/* Assumed it is "No such device" error. */
return PJMEDIA_EAUD_INVDEV;
}
play_id = param->play_id;
if (play_id < 0) {
play_id = pa_get_default_output_dev(param->channel_count);
if (play_id < 0) {
/* No such device. */
return PJMEDIA_EAUD_NODEFDEV;
}
}
paPlayDevInfo = Pa_GetDeviceInfo(play_id);
if (!paPlayDevInfo) {
/* Assumed it is "No such device" error. */
return PJMEDIA_EAUD_INVDEV;
}
if (param->bits_per_sample == 8)
sampleFormat = paUInt8;
else if (param->bits_per_sample == 16)
sampleFormat = paInt16;
else if (param->bits_per_sample == 32)
sampleFormat = paInt32;
else
return PJMEDIA_EAUD_SAMPFORMAT;
pool = pj_pool_create(pa->pf, "sndstream", 1024, 1024, NULL);
if (!pool)
return PJ_ENOMEM;
stream = PJ_POOL_ZALLOC_T(pool, struct pa_aud_stream);
stream->pool = pool;
pj_strdup2_with_null(pool, &stream->name, paRecDevInfo->name);
stream->dir = PJMEDIA_DIR_CAPTURE_PLAYBACK;
stream->play_id = play_id;
stream->rec_id = rec_id;
stream->user_data = user_data;
stream->samples_per_sec = param->clock_rate;
stream->samples_per_frame = param->samples_per_frame;
stream->bytes_per_sample = param->bits_per_sample / 8;
stream->channel_count = param->channel_count;
stream->rec_cb = rec_cb;
stream->play_cb = play_cb;
stream->rec_buf = (pj_int16_t*)pj_pool_alloc(pool,
stream->samples_per_frame * stream->bytes_per_sample);
stream->rec_buf_count = 0;
stream->play_buf = (pj_int16_t*)pj_pool_alloc(pool,
stream->samples_per_frame * stream->bytes_per_sample);
stream->play_buf_count = 0;
pj_bzero(&inputParam, sizeof(inputParam));
inputParam.device = rec_id;
inputParam.channelCount = param->channel_count;
inputParam.hostApiSpecificStreamInfo = NULL;
inputParam.sampleFormat = sampleFormat;
if (param->flags & PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY)
inputParam.suggestedLatency = param->input_latency_ms / 1000.0;
else
inputParam.suggestedLatency = PJMEDIA_SND_DEFAULT_REC_LATENCY / 1000.0;
//.........这里部分代码省略.........
开发者ID:Antares84,项目名称:asuswrt-merlin,代码行数:101,代码来源:pa_dev.c
示例7: open_capture
static pj_status_t open_capture (struct alsa_stream* stream,
const pjmedia_aud_param *param)
{
snd_pcm_hw_params_t* params;
snd_pcm_format_t format;
int result;
unsigned int rate;
snd_pcm_uframes_t tmp_buf_size;
snd_pcm_uframes_t tmp_period_size;
if (param->rec_id < 0 || param->rec_id >= stream->af->dev_cnt)
return PJMEDIA_EAUD_INVDEV;
/* Open PCM for capture */
PJ_LOG (5,(THIS_FILE, "open_capture: Open capture device '%s'",
stream->af->devs[param->rec_id].name));
result = snd_pcm_open (&stream->ca_pcm,
stream->af->devs[param->rec_id].name,
SND_PCM_STREAM_CAPTURE,
0);
if (result < 0)
return PJMEDIA_EAUD_SYSERR;
/* Allocate a hardware parameters object. */
snd_pcm_hw_params_alloca (¶ms);
/* Fill it in with default values. */
snd_pcm_hw_params_any (stream->ca_pcm, params);
/* Set interleaved mode */
snd_pcm_hw_params_set_access (stream->ca_pcm, params,
SND_PCM_ACCESS_RW_INTERLEAVED);
/* Set format */
switch (param->bits_per_sample) {
case 8:
TRACE_((THIS_FILE, "open_capture: set format SND_PCM_FORMAT_S8"));
format = SND_PCM_FORMAT_S8;
break;
case 16:
TRACE_((THIS_FILE, "open_capture: set format SND_PCM_FORMAT_S16_LE"));
format = SND_PCM_FORMAT_S16_LE;
break;
case 24:
TRACE_((THIS_FILE, "open_capture: set format SND_PCM_FORMAT_S24_LE"));
format = SND_PCM_FORMAT_S24_LE;
break;
case 32:
TRACE_((THIS_FILE, "open_capture: set format SND_PCM_FORMAT_S32_LE"));
format = SND_PCM_FORMAT_S32_LE;
break;
default:
TRACE_((THIS_FILE, "open_capture: set format SND_PCM_FORMAT_S16_LE"));
format = SND_PCM_FORMAT_S16_LE;
break;
}
snd_pcm_hw_params_set_format (stream->ca_pcm, params, format);
/* Set number of channels */
TRACE_((THIS_FILE, "open_capture: set channels: %d",
param->channel_count));
snd_pcm_hw_params_set_channels (stream->ca_pcm, params,
param->channel_count);
/* Set clock rate */
rate = param->clock_rate;
TRACE_((THIS_FILE, "open_capture: set clock rate: %d", rate));
snd_pcm_hw_params_set_rate_near (stream->ca_pcm, params, &rate, NULL);
TRACE_((THIS_FILE, "open_capture: clock rate set to: %d", rate));
/* Set period size to samples_per_frame frames. */
stream->ca_frames = (snd_pcm_uframes_t) param->samples_per_frame /
param->channel_count;
TRACE_((THIS_FILE, "open_capture: set period size: %d",
stream->ca_frames));
tmp_period_size = stream->ca_frames;
snd_pcm_hw_params_set_period_size_near (stream->ca_pcm, params,
&tmp_period_size, NULL);
TRACE_((THIS_FILE, "open_capture: period size set to: %d",
tmp_period_size));
/* Set the sound device buffer size and latency */
if (param->flags & PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY)
tmp_buf_size = (rate / 1000) * param->input_latency_ms;
else
tmp_buf_size = (rate / 1000) * PJMEDIA_SND_DEFAULT_REC_LATENCY;
snd_pcm_hw_params_set_buffer_size_near (stream->ca_pcm, params,
&tmp_buf_size);
stream->param.input_latency_ms = tmp_buf_size / (rate / 1000);
/* Set our buffer */
stream->ca_buf_size = stream->ca_frames * param->channel_count *
(param->bits_per_sample/8);
stream->ca_buf = (char*) pj_pool_alloc (stream->pool, stream->ca_buf_size);
TRACE_((THIS_FILE, "open_capture: buffer size set to: %d",
(int)tmp_buf_size));
TRACE_((THIS_FILE, "open_capture: capture_latency set to: %d ms",
(int)stream->param.input_latency_ms));
//.........这里部分代码省略.........
开发者ID:waspxyz,项目名称:pjproject-2.7.2,代码行数:101,代码来源:alsa_dev.c
示例8: PJ_DEF
/*
* Create the echo canceller.
*/
PJ_DEF(pj_status_t) pjmedia_echo_create2(pj_pool_t *pool,
unsigned clock_rate,
unsigned channel_count,
unsigned samples_per_frame,
unsigned tail_ms,
unsigned latency_ms,
unsigned options,
pjmedia_echo_state **p_echo )
{
unsigned ptime, lat_cnt;
unsigned delay_buf_opt = 0;
pjmedia_echo_state *ec;
pj_status_t status;
/* Create new pool and instantiate and init the EC */
pool = pj_pool_create(pool->factory, "ec%p", 256, 256, NULL);
ec = PJ_POOL_ZALLOC_T(pool, struct pjmedia_echo_state);
ec->pool = pool;
ec->obj_name = pool->obj_name;
ec->samples_per_frame = samples_per_frame;
ec->frm_buf = (pj_int16_t*)pj_pool_alloc(pool, samples_per_frame<<1);
pj_list_init(&ec->lat_buf);
pj_list_init(&ec->lat_free);
/* Select the backend algorithm */
if (0) {
/* Dummy */
;
#if defined(PJMEDIA_HAS_SPEEX_AEC) && PJMEDIA_HAS_SPEEX_AEC!=0
} else if ((options & PJMEDIA_ECHO_ALGO_MASK) == PJMEDIA_ECHO_SPEEX ||
(options & PJMEDIA_ECHO_ALGO_MASK) == PJMEDIA_ECHO_DEFAULT)
{
ec->op = &speex_aec_op;
#endif
#if defined(PJMEDIA_HAS_INTEL_IPP_AEC) && PJMEDIA_HAS_INTEL_IPP_AEC!=0
} else if ((options & PJMEDIA_ECHO_ALGO_MASK) == PJMEDIA_ECHO_IPP ||
(options & PJMEDIA_ECHO_ALGO_MASK) == PJMEDIA_ECHO_DEFAULT)
{
ec->op = &ipp_aec_op;
#endif
} else {
ec->op = &echo_supp_op;
}
/* Completeness check for EC operation playback and capture, they must
* be implemented both or none.
*/
pj_assert(!ec->op->ec_capture == !ec->op->ec_playback);
PJ_LOG(5,(ec->obj_name, "Creating %s", ec->op->name));
/* Instantiate EC object */
status = (*ec->op->ec_create)(pool, clock_rate, channel_count,
samples_per_frame, tail_ms,
options, &ec->state);
if (status != PJ_SUCCESS) {
pj_pool_release(pool);
return status;
}
/* If EC algo does not have playback and capture callbakcs,
* create latency buffer and delay buffer to handle drift.
*/
if (ec->op->ec_playback && ec->op->ec_capture) {
latency_ms = 0;
} else {
/* Create latency buffers */
ptime = samples_per_frame * 1000 / clock_rate;
if (latency_ms > ptime) {
/* Normalize latency with delaybuf/WSOLA latency */
latency_ms -= PJ_MIN(ptime, PJMEDIA_WSOLA_DELAY_MSEC);
}
if (latency_ms < ptime) {
/* Give at least one frame delay to simplify programming */
latency_ms = ptime;
}
lat_cnt = latency_ms / ptime;
while (lat_cnt--) {
struct frame *frm;
frm = (struct frame*) pj_pool_alloc(pool, (samples_per_frame<<1) +
sizeof(struct frame));
pj_list_push_back(&ec->lat_free, frm);
}
/* Create delay buffer to compensate drifts */
if (options & PJMEDIA_ECHO_USE_SIMPLE_FIFO)
delay_buf_opt |= PJMEDIA_DELAY_BUF_SIMPLE_FIFO;
status = pjmedia_delay_buf_create(ec->pool, ec->obj_name, clock_rate,
samples_per_frame, channel_count,
(PJMEDIA_SOUND_BUFFER_COUNT+1) * ptime,
delay_buf_opt, &ec->delay_buf);
if (status != PJ_SUCCESS) {
pj_pool_release(pool);
//.........这里部分代码省略.........
开发者ID:CloudStyleStudio,项目名称:csip,代码行数:101,代码来源:echo_common.c
示例9: create_play_stream
/* Internal: create playback stream */
static pj_status_t create_play_stream(struct pa_aud_factory *pa,
const pjmedia_aud_param *param,
pjmedia_aud_play_cb play_cb,
void *user_data,
pjmedia_aud_stream **p_snd_strm)
{
pj_pool_t *pool;
pjmedia_aud_dev_index play_id;
struct pa_aud_stream *stream;
PaStreamParameters outputParam;
int sampleFormat;
const PaDeviceInfo *paDevInfo = NULL;
const PaHostApiInfo *paHostApiInfo = NULL;
const PaStreamInfo *paSI;
unsigned paFrames, paRate, paLatency;
PaError err;
PJ_ASSERT_RETURN(play_cb && p_snd_strm, PJ_EINVAL);
play_id = param->play_id;
if (play_id < 0) {
play_id = pa_get_default_output_dev(param->channel_count);
if (play_id < 0) {
/* No such device. */
return PJMEDIA_EAUD_NODEFDEV;
}
}
paDevInfo = Pa_GetDeviceInfo(play_id);
if (!paDevInfo) {
/* Assumed it is "No such device" error. */
return PJMEDIA_EAUD_INVDEV;
}
if (param->bits_per_sample == 8)
sampleFormat = paUInt8;
else if (param->bits_per_sample == 16)
sampleFormat = paInt16;
else if (param->bits_per_sample == 32)
sampleFormat = paInt32;
else
return PJMEDIA_EAUD_SAMPFORMAT;
pool = pj_pool_create(pa->pf, "playstrm", 1024, 1024, NULL);
if (!pool)
return PJ_ENOMEM;
stream = PJ_POOL_ZALLOC_T(pool, struct pa_aud_stream);
stream->pool = pool;
pj_strdup2_with_null(pool, &stream->name, paDevInfo->name);
stream->dir = PJMEDIA_DIR_PLAYBACK;
stream->play_id = play_id;
stream->rec_id = -1;
stream->user_data = user_data;
stream->samples_per_sec = param->clock_rate;
stream->samples_per_frame = param->samples_per_frame;
stream->bytes_per_sample = param->bits_per_sample / 8;
stream->channel_count = param->channel_count;
stream->play_cb = play_cb;
stream->play_buf = (pj_int16_t*)pj_pool_alloc(pool,
stream->samples_per_frame *
stream->bytes_per_sample);
stream->play_buf_count = 0;
pj_bzero(&outputParam, sizeof(outputParam));
outputParam.device = play_id;
outputParam.channelCount = param->channel_count;
outputParam.hostApiSpecificStreamInfo = NULL;
outputParam.sampleFormat = sampleFormat;
if (param->flags & PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY)
outputParam.suggestedLatency=param->output_latency_ms / 1000.0;
else
outputParam.suggestedLatency=PJMEDIA_SND_DEFAULT_PLAY_LATENCY/1000.0;
paHostApiInfo = Pa_GetHostApiInfo(paDevInfo->hostApi);
/* Frames in PortAudio is number of samples in a single channel */
paFrames = param->samples_per_frame / param->channel_count;
err = Pa_OpenStream( &stream->play_strm, NULL, &outputParam,
param->clock_rate, paFrames,
paClipOff, &PaPlayerCallback, stream );
if (err != paNoError) {
pj_pool_release(pool);
return PJMEDIA_AUDIODEV_ERRNO_FROM_PORTAUDIO(err);
}
paSI = Pa_GetStreamInfo(stream->play_strm);
paRate = (unsigned)(paSI->sampleRate);
paLatency = (unsigned)(paSI->outputLatency * 1000);
PJ_LOG(5,(THIS_FILE, "Opened device %d: %s(%s) for playing, sample rate=%d"
", ch=%d, "
"bits=%d, %d samples per frame, latency=%d ms",
play_id, paDevInfo->name, paHostApiInfo->name,
paRate, param->channel_count,
param->bits_per_sample, param->samples_per_frame,
paLatency));
//.........这里部分代码省略.........
开发者ID:Antares84,项目名称:asuswrt-merlin,代码行数:101,代码来源:pa_dev.c
示例10: PJ_DEF
PJ_DEF(pj_status_t) pjmedia_resample_port_create( pj_pool_t *pool,
pjmedia_port *dn_port,
unsigned clock_rate,
unsigned opt,
pjmedia_port **p_port )
{
const pj_str_t name = pj_str("resample");
struct resample_port *rport;
unsigned ptime;
pj_status_t status;
/* Validate arguments. */
PJ_ASSERT_RETURN(pool && dn_port && clock_rate && p_port, PJ_EINVAL);
/* Only supports 16bit samples per frame */
PJ_ASSERT_RETURN(dn_port->info.bits_per_sample == 16, PJMEDIA_ENCBITS);
ptime = dn_port->info.samples_per_frame * 1000 /
dn_port->info.clock_rate;
/* Create and initialize port. */
rport = PJ_POOL_ZALLOC_T(pool, struct resample_port);
PJ_ASSERT_RETURN(rport != NULL, PJ_ENOMEM);
pjmedia_port_info_init(&rport->base.info, &name, SIGNATURE, clock_rate,
dn_port->info.channel_count, BYTES_PER_SAMPLE * 8,
clock_rate * ptime / 1000);
rport->dn_port = dn_port;
rport->options = opt;
/* Create buffers.
* We need separate buffer for get_frame() and put_frame() since
* both functions may run simultaneously.
*/
rport->get_buf = (pj_int16_t*)
pj_pool_alloc(pool, dn_port->info.bytes_per_frame);
PJ_ASSERT_RETURN(rport->get_buf != NULL, PJ_ENOMEM);
rport->put_buf = (pj_int16_t*)
pj_pool_alloc(pool, dn_port->info.bytes_per_frame);
PJ_ASSERT_RETURN(rport->put_buf != NULL, PJ_ENOMEM);
/* Create "get_frame" resample */
status = pjmedia_resample_create(pool,
(opt&PJMEDIA_RESAMPLE_USE_LINEAR)==0,
(opt&PJMEDIA_RESAMPLE_USE_SMALL_FILTER)==0,
dn_port->info.channel_count,
dn_port->info.clock_rate,
rport->base.info.clock_rate,
dn_port->info.samples_per_frame,
&rport->resample_get);
if (status != PJ_SUCCESS)
return status;
/* Create "put_frame" resample */
status = pjmedia_resample_create(pool,
(opt&PJMEDIA_RESAMPLE_USE_LINEAR)==0,
(opt&PJMEDIA_RESAMPLE_USE_SMALL_FILTER)==0,
dn_port->info.channel_count,
rport->base.info.clock_rate,
dn_port->info.clock_rate,
rport->base.info.samples_per_frame,
&rport->resample_put);
/* Media port interface */
rport->base.get_frame = &resample_get_frame;
rport->base.put_frame = &resample_put_frame;
rport->base.on_destroy = &resample_destroy;
/* Done */
*p_port = &rport->base;
return PJ_SUCCESS;
}
开发者ID:Jopie64,项目名称:pjsip,代码行数:78,代码来源:resample_port.c
示例11: test_init
//.........这里部分代码省略.........
/*
* Initialize media endpoint.
* This will implicitly initialize PJMEDIA too.
*/
status = pjmedia_endpt_create(&g_app.cp.factory, NULL, 0, &g_app.endpt);
if (status != PJ_SUCCESS) {
jbsim_perror("Error creating media endpoint", status);
goto on_error;
}
/* Register codecs */
pjmedia_codec_register_audio_codecs(g_app.endpt, NULL);
/* Create the loop transport */
status = pjmedia_transport_loop_create(g_app.endpt, &g_app.loop);
if (status != PJ_SUCCESS) {
jbsim_perror("Error creating loop transport", status);
goto on_error;
}
/* Create transmitter stream */
pj_bzero(&strm_cfg, sizeof(strm_cfg));
strm_cfg.name = "tx";
strm_cfg.dir = PJMEDIA_DIR_ENCODING;
strm_cfg.codec = g_app.cfg.codec;
strm_cfg.ptime = g_app.cfg.tx_ptime;
strm_cfg.dtx = g_app.cfg.tx_dtx;
strm_cfg.plc = PJ_TRUE;
status = stream_init(&strm_cfg, &g_app.tx);
if (status != PJ_SUCCESS)
goto on_error;
/* Create transmitter WAV */
status = pjmedia_wav_player_port_create(g_app.pool,
g_app.cfg.tx_wav_in,
g_app.cfg.tx_ptime,
0,
0,
&g_app.tx_wav);
if (status != PJ_SUCCESS) {
jbsim_perror("Error reading input WAV file", status);
goto on_error;
}
/* Make sure stream and WAV parameters match */
if (PJMEDIA_PIA_SRATE(&g_app.tx_wav->info) != PJMEDIA_PIA_SRATE(&g_app.tx->port->info) ||
PJMEDIA_PIA_CCNT(&g_app.tx_wav->info) != PJMEDIA_PIA_CCNT(&g_app.tx->port->info))
{
jbsim_perror("Error: Input WAV file has different clock rate "
"or number of channels than the codec", PJ_SUCCESS);
goto on_error;
}
/* Create receiver */
pj_bzero(&strm_cfg, sizeof(strm_cfg));
strm_cfg.name = "rx";
strm_cfg.dir = PJMEDIA_DIR_DECODING;
strm_cfg.codec = g_app.cfg.codec;
strm_cfg.ptime = g_app.cfg.rx_ptime;
strm_cfg.dtx = PJ_TRUE;
strm_cfg.plc = g_app.cfg.rx_plc;
status = stream_init(&strm_cfg, &g_app.rx);
if (status != PJ_SUCCESS)
goto on_error;
/* Create receiver WAV */
status = pjmedia_wav_writer_port_create(g_app.pool,
g_app.cfg.rx_wav_out,
PJMEDIA_PIA_SRATE(&g_app.rx->port->info),
PJMEDIA_PIA_CCNT(&g_app.rx->port->info),
PJMEDIA_PIA_SPF(&g_app.rx->port->info),
PJMEDIA_PIA_BITS(&g_app.rx->port->info),
0,
0,
&g_app.rx_wav);
if (status != PJ_SUCCESS) {
jbsim_perror("Error creating output WAV file", status);
goto on_error;
}
/* Frame buffer */
g_app.framebuf = (pj_int16_t*)
pj_pool_alloc(g_app.pool,
MAX(PJMEDIA_PIA_SPF(&g_app.rx->port->info),
PJMEDIA_PIA_SPF(&g_app.tx->port->info)) * sizeof(pj_int16_t));
/* Set the receiver in the loop transport */
pjmedia_transport_loop_disable_rx(g_app.loop, g_app.tx->strm, PJ_TRUE);
/* Done */
return PJ_SUCCESS;
on_error:
test_destroy();
return status;
}
开发者ID:0x0B501E7E,项目名称:pjproject,代码行数:101,代码来源:jbsim.c
示例12: test_init
//.........这里部分代码省略.........
* places as other codecs.
*/
pjmedia_codec_ilbc_init(g_app.endpt, 20);
#endif
#if defined(PJMEDIA_HAS_INTEL_IPP) && PJMEDIA_HAS_INTEL_IPP != 0
pjmedia_codec_ipp_init(g_app.endpt);
#endif
#if defined(PJMEDIA_HAS_OPENCORE_AMRNB_CODEC) && (PJMEDIA_HAS_OPENCORE_AMRNB_CODEC != 0)
pjmedia_codec_opencore_amrnb_init(g_app.endpt);
#endif
#if defined(PJMEDIA_HAS_L16_CODEC) && PJMEDIA_HAS_L16_CODEC != 0
pjmedia_codec_l16_init(g_app.endpt, 0);
#endif
/* Create the loop transport */
status = pjmedia_transport_loop_create(g_app.endpt, &g_app.loop);
if (status != PJ_SUCCESS) {
jbsim_perror("Error creating loop transport", status);
goto on_error;
}
/* Create transmitter stream */
pj_bzero(&strm_cfg, sizeof(strm_cfg));
strm_cfg.name = "tx";
strm_cfg.dir = PJMEDIA_DIR_ENCODING;
strm_cfg.codec = g_app.cfg.codec;
strm_cfg.ptime = g_app.cfg.tx_ptime;
strm_cfg.dtx = g_app.cfg.tx_dtx;
strm_cfg.plc = PJ_TRUE;
status = stream_init(&strm_cfg, &g_app.tx);
if (status != PJ_SUCCESS)
goto on_error;
/* Create transmitter WAV */
status = pjmedia_wav_player_port_create(g_app.pool,
g_app.cfg.tx_wav_in,
g_app.cfg.tx_ptime,
0,
0,
&g_app.tx_wav);
if (status != PJ_SUCCESS) {
jbsim_perror("Error reading input WAV file", status);
goto on_error;
}
/* Make sure stream and WAV parameters match */
if (g_app.tx_wav->info.clock_rate != g_app.tx->port->info.clock_rate ||
g_app.tx_wav->info.channel_count != g_app.tx->port->info.channel_count)
{
jbsim_perror("Error: Input WAV file has different clock rate "
"or number of channels than the codec", PJ_SUCCESS);
goto on_error;
}
/* Create receiver */
pj_bzero(&strm_cfg, sizeof(strm_cfg));
strm_cfg.name = "rx";
strm_cfg.dir = PJMEDIA_DIR_DECODING;
strm_cfg.codec = g_app.cfg.codec;
strm_cfg.ptime = g_app.cfg.rx_ptime;
strm_cfg.dtx = PJ_TRUE;
strm_cfg.plc = g_app.cfg.rx_plc;
status = stream_init(&strm_cfg, &g_app.rx);
if (status != PJ_SUCCESS)
goto on_error;
/* Create receiver WAV */
status = pjmedia_wav_writer_port_create(g_app.pool,
g_app.cfg.rx_wav_out,
g_app.rx->port->info.clock_rate,
g_app.rx->port->info.channel_count,
g_app.rx->port->info.samples_per_frame,
g_app.rx->port->info.bits_per_sample,
0,
0,
&g_app.rx_wav);
if (status != PJ_SUCCESS) {
jbsim_perror("Error creating output WAV file", status);
goto on_error;
}
/* Frame buffer */
g_app.framebuf = (pj_int16_t*)
pj_pool_alloc(g_app.pool,
MAX(g_app.rx->port->info.samples_per_frame,
g_app.tx->port->info.samples_per_frame) * sizeof(pj_int16_t));
/* Set the receiver in the loop transport */
pjmedia_transport_loop_disable_rx(g_app.loop, g_app.tx->strm, PJ_TRUE);
/* Done */
return PJ_SUCCESS;
on_error:
test_destroy();
return status;
}
开发者ID:ddv2005,项目名称:intercom,代码行数:101,代码来源:jbsim.c
示例13: PJ_DEF
/* Public function to parse multipart message bodies into its parts */
PJ_DEF(pjsip_msg_body*) pjsip_multipart_parse(pj_pool_t *pool,
char *buf, pj_size_t len,
const pjsip_media_type *ctype,
unsigned options)
{
pj_str_t boundary, delim;
char *curptr, *endptr;
const pjsip_param *ctype_param;
const pj_str_t STR_BOUNDARY = { "boundary", 8 };
pjsip_msg_body *body = NULL;
PJ_ASSERT_RETURN(pool && buf && len && ctype && !options, NULL);
TRACE_((THIS_FILE, "Started parsing multipart body"));
/* Get the boundary value in the ctype */
boundary.ptr = NULL;
boundary.slen = 0;
ctype_param = pjsip_param_find(&ctype->param, &STR_BOUNDARY);
if (ctype_param) {
boundary = ctype_param->value;
if (boundary.slen>2 && *boundary.ptr=='"') {
/* Remove quote */
boundary.ptr++;
boundary.slen -= 2;
}
TRACE_((THIS_FILE, "Boundary is specified: '%.*s'", (int)boundary.slen,
boundary.ptr));
}
if (!boundary.slen) {
/* Boundary not found or not specified. Try to be clever, get
* the boundary from the body.
*/
char *p=buf, *end=buf+len;
PJ_LOG(4,(THIS_FILE, "Warning: boundary parameter not found or "
"not specified when parsing multipart body"));
/* Find the first "--". This "--" must be right after a CRLF, unless
* it really appears at the start of the buffer.
*/
for (;;) {
while (p!=end && *p!='-') ++p;
if (p!=end && *(p+1)=='-' &&
((p>buf && *(p-1)=='\n') || (p==buf)))
{
p+=2;
break;
} else {
++p;
}
}
if (p==end) {
/* Unable to determine boundary. Maybe this is not a multipart
* message?
*/
PJ_LOG(4,(THIS_FILE, "Error: multipart boundary not specified and"
" unable to calculate from the body"));
return NULL;
}
boundary.ptr = p;
while (p!=end && !pj_isspace(*p)) ++p;
boundary.slen = p - boundary.ptr;
TRACE_((THIS_FILE, "Boundary is calculated: '%.*s'",
(int)boundary.slen, boundary.ptr));
}
/* Build the delimiter:
* delimiter = "--" boundary
*/
delim.slen = boundary.slen+2;
delim.ptr = (char*)pj_pool_alloc(pool, (int)delim.slen);
delim.ptr[0] = '-';
delim.ptr[1] = '-';
pj_memcpy(delim.ptr+2, boundary.ptr, boundary.slen);
/* Start parsing the body, skip until the first delimiter. */
curptr = buf;
endptr = buf + len;
{
pj_str_t body;
body.ptr = buf; body.slen = len;
curptr = pj_strstr(&body, &delim);
if (!curptr)
return NULL;
}
body = pjsip_multipart_create(pool, ctype, &boundary);
for (;;) {
char *start_body, *end_body;
pjsip_multipart_part *part;
/* Eat the boundary */
//.........这里部分代码省略.........
开发者ID:LuLei2013,项目名称:pjproject,代码行数:101,代码来源:sip_multipart.c
示例14: tls_create
/*
* Common function to create TLS transport, called when pending accept() and
* pending connect() complete.
*/
static pj_status_t tls_create( struct tls_listener *listener,
pj_pool_t *pool,
pj_ssl_sock_t *ssock,
pj_bool_t is_server,
const pj_sockaddr_in *local,
const pj_sockaddr_in *remote,
const pj_str_t *remote_name,
struct tls_transport **p_tls)
{
struct tls_transport *tls;
const pj_str_t ka_pkt = PJSIP_TLS_KEEP_ALIVE_DATA;
pj_status_t status;
PJ_ASSERT_RETURN(listener && ssock && local && remote && p_tls, PJ_EINVAL);
if (pool == NULL) {
pool = pjsip_endpt_create_pool(listener->endpt, "tls",
POOL_TP_INIT, POOL_TP_INC);
PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
}
/*
* Create and initialize basic transport structure.
*/
tls = PJ_POOL_ZALLOC_T(pool, struct tls_transport);
tls->is_server = is_server;
tls->verify_server = listener->tls_setting.verify_server;
pj_list_init(&tls->delayed_list);
tls->base.pool = pool;
pj_ansi_snprintf(tls->base.obj_name, PJ_MAX_OBJ_NAME,
(is_server ? "tlss%p" :"tlsc%p"), tls);
status = pj_atomic_create(pool, 0, &tls->base.ref_cnt);
if (status != PJ_SUCCESS) {
goto on_error;
}
status = pj_lock_create_recursive_mutex(pool, "tls", &tls->base.lock);
if (status != PJ_SUCCESS) {
goto on_error;
}
if (remote_name)
pj_strdup(pool, &tls->remote_name, remote_name);
tls->base.key.type = PJSIP_TRANSPORT_TLS;
pj_memcpy(&tls->base.key.rem_addr, remote, sizeof(pj_sockaddr_in));
tls->base.type_name = "tls";
tls->base.flag = pjsip_transport_get_flag_from_type(PJSIP_TRANSPORT_TLS);
tls->base.info = (char*) pj_pool_alloc(pool, 64);
pj_ansi_snprintf(tls->base.info, 64, "TLS to %s:%d",
pj_inet_ntoa(remote->sin_addr),
(int)pj_ntohs(remote->sin_port));
tls->base.addr_len = sizeof(pj_sockaddr_in);
tls->base.dir = is_server? PJSIP_TP_DIR_INCOMING : PJSIP_TP_DIR_OUTGOING;
/* Set initial local address */
if (!pj_sockaddr_has_addr(local)) {
pj_sockaddr_cp(&tls->base.local_addr,
&listener->factory.local_addr);
} else {
pj_sockaddr_cp(&tls->base.local_addr, local);
}
sockaddr_to_host_port(pool, &tls->base.local_name,
(pj_sockaddr_in*)&tls->base.local_addr);
if (tls->remote_name.slen) {
tls->base.remote_name.host = tls->remote_name;
tls->base.remote_name.port = pj_sockaddr_in_get_port(remote);
} else {
sockaddr_to_host_port(pool, &tls->base.remote_name, remote);
}
tls->base.endpt = listener->endpt;
tls->base.tpmgr = listener->tpmgr;
tls->base.send_msg = &tls_send_msg;
tls->base.do_shutdown = &tls_shutdown;
tls->base.destroy = &tls_destroy_transport;
tls->ssock = ssock;
/* Register transport to transport manager */
status = pjsip_transport_register(listener->tpmgr, &tls->base);
if (status != PJ_SUCCESS) {
goto on_error;
}
tls->is_registered = PJ_TRUE;
/* Initialize keep-alive timer */
tls->ka_timer.user_data =
|
请发表评论