@@ -54,6 +54,7 @@ NuPlayer::NuPlayer()
5454 mVideoEOS(false ),
5555 mScanSourcesPending(false ),
5656 mScanSourcesGeneration(0 ),
57+ mTimeDiscontinuityPending(false ),
5758 mFlushingAudio(NONE),
5859 mFlushingVideo(NONE),
5960 mResetInProgress(false ),
@@ -477,6 +478,8 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
477478 break ;
478479 }
479480
481+ mTimeDiscontinuityPending = true ;
482+
480483 if (mAudioDecoder != NULL ) {
481484 flushDecoder (true /* audio */ , true /* needShutdown */ );
482485 }
@@ -540,7 +543,10 @@ void NuPlayer::finishFlushIfPossible() {
540543
541544 LOGV (" both audio and video are flushed now." );
542545
543- mRenderer ->signalTimeDiscontinuity ();
546+ if (mTimeDiscontinuityPending ) {
547+ mRenderer ->signalTimeDiscontinuity ();
548+ mTimeDiscontinuityPending = false ;
549+ }
544550
545551 if (mAudioDecoder != NULL ) {
546552 mAudioDecoder ->signalResume ();
@@ -663,37 +669,61 @@ status_t NuPlayer::feedDecoderInputData(bool audio, const sp<AMessage> &msg) {
663669 CHECK (accessUnit->meta ()->findInt32 (" discontinuity" , &type));
664670
665671 bool formatChange =
666- type == ATSParser::DISCONTINUITY_FORMATCHANGE;
672+ (audio &&
673+ (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT))
674+ || (!audio &&
675+ (type & ATSParser::DISCONTINUITY_VIDEO_FORMAT));
667676
668- LOGV (" %s discontinuity (formatChange=%d)" ,
669- audio ? " audio" : " video" , formatChange);
677+ bool timeChange = (type & ATSParser::DISCONTINUITY_TIME) != 0 ;
678+
679+ LOGI (" %s discontinuity (formatChange=%d, time=%d)" ,
680+ audio ? " audio" : " video" , formatChange, timeChange);
670681
671682 if (audio) {
672683 mSkipRenderingAudioUntilMediaTimeUs = -1 ;
673684 } else {
674685 mSkipRenderingVideoUntilMediaTimeUs = -1 ;
675686 }
676687
677- sp<AMessage> extra;
678- if (accessUnit->meta ()->findMessage (" extra" , &extra)
679- && extra != NULL ) {
680- int64_t resumeAtMediaTimeUs;
681- if (extra->findInt64 (
682- " resume-at-mediatimeUs" , &resumeAtMediaTimeUs)) {
683- LOGI (" suppressing rendering of %s until %lld us" ,
684- audio ? " audio" : " video" , resumeAtMediaTimeUs);
685-
686- if (audio) {
687- mSkipRenderingAudioUntilMediaTimeUs =
688- resumeAtMediaTimeUs;
689- } else {
690- mSkipRenderingVideoUntilMediaTimeUs =
691- resumeAtMediaTimeUs;
688+ if (timeChange) {
689+ sp<AMessage> extra;
690+ if (accessUnit->meta ()->findMessage (" extra" , &extra)
691+ && extra != NULL ) {
692+ int64_t resumeAtMediaTimeUs;
693+ if (extra->findInt64 (
694+ " resume-at-mediatimeUs" , &resumeAtMediaTimeUs)) {
695+ LOGI (" suppressing rendering of %s until %lld us" ,
696+ audio ? " audio" : " video" , resumeAtMediaTimeUs);
697+
698+ if (audio) {
699+ mSkipRenderingAudioUntilMediaTimeUs =
700+ resumeAtMediaTimeUs;
701+ } else {
702+ mSkipRenderingVideoUntilMediaTimeUs =
703+ resumeAtMediaTimeUs;
704+ }
692705 }
693706 }
694707 }
695708
696- flushDecoder (audio, formatChange);
709+ mTimeDiscontinuityPending =
710+ mTimeDiscontinuityPending || timeChange;
711+
712+ if (formatChange || timeChange) {
713+ flushDecoder (audio, formatChange);
714+ } else {
715+ // This stream is unaffected by the discontinuity
716+
717+ if (audio) {
718+ mFlushingAudio = FLUSHED;
719+ } else {
720+ mFlushingVideo = FLUSHED;
721+ }
722+
723+ finishFlushIfPossible ();
724+
725+ return -EWOULDBLOCK;
726+ }
697727 }
698728
699729 reply->setInt32 (" err" , err);
@@ -794,6 +824,11 @@ void NuPlayer::notifyListener(int msg, int ext1, int ext2) {
794824}
795825
796826void NuPlayer::flushDecoder (bool audio, bool needShutdown) {
827+ if ((audio && mAudioDecoder == NULL ) || (!audio && mVideoDecoder == NULL )) {
828+ LOGI (" flushDecoder %s without decoder present" ,
829+ audio ? " audio" : " video" );
830+ }
831+
797832 // Make sure we don't continue to scan sources until we finish flushing.
798833 ++mScanSourcesGeneration ;
799834 mScanSourcesPending = false ;
0 commit comments