shaka-player 4.12.5 → 4.12.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/controls.css +1 -1
  2. package/dist/controls.css.map +1 -1
  3. package/dist/deps.js +3 -3
  4. package/dist/locales.js +34 -34
  5. package/dist/shaka-player.compiled.d.ts +12 -4
  6. package/dist/shaka-player.compiled.debug.d.ts +12 -4
  7. package/dist/shaka-player.compiled.debug.externs.js +10 -6
  8. package/dist/shaka-player.compiled.debug.js +439 -425
  9. package/dist/shaka-player.compiled.debug.map +3 -3
  10. package/dist/shaka-player.compiled.externs.js +10 -6
  11. package/dist/shaka-player.compiled.js +1352 -1345
  12. package/dist/shaka-player.compiled.map +3 -3
  13. package/dist/shaka-player.ui.d.ts +12 -4
  14. package/dist/shaka-player.ui.debug.d.ts +12 -4
  15. package/dist/shaka-player.ui.debug.externs.js +10 -6
  16. package/dist/shaka-player.ui.debug.js +439 -425
  17. package/dist/shaka-player.ui.debug.map +3 -3
  18. package/dist/shaka-player.ui.externs.js +10 -6
  19. package/dist/shaka-player.ui.js +1596 -1588
  20. package/dist/shaka-player.ui.map +3 -3
  21. package/externs/shaka/codecs.js +21 -0
  22. package/externs/shaka/offline.js +4 -0
  23. package/lib/cast/cast_utils.js +1 -0
  24. package/lib/cea/cea708_service.js +27 -2
  25. package/lib/cea/dtvcc_packet_builder.js +15 -0
  26. package/lib/dash/dash_parser.js +5 -2
  27. package/lib/dash/mpd_utils.js +7 -4
  28. package/lib/dash/segment_template.js +30 -17
  29. package/lib/hls/hls_parser.js +31 -7
  30. package/lib/media/drm_engine.js +55 -12
  31. package/lib/media/media_source_engine.js +127 -41
  32. package/lib/media/segment_utils.js +65 -47
  33. package/lib/net/http_fetch_plugin.js +1 -1
  34. package/lib/net/http_plugin_utils.js +3 -0
  35. package/lib/offline/download_info.js +5 -0
  36. package/lib/offline/download_manager.js +54 -0
  37. package/lib/offline/manifest_converter.js +1 -0
  38. package/lib/offline/storage.js +11 -2
  39. package/lib/player.js +53 -22
  40. package/lib/polyfill/media_capabilities.js +1 -1
  41. package/lib/text/simple_text_displayer.js +9 -1
  42. package/lib/text/ui_text_displayer.js +2 -14
  43. package/lib/transmuxer/aac_transmuxer.js +11 -3
  44. package/lib/transmuxer/ac3_transmuxer.js +11 -3
  45. package/lib/transmuxer/ec3_transmuxer.js +11 -3
  46. package/lib/transmuxer/h264.js +143 -70
  47. package/lib/transmuxer/mp3_transmuxer.js +11 -3
  48. package/lib/transmuxer/ts_transmuxer.js +68 -28
  49. package/lib/util/drm_utils.js +20 -0
  50. package/lib/util/stream_utils.js +0 -60
  51. package/lib/util/ts_parser.js +111 -85
  52. package/package.json +1 -1
  53. package/ui/audio_language_selection.js +1 -1
  54. package/ui/controls.js +4 -0
  55. package/ui/fast_forward_button.js +7 -0
  56. package/ui/play_button.js +1 -1
  57. package/ui/playback_rate_selection.js +1 -1
  58. package/ui/rewind_button.js +7 -0
@@ -52,6 +52,9 @@ shaka.transmuxer.TsTransmuxer = class {
52
52
 
53
53
  /** @private {?shaka.transmuxer.AacTransmuxer} */
54
54
  this.aacTransmuxer_ = null;
55
+
56
+ /** @private {?Uint8Array} */
57
+ this.lastInitSegment_ = null;
55
58
  }
56
59
 
57
60
 
@@ -293,11 +296,16 @@ shaka.transmuxer.TsTransmuxer = class {
293
296
  } else {
294
297
  initSegment = this.initSegments.get(initSegmentKey);
295
298
  }
299
+ const appendInitSegment = this.lastInitSegment_ !== initSegment;
296
300
  const segmentData = mp4Generator.segmentData();
297
-
301
+ this.lastInitSegment_ = initSegment;
298
302
  this.frameIndex_++;
299
- const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
300
- return Promise.resolve(transmuxData);
303
+ if (appendInitSegment) {
304
+ const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
305
+ return Promise.resolve(transmuxData);
306
+ } else {
307
+ return Promise.resolve(segmentData);
308
+ }
301
309
  }
302
310
 
303
311
 
@@ -312,6 +320,7 @@ shaka.transmuxer.TsTransmuxer = class {
312
320
  getAacStreamInfo_(tsParser, stream, duration, reference) {
313
321
  const ADTS = shaka.transmuxer.ADTS;
314
322
  const timescale = shaka.util.TsParser.Timescale;
323
+ const Uint8ArrayUtils = shaka.util.Uint8ArrayUtils;
315
324
 
316
325
  /** @type {!Array.<shaka.util.Mp4Generator.Mp4Sample>} */
317
326
  const samples = [];
@@ -320,12 +329,41 @@ shaka.transmuxer.TsTransmuxer = class {
320
329
 
321
330
  let firstPts = null;
322
331
 
332
+ /** @type {?number} */
333
+ let nextStartOffset = null;
334
+ /** @type {?Uint8Array} */
335
+ let overflowBytes = null;
336
+
323
337
  for (const audioData of tsParser.getAudioData()) {
324
- const data = audioData.data;
338
+ let data = audioData.data;
325
339
  if (!data) {
326
340
  continue;
327
341
  }
328
342
  let offset = 0;
343
+ if (nextStartOffset == -1 && overflowBytes) {
344
+ data = Uint8ArrayUtils.concat(overflowBytes, audioData.data);
345
+ nextStartOffset = null;
346
+ } else if (nextStartOffset != null && overflowBytes) {
347
+ offset = Math.max(0, nextStartOffset);
348
+ const missingFrameData =
349
+ Uint8ArrayUtils.concat(overflowBytes, data.subarray(0, offset));
350
+ samples.push({
351
+ data: missingFrameData,
352
+ size: missingFrameData.byteLength,
353
+ duration: ADTS.AAC_SAMPLES_PER_FRAME,
354
+ cts: 0,
355
+ flags: {
356
+ isLeading: 0,
357
+ isDependedOn: 0,
358
+ hasRedundancy: 0,
359
+ degradPrio: 0,
360
+ dependsOn: 2,
361
+ isNonSync: 0,
362
+ },
363
+ });
364
+ overflowBytes = null;
365
+ nextStartOffset = null;
366
+ }
329
367
  info = ADTS.parseInfo(data, offset);
330
368
  if (!info) {
331
369
  throw new shaka.util.Error(
@@ -342,12 +380,16 @@ shaka.transmuxer.TsTransmuxer = class {
342
380
  while (offset < data.length) {
343
381
  const header = ADTS.parseHeader(data, offset);
344
382
  if (!header) {
345
- // We will increment one byte each time until we find the header.
346
- offset++;
347
- continue;
383
+ overflowBytes = data.subarray(offset, data.length);
384
+ nextStartOffset = -1;
385
+ break;
348
386
  }
349
387
  const length = header.headerLength + header.frameLength;
350
- if (offset + length <= data.length) {
388
+ nextStartOffset = Math.max(0, offset + length - data.length);
389
+ if (nextStartOffset != 0) {
390
+ overflowBytes = data.subarray(
391
+ offset + header.headerLength, offset + length);
392
+ } else if (offset + length <= data.length) {
351
393
  const frameData = data.subarray(
352
394
  offset + header.headerLength, offset + length);
353
395
 
@@ -865,50 +907,48 @@ shaka.transmuxer.TsTransmuxer = class {
865
907
  /** @type {?number} */
866
908
  let baseMediaDecodeTime = null;
867
909
 
868
- const nalus = [];
869
910
  const videoData = tsParser.getVideoData();
870
- if (!videoData.length) {
911
+ const videoSamples = H264.getVideoSamples(videoData);
912
+ if (!videoSamples.length) {
871
913
  throw new shaka.util.Error(
872
914
  shaka.util.Error.Severity.CRITICAL,
873
915
  shaka.util.Error.Category.MEDIA,
874
916
  shaka.util.Error.Code.TRANSMUXING_NO_VIDEO_DATA,
875
917
  reference ? reference.getUris()[0] : null);
876
918
  }
877
- for (let i = 0; i < videoData.length; i++) {
878
- const pes = videoData[i];
879
- const dataNalus = pes.nalus;
880
- nalus.push(...dataNalus);
881
- const frame = H264.parseFrame(dataNalus);
882
- if (!frame) {
883
- continue;
884
- }
919
+ for (let i = 0; i < videoSamples.length; i++) {
920
+ const videoSample = videoSamples[i];
885
921
  if (baseMediaDecodeTime == null) {
886
- baseMediaDecodeTime = pes.dts;
922
+ baseMediaDecodeTime = videoSample.dts;
887
923
  }
888
924
  let duration;
889
- if (i + 1 < videoData.length) {
890
- duration = (videoData[i + 1].dts || 0) - (pes.dts || 0);
891
- } else if (videoData.length > 1) {
892
- duration = (pes.dts || 0) - (videoData[i - 1].dts || 0);
925
+ if (i + 1 < videoSamples.length) {
926
+ duration = (videoSamples[i + 1].dts || 0) - (videoSample.dts || 0);
927
+ } else if (videoSamples.length > 1) {
928
+ duration = (videoSample.dts || 0) - (videoSamples[i - 1].dts || 0);
893
929
  } else {
894
930
  duration = (reference.endTime - reference.startTime) * timescale;
895
931
  }
896
932
  samples.push({
897
- data: frame.data,
898
- size: frame.data.byteLength,
933
+ data: videoSample.data,
934
+ size: videoSample.data.byteLength,
899
935
  duration: duration,
900
- cts: Math.round((pes.pts || 0) - (pes.dts || 0)),
936
+ cts: Math.round((videoSample.pts || 0) - (videoSample.dts || 0)),
901
937
  flags: {
902
938
  isLeading: 0,
903
939
  isDependedOn: 0,
904
940
  hasRedundancy: 0,
905
941
  degradPrio: 0,
906
- dependsOn: frame.isKeyframe ? 2 : 1,
907
- isNonSync: frame.isKeyframe ? 0 : 1,
942
+ dependsOn: videoSample.isKeyframe ? 2 : 1,
943
+ isNonSync: videoSample.isKeyframe ? 0 : 1,
908
944
  },
909
945
  });
910
946
  }
911
947
 
948
+ const nalus = [];
949
+ for (const pes of videoData) {
950
+ nalus.push(...pes.nalus);
951
+ }
912
952
  const info = H264.parseInfo(nalus);
913
953
 
914
954
  if (!info || baseMediaDecodeTime == null) {
@@ -113,6 +113,26 @@ shaka.util.DrmUtils = class {
113
113
  return drmInfo ? drmInfo.keySystem : '';
114
114
  }
115
115
 
116
+ /**
117
+ * @param {?string} keySystem
118
+ * @return {boolean}
119
+ */
120
+ static isClearKeySystem(keySystem) {
121
+ return keySystem === 'org.w3.clearkey';
122
+ }
123
+
124
+ /**
125
+ * @param {?string} keySystem
126
+ * @return {boolean}
127
+ */
128
+ static isWidevineKeySystem(keySystem) {
129
+ if (keySystem) {
130
+ return !!keySystem.match(/^com\.widevine\.alpha/);
131
+ }
132
+
133
+ return false;
134
+ }
135
+
116
136
  /**
117
137
  * @param {?string} keySystem
118
138
  * @return {boolean}
@@ -516,11 +516,6 @@ shaka.util.StreamUtils = class {
516
516
  if (!variantSupported) {
517
517
  return false;
518
518
  }
519
- const ContentType = shaka.util.ManifestParserUtils.ContentType;
520
- const Capabilities = shaka.media.Capabilities;
521
- const ManifestParserUtils = shaka.util.ManifestParserUtils;
522
- const MimeUtils = shaka.util.MimeUtils;
523
- const StreamUtils = shaka.util.StreamUtils;
524
519
 
525
520
  const isXboxOne = shaka.util.Platform.isXboxOne();
526
521
  const isFirefoxAndroid = shaka.util.Platform.isFirefox() &&
@@ -538,45 +533,6 @@ shaka.util.StreamUtils = class {
538
533
  return false;
539
534
  }
540
535
 
541
- if (video) {
542
- let videoCodecs = StreamUtils.getCorrectVideoCodecs(video.codecs);
543
- // For multiplexed streams. Here we must check the audio of the
544
- // stream to see if it is compatible.
545
- if (video.codecs.includes(',')) {
546
- const allCodecs = video.codecs.split(',');
547
-
548
- videoCodecs = ManifestParserUtils.guessCodecs(
549
- ContentType.VIDEO, allCodecs);
550
- videoCodecs = StreamUtils.getCorrectVideoCodecs(videoCodecs);
551
- let audioCodecs = ManifestParserUtils.guessCodecs(
552
- ContentType.AUDIO, allCodecs);
553
- audioCodecs = StreamUtils.getCorrectAudioCodecs(
554
- audioCodecs, video.mimeType);
555
-
556
- const audioFullType = MimeUtils.getFullOrConvertedType(
557
- video.mimeType, audioCodecs, ContentType.AUDIO);
558
-
559
- if (!Capabilities.isTypeSupported(audioFullType)) {
560
- return false;
561
- }
562
-
563
- // Update the codec string with the (possibly) converted codecs.
564
- videoCodecs = [videoCodecs, audioCodecs].join(',');
565
- }
566
-
567
- if (video.codecs != videoCodecs) {
568
- const fullType = MimeUtils.getFullOrConvertedType(
569
- video.mimeType, videoCodecs, ContentType.VIDEO);
570
-
571
- if (!Capabilities.isTypeSupported(fullType)) {
572
- return false;
573
- }
574
-
575
- // Update the codec string with the (possibly) converted codecs.
576
- video.codecs = videoCodecs;
577
- }
578
- }
579
-
580
536
  const audio = variant.audio;
581
537
 
582
538
  // See: https://github.com/shaka-project/shaka-player/issues/6111
@@ -588,22 +544,6 @@ shaka.util.StreamUtils = class {
588
544
  return false;
589
545
  }
590
546
 
591
- if (audio) {
592
- const codecs = StreamUtils.getCorrectAudioCodecs(
593
- audio.codecs, audio.mimeType);
594
- if (audio.codecs != codecs) {
595
- const fullType = MimeUtils.getFullOrConvertedType(
596
- audio.mimeType, codecs, ContentType.AUDIO);
597
-
598
- if (!Capabilities.isTypeSupported(fullType)) {
599
- return false;
600
- }
601
-
602
- // Update the codec string with the (possibly) converted codecs.
603
- audio.codecs = codecs;
604
- }
605
- }
606
-
607
547
  return true;
608
548
  }
609
549
 
@@ -517,7 +517,11 @@ shaka.util.TsParser = class {
517
517
  shaka.Deprecate.deprecateFeature(5,
518
518
  'TsParser.parseAvcNalus',
519
519
  'Please use parseNalus function instead.');
520
- return this.parseNalus(pes);
520
+ const lastInfo = {
521
+ nalu: null,
522
+ state: null,
523
+ };
524
+ return this.parseNalus(pes, lastInfo);
521
525
  }
522
526
 
523
527
  /**
@@ -527,12 +531,11 @@ shaka.util.TsParser = class {
527
531
  * Credit to https://github.com/video-dev/hls.js/blob/master/src/demux/tsdemuxer.ts
528
532
  *
529
533
  * @param {shaka.extern.MPEG_PES} pes
530
- * @param {?shaka.extern.VideoNalu=} lastNalu
531
- * @param {?number=} lastState
534
+ * @param {{nalu: ?shaka.extern.VideoNalu, state: ?number}} lastInfo
532
535
  * @return {!Array.<shaka.extern.VideoNalu>}
533
536
  * @export
534
537
  */
535
- parseNalus(pes, lastNalu, lastState) {
538
+ parseNalus(pes, lastInfo) {
536
539
  const timescale = shaka.util.TsParser.Timescale;
537
540
  const time = pes.pts ? pes.pts / timescale : null;
538
541
  const data = pes.data;
@@ -548,7 +551,12 @@ shaka.util.TsParser = class {
548
551
  // precede each NALU. A start code is 2 or 3 0x00 bytes followed with a
549
552
  // 0x01 byte. e.g. 0x000001 or 0x00000001.
550
553
  // More info in: https://stackoverflow.com/questions/24884827/possible-locations-for-sequence-picture-parameter-sets-for-h-264-stream/24890903#24890903
551
- let numZeros = lastState || 0;
554
+ let numZeros = lastInfo.state || 0;
555
+
556
+ const initialNumZeros = numZeros;
557
+
558
+ /** @type {number} */
559
+ let i = 0;
552
560
 
553
561
  /** @type {!Array.<shaka.extern.VideoNalu>} */
554
562
  const nalus = [];
@@ -559,103 +567,119 @@ shaka.util.TsParser = class {
559
567
  // Extracted from the first byte.
560
568
  let lastNaluType = 0;
561
569
 
562
- /** @type {?shaka.extern.VideoNalu} */
563
- let infoOfLastNalu;
570
+ const getNaluType = (offset) => {
571
+ if (this.videoCodec_ == 'hvc') {
572
+ return (data[offset] >> 1) & 0x3f;
573
+ } else {
574
+ return data[offset] & 0x1f;
575
+ }
576
+ };
564
577
 
565
- for (let i = 0; i < len; ++i) {
566
- const value = data[i];
567
- if (!value) {
568
- numZeros++;
569
- } else if (numZeros >= 2 && value == 1) {
570
- if (lastNalu && !nalus.length && lastNaluStart == -1) {
571
- // If we are scanning the next PES, we need append the data to the
572
- // previous Nalu and don't scan for more nalus.
573
- const startCodeSize = numZeros > 3 ? 3 : numZeros;
574
- const lastByteToKeep = i - startCodeSize;
575
- // Optimization
576
- if (lastState && lastByteToKeep != 0) {
577
- const prevData = data.subarray(0, lastByteToKeep);
578
- lastNalu.data = shaka.util.Uint8ArrayUtils.concat(
579
- lastNalu.data, prevData);
580
- lastNalu.fullData = shaka.util.Uint8ArrayUtils.concat(
581
- lastNalu.fullData, prevData);
582
- }
583
- }
584
- // We just read a start code. Consume the NALU we passed, if any.
585
- if (lastNaluStart >= 0) {
586
- // Because the start position includes the header size.
587
- const firstByteToKeep = lastNaluStart + naluHeaderSize;
578
+ const getLastNalu = () => {
579
+ if (nalus.length) {
580
+ return nalus[nalus.length - 1];
581
+ }
582
+ return lastInfo.nalu;
583
+ };
588
584
 
589
- // Compute the last byte to keep. The start code is at most 3 zeros.
590
- // Any earlier zeros are not part of the start code.
591
- const startCodeSize = (numZeros > 3 ? 3 : numZeros) + 1;
592
- const lastByteToKeep = i - startCodeSize;
585
+ if (numZeros == -1) {
586
+ // special use case where we found 3 or 4-byte start codes exactly at the
587
+ // end of previous PES packet
588
+ lastNaluStart = 0;
589
+ // NALu type is value read from offset 0
590
+ lastNaluType = getNaluType(0);
591
+ numZeros = 0;
592
+ i = 1;
593
+ }
593
594
 
595
+ while (i < len) {
596
+ const value = data[i++];
597
+ // Optimization. numZeros 0 and 1 are the predominant case.
598
+ if (!numZeros) {
599
+ numZeros = value ? 0 : 1;
600
+ continue;
601
+ }
602
+ if (numZeros === 1) {
603
+ numZeros = value ? 0 : 2;
604
+ continue;
605
+ }
606
+ if (!value) {
607
+ numZeros = 3;
608
+ } else if (value == 1) {
609
+ const overflow = i - numZeros - 1;
610
+ if (lastNaluStart >= 0) {
594
611
  /** @type {shaka.extern.VideoNalu} */
595
612
  const nalu = {
596
- // subarray's end position is exclusive, so add one.
597
- data: data.subarray(firstByteToKeep, lastByteToKeep + 1),
598
- fullData: data.subarray(lastNaluStart, lastByteToKeep + 1),
613
+ data: data.subarray(lastNaluStart + naluHeaderSize, overflow),
614
+ fullData: data.subarray(lastNaluStart, overflow),
599
615
  type: lastNaluType,
600
616
  time: time,
617
+ state: null,
601
618
  };
602
619
  nalus.push(nalu);
603
- } else if (lastNalu && !nalus.length) {
604
- const overflow = i - numZeros;
605
- if (overflow > 0) {
606
- const prevData = data.subarray(0, overflow);
607
- lastNalu.data = shaka.util.Uint8ArrayUtils.concat(
608
- lastNalu.data, prevData);
609
- lastNalu.fullData = shaka.util.Uint8ArrayUtils.concat(
610
- lastNalu.fullData, prevData);
620
+ } else {
621
+ const lastNalu = getLastNalu();
622
+ if (lastNalu) {
623
+ if (initialNumZeros && i <= 4 - initialNumZeros) {
624
+ // Start delimiter overlapping between PES packets
625
+ // strip start delimiter bytes from the end of last NAL unit
626
+ // check if lastNalu had a state different from zero
627
+ if (lastNalu.state) {
628
+ // strip last bytes
629
+ lastNalu.data = lastNalu.data.subarray(
630
+ 0, lastNalu.data.byteLength - initialNumZeros);
631
+ lastNalu.fullData = lastNalu.fullData.subarray(
632
+ 0, lastNalu.fullData.byteLength - initialNumZeros);
633
+ }
634
+ }
635
+ // If NAL units are not starting right at the beginning of the PES
636
+ // packet, push preceding data into previous NAL unit.
637
+ if (overflow > 0) {
638
+ const prevData = data.subarray(0, overflow);
639
+ lastNalu.data = shaka.util.Uint8ArrayUtils.concat(
640
+ lastNalu.data, prevData);
641
+ lastNalu.fullData = shaka.util.Uint8ArrayUtils.concat(
642
+ lastNalu.fullData, prevData);
643
+ lastNalu.state = 0;
644
+ }
611
645
  }
612
646
  }
613
647
 
614
- // We just read a start code, so there should be another byte here, at
615
- // least, for the NALU type. Check just in case.
616
- if (i >= len - naluHeaderSize) {
617
- shaka.log.warning('Malformed TS, incomplete NALU, ignoring.');
618
- return nalus;
619
- }
620
-
621
- // Advance and read the type of the next NALU.
622
- i++;
623
- lastNaluStart = i;
624
- if (this.videoCodec_ == 'hvc') {
625
- lastNaluType = (data[i] >> 1) & 0x3f;
648
+ // Check if we can read unit type
649
+ if (i < len) {
650
+ lastNaluType = getNaluType(i);
651
+ lastNaluStart = i;
652
+ numZeros = 0;
626
653
  } else {
627
- lastNaluType = data[i] & 0x1f;
654
+ // Not enough byte to read unit type.
655
+ // Let's read it on next PES parsing.
656
+ numZeros = -1;
628
657
  }
629
- numZeros = 0;
630
658
  } else {
631
659
  numZeros = 0;
632
660
  }
633
- // If we have gone through all the data from the PES and we have an
634
- // unfinished Nalu, we will try to use the next PES to complete the
635
- // unfinished Nalu.
636
- if (i >= (len - 1) && lastNaluStart >= 0 && numZeros >= 0) {
637
- // The rest of the buffer was a NALU.
638
- // Because the start position includes the header size.
639
- const firstByteToKeep = lastNaluStart + naluHeaderSize;
640
- infoOfLastNalu = {
641
- data: data.subarray(firstByteToKeep, len),
642
- fullData: data.subarray(lastNaluStart, len),
643
- type: lastNaluType,
644
- time: time,
645
- };
646
- }
647
661
  }
648
662
 
649
- if (infoOfLastNalu) {
650
- nalus.push(infoOfLastNalu);
663
+ if (lastNaluStart >= 0 && numZeros >= 0) {
664
+ const nalu = {
665
+ data: data.subarray(lastNaluStart + naluHeaderSize, len),
666
+ fullData: data.subarray(lastNaluStart, len),
667
+ type: lastNaluType,
668
+ time: time,
669
+ state: numZeros,
670
+ };
671
+ nalus.push(nalu);
651
672
  }
652
- if (!nalus.length && lastNalu) {
653
- lastNalu.data = shaka.util.Uint8ArrayUtils.concat(
654
- lastNalu.data, data);
655
- lastNalu.fullData = shaka.util.Uint8ArrayUtils.concat(
656
- lastNalu.fullData, data);
673
+ if (!nalus.length && lastInfo.nalu) {
674
+ const lastNalu = getLastNalu();
675
+ if (lastNalu) {
676
+ lastNalu.data = shaka.util.Uint8ArrayUtils.concat(
677
+ lastNalu.data, data);
678
+ lastNalu.fullData = shaka.util.Uint8ArrayUtils.concat(
679
+ lastNalu.fullData, data);
680
+ }
657
681
  }
658
- lastState = Math.min(3, numZeros);
682
+ lastInfo.state = numZeros;
659
683
  return nalus;
660
684
  }
661
685
 
@@ -759,14 +783,16 @@ shaka.util.TsParser = class {
759
783
  }
760
784
  }
761
785
  if (naluProcessing) {
762
- let lastNalu;
763
- let lastState;
786
+ const lastInfo = {
787
+ nalu: null,
788
+ state: null,
789
+ };
764
790
  const pesWithLength = [];
765
791
  for (const pes of this.videoPes_) {
766
- pes.nalus = this.parseNalus(pes, lastNalu, lastState);
792
+ pes.nalus = this.parseNalus(pes, lastInfo);
767
793
  if (pes.nalus.length) {
768
794
  pesWithLength.push(pes);
769
- lastNalu = pes.nalus[pes.nalus.length - 1];
795
+ lastInfo.nalu = pes.nalus[pes.nalus.length - 1];
770
796
  }
771
797
  }
772
798
  this.videoPes_ = pesWithLength;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shaka-player",
3
3
  "description": "DASH/EME video player library",
4
- "version": "4.12.5",
4
+ "version": "4.12.7",
5
5
  "homepage": "https://github.com/shaka-project/shaka-player",
6
6
  "author": "Google",
7
7
  "maintainers": [
@@ -107,7 +107,7 @@ shaka.ui.AudioLanguageSelection = class extends shaka.ui.SettingsMenu {
107
107
  codec = track.audioCodec;
108
108
  }
109
109
  this.player.selectAudioLanguage(track.language, track.roles[0],
110
- channelsCount, /* safeMargin= */ 0, codec);
110
+ channelsCount, /* safeMargin= */ 0, codec, track.spatialAudio);
111
111
  }
112
112
 
113
113
 
package/ui/controls.js CHANGED
@@ -869,6 +869,10 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
869
869
  }
870
870
 
871
871
  if (this.presentationIsPaused()) {
872
+ // If we are at the end, go back to the beginning.
873
+ if (this.player_.isEnded()) {
874
+ this.video_.currentTime = this.player_.seekRange().start;
875
+ }
872
876
  this.video_.play();
873
877
  } else {
874
878
  this.video_.pause();
@@ -81,6 +81,13 @@ shaka.ui.FastForwardButton = class extends shaka.ui.Element {
81
81
  // selected. If no more rates are available, the first one is set.
82
82
  const newRate = (newRateIndex != this.fastForwardRates_.length) ?
83
83
  this.fastForwardRates_[newRateIndex] : this.fastForwardRates_[0];
84
+
85
+ if (this.video.paused) {
86
+ // Our fast forward is implemented with playbackRate and needs the video
87
+ // to be playing (to not be paused) to take immediate effect.
88
+ // If the video is paused, "unpause" it.
89
+ this.video.play();
90
+ }
84
91
  this.player.trickPlay(newRate);
85
92
 
86
93
  this.button_.setAttribute('shaka-status', newRate + 'x');
package/ui/play_button.js CHANGED
@@ -116,7 +116,7 @@ shaka.ui.PlayButton = class extends shaka.ui.Element {
116
116
  return false;
117
117
  }
118
118
 
119
- return this.video.ended;
119
+ return this.player ? this.player.isEnded() : true;
120
120
  }
121
121
 
122
122
  /**
@@ -121,7 +121,7 @@ shaka.ui.PlaybackRateSelection = class extends shaka.ui.SettingsMenu {
121
121
 
122
122
  this.eventManager.listen(button, 'click', () => {
123
123
  const rate = this.playbackRates_.get(rateStr);
124
- if (rate == 1) {
124
+ if (rate == this.video.defaultPlaybackRate) {
125
125
  this.player.cancelTrickPlay();
126
126
  } else {
127
127
  this.player.trickPlay(rate, /* useTrickPlayTrack= */ false);
@@ -82,6 +82,13 @@ shaka.ui.RewindButton = class extends shaka.ui.Element {
82
82
  // selected. If no more rates are available, the first one is set.
83
83
  const newRate = (newRateIndex != this.rewindRates_.length) ?
84
84
  this.rewindRates_[newRateIndex] : this.rewindRates_[0];
85
+
86
+ if (this.video.paused) {
87
+ // Our fast forward is implemented with playbackRate and needs the video
88
+ // to be playing (to not be paused) to take immediate effect.
89
+ // If the video is paused, "unpause" it.
90
+ this.video.play();
91
+ }
85
92
  this.player.trickPlay(newRate);
86
93
 
87
94
  this.button_.setAttribute('shaka-status', newRate + 'x');