本文整理汇总了C++中pj_rand函数 的典型用法代码示例。如果您正苦于以下问题:C++ pj_rand函数的具体用法?C++ pj_rand怎么用?C++ pj_rand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pj_rand函数 的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: PJ_DEF
PJ_DEF(char*) pj_create_random_string(char *str, pj_size_t len)
{
unsigned i;
char *p = str;
PJ_CHECK_STACK();
for (i=0; i<len/8; ++i) {
pj_uint32_t val = pj_rand();
pj_val_to_hex_digit( (val & 0xFF000000) >> 24, p+0 );
pj_val_to_hex_digit( (val & 0x00FF0000) >> 16, p+2 );
pj_val_to_hex_digit( (val & 0x0000FF00) >> 8, p+4 );
pj_val_to_hex_digit( (val & 0x000000FF) >> 0, p+6 );
p += 8;
}
for (i=i * 8; i<len; ++i) {
*p++ = pj_hex_digits[ pj_rand() & 0x0F ];
}
return str;
}
开发者ID:Jopie64, 项目名称:pjsip, 代码行数:20, 代码来源:string.c
示例2: create_stream
/*
* Create stream based on the codec, dir, remote address, etc.
*/
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) {
app_perror(THIS_FILE, "Error creating stream", status);
pjmedia_transport_udp_close(transport);
return status;
}
return PJ_SUCCESS;
}
开发者ID:tibastral, 项目名称:symphonie, 代码行数:55, 代码来源:streamutil.c
示例3: plc_put_frame
static pj_status_t plc_put_frame( pjmedia_port *this_port,
const pjmedia_frame *frame)
{
pj_status_t status;
int i;
struct plc_port *plcp = (struct plc_port*)this_port;
PJ_ASSERT_RETURN(this_port->info.signature == SIGNATURE, PJ_EINVAL);
PJ_LOG(6, (THIS_FILE, "packet: sz=%d ts=%llu",
frame->size/sizeof(pj_uint16_t), frame->timestamp.u64));
if (frame->type == PJMEDIA_FRAME_TYPE_NONE ) {
em_plc_mode mode = plcp->frame.type == PJMEDIA_FRAME_TYPE_NONE ? \
EM_PLC_EMPTY : plcp->plc_mode;
switch (mode) {
case EM_PLC_SMART:
for (i=0; i<plcp->fpp; i++){
status = plcp->codec->op->recover(plcp->codec, BUF_SIZE, &plcp->frame);
plcp->frame.timestamp.u64 = 0;
if (status != PJ_SUCCESS) return status;
status = pjmedia_port_put_frame(plcp->dn_port, &plcp->frame);
if (status != PJ_SUCCESS) return status;
}
break;
case EM_PLC_REPEAT:
for (i=0; i<plcp->fpp; i++){
plcp->frame.timestamp.u64 = 0;
status = pjmedia_port_put_frame(plcp->dn_port, &plcp->frame);
if (status != PJ_SUCCESS) return status;
}
break;
case EM_PLC_NOISE:
for (i=0; i<plcp->fpp; i++){
int j=0;
plcp->frame.size = plcp->dn_port->info.bytes_per_frame;
plcp->frame.type = PJMEDIA_FRAME_TYPE_AUDIO;
plcp->frame.timestamp.u64 = 0;
for (j=0; j<plcp->frame.size; j++)
((char*)plcp->frame.buf)[j] = ((char)pj_rand()) >> 5;
status = pjmedia_port_put_frame(plcp->dn_port, &plcp->frame);
if (status != PJ_SUCCESS) return status;
}
default:
for (i=0; i<plcp->fpp; i++){
plcp->frame.size = plcp->dn_port->info.bytes_per_frame;
plcp->frame.type = PJMEDIA_FRAME_TYPE_AUDIO;
plcp->frame.timestamp.u64 = 0;
pj_bzero(plcp->frame.buf, plcp->frame.size);
status = pjmedia_port_put_frame(plcp->dn_port, &plcp->frame);
}
}
plcp->stats.lost++;
} else {
开发者ID:froggatt, 项目名称:network-emulator, 代码行数:52, 代码来源:plc_port.c
示例4: do_test
int do_test(void *user) {
int i;
pj_pool_t *pool = (pj_pool_t *)user;
opool_init(&opool, 10, strlen(s)+10, pool);
for (i = 0; i < 100; i++) {
opool_item_t *p_item = opool_get(&opool);
pj_memcpy(p_item->data, s, strlen(s));
printf("%d: %s\n", i, p_item->data);
pj_thread_sleep(pj_rand()%100);
opool_free(&opool, p_item);
}
return 0;
}
开发者ID:mocidis, 项目名称:object-pool, 代码行数:13, 代码来源:main.c
示例5: transport_send_rtp
/* Called by application to send RTP packet */
static pj_status_t transport_send_rtp( pjmedia_transport *tp,
const void *pkt,
pj_size_t size)
{
struct transport_udp *udp = (struct transport_udp*)tp;
pj_ssize_t sent;
unsigned id;
struct pending_write *pw;
pj_status_t status;
/* Must be attached */
PJ_ASSERT_RETURN(udp->attached, PJ_EINVALIDOP);
/* Check that the size is supported */
PJ_ASSERT_RETURN(size <= RTP_LEN, PJ_ETOOBIG);
/* Simulate packet lost on TX direction */
if (udp->tx_drop_pct) {
if ((pj_rand() % 100) <= (int)udp->tx_drop_pct) {
PJ_LOG(5,(udp->base.name,
"TX RTP packet dropped because of pkt lost "
"simulation"));
return PJ_SUCCESS;
}
}
id = udp->rtp_write_op_id;
pw = &udp->rtp_pending_write[id];
/* We need to copy packet to our buffer because when the
* operation is pending, caller might write something else
* to the original buffer.
*/
pj_memcpy(pw->buffer, pkt, size);
sent = size;
status = pj_ioqueue_sendto( udp->rtp_key,
&udp->rtp_pending_write[id].op_key,
pw->buffer, &sent, 0,
&udp->rem_rtp_addr,
sizeof(pj_sockaddr_in));
udp->rtp_write_op_id = (udp->rtp_write_op_id + 1) %
PJ_ARRAY_SIZE(udp->rtp_pending_write);
if (status==PJ_SUCCESS || status==PJ_EPENDING)
return PJ_SUCCESS;
return status;
}
开发者ID:svn2github, 项目名称:pjproject, 代码行数:52, 代码来源:transport_udp.c
示例6: transport_send_rtp
/* Called by application to send RTP packet */
static pj_status_t transport_send_rtp( pjmedia_transport *tp,
const void *pkt,
pj_size_t size)
{
struct transport_loop *loop = (struct transport_loop*)tp;
unsigned i;
/* Simulate packet lost on TX direction */
if (loop->tx_drop_pct) {
if ((pj_rand() % 100) <= (int)loop->tx_drop_pct) {
PJ_LOG(5,(loop->base.name,
"TX RTP packet dropped because of pkt lost "
"simulation"));
return PJ_SUCCESS;
}
}
/* Simulate packet lost on RX direction */
if (loop->rx_drop_pct) {
if ((pj_rand() % 100) <= (int)loop->rx_drop_pct) {
PJ_LOG(5,(loop->base.name,
"RX RTP packet dropped because of pkt lost "
"simulation"));
return PJ_SUCCESS;
}
}
/* Distribute to users */
for (i=0; i<loop->user_cnt; ++i) {
if (!loop->users[i].rx_disabled && loop->users[i].rtp_cb)
(*loop->users[i].rtp_cb)(loop->users[i].user_data, (void*)pkt,
size);
}
return PJ_SUCCESS;
}
开发者ID:LuLei2013, 项目名称:pjproject, 代码行数:37, 代码来源:transport_loop.c
示例7: rand_test
/*
* rand_test(), simply generates COUNT number of random number and
* check that there's no duplicate numbers.
*/
int rand_test(void)
{
int i;
for (i=0; i<COUNT; ++i) {
int j;
values[i] = pj_rand();
for (j=0; j<i; ++j) {
if (values[i] == values[j]) {
PJ_LOG(3,("test", "error: duplicate value %d at %d-th index",
values[i], i));
return -10;
}
}
}
return 0;
}
开发者ID:avble, 项目名称:natClientEx, 代码行数:23, 代码来源:rand.c
示例8: pjsip_messaging_create_session
pjsip_messaging_create_session( pjsip_endpoint *endpt, const pj_str_t *param_from,
const pj_str_t *param_to )
{
pj_pool_t *pool;
pjsip_messaging_session *ses;
pj_str_t tmp, to;
pool = pjsip_endpt_create_pool(endpt, "imsess", 1024, 1024);
if (!pool)
return NULL;
ses = pj_pool_calloc(pool, 1, sizeof(pjsip_messaging_session));
ses->pool = pool;
ses->endpt = endpt;
ses->call_id = pjsip_cid_hdr_create(pool);
pj_create_unique_string(pool, &ses->call_id->id);
ses->cseq = pjsip_cseq_hdr_create(pool);
ses->cseq->cseq = pj_rand();
ses->cseq->method = message_method;
ses->from = pjsip_from_hdr_create(pool);
pj_strdup_with_null(pool, &tmp, param_from);
ses->from->uri = pjsip_parse_uri(pool, tmp.ptr, tmp.slen, PJSIP_PARSE_URI_AS_NAMEADDR);
if (ses->from->uri == NULL) {
pjsip_endpt_destroy_pool(endpt, pool);
return NULL;
}
pj_create_unique_string(pool, &ses->from->tag);
ses->to = pjsip_to_hdr_create(pool);
pj_strdup_with_null(pool, &to, param_from);
ses->to->uri = pjsip_parse_uri(pool, to.ptr, to.slen, PJSIP_PARSE_URI_AS_NAMEADDR);
if (ses->to->uri == NULL) {
pjsip_endpt_destroy_pool(endpt, pool);
return NULL;
}
PJ_LOG(4,(THIS_FILE, "IM session created: recipient=%s", to.ptr));
return ses;
}
开发者ID:svn2github, 项目名称:pjproject, 代码行数:42, 代码来源:messaging.c
示例9: test_timer_heap
static int test_timer_heap(void)
{
int i, j;
pj_timer_entry *entry;
pj_pool_t *pool;
pj_timer_heap_t *timer;
pj_time_val delay;
pj_status_t rc; int err=0;
unsigned size, count;
size = pj_timer_heap_mem_size(MAX_COUNT)+MAX_COUNT*sizeof(pj_timer_entry);
pool = pj_pool_create( mem, NULL, size, 4000, NULL);
if (!pool) {
PJ_LOG(3,("test", "...error: unable to create pool of %u bytes",
size));
return -10;
}
entry = (pj_timer_entry*)pj_pool_calloc(pool, MAX_COUNT, sizeof(*entry));
if (!entry)
return -20;
for (i=0; i<MAX_COUNT; ++i) {
entry[i].cb = &timer_callback;
}
rc = pj_timer_heap_create(pool, MAX_COUNT, &timer);
if (rc != PJ_SUCCESS) {
app_perror("...error: unable to create timer heap", rc);
return -30;
}
count = MIN_COUNT;
for (i=0; i<LOOP; ++i) {
int early = 0;
int done=0;
int cancelled=0;
int rc;
pj_timestamp t1, t2, t_sched, t_cancel, t_poll;
pj_time_val now, expire;
pj_gettimeofday(&now);
pj_srand(now.sec);
t_sched.u32.lo = t_cancel.u32.lo = t_poll.u32.lo = 0;
// Register timers
for (j=0; j<(int)count; ++j) {
delay.sec = pj_rand() % DELAY;
delay.msec = pj_rand() % 1000;
// Schedule timer
pj_get_timestamp(&t1);
rc = pj_timer_heap_schedule(timer, &entry[j], &delay);
if (rc != 0)
return -40;
pj_get_timestamp(&t2);
t_sched.u32.lo += (t2.u32.lo - t1.u32.lo);
// Poll timers.
pj_get_timestamp(&t1);
rc = pj_timer_heap_poll(timer, NULL);
pj_get_timestamp(&t2);
if (rc > 0) {
t_poll.u32.lo += (t2.u32.lo - t1.u32.lo);
early += rc;
}
}
// Set the time where all timers should finish
pj_gettimeofday(&expire);
delay.sec = DELAY;
delay.msec = 0;
PJ_TIME_VAL_ADD(expire, delay);
// Wait unfil all timers finish, cancel some of them.
do {
int index = pj_rand() % count;
pj_get_timestamp(&t1);
rc = pj_timer_heap_cancel(timer, &entry[index]);
pj_get_timestamp(&t2);
if (rc > 0) {
cancelled += rc;
t_cancel.u32.lo += (t2.u32.lo - t1.u32.lo);
}
pj_gettimeofday(&now);
pj_get_timestamp(&t1);
#if defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0
/* On Symbian, we must use OS poll (Active Scheduler poll) since
* timer is implemented using Active Object.
*/
rc = 0;
while (pj_symbianos_poll(-1, 0))
++rc;
#else
rc = pj_timer_heap_poll(timer, NULL);
#endif
pj_get_timestamp(&t2);
if (rc > 0) {
//.........这里部分代码省略.........
开发者ID:carlosdelfino, 项目名称:WorkshopTelefoniaAutomacao, 代码行数:101, 代码来源:timer.c
示例10: perf_test
//.........这里部分代码省略.........
pj_sockaddr_cp(&listen_addr, &info.local_addr);
pj_sockaddr_print((pj_sockaddr_t*)&listen_addr, buf, sizeof(buf), 1);
PJ_LOG(3, ("", "...Listener ready at %s", buf));
}
/* CLIENTS */
clients_num = clients;
param.timeout.sec = 0;
param.timeout.msec = 0;
/* Init random seed */
{
pj_time_val now;
pj_gettimeofday(&now);
pj_srand((unsigned)now.sec);
}
/* Allocate SSL socket pointers and test state */
ssock_cli = pj_pool_calloc(pool, clients, sizeof(pj_ssl_sock_t*));
state_cli = pj_pool_calloc(pool, clients, sizeof(struct test_state));
/* Get start timestamp */
pj_gettimeofday(&start);
/* Setup clients */
for (i = 0; i < clients; ++i) {
param.user_data = &state_cli[i];
state_cli[i].pool = pool;
state_cli[i].check_echo = PJ_TRUE;
state_cli[i].send_str_len = (pj_rand() % 5 + 1) * 1024 + pj_rand() % 1024;
state_cli[i].send_str = pj_pool_alloc(pool, state_cli[i].send_str_len);
{
unsigned j;
for (j = 0; j < state_cli[i].send_str_len; ++j)
state_cli[i].send_str[j] = (char)(pj_rand() % 256);
}
status = pj_ssl_sock_create(pool, ¶m, &ssock_cli[i]);
if (status != PJ_SUCCESS) {
app_perror("...ERROR pj_ssl_sock_create()", status);
cli_err++;
clients_num--;
continue;
}
status = pj_ssl_sock_start_connect(ssock_cli[i], pool, &addr, &listen_addr, pj_sockaddr_get_len(&addr));
if (status == PJ_SUCCESS) {
ssl_on_connect_complete(ssock_cli[i], PJ_SUCCESS);
} else if (status == PJ_EPENDING) {
status = PJ_SUCCESS;
} else {
app_perror("...ERROR pj_ssl_sock_create()", status);
pj_ssl_sock_close(ssock_cli[i]);
ssock_cli[i] = NULL;
clients_num--;
cli_err++;
continue;
}
/* Give chance to server to accept this client */
{
unsigned n = 5;
开发者ID:kaaustubh, 项目名称:pjsip, 代码行数:67, 代码来源:ssl_sock.c
示例11: stun_destroy_test
static int stun_destroy_test(void)
{
enum { LOOP = 500 };
struct stun_test_session test_sess;
pj_sockaddr bind_addr;
int addr_len;
pj_caching_pool cp;
pj_pool_t *pool;
unsigned i;
pj_status_t status;
int rc = 0;
PJ_LOG(3,(THIS_FILE, " STUN destroy concurrency test"));
pj_bzero(&test_sess, sizeof(test_sess));
pj_caching_pool_init(&cp, NULL, 0);
pool = pj_pool_create(&cp.factory, "testsess", 512, 512, NULL);
pj_stun_config_init(&test_sess.stun_cfg, &cp.factory, 0, NULL, NULL);
status = pj_timer_heap_create(pool, 1023, &test_sess.stun_cfg.timer_heap);
pj_assert(status == PJ_SUCCESS);
status = pj_lock_create_recursive_mutex(pool, NULL, &test_sess.lock);
pj_assert(status == PJ_SUCCESS);
pj_timer_heap_set_lock(test_sess.stun_cfg.timer_heap, test_sess.lock, PJ_TRUE);
pj_assert(status == PJ_SUCCESS);
status = pj_ioqueue_create(pool, 512, &test_sess.stun_cfg.ioqueue);
pj_assert(status == PJ_SUCCESS);
pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &test_sess.server_sock);
pj_sockaddr_init(pj_AF_INET(), &bind_addr, NULL, 0);
status = pj_sock_bind(test_sess.server_sock, &bind_addr, pj_sockaddr_get_len(&bind_addr));
pj_assert(status == PJ_SUCCESS);
addr_len = sizeof(bind_addr);
status = pj_sock_getsockname(test_sess.server_sock, &bind_addr, &addr_len);
pj_assert(status == PJ_SUCCESS);
test_sess.server_port = pj_sockaddr_get_port(&bind_addr);
status = pj_event_create(pool, NULL, PJ_TRUE, PJ_FALSE, &test_sess.server_event);
pj_assert(status == PJ_SUCCESS);
for (i=0; i<SERVER_THREAD_CNT; ++i) {
status = pj_thread_create(pool, NULL,
&server_thread_proc, &test_sess,
0, 0, &test_sess.server_threads[i]);
pj_assert(status == PJ_SUCCESS);
}
for (i=0; i<WORKER_THREAD_CNT; ++i) {
status = pj_thread_create(pool, NULL,
&worker_thread_proc, &test_sess,
0, 0, &test_sess.worker_threads[i]);
pj_assert(status == PJ_SUCCESS);
}
/* Test 1: Main thread calls destroy while callback is processing response */
PJ_LOG(3,(THIS_FILE, " Destroy in main thread while callback is running"));
for (i=0; i<LOOP; ++i) {
int sleep = pj_rand() % 5;
PJ_LOG(3,(THIS_FILE, " Try %-3d of %d", i+1, LOOP));
/* Test 1: destroy at the same time when receiving response */
pj_bzero(&test_sess.param, sizeof(test_sess.param));
test_sess.param.client_sleep_after_start = 20;
test_sess.param.client_sleep_before_destroy = sleep;
test_sess.param.server_wait_for_event = PJ_TRUE;
stun_destroy_test_session(&test_sess);
PJ_LOG(3,(THIS_FILE,
" stun test a: sleep delay:%d: clients with response: %d",
sleep, test_sess.param.client_got_response));
/* Test 2: destroy at the same time with STUN retransmit timer */
test_sess.param.server_drop_request = PJ_TRUE;
test_sess.param.client_sleep_after_start = 0;
test_sess.param.client_sleep_before_destroy = PJ_STUN_RTO_VALUE;
test_sess.param.server_wait_for_event = PJ_FALSE;
stun_destroy_test_session(&test_sess);
PJ_LOG(3,(THIS_FILE, " stun test b: retransmit concurrency"));
/* Test 3: destroy at the same time with receiving response
* AND STUN retransmit timer */
test_sess.param.client_got_response = 0;
test_sess.param.server_drop_request = PJ_FALSE;
test_sess.param.client_sleep_after_start = PJ_STUN_RTO_VALUE;
test_sess.param.client_sleep_before_destroy = 0;
test_sess.param.server_wait_for_event = PJ_TRUE;
stun_destroy_test_session(&test_sess);
PJ_LOG(3,(THIS_FILE,
" stun test c: clients with response: %d",
test_sess.param.client_got_response));
pj_thread_sleep(10);
//.........这里部分代码省略.........
开发者ID:AmoebaLabs, 项目名称:pjsip, 代码行数:101, 代码来源:concur_test.c
示例12: PJ_DEF
PJ_DEF(pj_status_t) pjstun_get_mapped_addr( pj_pool_factory *pf,
int sock_cnt, pj_sock_t sock[],
const pj_str_t *srv1, int port1,
const pj_str_t *srv2, int port2,
pj_sockaddr_in mapped_addr[])
{
unsigned srv_cnt;
pj_sockaddr_in srv_addr[2];
int i, j, send_cnt = 0, nfds;
pj_pool_t *pool;
struct query_rec {
struct {
pj_uint32_t mapped_addr;
pj_uint32_t mapped_port;
} srv[2];
} *rec;
void *out_msg;
pj_size_t out_msg_len;
int wait_resp = 0;
pj_status_t status;
PJ_CHECK_STACK();
TRACE_((THIS_FILE, "Entering pjstun_get_mapped_addr()"));
/* Create pool. */
pool = pj_pool_create(pf, "stun%p", 400, 400, NULL);
if (!pool)
return PJ_ENOMEM;
/* Allocate client records */
rec = (struct query_rec*) pj_pool_calloc(pool, sock_cnt, sizeof(*rec));
if (!rec) {
status = PJ_ENOMEM;
goto on_error;
}
TRACE_((THIS_FILE, " Memory allocated."));
/* Create the outgoing BIND REQUEST message template */
status = pjstun_create_bind_req( pool, &out_msg, &out_msg_len,
pj_rand(), pj_rand());
if (status != PJ_SUCCESS)
goto on_error;
TRACE_((THIS_FILE, " Binding request created."));
/* Resolve servers. */
status = pj_sockaddr_in_init(&srv_addr[0], srv1, (pj_uint16_t)port1);
if (status != PJ_SUCCESS)
goto on_error;
srv_cnt = 1;
if (srv2 && port2) {
status = pj_sockaddr_in_init(&srv_addr[1], srv2, (pj_uint16_t)port2);
if (status != PJ_SUCCESS)
goto on_error;
if (srv_addr[1].sin_addr.s_addr != srv_addr[0].sin_addr.s_addr &&
srv_addr[1].sin_port != srv_addr[0].sin_port)
{
srv_cnt++;
}
}
TRACE_((THIS_FILE, " Server initialized, using %d server(s)", srv_cnt));
/* Init mapped addresses to zero */
pj_memset(mapped_addr, 0, sock_cnt * sizeof(pj_sockaddr_in));
/* We need these many responses */
wait_resp = sock_cnt * srv_cnt;
TRACE_((THIS_FILE, " Done initialization."));
#if defined(PJ_SELECT_NEEDS_NFDS) && PJ_SELECT_NEEDS_NFDS!=0
nfds = -1;
for (i=0; i<sock_cnt; ++i) {
if (sock[i] > nfds) {
nfds = sock[i];
}
}
#else
nfds = FD_SETSIZE-1;
#endif
/* Main retransmission loop. */
for (send_cnt=0; send_cnt<MAX_REQUEST; ++send_cnt) {
pj_time_val next_tx, now;
pj_fd_set_t r;
int select_rc;
PJ_FD_ZERO(&r);
/* Send messages to servers that has not given us response. */
for (i=0; i<sock_cnt && status==PJ_SUCCESS; ++i) {
for (j=0; j<srv_cnt && status==PJ_SUCCESS; ++j) {
pjstun_msg_hdr *msg_hdr = (pjstun_msg_hdr*) out_msg;
//.........这里部分代码省略.........
开发者ID:Antares84, 项目名称:asuswrt-merlin, 代码行数:101, 代码来源:stun_simple_client.c
示例13: timestamp_test
int timestamp_test(void)
{
enum { CONSECUTIVE_LOOP = 100 };
volatile unsigned i;
pj_timestamp freq, t1, t2;
pj_time_val tv1, tv2;
unsigned elapsed;
pj_status_t rc;
PJ_LOG(3,(THIS_FILE, "...Testing timestamp (high res time)"));
/* Get and display timestamp frequency. */
if ((rc=pj_get_timestamp_freq(&freq)) != PJ_SUCCESS) {
app_perror("...ERROR: get timestamp freq", rc);
return -1000;
}
PJ_LOG(3,(THIS_FILE, "....frequency: hiword=%lu loword=%lu",
freq.u32.hi, freq.u32.lo));
PJ_LOG(3,(THIS_FILE, "...checking if time can run backwards (pls wait).."));
/*
* Check if consecutive readings should yield timestamp value
* that is bigger than previous value.
* First we get the first timestamp.
*/
rc = pj_get_timestamp(&t1);
if (rc != PJ_SUCCESS) {
app_perror("...ERROR: pj_get_timestamp", rc);
return -1001;
}
rc = pj_gettimeofday(&tv1);
if (rc != PJ_SUCCESS) {
app_perror("...ERROR: pj_gettimeofday", rc);
return -1002;
}
for (i=0; i<CONSECUTIVE_LOOP; ++i) {
pj_thread_sleep(pj_rand() % 100);
rc = pj_get_timestamp(&t2);
if (rc != PJ_SUCCESS) {
app_perror("...ERROR: pj_get_timestamp", rc);
return -1003;
}
rc = pj_gettimeofday(&tv2);
if (rc != PJ_SUCCESS) {
app_perror("...ERROR: pj_gettimeofday", rc);
return -1004;
}
/* compare t2 with t1, expecting t2 >= t1. */
if (t2.u32.hi < t1.u32.hi ||
(t2.u32.hi == t1.u32.hi && t2.u32.lo < t1.u32.lo))
{
PJ_LOG(3,(THIS_FILE, "...ERROR: timestamp run backwards!"));
return -1005;
}
/* compare tv2 with tv1, expecting tv2 >= tv1. */
if (PJ_TIME_VAL_LT(tv2, tv1)) {
PJ_LOG(3,(THIS_FILE, "...ERROR: time run backwards!"));
return -1006;
}
}
/*
* Simple test to time some loop.
*/
PJ_LOG(3,(THIS_FILE, "....testing simple 1000000 loop"));
/* Mark start time. */
if ((rc=pj_get_timestamp(&t1)) != PJ_SUCCESS) {
app_perror("....error: cat't get timestamp", rc);
return -1010;
}
/* Loop.. */
for (i=0; i<1000000; ++i) {
/* Try to do something so that smart compilers wont
* remove this silly loop.
*/
null_func();
}
pj_thread_sleep(0);
/* Mark end time. */
pj_get_timestamp(&t2);
/* Get elapsed time in usec. */
elapsed = pj_elapsed_usec(&t1, &t2);
PJ_LOG(3,(THIS_FILE, "....elapsed: %u usec", (unsigned)elapsed));
/* See if elapsed time is "reasonable".
* This should be good even on 50Mhz embedded powerpc.
*/
if (elapsed < 1 || elapsed > 1000000) {
//.........这里部分代码省略.........
开发者ID:tibastral, 项目名称:symphonie, 代码行数:101, 代码来源:timestamp.c
示例14: on_rx_rtp
/* Notification from ioqueue about incoming RTP packet */
static void on_rx_rtp( pj_ioqueue_key_t *key,
pj_ioqueue_op_key_t *op_key,
pj_ssize_t bytes_read)
{
struct transport_udp *udp;
pj_status_t status;
PJ_UNUSED_ARG(op_key);
udp = pj_ioqueue_get_user_data(key);
do {
void (*cb)(void*,const void*,pj_ssize_t);
void *user_data;
cb = udp->rtp_cb;
user_data = udp->user_data;
/* Simulate packet lost on RX direction */
if (udp->rx_drop_pct) {
if ((pj_rand() % 100) <= (int)udp->rx_drop_pct) {
PJ_LOG(5,(udp->base.name,
"RX RTP packet dropped because of pkt lost "
"simulation"));
goto read_next_packet;
}
}
if (udp->attached && cb)
(*cb)(user_data, udp->rtp_pkt, bytes_read);
/* See if source address of RTP packet is different than the
* configured address, and switch RTP remote address to
* source packet address after several consecutive packets
* have been received.
*/
if (bytes_read>0 &&
(udp->options & PJMEDIA_UDP_NO_SRC_ADDR_CHECKING)==0)
{
if ((udp->rem_rtp_addr.sin_addr.s_addr !=
udp->rtp_src_addr.sin_addr.s_addr) ||
(udp->rem_rtp_addr.sin_port !=
udp->rtp_src_addr.sin_port))
{
udp->rtp_src_cnt++;
if (udp->rtp_src_cnt >= PJMEDIA_RTP_NAT_PROBATION_CNT) {
/* Set remote RTP address to source address */
udp->rem_rtp_addr = udp->rtp_src_addr;
/* Reset counter */
udp->rtp_src_cnt = 0;
PJ_LOG(4,(udp->base.name,
"Remote RTP address switched to %s:%d",
pj_inet_ntoa(udp->rtp_src_addr.sin_addr),
pj_ntohs(udp->rtp_src_addr.sin_port)));
/* Also update remote RTCP address if actual RTCP source
* address is not heard yet.
*/
if (udp->rtcp_src_addr.sin_addr.s_addr == 0) {
pj_uint16_t port;
pj_memcpy(&udp->rem_rtcp_addr, &udp->rem_rtp_addr,
sizeof(pj_sockaddr_in));
port = (pj_uint16_t)
(pj_ntohs(udp->rem_rtp_addr.sin_port)+1);
udp->rem_rtcp_addr.sin_port = pj_htons(port);
pj_memcpy(&udp->rtcp_src_addr, &udp->rem_rtcp_addr,
sizeof(pj_sockaddr_in));
PJ_LOG(4,(udp->base.name,
"Remote RTCP address switched to %s:%d",
pj_inet_ntoa(udp->rtcp_src_addr.sin_addr),
pj_ntohs(udp->rtcp_src_addr.sin_port)));
}
}
}
}
read_next_packet:
bytes_read = sizeof(udp->rtp_pkt);
udp->rtp_addrlen = sizeof(pj_sockaddr_in);
status = pj_ioqueue_recvfrom(udp->rtp_key, &udp->rtp_read_op,
udp->rtp_pkt, &bytes_read, 0,
&udp->rtp_src_addr,
&udp->rtp_addrlen);
if (status != PJ_EPENDING && status != PJ_SUCCESS)
bytes_read = -status;
} while (status != PJ_EPENDING);
}
开发者ID:svn2github, 项目名称:pjproject, 代码行数:99, 代码来源:transport_udp.c
示例15: create_stream
/*
* Create stream based on the codec, dir, remote address, etc.
*/
static pj_status_t create_stream( pj_pool_t *pool,
pjmedia_endpt *med_endpt,
const pjmedia_vid_codec_info *codec_info,
pjmedia_vid_codec_param *codec_param,
pjmedia_dir dir,
pj_int8_t rx_pt,
pj_int8_t tx_pt,
pj_uint16_t local_port,
const pj_sockaddr_in *rem_addr,
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
pj_bool_t use_srtp,
const pj_str_t *crypto_suite,
const pj_str_t *srtp_tx_key,
const pj_str_t *srtp_rx_key,
#endif
pjmedia_vid_stream **p_stream )
{
pjmedia_vid_stream_info info;
pjmedia_transport *transport = NULL;
pj_status_t status;
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
pjmedia_transport *srtp_tp = NULL;
#endif
/* Reset stream info. */
pj_bzero(&info, sizeof(info));
/* Initialize stream info formats */
info.type = PJMEDIA_TYPE_VIDEO;
info.dir = dir;
info.codec_info = *codec_info;
info.tx_pt = (tx_pt == -1)? codec_info->pt : tx_pt;
info.rx_pt = (rx_pt == -1)? codec_info->pt : rx_pt;
info.ssrc = pj_rand();
if (codec_param)
info.codec_param = codec_param;
/* Copy remote address */
pj_memcpy(&info.rem_addr, rem_addr, sizeof(pj_sockaddr_in));
/* If remote address is not set, set to an arbitrary address
* (otherwise stream will assert).
*/
if (info.rem_addr.addr.sa_family == 0) {
const pj_str_t addr = pj_str("127.0.0.1");
pj_sockaddr_in_init(&info.rem_addr.ipv4, &addr, 0);
}
/* Create media transport */
status = pjmedia_transport_udp_create(med_endpt, NULL, local_port,
0, &transport);
if (status != PJ_SUCCESS)
return status;
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
/* Check if SRTP enabled */
if (use_srtp) {
pjmedia_srtp_crypto tx_plc, rx_plc;
status = pjmedia_transport_srtp_create(med_endpt, transport,
NULL, &srtp_tp);
if (status != PJ_SUCCESS)
return status;
pj_bzero(&tx_plc, sizeof(pjmedia_srtp_crypto));
pj_bzero(&rx_plc, sizeof(pjmedia_srtp_crypto));
tx_plc.key = *srtp_tx_key;
tx_plc.name = *crypto_suite;
rx_plc.key = *srtp_rx_key;
rx_plc.name = *crypto_suite;
status = pjmedia_transport_srtp_start(srtp_tp, &tx_plc, &rx_plc);
if (status != PJ_SUCCESS)
return status;
transport = srtp_tp;
}
#endif
/* Now that the stream info is initialized, we can create the
* stream.
*/
status = pjmedia_vid_stream_create( med_endpt, pool, &info,
transport,
NULL, p_stream);
if (status != PJ_SUCCESS) {
app_perror(THIS_FILE, "Error creating stream", status);
pjmedia_transport_close(transport);
return status;
}
return PJ_SUCCESS;
}
开发者ID:RockHardJim, 项目名称:idphone, 代码行数:100, 代码来源:vid_streamutil.c
示例16: PJ_DEF
//.........这里部分代码省略.........
return PJ_EAFNOTSUP;
/* Media direction: */
if (local_m->desc.port == 0 ||
pj_sockaddr_has_addr(&local_addr)==PJ_FALSE ||
pj_sockaddr_has_addr(&si->rem_addr)==PJ_FALSE ||
pjmedia_sdp_media_find_attr(local_m, &STR_INACTIVE, NULL)!=NULL)
{
/* Inactive stream. */
si->dir = PJMEDIA_DIR_NONE;
} else if (pjmedia_sdp_media_find_attr(local_m, &STR_SENDONLY, NULL)!=NULL) {
/* Send only stream. */
si->dir = PJMEDIA_DIR_ENCODING;
} else if (pjmedia_sdp_media_find_attr(local_m, &STR_RECVONLY, NULL)!=NULL) {
/* Recv only stream. */
si->dir = PJMEDIA_DIR_DECODING;
} else {
/* Send and receive stream. */
si->dir = PJMEDIA_DIR_ENCODING_DECODING;
}
/* No need to do anything else if stream is rejected */
if (local_m->desc.port == 0) {
return PJ_SUCCESS;
}
/* If "rtcp" attribute is present in the SDP, set the RTCP address
* from that attribute. Otherwise, calculate from RTP address.
*/
attr = pjmedia_sdp_attr_find2(rem_m->attr_count, rem_m->attr,
"rtcp", NULL);
if (attr) {
pjmedia_sdp_rtcp_attr rtcp;
status = pjmedia_sdp_attr_get_rtcp(attr, &rtcp);
if (status == PJ_SUCCESS) {
if (rtcp.addr.slen) {
status = pj_sockaddr_init(rem_af, &si->rem_rtcp, &rtcp.addr,
(pj_uint16_t)rtcp.port);
} else {
pj_sockaddr_init(rem_af, &si->rem_rtcp, NULL,
(pj_uint16_t)rtcp.port);
pj_memcpy(pj_sockaddr_get_addr(&si->rem_rtcp),
pj_sockaddr_get_addr(&si->rem_addr),
pj_sockaddr_get_addr_len(&si->rem_addr));
}
}
}
if (!pj_sockaddr_has_addr(&si->rem_rtcp)) {
int rtcp_port;
pj_memcpy(&si->rem_rtcp, &si->rem_addr, sizeof(pj_sockaddr));
rtcp_port = pj_sockaddr_get_port(&si->rem_addr) + 1;
pj_sockaddr_set_port(&si->rem_rtcp, (pj_uint16_t)rtcp_port);
}
/* Get the payload number for receive channel. */
/*
Previously we used to rely on fmt[0] being the selected codec,
but some UA sends telephone-event as fmt[0] and this would
cause assert failure below.
Thanks Chris Hamilton <chamilton .at. cs.dal.ca> for this patch.
// And codec must be numeric!
if (!pj_isdigit(*local_m->desc.fmt[0].ptr) ||
!pj_isdigit(*rem_m->desc.fmt[0].ptr))
{
return PJMEDIA_EINVALIDPT;
}
pt = pj_strtoul(&local_m->desc.fmt[0]);
pj_assert(PJMEDIA_RTP_PT_TELEPHONE_EVENTS==0 ||
pt != PJMEDIA_RTP_PT_TELEPHONE_EVENTS);
*/
/* Get codec info and param */
status = get_audio_codec_info_param(si, pool, mgr, local_m, rem_m);
/* Leave SSRC to random. */
si->ssrc = pj_rand();
/* Set default jitter buffer parameter. */
si->jb_init = si->jb_max = si->jb_min_pre = si->jb_max_pre = -1;
return status;
}
开发者ID:avble, 项目名称:natClientEx, 代码行数:101, 代码来源:stream_info.c
示例17: build_server_entries
/* Build server entries in the query_job based on received SRV response */
static void build_server_entries(pj_dns_srv_async_query *query_job,
pj_dns_parsed_packet *response)
{
unsigned i;
/* Save the Resource Records in DNS answer into SRV targets. */
query_job->srv_cnt = 0;
for (i=0; i<response->hdr.anscount &&
query_job->srv_cnt < PJ_DNS_SRV_MAX_ADDR; ++i)
{
pj_dns_parsed_rr *rr = &response->ans[i];
struct srv_target *srv = &query_job->srv[query_job->srv_cnt];
if (rr->type != PJ_DNS_TYPE_SRV) {
PJ_LOG(4,(query_job->objname,
"Received non SRV answer for SRV query_job!"));
continue;
}
if (rr->rdata.srv.target.slen > PJ_MAX_HOSTNAME) {
PJ_LOG(4,(query_job->objname, "Hostname is too long!"));
continue;
}
/* Build the SRV entry for RR */
pj_bzero(srv, sizeof(*srv));
srv->target_name.ptr = srv->target_buf;
pj_strncpy(&srv->target_name, &rr->rdata.srv.target,
sizeof(srv->target_buf));
srv->port = rr->rdata.srv.port;
srv->priority = rr->rdata.srv.prio;
srv->weight = rr->rdata.srv.weight;
++query_job->srv_cnt;
}
if (query_job->srv_cnt == 0) {
PJ_LOG(4,(query_job->objname,
"Could not find SRV record in DNS answer!"));
return;
}
/* First pass:
* order the entries based on priority.
*/
for (i=0; i<query_job->srv_cnt-1; ++i) {
unsigned min = i, j;
for (j=i+1; j<query_job->srv_cnt; ++j) {
if (query_job->srv[j].priority < query_job->srv[min].priority)
min = j;
}
SWAP(struct srv_target, &query_job->srv[i], &query_job->srv[min]);
}
/* Second pass:
* Order the entry in a list.
*
* The algorithm for selecting server among servers with the same
* priority is described in RFC 2782.
*/
for (i=0; i<query_job->srv_cnt; ++i) {
unsigned j, count=1, sum;
/* Calculate running sum for servers with the same priority */
sum = query_job->srv[i].sum = query_job->srv[i].weight;
for (j=i+1; j<query_job->srv_cnt &&
query_job->srv[j].priority == query_job->srv[i].priority; ++j)
{
sum += query_job->srv[j].weight;
query_job->srv[j].sum = sum;
++count;
}
if (count > 1) {
unsigned r;
/* Elect one random number between zero and the total sum of
* weight (inclusive).
*/
r = pj_rand() % (sum + 1);
/* Select the first server which running sum is greater than or
* equal to the random number.
*/
for (j=i; j<i+count; ++j) {
if (query_job->srv[j].sum >= r)
break;
}
/* Must have selected one! */
pj_assert(j != i+count);
/* Put this entry in front (of entries with same priority) */
SWAP(struct srv_target, &query_job->srv[i], &query_job->srv[j]);
/* Remove all other entries (of the same priority) */
/* Don't need to do this.
* See https://trac.pjsip.org/repos/ticket/1719
while (count > 1) {
//.........这里部分代码省略.........
开发者ID:Archipov, 项目名称:android-client, 代码行数:101, 代码来源:srv_resolver.c
示例18: PJ_DEF
//.........这里部分代码省略.........
} else {
si->fmt.channel_cnt = 1;
}
/* Get fmtp mode= param in local SDP, if any */
get_fmtp_mode(local_m, &local_m->desc.fmt[fmti], &local_fmtp_mode);
/* Determine payload type for outgoing channel, by finding
* dynamic payload type in remote SDP that matches the answer.
*/
si->tx_pt = 0xFFFF;
for (i=0; i<rem_m->desc.fmt_count; ++i) {
unsigned rpt;
pjmedia_sdp_attr *r_attr;
pjmedia_sdp_rtpmap r_rtpmap;
rpt = pj_strtoul(&rem_m->desc.fmt[i]);
if (rpt < 96)
continue;
r_attr = pjmedia_sdp_media_find_attr(rem_m, &ID_RTPMAP,
&rem_m->desc.fmt[i]);
if (!r_attr)
continue;
if (pjmedia_sdp_attr_get_rtpmap(r_attr, &r_rtpmap) != PJ_SUCCESS)
continue;
if (!pj_stricmp(&rtpmap->enc_name, &r_rtpmap.enc_name) &&
rtpmap->clock_rate == r_rtpmap.clock_rate)
{
/* Found matched codec. */
si->tx_pt = rpt;
/* Get fmtp mode param in remote SDP, if any */
get_fmtp_mode(rem_m, &rtpmap->pt, &rem_fmtp_mode);
break;
}
}
if (si->tx_pt == 0xFFFF)
return PJMEDIA_EMISSINGRTPMAP;
}
/* Now that we have codec info, get the codec param. */
si->param = pj_pool_alloc(pool, sizeof(*si->param));
status = pjmedia_codec_mgr_get_default_param(mgr, &si->fmt, si->param);
if (status != PJ_SUCCESS)
return status;
/* Set fmtp mode for both local and remote */
if (local_fmtp_mode != 0)
si->param->setting.dec_fmtp_mode = (pj_int8_t)local_fmtp_mode;
if (rem_fmtp_mode != 0)
si->param->setting.enc_fmtp_mode = (pj_int8_t)rem_fmtp_mode;
/* Get incomming payload type for telephone-events */
si->rx_event_pt = -1;
for (i=0; i<local_m->attr_count; ++i) {
pjmedia_sdp_rtpmap r;
attr = local_m->attr[i];
if (pj_strcmp(&attr->name, &ID_RTPMAP) != 0)
continue;
if (pjmedia_sdp_attr_get_rtpmap(attr, &r) != PJ_SUCCESS)
continue;
if (pj_strcmp(&r.enc_name, &ID_TELEPHONE_EVENT) == 0) {
si->rx_event_pt = pj_strtoul(&r.pt);
break;
}
}
/* Get outgoing payload type for telephone-events */
si->tx_event_pt = -1;
for (i=0; i<rem_m->attr_count; ++i) {
pjmedia_sdp_rtpmap r;
attr = rem_m->attr[i];
if (pj_strcmp(&attr->name, &ID_RTPMAP) != 0)
continue;
if (pjmedia_sdp_attr_get_rtpmap(attr, &r) != PJ_SUCCESS)
continue;
if (pj_strcmp(&r.enc_name, &ID_TELEPHONE_EVENT) == 0) {
si->tx_event_pt = pj_strtoul(&r.pt);
break;
}
}
/* Leave SSRC to random. */
si->ssrc = pj_rand();
/* Set default jitter buffer parameter. */
si->jb_init = si->jb_max = si->jb_min_pre = si->jb_max_pre = -1;
return PJ_SUCCESS;
}
开发者ID:tibastral, 项目名称:symphonie, 代码行数:101, 代码来源:session.c
六六分期app的软件客服如何联系?不知道吗?加qq群【895510560】即可!标题:六六分期
阅读:19216| 2023-10-27
今天小编告诉大家如何处理win10系统火狐flash插件总是崩溃的问题,可能很多用户都不知
阅读:9995| 2022-11-06
今天小编告诉大家如何对win10系统删除桌面回收站图标进行设置,可能很多用户都不知道
阅读:8331| 2022-11-06
今天小编告诉大家如何对win10系统电脑设置节能降温的设置方法,想必大家都遇到过需要
阅读:8699| 2022-11-06
我们在使用xp系统的过程中,经常需要对xp系统无线网络安装向导设置进行设置,可能很多
阅读:8643| 2022-11-06
今天小编告诉大家如何处理win7系统玩cf老是与主机连接不稳定的问题,可能很多用户都不
阅读:9665| 2022-11-06
电脑对日常生活的重要性小编就不多说了,可是一旦碰到win7系统设置cf烟雾头的问题,很
阅读:8628| 2022-11-06
我们在日常使用电脑的时候,有的小伙伴们可能在打开应用的时候会遇见提示应用程序无法
阅读:8003| 2022-11-06
今天小编告诉大家如何对win7系统打开vcf文件进行设置,可能很多用户都不知道怎么对win
阅读:8661| 2022-11-06
今天小编告诉大家如何对win10系统s4开启USB调试模式进行设置,可能很多用户都不知道怎
阅读:7537| 2022-11-06
请发表评论