@@ -871,21 +871,19 @@ void AVPlayer::setPosition(qint64 position)
871871
872872int AVPlayer::repeat () const
873873{
874- return d->repeat_max ;
874+ return d->read_thread -> getRepeatMax () ;
875875}
876876
877877int AVPlayer::currentRepeat () const
878878{
879- return d->repeat_current ;
879+ return d->read_thread -> getRepeatCurrent () ;
880880}
881881
882882// TODO: reset current_repeat?
883883void AVPlayer::setRepeat (int max)
884884{
885- d->repeat_max = max;
886- if (d->repeat_max < 0 )
887- d->repeat_max = std::numeric_limits<int >::max ();
888- Q_EMIT repeatChanged (d->repeat_max );
885+ d->read_thread ->setRepeatMax (max);
886+ Q_EMIT repeatChanged (d->read_thread ->getRepeatMax ());
889887}
890888
891889bool AVPlayer::setExternalAudio (const QString &file)
@@ -1250,8 +1248,8 @@ void AVPlayer::playInternal()
12501248 QMetaObject::invokeMethod (this , " startNotifyTimer" , Qt::AutoConnection);
12511249 }
12521250 d->state = PlayingState;
1253- if (d-> repeat_current < 0 )
1254- d->repeat_current = 0 ;
1251+ if ( currentRepeat () < 0 )
1252+ d->read_thread -> setRepeatCurrent ( 0 ) ;
12551253 } // end lock scoped here to avoid dead lock if connect started() to a slot that call unload()/play()
12561254 if (d->start_position_norm > 0 ) {
12571255 if (relativeTimeMode ())
@@ -1267,34 +1265,30 @@ void AVPlayer::stopFromDemuxerThread()
12671265{
12681266 qDebug (" demuxer thread emit finished. repeat: %d/%d" , currentRepeat (), repeat ());
12691267 d->seeking = false ;
1270- if (currentRepeat () < 0 || (currentRepeat () >= repeat () && repeat () >= 0 )) {
1271- qreal stop_pts = masterClock ()->videoTime ();
1272- if (stop_pts <= 0 )
1273- stop_pts = masterClock ()->value ();
1274- masterClock ()->reset ();
1275- QMetaObject::invokeMethod (this , " stopNotifyTimer" );
1276- // vars not set by user can be reset
1277- d->repeat_current = -1 ;
1278- d->start_position_norm = 0 ;
1279- d->stop_position_norm = kInvalidPosition ; // already stopped. so not 0 but invalid. 0 can stop the playback in timerEvent
1280- d->media_end = kInvalidPosition ;
1281- qDebug (" avplayer emit stopped()" );
1282- d->state = StoppedState;
1283- QMetaObject::invokeMethod (this , " stateChanged" , Q_ARG (QtAV::AVPlayer::State, d->state ));
1284- QMetaObject::invokeMethod (this , " stopped" );
1285- QMetaObject::invokeMethod (this , " stoppedAt" , Q_ARG (qint64, qint64 (stop_pts*1000.0 )));
1286- // Q_EMIT stateChanged(d->state);
1287- // Q_EMIT stopped();
1288- // Q_EMIT stoppedAt(stop_pts*1000.0);
12891268
1290- /*
1291- * currently preload is not supported. so always unload. Then some properties will be reset, e.g. duration()
1292- */
1293- unload (); // TODO: invoke?
1294- } else {
1295- d->repeat_current ++;
1296- QMetaObject::invokeMethod (this , " play" ); // ensure play() is called from player thread
1297- }
1269+ qreal stop_pts = masterClock ()->videoTime ();
1270+ if (stop_pts <= 0 )
1271+ stop_pts = masterClock ()->value ();
1272+ masterClock ()->reset ();
1273+ QMetaObject::invokeMethod (this , " stopNotifyTimer" );
1274+ // vars not set by user can be reset
1275+
1276+ d->start_position_norm = 0 ;
1277+ d->stop_position_norm = kInvalidPosition ; // already stopped. so not 0 but invalid. 0 can stop the playback in timerEvent
1278+ d->media_end = kInvalidPosition ;
1279+ qDebug (" avplayer emit stopped()" );
1280+ d->state = StoppedState;
1281+ QMetaObject::invokeMethod (this , " stateChanged" , Q_ARG (QtAV::AVPlayer::State, d->state ));
1282+ QMetaObject::invokeMethod (this , " stopped" );
1283+ QMetaObject::invokeMethod (this , " stoppedAt" , Q_ARG (qint64, qint64 (stop_pts*1000.0 )));
1284+ // Q_EMIT stateChanged(d->state);
1285+ // Q_EMIT stopped();
1286+ // Q_EMIT stoppedAt(stop_pts*1000.0);
1287+
1288+ /*
1289+ * currently preload is not supported. so always unload. Then some properties will be reset, e.g. duration()
1290+ */
1291+ unload (); // TODO: invoke?
12981292}
12991293
13001294void AVPlayer::aboutToQuitApp ()
@@ -1455,7 +1449,7 @@ void AVPlayer::stop()
14551449 }
14561450 d->seeking = false ;
14571451 d->reset_state = true ;
1458- d->repeat_current = - 1 ;
1452+ d->read_thread -> setRepeatCurrent (- 1 ) ;
14591453 if (!isPlaying ()) {
14601454 qDebug (" Not playing~" );
14611455 if (mediaStatus () == LoadingMedia || mediaStatus () == LoadedMedia) {
@@ -1515,22 +1509,25 @@ void AVPlayer::timerEvent(QTimerEvent *te)
15151509 qDebug (" stopPosition() == 0, stop" );
15161510 stop ();
15171511 }
1518- // t < d->start_position is ok. d->repeat_max<0 means repeat forever
1512+ // t < d->start_position is ok. repeat()< 0 means repeat forever
1513+
15191514 if (currentRepeat () >= repeat () && repeat () >= 0 ) {
15201515 d->reset_state = true ; // true is default, can remove here
15211516 qDebug (" stopPosition() %lld/%lld reached and no repeat: %d" , t, stopPosition (), repeat ());
15221517 stop ();
15231518 return ;
15241519 }
1520+
15251521 // FIXME: now stop instead of seek if reach media's end. otherwise will not get eof again
15261522 if (d->stop_position_norm == mediaStopPosition () || !isSeekable ()) {
15271523 // if not seekable, how it can start to play at specified position?
1528- qDebug (" normalized stopPosition() == mediaStopPosition() or !seekable. d->repeat_current =%d" , d-> repeat_current );
1524+ qDebug (" normalized stopPosition() == mediaStopPosition() or !seekable. currentRepeat() =%d" , currentRepeat () );
15291525 d->reset_state = false ;
15301526 stop (); // repeat after all threads stopped
15311527 } else {
1532- d->repeat_current ++;
1533- qDebug (" noramlized stopPosition() != mediaStopPosition() and seekable. d->repeat_current=%d" , d->repeat_current );
1528+ int repeat_current = d->read_thread ->getRepeatCurrent ();
1529+ d->read_thread ->setRepeatCurrent (repeat_current++);
1530+ qDebug (" noramlized stopPosition() != mediaStopPosition() and seekable. currentRepeat()=%d" , currentRepeat ());
15341531 setPosition (d->start_position_norm );
15351532 }
15361533 }
0 commit comments