Skip to content

Commit

Permalink
add AVPlayer.stoppedAt. change state in stop()
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Mar 23, 2016
1 parent ed9366f commit ef76909
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/AVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 80,7 @@ AVPlayer::AVPlayer(QObject *parent) :
d->read_thread = new AVDemuxThread(this);
d->read_thread->setDemuxer(&d->demuxer);
//direct connection can not sure slot order?
connect(d->read_thread, SIGNAL(finished()), this, SLOT(stopFromDemuxerThread()), Qt::DirectConnection); // ensure state after stop() is StoppedState
connect(d->read_thread, SIGNAL(finished()), this, SLOT(stopFromDemuxerThread()));
connect(d->read_thread, SIGNAL(requestClockPause(bool)), masterClock(), SLOT(pause(bool)), Qt::DirectConnection);
connect(d->read_thread, SIGNAL(mediaStatusChanged(QtAV::MediaStatus)), this, SLOT(updateMediaStatus(QtAV::MediaStatus)));
connect(d->read_thread, SIGNAL(bufferProgressChanged(qreal)), this, SIGNAL(bufferProgressChanged(qreal)));
Expand Down Expand Up @@ -1304,6 1304,9 @@ void AVPlayer::stopFromDemuxerThread()
qDebug("demuxer thread emit finished.");
d->seeking = false;
if (currentRepeat() >= repeat() && repeat() >= 0) {
qreal stop_pts = masterClock()->videoTime();
if (stop_pts <= 0)
stop_pts = masterClock()->value();
masterClock()->reset();
stopNotifyTimer();
d->start_position = 0;
Expand All @@ -1314,12 1317,12 @@ void AVPlayer::stopFromDemuxerThread()
d->state = StoppedState;
Q_EMIT stateChanged(d->state);
Q_EMIT stopped();
Q_EMIT stoppedAt(stop_pts*1000.0);
} else {
qDebug("stopPosition() == mediaStopPosition() or !seekable. repeate: %d/%d", currentRepeat(), repeat());
d->repeat_current ;
d->last_position = startPosition(); // for seeking to startPosition() if seekable. already set in stop()
QMetaObject::invokeMethod(this, "play", Qt::AutoConnection);
//play();
play();
}
}

Expand Down Expand Up @@ -1412,7 1415,6 @@ void AVPlayer::tryClearVideoRenderers()
}
}

// TODO: doc about when the state will be reset
void AVPlayer::stop()
{
// check d->timer_id, <0 return?
Expand Down Expand Up @@ -1460,6 1462,7 @@ void AVPlayer::stop()
// interrupt to quit av_read_frame quickly.
d->demuxer.setInterruptStatus(-1);
}
d->state = StoppedState;
qDebug("all audio/video threads stopped...");
}

Expand Down
1 change: 1 addition & 0 deletions src/QtAV/AVPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 516,7 @@ public slots:
void paused(bool p);
void started();
void stopped();
void stoppedAt(qint64 position);
void stateChanged(QtAV::AVPlayer::State state);
void speedChanged(qreal speed);
void repeatChanged(int r);
Expand Down

0 comments on commit ef76909

Please sign in to comment.