From 03445f7dc9010ed69c340596a11752ae33547e4a Mon Sep 17 00:00:00 2001 From: wang-bin Date: Sat, 16 Jan 2016 20:44:44 +0800 Subject: [PATCH] workaround long wait if seek on a video with short audio --- src/AVDemuxThread.cpp | 5 ++--- src/AudioThread.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/AVDemuxThread.cpp b/src/AVDemuxThread.cpp index 3e9baaaa..6210190d 100644 --- a/src/AVDemuxThread.cpp +++ b/src/AVDemuxThread.cpp @@ -531,8 +531,8 @@ void AVDemuxThread::run() const qreal dpts = last_vpts - last_apts; if (dpts > 0.1) { Packet fake_apkt; - fake_apkt.duration = dpts; // FIXME: too long for seek - qDebug("audio is too short than video: %.3f", dpts); + fake_apkt.duration = last_vpts - qMin(thread->clock()->videoTime(), thread->clock()->value()); // FIXME: when clock value < 0? + qDebug("audio is too short than video: %.3f, fake_apkt.duration: %.3f", dpts, fake_apkt.duration); last_apts = last_vpts = 0; // if not reset to 0, for example real eof pts, then no fake apkt after seek because dpts < 0 aqueue->put(fake_apkt); } @@ -564,7 +564,6 @@ void AVDemuxThread::run() vqueue->blockEmpty(true); } // wait for a/v thread finished - msleep(100); continue; } diff --git a/src/AudioThread.cpp b/src/AudioThread.cpp index 2f946e63..7fc827ac 100644 --- a/src/AudioThread.cpp +++ b/src/AudioThread.cpp @@ -113,8 +113,11 @@ void AudioThread::run() d.dec->flush(); d.render_pts0 = pkt.pts; pkt = Packet(); //mark invalid to take next - fake_duration = fake_duration + fake_pts - d.render_pts0*1000.0; - fake_pts = d.render_pts0*1000.0; + if (fake_duration > 0) { + //qDebug("fake_duration update on seek: %ul + %ul - %.3f", fake_duration, fake_pts, d.render_pts0); + fake_duration = fake_duration + fake_pts - d.render_pts0*1000.0; + fake_pts = d.render_pts0*1000.0; + } d.clock->updateValue(d.render_pts0); d.clock->updateDelay(0); continue;