Skip to content

Commit

Permalink
fix playback restart after stop() in repeat mode wang-bin#670
Browse files Browse the repository at this point in the history
AVPlayer.currentRepeat() < 0 if playback is stopped. Previous was 0
  • Loading branch information
wang-bin committed Jul 6, 2016
1 parent fb2ca6e commit 4746975
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion examples/player/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ bool MainWindow::setRenderer(QtAV::VideoRenderer *renderer)
mpOSD->installTo(mpRenderer);
mpSubtitle->installTo(mpRenderer);
onUserShaderChanged();
#define GL_ASS 0
#if GL_ASS
GLSLFilter* glsl = new GLSLFilter(this);
glsl->setOutputSize(QSize(4096, 2160));
Expand Down Expand Up @@ -861,7 +862,7 @@ void MainWindow::onStartPlay()
void MainWindow::onStopPlay()
{
mpPlayer->setPriority(idsFromNames(Config::instance().decoderPriorityNames()));
if (mpPlayer->currentRepeat() < mpPlayer->repeat())
if (mpPlayer->currentRepeat() >= 0 && mpPlayer->currentRepeat() < mpPlayer->repeat())
return;
// use shortcut to replay in EventFilter, the options will not be set, so set here
mpPlayer->setFrameRate(Config::instance().forceFrameRate());
Expand Down
9 changes: 6 additions & 3 deletions src/AVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,8 @@ void AVPlayer::playInternal()
QMetaObject::invokeMethod(this, "startNotifyTimer", Qt::AutoConnection);
}
d->state = PlayingState;
if (d->repeat_current < 0)
d->repeat_current = 0;
} //end lock scoped here to avoid dead lock if connect started() to a slot that call unload()/play()
if (d->start_position_norm > 0) {
if (relativeTimeMode())
Expand All @@ -1243,15 +1245,16 @@ void AVPlayer::playInternal()

void AVPlayer::stopFromDemuxerThread()
{
qDebug("demuxer thread emit finished.");
qDebug("demuxer thread emit finished. repeat: %d/%d", currentRepeat(), repeat());
d->seeking = false;
if (currentRepeat() >= repeat() && repeat() >= 0) {
if (currentRepeat() < 0 || (currentRepeat() >= repeat() && repeat() >= 0)) {
qreal stop_pts = masterClock()->videoTime();
if (stop_pts <= 0)
stop_pts = masterClock()->value();
masterClock()->reset();
stopNotifyTimer();
// vars not set by user can be reset
d->repeat_current = -1;
d->start_position_norm = 0;
d->stop_position_norm = kInvalidPosition; // already stopped. so not 0 but invalid. 0 can stop the playback in timerEvent
d->media_end = kInvalidPosition;
Expand Down Expand Up @@ -1396,7 +1399,7 @@ void AVPlayer::stop()
}
d->seeking = false;
d->reset_state = true;

d->repeat_current = -1;
if (!isPlaying()) {
qDebug("Not playing~");
if (mediaStatus() == LoadingMedia || mediaStatus() == LoadedMedia) {
Expand Down
2 changes: 1 addition & 1 deletion src/AVPlayerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ AVPlayer::Private::Private()
, start_position_norm(0)
, stop_position_norm(kInvalidPosition)
, repeat_max(0)
, repeat_current(0)
, repeat_current(-1)
, timer_id(-1)
, audio_track(0)
, video_track(0)
Expand Down
4 changes: 4 additions & 0 deletions src/QtAV/AVPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ class Q_AV_EXPORT AVPlayer : public QObject
qint64 position() const; //unit: ms
//0: play once. N: play N+1 times. <0: infinity
int repeat() const; //or repeatMax()?
/*!
* \brief currentRepeat
* \return -1 if not playback is stopped, otherwise (Playback times - 1)
*/
int currentRepeat() const;
/*!
* \brief setExternalAudio
Expand Down

0 comments on commit 4746975

Please sign in to comment.