Package list squeezelite / 789d26f
pa workaround for wdm-ks report of outputBufferDacTime Adrian Smith 7 years ago
2 changed file(s) with 21 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
5757 LOG_WARN("error initialising port audio: %s", Pa_GetErrorText(err));
5858 return;
5959 }
60
60
6161 printf("Output devices:\n");
6262 for (i = 0; i < Pa_GetDeviceCount(); ++i) {
63 printf(" %i - %s [%s]\n", i, Pa_GetDeviceInfo(i)->name, Pa_GetHostApiInfo(Pa_GetDeviceInfo(i)->hostApi)->name);
63 if (Pa_GetDeviceInfo(i)->maxOutputChannels) {
64 printf(" %i - %s [%s]\n", i, Pa_GetDeviceInfo(i)->name, Pa_GetHostApiInfo(Pa_GetDeviceInfo(i)->hostApi)->name);
65 }
6466 }
6567 printf("\n");
66
68
6769 if ((err = Pa_Terminate()) != paNoError) {
6870 LOG_WARN("error closing port audio: %s", Pa_GetErrorText(err));
6971 }
327329 static int pa_callback(const void *pa_input, void *pa_output, unsigned long pa_frames_wanted,
328330 const PaStreamCallbackTimeInfo *time_info, PaStreamCallbackFlags statusFlags, void *userData) {
329331 int ret;
332 double stream_time;
330333 frames_t frames;
331334
332335 optr = (u8_t *)pa_output;
333336
334337 LOCK;
335338
336 output.device_frames = (unsigned)((time_info->outputBufferDacTime - Pa_GetStreamTime(pa.stream)) * output.current_sample_rate);
339 stream_time = Pa_GetStreamTime(pa.stream);
340
341 if (time_info->outputBufferDacTime > stream_time) {
342 // workaround for wdm-ks which can return outputBufferDacTime with a different epoch
343 output.device_frames = (unsigned)((time_info->outputBufferDacTime - stream_time) * output.current_sample_rate);
344 } else {
345 output.device_frames = 0;
346 }
347
337348 output.updated = gettime_ms();
338349
339350 frames = _output_frames(pa_frames_wanted);
131131 if (status.current_sample_rate && status.frames_played && status.frames_played > status.device_frames) {
132132 ms_played = (u32_t)(((u64_t)(status.frames_played - status.device_frames) * (u64_t)1000) / (u64_t)status.current_sample_rate);
133133 if (now > status.updated) ms_played += (now - status.updated);
134 LOG_SDEBUG("ms_played: %u (frames_played: %u device_frames: %u)", ms_played, status.frames_played, status.device_frames);
135 } else if (status.frames_played && now > status.stream_start) {
136 ms_played = now - status.stream_start;
137 LOG_SDEBUG("ms_played: %u using elapsed time (frames_played: %u device_frames: %u)", ms_played, status.frames_played, status.device_frames);
134138 } else {
139 LOG_SDEBUG("ms_played: 0");
135140 ms_played = 0;
136141 }
137142
158163 LOG_INFO("STAT: %s", event);
159164
160165 if (loglevel == lSDEBUG) {
161 LOG_SDEBUG("received bytesL: %u streambuf: %u outputbuf: %u calc elapsed: %u real elapsed: %u (diff: %u) device: %u delay: %d",
166 LOG_SDEBUG("received bytesL: %u streambuf: %u outputbuf: %u calc elapsed: %u real elapsed: %u (diff: %d) device: %u delay: %d",
162167 (u32_t)status.stream_bytes, status.stream_full, status.output_full, ms_played, now - status.stream_start,
163168 ms_played - now + status.stream_start, status.device_frames * 1000 / status.current_sample_rate, now - status.updated);
164169 }