mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	various places: Include resampler delay to latency reports and calculations
The resampler delay was not taken into account in all necessary places. This patch adds it where required. Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/708>
This commit is contained in:
		
							parent
							
								
									3271020747
								
							
						
					
					
						commit
						2af10cf39b
					
				
					 9 changed files with 31 additions and 0 deletions
				
			
		| 
						 | 
					@ -460,6 +460,9 @@ static int sink_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t of
 | 
				
			||||||
                /* Add the latency internal to our sink input on top */
 | 
					                /* Add the latency internal to our sink input on top */
 | 
				
			||||||
                pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
 | 
					                pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /* Add resampler delay */
 | 
				
			||||||
 | 
					            *((int64_t*) data) += pa_resampler_get_delay_usec(u->sink_input->thread_info.resampler);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1053,6 +1056,9 @@ static void source_output_snapshot_within_thread(struct userdata *u, struct snap
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    now = pa_rtclock_now();
 | 
					    now = pa_rtclock_now();
 | 
				
			||||||
    latency = pa_source_get_latency_within_thread(u->source_output->source, false);
 | 
					    latency = pa_source_get_latency_within_thread(u->source_output->source, false);
 | 
				
			||||||
 | 
					    /* Add resampler delay */
 | 
				
			||||||
 | 
					    latency += pa_resampler_get_delay_usec(u->source_output->thread_info.resampler);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    delay = pa_memblockq_get_length(u->source_output->thread_info.delay_memblockq);
 | 
					    delay = pa_memblockq_get_length(u->source_output->thread_info.delay_memblockq);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    delay = (u->source_output->thread_info.resampler ? pa_resampler_request(u->source_output->thread_info.resampler, delay) : delay);
 | 
					    delay = (u->source_output->thread_info.resampler ? pa_resampler_request(u->source_output->thread_info.resampler, delay) : delay);
 | 
				
			||||||
| 
						 | 
					@ -1132,6 +1138,9 @@ static int sink_input_process_msg_cb(pa_msgobject *obj, int code, void *data, in
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            now = pa_rtclock_now();
 | 
					            now = pa_rtclock_now();
 | 
				
			||||||
            latency = pa_sink_get_latency_within_thread(u->sink_input->sink, false);
 | 
					            latency = pa_sink_get_latency_within_thread(u->sink_input->sink, false);
 | 
				
			||||||
 | 
					            /* Add resampler delay */
 | 
				
			||||||
 | 
					            latency += pa_resampler_get_delay_usec(u->sink_input->thread_info.resampler);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            delay = pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq);
 | 
					            delay = pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            delay = (u->sink_input->thread_info.resampler ? pa_resampler_request(u->sink_input->thread_info.resampler, delay) : delay);
 | 
					            delay = (u->sink_input->thread_info.resampler ? pa_resampler_request(u->sink_input->thread_info.resampler, delay) : delay);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -771,6 +771,8 @@ static int sink_input_process_msg(pa_msgobject *obj, int code, void *data, int64
 | 
				
			||||||
            /* Add content of memblockq's to sink latency */
 | 
					            /* Add content of memblockq's to sink latency */
 | 
				
			||||||
            o->latency_snapshot.sink_latency = pa_sink_get_latency_within_thread(o->sink, true) +
 | 
					            o->latency_snapshot.sink_latency = pa_sink_get_latency_within_thread(o->sink, true) +
 | 
				
			||||||
                                               pa_bytes_to_usec(length, &o->sink->sample_spec);
 | 
					                                               pa_bytes_to_usec(length, &o->sink->sample_spec);
 | 
				
			||||||
 | 
					            /* Add resampler latency */
 | 
				
			||||||
 | 
					            o->latency_snapshot.sink_latency += pa_resampler_get_delay_usec(o->sink_input->thread_info.resampler);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            o->latency_snapshot.timestamp = pa_rtclock_now();
 | 
					            o->latency_snapshot.timestamp = pa_rtclock_now();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -265,6 +265,9 @@ static int sink_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t of
 | 
				
			||||||
                pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
 | 
					                pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
 | 
				
			||||||
            //    pa_bytes_to_usec(u->samples_gathered * fs, &u->sink->sample_spec);
 | 
					            //    pa_bytes_to_usec(u->samples_gathered * fs, &u->sink->sample_spec);
 | 
				
			||||||
            //+ pa_bytes_to_usec(u->latency * fs, ss)
 | 
					            //+ pa_bytes_to_usec(u->latency * fs, ss)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /* Add resampler latency */
 | 
				
			||||||
 | 
					            *((int64_t*) data) += pa_resampler_get_delay_usec(u->sink_input->thread_info.resampler);
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -361,6 +361,9 @@ static int sink_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t of
 | 
				
			||||||
            /* Add the latency internal to our sink input on top */
 | 
					            /* Add the latency internal to our sink input on top */
 | 
				
			||||||
            pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
 | 
					            pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /* Add resampler latency */
 | 
				
			||||||
 | 
					            *((int64_t*) data) += pa_resampler_get_delay_usec(u->sink_input->thread_info.resampler);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case LADSPA_SINK_MESSAGE_UPDATE_PARAMETERS:
 | 
					    case LADSPA_SINK_MESSAGE_UPDATE_PARAMETERS:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -93,6 +93,9 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
 | 
				
			||||||
                /* Add the latency internal to our sink input on top */
 | 
					                /* Add the latency internal to our sink input on top */
 | 
				
			||||||
                pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
 | 
					                pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /* Add resampler latency */
 | 
				
			||||||
 | 
					            *((int64_t*) data) += pa_resampler_get_delay_usec(u->sink_input->thread_info.resampler);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -105,6 +105,9 @@ static int sink_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t of
 | 
				
			||||||
                /* Add the latency internal to our sink input on top */
 | 
					                /* Add the latency internal to our sink input on top */
 | 
				
			||||||
                pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
 | 
					                pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /* Add resampler latency */
 | 
				
			||||||
 | 
					            *((int64_t*) data) += pa_resampler_get_delay_usec(u->sink_input->thread_info.resampler);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -280,6 +280,9 @@ static int sink_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t of
 | 
				
			||||||
                /* Add the latency internal to our sink input on top */
 | 
					                /* Add the latency internal to our sink input on top */
 | 
				
			||||||
                pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
 | 
					                pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /* Add resampler latency */
 | 
				
			||||||
 | 
					            *((int64_t*) data) += pa_resampler_get_delay_usec(u->sink_input->thread_info.resampler);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -285,6 +285,7 @@ static int rtpoll_work_cb(pa_rtpoll_item *i) {
 | 
				
			||||||
        pa_log_debug("wi=%lu ri=%lu", (unsigned long) wi, (unsigned long) ri);
 | 
					        pa_log_debug("wi=%lu ri=%lu", (unsigned long) wi, (unsigned long) ri);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        sink_delay = pa_sink_get_latency_within_thread(s->sink_input->sink, false);
 | 
					        sink_delay = pa_sink_get_latency_within_thread(s->sink_input->sink, false);
 | 
				
			||||||
 | 
					        sink_delay += pa_resampler_get_delay_usec(s->sink_input->thread_info.resampler);
 | 
				
			||||||
        render_delay = pa_bytes_to_usec(pa_memblockq_get_length(s->sink_input->thread_info.render_memblockq), &s->sink_input->sink->sample_spec);
 | 
					        render_delay = pa_bytes_to_usec(pa_memblockq_get_length(s->sink_input->thread_info.render_memblockq), &s->sink_input->sink->sample_spec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (ri > render_delay+sink_delay)
 | 
					        if (ri > render_delay+sink_delay)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1422,6 +1422,8 @@ static int sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int
 | 
				
			||||||
            s->write_index = pa_memblockq_get_write_index(s->memblockq);
 | 
					            s->write_index = pa_memblockq_get_write_index(s->memblockq);
 | 
				
			||||||
            s->render_memblockq_length = pa_memblockq_get_length(s->sink_input->thread_info.render_memblockq);
 | 
					            s->render_memblockq_length = pa_memblockq_get_length(s->sink_input->thread_info.render_memblockq);
 | 
				
			||||||
            s->current_sink_latency = pa_sink_get_latency_within_thread(s->sink_input->sink, false);
 | 
					            s->current_sink_latency = pa_sink_get_latency_within_thread(s->sink_input->sink, false);
 | 
				
			||||||
 | 
					            /* Add resampler latency */
 | 
				
			||||||
 | 
					            s->current_sink_latency += pa_resampler_get_delay_usec(i->thread_info.resampler);
 | 
				
			||||||
            s->underrun_for = s->sink_input->thread_info.underrun_for;
 | 
					            s->underrun_for = s->sink_input->thread_info.underrun_for;
 | 
				
			||||||
            s->playing_for = s->sink_input->thread_info.playing_for;
 | 
					            s->playing_for = s->sink_input->thread_info.playing_for;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1700,6 +1702,8 @@ static int source_output_process_msg(pa_msgobject *_o, int code, void *userdata,
 | 
				
			||||||
            /* Atomically get a snapshot of all timing parameters... */
 | 
					            /* Atomically get a snapshot of all timing parameters... */
 | 
				
			||||||
            s->current_monitor_latency = o->source->monitor_of ? pa_sink_get_latency_within_thread(o->source->monitor_of, false) : 0;
 | 
					            s->current_monitor_latency = o->source->monitor_of ? pa_sink_get_latency_within_thread(o->source->monitor_of, false) : 0;
 | 
				
			||||||
            s->current_source_latency = pa_source_get_latency_within_thread(o->source, false);
 | 
					            s->current_source_latency = pa_source_get_latency_within_thread(o->source, false);
 | 
				
			||||||
 | 
					            /* Add resampler latency */
 | 
				
			||||||
 | 
					            s->current_source_latency += pa_resampler_get_delay_usec(o->thread_info.resampler);
 | 
				
			||||||
            s->on_the_fly_snapshot = pa_atomic_load(&s->on_the_fly);
 | 
					            s->on_the_fly_snapshot = pa_atomic_load(&s->on_the_fly);
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue