libobs: Fix audio monitoring delaying perpetually

On windows, when a source has only audio (no video) yet is marked as
capable of both video and audio, it would be programmed to expect a
video frame to synchronize with.  This fixes that potential issue by
detecting whether any video is actually playing or not.
This commit is contained in:
jp9000 2017-02-21 10:59:02 -08:00
parent eb90b7dfff
commit 528325578f

View File

@ -30,6 +30,8 @@ struct audio_monitor {
IAudioRenderClient *render;
uint64_t last_recv_time;
uint64_t prev_video_ts;
uint64_t time_since_prev;
audio_resampler_t *resampler;
uint32_t sample_rate;
uint32_t channels;
@ -66,6 +68,16 @@ static bool process_audio_delay(struct audio_monitor *monitor,
circlebuf_push_back(&monitor->delay_buffer, *data,
*frames * blocksize);
if (!monitor->prev_video_ts) {
monitor->prev_video_ts = last_frame_ts;
} else if (monitor->prev_video_ts == last_frame_ts) {
monitor->time_since_prev += (uint64_t)*frames *
1000000000ULL / (uint64_t)monitor->sample_rate;
} else {
monitor->time_since_prev = 0;
}
while (monitor->delay_buffer.size != 0) {
size_t size;
bool bad_diff;
@ -76,7 +88,9 @@ static bool process_audio_delay(struct audio_monitor *monitor,
((uint64_t)pad * 1000000000ULL /
(uint64_t)monitor->sample_rate);
diff = (int64_t)front_ts - (int64_t)last_frame_ts;
bad_diff = llabs(diff) > 5000000000;
bad_diff = !last_frame_ts ||
llabs(diff) > 5000000000 ||
monitor->time_since_prev > 100000000ULL;
/* delay audio if rushing */
if (!bad_diff && diff > 75000000) {