jack-sink: fix latency calculation

The compiler warned about number_of_frames being possibly used
uninitialized, and on closer inspection I found that it was indeed not
initialized if saved_frame_time_valid is false.

In commit fe70b9e11a "source/sink: Allow pa_{source,
sink}_get_latency_within_thread() to return negative values" the
number_of_frames variable was added as an unsigned version of the l
variable, and number_of_frames partially replaced the l variable. The
replacement should have gone all the way, however. This patch removes
the remaining uses of the l variable and substitutes number_of_frames
on its place, and as a result, number_of_frames is now always
initialized.
This commit is contained in:
Tanu Kaskinen 2017-05-02 16:44:29 +03:00
parent 1c477fcb67
commit 4e3aa53a3f

View file

@ -165,14 +165,14 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
return 0; return 0;
case PA_SINK_MESSAGE_GET_LATENCY: { case PA_SINK_MESSAGE_GET_LATENCY: {
jack_nframes_t l, ft, d; jack_nframes_t ft, d;
jack_latency_range_t r; jack_latency_range_t r;
size_t n; size_t n;
int32_t number_of_frames; int32_t number_of_frames;
/* This is the "worst-case" latency */ /* This is the "worst-case" latency */
jack_port_get_latency_range(u->port[0], JackPlaybackLatency, &r); jack_port_get_latency_range(u->port[0], JackPlaybackLatency, &r);
l = r.max + u->frames_in_buffer; number_of_frames = r.max + u->frames_in_buffer;
if (u->saved_frame_time_valid) { if (u->saved_frame_time_valid) {
/* Adjust the worst case latency by the time that /* Adjust the worst case latency by the time that
@ -180,7 +180,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
ft = jack_frame_time(u->client); ft = jack_frame_time(u->client);
d = ft > u->saved_frame_time ? ft - u->saved_frame_time : 0; d = ft > u->saved_frame_time ? ft - u->saved_frame_time : 0;
number_of_frames = (int32_t)l - d; number_of_frames -= d;
} }
/* Convert it to usec */ /* Convert it to usec */