Lines Matching refs:jitter
173 static spx_int16_t compute_opt_delay(JitterBuffer *jitter) in compute_opt_delay() argument
188 tb = jitter->_tb; in compute_opt_delay()
198 if (jitter->latency_tradeoff != 0) in compute_opt_delay()
199 late_factor = jitter->latency_tradeoff * 100.0f / tot_count; in compute_opt_delay()
201 late_factor = jitter->auto_tradeoff * jitter->window_size/tot_count; in compute_opt_delay()
230 latest = ROUND_DOWN(latest, jitter->delay_step); in compute_opt_delay()
257 jitter->auto_tradeoff = 1 + deltaT/TOP_DELAY; in compute_opt_delay()
272 JitterBuffer *jitter = (JitterBuffer*)speex_alloc(sizeof(JitterBuffer)); in jitter_buffer_init() local
273 if (jitter) in jitter_buffer_init()
278 jitter->packets[i].data=NULL; in jitter_buffer_init()
279 jitter->delay_step = step_size; in jitter_buffer_init()
280 jitter->concealment_size = step_size; in jitter_buffer_init()
282 jitter->buffer_margin = 0; in jitter_buffer_init()
283 jitter->late_cutoff = 50; in jitter_buffer_init()
284 jitter->destroy = NULL; in jitter_buffer_init()
285 jitter->latency_tradeoff = 0; in jitter_buffer_init()
286 jitter->auto_adjust = 1; in jitter_buffer_init()
288 jitter_buffer_ctl(jitter, JITTER_BUFFER_SET_MAX_LATE_RATE, &tmp); in jitter_buffer_init()
289 jitter_buffer_reset(jitter); in jitter_buffer_init()
291 return jitter; in jitter_buffer_init()
295 EXPORT void jitter_buffer_reset(JitterBuffer *jitter) in jitter_buffer_reset() argument
300 if (jitter->packets[i].data) in jitter_buffer_reset()
302 if (jitter->destroy) in jitter_buffer_reset()
303 jitter->destroy(jitter->packets[i].data); in jitter_buffer_reset()
305 speex_free(jitter->packets[i].data); in jitter_buffer_reset()
306 jitter->packets[i].data = NULL; in jitter_buffer_reset()
310 jitter->pointer_timestamp = 0; in jitter_buffer_reset()
311 jitter->next_stop = 0; in jitter_buffer_reset()
312 jitter->reset_state = 1; in jitter_buffer_reset()
313 jitter->lost_count = 0; in jitter_buffer_reset()
314 jitter->buffered = 0; in jitter_buffer_reset()
315 jitter->auto_tradeoff = 32000; in jitter_buffer_reset()
319 tb_init(&jitter->_tb[i]); in jitter_buffer_reset()
320 jitter->timeBuffers[i] = &jitter->_tb[i]; in jitter_buffer_reset()
326 EXPORT void jitter_buffer_destroy(JitterBuffer *jitter) in jitter_buffer_destroy() argument
328 jitter_buffer_reset(jitter); in jitter_buffer_destroy()
329 speex_free(jitter); in jitter_buffer_destroy()
333 static void update_timings(JitterBuffer *jitter, spx_int32_t timing) in update_timings() argument
340 if (jitter->timeBuffers[0]->curr_count >= jitter->subwindow_size) in update_timings()
344 struct TimingBuffer *tmp = jitter->timeBuffers[MAX_BUFFERS-1]; in update_timings()
346 jitter->timeBuffers[i] = jitter->timeBuffers[i-1]; in update_timings()
347 jitter->timeBuffers[0] = tmp; in update_timings()
348 tb_init(jitter->timeBuffers[0]); in update_timings()
350 tb_add(jitter->timeBuffers[0], timing); in update_timings()
354 static void shift_timings(JitterBuffer *jitter, spx_int16_t amount) in shift_timings() argument
359 for (j=0;j<jitter->timeBuffers[i]->filled;j++) in shift_timings()
360 jitter->timeBuffers[i]->timing[j] += amount; in shift_timings()
366 EXPORT void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet) in jitter_buffer_put() argument
373 if (!jitter->reset_state) in jitter_buffer_put()
378 …if (jitter->packets[i].data && LE32(jitter->packets[i].timestamp + jitter->packets[i].span, jitter… in jitter_buffer_put()
381 if (jitter->destroy) in jitter_buffer_put()
382 jitter->destroy(jitter->packets[i].data); in jitter_buffer_put()
384 speex_free(jitter->packets[i].data); in jitter_buffer_put()
385 jitter->packets[i].data = NULL; in jitter_buffer_put()
392 if (!jitter->reset_state && LT32(packet->timestamp, jitter->next_stop)) in jitter_buffer_put()
394 …update_timings(jitter, ((spx_int32_t)packet->timestamp) - ((spx_int32_t)jitter->next_stop) - jitte… in jitter_buffer_put()
402 if (jitter->lost_count>20) in jitter_buffer_put()
404 jitter_buffer_reset(jitter); in jitter_buffer_put()
408 …if (jitter->reset_state || GE32(packet->timestamp+packet->span+jitter->delay_step, jitter->pointer… in jitter_buffer_put()
414 if (jitter->packets[i].data==NULL) in jitter_buffer_put()
421 int earliest=jitter->packets[0].timestamp; in jitter_buffer_put()
425 if (!jitter->packets[i].data || LT32(jitter->packets[j].timestamp,earliest)) in jitter_buffer_put()
427 earliest = jitter->packets[j].timestamp; in jitter_buffer_put()
431 if (jitter->destroy) in jitter_buffer_put()
432 jitter->destroy(jitter->packets[i].data); in jitter_buffer_put()
434 speex_free(jitter->packets[i].data); in jitter_buffer_put()
435 jitter->packets[i].data=NULL; in jitter_buffer_put()
440 if (jitter->destroy) in jitter_buffer_put()
442 jitter->packets[i].data = packet->data; in jitter_buffer_put()
444 jitter->packets[i].data=(char*)speex_alloc(packet->len); in jitter_buffer_put()
446 jitter->packets[i].data[j]=packet->data[j]; in jitter_buffer_put()
448 jitter->packets[i].timestamp=packet->timestamp; in jitter_buffer_put()
449 jitter->packets[i].span=packet->span; in jitter_buffer_put()
450 jitter->packets[i].len=packet->len; in jitter_buffer_put()
451 jitter->packets[i].sequence=packet->sequence; in jitter_buffer_put()
452 jitter->packets[i].user_data=packet->user_data; in jitter_buffer_put()
453 if (jitter->reset_state || late) in jitter_buffer_put()
454 jitter->arrival[i] = 0; in jitter_buffer_put()
456 jitter->arrival[i] = jitter->next_stop; in jitter_buffer_put()
463 EXPORT int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t desired_… in jitter_buffer_get() argument
473 if (jitter->reset_state) in jitter_buffer_get()
480 if (jitter->packets[i].data && (!found || LT32(jitter->packets[i].timestamp,oldest))) in jitter_buffer_get()
482 oldest = jitter->packets[i].timestamp; in jitter_buffer_get()
488 jitter->reset_state=0; in jitter_buffer_get()
489 jitter->pointer_timestamp = oldest; in jitter_buffer_get()
490 jitter->next_stop = oldest; in jitter_buffer_get()
493 packet->span = jitter->interp_requested; in jitter_buffer_get()
499 jitter->last_returned_timestamp = jitter->pointer_timestamp; in jitter_buffer_get()
501 if (jitter->interp_requested != 0) in jitter_buffer_get()
503 packet->timestamp = jitter->pointer_timestamp; in jitter_buffer_get()
504 packet->span = jitter->interp_requested; in jitter_buffer_get()
507 jitter->pointer_timestamp += jitter->interp_requested; in jitter_buffer_get()
511 jitter->interp_requested = 0; in jitter_buffer_get()
513 jitter->buffered = packet->span - desired_span; in jitter_buffer_get()
523 …(jitter->packets[i].data && jitter->packets[i].timestamp==jitter->pointer_timestamp && GE32(jitter… in jitter_buffer_get()
532 …jitter->packets[i].data && LE32(jitter->packets[i].timestamp, jitter->pointer_timestamp) && GE32(j… in jitter_buffer_get()
542 …jitter->packets[i].data && LE32(jitter->packets[i].timestamp, jitter->pointer_timestamp) && GT32(j… in jitter_buffer_get()
557 …if (jitter->packets[i].data && LT32(jitter->packets[i].timestamp,jitter->pointer_timestamp+desired… in jitter_buffer_get()
559 …if (!found || LT32(jitter->packets[i].timestamp,best_time) || (jitter->packets[i].timestamp==best_… in jitter_buffer_get()
561 best_time = jitter->packets[i].timestamp; in jitter_buffer_get()
562 best_span = jitter->packets[i].span; in jitter_buffer_get()
581 jitter->lost_count = 0; in jitter_buffer_get()
584 if (jitter->arrival[i] != 0) in jitter_buffer_get()
586 …update_timings(jitter, ((spx_int32_t)jitter->packets[i].timestamp) - ((spx_int32_t)jitter->arrival… in jitter_buffer_get()
591 if (jitter->destroy) in jitter_buffer_get()
593 packet->data = jitter->packets[i].data; in jitter_buffer_get()
594 packet->len = jitter->packets[i].len; in jitter_buffer_get()
596 if (jitter->packets[i].len > packet->len) in jitter_buffer_get()
598 …speex_warning_int("jitter_buffer_get(): packet too large to fit. Size is", jitter->packets[i].len); in jitter_buffer_get()
600 packet->len = jitter->packets[i].len; in jitter_buffer_get()
603 packet->data[j] = jitter->packets[i].data[j]; in jitter_buffer_get()
605 speex_free(jitter->packets[i].data); in jitter_buffer_get()
607 jitter->packets[i].data = NULL; in jitter_buffer_get()
609 offset = (spx_int32_t)jitter->packets[i].timestamp-(spx_int32_t)jitter->pointer_timestamp; in jitter_buffer_get()
615 packet->timestamp = jitter->packets[i].timestamp; in jitter_buffer_get()
616 jitter->last_returned_timestamp = packet->timestamp; in jitter_buffer_get()
618 packet->span = jitter->packets[i].span; in jitter_buffer_get()
619 packet->sequence = jitter->packets[i].sequence; in jitter_buffer_get()
620 packet->user_data = jitter->packets[i].user_data; in jitter_buffer_get()
622 jitter->pointer_timestamp = jitter->packets[i].timestamp+jitter->packets[i].span; in jitter_buffer_get()
624 jitter->buffered = packet->span - desired_span; in jitter_buffer_get()
627 jitter->buffered += *start_offset; in jitter_buffer_get()
636 jitter->lost_count++; in jitter_buffer_get()
640 opt = compute_opt_delay(jitter); in jitter_buffer_get()
648 shift_timings(jitter, -opt); in jitter_buffer_get()
650 packet->timestamp = jitter->pointer_timestamp; in jitter_buffer_get()
655 jitter->buffered = packet->span - desired_span; in jitter_buffer_get()
661 packet->timestamp = jitter->pointer_timestamp; in jitter_buffer_get()
663 desired_span = ROUND_DOWN(desired_span, jitter->concealment_size); in jitter_buffer_get()
665 jitter->pointer_timestamp += desired_span; in jitter_buffer_get()
668 jitter->buffered = packet->span - desired_span; in jitter_buffer_get()
676 EXPORT int jitter_buffer_get_another(JitterBuffer *jitter, JitterBufferPacket *packet) in jitter_buffer_get_another() argument
681 if (jitter->packets[i].data && jitter->packets[i].timestamp==jitter->last_returned_timestamp) in jitter_buffer_get_another()
687 packet->len = jitter->packets[i].len; in jitter_buffer_get_another()
688 if (jitter->destroy) in jitter_buffer_get_another()
690 packet->data = jitter->packets[i].data; in jitter_buffer_get_another()
693 packet->data[j] = jitter->packets[i].data[j]; in jitter_buffer_get_another()
695 speex_free(jitter->packets[i].data); in jitter_buffer_get_another()
697 jitter->packets[i].data = NULL; in jitter_buffer_get_another()
698 packet->timestamp = jitter->packets[i].timestamp; in jitter_buffer_get_another()
699 packet->span = jitter->packets[i].span; in jitter_buffer_get_another()
700 packet->sequence = jitter->packets[i].sequence; in jitter_buffer_get_another()
701 packet->user_data = jitter->packets[i].user_data; in jitter_buffer_get_another()
712 static int _jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_… in _jitter_buffer_update_delay() argument
714 spx_int16_t opt = compute_opt_delay(jitter); in _jitter_buffer_update_delay()
719 shift_timings(jitter, -opt); in _jitter_buffer_update_delay()
721 jitter->pointer_timestamp += opt; in _jitter_buffer_update_delay()
722 jitter->interp_requested = -opt; in _jitter_buffer_update_delay()
726 shift_timings(jitter, -opt); in _jitter_buffer_update_delay()
727 jitter->pointer_timestamp += opt; in _jitter_buffer_update_delay()
735 EXPORT int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t… in jitter_buffer_update_delay() argument
739 jitter->auto_adjust = 0; in jitter_buffer_update_delay()
741 return _jitter_buffer_update_delay(jitter, packet, start_offset); in jitter_buffer_update_delay()
745 EXPORT int jitter_buffer_get_pointer_timestamp(JitterBuffer *jitter) in jitter_buffer_get_pointer_timestamp() argument
747 return jitter->pointer_timestamp; in jitter_buffer_get_pointer_timestamp()
750 EXPORT void jitter_buffer_tick(JitterBuffer *jitter) in jitter_buffer_tick() argument
753 if (jitter->auto_adjust) in jitter_buffer_tick()
754 _jitter_buffer_update_delay(jitter, NULL, NULL); in jitter_buffer_tick()
756 if (jitter->buffered >= 0) in jitter_buffer_tick()
758 jitter->next_stop = jitter->pointer_timestamp - jitter->buffered; in jitter_buffer_tick()
760 jitter->next_stop = jitter->pointer_timestamp; in jitter_buffer_tick()
761 …t("jitter buffer sees negative buffering, your code might be broken. Value is ", jitter->buffered); in jitter_buffer_tick()
763 jitter->buffered = 0; in jitter_buffer_tick()
766 EXPORT void jitter_buffer_remaining_span(JitterBuffer *jitter, spx_uint32_t rem) in jitter_buffer_remaining_span() argument
769 if (jitter->auto_adjust) in jitter_buffer_remaining_span()
770 _jitter_buffer_update_delay(jitter, NULL, NULL); in jitter_buffer_remaining_span()
772 if (jitter->buffered < 0) in jitter_buffer_remaining_span()
773 …t("jitter buffer sees negative buffering, your code might be broken. Value is ", jitter->buffered); in jitter_buffer_remaining_span()
774 jitter->next_stop = jitter->pointer_timestamp - rem; in jitter_buffer_remaining_span()
779 EXPORT int jitter_buffer_ctl(JitterBuffer *jitter, int request, void *ptr) in jitter_buffer_ctl() argument
785 jitter->buffer_margin = *(spx_int32_t*)ptr; in jitter_buffer_ctl()
788 *(spx_int32_t*)ptr = jitter->buffer_margin; in jitter_buffer_ctl()
794 … if (jitter->packets[i].data && LE32(jitter->pointer_timestamp, jitter->packets[i].timestamp)) in jitter_buffer_ctl()
802 jitter->destroy = (void (*) (void *))ptr; in jitter_buffer_ctl()
805 *(void (**) (void *))ptr = jitter->destroy; in jitter_buffer_ctl()
808 jitter->delay_step = *(spx_int32_t*)ptr; in jitter_buffer_ctl()
811 *(spx_int32_t*)ptr = jitter->delay_step; in jitter_buffer_ctl()
814 jitter->concealment_size = *(spx_int32_t*)ptr; in jitter_buffer_ctl()
817 *(spx_int32_t*)ptr = jitter->concealment_size; in jitter_buffer_ctl()
820 jitter->max_late_rate = *(spx_int32_t*)ptr; in jitter_buffer_ctl()
821 jitter->window_size = 100*TOP_DELAY/jitter->max_late_rate; in jitter_buffer_ctl()
822 jitter->subwindow_size = jitter->window_size/MAX_BUFFERS; in jitter_buffer_ctl()
825 *(spx_int32_t*)ptr = jitter->max_late_rate; in jitter_buffer_ctl()
828 jitter->latency_tradeoff = *(spx_int32_t*)ptr; in jitter_buffer_ctl()
831 *(spx_int32_t*)ptr = jitter->latency_tradeoff; in jitter_buffer_ctl()