Skip to content

Commit

Permalink
no frame drop for step forward seeking
Browse files Browse the repository at this point in the history
currently record the decoded pts. so frame drop cause  earlier previous
pts.
seeking is slower. If use the packet pts, we must reorder the pts list
and record the current rendered pts.
bug: stepforward may not work and video playback is fast after
stepbackward
  • Loading branch information
wang-bin committed Oct 6, 2015
1 parent e4201d6 commit 38d736e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/AVDemuxThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ void AVDemuxThread::stepBackward()
pts = ts.back();
}
qDebug("step backward: %lld, %f", qint64(pts*1000.0), pts);
demux_thread->video_thread->setDropFrameOnSeek(false);
demux_thread->seekInternal(qint64(pts*1000.0), AccurateSeek);
}
private:
Expand Down Expand Up @@ -216,6 +217,8 @@ void AVDemuxThread::seek(qint64 pos, SeekType type)
, position(t)
{}
void run() {
if (demux_thread->video_thread)
demux_thread->video_thread->setDropFrameOnSeek(true);
demux_thread->seekInternal(position, type);
}
private:
Expand Down
2 changes: 2 additions & 0 deletions src/AVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,8 @@ void AVPlayer::stepForward()

void AVPlayer::stepBackward()
{
d->clock->pause(true);
Q_EMIT paused(true);
d->read_thread->stepBackward();
}

Expand Down
5 changes: 5 additions & 0 deletions src/AVThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ qreal AVThread::previousHistoryPts() const
return d.pts_history.at(d.pts_history.size() - 2);
}

void AVThread::setDropFrameOnSeek(bool value)
{
d_func().drop_frame_seek = value;
}

// TODO: shall we close decoder here?
void AVThread::stop()
{
Expand Down
1 change: 1 addition & 0 deletions src/AVThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class AVThread : public QThread
void scheduleTask(QRunnable *task);
void scheduleFrameDrop(bool value = true);
qreal previousHistoryPts() const;
void setDropFrameOnSeek(bool value);

public slots:
virtual void stop();
Expand Down
2 changes: 2 additions & 0 deletions src/AVThread_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class AVThreadPrivate : public DPtrPrivate<AVThread>
, statistics(0)
, ready(false)
, render_pts0(-1)
, drop_frame_seek(true)
, pts_history(30, -1)
{
tasks.blockFull(false);
Expand Down Expand Up @@ -85,6 +86,7 @@ class AVThreadPrivate : public DPtrPrivate<AVThread>
qreal render_pts0;

static QVariantHash dec_opt_framedrop, dec_opt_normal;
bool drop_frame_seek;
ring<qreal> pts_history;
};

Expand Down
44 changes: 24 additions & 20 deletions src/VideoThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ void VideoThread::run()
}
if(!pkt.isValid() && !pkt.isEOF()) { // can't seek back if eof packet is read
pkt = d.packets.take(); //wait to dequeue
// TODO: push pts history here and reorder
}
if (pkt.isEOF()) {
d.render_pts0 = -1;
Expand Down Expand Up @@ -427,27 +428,31 @@ void VideoThread::run()
wait_key_frame = false;
}
QVariantHash *dec_opt_old = dec_opt;
if (!seeking) { // MAYBE not seeking
if (nb_dec_slow < kNbSlowFrameDrop) {
if (dec_opt == &d.dec_opt_framedrop) {
qDebug("frame drop normal. nb_dec_slow: %d, line: %d", nb_dec_slow, __LINE__);
dec_opt = &d.dec_opt_normal;
}
} else {
if (dec_opt == &d.dec_opt_normal) {
qDebug("frame drop noref. nb_dec_slow: %d, line: %d", nb_dec_slow, __LINE__);
dec_opt = &d.dec_opt_framedrop;
if (d.drop_frame_seek) {
if (!seeking) { // MAYBE not seeking
if (nb_dec_slow < kNbSlowFrameDrop) {
if (dec_opt == &d.dec_opt_framedrop) {
qDebug("frame drop normal. nb_dec_slow: %d. not seeking", nb_dec_slow);
dec_opt = &d.dec_opt_normal;
}
} else {
if (dec_opt == &d.dec_opt_normal) {
qDebug("frame drop noref. nb_dec_slow: %d too slow. not seeking", nb_dec_slow);
dec_opt = &d.dec_opt_framedrop;
}
}
}
} else { // seeking
if (seek_count > 0) {
if (dec_opt == &d.dec_opt_normal) {
qDebug("seeking... frame drop noref. nb_dec_slow: %d, line: %d", nb_dec_slow, __LINE__);
dec_opt = &d.dec_opt_framedrop;
} else { // seeking
if (seek_count > 0) {
if (dec_opt == &d.dec_opt_normal) {
qDebug("seeking... frame drop noref. nb_dec_slow: %d", nb_dec_slow);
dec_opt = &d.dec_opt_framedrop;
}
} else {
seek_count = -1;
}
} else {
seek_count = -1;
}
} else {
dec_opt = &d.dec_opt_normal;
}

// decoder maybe changed in processNextTask(). code above MUST use d.dec but not dec
Expand Down Expand Up @@ -486,10 +491,9 @@ void VideoThread::run()
if (frame.timestamp() <= 0)
frame.setTimestamp(pkt.pts); // pkt.pts is wrong. >= real timestamp
const qreal pts = frame.timestamp();
d.pts_history.push_back(pts);
// seek finished because we can ensure no packet before seek decoded when render_pts0 is set
//qDebug("pts0: %f, pts: %f", d.render_pts0, pts);
d.pts_history.push_back(pts);

if (d.render_pts0 >= 0.0) {
if (pts < d.render_pts0) {
if (!pkt.isEOF())
Expand Down

0 comments on commit 38d736e

Please sign in to comment.