• Home
  • Raw
  • Download

Lines Matching refs:jitter

175 static spx_int16_t compute_opt_delay(JitterBuffer *jitter)  in compute_opt_delay()  argument
190 tb = jitter->_tb; in compute_opt_delay()
200 if (jitter->latency_tradeoff != 0) in compute_opt_delay()
201 late_factor = jitter->latency_tradeoff * 100.0f / tot_count; in compute_opt_delay()
203 late_factor = jitter->auto_tradeoff * jitter->window_size/tot_count; in compute_opt_delay()
232 latest = ROUND_DOWN(latest, jitter->delay_step); in compute_opt_delay()
259 jitter->auto_tradeoff = 1 + deltaT/TOP_DELAY; in compute_opt_delay()
274 JitterBuffer *jitter = (JitterBuffer*)speex_alloc(sizeof(JitterBuffer)); in jitter_buffer_init() local
275 if (jitter) in jitter_buffer_init()
280 jitter->packets[i].data=NULL; in jitter_buffer_init()
281 jitter->delay_step = step_size; in jitter_buffer_init()
282 jitter->concealment_size = step_size; in jitter_buffer_init()
284 jitter->buffer_margin = 0; in jitter_buffer_init()
285 jitter->late_cutoff = 50; in jitter_buffer_init()
286 jitter->destroy = NULL; in jitter_buffer_init()
287 jitter->latency_tradeoff = 0; in jitter_buffer_init()
288 jitter->auto_adjust = 1; in jitter_buffer_init()
290 jitter_buffer_ctl(jitter, JITTER_BUFFER_SET_MAX_LATE_RATE, &tmp); in jitter_buffer_init()
291 jitter_buffer_reset(jitter); in jitter_buffer_init()
293 return jitter; in jitter_buffer_init()
297 EXPORT void jitter_buffer_reset(JitterBuffer *jitter) in jitter_buffer_reset() argument
302 if (jitter->packets[i].data) in jitter_buffer_reset()
304 if (jitter->destroy) in jitter_buffer_reset()
305 jitter->destroy(jitter->packets[i].data); in jitter_buffer_reset()
307 speex_free(jitter->packets[i].data); in jitter_buffer_reset()
308 jitter->packets[i].data = NULL; in jitter_buffer_reset()
312 jitter->pointer_timestamp = 0; in jitter_buffer_reset()
313 jitter->next_stop = 0; in jitter_buffer_reset()
314 jitter->reset_state = 1; in jitter_buffer_reset()
315 jitter->lost_count = 0; in jitter_buffer_reset()
316 jitter->buffered = 0; in jitter_buffer_reset()
317 jitter->auto_tradeoff = 32000; in jitter_buffer_reset()
321 tb_init(&jitter->_tb[i]); in jitter_buffer_reset()
322 jitter->timeBuffers[i] = &jitter->_tb[i]; in jitter_buffer_reset()
328 EXPORT void jitter_buffer_destroy(JitterBuffer *jitter) in jitter_buffer_destroy() argument
330 jitter_buffer_reset(jitter); in jitter_buffer_destroy()
331 speex_free(jitter); in jitter_buffer_destroy()
335 static void update_timings(JitterBuffer *jitter, spx_int32_t timing) in update_timings() argument
342 if (jitter->timeBuffers[0]->curr_count >= jitter->subwindow_size) in update_timings()
346 struct TimingBuffer *tmp = jitter->timeBuffers[MAX_BUFFERS-1]; in update_timings()
348 jitter->timeBuffers[i] = jitter->timeBuffers[i-1]; in update_timings()
349 jitter->timeBuffers[0] = tmp; in update_timings()
350 tb_init(jitter->timeBuffers[0]); in update_timings()
352 tb_add(jitter->timeBuffers[0], timing); in update_timings()
356 static void shift_timings(JitterBuffer *jitter, spx_int16_t amount) in shift_timings() argument
361 for (j=0;j<jitter->timeBuffers[i]->filled;j++) in shift_timings()
362 jitter->timeBuffers[i]->timing[j] += amount; in shift_timings()
368 EXPORT void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet) in jitter_buffer_put() argument
375 if (!jitter->reset_state) in jitter_buffer_put()
380 …if (jitter->packets[i].data && LE32(jitter->packets[i].timestamp + jitter->packets[i].span, jitter in jitter_buffer_put()
383 if (jitter->destroy) in jitter_buffer_put()
384 jitter->destroy(jitter->packets[i].data); in jitter_buffer_put()
386 speex_free(jitter->packets[i].data); in jitter_buffer_put()
387 jitter->packets[i].data = NULL; in jitter_buffer_put()
394 if (!jitter->reset_state && LT32(packet->timestamp, jitter->next_stop)) in jitter_buffer_put()
396 …update_timings(jitter, ((spx_int32_t)packet->timestamp) - ((spx_int32_t)jitter->next_stop) - jitte… in jitter_buffer_put()
404 if (jitter->lost_count>20) in jitter_buffer_put()
406 jitter_buffer_reset(jitter); in jitter_buffer_put()
410 …if (jitter->reset_state || GE32(packet->timestamp+packet->span+jitter->delay_step, jitter->pointer… in jitter_buffer_put()
416 if (jitter->packets[i].data==NULL) in jitter_buffer_put()
423 int earliest=jitter->packets[0].timestamp; in jitter_buffer_put()
427 if (!jitter->packets[i].data || LT32(jitter->packets[j].timestamp,earliest)) in jitter_buffer_put()
429 earliest = jitter->packets[j].timestamp; in jitter_buffer_put()
433 if (jitter->destroy) in jitter_buffer_put()
434 jitter->destroy(jitter->packets[i].data); in jitter_buffer_put()
436 speex_free(jitter->packets[i].data); in jitter_buffer_put()
437 jitter->packets[i].data=NULL; in jitter_buffer_put()
442 if (jitter->destroy) in jitter_buffer_put()
444 jitter->packets[i].data = packet->data; in jitter_buffer_put()
446 jitter->packets[i].data=(char*)speex_alloc(packet->len); in jitter_buffer_put()
448 jitter->packets[i].data[j]=packet->data[j]; in jitter_buffer_put()
450 jitter->packets[i].timestamp=packet->timestamp; in jitter_buffer_put()
451 jitter->packets[i].span=packet->span; in jitter_buffer_put()
452 jitter->packets[i].len=packet->len; in jitter_buffer_put()
453 jitter->packets[i].sequence=packet->sequence; in jitter_buffer_put()
454 jitter->packets[i].user_data=packet->user_data; in jitter_buffer_put()
455 if (jitter->reset_state || late) in jitter_buffer_put()
456 jitter->arrival[i] = 0; in jitter_buffer_put()
458 jitter->arrival[i] = jitter->next_stop; in jitter_buffer_put()
465 EXPORT int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t desired_… in jitter_buffer_get() argument
476 if (jitter->reset_state) in jitter_buffer_get()
483 if (jitter->packets[i].data && (!found || LT32(jitter->packets[i].timestamp,oldest))) in jitter_buffer_get()
485 oldest = jitter->packets[i].timestamp; in jitter_buffer_get()
491 jitter->reset_state=0; in jitter_buffer_get()
492 jitter->pointer_timestamp = oldest; in jitter_buffer_get()
493 jitter->next_stop = oldest; in jitter_buffer_get()
496 packet->span = jitter->interp_requested; in jitter_buffer_get()
502 jitter->last_returned_timestamp = jitter->pointer_timestamp; in jitter_buffer_get()
504 if (jitter->interp_requested != 0) in jitter_buffer_get()
506 packet->timestamp = jitter->pointer_timestamp; in jitter_buffer_get()
507 packet->span = jitter->interp_requested; in jitter_buffer_get()
510 jitter->pointer_timestamp += jitter->interp_requested; in jitter_buffer_get()
514 jitter->interp_requested = 0; in jitter_buffer_get()
516 jitter->buffered = packet->span - desired_span; in jitter_buffer_get()
526 …(jitter->packets[i].data && jitter->packets[i].timestamp==jitter->pointer_timestamp && GE32(jitter in jitter_buffer_get()
535jitter->packets[i].data && LE32(jitter->packets[i].timestamp, jitter->pointer_timestamp) && GE32(j… in jitter_buffer_get()
545jitter->packets[i].data && LE32(jitter->packets[i].timestamp, jitter->pointer_timestamp) && GT32(j… in jitter_buffer_get()
560 …if (jitter->packets[i].data && LT32(jitter->packets[i].timestamp,jitter->pointer_timestamp+desired… in jitter_buffer_get()
562 …if (!found || LT32(jitter->packets[i].timestamp,best_time) || (jitter->packets[i].timestamp==best_… in jitter_buffer_get()
564 best_time = jitter->packets[i].timestamp; in jitter_buffer_get()
565 best_span = jitter->packets[i].span; in jitter_buffer_get()
585 jitter->lost_count = 0; in jitter_buffer_get()
588 if (jitter->arrival[i] != 0) in jitter_buffer_get()
590 …update_timings(jitter, ((spx_int32_t)jitter->packets[i].timestamp) - ((spx_int32_t)jitter->arrival… in jitter_buffer_get()
595 if (jitter->destroy) in jitter_buffer_get()
597 packet->data = jitter->packets[i].data; in jitter_buffer_get()
598 packet->len = jitter->packets[i].len; in jitter_buffer_get()
600 if (jitter->packets[i].len > packet->len) in jitter_buffer_get()
602 …speex_warning_int("jitter_buffer_get(): packet too large to fit. Size is", jitter->packets[i].len); in jitter_buffer_get()
604 packet->len = jitter->packets[i].len; in jitter_buffer_get()
607 packet->data[j] = jitter->packets[i].data[j]; in jitter_buffer_get()
609 speex_free(jitter->packets[i].data); in jitter_buffer_get()
611 jitter->packets[i].data = NULL; in jitter_buffer_get()
613 offset = (spx_int32_t)jitter->packets[i].timestamp-(spx_int32_t)jitter->pointer_timestamp; in jitter_buffer_get()
619 packet->timestamp = jitter->packets[i].timestamp; in jitter_buffer_get()
620 jitter->last_returned_timestamp = packet->timestamp; in jitter_buffer_get()
622 packet->span = jitter->packets[i].span; in jitter_buffer_get()
623 packet->sequence = jitter->packets[i].sequence; in jitter_buffer_get()
624 packet->user_data = jitter->packets[i].user_data; in jitter_buffer_get()
626 jitter->pointer_timestamp = jitter->packets[i].timestamp+jitter->packets[i].span; in jitter_buffer_get()
628 jitter->buffered = packet->span - desired_span; in jitter_buffer_get()
631 jitter->buffered += *start_offset; in jitter_buffer_get()
640 jitter->lost_count++; in jitter_buffer_get()
644 opt = compute_opt_delay(jitter); in jitter_buffer_get()
652 shift_timings(jitter, -opt); in jitter_buffer_get()
654 packet->timestamp = jitter->pointer_timestamp; in jitter_buffer_get()
659 jitter->buffered = packet->span - desired_span; in jitter_buffer_get()
665 packet->timestamp = jitter->pointer_timestamp; in jitter_buffer_get()
667 desired_span = ROUND_DOWN(desired_span, jitter->concealment_size); in jitter_buffer_get()
669 jitter->pointer_timestamp += desired_span; in jitter_buffer_get()
672 jitter->buffered = packet->span - desired_span; in jitter_buffer_get()
680 EXPORT int jitter_buffer_get_another(JitterBuffer *jitter, JitterBufferPacket *packet) in jitter_buffer_get_another() argument
685 if (jitter->packets[i].data && jitter->packets[i].timestamp==jitter->last_returned_timestamp) in jitter_buffer_get_another()
691 packet->len = jitter->packets[i].len; in jitter_buffer_get_another()
692 if (jitter->destroy) in jitter_buffer_get_another()
694 packet->data = jitter->packets[i].data; in jitter_buffer_get_another()
697 packet->data[j] = jitter->packets[i].data[j]; in jitter_buffer_get_another()
699 speex_free(jitter->packets[i].data); in jitter_buffer_get_another()
701 jitter->packets[i].data = NULL; in jitter_buffer_get_another()
702 packet->timestamp = jitter->packets[i].timestamp; in jitter_buffer_get_another()
703 packet->span = jitter->packets[i].span; in jitter_buffer_get_another()
704 packet->sequence = jitter->packets[i].sequence; in jitter_buffer_get_another()
705 packet->user_data = jitter->packets[i].user_data; in jitter_buffer_get_another()
716 static int _jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_… in _jitter_buffer_update_delay() argument
718 spx_int16_t opt = compute_opt_delay(jitter); in _jitter_buffer_update_delay()
723 shift_timings(jitter, -opt); in _jitter_buffer_update_delay()
725 jitter->pointer_timestamp += opt; in _jitter_buffer_update_delay()
726 jitter->interp_requested = -opt; in _jitter_buffer_update_delay()
730 shift_timings(jitter, -opt); in _jitter_buffer_update_delay()
731 jitter->pointer_timestamp += opt; in _jitter_buffer_update_delay()
739 EXPORT int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t… in jitter_buffer_update_delay() argument
743 jitter->auto_adjust = 0; in jitter_buffer_update_delay()
745 return _jitter_buffer_update_delay(jitter, packet, start_offset); in jitter_buffer_update_delay()
749 EXPORT int jitter_buffer_get_pointer_timestamp(JitterBuffer *jitter) in jitter_buffer_get_pointer_timestamp() argument
751 return jitter->pointer_timestamp; in jitter_buffer_get_pointer_timestamp()
754 EXPORT void jitter_buffer_tick(JitterBuffer *jitter) in jitter_buffer_tick() argument
757 if (jitter->auto_adjust) in jitter_buffer_tick()
758 _jitter_buffer_update_delay(jitter, NULL, NULL); in jitter_buffer_tick()
760 if (jitter->buffered >= 0) in jitter_buffer_tick()
762 jitter->next_stop = jitter->pointer_timestamp - jitter->buffered; in jitter_buffer_tick()
764 jitter->next_stop = jitter->pointer_timestamp; in jitter_buffer_tick()
765 …t("jitter buffer sees negative buffering, your code might be broken. Value is ", jitter->buffered); in jitter_buffer_tick()
767 jitter->buffered = 0; in jitter_buffer_tick()
770 EXPORT void jitter_buffer_remaining_span(JitterBuffer *jitter, spx_uint32_t rem) in jitter_buffer_remaining_span() argument
773 if (jitter->auto_adjust) in jitter_buffer_remaining_span()
774 _jitter_buffer_update_delay(jitter, NULL, NULL); in jitter_buffer_remaining_span()
776 if (jitter->buffered < 0) in jitter_buffer_remaining_span()
777 …t("jitter buffer sees negative buffering, your code might be broken. Value is ", jitter->buffered); in jitter_buffer_remaining_span()
778 jitter->next_stop = jitter->pointer_timestamp - rem; in jitter_buffer_remaining_span()
783 EXPORT int jitter_buffer_ctl(JitterBuffer *jitter, int request, void *ptr) in jitter_buffer_ctl() argument
789 jitter->buffer_margin = *(spx_int32_t*)ptr; in jitter_buffer_ctl()
792 *(spx_int32_t*)ptr = jitter->buffer_margin; in jitter_buffer_ctl()
798 … if (jitter->packets[i].data && LE32(jitter->pointer_timestamp, jitter->packets[i].timestamp)) in jitter_buffer_ctl()
806 jitter->destroy = (void (*) (void *))ptr; in jitter_buffer_ctl()
809 *(void (**) (void *))ptr = jitter->destroy; in jitter_buffer_ctl()
812 jitter->delay_step = *(spx_int32_t*)ptr; in jitter_buffer_ctl()
815 *(spx_int32_t*)ptr = jitter->delay_step; in jitter_buffer_ctl()
818 jitter->concealment_size = *(spx_int32_t*)ptr; in jitter_buffer_ctl()
821 *(spx_int32_t*)ptr = jitter->concealment_size; in jitter_buffer_ctl()
824 jitter->max_late_rate = *(spx_int32_t*)ptr; in jitter_buffer_ctl()
825 jitter->window_size = 100*TOP_DELAY/jitter->max_late_rate; in jitter_buffer_ctl()
826 jitter->subwindow_size = jitter->window_size/MAX_BUFFERS; in jitter_buffer_ctl()
829 *(spx_int32_t*)ptr = jitter->max_late_rate; in jitter_buffer_ctl()
832 jitter->latency_tradeoff = *(spx_int32_t*)ptr; in jitter_buffer_ctl()
835 *(spx_int32_t*)ptr = jitter->latency_tradeoff; in jitter_buffer_ctl()