@@ -64,7 +64,7 @@ function StreamController() {
6464 protectionData , extUrlQueryInfoController ,
6565 autoPlay , isStreamSwitchingInProgress , hasMediaError , hasInitialisationError , mediaSource , videoModel ,
6666 playbackController , serviceDescriptionController , mediaPlayerModel , customParametersModel , isPaused ,
67- initialPlayback , initialSteeringRequest , playbackEndedTimerInterval , bufferSinks , preloadingStreams , settings ,
67+ initialPlayback , initialSteeringRequest , playbackEndedTimerInterval , preloadingStreams , settings ,
6868 firstLicenseIsFetched , waitForPlaybackStartTimeout , providedStartTime , errorInformation ;
6969
7070 function setup ( ) {
@@ -430,6 +430,7 @@ function StreamController() {
430430
431431 let keepBuffers = false ;
432432 let representationsFromPreviousPeriod = [ ] ;
433+ let sourceBufferSinksFromPreviousPeriod = _getSourceBufferSinksFromPreviousPeriod ( previousStream ) ;
433434 activeStream = stream ;
434435
435436 if ( previousStream ) {
@@ -451,9 +452,15 @@ function StreamController() {
451452
452453 // If we have a video element we are not preloading into a virtual buffer
453454 if ( videoModel . getElement ( ) ) {
454- _openMediaSource ( { seekTime, keepBuffers, streamActivated : false , representationsFromPreviousPeriod } ) ;
455+ _openMediaSource ( {
456+ seekTime,
457+ keepBuffers,
458+ sourceBufferSinksFromPreviousPeriod,
459+ streamActivated : false ,
460+ representationsFromPreviousPeriod
461+ } ) ;
455462 } else {
456- _activateStream ( { seekTime, keepBuffers } ) ;
463+ _activateStream ( { seekTime, keepBuffers, sourceBufferSinksFromPreviousPeriod } ) ;
457464 }
458465 } catch ( e ) {
459466 isStreamSwitchingInProgress = false ;
@@ -524,11 +531,8 @@ function StreamController() {
524531 */
525532 function _activateStream ( inputParameters ) {
526533 const representationsFromPreviousPeriod = inputParameters . representationsFromPreviousPeriod || [ ] ;
527- activeStream . activate ( mediaSource , inputParameters . keepBuffers ? bufferSinks : undefined , representationsFromPreviousPeriod )
528- . then ( ( sinks ) => {
529- if ( sinks ) {
530- bufferSinks = sinks ;
531- }
534+ activeStream . activate ( mediaSource , inputParameters . sourceBufferSinksFromPreviousPeriod , representationsFromPreviousPeriod )
535+ . then ( ( ) => {
532536
533537 // Set the initial time for this stream in the StreamProcessor
534538 if ( ! isNaN ( inputParameters . seekTime ) ) {
@@ -549,6 +553,25 @@ function StreamController() {
549553 } )
550554 }
551555
556+ function _getSourceBufferSinksFromPreviousPeriod ( previousStream ) {
557+ const sourceBufferSinkMap = new Map ( ) ;
558+
559+ if ( ! previousStream ) {
560+ return sourceBufferSinkMap ;
561+ }
562+
563+ const previousStreamProcessors = previousStream ? previousStream . getStreamProcessors ( ) : [ ] ;
564+
565+ previousStreamProcessors . forEach ( ( streamProcessor ) => {
566+ const sourceBufferSink = streamProcessor . getBuffer ( ) ;
567+ if ( sourceBufferSink ) {
568+ sourceBufferSinkMap . set ( sourceBufferSink . getType ( ) , sourceBufferSink ) ;
569+ }
570+ } )
571+
572+ return sourceBufferSinkMap
573+ }
574+
552575 /**
553576 * A playback seeking event was triggered. We need to disable the preloading streams and call the respective seeking handler.
554577 * We distinguish between inner period seeks and outer period seeks
@@ -693,17 +716,22 @@ function StreamController() {
693716 */
694717 function _onStreamCanLoadNext ( nextStream , previousStream = null ) {
695718
696- if ( mediaSource && ! nextStream . getPreloaded ( ) ) {
697- let seamlessPeriodSwitch = _canSourceBuffersBeKept ( nextStream , previousStream ) ;
719+ if ( ! mediaSource || nextStream . getPreloaded ( ) ) {
720+ return ;
721+ }
698722
699- if ( seamlessPeriodSwitch ) {
700- const representationsFromPreviousPeriod = _getRepresentationsFromPreviousPeriod ( previousStream ) ;
701- nextStream . startPreloading ( mediaSource , bufferSinks , representationsFromPreviousPeriod )
702- . then ( ( ) => {
703- preloadingStreams . push ( nextStream ) ;
704- } ) ;
705- }
723+ let seamlessPeriodSwitch = _canSourceBuffersBeKept ( nextStream , previousStream ) ;
724+
725+ if ( ! seamlessPeriodSwitch ) {
726+ return ;
706727 }
728+
729+ const representationsFromPreviousPeriod = _getRepresentationsFromPreviousPeriod ( previousStream ) ;
730+ const previousSourceBufferSinks = _getSourceBufferSinksFromPreviousPeriod ( previousStream ) ;
731+ nextStream . startPreloading ( mediaSource , previousSourceBufferSinks , representationsFromPreviousPeriod )
732+ . then ( ( ) => {
733+ preloadingStreams . push ( nextStream ) ;
734+ } ) ;
707735 }
708736
709737 /**
@@ -904,9 +932,7 @@ function StreamController() {
904932
905933 // If the preloading for the current stream is not scheduled, but its predecessor has finished buffering we can start prebuffering this stream
906934 if ( ! stream . getPreloaded ( ) && previousStream . getHasFinishedBuffering ( ) ) {
907- if ( mediaSource ) {
908- _onStreamCanLoadNext ( stream , previousStream ) ;
909- }
935+ _onStreamCanLoadNext ( stream , previousStream ) ;
910936 }
911937 i += 1 ;
912938 }
@@ -1307,7 +1333,6 @@ function StreamController() {
13071333
13081334 let allUTCTimingSources = ( ! adapter . getIsDynamic ( ) ) ? manifestUTCTimingSources : manifestUTCTimingSources . concat ( customParametersModel . getUTCTimingSources ( ) ) ;
13091335 timeSyncController . attemptSync ( allUTCTimingSources , adapter . getIsDynamic ( ) ) ;
1310-
13111336 extUrlQueryInfoController . createFinalQueryStrings ( manifest ) ;
13121337 } ) ;
13131338 } else {
0 commit comments