@@ -46,11 +46,6 @@ export default class VTTSegmentLoader extends SegmentLoader {
4646 this . shouldSaveSegmentTimingInfo_ = false ;
4747 }
4848
49- createTransmuxer_ ( ) {
50- // don't need to transmux any subtitles
51- return null ;
52- }
53-
5449 /**
5550 * Indicates which time ranges are buffered
5651 *
@@ -282,6 +277,11 @@ export default class VTTSegmentLoader extends SegmentLoader {
282277 }
283278
284279 const segmentInfo = this . pendingSegment_ ;
280+ const isMp4WebVttSegmentWithCues = result . mp4VttCues && result . mp4VttCues . length ;
281+
282+ if ( isMp4WebVttSegmentWithCues ) {
283+ segmentInfo . mp4VttCues = result . mp4VttCues ;
284+ }
285285
286286 // although the VTT segment loader bandwidth isn't really used, it's good to
287287 // maintain functionality between segment loaders
@@ -334,11 +334,13 @@ export default class VTTSegmentLoader extends SegmentLoader {
334334 return ;
335335 }
336336
337- this . updateTimeMapping_ (
338- segmentInfo ,
339- this . syncController_ . timelines [ segmentInfo . timeline ] ,
340- this . playlist_
341- ) ;
337+ if ( ! isMp4WebVttSegmentWithCues ) {
338+ this . updateTimeMapping_ (
339+ segmentInfo ,
340+ this . syncController_ . timelines [ segmentInfo . timeline ] ,
341+ this . playlist_
342+ ) ;
343+ }
342344
343345 if ( segmentInfo . cues . length ) {
344346 segmentInfo . timingInfo = {
@@ -380,14 +382,49 @@ export default class VTTSegmentLoader extends SegmentLoader {
380382 this . handleAppendsDone_ ( ) ;
381383 }
382384
383- handleData_ ( ) {
384- // noop as we shouldn't be getting video/audio data captions
385- // that we do not support here.
385+ handleData_ ( simpleSegment , result ) {
386+ const isVttType = simpleSegment && simpleSegment . type === 'vtt' ;
387+ const isTextResult = result && result . type === 'text' ;
388+ const isFmp4VttSegment = isVttType && isTextResult ;
389+ // handle segment data for fmp4 encapsulated webvtt
390+
391+ if ( isFmp4VttSegment ) {
392+ super . handleData_ ( simpleSegment , result ) ;
393+ }
386394 }
395+
387396 updateTimingInfoEnd_ ( ) {
388397 // noop
389398 }
390399
400+ /**
401+ * Utility function for converting mp4 webvtt cue objects into VTTCues.
402+ *
403+ * @param {Object } segmentInfo with mp4 webvtt cues for parsing into VTTCue objecs
404+ */
405+ parseMp4VttCues_ ( segmentInfo ) {
406+ const timestampOffset = this . sourceUpdater_ . videoTimestampOffset ( ) === null ?
407+ this . sourceUpdater_ . audioTimestampOffset ( ) :
408+ this . sourceUpdater_ . videoTimestampOffset ( ) ;
409+
410+ segmentInfo . mp4VttCues . forEach ( ( cue ) => {
411+ const start = cue . start + timestampOffset ;
412+ const end = cue . end + timestampOffset ;
413+ const vttCue = new window . VTTCue ( start , end , cue . cueText ) ;
414+
415+ if ( cue . settings ) {
416+ cue . settings . split ( ' ' ) . forEach ( ( cueSetting ) => {
417+ const keyValString = cueSetting . split ( ':' ) ;
418+ const key = keyValString [ 0 ] ;
419+ const value = keyValString [ 1 ] ;
420+
421+ vttCue [ key ] = isNaN ( value ) ? value : Number ( value ) ;
422+ } ) ;
423+ }
424+ segmentInfo . cues . push ( vttCue ) ;
425+ } ) ;
426+ }
427+
391428 /**
392429 * Uses the WebVTT parser to parse the segment response
393430 *
@@ -406,6 +443,14 @@ export default class VTTSegmentLoader extends SegmentLoader {
406443 throw new NoVttJsError ( ) ;
407444 }
408445
446+ segmentInfo . cues = [ ] ;
447+ segmentInfo . timestampmap = { MPEGTS : 0 , LOCAL : 0 } ;
448+
449+ if ( segmentInfo . mp4VttCues ) {
450+ this . parseMp4VttCues_ ( segmentInfo ) ;
451+ return ;
452+ }
453+
409454 if ( typeof window . TextDecoder === 'function' ) {
410455 decoder = new window . TextDecoder ( 'utf8' ) ;
411456 } else {
@@ -419,9 +464,6 @@ export default class VTTSegmentLoader extends SegmentLoader {
419464 decoder
420465 ) ;
421466
422- segmentInfo . cues = [ ] ;
423- segmentInfo . timestampmap = { MPEGTS : 0 , LOCAL : 0 } ;
424-
425467 parser . oncue = segmentInfo . cues . push . bind ( segmentInfo . cues ) ;
426468 parser . ontimestampmap = ( map ) => {
427469 segmentInfo . timestampmap = map ;
0 commit comments