@mediabunny/server 1.62.1 → 1.64.0

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.
@@ -50,7 +50,7 @@ var MediabunnyServer = (() => {
50
50
  registerMediabunnyServer: () => registerMediabunnyServer,
51
51
  toAvFrame: () => toAvFrame
52
52
  });
53
- var import_mediabunny7 = __require("mediabunny");
53
+ var import_mediabunny8 = __require("mediabunny");
54
54
  var NodeAv8 = __toESM(__require("node-av"));
55
55
 
56
56
  // packages/server/src/video-decoder.ts
@@ -73,7 +73,8 @@ var MediabunnyServer = (() => {
73
73
  flac: NodeAv.AV_CODEC_ID_FLAC,
74
74
  ac3: NodeAv.AV_CODEC_ID_AC3,
75
75
  eac3: NodeAv.AV_CODEC_ID_EAC3,
76
- dts: NodeAv.AV_CODEC_ID_DTS
76
+ dts: NodeAv.AV_CODEC_ID_DTS,
77
+ truehd: NodeAv.AV_CODEC_ID_TRUEHD
77
78
  };
78
79
  var cachedHardwareContext = void 0;
79
80
  var getHardwareContext = () => {
@@ -402,6 +403,24 @@ var MediabunnyServer = (() => {
402
403
  return { nbChannels: numChannels, order: NodeAv.AV_CHANNEL_ORDER_UNSPEC, mask: 0n };
403
404
  }
404
405
  };
406
+ var getTrueHdChannelLayout = (numChannels) => {
407
+ switch (numChannels) {
408
+ case 1:
409
+ return NodeAv.AV_CHANNEL_LAYOUT_MONO;
410
+ case 2:
411
+ return NodeAv.AV_CHANNEL_LAYOUT_STEREO;
412
+ case 3:
413
+ return NodeAv.AV_CHANNEL_LAYOUT_SURROUND;
414
+ case 4:
415
+ return NodeAv.AV_CHANNEL_LAYOUT_4POINT0;
416
+ case 5:
417
+ return NodeAv.AV_CHANNEL_LAYOUT_5POINT0;
418
+ case 6:
419
+ return NodeAv.AV_CHANNEL_LAYOUT_5POINT1;
420
+ default:
421
+ return { nbChannels: numChannels, order: NodeAv.AV_CHANNEL_ORDER_UNSPEC, mask: 0n };
422
+ }
423
+ };
405
424
 
406
425
  // src/logging.ts
407
426
  var _Logging = class _Logging {
@@ -699,6 +718,14 @@ var MediabunnyServer = (() => {
699
718
  throw new Error(`Unexpected value: ${x}`);
700
719
  };
701
720
  var SECOND_TO_MICROSECOND_FACTOR = 1e6 * (1 + Number.EPSILON);
721
+ var isWebKitCache = null;
722
+ var isWebKit = () => {
723
+ if (isWebKitCache !== null) {
724
+ return isWebKitCache;
725
+ }
726
+ return isWebKitCache = !!(typeof navigator !== "undefined" && // eslint-disable-next-line @typescript-eslint/no-deprecated
727
+ (navigator.vendor?.match(/apple/i) || /AppleWebKit/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent) || /\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent)));
728
+ };
702
729
  var NativePromiseConstructor = (async () => {
703
730
  })().constructor;
704
731
  var simplifyRational = (rational) => {
@@ -1219,6 +1246,7 @@ var MediabunnyServer = (() => {
1219
1246
  7350
1220
1247
  ];
1221
1248
  var aacChannelMap = [-1, 1, 2, 3, 4, 5, 6, 8];
1249
+ var generalAudioObjectTypes = [1, 2, 3, 4, 6, 7, 17, 19, 20, 21, 22];
1222
1250
  var parseAacAudioSpecificConfig = (bytes) => {
1223
1251
  if (!bytes || bytes.byteLength < 2) {
1224
1252
  throw new TypeError("AAC description must be at least 2 bytes long.");
@@ -1241,7 +1269,12 @@ var MediabunnyServer = (() => {
1241
1269
  if (coreObjectType === 22) {
1242
1270
  bitstream.skipBits(4);
1243
1271
  }
1244
- } else {
1272
+ }
1273
+ let frameLength = 1024;
1274
+ if (generalAudioObjectTypes.includes(coreObjectType)) {
1275
+ frameLength = bitstream.readBits(1) ? 960 : 1024;
1276
+ }
1277
+ if (objectType !== 5 && objectType !== 29) {
1245
1278
  while (bitstream.getBitsLeft() > 15) {
1246
1279
  const searchStart = bitstream.pos;
1247
1280
  if (bitstream.readBits(11) !== 695) {
@@ -1265,8 +1298,10 @@ var MediabunnyServer = (() => {
1265
1298
  coreObjectType,
1266
1299
  frequencyIndex,
1267
1300
  channelConfiguration,
1301
+ coreSampleRate: sampleRate,
1268
1302
  outputSampleRate,
1269
- outputNumberOfChannels: psPresent && numberOfChannels === 1 ? 2 : numberOfChannels
1303
+ outputNumberOfChannels: psPresent && numberOfChannels === 1 ? 2 : numberOfChannels,
1304
+ frameLength
1270
1305
  };
1271
1306
  };
1272
1307
  var readAacObjectType = (bitstream) => {
@@ -1335,7 +1370,8 @@ var MediabunnyServer = (() => {
1335
1370
  "flac",
1336
1371
  "ac3",
1337
1372
  "eac3",
1338
- "dts"
1373
+ "dts",
1374
+ "truehd"
1339
1375
  ];
1340
1376
  var AUDIO_CODECS = [
1341
1377
  ...NON_PCM_AUDIO_CODECS,
@@ -1577,6 +1613,11 @@ var MediabunnyServer = (() => {
1577
1613
  };
1578
1614
  var VALID_VIDEO_CODEC_STRING_PREFIXES = ["avc1", "avc3", "hev1", "hvc1", "vp8", "vp09", "av01", ...PRORES_FOURCCS];
1579
1615
 
1616
+ // shared/truehd-misc.ts
1617
+ var TRUEHD_MAJOR_SYNC_WORD = 4168249274;
1618
+ var TRUEHD_SAMPLE_RATES = [44100, 48e3, 88200, 96e3, 176400, 192e3];
1619
+ var TRUEHD_CHANNEL_COUNTS = [1, 2, 3, 4, 5, 6];
1620
+
1580
1621
  // src/codec-data.ts
1581
1622
  var iterateNalUnitsInAnnexB = function* (packetData) {
1582
1623
  let i = 0;
@@ -2824,6 +2865,14 @@ var MediabunnyServer = (() => {
2824
2865
  var av1CodecInfoHasColorInfo = (info) => {
2825
2866
  return info.colourPrimaries !== 2 || info.transferCharacteristics !== 2 || info.matrixCoefficients !== 2;
2826
2867
  };
2868
+ var determineAudioPacketType = (codec, packetData) => {
2869
+ if (codec === "truehd") {
2870
+ const syncWord = packetData.byteLength >= 8 ? toDataView(packetData).getUint32(4) : null;
2871
+ return syncWord === TRUEHD_MAJOR_SYNC_WORD ? "key" : "delta";
2872
+ } else {
2873
+ return "key";
2874
+ }
2875
+ };
2827
2876
  var AC3_FRAME_SIZES = [
2828
2877
  // frmsizecod, [48kHz, 44.1kHz, 32kHz] in bytes
2829
2878
  64 * 2,
@@ -3556,7 +3605,7 @@ var MediabunnyServer = (() => {
3556
3605
  }
3557
3606
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
3558
3607
  static supports(codec, config) {
3559
- return codec === "aac" || codec === "opus" || codec === "mp3" || codec === "vorbis" || codec === "flac" || codec === "ac3" || codec === "eac3" || codec === "dts";
3608
+ return codec === "aac" || codec === "opus" || codec === "mp3" || codec === "vorbis" || codec === "flac" || codec === "ac3" || codec === "eac3" || codec === "dts" || codec === "truehd";
3560
3609
  }
3561
3610
  async init() {
3562
3611
  this.frame = new NodeAv6.Frame();
@@ -3574,6 +3623,7 @@ var MediabunnyServer = (() => {
3574
3623
  codecContext.sampleRate = this.config.sampleRate;
3575
3624
  codecContext.channelLayout = getChannelLayout(this.config.numberOfChannels);
3576
3625
  codecContext.timeBase = new NodeAv6.Rational(1, this.config.sampleRate);
3626
+ codecContext.pktTimebase = new NodeAv6.Rational(1, this.config.sampleRate);
3577
3627
  codecContext.codecType = NodeAv6.AVMEDIA_TYPE_AUDIO;
3578
3628
  codecContext.codecId = codecId;
3579
3629
  codecContext.extraData = this.config.description ? Buffer.from(toUint8Array(this.config.description)) : null;
@@ -3660,8 +3710,6 @@ var MediabunnyServer = (() => {
3660
3710
  this.codecContext = null;
3661
3711
  this.resampler = null;
3662
3712
  this.dstFrame = null;
3663
- this.firstExpectedTimestamp = null;
3664
- this.outputTimestampOffset = 0;
3665
3713
  this.inputParametersKey = null;
3666
3714
  this.resamplerInputSampleRate = null;
3667
3715
  this.nextResamplerPts = null;
@@ -3670,7 +3718,7 @@ var MediabunnyServer = (() => {
3670
3718
  }
3671
3719
  static supports(codec, config) {
3672
3720
  const { numberOfChannels, sampleRate } = config;
3673
- return codec === "aac" && numberOfChannels >= 1 && numberOfChannels <= 48 && AAC_SAMPLE_RATES.includes(sampleRate) || codec === "opus" && numberOfChannels >= 1 && numberOfChannels <= 255 && OPUS_SAMPLE_RATES.includes(sampleRate) || codec === "mp3" && numberOfChannels >= 1 && numberOfChannels <= 2 && MP3_SAMPLE_RATES.includes(sampleRate) || codec === "vorbis" && numberOfChannels >= 1 && numberOfChannels <= 255 && sampleRate <= 2e5 || codec === "flac" && numberOfChannels >= 1 && numberOfChannels <= 8 && sampleRate <= 655350 || codec === "ac3" && numberOfChannels >= 1 && numberOfChannels <= 6 && AC3_SAMPLE_RATES.includes(sampleRate) || codec === "eac3" && numberOfChannels >= 1 && numberOfChannels <= 16 && AC3_SAMPLE_RATES.includes(sampleRate) || codec === "dts" && DTS_CHANNEL_COUNTS.includes(numberOfChannels) && DTS_SAMPLE_RATES.includes(sampleRate) && dtsBitrateFits(resolveBitrate(config, codec), sampleRate, numberOfChannels);
3721
+ return codec === "aac" && numberOfChannels >= 1 && numberOfChannels <= 48 && AAC_SAMPLE_RATES.includes(sampleRate) || codec === "opus" && numberOfChannels >= 1 && numberOfChannels <= 255 && OPUS_SAMPLE_RATES.includes(sampleRate) || codec === "mp3" && numberOfChannels >= 1 && numberOfChannels <= 2 && MP3_SAMPLE_RATES.includes(sampleRate) || codec === "vorbis" && numberOfChannels >= 1 && numberOfChannels <= 255 && sampleRate <= 2e5 || codec === "flac" && numberOfChannels >= 1 && numberOfChannels <= 8 && sampleRate <= 655350 || codec === "ac3" && numberOfChannels >= 1 && numberOfChannels <= 6 && AC3_SAMPLE_RATES.includes(sampleRate) || codec === "eac3" && numberOfChannels >= 1 && numberOfChannels <= 16 && AC3_SAMPLE_RATES.includes(sampleRate) || codec === "dts" && DTS_CHANNEL_COUNTS.includes(numberOfChannels) && DTS_SAMPLE_RATES.includes(sampleRate) && dtsBitrateFits(resolveBitrate(config, codec), sampleRate, numberOfChannels) || codec === "truehd" && TRUEHD_CHANNEL_COUNTS.includes(numberOfChannels) && TRUEHD_SAMPLE_RATES.includes(sampleRate);
3674
3722
  }
3675
3723
  async init() {
3676
3724
  this.frame = new NodeAv7.Frame();
@@ -3691,11 +3739,19 @@ var MediabunnyServer = (() => {
3691
3739
  const codecContext = new NodeAv7.CodecContext();
3692
3740
  codecContext.allocContext3(this.avCodec);
3693
3741
  let sampleFormat = NodeAv7.AV_SAMPLE_FMT_FLTP;
3694
- if (this.avCodec.sampleFormats && !this.avCodec.sampleFormats.includes(NodeAv7.AV_SAMPLE_FMT_FLTP)) {
3742
+ if (this.codec === "truehd") {
3743
+ sampleFormat = NodeAv7.AV_SAMPLE_FMT_S32P;
3744
+ } else if (this.avCodec.sampleFormats && !this.avCodec.sampleFormats.includes(NodeAv7.AV_SAMPLE_FMT_FLTP)) {
3695
3745
  sampleFormat = this.avCodec.sampleFormats[0];
3696
3746
  }
3697
3747
  codecContext.sampleRate = this.config.sampleRate;
3698
- codecContext.channelLayout = this.codec === "dts" ? getDtsChannelLayout(this.config.numberOfChannels) : getChannelLayout(this.config.numberOfChannels);
3748
+ if (this.codec === "dts") {
3749
+ codecContext.channelLayout = getDtsChannelLayout(this.config.numberOfChannels);
3750
+ } else if (this.codec === "truehd") {
3751
+ codecContext.channelLayout = getTrueHdChannelLayout(this.config.numberOfChannels);
3752
+ } else {
3753
+ codecContext.channelLayout = getChannelLayout(this.config.numberOfChannels);
3754
+ }
3699
3755
  codecContext.codecType = NodeAv7.AVMEDIA_TYPE_AUDIO;
3700
3756
  codecContext.codecId = CODEC_TO_CODEC_ID[this.codec];
3701
3757
  codecContext.sampleFormat = sampleFormat;
@@ -3705,7 +3761,7 @@ var MediabunnyServer = (() => {
3705
3761
  codecContext.rcMinRate = codecContext.bitRate;
3706
3762
  codecContext.rcMaxRate = codecContext.bitRate;
3707
3763
  }
3708
- const options = this.codec === "dts" ? NodeAv7.Dictionary.fromObject({ strict: -2 }) : null;
3764
+ const options = this.codec === "dts" || this.codec === "truehd" ? NodeAv7.Dictionary.fromObject({ strict: -2 }) : null;
3709
3765
  const ret = await codecContext.open2(this.avCodec, options);
3710
3766
  NodeAv7.FFmpegError.throwIfError(ret, "Open codec context");
3711
3767
  this.codecContext = codecContext;
@@ -3715,7 +3771,6 @@ var MediabunnyServer = (() => {
3715
3771
  await this.createCodecContext();
3716
3772
  assert(this.codecContext);
3717
3773
  }
3718
- this.firstExpectedTimestamp ??= audioSample.timestamp;
3719
3774
  if (audioSample._data instanceof AvFrameAudioSampleResource) {
3720
3775
  this.frame.unref();
3721
3776
  this.frame.ref(audioSample._data.frame);
@@ -3801,19 +3856,17 @@ var MediabunnyServer = (() => {
3801
3856
  }
3802
3857
  receivePacket(ret) {
3803
3858
  assert(this.codecContext);
3804
- assert(this.firstExpectedTimestamp !== null);
3805
3859
  NodeAv7.FFmpegError.throwIfError(ret, "Receive packet");
3806
3860
  if (!this.packet.data) {
3807
3861
  return;
3808
3862
  }
3809
- let timestamp = Number(this.packet.pts) / this.codecContext.sampleRate;
3863
+ const timestamp = Number(this.packet.pts) / this.codecContext.sampleRate;
3810
3864
  const duration = Number(this.packet.duration) / this.codecContext.sampleRate;
3811
3865
  let data = this.packet.data;
3812
3866
  let metadata;
3813
3867
  if (this.packetEmitted) {
3814
3868
  metadata = {};
3815
3869
  } else {
3816
- this.outputTimestampOffset = Math.max(this.firstExpectedTimestamp - timestamp, 0);
3817
3870
  const codecString = this.config.codec;
3818
3871
  let description = this.codecContext.extraData ? toUint8Array(this.codecContext.extraData) : void 0;
3819
3872
  if (this.codec === "aac") {
@@ -3869,10 +3922,9 @@ var MediabunnyServer = (() => {
3869
3922
  final.set(data, this.adtsHeaderTemplate.header.byteLength);
3870
3923
  data = final;
3871
3924
  }
3872
- timestamp += this.outputTimestampOffset;
3873
3925
  const packet = new import_mediabunny6.EncodedPacket(
3874
3926
  data,
3875
- "key",
3927
+ determineAudioPacketType(this.codec, data),
3876
3928
  timestamp,
3877
3929
  duration
3878
3930
  );
@@ -3902,8 +3954,6 @@ var MediabunnyServer = (() => {
3902
3954
  this.codecContext.freeContext();
3903
3955
  this.codecContext = null;
3904
3956
  this.packetEmitted = false;
3905
- this.firstExpectedTimestamp = null;
3906
- this.outputTimestampOffset = 0;
3907
3957
  this.adtsHeaderTemplate = null;
3908
3958
  this.resampler?.free();
3909
3959
  this.resampler = null;
@@ -3925,16 +3975,204 @@ var MediabunnyServer = (() => {
3925
3975
  return config.bitrate ?? new import_mediabunny6.Quality("medium")._toAudioBitrate(codec) ?? 0;
3926
3976
  };
3927
3977
 
3978
+ // packages/prores/src/index.ts
3979
+ var import_mediabunny7 = __require("mediabunny");
3980
+ var import_turbores = __require("turbores");
3981
+ var PRORES_LOADED_SYMBOL = Symbol.for("@mediabunny/prores loaded");
3982
+ if (globalThis[PRORES_LOADED_SYMBOL]) {
3983
+ import_mediabunny7.Logging._error(
3984
+ "[WARNING]\n@mediabunny/prores was loaded twice. This will likely cause the decoder not to work correctly. Check if multiple dependencies are importing different versions of @mediabunny/prores, or if something is being bundled incorrectly."
3985
+ );
3986
+ }
3987
+ globalThis[PRORES_LOADED_SYMBOL] = true;
3988
+ var _ProresDecoder = class _ProresDecoder extends import_mediabunny7.CustomVideoDecoder {
3989
+ constructor() {
3990
+ super(...arguments);
3991
+ this.decoder = null;
3992
+ this.framePool = [];
3993
+ }
3994
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3995
+ static supports(codec, config) {
3996
+ return codec === "prores";
3997
+ }
3998
+ /** @internal */
3999
+ static _determineSupportedVideoFrameFormats() {
4000
+ const result = [];
4001
+ const data = new Uint8Array(32);
4002
+ for (const format of import_turbores.PIXEL_FORMATS) {
4003
+ try {
4004
+ const frame = new VideoFrame(data, {
4005
+ format,
4006
+ codedWidth: 2,
4007
+ codedHeight: 2,
4008
+ timestamp: 0,
4009
+ duration: 0
4010
+ });
4011
+ frame.close();
4012
+ result.push(format);
4013
+ } catch {
4014
+ }
4015
+ }
4016
+ return result;
4017
+ }
4018
+ async init() {
4019
+ if (typeof VideoFrame !== "undefined") {
4020
+ _ProresDecoder._supportedVideoFrameFormats ??= _ProresDecoder._determineSupportedVideoFrameFormats();
4021
+ }
4022
+ const decoder = await import_turbores.Decoder.create({
4023
+ proresFourCc: this.config.codec,
4024
+ useSharedMemory: import_turbores.Decoder.canUseSharedMemory(),
4025
+ allowedOutputFormats: _ProresDecoder._supportedVideoFrameFormats ?? void 0
4026
+ });
4027
+ if (decoder instanceof Error) {
4028
+ throw decoder;
4029
+ }
4030
+ this.decoder = decoder;
4031
+ }
4032
+ async decode(packet) {
4033
+ assert(this.decoder);
4034
+ while (this.decoder.desiredSize <= 0) {
4035
+ await this.decoder.dequeued;
4036
+ }
4037
+ void this.runDecode(packet).catch((error) => this.onError(error));
4038
+ }
4039
+ async runDecode(packet) {
4040
+ assert(this.decoder);
4041
+ let frame;
4042
+ if (this.framePool.length > 0) {
4043
+ frame = this.framePool.shift();
4044
+ } else {
4045
+ frame = new import_turbores.Frame();
4046
+ }
4047
+ const result = await this.decoder.decode(packet.data, frame);
4048
+ this.framePool.push(frame);
4049
+ if (result instanceof Error) {
4050
+ throw result;
4051
+ }
4052
+ if (result.visibleHeight < result.codedHeight && isWebKit()) {
4053
+ this.trimCodedHeightToVisibleHeight(result);
4054
+ }
4055
+ const colorSpaceInit = {
4056
+ primaries: result.colorPrimariesString,
4057
+ matrix: result.colorMatrixString,
4058
+ transfer: result.colorTransferString,
4059
+ fullRange: result.colorRangeFull
4060
+ };
4061
+ let displayWidth = result.visibleWidth;
4062
+ let displayHeight = result.visibleHeight;
4063
+ if (result.pixelAspectRatio.num > result.pixelAspectRatio.den) {
4064
+ displayWidth = Math.round(
4065
+ result.visibleWidth * result.pixelAspectRatio.num / result.pixelAspectRatio.den
4066
+ );
4067
+ } else {
4068
+ displayHeight = Math.round(
4069
+ result.visibleHeight * result.pixelAspectRatio.den / result.pixelAspectRatio.num
4070
+ );
4071
+ }
4072
+ let sample;
4073
+ if (typeof VideoFrame !== "undefined") {
4074
+ const frame2 = new VideoFrame(result.frameData, {
4075
+ format: result.pixelFormat,
4076
+ codedWidth: result.codedWidth,
4077
+ codedHeight: result.codedHeight,
4078
+ displayWidth,
4079
+ displayHeight,
4080
+ visibleRect: {
4081
+ x: 0,
4082
+ y: 0,
4083
+ width: result.visibleWidth,
4084
+ height: result.visibleHeight
4085
+ },
4086
+ timestamp: packet.microsecondTimestamp,
4087
+ duration: packet.microsecondDuration,
4088
+ colorSpace: colorSpaceInit
4089
+ });
4090
+ sample = new import_mediabunny7.VideoSample(frame2, {
4091
+ timestamp: packet.timestamp,
4092
+ duration: packet.duration
4093
+ });
4094
+ } else {
4095
+ sample = new import_mediabunny7.VideoSample(result.frameData, {
4096
+ format: result.pixelFormat,
4097
+ codedWidth: result.codedWidth,
4098
+ codedHeight: result.codedHeight,
4099
+ displayWidth,
4100
+ displayHeight,
4101
+ visibleRect: {
4102
+ left: 0,
4103
+ top: 0,
4104
+ width: result.visibleWidth,
4105
+ height: result.visibleHeight
4106
+ },
4107
+ timestamp: packet.timestamp,
4108
+ duration: packet.duration,
4109
+ colorSpace: colorSpaceInit
4110
+ });
4111
+ }
4112
+ this.onSample(sample);
4113
+ }
4114
+ trimCodedHeightToVisibleHeight(result) {
4115
+ const bytesPerSample = result.pixelFormat.includes("P") ? 2 : 1;
4116
+ const subWidth = result.pixelFormat.includes("444") ? 1 : 2;
4117
+ const subHeight = result.pixelFormat.includes("420") ? 2 : 1;
4118
+ const chromaCodedWidth = result.codedWidth / subWidth;
4119
+ const chromaCodedHeight = result.codedHeight / subHeight;
4120
+ const chromaVisibleHeight = Math.ceil(result.visibleHeight / subHeight);
4121
+ const lumaCodedPixels = result.codedWidth * result.codedHeight;
4122
+ const lumaVisiblePixels = result.codedWidth * result.visibleHeight;
4123
+ const chromaCodedPixels = chromaCodedWidth * chromaCodedHeight;
4124
+ const chromaVisiblePixels = chromaCodedWidth * chromaVisibleHeight;
4125
+ result.frameData.set(
4126
+ result.frameData.subarray(
4127
+ bytesPerSample * lumaCodedPixels,
4128
+ bytesPerSample * (lumaCodedPixels + chromaCodedPixels)
4129
+ ),
4130
+ bytesPerSample * lumaVisiblePixels
4131
+ );
4132
+ result.frameData.set(
4133
+ result.frameData.subarray(
4134
+ bytesPerSample * (lumaCodedPixels + chromaCodedPixels),
4135
+ bytesPerSample * (lumaCodedPixels + 2 * chromaCodedPixels)
4136
+ ),
4137
+ bytesPerSample * (lumaVisiblePixels + chromaVisiblePixels)
4138
+ );
4139
+ result.codedHeight = result.visibleHeight;
4140
+ }
4141
+ async flush() {
4142
+ assert(this.decoder);
4143
+ while (this.decoder.decodeQueueSize > 0) {
4144
+ await this.decoder.dequeued;
4145
+ }
4146
+ }
4147
+ async close() {
4148
+ assert(this.decoder);
4149
+ await this.decoder.close();
4150
+ for (const frame of this.framePool) {
4151
+ frame.clear();
4152
+ }
4153
+ }
4154
+ };
4155
+ /** @internal */
4156
+ _ProresDecoder._supportedVideoFrameFormats = null;
4157
+ var ProresDecoder = _ProresDecoder;
4158
+ var registered = false;
4159
+ var registerProresDecoder = () => {
4160
+ if (registered) {
4161
+ return;
4162
+ }
4163
+ registered = true;
4164
+ (0, import_mediabunny7.registerDecoder)(ProresDecoder);
4165
+ };
4166
+
3928
4167
  // packages/server/src/index.ts
3929
- var import_prores = __require("@mediabunny/prores");
3930
4168
  var SERVER_LOADED_SYMBOL = Symbol.for("@mediabunny/server loaded");
3931
4169
  if (globalThis[SERVER_LOADED_SYMBOL]) {
3932
- import_mediabunny7.Logging._error(
4170
+ import_mediabunny8.Logging._error(
3933
4171
  "[WARNING]\n@mediabunny/server was loaded twice. This will likely cause the package not to work correctly. Check if multiple dependencies are importing different versions of @mediabunny/server, or if something is being bundled incorrectly."
3934
4172
  );
3935
4173
  }
3936
4174
  globalThis[SERVER_LOADED_SYMBOL] = true;
3937
- var registered = false;
4175
+ var registered2 = false;
3938
4176
  var _serverOptions = {};
3939
4177
  var registerMediabunnyServer = (options = {}) => {
3940
4178
  if (typeof options !== "object" || !options) {
@@ -3945,27 +4183,27 @@ var MediabunnyServer = (() => {
3945
4183
  "options.hardwareContext, when provided, must be a NodeAv.HardwareContext, a function, or null."
3946
4184
  );
3947
4185
  }
3948
- if (registered) {
4186
+ if (registered2) {
3949
4187
  return;
3950
4188
  }
3951
- registered = true;
4189
+ registered2 = true;
3952
4190
  _serverOptions = options;
3953
4191
  NodeAv8.Log.setLevel(NodeAv8.AV_LOG_ERROR);
3954
- (0, import_mediabunny7.registerDecoder)(NodeAvVideoDecoder);
3955
- (0, import_prores.registerProresDecoder)();
3956
- (0, import_mediabunny7.registerEncoder)(NodeAvVideoEncoder);
3957
- (0, import_mediabunny7.registerDecoder)(NodeAvAudioDecoder);
3958
- (0, import_mediabunny7.registerEncoder)(NodeAvAudioEncoder);
3959
- (0, import_mediabunny7.registerVideoSampleTransformer)(transformVideoSample);
4192
+ (0, import_mediabunny8.registerDecoder)(NodeAvVideoDecoder);
4193
+ registerProresDecoder();
4194
+ (0, import_mediabunny8.registerEncoder)(NodeAvVideoEncoder);
4195
+ (0, import_mediabunny8.registerDecoder)(NodeAvAudioDecoder);
4196
+ (0, import_mediabunny8.registerEncoder)(NodeAvAudioEncoder);
4197
+ (0, import_mediabunny8.registerVideoSampleTransformer)(transformVideoSample);
3960
4198
  };
3961
4199
  var toAvFrame = async (sample, frame) => {
3962
- if (!(sample instanceof import_mediabunny7.VideoSample) && !(sample instanceof import_mediabunny7.AudioSample)) {
4200
+ if (!(sample instanceof import_mediabunny8.VideoSample) && !(sample instanceof import_mediabunny8.AudioSample)) {
3963
4201
  throw new TypeError("sample must be a VideoSample or an AudioSample.");
3964
4202
  }
3965
4203
  if (!(frame instanceof NodeAv8.Frame)) {
3966
4204
  throw new TypeError("frame must be a NodeAv.Frame.");
3967
4205
  }
3968
- if (sample instanceof import_mediabunny7.VideoSample) {
4206
+ if (sample instanceof import_mediabunny8.VideoSample) {
3969
4207
  if (sample._data instanceof AvFrameVideoSampleResource) {
3970
4208
  frame.unref();
3971
4209
  frame.ref(sample._data.frame);