dasha 4.5.0 → 4.5.2

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.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { AudioCodec as AudioCodec$1, DurationMetadataRequestOptions, EncodedPacket, FilePathSource, HLS, HLS_FORMATS, Input as Input$1, InputAudioTrack as InputAudioTrack$1, InputFormat, InputOptions, InputTrack as InputTrack$2, InputTrackQuery, InputTrackQuery as InputTrackQuery$1, InputVideoTrack as InputVideoTrack$1, MP3, MP4, MaybePromise, MaybePromise as MaybePromise$1, MediaCodec as MediaCodec$1, MetadataTags, PacketRetrievalOptions, PathedSource, Source, SourceRef, SubtitleCodec as SubtitleCodec$1, TrackDisposition, TransformationMatrix, UrlSource, VideoCodec as VideoCodec$1, asc, desc, prefer } from "mediabunny";
2
+ import { Temporal } from "temporal-polyfill";
2
3
  //#region src/mediabunny.d.ts
3
4
  type Segment$1 = {
4
5
  timestamp: number;
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ADTS, ALL_FORMATS as ALL_FORMATS$1, CustomPathedSource, FilePathSource, HLS, HLS as HLS$1, HLS_FORMATS, Input as Input$1, InputFormat, InputTrack, InputVideoTrack, MATROSKA, MP3, MP3 as MP3$1, MP4, MP4 as MP4$1, QTFF, SourceRef, UrlSource, WEBM, asc, desc, prefer } from "mediabunny";
2
2
  import { DOMParser } from "@xmldom/xmldom";
3
- import { Temporal } from "temporal-polyfill";
4
3
  import { readFile } from "node:fs/promises";
4
+ import { Temporal } from "temporal-polyfill";
5
5
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
6
6
  import { pathToFileURL } from "node:url";
7
7
  //#region src/util.ts
@@ -514,6 +514,13 @@ const parseDashRange = (range) => {
514
514
  const [startRange, end] = range.split("-").map(Number);
515
515
  return [startRange, end - startRange + 1];
516
516
  };
517
+ const OVERPRECISE_SECONDS_PATTERN = /(\d+)\.(\d{10,})S/;
518
+ const normalizeDashDuration = (duration) => duration.replace(OVERPRECISE_SECONDS_PATTERN, (_, seconds, fraction) => {
519
+ const nanos = Math.round(Number(`0.${fraction}`) * 1e9);
520
+ if (nanos >= 1e9) return `${Number(seconds) + 1}.000000000S`;
521
+ return `${seconds}.${String(nanos).padStart(9, "0")}S`;
522
+ });
523
+ const parseDashDuration = (duration) => Temporal.Duration.from(normalizeDashDuration(duration));
517
524
  //#endregion
518
525
  //#region src/hls/hls-subtitles.ts
519
526
  const TAG_STREAM_INF = "#EXT-X-STREAM-INF:";
@@ -1888,7 +1895,6 @@ var SegmentedMediabunnyInput = class SegmentedMediabunnyInput extends Input$1 {
1888
1895
  //#endregion
1889
1896
  //#region src/dash/dash-segmented-input.ts
1890
1897
  const roundToDivisor = (value, multiple) => Math.round(value * multiple) / multiple;
1891
- const isEncryptedSamplesError = (error) => error instanceof Error && error.message.startsWith("Encrypted media samples encountered");
1892
1898
  const binarySearchLessOrEqual = (array, value, getValue) => {
1893
1899
  let left = 0;
1894
1900
  let right = array.length - 1;
@@ -2153,12 +2159,7 @@ var DashSegmentedInput = class {
2153
2159
  if (!firstSegment) return null;
2154
2160
  const track = await this.getTrackForSegment(firstSegment);
2155
2161
  if (!track) return null;
2156
- let packet = null;
2157
- try {
2158
- packet = await track._backing.getFirstPacket(options);
2159
- } catch (error) {
2160
- if (!isEncryptedSamplesError(error)) throw error;
2161
- }
2162
+ const packet = await track._backing.getFirstPacket(options);
2162
2163
  if (!packet) return null;
2163
2164
  return this.createAdjustedPacket(packet, firstSegment, track);
2164
2165
  }
@@ -2207,12 +2208,7 @@ var DashSegmentedInput = class {
2207
2208
  }
2208
2209
  const input = track.input;
2209
2210
  const offsetTimestamp = timestamp - await this.getMediaOffset(currentSegment, input, track);
2210
- let packet = null;
2211
- try {
2212
- packet = keyframesOnly ? await track._backing.getKeyPacket(offsetTimestamp, options) : await track._backing.getPacket(offsetTimestamp, options);
2213
- } catch (error) {
2214
- if (!keyframesOnly || !isEncryptedSamplesError(error)) throw error;
2215
- }
2211
+ const packet = keyframesOnly ? await track._backing.getKeyPacket(offsetTimestamp, options) : await track._backing.getPacket(offsetTimestamp, options);
2216
2212
  if (!packet) {
2217
2213
  currentSegment = await this.getPreviousSegment(currentSegment);
2218
2214
  continue;
@@ -2255,7 +2251,7 @@ const processDashContent = (mpdContent) => {
2255
2251
  const missingNamespaceDefinitions = missingNamespaceKeys.map((key) => `xmlns:${key}="${DASH_NAMESPACE_MAP.get(key)}"`);
2256
2252
  return replaceFirst(mpdContent, "<MPD ", `<MPD ${missingNamespaceDefinitions.join(" ")} `);
2257
2253
  };
2258
- const getDashRefreshIntervalMs = (timeShiftBufferDepth) => Temporal.Duration.from(timeShiftBufferDepth).total("milliseconds") / 2;
2254
+ const getDashRefreshIntervalMs = (timeShiftBufferDepth) => parseDashDuration(timeShiftBufferDepth).total("milliseconds") / 2;
2259
2255
  const getDisposition = (track) => ({
2260
2256
  ...DEFAULT_TRACK_DISPOSITION,
2261
2257
  commentary: track.role === ROLE_TYPE.Commentary,
@@ -2533,7 +2529,7 @@ const applyFixedDurationTemplate = (params) => {
2533
2529
  const offsetMs = Number(presentationTimeOffset) / 1e3;
2534
2530
  availableTime.setUTCMilliseconds(availableTime.getUTCMilliseconds() + offsetMs);
2535
2531
  const elapsedSeconds = (now - availableTime.getTime()) / 1e3;
2536
- const updateWindowSeconds = Temporal.Duration.from(timeShiftBufferDepth).total("seconds");
2532
+ const updateWindowSeconds = parseDashDuration(timeShiftBufferDepth).total("seconds");
2537
2533
  startNumber += (elapsedSeconds - updateWindowSeconds) * timescale / duration;
2538
2534
  totalNumber = updateWindowSeconds * timescale / duration;
2539
2535
  }
@@ -2750,7 +2746,7 @@ var DashDemuxer = class {
2750
2746
  return manifest;
2751
2747
  }
2752
2748
  appendPeriodTracks(tracks, manifest, period) {
2753
- const periodDurationSeconds = Temporal.Duration.from(period.getAttribute("duration") || manifest.mediaPresentationDuration || "PT0S").total("seconds");
2749
+ const periodDurationSeconds = parseDashDuration(period.getAttribute("duration") || manifest.mediaPresentationDuration || "PT0S").total("seconds");
2754
2750
  const periodBaseUrl = extendDashBaseUrl(period, this.baseUrl);
2755
2751
  for (const adaptationSet of getDirectDashChildren(period, "AdaptationSet")) this.appendAdaptationSetTracks({
2756
2752
  tracks,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dasha",
3
- "version": "4.5.0",
3
+ "version": "4.5.2",
4
4
  "description": "Streaming manifest parser",
5
5
  "files": [
6
6
  "dist"