本文整理汇总了C++中pj_get_timestamp函数的典型用法代码示例。如果您正苦于以下问题:C++ pj_get_timestamp函数的具体用法?C++ pj_get_timestamp怎么用?C++ pj_get_timestamp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pj_get_timestamp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PJ_DEF
PJ_DEF(Frame_Buffer *) jitter_buffer_getCompleteFrameForDecoding(Jitter_Buffer *jitter_buffer, pj_uint32_t max_wait_time_ms) {
//running
if(!jitter_buffer->running)
return NULL;
if(pj_mutex_lock(jitter_buffer->jb_mutex) != PJ_SUCCESS) { //error
return NULL;
}
/*{
char buf[1024];
getFrameInfo(&jitter_buffer->frameList, &jitter_buffer->decode_state, buf, 1024);
PJ_LOG(4, (THIS_FILE, "jb status:\n%s\n", buf));
}*/
//the first frame must be a key frame
if(jitter_buffer->decode_state.inited == PJ_FALSE)
jitter_buffer->waiting_for_key_frame == PJ_TRUE;
//clean old frames
CleanOldFrames(jitter_buffer);
//get complete , continuous frame
Frame_Buffer * frame = findOldestCompleteContinuousFrame(jitter_buffer);
//if not got, try to wait a frame
if(frame == NULL) {
if(max_wait_time_ms == 0)
goto ON_RET;
pj_timestamp current ;
pj_get_timestamp(¤t);
pj_timestamp end = current;
pj_add_timestamp32(&end, max_wait_time_ms);
pj_int32_t wait_time_ms = max_wait_time_ms;
event_reset(jitter_buffer->packet_event);
while(wait_time_ms > 0) {
pj_mutex_unlock(jitter_buffer->jb_mutex);
if(event_wait(jitter_buffer->packet_event, wait_time_ms) == WAIT_RET_SIGNAL) {
//incoming a packet
pj_mutex_lock(jitter_buffer->jb_mutex);
if(!jitter_buffer->running) //jitter buffer stoped
goto ON_RET;
CleanOldFrames(jitter_buffer);
frame = findOldestCompleteContinuousFrame(jitter_buffer);
if(frame != NULL)
break;
pj_get_timestamp(¤t);
int elapsed_msec = pj_elapsed_msec(¤t, &end);
wait_time_ms = elapsed_msec;
} else {
pj_mutex_lock(jitter_buffer->jb_mutex); //error or timeout
break;
}
}
} else
event_reset(jitter_buffer->packet_event);
if(frame == NULL)
goto ON_RET;
/*if(jitter_buffer->waiting_for_key_frame && !frame->session_info.isKeyFrame) {
frame = NULL; //not a key frame
goto ON_RET;
}*/
//got one, update jitter
if(frame->nack_count > 0) {
jitter_estimator_frameNacked(&jitter_buffer->jitter_estimator); //nacked
} else {
//update jitter estimator
UpdateJitterEstimatorForFrame(jitter_buffer, frame);
}
//set frame status
frame_buffer_setStatus(frame, FRAME_STATUS_DECODING);
//update decode state
decode_state_updateFrame(frame, &jitter_buffer->decode_state);
//waiting for key frame
if(frame->session_info.isKeyFrame)
jitter_buffer->waiting_for_key_frame = PJ_FALSE;
//clean old frames
CleanOldFrames(jitter_buffer);
//return frame
ON_RET:
pj_mutex_unlock(jitter_buffer->jb_mutex);
return frame;
}
示例2: PJ_DEF
/*
* pj_ioqueue_poll()
*
*/
PJ_DEF(int) pj_ioqueue_poll( pj_ioqueue_t *ioqueue, const pj_time_val *timeout)
{
int i, count, processed;
int msec;
//struct epoll_event *events = ioqueue->events;
//struct queue *queue = ioqueue->queue;
struct epoll_event events[PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL];
struct queue queue[PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL];
pj_timestamp t1, t2;
PJ_CHECK_STACK();
msec = timeout ? PJ_TIME_VAL_MSEC(*timeout) : 9000;
TRACE_((THIS_FILE, "start os_epoll_wait, msec=%d", msec));
pj_get_timestamp(&t1);
//count = os_epoll_wait( ioqueue->epfd, events, ioqueue->max, msec);
count = os_epoll_wait( ioqueue->epfd, events, PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL, msec);
if (count == 0) {
#if PJ_IOQUEUE_HAS_SAFE_UNREG
/* Check the closing keys only when there's no activity and when there are
* pending closing keys.
*/
if (count == 0 && !pj_list_empty(&ioqueue->closing_list)) {
pj_lock_acquire(ioqueue->lock);
scan_closing_keys(ioqueue);
pj_lock_release(ioqueue->lock);
}
#endif
TRACE_((THIS_FILE, "os_epoll_wait timed out"));
return count;
}
else if (count < 0) {
TRACE_((THIS_FILE, "os_epoll_wait error"));
return -pj_get_netos_error();
}
pj_get_timestamp(&t2);
TRACE_((THIS_FILE, "os_epoll_wait returns %d, time=%d usec",
count, pj_elapsed_usec(&t1, &t2)));
/* Lock ioqueue. */
pj_lock_acquire(ioqueue->lock);
for (processed=0, i=0; i<count; ++i) {
pj_ioqueue_key_t *h = (pj_ioqueue_key_t*)(epoll_data_type)
events[i].epoll_data;
TRACE_((THIS_FILE, "event %d: events=%d", i, events[i].events));
/*
* Check readability.
*/
if ((events[i].events & EPOLLIN) &&
(key_has_pending_read(h) || key_has_pending_accept(h)) && !IS_CLOSING(h) ) {
#if PJ_IOQUEUE_HAS_SAFE_UNREG
increment_counter(h);
#endif
queue[processed].key = h;
queue[processed].event_type = READABLE_EVENT;
++processed;
continue;
}
/*
* Check for writeability.
*/
if ((events[i].events & EPOLLOUT) && key_has_pending_write(h) && !IS_CLOSING(h)) {
#if PJ_IOQUEUE_HAS_SAFE_UNREG
increment_counter(h);
#endif
queue[processed].key = h;
queue[processed].event_type = WRITEABLE_EVENT;
++processed;
continue;
}
#if PJ_HAS_TCP
/*
* Check for completion of connect() operation.
*/
if ((events[i].events & EPOLLOUT) && (h->connecting) && !IS_CLOSING(h)) {
#if PJ_IOQUEUE_HAS_SAFE_UNREG
increment_counter(h);
#endif
queue[processed].key = h;
queue[processed].event_type = WRITEABLE_EVENT;
++processed;
continue;
}
#endif /* PJ_HAS_TCP */
//.........这里部分代码省略.........
示例3: 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) {
//.........这里部分代码省略.........
示例4: 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) {
//.........这里部分代码省略.........
示例5: PJ_DEF
/*
* Get NTP time.
*/
PJ_DEF(pj_status_t) pjmedia_rtcp_get_ntp_time(const pjmedia_rtcp_session *sess,
pjmedia_rtcp_ntp_rec *ntp)
{
/* Seconds between 1900-01-01 to 1970-01-01 */
#define JAN_1970 (2208988800UL)
pj_timestamp ts;
pj_status_t status;
status = pj_get_timestamp(&ts);
/* Fill up the high 32bit part */
ntp->hi = (pj_uint32_t)((ts.u64 - sess->ts_base.u64) / sess->ts_freq.u64)
+ sess->tv_base.sec + JAN_1970;
/* Calculate seconds fractions */
ts.u64 = (ts.u64 - sess->ts_base.u64) % sess->ts_freq.u64;
pj_assert(ts.u64 < sess->ts_freq.u64);
ts.u64 = (ts.u64 << 32) / sess->ts_freq.u64;
/* Fill up the low 32bit part */
ntp->lo = ts.u32.lo;
#if (defined(PJ_WIN32) && PJ_WIN32!=0) || \
(defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0)
/* On Win32, since we use QueryPerformanceCounter() as the backend
* timestamp API, we need to protect against this bug:
* Performance counter value may unexpectedly leap forward
* http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q274323
*/
{
/*
* Compare elapsed time reported by timestamp with actual elapsed
* time. If the difference is too excessive, then we use system
* time instead.
*/
/* MIN_DIFF needs to be large enough so that "normal" diff caused
* by system activity or context switch doesn't trigger the time
* correction.
*/
enum { MIN_DIFF = 400 };
pj_time_val ts_time, elapsed, diff;
pj_gettimeofday(&elapsed);
ts_time.sec = ntp->hi - sess->tv_base.sec - JAN_1970;
ts_time.msec = (long)(ntp->lo * 1000.0 / 0xFFFFFFFF);
PJ_TIME_VAL_SUB(elapsed, sess->tv_base);
if (PJ_TIME_VAL_LT(ts_time, elapsed)) {
diff = elapsed;
PJ_TIME_VAL_SUB(diff, ts_time);
} else {
diff = ts_time;
PJ_TIME_VAL_SUB(diff, elapsed);
}
if (PJ_TIME_VAL_MSEC(diff) >= MIN_DIFF) {
TRACE_((sess->name, "RTCP NTP timestamp corrected by %d ms",
PJ_TIME_VAL_MSEC(diff)));
ntp->hi = elapsed.sec + sess->tv_base.sec + JAN_1970;
ntp->lo = (elapsed.msec * 65536 / 1000) << 16;
}
}
#endif
return status;
}
示例6: AndroidRecorderCallback
static int PJ_THREAD_FUNC AndroidRecorderCallback(void* userData){
struct android_aud_stream *stream = (struct android_aud_stream*) userData;
JNIEnv *jni_env = 0;
ATTACH_JVM(jni_env);
jmethodID read_method=0, record_method=0;
int bytesRead;
int size = stream->samples_per_frame * stream->bytes_per_sample;
int nframes = stream->samples_per_frame / stream->channel_count;
jbyte* buf;
pj_status_t status = 0;
jbyteArray inputBuffer;
pj_timestamp tstamp, now, last_frame;
int elapsed_time = 0;
//Frame time in ms
int frame_time = nframes * 1000 / stream->samples_per_sec;
int missed_time = frame_time;
int to_wait = 0;
PJ_LOG(3,(THIS_FILE, "<< Enter recorder thread"));
if(!stream->record){
goto on_break;
}
//Get methods ids
read_method = jni_env->GetMethodID(stream->record_class,"read", "([BII)I");
record_method = jni_env->GetMethodID(stream->record_class,"startRecording", "()V");
if(read_method==0 || record_method==0) {
goto on_break;
}
//Create a buffer for frames read
inputBuffer = jni_env->NewByteArray(size);
if (inputBuffer == 0) {
PJ_LOG(2, (THIS_FILE, "Not able to allocate a buffer for input read process"));
goto on_break;
}
//start recording
//setpriority(PRIO_PROCESS, 0, -19 /*ANDROID_PRIORITY_AUDIO*/);
// set priority is probably not enough cause does not change the thread group in scheduler
// Temporary solution is to call the java api to set the thread priority.
// A cool solution would be to port (if possible) the code from the android os regarding set_sched groups
set_android_thread_priority(THREAD_PRIORITY_URGENT_AUDIO);
buf = jni_env->GetByteArrayElements(inputBuffer, 0);
//Init everything
tstamp.u64 = 0;
pj_bzero (buf, size);
jni_env->CallVoidMethod(stream->record, record_method);
pj_get_timestamp(&last_frame);
while ( !stream->quit_flag ) {
pj_bzero (buf, size);
#if COMPATIBLE_ALSA
pj_get_timestamp(&now);
// Time between now and last frame next frame (ms)
elapsed_time = pj_elapsed_msec(&last_frame, &now);
pj_get_timestamp(&last_frame);
//PJ_LOG (4, (THIS_FILE, "Elapsed time is %d | missed time is %d | frame time %d", elapsed_time, missed_time, frame_time));
//Update missed time
// Positif if we are late
// negatif if we are earlier
// dividing by 2 is empiric result
// on N1 if not we get buffer overflow I assume that it fill packets faster than the frequency
missed_time = missed_time/2 + elapsed_time - frame_time;
//PJ_LOG (4, (THIS_FILE, "And now :: Elapsed time is %d | missed time is %d", elapsed_time, missed_time));
//If we go faster than the buffer filling we have to wait no
if( missed_time <= 0 ){
//if(elapsed_time < frame_time){
to_wait = - missed_time - 2;
if(to_wait > 0){
// PJ_LOG (4, (THIS_FILE, "Wait for %d / %d", to_wait, frame_time));
pj_thread_sleep(to_wait);
}
//}
}
/*
//PJ_LOG (4, (THIS_FILE, "Next frame %d", next_frame_in));
if (next_frame_in-2 > 0) {
//PJ_LOG (4, (THIS_FILE, "Wait for buffer %d", next_frame_in));
pj_thread_sleep(next_frame_in-5);
//Reset the delay we have regarding next frame
retard = 0;
}else{
if(next_frame_in < 0){
retard += next_frame_in;
}
//.........这里部分代码省略.........
示例7: test
static int test(void)
{
pj_rbtree rb;
node_key *key;
pj_rbtree_node *node;
pj_pool_t *pool;
int err=0;
int count = MIN_COUNT;
int i;
unsigned size;
pj_rbtree_init(&rb, (pj_rbtree_comp*)&compare_node);
size = MAX_COUNT*(sizeof(*key)+PJ_RBTREE_NODE_SIZE) +
PJ_RBTREE_SIZE + PJ_POOL_SIZE;
pool = pj_pool_create( mem, "pool", size, 0, NULL);
if (!pool) {
PJ_LOG(3,("test", "...error: creating pool of %u bytes", size));
return -10;
}
key = (node_key *)pj_pool_alloc(pool, MAX_COUNT*sizeof(*key));
if (!key)
return -20;
node = (pj_rbtree_node*)pj_pool_alloc(pool, MAX_COUNT*sizeof(*node));
if (!node)
return -30;
for (i=0; i<LOOP; ++i) {
int j;
pj_rbtree_node *prev, *it;
pj_timestamp t1, t2, t_setup, t_insert, t_search, t_erase;
pj_assert(rb.size == 0);
t_setup.u32.lo = t_insert.u32.lo = t_search.u32.lo = t_erase.u32.lo = 0;
for (j=0; j<count; j++) {
randomize_string(key[j].str, STRSIZE);
pj_get_timestamp(&t1);
node[j].key = &key[j];
node[j].user_data = key[j].str;
key[j].hash = pj_hash_calc(0, key[j].str, PJ_HASH_KEY_STRING);
pj_get_timestamp(&t2);
t_setup.u32.lo += (t2.u32.lo - t1.u32.lo);
pj_get_timestamp(&t1);
pj_rbtree_insert(&rb, &node[j]);
pj_get_timestamp(&t2);
t_insert.u32.lo += (t2.u32.lo - t1.u32.lo);
}
pj_assert(rb.size == (unsigned)count);
// Iterate key, make sure they're sorted.
prev = NULL;
it = pj_rbtree_first(&rb);
while (it) {
if (prev) {
if (compare_node((node_key*)prev->key,(node_key*)it->key)>=0) {
++err;
PJ_LOG(3, (THIS_FILE, "Error: %s >= %s",
(char*)prev->user_data, (char*)it->user_data));
}
}
prev = it;
it = pj_rbtree_next(&rb, it);
}
// Search.
for (j=0; j<count; j++) {
pj_get_timestamp(&t1);
it = pj_rbtree_find(&rb, &key[j]);
pj_get_timestamp(&t2);
t_search.u32.lo += (t2.u32.lo - t1.u32.lo);
pj_assert(it != NULL);
if (it == NULL)
++err;
}
// Erase node.
for (j=0; j<count; j++) {
pj_get_timestamp(&t1);
it = pj_rbtree_erase(&rb, &node[j]);
pj_get_timestamp(&t2);
t_erase.u32.lo += (t2.u32.lo - t1.u32.lo);
}
PJ_LOG(4, (THIS_FILE,
"...count:%d, setup:%d, insert:%d, search:%d, erase:%d",
count,
t_setup.u32.lo / count, t_insert.u32.lo / count,
t_search.u32.lo / count, t_erase.u32.lo / count));
count = 2 * count;
if (count > MAX_COUNT)
break;
}
//.........这里部分代码省略.........
示例8: expand
int expand(pj_pool_t *pool, const char *filein, const char *fileout,
int expansion_rate100, int lost_rate10, int lost_burst)
{
enum { LOST_RATE = 10 };
FILE *in, *out;
short frame[SAMPLES_PER_FRAME];
pjmedia_wsola *wsola;
pj_timestamp elapsed, zero;
unsigned samples;
int last_lost = 0;
/* Lost burst must be > 0 */
assert(lost_rate10==0 || lost_burst > 0);
in = fopen(filein, "rb");
if (!in) return 1;
out = fopen(fileout, "wb");
if (!out) return 1;
pjmedia_wsola_create(pool, CLOCK_RATE, SAMPLES_PER_FRAME, 1, 0, &wsola);
samples = 0;
elapsed.u64 = 0;
while (fread(frame, SAMPLES_PER_FRAME*2, 1, in) == 1) {
pj_timestamp t1, t2;
if (lost_rate10 == 0) {
/* Expansion */
pj_get_timestamp(&t1);
pjmedia_wsola_save(wsola, frame, 0);
pj_get_timestamp(&t2);
pj_sub_timestamp(&t2, &t1);
pj_add_timestamp(&elapsed, &t2);
fwrite(frame, SAMPLES_PER_FRAME*2, 1, out);
samples += SAMPLES_PER_FRAME;
if ((rand() % 100) < expansion_rate100) {
pj_get_timestamp(&t1);
pjmedia_wsola_generate(wsola, frame);
pj_get_timestamp(&t2);
pj_sub_timestamp(&t2, &t1);
pj_add_timestamp(&elapsed, &t2);
samples += SAMPLES_PER_FRAME;
fwrite(frame, SAMPLES_PER_FRAME*2, 1, out);
}
} else {
/* Lost */
if ((rand() % 10) < lost_rate10) {
int burst;
for (burst=0; burst<lost_burst; ++burst) {
pj_get_timestamp(&t1);
pjmedia_wsola_generate(wsola, frame);
pj_get_timestamp(&t2);
pj_sub_timestamp(&t2, &t1);
pj_add_timestamp(&elapsed, &t2);
samples += SAMPLES_PER_FRAME;
fwrite(frame, SAMPLES_PER_FRAME*2, 1, out);
}
last_lost = 1;
} else {
pj_get_timestamp(&t1);
pjmedia_wsola_save(wsola, frame, last_lost);
pj_get_timestamp(&t2);
pj_sub_timestamp(&t2, &t1);
pj_add_timestamp(&elapsed, &t2);
samples += SAMPLES_PER_FRAME;
fwrite(frame, SAMPLES_PER_FRAME*2, 1, out);
last_lost = 0;
}
}
}
zero.u64 = 0;
zero.u64 = pj_elapsed_usec(&zero, &elapsed);
zero.u64 = samples * PJ_INT64(1000000) / zero.u64;
assert(zero.u32.hi == 0);
PJ_LOG(3,("test.c", "Processing: %f Msamples per second",
zero.u32.lo/1000000.0));
//.........这里部分代码省略.........
示例9: printf
int CChannel::sendto(const sockaddr* addr, CPacket& packet) const
{
// convert control information into network order
if (packet.getFlag()) {
for (int i = 0, n = packet.getLength() / 4; i < n; ++ i)
*((uint32_t *)packet.m_pcData + i) = htonl(*((uint32_t *)packet.m_pcData + i));
}
uint32_t* p = packet.m_nHeader;
for (int j = 0; j < 4; ++ j)
{
*p = htonl(*p);
++ p;
}
#ifdef DEBUGP
//dump ctrl packet
printf("\nSend Header:\n");
dumpHex((char *)packet.m_PacketVector[0].iov_base, packet.m_PacketVector[0].iov_len);
char *bb = (char *)packet.m_PacketVector[0].iov_base;
if(bb[0]&0x80) {
printf("Data:\n");
dumpHex((char *)packet.m_PacketVector[1].iov_base, packet.m_PacketVector[1].iov_len);
printf("================\n");
}
#endif
int res = -1;
unsigned size;
unsigned len;
natnl_hdr hdr = {0xff, 0x00, 0x0000};
int is_tnl_data = 0;
pj_thread_desc desc;
pj_thread_t *thread = 0;
if(m_iSocket == -1) {
pjsua_call *call = (pjsua_call *)m_call;
if(call == NULL) return -1;
// DEAN, prevent assert fail while garbage collector remove UDT socket on multiple instance.
if (!pj_thread_is_registered(call->inst_id)) {
int status = pj_thread_register(call->inst_id, "CChannel::sendto", desc, &thread );
if (status != PJ_SUCCESS)
return -1;
}
pj_mutex_lock(call->tnl_stream_lock2);
natnl_stream *stream = (natnl_stream *)call->tnl_stream;
if(stream == NULL) {
pj_mutex_unlock(call->tnl_stream_lock2);
return -1;
}
size = CPacket::m_iPktHdrSize + packet.getLength() + sizeof(natnl_hdr);
len = (CPacket::m_iPktHdrSize + packet.getLength());
hdr.length = htons(len);
memcpy((char *)&m_pktBuffer[sizeof(natnl_hdr)], packet.m_PacketVector[0].iov_base, packet.m_PacketVector[0].iov_len);
memcpy((char *)&m_pktBuffer[packet.m_PacketVector[0].iov_len+sizeof(natnl_hdr)], packet.m_PacketVector[1].iov_base, packet.m_PacketVector[1].iov_len);
memcpy((char *)&m_pktBuffer[0], &hdr, sizeof(natnl_hdr));
resend:
// DEAN, check if this is tunnel data. If true, update last_data time.
is_tnl_data = pjmedia_natnl_udt_packet_is_tnl_data(&m_pktBuffer[0], size);
pj_assert(size < sizeof(m_pktBuffer));
((pj_uint8_t*)m_pktBuffer)[size] = 0; // tunnel data flag off
if (is_tnl_data) {
pj_get_timestamp(&stream->last_data); // DEAN save current time
((pj_uint8_t*)m_pktBuffer)[size] = 1; // tunnel data flag on
}
res = pjmedia_transport_send_rtp(stream->med_tp, m_pktBuffer, size); // +Roger modified - stream pointer to med_tp
#if 0 // No need to resend it, because UDT will handle this.
if(res == 70011) { //EAGAIN
m_pTimer->sleepto(50000); //sleep for 50 us
goto resend;
}
#endif
pj_mutex_unlock(call->tnl_stream_lock2);
}
res = (0 == res) ? size : -1;
// convert back into local host order
//for (int k = 0; k < 4; ++ k)
// packet.m_nHeader[k] = ntohl(packet.m_nHeader[k]);
p = packet.m_nHeader;
for (int k = 0; k < 4; ++ k)
{
*p = ntohl(*p);
++ p;
}
if (packet.getFlag())
{
for (int l = 0, n = packet.getLength() / 4; l < n; ++ l)
//.........这里部分代码省略.........
示例10: snd_agc
pj_status_t latency_checker::start(latency_config_t &config)
{
pj_status_t result = PJ_EINVAL;
if(m_pool == NULL)
{
m_dstate = 0;
m_start_tone_time.u64 = 0;
m_latency = 0;
m_quality = 0;
m_config = config;
m_status_string[0] = 0;
m_gain = new snd_agc("",30,1,32000,32000);
m_idle_freq1_det = new tone_detector(m_config.clock_rate,IDLE_FREQ1);
m_idle_freq2_det = new tone_detector(m_config.clock_rate,IDLE_FREQ2);
m_active_freq1_det = new tone_detector(m_config.clock_rate,ACTIVE_FREQ1);
m_active_freq2_det = new tone_detector(m_config.clock_rate,ACTIVE_FREQ2);
init_generate_dual_tone(&m_idle_tone,m_config.clock_rate,IDLE_FREQ1,IDLE_FREQ2,32767);
init_generate_dual_tone(&m_active_tone,m_config.clock_rate,ACTIVE_FREQ1,ACTIVE_FREQ2,32767);
pj_log_set_level(0);
pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_SENDER | PJ_LOG_HAS_TIME | PJ_LOG_HAS_MICRO_SEC);
if(pj_init()==PJ_SUCCESS)
{
m_caching_pool = (pj_caching_pool *)malloc(sizeof(pj_caching_pool));
pj_caching_pool_init( m_caching_pool, NULL, 0 );
m_pool_factory=&m_caching_pool->factory;
m_pool = pj_pool_create(m_pool_factory, "LATENCY NATIVE", 4000, 4000, NULL);
pj_log_set_level(m_config.logs.level);
pj_logging_init(m_pool);
pj_logging_setLogToConsole(1);
pj_logging_setFilename(m_config.logs.file_name);
pj_logging_setMaxLogFiles(m_config.logs.max_files);
pj_logging_setMaxLogFileSize(m_config.logs.max_file_size*1024*1024);
pj_logging_start();
pj_get_timestamp(&m_last_get_frame_time);
m_lock = new PPJ_SemaphoreLock(m_pool,NULL,1,1);
pjmedia_aud_subsys_init(m_pool_factory);
#if PJMEDIA_AUDIO_DEV_HAS_ANDROID
#if PJ_ANDROID_DEVICE==1
pjmedia_aud_register_factory(&pjmedia_android_factory);
#endif
#if PJ_ANDROID_DEVICE==2
pjmedia_aud_register_factory(&pjmedia_opensl_factory);
#endif
#if PJ_ANDROID_DEVICE==3
pjmedia_aud_register_factory(&pjmedia_alsa_factory);
#endif
#endif
pjmedia_aud_param params;
params.dir = PJMEDIA_DIR_CAPTURE_PLAYBACK;
params.rec_id = 1;
params.play_id = 6;
params.clock_rate = m_config.clock_rate;
params.channel_count = 1;
params.samples_per_frame = m_config.min_frame_length*m_config.clock_rate/1000;
params.bits_per_sample = 16;
params.flags = PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY | PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY;
params.input_latency_ms = m_config.min_frame_length;
params.output_latency_ms = m_config.min_frame_length;
result = pjmedia_aud_stream_create(¶ms,&rec_cb_s,&play_cb_s,this,&m_aud_stream);
if(result==PJ_SUCCESS)
{
result = pjmedia_aud_stream_start(m_aud_stream);
if(result==PJ_SUCCESS)
{
}
}
}
}
if(result!=PJ_SUCCESS)
internal_clean();
return result;
}
示例11: compress
int compress(pj_pool_t *pool,
const char *filein, const char *fileout,
int rate10)
{
enum { BUF_CNT = SAMPLES_PER_FRAME * 10 };
FILE *in, *out;
pjmedia_wsola *wsola;
short buf[BUF_CNT];
pj_timestamp elapsed, zero;
unsigned samples = 0;
in = fopen(filein, "rb");
if (!in) return 1;
out = fopen(fileout, "wb");
if (!out) return 1;
pjmedia_wsola_create(pool, CLOCK_RATE, SAMPLES_PER_FRAME, 1, 0, &wsola);
elapsed.u64 = 0;
for (;;) {
unsigned size_del, count;
pj_timestamp t1, t2;
int i;
if (fread(buf, sizeof(buf), 1, in) != 1)
break;
count = BUF_CNT;
size_del = 0;
pj_get_timestamp(&t1);
for (i=0; i<rate10; ++i) {
unsigned to_del = SAMPLES_PER_FRAME;
#if 0
/* Method 1: buf1 contiguous */
pjmedia_wsola_discard(wsola, buf, count, NULL, 0, &to_del);
#elif 0
/* Method 2: split, majority in buf1 */
assert(count > SAMPLES_PER_FRAME);
pjmedia_wsola_discard(wsola, buf, count-SAMPLES_PER_FRAME,
buf+count-SAMPLES_PER_FRAME, SAMPLES_PER_FRAME,
&to_del);
#elif 0
/* Method 3: split, majority in buf2 */
assert(count > SAMPLES_PER_FRAME);
pjmedia_wsola_discard(wsola, buf, SAMPLES_PER_FRAME,
buf+SAMPLES_PER_FRAME, count-SAMPLES_PER_FRAME,
&to_del);
#elif 1
/* Method 4: split, each with small length */
enum { TOT_LEN = 3 * SAMPLES_PER_FRAME };
unsigned buf1_len = (rand() % TOT_LEN);
short *ptr = buf + count - TOT_LEN;
assert(count > TOT_LEN);
if (buf1_len==0) buf1_len=SAMPLES_PER_FRAME*2;
pjmedia_wsola_discard(wsola, ptr, buf1_len,
ptr+buf1_len, TOT_LEN-buf1_len,
&to_del);
#endif
count -= to_del;
size_del += to_del;
}
pj_get_timestamp(&t2);
samples += BUF_CNT;
pj_sub_timestamp(&t2, &t1);
pj_add_timestamp(&elapsed, &t2);
assert(size_del >= SAMPLES_PER_FRAME);
fwrite(buf, count, 2, out);
}
pjmedia_wsola_destroy(wsola);
fclose(in);
fclose(out);
zero.u64 = 0;
zero.u64 = pj_elapsed_usec(&zero, &elapsed);
zero.u64 = samples * PJ_INT64(1000000) / zero.u64;
assert(zero.u32.hi == 0);
PJ_LOG(3,("test.c", "Processing: %f Msamples per second",
zero.u32.lo/1000000.0));
PJ_LOG(3,("test.c", "CPU load for current settings: %f%%",
CLOCK_RATE * 100.0 / zero.u32.lo));
return 0;
}
示例12: get_timestamp
pj_status_t get_timestamp()
{
return pj_get_timestamp(&ts_);
}
示例13: sleep_duration_test
static int sleep_duration_test(void)
{
enum { MIS = 20};
unsigned duration[] = { 2000, 1000, 500, 200, 100 };
unsigned i;
pj_status_t rc;
PJ_LOG(3,(THIS_FILE, "..running sleep duration test"));
/* Test pj_thread_sleep() and pj_gettimeofday() */
for (i=0; i<PJ_ARRAY_SIZE(duration); ++i) {
pj_time_val start, stop;
pj_uint32_t msec;
/* Mark start of test. */
rc = pj_gettimeofday(&start);
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_gettimeofday()", rc);
return -10;
}
/* Sleep */
rc = pj_thread_sleep(duration[i]);
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_thread_sleep()", rc);
return -20;
}
/* Mark end of test. */
rc = pj_gettimeofday(&stop);
/* Calculate duration (store in stop). */
PJ_TIME_VAL_SUB(stop, start);
/* Convert to msec. */
msec = PJ_TIME_VAL_MSEC(stop);
/* Check if it's within range. */
if (msec < duration[i] * (100-MIS)/100 ||
msec > duration[i] * (100+MIS)/100)
{
PJ_LOG(3,(THIS_FILE,
"...error: slept for %d ms instead of %d ms "
"(outside %d%% err window)",
msec, duration[i], MIS));
return -30;
}
}
/* Test pj_thread_sleep() and pj_get_timestamp() and friends */
for (i=0; i<PJ_ARRAY_SIZE(duration); ++i) {
pj_time_val t1, t2;
pj_timestamp start, stop;
pj_uint32_t msec;
pj_thread_sleep(0);
/* Mark start of test. */
rc = pj_get_timestamp(&start);
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_get_timestamp()", rc);
return -60;
}
/* ..also with gettimeofday() */
pj_gettimeofday(&t1);
/* Sleep */
rc = pj_thread_sleep(duration[i]);
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_thread_sleep()", rc);
return -70;
}
/* Mark end of test. */
pj_get_timestamp(&stop);
/* ..also with gettimeofday() */
pj_gettimeofday(&t2);
/* Compare t1 and t2. */
if (PJ_TIME_VAL_LT(t2, t1)) {
PJ_LOG(3,(THIS_FILE, "...error: t2 is less than t1!!"));
return -75;
}
/* Get elapsed time in msec */
msec = pj_elapsed_msec(&start, &stop);
/* Check if it's within range. */
if (msec < duration[i] * (100-MIS)/100 ||
msec > duration[i] * (100+MIS)/100)
{
PJ_LOG(3,(THIS_FILE,
"...error: slept for %d ms instead of %d ms "
"(outside %d%% err window)",
msec, duration[i], MIS));
PJ_TIME_VAL_SUB(t2, t1);
PJ_LOG(3,(THIS_FILE,
//.........这里部分代码省略.........
示例14: PJ_DEF
PJ_DEF(pj_status_t) pjmedia_natnl_stream_create(pj_pool_t *pool,
pjsua_call *call,
pjmedia_stream_info *si,
natnl_stream **stream)
{
pj_status_t status = PJ_SUCCESS;
unsigned strm_idx = 0;
strm_idx = call->index;
/* TODO:
* - Create and start your media stream based on the parameters
* in si
*/
PJ_ASSERT_RETURN(pool, PJ_EINVAL);
PJ_LOG(4,(THIS_FILE,"natnl audio channel update..strm_idx=%d", strm_idx));
/* Check if no media is active */
if (si->dir != PJMEDIA_DIR_NONE) {
/* Create session based on session info. */
#if 0
pool = pj_pool_create(strm_pool->factory, "strm%p",
NATNL_STREAM_SIZE, NATNL_STREAM_INC, NULL);
PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
#endif
pj_mutex_lock(call->tnl_stream_lock);
pj_mutex_lock(call->tnl_stream_lock2);
pj_mutex_lock(call->tnl_stream_lock3);
// DEAN don't re-create natnl stream
if (call->tnl_stream) {
*stream = call->tnl_stream;
pj_mutex_unlock(call->tnl_stream_lock3);
pj_mutex_unlock(call->tnl_stream_lock2);
pj_mutex_unlock(call->tnl_stream_lock);
return PJ_SUCCESS;
}
call->tnl_stream = *stream = PJ_POOL_ZALLOC_T(pool, natnl_stream);
PJ_ASSERT_RETURN(*stream != NULL, PJ_ENOMEM);
(*stream)->call = call;
(*stream)->own_pool = pool;
(*stream)->med_tp = call->med_tp;
pj_memcpy(&(*stream)->rem_addr, &si->rem_addr, sizeof(pj_sockaddr));
pj_list_init(&(*stream)->rbuff);
pj_list_init(&(*stream)->gcbuff);
pj_get_timestamp(&(*stream)->last_data_or_ka);
pj_get_timestamp(&(*stream)->last_data);
(*stream)->rbuff_cnt = 0;
(*stream)->rx_band = (pj_band_t *)malloc(sizeof(pj_band_t));
(*stream)->tx_band = (pj_band_t *)malloc(sizeof(pj_band_t));
pj_memset((*stream)->rx_band, 0, sizeof(pj_band_t));
pj_memset((*stream)->tx_band, 0, sizeof(pj_band_t));
pj_bandwidthSetLimited((*stream)->rx_band, PJ_FALSE);
pj_bandwidthSetLimited((*stream)->tx_band, PJ_FALSE);
/* Create mutex to protect jitter buffer: */
status = pj_mutex_create_simple(pool, NULL, &(*stream)->rbuff_mutex);
if (status != PJ_SUCCESS) {
//pj_pool_t *tmp_pool = (*stream)->own_pool;
(*stream)->own_pool = NULL;
//pj_pool_release(tmp_pool);
goto on_return;
}
status = pj_mutex_create_simple(pool, NULL, &(*stream)->gcbuff_mutex);
if (status != PJ_SUCCESS) {
(*stream)->own_pool = NULL;
goto on_return;
}
/* Create semaphore */
status = pj_sem_create(pool, "client", 0, 65535, &(*stream)->rbuff_sem);
if (status != PJ_SUCCESS) {
(*stream)->own_pool = NULL;
goto on_return;
}
// +Roger - Create Send buffer Mutex
status = pj_mutex_create_simple(pool, NULL, &(*stream)->sbuff_mutex);
if (status != PJ_SUCCESS) {
//pj_pool_t *tmp_pool = (*stream)->own_pool;
(*stream)->own_pool = NULL;
//pj_pool_release(tmp_pool);
goto on_return;
}
//------------------------------------//
#if 0
/* Attach our RTP and RTCP callbacks to the media transport */
status = pjmedia_transport_attach(call_med->tp, stream, //call_med,
&si->rem_addr, &si->rem_rtcp,
pj_sockaddr_get_len(&si->rem_addr),
&aud_rtp_cb, &aud_rtcp_cb);
#endif
}
//.........这里部分代码省略.........
示例15: uas_tsx_bench
static int uas_tsx_bench(unsigned working_set, pj_timestamp *p_elapsed)
{
unsigned i;
pjsip_tx_data *request;
pjsip_via_hdr *via;
pjsip_rx_data rdata;
pj_sockaddr_in remote;
pjsip_transaction **tsx;
pj_timestamp t1, t2, elapsed;
char branch_buf[80] = PJSIP_RFC3261_BRANCH_ID "0000000000";
pj_status_t status;
/* Create the request first. */
pj_str_t str_target = pj_str("sip:[email protected]");
pj_str_t str_from = pj_str("\"Local User\" <sip:[email protected]>");
pj_str_t str_to = pj_str("\"Remote User\" <sip:[email protected]>");
pj_str_t str_contact = str_from;
status = pjsip_endpt_create_request(endpt, &pjsip_invite_method,
&str_target, &str_from, &str_to,
&str_contact, NULL, -1, NULL,
&request);
if (status != PJ_SUCCESS) {
app_perror(" error: unable to create request", status);
return status;
}
/* Create Via */
via = pjsip_via_hdr_create(request->pool);
via->sent_by.host = pj_str("192.168.0.7");
via->sent_by.port = 5061;
via->transport = pj_str("udp");
via->rport_param = 1;
via->recvd_param = pj_str("192.168.0.7");
pjsip_msg_insert_first_hdr(request->msg, (pjsip_hdr*)via);
/* Create "dummy" rdata from the tdata */
pj_bzero(&rdata, sizeof(pjsip_rx_data));
rdata.tp_info.pool = request->pool;
rdata.msg_info.msg = request->msg;
rdata.msg_info.from = (pjsip_from_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_FROM, NULL);
rdata.msg_info.to = (pjsip_to_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_TO, NULL);
rdata.msg_info.cseq = (pjsip_cseq_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_CSEQ, NULL);
rdata.msg_info.cid = (pjsip_cid_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_FROM, NULL);
rdata.msg_info.via = via;
pj_sockaddr_in_init(&remote, 0, 0);
status = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_LOOP_DGRAM,
&remote, sizeof(pj_sockaddr_in),
NULL, &rdata.tp_info.transport);
if (status != PJ_SUCCESS) {
app_perror(" error: unable to get loop transport", status);
return status;
}
/* Create transaction array */
tsx = (pjsip_transaction**) pj_pool_zalloc(request->pool, working_set * sizeof(pj_pool_t*));
pj_bzero(&mod_tsx_user, sizeof(mod_tsx_user));
mod_tsx_user.id = -1;
/* Benchmark */
elapsed.u64 = 0;
pj_get_timestamp(&t1);
for (i=0; i<working_set; ++i) {
via->branch_param.ptr = branch_buf;
via->branch_param.slen = PJSIP_RFC3261_BRANCH_LEN +
pj_ansi_sprintf(branch_buf+PJSIP_RFC3261_BRANCH_LEN,
"-%d", i);
status = pjsip_tsx_create_uas(&mod_tsx_user, &rdata, &tsx[i]);
if (status != PJ_SUCCESS)
goto on_error;
}
pj_get_timestamp(&t2);
pj_sub_timestamp(&t2, &t1);
pj_add_timestamp(&elapsed, &t2);
p_elapsed->u64 = elapsed.u64;
status = PJ_SUCCESS;
on_error:
for (i=0; i<working_set; ++i) {
if (tsx[i]) {
pjsip_tsx_terminate(tsx[i], 601);
tsx[i] = NULL;
}
}
pjsip_tx_data_dec_ref(request);
flush_events(2000);
return status;
}