diff --git a/overlay_queue.c b/overlay_queue.c index 1989f725..21d17091 100644 --- a/overlay_queue.c +++ b/overlay_queue.c @@ -52,7 +52,7 @@ struct sched_ent next_packet; struct profile_total send_packet; static void overlay_send_packet(struct sched_ent *alarm); -static void overlay_update_queue_schedule(overlay_txqueue *queue, struct overlay_frame *frame); +static int overlay_calc_queue_time(overlay_txqueue *queue, struct overlay_frame *frame); int overlay_queue_init(){ /* Set default congestion levels for queues */ @@ -62,6 +62,7 @@ int overlay_queue_init(){ overlay_tx[i].latencyTarget=1000; /* Keep packets in queue for 1 second by default */ } /* expire voice/video call packets much sooner, as they just aren't any use if late */ + overlay_tx[OQ_ISOCHRONOUS_VOICE].maxLength=20; overlay_tx[OQ_ISOCHRONOUS_VOICE].latencyTarget=200; overlay_tx[OQ_ISOCHRONOUS_VIDEO].latencyTarget=200; return 0; @@ -217,7 +218,7 @@ int overlay_payload_enqueue(struct overlay_frame *p) if (p->queue==OQ_ISOCHRONOUS_VOICE) rhizome_saw_voice_traffic(); - overlay_update_queue_schedule(queue, p); + overlay_calc_queue_time(queue, p); return 0; } @@ -276,21 +277,24 @@ overlay_calc_queue_time(overlay_txqueue *queue, struct overlay_frame *frame){ if (next_allowed_packet==0||next_packet < next_allowed_packet) next_allowed_packet = next_packet; } + if (next_allowed_packet==0) + return 0; } if (next_packet.alarm==0 || next_allowed_packet < next_packet.alarm){ + if (!next_packet.function){ + next_packet.function=overlay_send_packet; + send_packet.name="overlay_send_packet"; + next_packet.stats=&send_packet; + } + unschedule(&next_packet); next_packet.alarm=next_allowed_packet; - // no grace period, send IO ASAP - next_packet.deadline=next_allowed_packet; - ret = 1; + // small grace period, we want to read incoming IO first + next_packet.deadline=next_allowed_packet+15; + schedule(&next_packet); } - if (!next_packet.function){ - next_packet.function=overlay_send_packet; - send_packet.name="overlay_send_packet"; - next_packet.stats=&send_packet; - } - return ret; + return 0; } static void @@ -431,11 +435,8 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim if (frame->destination_resolved){ frame->send_copies --; - if (frame->send_copies>0){ + if (frame->send_copies>0) keep_payload=1; - // make sure we don't schedule the next alarm immediately - frame->enqueued_at=gettime_ms(); - } }else{ int i; frame->broadcast_sent_via[packet->i]=1; @@ -479,9 +480,6 @@ overlay_fill_send_packet(struct outgoing_packet *packet, time_ms_t now) { overlay_stuff_packet(packet, queue, now); } - if (next_packet.alarm) - schedule(&next_packet); - if(packet->buffer){ if (ob_position(packet->buffer) > packet->header_length){ @@ -514,14 +512,6 @@ static void overlay_send_packet(struct sched_ent *alarm){ overlay_fill_send_packet(&packet, gettime_ms()); } -// update time for next alarm and reschedule -static void overlay_update_queue_schedule(overlay_txqueue *queue, struct overlay_frame *frame){ - if (overlay_calc_queue_time(queue, frame)){ - unschedule(&next_packet); - schedule(&next_packet); - } -} - int overlay_tick_interface(int i, time_ms_t now) { struct outgoing_packet packet; @@ -532,7 +522,7 @@ overlay_tick_interface(int i, time_ms_t now) { } if (limit_is_allowed(&overlay_interfaces[i].transfer_limit)){ - WARN("Throttling has blocked a tick packet"); + //WARN("Throttling has blocked a tick packet"); RETURN(-1); } diff --git a/vomp.c b/vomp.c index 165fca66..0b3bfbde 100644 --- a/vomp.c +++ b/vomp.c @@ -227,7 +227,7 @@ char vomp_dtmf_digit_to_char(int digit) return '?'; } -static int store_jitter_sample(struct jitter_measurements *measurements, int sample_clock, int local_clock){ +static int store_jitter_sample(struct jitter_measurements *measurements, int sample_clock, int local_clock, int *delay){ IN(); int i, count=0; @@ -298,6 +298,8 @@ static int store_jitter_sample(struct jitter_measurements *measurements, int sam if (sample_clock > measurements->max_sample_clock) measurements->max_sample_clock=sample_clock; + *delay=sample->delta - measurements->sorted_samples[0]->delta; + RETURN(0); } @@ -307,10 +309,9 @@ static int get_jitter_size(struct jitter_measurements *measurements){ int jitter; if (i>=measurements->sample_count) i=measurements->sample_count -1; - do{ - jitter=measurements->sorted_samples[i]->delta - measurements->sorted_samples[0]->delta; - i--; - }while(jitter > 1500); + jitter=measurements->sorted_samples[i]->delta - measurements->sorted_samples[0]->delta; + if (jitter < 60) + jitter=60; RETURN(jitter); } @@ -582,7 +583,7 @@ static int monitor_call_status(struct vomp_call_state *call) } static int monitor_send_audio(struct vomp_call_state *call, int audio_codec, int time, int sequence, - const unsigned char *audio, int audio_length) + const unsigned char *audio, int audio_length, int delay) { if (0) DEBUGF("Tell call monitor about audio for call %06x:%06x", call->local.session,call->remote.session); @@ -595,11 +596,11 @@ static int monitor_send_audio(struct vomp_call_state *call, int audio_codec, int int jitter_delay = get_jitter_size(&call->jitter); int msglen = snprintf(msg, 1024, - "\n*%d:AUDIO:%x:%d:%d:%d:%d\n", + "\n*%d:AUDIO:%x:%d:%d:%d:%d:%d\n", audio_length, call->local.session, audio_codec, time, sequence, - jitter_delay); + jitter_delay, delay); bcopy(audio, &msg[msglen], audio_length); msglen+=audio_length; @@ -730,15 +731,16 @@ static int vomp_process_audio(struct vomp_call_state *call, overlay_mdp_frame *m time=call->remote_audio_clock * 20; int audio_len = mdp->in.payload_length - ofs; - - if (store_jitter_sample(&call->jitter, time, now)) + int delay=0; + + if (store_jitter_sample(&call->jitter, time, now, &delay)) return 0; /* Pass audio frame to all registered listeners */ if (monitor_socket_count) monitor_send_audio(call, codec, time, call->remote.sequence, &mdp->in.payload[ofs], - audio_len); + audio_len, delay); return 0; }