@libmedia/avplayer 0.5.0 → 0.6.1

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.
@@ -1,7 +1,6 @@
1
1
  import { AVCodecID, AVMediaType } from "@libmedia/avutil/codec";
2
2
  import IOPipeline from "@libmedia/avpipeline/IOPipeline";
3
3
  import DemuxPipeline from "@libmedia/avpipeline/DemuxPipeline";
4
- import VideoDecodePipeline from "@libmedia/avpipeline/VideoDecodePipeline";
5
4
  import AudioDecodePipeline from "@libmedia/avpipeline/AudioDecodePipeline";
6
5
  import { Thread } from "@libmedia/cheap/thread/thread";
7
6
  import Emitter, { EmitterOptions } from "@libmedia/common/event/Emitter";
@@ -16,7 +15,7 @@ import MSEPipeline from "./mse/MSEPipeline";
16
15
  import { AVStreamInterface } from "@libmedia/avutil/AVStream";
17
16
  import { AVFormatContextInterface } from "@libmedia/avformat/AVFormatContext";
18
17
  import { Data, Fn } from "@libmedia/common/types/type";
19
- import { playerEventChanged, playerEventChanging, playerEventError, playerEventNoParam, playerEventTime } from "./type";
18
+ import { playerEventChanged, playerEventChanging, playerEventError, playerEventNoParam, playerEventProgress, playerEventSubtitleDelayChange, playerEventTime, playerEventVolumeChange } from "./type";
20
19
  import FetchIOLoader from "@libmedia/avnetwork/ioLoader/FetchIOLoader";
21
20
  import FileIOLoader from "@libmedia/avnetwork/ioLoader/FileIOLoader";
22
21
  import CustomIOLoader from "@libmedia/avnetwork/ioLoader/CustomIOLoader";
@@ -156,6 +155,10 @@ export interface AVPlayerLoadOptions {
156
155
  * 透传给 format 的参数
157
156
  */
158
157
  formatOptions?: Data;
158
+ /**
159
+ * 设置源是否是直播,覆盖 AVPlayerOptions 里面的配置
160
+ */
161
+ isLive?: boolean;
159
162
  }
160
163
  export interface AVPlayerPlayOptions {
161
164
  /**
@@ -191,6 +194,9 @@ export declare const enum AVPlayerProgress {
191
194
  LOAD_VIDEO_DECODER = 3
192
195
  }
193
196
  export default class AVPlayer extends Emitter implements ControllerObserver {
197
+ /**
198
+ * @internal
199
+ */
194
200
  static Instances: AVPlayer[];
195
201
  static Util: {
196
202
  compile: typeof compile;
@@ -206,23 +212,66 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
206
212
  WebTransportIOLoader: typeof WebTransportIOLoader;
207
213
  };
208
214
  static level: number;
215
+ /**
216
+ * @internal
217
+ */
209
218
  static DemuxThreadReady: Promise<void>;
219
+ /**
220
+ * @internal
221
+ */
210
222
  static AudioThreadReady: Promise<void>;
223
+ /**
224
+ * @internal
225
+ */
211
226
  static VideoThreadReady: Promise<void>;
227
+ /**
228
+ * @internal
229
+ */
212
230
  static MSEThreadReady: Promise<void>;
231
+ /**
232
+ * @internal
233
+ */
213
234
  static IODemuxProxy: IODemuxPipelineProxy;
235
+ /**
236
+ * @internal
237
+ */
214
238
  static AudioPipelineProxy: AudioPipelineProxy;
239
+ /**
240
+ * @internal
241
+ */
215
242
  static MSEPipelineProxy: MSEPipelineProxy;
243
+ /**
244
+ * @internal
245
+ * 下面的线程所有 AVPlayer 实例共享
246
+ */
216
247
  static IOThread: Thread<IOPipeline>;
248
+ /**
249
+ * @internal
250
+ */
217
251
  static DemuxerThread: Thread<DemuxPipeline>;
252
+ /**
253
+ * @internal
254
+ */
218
255
  static AudioDecoderThread: Thread<AudioDecodePipeline>;
256
+ /**
257
+ * @internal
258
+ */
219
259
  static AudioRenderThread: Thread<AudioRenderPipeline>;
260
+ /**
261
+ * @internal
262
+ */
220
263
  static VideoRenderThread: Thread<VideoRenderPipeline>;
264
+ /**
265
+ * @internal
266
+ */
221
267
  static MSEThread: Thread<MSEPipeline>;
222
268
  static audioContext: AudioContext;
269
+ /**
270
+ * @internal
271
+ */
223
272
  static Resource: Map<string, WebAssemblyResource | ArrayBuffer>;
224
- VideoDecoderThread: Thread<VideoDecodePipeline>;
225
- VideoRenderThread: Thread<VideoRenderPipeline>;
273
+ private VideoDecoderThread;
274
+ private VideoRenderThread;
226
275
  private VideoPipelineProxy;
227
276
  private GlobalData;
228
277
  taskId: string;
@@ -259,6 +308,7 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
259
308
  private lastStatus;
260
309
  private playChannels;
261
310
  private seekedTimestamp;
311
+ private isLive_;
262
312
  private statsController;
263
313
  private jitterBufferController;
264
314
  private selectedVideoStream;
@@ -272,7 +322,13 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
272
322
  * 当前播放时间戳(毫秒)
273
323
  */
274
324
  get currentTime(): int64;
325
+ /**
326
+ * @internal
327
+ */
275
328
  private isCodecIdSupported;
329
+ /**
330
+ * @internal
331
+ */
276
332
  private findBestStream;
277
333
  private checkUseMSE;
278
334
  private createCanvas;
@@ -309,13 +365,7 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
309
365
  * @param options 配置项
310
366
  */
311
367
  load(source: string | File | CustomIOLoader, options?: AVPlayerLoadOptions): Promise<void>;
312
- /**
313
- * @internal
314
- */
315
368
  private playUseMSE;
316
- /**
317
- * @internal
318
- */
319
369
  private playUseDecoder;
320
370
  /**
321
371
  * 播放
@@ -404,6 +454,10 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
404
454
  * resume 音频
405
455
  */
406
456
  resume(): Promise<void>;
457
+ /**
458
+ * audioContext 是否是 suspended 状态
459
+ */
460
+ isSuspended(): boolean;
407
461
  /**
408
462
  * 获取播放音量
409
463
  *
@@ -557,12 +611,6 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
557
611
  * @returns
558
612
  */
559
613
  getOptions(): AVPlayerOptions;
560
- /**
561
- * 重新设置是否是直播,load 之前调用
562
- *
563
- * @param is
564
- */
565
- setIsLive(is: boolean): void;
566
614
  /**
567
615
  * 获取 audioContext 声音输出 Node,可拿给外部去处理
568
616
  */
@@ -673,14 +721,30 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
673
721
  * @internal
674
722
  */
675
723
  onMSESeek(time: number): void;
724
+ /**
725
+ * @internal
726
+ */
727
+ onMasterTimerUpdate(time: int64): void;
676
728
  /**
677
729
  * @internal
678
730
  */
679
731
  onAudioContextStateChange(): void;
680
732
  private createVideoDecoderThread;
733
+ /**
734
+ * @internal
735
+ */
681
736
  static startDemuxPipeline(enableWorker?: boolean): Promise<void>;
737
+ /**
738
+ * @internal
739
+ */
682
740
  static startAudioPipeline(enableWorker?: boolean): Promise<void>;
741
+ /**
742
+ * @internal
743
+ */
683
744
  static startVideoRenderPipeline(enableWorker?: boolean): Promise<void>;
745
+ /**
746
+ * @internal
747
+ */
684
748
  static startMSEPipeline(enableWorker?: boolean): Promise<void>;
685
749
  /**
686
750
  * 提前运行所有管线
@@ -704,6 +768,7 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
704
768
  on(event: typeof eventType.STOPPED, listener: typeof playerEventNoParam, options?: Partial<EmitterOptions>): AVPlayer;
705
769
  on(event: typeof eventType.ENDED, listener: typeof playerEventNoParam, options?: Partial<EmitterOptions>): AVPlayer;
706
770
  on(event: typeof eventType.SEEKING, listener: typeof playerEventNoParam, options?: Partial<EmitterOptions>): AVPlayer;
771
+ on(event: typeof eventType.SEEKED, listener: typeof playerEventNoParam, options?: Partial<EmitterOptions>): AVPlayer;
707
772
  on(event: typeof eventType.CHANGING, listener: typeof playerEventChanging, options?: Partial<EmitterOptions>): AVPlayer;
708
773
  on(event: typeof eventType.CHANGED, listener: typeof playerEventChanged, options?: Partial<EmitterOptions>): AVPlayer;
709
774
  on(event: typeof eventType.RESUME, listener: typeof playerEventNoParam, options?: Partial<EmitterOptions>): AVPlayer;
@@ -713,6 +778,10 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
713
778
  on(event: typeof eventType.FIRST_VIDEO_RENDERED, listener: typeof playerEventNoParam, options?: Partial<EmitterOptions>): AVPlayer;
714
779
  on(event: typeof eventType.ERROR, listener: typeof playerEventError, options?: Partial<EmitterOptions>): AVPlayer;
715
780
  on(event: typeof eventType.TIMEOUT, listener: typeof playerEventNoParam, options?: Partial<EmitterOptions>): AVPlayer;
781
+ on(event: typeof eventType.AUDIO_CONTEXT_RUNNING, listener: typeof playerEventNoParam, options?: Partial<EmitterOptions>): AVPlayer;
782
+ on(event: typeof eventType.PROGRESS, listener: typeof playerEventProgress, options?: Partial<EmitterOptions>): AVPlayer;
783
+ on(event: typeof eventType.VOLUME_CHANGE, listener: typeof playerEventVolumeChange, options?: Partial<EmitterOptions>): AVPlayer;
784
+ on(event: typeof eventType.SUBTITLE_DELAY_CHANGE, listener: typeof playerEventSubtitleDelayChange, options?: Partial<EmitterOptions>): AVPlayer;
716
785
  on(event: string, listener: Fn, options?: Partial<EmitterOptions>): AVPlayer;
717
786
  one(event: string, listener: Fn, options?: Partial<EmitterOptions>): this;
718
787
  }
@@ -2,6 +2,7 @@ import Stats from "@libmedia/avpipeline/struct/stats";
2
2
  export interface StatsControllerObserver {
3
3
  onVideoStutter: () => void;
4
4
  onVideoDiscard: () => void;
5
+ onMasterTimerUpdate: (time: int64) => void;
5
6
  }
6
7
  export default class StatsController {
7
8
  private stats;
@@ -13,6 +13,7 @@ export declare const TIMEOUT = "timeout";
13
13
  export declare const ERROR = "error";
14
14
  export declare const TIME = "time";
15
15
  export declare const RESUME = "resume";
16
+ export declare const AUDIO_CONTEXT_RUNNING = "audioContextRunning";
16
17
  export declare const FIRST_AUDIO_RENDERED = "firstAudioRendered";
17
18
  export declare const FIRST_VIDEO_RENDERED = "firstVideoRendered";
18
19
  export declare const STREAM_UPDATE = "streamUpdate";
@@ -47,6 +47,7 @@ interface MSEResource {
47
47
  ended: boolean;
48
48
  seekSync: () => void;
49
49
  startPTS: int64;
50
+ lastDTS: int64;
50
51
  pullQueue: PullQueue;
51
52
  enableRawMpeg: boolean;
52
53
  timestampOffsetUpdated: boolean;
@@ -65,6 +66,8 @@ type SelfTask = MSETaskOptions & {
65
66
  currentTime: double;
66
67
  currentTimeNTP: int32;
67
68
  avpacketPool: AVPacketPool;
69
+ maxBuffer: float;
70
+ minBuffer: float;
68
71
  };
69
72
  export default class MSEPipeline extends Pipeline {
70
73
  tasks: Map<string, SelfTask>;
@@ -81,8 +84,8 @@ export default class MSEPipeline extends Pipeline {
81
84
  private createLoop;
82
85
  private startMux;
83
86
  private resetResource;
84
- addStream(taskId: string, streamIndex: int32, parameters: pointer<AVCodecParameters> | AVCodecParametersSerialize, timeBase: Rational, startPTS: int64, pullIPCPort: MessagePort): Promise<void>;
85
- reAddStream(taskId: string, streamIndex: int32, parameters: pointer<AVCodecParameters> | AVCodecParametersSerialize, timeBase: Rational, startPTS: int64): Promise<void>;
87
+ addStream(taskId: string, streamIndex: int32, parameters: pointer<AVCodecParameters> | AVCodecParametersSerialize, timeBase: Rational, startPTS: int64, pullIPCPort: MessagePort, matrix?: number[]): Promise<void>;
88
+ reAddStream(taskId: string, streamIndex: int32, parameters: pointer<AVCodecParameters> | AVCodecParametersSerialize, timeBase: Rational, startPTS: int64, matrix?: number[]): Promise<void>;
86
89
  pause(taskId: string): Promise<void>;
87
90
  unpause(taskId: string): Promise<void>;
88
91
  beforeSeek(taskId: string): Promise<void>;
@@ -90,6 +93,7 @@ export default class MSEPipeline extends Pipeline {
90
93
  setPlayRate(taskId: string, rate: double): Promise<void>;
91
94
  restart(taskId: string): Promise<void>;
92
95
  setCurrentTime(taskId: string, time: number): Promise<void>;
96
+ private checkWaiting;
93
97
  getMediaSource(taskId: string): Promise<MediaSource>;
94
98
  private createTask;
95
99
  registerTask(options: MSETaskOptions, startTimestamp?: int64): Promise<number>;
@@ -1,6 +1,10 @@
1
+ import { AVPlayerProgress } from "./AVPlayer";
1
2
  import { AVMediaType } from "@libmedia/avutil/codec";
2
3
  export declare function playerEventNoParam(): void;
3
4
  export declare function playerEventTime(pts: int64): void;
4
5
  export declare function playerEventChanging(type: AVMediaType, newStreamId: int32, oldStreamId: int32): void;
5
6
  export declare function playerEventChanged(type: AVMediaType, newStreamId: int32, oldStreamId: int32): void;
6
7
  export declare function playerEventError(error: Error): void;
8
+ export declare function playerEventProgress(progress: AVPlayerProgress, data: any): void;
9
+ export declare function playerEventVolumeChange(volume: double): void;
10
+ export declare function playerEventSubtitleDelayChange(delay: int32): void;
@@ -1 +1 @@
1
- (self.webpackChunklibmedia=self.webpackChunklibmedia||[]).push([[118],{85947:(t,i,e)=>{e.d(i,{A:()=>r});var s=e(134);class r{constructor(){(0,s.A)(this,"type",-1),(0,s.A)(this,"onStreamAdd",void 0)}async destroy(t){}}},29118:(t,i,e)=>{e.r(i),e.d(i,{default:()=>P});var s=e(134),r=e(63939),n=e(50932),a=e(38743),h=e(4624),o=e(54712),d=e(87400),g=e(9705),l=e(92647),p=e(85947),u=e(14686),f=e(37837),c=e(71517),m=e(82348),w=e(35336),b=e(77231),I=e(52071),k=e(44328),S=e(72739),B=e(79630),v=e(43607);const y="src/avformat/formats/IOggFormat.ts";class P extends p.A{constructor(){super(),(0,s.A)(this,"type",4),(0,s.A)(this,"headerPagesPayload",void 0),(0,s.A)(this,"page",void 0),(0,s.A)(this,"curSegIndex",void 0),(0,s.A)(this,"curSegStart",void 0),(0,s.A)(this,"segCount",void 0),(0,s.A)(this,"segIndex",void 0),(0,s.A)(this,"currentPts",void 0),(0,s.A)(this,"firstPos",void 0),(0,s.A)(this,"firstGranulePosition",void 0),(0,s.A)(this,"paddingPayload",void 0),this.page=new a.B,this.headerPagesPayload=[]}init(t){t.ioReader&&t.ioReader.setEndian(!1),t.ioReader&&t.ioReader.setEndian(!1),this.curSegIndex=-1,this.curSegStart=0,this.currentPts=BigInt(0),this.segCount=0,this.segIndex=0,this.firstGranulePosition=BigInt(0)}async estimateTotalBlock(t){let i=BigInt(0);const e=t.ioReader.getPos(),s=this.currentPts,r=await t.ioReader.fileSize();for(await t.ioReader.seek(v.T9(r-BigInt(195072),BigInt(0))),await this.syncPage(t);;)try{this.page.reset(),await this.page.read(t.ioReader),i=this.page.granulePosition}catch(t){break}return await t.ioReader.seek(e),this.currentPts=s,i}async getNextSegment(t){if(this.curSegIndex<0){this.page.granulePosition>BigInt(0)&&(this.currentPts=this.page.granulePosition),this.page.reset(),await this.page.read(t.ioReader),this.curSegIndex=0,this.curSegStart=0,this.segIndex=-1,this.segCount=0;for(let t=0;t<this.page.segmentTable.length;t++)255!==this.page.segmentTable[t]&&this.segCount++;this.segCount||(this.segCount=1)}let i=0;for(;this.curSegIndex<this.page.segmentTable.length;){const t=this.page.segmentTable[this.curSegIndex++];if(i+=t,255!==t)break}const e=this.curSegStart;return this.curSegStart+=i,this.segIndex++,this.curSegIndex===this.page.segmentTable.length&&(this.curSegIndex=-1),this.page.payload.subarray(e,e+i)}addComment(t,i){t.vendorString&&(i.metadata.vendor=t.vendorString),S.__(t.comments.list,(t=>{const e=t.split("=");if(e.length>1){const t=e.shift(),s=e.join("=");i.metadata[t]=s}}))}async createStream(t,i){if(i.length<8)return 0;let e=new m.A(i.length,!1);e.appendBuffer(i);const s=e.peekString(8);if("OpusHead"===s){const s=new o.q;s.read(e);const r=new o.o;i=await this.getNextSegment(t),e=new m.A(i.length,!1),e.appendBuffer(i),r.read(e),this.headerPagesPayload=[s,r];const n=t.createStream();n.codecpar.codecType=1,n.codecpar.codecId=86076,n.codecpar.sampleRate=s.sampleRate,n.codecpar.chLayout.nbChannels=s.channels,n.timeBase.den=n.codecpar.sampleRate,n.timeBase.num=1,n.privData={serialNumber:this.page.serialNumber},this.addComment(r,n),n.duration=await this.estimateTotalBlock(t)}else if("vorbis"===s.slice(1,7)){const s=[i],r=new d.m;r.read(e);const n=new d.G;i=await this.getNextSegment(t),e=new m.A(i.length,!1),e.appendBuffer(i),n.read(e),s.push(i),this.headerPagesPayload=[r,n];const a=t.createStream();a.codecpar.codecType=1,a.codecpar.codecId=86021,a.codecpar.sampleRate=r.sampleRate,a.codecpar.chLayout.nbChannels=r.channels,a.timeBase.den=a.codecpar.sampleRate,a.timeBase.num=1,a.privData={serialNumber:this.page.serialNumber},this.addComment(n,a),s.push(await this.getNextSegment(t));const h=s.reduce(((t,i)=>t+2+i.length),0),o=(0,f.sY)(h),g=new w.A(h,!0,new B.A(o,h));s.forEach((t=>{g.writeUint16(t.length),g.writeBuffer(t)})),a.codecpar.extradata=o,a.codecpar.extradataSize=h,a.duration=await this.estimateTotalBlock(t)}else if("FLAC"===s.slice(1,5)){e.setEndian(!0),e.skip(1),e.skip(4),e.skip(1),e.skip(1),e.readUint16(),e.skip(4);const s=e.readUint8(),r=e.readUint24();if(0!==s)return g.LR;{const s=t.createStream();s.codecpar.codecType=1,s.codecpar.codecId=86028;const n=(0,f.sY)(r);e.peekBuffer(r,(0,u.s3)(n,r)),e.skip(10);const h=e.readUint24();s.codecpar.sampleRate=h>>4,s.codecpar.chLayout.nbChannels=1+((15&h)>>>1),s.timeBase.den=s.codecpar.sampleRate,s.timeBase.num=1,s.privData={serialNumber:this.page.serialNumber},s.codecpar.extradata=n,s.codecpar.extradataSize=r;const o=new a.h;i=await this.getNextSegment(t),e=new m.A(i.length-4,!1),e.appendBuffer(i.subarray(4)),o.read(e),s.duration=await this.estimateTotalBlock(t),this.addComment(o,s),this.headerPagesPayload=[o]}}else{if("Speex"!==s.slice(0,5))return 0;{const s=t.createStream();s.codecpar.codecType=1,s.codecpar.codecId=86051;const r=(0,f.sY)(i.length);(0,u.lW)(r,i.length,i),s.codecpar.extradata=r,s.codecpar.extradataSize=i.length,e.seek(BigInt(36)),s.codecpar.sampleRate=e.readUint32(),e.seek(BigInt(48)),s.codecpar.chLayout.nbChannels=e.readUint32(),s.timeBase.den=s.codecpar.sampleRate,s.timeBase.num=1,s.privData={serialNumber:this.page.serialNumber};const n=new a.h;i=await this.getNextSegment(t),e=new m.A(i.length,!1),e.appendBuffer(i),n.read(e),s.duration=await this.estimateTotalBlock(t),this.addComment(n,s),this.headerPagesPayload=[n]}}return 1}async readHeader(t){try{if("OggS"!==await t.ioReader.peekString(4))return h.z3("the file format is not oggs",y,387),g.LR;for(;;){let i=this.paddingPayload||await this.getNextSegment(t);this.paddingPayload&&(this.paddingPayload=null);const e=await this.createStream(t,i);if(e<0)return e;if(!e){this.paddingPayload=i;break}}return this.firstPos=this.paddingPayload?this.page.pos:t.ioReader.getPos(),0}catch(i){return h.z3(i.message,y,409),t.ioReader.error}}async readAVPacket(t,i){n.M[17](i+56,t.ioReader.getPos());try{const e=this.paddingPayload||await this.getNextSegment(t);this.paddingPayload&&(this.paddingPayload=null);let s=this.currentPts+(this.page.granulePosition-this.currentPts)/BigInt(Math.floor(this.segCount))*BigInt(Math.floor(this.segIndex));n.M[17](i+16,s),n.M[17](i+8,s),this.firstGranulePosition||(this.firstGranulePosition=this.page.granulePosition);const a=t.streams.find((t=>t.privData&&t.privData.serialNumber===this.page.serialNumber));if(!a)return await this.createStream(t,e),this.readAVPacket(t,i);n.M[15](i+32,a.index),n.M[15](i+76,a.timeBase.den),n.M[15](i+72,a.timeBase.num),1===a.codecpar.codecType&&n.M[15](i+36,1|r.f[15](i+36));const h=[e];for(;this.curSegIndex<0;)try{if(!(1&(await t.ioReader.peekBuffer(6))[5]))break;h.push(await this.getNextSegment(t))}catch(t){break}const o=(0,l.A)(Uint8Array,h),d=o.length,g=(0,f.sY)(d);return(0,u.lW)(g,d,o),(0,c.NX)(i,g,d),0}catch(i){return-1048576!==t.ioReader.error?(h.z3(`read packet error, ${i}`,y,478),g.LR):t.ioReader.error}}async syncPage(t){let i=b.Dh,e=BigInt(0);for(;;)try{if("OggS"===await t.ioReader.peekString(4)){i=t.ioReader.getPos(),this.page.reset(),await this.page.read(t.ioReader),e=this.page.granulePosition;let s=0;for(;3!==s&&"OggS"===await t.ioReader.peekString(4);)s++,this.page.reset(),await this.page.read(t.ioReader);if(3===s)break}await t.ioReader.skip(1)}catch(t){break}if(i!==b.Dh){for(await t.ioReader.seek(i);1&(await t.ioReader.peekBuffer(6))[5];)this.page.reset(),await this.page.read(t.ioReader),e=this.page.granulePosition;this.currentPts=e-this.firstGranulePosition,this.curSegIndex=-1}}async seek(t,i,e,s){const r=t.ioReader.getPos();if(2&s){const i=await t.ioReader.fileSize();return i<=BigInt(0)?BigInt(g.E$):(e<BigInt(0)?e=BigInt(0):e>i&&(e=i),await t.ioReader.seek(e),4&s||await this.syncPage(t),r)}return(0,k.k)(e,i.timeBase,b.i0)<BigInt(1e4)?(h.Yz(`seek pts is earlier then 10s, seek to first packet pos(${this.firstPos}) directly`,y,570),await t.ioReader.seek(this.firstPos),this.currentPts=BigInt(0),r):(0,I.A)(t,i,e,this.firstPos,this.readAVPacket.bind(this),this.syncPage.bind(this))}getAnalyzeStreamsCount(){return 1}}},38743:(t,i,e)=>{e.d(i,{B:()=>h,h:()=>o});var s=e(134),r=e(77231),n=e(50011);class a{constructor(){(0,s.A)(this,"list",void 0),this.list=[]}read(t,i){for(let e=0;e<i;e++){const i=t.readUint32();this.list.push(t.readString(i))}}write(t){for(let i=0;i<this.list.length;i++){const e=n.encode(this.list[i]);t.writeUint32(e.length),t.writeBuffer(e)}}addComment(t){this.list.push(t)}}class h{constructor(){(0,s.A)(this,"capturePattern",void 0),(0,s.A)(this,"streamStructureVersion",void 0),(0,s.A)(this,"headerTypeFlag",void 0),(0,s.A)(this,"granulePosition",void 0),(0,s.A)(this,"serialNumber",void 0),(0,s.A)(this,"pageSequenceNumber",void 0),(0,s.A)(this,"crcCheckSum",void 0),(0,s.A)(this,"numberPageSegments",void 0),(0,s.A)(this,"segmentTable",void 0),(0,s.A)(this,"payload",void 0),(0,s.A)(this,"pos",void 0),this.reset()}reset(){this.capturePattern="OggS",this.streamStructureVersion=0,this.headerTypeFlag=0,this.granulePosition=r.Dh,this.serialNumber=0,this.pageSequenceNumber=0,this.crcCheckSum=0,this.numberPageSegments=0,this.segmentTable=[],this.pos=BigInt(0)}async read(t){this.pos=t.getPos(),await this.readPageHeader(t);const i=this.segmentTable.reduce(((t,i)=>t+i),0);i&&(this.payload=await t.readBuffer(i))}async readPageHeader(t){if(this.capturePattern=await t.readString(4),this.streamStructureVersion=await t.readUint8(),this.headerTypeFlag=await t.readUint8(),this.granulePosition=await t.readUint64(),this.serialNumber=await t.readUint32(),this.pageSequenceNumber=await t.readUint32(),this.crcCheckSum=await t.readUint32(),this.numberPageSegments=await t.readUint8(),this.numberPageSegments)for(let i=0;i<this.numberPageSegments;i++){const i=await t.readUint8();this.segmentTable.push(i)}}write(t){if(this.pos=t.getPos(),t.writeString(this.capturePattern),t.writeUint8(this.streamStructureVersion),t.writeUint8(this.headerTypeFlag),t.writeUint64(this.granulePosition),t.writeUint32(this.serialNumber),t.writeUint32(this.pageSequenceNumber),t.writeUint32(this.crcCheckSum),this.payload){this.numberPageSegments=Math.floor(this.payload.length/255)+1;const i=this.payload.length%255;t.writeUint8(this.numberPageSegments);for(let i=0;i<this.numberPageSegments-1;i++)t.writeUint8(255);t.writeUint8(i),t.writeBuffer(this.payload)}else t.writeUint8(0)}}class o{constructor(){(0,s.A)(this,"streamIndex",void 0),(0,s.A)(this,"signature",void 0),(0,s.A)(this,"vendorStringLength",void 0),(0,s.A)(this,"vendorString",void 0),(0,s.A)(this,"userCommentListLength",void 0),(0,s.A)(this,"comments",void 0),this.vendorString="v0.5.0",this.vendorStringLength=this.vendorString.length,this.userCommentListLength=0,this.comments=new a}read(t){this.vendorStringLength=t.readUint32(),this.vendorString=t.readString(this.vendorStringLength),this.userCommentListLength=t.readUint32(),this.userCommentListLength&&this.comments.read(t,this.userCommentListLength)}write(t){const i=n.encode(this.vendorString);t.writeUint32(i.length),t.writeBuffer(i),t.writeUint32(this.comments.list.length),this.comments.write(t)}addComment(t){this.comments.addComment(t)}setCodec(t){}}},54712:(t,i,e)=>{e.d(i,{o:()=>h,q:()=>a});var s=e(134),r=e(38743);class n{constructor(){(0,s.A)(this,"streamCount",void 0),(0,s.A)(this,"coupledStreamCount",void 0),(0,s.A)(this,"mapping",void 0),this.streamCount=1,this.coupledStreamCount=0,this.mapping=new Uint8Array(1)}read(t){this.streamCount=t.readUint8(),this.coupledStreamCount=t.readUint8(),this.mapping=t.readBuffer(this.streamCount+this.coupledStreamCount)}write(t){t.writeUint8(this.streamCount),t.writeUint8(this.coupledStreamCount),t.writeBuffer(this.mapping)}}class a{constructor(){(0,s.A)(this,"streamIndex",void 0),(0,s.A)(this,"signature",void 0),(0,s.A)(this,"version",void 0),(0,s.A)(this,"channels",void 0),(0,s.A)(this,"preSkip",void 0),(0,s.A)(this,"sampleRate",void 0),(0,s.A)(this,"outputGain",void 0),(0,s.A)(this,"channelMappingFamily",void 0),(0,s.A)(this,"channelMappingTable",void 0),this.signature="OpusHead",this.version=1,this.channels=1,this.preSkip=0,this.sampleRate=48e3,this.outputGain=0,this.channelMappingFamily=0,this.channelMappingTable=new n}read(t){this.signature=t.readString(8),this.version=t.readUint8(),this.channels=t.readUint8(),this.preSkip=t.readUint16(),this.sampleRate=t.readUint32(),this.outputGain=t.readInt16(),this.channelMappingFamily=t.readUint8(),0!==this.channelMappingFamily&&this.channelMappingTable.read(t)}write(t){t.writeString(this.signature),t.writeUint8(this.version),t.writeUint8(this.channels),t.writeUint16(this.preSkip),t.writeUint32(this.sampleRate),t.writeInt16(this.outputGain),t.writeUint8(this.channelMappingFamily),0!==this.channelMappingFamily&&this.channelMappingTable.write(t)}setCodec(t){this.sampleRate=t.sampleRate,this.channels=t.chLayout.nbChannels,this.channelMappingFamily=t.format}}class h extends r.h{constructor(){super(),this.signature="OpusTags"}read(t){this.signature=t.readString(8),super.read(t)}write(t){t.writeString(this.signature),super.write(t)}addComment(t){this.comments.addComment(t)}setCodec(t){}}},87400:(t,i,e)=>{e.d(i,{G:()=>a,m:()=>n});var s=e(134),r=e(38743);class n{constructor(t="vorbis"){(0,s.A)(this,"streamIndex",void 0),(0,s.A)(this,"packetType",void 0),(0,s.A)(this,"signature",void 0),(0,s.A)(this,"version",void 0),(0,s.A)(this,"channels",void 0),(0,s.A)(this,"sampleRate",void 0),(0,s.A)(this,"bitrateMaximum",void 0),(0,s.A)(this,"bitrateNominal",void 0),(0,s.A)(this,"bitrateMinimum",void 0),(0,s.A)(this,"blocksize0",void 0),(0,s.A)(this,"blocksize1",void 0),(0,s.A)(this,"framingFlag",void 0),this.signature=t,this.version=0,this.channels=1,this.sampleRate=48e3,this.bitrateMaximum=0,this.bitrateNominal=0,this.bitrateMinimum=0,this.blocksize0=2048,this.blocksize1=256}read(t){this.packetType=t.readUint8(),this.signature=t.readString(6),this.version=t.readUint32(),this.channels=t.readUint8(),this.sampleRate=t.readInt32(),this.bitrateMaximum=t.readInt32(),this.bitrateNominal=t.readInt32(),this.bitrateMinimum=t.readInt32();const i=255&t.readUint8();this.blocksize0=Math.pow(2,i>>>4),this.blocksize1=Math.pow(2,15&i),this.framingFlag=t.readUint8()}write(t){t.writeUint8(1),t.writeString(this.signature),t.writeUint32(this.version),t.writeUint8(this.channels),t.writeInt32(this.sampleRate),t.writeInt32(this.bitrateMaximum),t.writeInt32(this.bitrateNominal),t.writeInt32(this.bitrateMinimum),t.writeUint8(Math.log2(this.blocksize0)<<4|Math.log2(this.blocksize1)),t.writeUint8(1)}setCodec(t){this.sampleRate=t.sampleRate,this.channels=t.chLayout.nbChannels}}class a extends r.h{constructor(t="vorbis"){super(),(0,s.A)(this,"packetType",void 0),(0,s.A)(this,"framingFlag",void 0),this.signature=t,this.packetType=1,this.framingFlag=1}read(t){this.packetType=t.readUint8(),this.signature=t.readString(6),super.read(t),"vorbis"===this.signature&&(this.framingFlag=t.readUint8())}write(t){t.writeUint8(this.packetType),t.writeString(this.signature),super.write(t),"vorbis"===this.signature&&t.writeUint8(this.framingFlag)}addComment(t){this.comments.addComment(t)}setCodec(t){}}},2187:(t,i,e)=>{e.d(i,{d:()=>a});var s=e(72739),r=e(44328),n=e(77231);function a(t,i,e){let a=BigInt(0);return s.__(t,(t=>{a+=t.codecpar.bitrate*(0,r.k)(i,e,n.i0)/BigInt(8e3)})),a}},52071:(t,i,e)=>{e.d(i,{A:()=>l});var s=e(63939),r=(e(9599),e(77231)),n=e(44328),a=e(2187),h=e(71517),o=e(9705),d=e(4624);const g="src/avformat/function/seekInBytes.ts";async function l(t,i,e,l,p,u){const f=t.ioReader.getPos(),c=await t.ioReader.fileSize();let m=r.Dh,w=e;i.startTime!==r.Dh?w-=i.startTime:w-=i.firstDTS;const b=(0,n.k)(e,i.timeBase,r.i0);if(b<BigInt(1e4))return d.Yz(`seek pts is earlier then 10s, seek to first packet pos(${l}) directly`,g,62),await t.ioReader.seek(l),f;let I=(0,a.d)(t.streams,w,i.timeBase);const k=c-(0,a.d)(t.streams,BigInt(1e4),r.i0),S=(0,a.d)(t.streams,BigInt(1e4),r.i0);if(I>k&&(I=k),I<l)return await t.ioReader.seek(l),f;const B=(0,h._5)();let v=c,y=BigInt(0);for(;;){if(v-y<S){m=y;break}if(await t.ioReader.seek(I),await u(t),8&t.ioReader.flags)break;const i=t.ioReader.getPos();if(!(await p(t,B)>=0)){m=r.Dh;break}{const t=(0,n.Mr)(s.f[17](B+8),B+72,r.i0),e=t-b;if(d.Yz(`try to seek to pos: ${I}, got packet pts: ${s.f[17](B+8)}(${t}ms), diff: ${e}ms`,g,100),e<=BigInt(0)&&-e<BigInt(1e4)){m=i;break}e>BigInt(0)?(v=I,I=y+v>>BigInt(1)):(y=I,I=y+v>>BigInt(1))}if(8&t.ioReader.flags)break}return(0,h.Qe)(B),m!==r.Dh?(d.Yz(`finally seek to pos ${m}`,g,131),await t.ioReader.seek(m),await u(t),f):(await t.ioReader.seek(f),8&t.ioReader.flags?BigInt(o.LT):BigInt(o.E$))}},82348:(t,i,e)=>{e.d(i,{A:()=>h});var s=e(134),r=e(4624),n=e(50011);const a="src/common/io/IOReaderSync.ts";class h{constructor(t=1048576,i=!0,e){if((0,s.A)(this,"data",void 0),(0,s.A)(this,"buffer",void 0),(0,s.A)(this,"pointer",void 0),(0,s.A)(this,"endPointer",void 0),(0,s.A)(this,"pos",void 0),(0,s.A)(this,"size",void 0),(0,s.A)(this,"littleEndian",void 0),(0,s.A)(this,"fileSize_",void 0),(0,s.A)(this,"error",void 0),(0,s.A)(this,"onFlush",void 0),(0,s.A)(this,"onSeek",void 0),(0,s.A)(this,"onSize",void 0),(0,s.A)(this,"flags",void 0),this.pos=BigInt(0),this.pointer=0,this.error=0,this.endPointer=0,this.littleEndian=!i,this.flags=0,e&&e.view)this.size=e.length,this.buffer=e,this.data=e.view;else if(e&&!e.byteOffset)this.size=e.length,this.buffer=e,this.data=new DataView(this.buffer.buffer);else{if(e)throw new Error("not support subarray of ArrayBuffer");this.size=Math.max(t,102400),this.buffer=new Uint8Array(this.size),this.data=new DataView(this.buffer.buffer)}}readUint8(){this.remainingLength()<1&&this.flush(1);const t=this.data.getUint8(this.pointer);return this.pointer++,this.pos++,t}peekUint8(){return this.remainingLength()<1&&this.flush(1),this.data.getUint8(this.pointer)}readUint16(){this.remainingLength()<2&&this.flush(2);const t=this.data.getUint16(this.pointer,this.littleEndian);return this.pointer+=2,this.pos+=BigInt(2),t}peekUint16(){return this.remainingLength()<2&&this.flush(2),this.data.getUint16(this.pointer,this.littleEndian)}readUint24(){this.remainingLength()<3&&this.flush(3);const t=this.readUint16(),i=this.readUint8();return this.littleEndian?i<<16|t:t<<8|i}peekUint24(){this.remainingLength()<3&&this.flush(3);const t=this.pointer,i=this.pos,e=this.readUint16(),s=this.readUint8(),r=this.littleEndian?s<<16|e:e<<8|s;return this.pointer=t,this.pos=i,r}readUint32(){this.remainingLength()<4&&this.flush(4);const t=this.data.getUint32(this.pointer,this.littleEndian);return this.pointer+=4,this.pos+=BigInt(4),t}peekUint32(){return this.remainingLength()<4&&this.flush(4),this.data.getUint32(this.pointer,this.littleEndian)}readUint64(){this.remainingLength()<8&&this.flush(8);const t=this.data.getBigUint64(this.pointer,this.littleEndian);return this.pointer+=8,this.pos+=BigInt(8),t}peekUint64(){return this.remainingLength()<8&&this.flush(8),this.data.getBigUint64(this.pointer,this.littleEndian)}readInt8(){this.remainingLength()<1&&this.flush(1);const t=this.data.getInt8(this.pointer);return this.pointer++,this.pos++,t}peekInt8(){return this.remainingLength()<1&&this.flush(1),this.data.getInt8(this.pointer)}readInt16(){this.remainingLength()<2&&this.flush(2);const t=this.data.getInt16(this.pointer,this.littleEndian);return this.pointer+=2,this.pos+=BigInt(2),t}peekInt16(){return this.remainingLength()<2&&this.flush(2),this.data.getInt16(this.pointer,this.littleEndian)}readInt24(){const t=this.readUint24();return 8388608&t?t-16777216:t}peekInt24(){const t=this.peekUint24();return 8388608&t?t-16777216:t}readInt32(){this.remainingLength()<4&&this.flush(4);const t=this.data.getInt32(this.pointer,this.littleEndian);return this.pointer+=4,this.pos+=BigInt(4),t}peekInt32(){return this.remainingLength()<4&&this.flush(4),this.data.getInt32(this.pointer,this.littleEndian)}readInt64(){this.remainingLength()<8&&this.flush(8);const t=this.data.getBigInt64(this.pointer,this.littleEndian);return this.pointer+=8,this.pos+=BigInt(8),t}peekInt64(){return this.remainingLength()<8&&this.flush(8),this.data.getBigInt64(this.pointer,this.littleEndian)}readFloat(){this.remainingLength()<4&&this.flush(4);const t=this.data.getFloat32(this.pointer,this.littleEndian);return this.pointer+=4,this.pos+=BigInt(4),t}peekFloat(){return this.remainingLength()<4&&this.flush(4),this.data.getFloat32(this.pointer,this.littleEndian)}readDouble(){this.remainingLength()<8&&this.flush(8);const t=this.data.getFloat64(this.pointer,this.littleEndian);return this.pointer+=8,this.pos+=BigInt(8),t}peekDouble(){return this.remainingLength()<8&&this.flush(8),this.data.getFloat64(this.pointer,this.littleEndian)}readHex(t=1){let i="";for(let e=0;e<t;e++){const t=this.readUint8().toString(16);i+=1===t.length?"0"+t:t}return i}peekHex(t=1){t>this.size&&(this.error=-1048574,r.h2("peekHex, length too large",a,412)),this.remainingLength()<t&&this.flush(t);const i=this.pointer,e=this.pos;let s="";for(let i=0;i<t;i++){const t=this.readUint8().toString(16);s+=1===t.length?"0"+t:t}return this.pointer=i,this.pos=e,s}readBuffer(t,i){if(!t)return new Uint8Array(0);if(i||(i=new Uint8Array(t)),this.remainingLength()<t){let e=0;if(this.remainingLength()>0){const s=this.remainingLength();i.set(this.buffer.subarray(this.pointer,this.pointer+s),e),e+=s,this.pointer+=s,this.pos+=BigInt(s),t-=s}for(;t>0;){this.flush();const s=Math.min(this.endPointer-this.pointer,t);i.set(this.buffer.subarray(this.pointer,this.pointer+s),e),e+=s,this.pointer+=s,this.pos+=BigInt(s),t-=s}}else i.set(this.buffer.subarray(this.pointer,this.pointer+t),0),this.pointer+=t,this.pos+=BigInt(t);return i}peekBuffer(t,i){return t?(t>this.size&&(this.error=-1048574,r.h2("peekBuffer, length too large",a,505)),this.remainingLength()<t&&this.flush(t),i||(i=new Uint8Array(t)),i.set(this.buffer.subarray(this.pointer,this.pointer+t),0),i):new Uint8Array(0)}readToBuffer(t,i){if(this.remainingLength()<t){let e=0;if(this.remainingLength()>0){const s=this.remainingLength();i.set(this.buffer.subarray(this.pointer,this.pointer+s),e),e+=s,this.pointer+=s,this.pos+=BigInt(s),t-=s}for(;t>0;){try{this.flush()}catch(t){if(-1048576===this.error&&e)return e;throw t}const s=Math.min(this.endPointer-this.pointer,t);i.set(this.buffer.subarray(this.pointer,this.pointer+s),e),e+=s,this.pointer+=s,this.pos+=BigInt(s),t-=s}return e}return i.set(this.buffer.subarray(this.pointer,this.pointer+t),0),this.pointer+=t,this.pos+=BigInt(t),t}readString(t=1){const i=this.readBuffer(t);return n.decode(i)}peekString(t=1){const i=this.peekBuffer(t);return n.decode(i)}readLine(){let t="";for(;;){let i=!1;for(let e=this.pointer;e<this.endPointer;e++)if(10===this.buffer[e]||13===this.buffer[e]){e!==this.pointer&&(t+=this.readString(e-this.pointer)),i=!0;break}if(i)break;t+=this.readString(this.remainingLength()),this.flush()}let i=this.peekUint8();return 10!==i&&13!==i||(this.pointer++,13===i&&(i=this.peekUint8(),10===i&&this.pointer++)),t}peekLine(){this.remainingLength()<this.size&&this.flush();let t="",i=!1;for(let e=this.pointer;e<this.endPointer;e++)if(10===this.buffer[e]||13===this.buffer[e]){t+=this.peekString(e-this.pointer),i=!0;break}return i||(this.error=-1048574,r.h2("peekLine, out of buffer",a,656)),t}getPointer(){return this.pointer}getPos(){return this.pos}skip(t){const i=t;for(;this.remainingLength()<t;)t-=this.remainingLength(),this.pointer=this.endPointer,this.flush();this.remainingLength()>=t&&(this.pointer+=t),this.pos+=BigInt(i)}remainingLength(){return this.endPointer-this.pointer}flush(t=0){if(this.onFlush||(this.error=-1048574,r.h2("IOReader error, flush failed because of no flush callback",a,720)),!(this.size-this.remainingLength()<=0)){if(t=Math.min(t,this.size),this.pointer<this.endPointer?(this.buffer.set(this.buffer.subarray(this.pointer,this.endPointer),0),this.endPointer=this.endPointer-this.pointer):this.endPointer=0,this.pointer=0,t)for(;this.remainingLength()<t;){const t=this.onFlush(this.buffer.subarray(this.endPointer));if(t<0)throw this.error=t,new Error(`IOReader error, flush ${-1048576===t?"ended":"failed"}, ret: ${t}`);this.endPointer+=t}else{const t=this.onFlush(this.buffer.subarray(this.endPointer));if(t<0)throw this.error=t,new Error(`IOReader error, flush ${-1048576===t?"ended":"failed"}, ret: ${t}`);this.endPointer+=t}this.error=0}}seek(t,i=!1,e=!0){if(!i){const i=Number(t-this.pos);if(i<0&&Math.abs(i)<this.pointer)return this.pointer+=i,void(this.pos=t);if(i>0&&this.pointer+i<this.endPointer)return this.pointer+=i,void(this.pos=t);if(0===i)return}this.onSeek||(this.error=-1048574,r.h2("IOReader error, seek failed because of no seek callback",a,790)),this.pointer=this.endPointer=0,this.pos=t;const s=this.onSeek(t);0!==s&&(this.error=s,r.h2("IOReader error, seek failed",a,799)),e&&this.flush()}getBuffer(){return this.buffer}appendBuffer(t){if(this.size-this.endPointer>=t.length)this.buffer.set(t,this.endPointer),this.endPointer+=t.length;else if(this.buffer.set(this.buffer.subarray(this.pointer,this.endPointer),0),this.endPointer=this.endPointer-this.pointer,this.pointer=0,this.size-this.endPointer>=t.length)this.buffer.set(t,this.endPointer),this.endPointer+=t.length;else{const i=Math.min(this.size-this.endPointer,t.length);this.buffer.set(t.subarray(0,i),this.endPointer),this.endPointer+=i,r.R8("IOReader, call appendBuffer but the buffer's size is lagger then the remaining size",a,838)}}reset(){this.pointer=this.endPointer=0,this.pos=BigInt(0),this.error=0}setEndian(t){this.littleEndian=!t}fileSize(){if(this.fileSize_)return this.fileSize_;if(!this.onSize)return r.R8("IOReader error, fileSize failed because of no onSize callback",a,871),BigInt(0);try{this.fileSize_=this.onSize()}catch(t){r.R8(`IOReader error, call fileSize failed: ${t}`,a,878),this.fileSize_=BigInt(0)}return this.fileSize_}getBufferSize(){return this.size}pipe(t,i){if(i)if(this.remainingLength()<i){if(this.remainingLength()>0){const e=this.remainingLength();t.writeBuffer(this.buffer.subarray(this.pointer,this.pointer+e)),this.pointer+=e,this.pos+=BigInt(e),i-=e}for(;i>0;){this.flush();const e=Math.min(this.endPointer-this.pointer,i);t.writeBuffer(this.buffer.subarray(this.pointer,this.pointer+e)),this.pointer+=e,this.pos+=BigInt(e),i-=e}}else t.writeBuffer(this.buffer.subarray(this.pointer,this.pointer+i)),this.pointer+=i,this.pos+=BigInt(i);else{if(this.remainingLength()>0){const i=this.remainingLength();t.writeBuffer(this.buffer.subarray(this.pointer,this.pointer+i)),this.pointer+=i,this.pos+=BigInt(i)}for(;this.onFlush(this.buffer.subarray(0))>0;){const i=this.remainingLength();t.writeBuffer(this.buffer.subarray(this.pointer,this.pointer+i)),this.pointer+=i,this.pos+=BigInt(i)}}}}},35336:(t,i,e)=>{e.d(i,{A:()=>n});var s=e(134),r=e(50011);class n{constructor(t=1048576,i=!0,e){if((0,s.A)(this,"data",void 0),(0,s.A)(this,"buffer",void 0),(0,s.A)(this,"pointer",void 0),(0,s.A)(this,"pos",void 0),(0,s.A)(this,"size",void 0),(0,s.A)(this,"littleEndian",void 0),(0,s.A)(this,"error",void 0),(0,s.A)(this,"onFlush",void 0),(0,s.A)(this,"onSeek",void 0),this.pointer=0,this.pos=BigInt(0),this.size=t,this.littleEndian=!i,this.error=0,e&&e.view)this.size=e.length,this.buffer=e,this.data=e.view;else if(e&&!e.byteOffset)this.size=e.length,this.buffer=e,this.data=new DataView(this.buffer.buffer);else{if(e)throw new Error("not support subarray of ArrayBuffer");this.buffer=new Uint8Array(this.size),this.data=new DataView(this.buffer.buffer)}}writeUint8(t){this.remainingLength()<1&&this.flush(),this.data.setUint8(this.pointer,t),this.pointer++,this.pos++}writeUint16(t){this.remainingLength()<2&&this.flush(),this.data.setUint16(this.pointer,t,this.littleEndian),this.pointer+=2,this.pos+=BigInt(2)}writeUint24(t){this.remainingLength()<3&&this.flush();const i=(16711680&t)>>16,e=(65280&t)>>8,s=255&t;this.littleEndian?(this.writeUint8(s),this.writeUint8(e),this.writeUint8(i)):(this.writeUint8(i),this.writeUint8(e),this.writeUint8(s))}writeUint32(t){this.remainingLength()<4&&this.flush(),this.data.setUint32(this.pointer,t,this.littleEndian),this.pointer+=4,this.pos+=BigInt(4)}writeUint64(t){this.remainingLength()<8&&this.flush(),this.data.setBigUint64(this.pointer,t,this.littleEndian),this.pointer+=8,this.pos+=BigInt(8)}writeInt8(t){this.remainingLength()<1&&this.flush(),this.data.setInt8(this.pointer,t),this.pointer++,this.pos++}writeInt16(t){this.remainingLength()<2&&this.flush(),this.data.setInt16(this.pointer,t,this.littleEndian),this.pointer+=2,this.pos+=BigInt(2)}writeInt24(t){this.writeUint24(t<0?t+16777216:t)}writeInt32(t){this.remainingLength()<4&&this.flush(),this.data.setInt32(this.pointer,t,this.littleEndian),this.pointer+=4,this.pos+=BigInt(4)}writeInt64(t){this.remainingLength()<8&&this.flush(),this.data.setBigInt64(this.pointer,t,this.littleEndian),this.pointer+=8,this.pos+=BigInt(8)}writeFloat(t){this.remainingLength()<4&&this.flush(),this.data.setFloat32(this.pointer,t,this.littleEndian),this.pointer+=4,this.pos+=BigInt(4)}writeDouble(t){this.remainingLength()<8&&this.flush(),this.data.setFloat64(this.pointer,t,this.littleEndian),this.pointer+=8,this.pos+=BigInt(8)}getPointer(){return this.pointer}getPos(){return this.pos}remainingLength(){return this.size-this.pointer}writeBuffer(t){if(!t.length)return;let i=t.length;if(this.remainingLength()<i){let e=0;for(;i>0;){this.flush();const s=Math.min(this.size,i);this.buffer.set(t.subarray(e,e+s),this.pointer),this.pointer+=s,this.pos+=BigInt(s),e+=s,i-=s}}else this.buffer.set(t,this.pointer),this.pointer+=i,this.pos+=BigInt(i)}writeString(t){const i=r.encode(t);return this.writeBuffer(i),i.length}flush(){if(!this.onFlush)throw this.error=-1048574,Error("IOWriter error, flush failed because of no flush callback");if(this.pointer){const t=this.onFlush(this.buffer.subarray(0,this.pointer));if(0!==t)throw this.error=t,Error("IOWriter error, flush failed")}this.pointer=0}flushToPos(t){if(!this.onFlush)throw this.error=-1048574,Error("IOWriter error, flush failed because of no flush callback");if(this.pointer){const i=this.onFlush(this.buffer.subarray(0,this.pointer),t);if(0!==i)throw this.error=i,Error("IOWriter error, flush failed")}this.pointer=0}seek(t){if(!this.onSeek)throw this.error=-1048574,Error("IOWriter error, seek failed because of no seek callback");this.flush();const i=this.onSeek(t);if(0!==i)throw this.error=i,Error("IOWriter error, seek failed");this.pos=t}seekInline(t){const i=this.pointer;this.pointer=Math.max(0,Math.min(this.size,t)),this.pos+=BigInt(this.pointer-i)}skip(t){const i=this.pointer;this.pointer=Math.min(this.size,this.pointer+t),this.pos+=BigInt(this.pointer-i)}back(t){const i=this.pointer;this.pointer=Math.max(0,this.pointer-t),this.pos+=BigInt(this.pointer-i)}getBuffer(){return this.buffer.subarray(0,this.pointer)}setEndian(t){this.littleEndian=!t}reset(){this.pointer=0,this.pos=BigInt(0),this.error=0}getBufferSize(){return this.size}}}}]);
1
+ (self.webpackChunklibmedia=self.webpackChunklibmedia||[]).push([[118],{85947:(t,i,e)=>{e.d(i,{A:()=>r});var s=e(134);class r{constructor(){(0,s.A)(this,"type",-1),(0,s.A)(this,"onStreamAdd",void 0)}async destroy(t){}}},29118:(t,i,e)=>{e.r(i),e.d(i,{default:()=>y});var s=e(134),r=e(63939),n=e(50932),a=e(38743),h=e(4624),o=e(54712),d=e(87400),g=e(9705),l=e(92647),p=e(85947),u=e(14686),c=e(37837),f=e(71517),m=e(82348),b=e(35336),w=e(77231),I=e(52071),k=e(44328),S=e(79630),B=e(43607);const v="src/avformat/formats/IOggFormat.ts";class y extends p.A{constructor(){super(),(0,s.A)(this,"type",4),(0,s.A)(this,"headerPagesPayload",void 0),(0,s.A)(this,"page",void 0),(0,s.A)(this,"curSegIndex",void 0),(0,s.A)(this,"curSegStart",void 0),(0,s.A)(this,"segCount",void 0),(0,s.A)(this,"segIndex",void 0),(0,s.A)(this,"currentPts",void 0),(0,s.A)(this,"firstPos",void 0),(0,s.A)(this,"firstGranulePosition",void 0),(0,s.A)(this,"paddingPayload",void 0),this.page=new a.B,this.headerPagesPayload=[]}init(t){t.ioReader&&t.ioReader.setEndian(!1),t.ioReader&&t.ioReader.setEndian(!1),this.curSegIndex=-1,this.curSegStart=0,this.currentPts=BigInt(0),this.segCount=0,this.segIndex=0,this.firstGranulePosition=BigInt(0)}async estimateTotalBlock(t){let i=BigInt(0);const e=t.ioReader.getPos(),s=this.currentPts,r=await t.ioReader.fileSize();for(await t.ioReader.seek(B.T9(r-BigInt(195072),BigInt(0))),await this.syncPage(t);;)try{this.page.reset(),await this.page.read(t.ioReader),i=this.page.granulePosition}catch(t){break}return await t.ioReader.seek(e),this.currentPts=s,i}async getNextSegment(t){if(this.curSegIndex<0){this.page.granulePosition>BigInt(0)&&(this.currentPts=this.page.granulePosition),this.page.reset(),await this.page.read(t.ioReader),this.curSegIndex=0,this.curSegStart=0,this.segIndex=-1,this.segCount=0;for(let t=0;t<this.page.segmentTable.length;t++)255!==this.page.segmentTable[t]&&this.segCount++;this.segCount||(this.segCount=1)}let i=0;for(;this.curSegIndex<this.page.segmentTable.length;){const t=this.page.segmentTable[this.curSegIndex++];if(i+=t,255!==t)break}const e=this.curSegStart;return this.curSegStart+=i,this.segIndex++,this.curSegIndex===this.page.segmentTable.length&&(this.curSegIndex=-1),this.page.payload.subarray(e,e+i)}addComment(t,i){t.vendorString&&(i.metadata.vendor=t.vendorString),(0,d.ol)(t.comments.list,i.metadata)}async createStream(t,i){if(i.length<8)return 0;let e=new m.A(i.length,!1);e.appendBuffer(i);const s=e.peekString(8);if("OpusHead"===s){const s=new o.q;s.read(e);const r=new o.o;i=await this.getNextSegment(t),e=new m.A(i.length,!1),e.appendBuffer(i),r.read(e),this.headerPagesPayload=[s,r];const n=t.createStream();n.codecpar.codecType=1,n.codecpar.codecId=86076,n.codecpar.sampleRate=s.sampleRate,n.codecpar.chLayout.nbChannels=s.channels,n.timeBase.den=n.codecpar.sampleRate,n.timeBase.num=1,n.privData={serialNumber:this.page.serialNumber},this.addComment(r,n),n.duration=await this.estimateTotalBlock(t)}else if("vorbis"===s.slice(1,7)){const s=[i],r=new d.mS;r.read(e);const n=new d.GM;i=await this.getNextSegment(t),e=new m.A(i.length,!1),e.appendBuffer(i),n.read(e),s.push(i),this.headerPagesPayload=[r,n];const a=t.createStream();a.codecpar.codecType=1,a.codecpar.codecId=86021,a.codecpar.sampleRate=r.sampleRate,a.codecpar.chLayout.nbChannels=r.channels,a.timeBase.den=a.codecpar.sampleRate,a.timeBase.num=1,a.privData={serialNumber:this.page.serialNumber},this.addComment(n,a),s.push(await this.getNextSegment(t));const h=s.reduce(((t,i)=>t+2+i.length),0),o=(0,c.sY)(h),g=new b.A(h,!0,new S.A(o,h));s.forEach((t=>{g.writeUint16(t.length),g.writeBuffer(t)})),a.codecpar.extradata=o,a.codecpar.extradataSize=h,a.duration=await this.estimateTotalBlock(t)}else if("FLAC"===s.slice(1,5)){e.setEndian(!0),e.skip(1),e.skip(4),e.skip(1),e.skip(1),e.readUint16(),e.skip(4);const s=e.readUint8(),r=e.readUint24();if(0!==s)return g.LR;{const s=t.createStream();s.codecpar.codecType=1,s.codecpar.codecId=86028;const n=(0,c.sY)(r);e.peekBuffer(r,(0,u.s3)(n,r)),e.skip(10);const h=e.readUint24();s.codecpar.sampleRate=h>>4,s.codecpar.chLayout.nbChannels=1+((15&h)>>>1),s.timeBase.den=s.codecpar.sampleRate,s.timeBase.num=1,s.privData={serialNumber:this.page.serialNumber},s.codecpar.extradata=n,s.codecpar.extradataSize=r;const o=new a.h;i=await this.getNextSegment(t),e=new m.A(i.length-4,!1),e.appendBuffer(i.subarray(4)),o.read(e),s.duration=await this.estimateTotalBlock(t),this.addComment(o,s),this.headerPagesPayload=[o]}}else{if("Speex"!==s.slice(0,5))return 0;{const s=t.createStream();s.codecpar.codecType=1,s.codecpar.codecId=86051;const r=(0,c.sY)(i.length);(0,u.lW)(r,i.length,i),s.codecpar.extradata=r,s.codecpar.extradataSize=i.length,e.seek(BigInt(36)),s.codecpar.sampleRate=e.readUint32(),e.seek(BigInt(48)),s.codecpar.chLayout.nbChannels=e.readUint32(),s.timeBase.den=s.codecpar.sampleRate,s.timeBase.num=1,s.privData={serialNumber:this.page.serialNumber};const n=new a.h;i=await this.getNextSegment(t),e=new m.A(i.length,!1),e.appendBuffer(i),n.read(e),s.duration=await this.estimateTotalBlock(t),this.addComment(n,s),this.headerPagesPayload=[n]}}return 1}async readHeader(t){try{if("OggS"!==await t.ioReader.peekString(4))return h.z3("the file format is not oggs",v,381),g.LR;for(;;){let i=this.paddingPayload||await this.getNextSegment(t);this.paddingPayload&&(this.paddingPayload=null);const e=await this.createStream(t,i);if(e<0)return e;if(!e){this.paddingPayload=i;break}}return this.firstPos=this.paddingPayload?this.page.pos:t.ioReader.getPos(),0}catch(i){return h.z3(i.message,v,403),t.ioReader.error}}async readAVPacket(t,i){n.M[17](i+56,t.ioReader.getPos());try{const e=this.paddingPayload||await this.getNextSegment(t);this.paddingPayload&&(this.paddingPayload=null);let s=this.currentPts+(this.page.granulePosition-this.currentPts)/BigInt(Math.floor(this.segCount))*BigInt(Math.floor(this.segIndex));n.M[17](i+16,s),n.M[17](i+8,s),this.firstGranulePosition||(this.firstGranulePosition=this.page.granulePosition);const a=t.streams.find((t=>t.privData&&t.privData.serialNumber===this.page.serialNumber));if(!a)return await this.createStream(t,e),this.readAVPacket(t,i);n.M[15](i+32,a.index),n.M[15](i+76,a.timeBase.den),n.M[15](i+72,a.timeBase.num),1===a.codecpar.codecType&&n.M[15](i+36,1|r.f[15](i+36));const h=[e];for(;this.curSegIndex<0;)try{if(!(1&(await t.ioReader.peekBuffer(6))[5]))break;h.push(await this.getNextSegment(t))}catch(t){break}const o=(0,l.A)(Uint8Array,h),d=o.length,g=(0,c.sY)(d);return(0,u.lW)(g,d,o),(0,f.NX)(i,g,d),0}catch(i){return-1048576!==t.ioReader.error?(h.z3(`read packet error, ${i}`,v,472),g.LR):t.ioReader.error}}async syncPage(t){let i=w.Dh,e=BigInt(0);for(;;)try{if("OggS"===await t.ioReader.peekString(4)){i=t.ioReader.getPos(),this.page.reset(),await this.page.read(t.ioReader),e=this.page.granulePosition;let s=0;for(;3!==s&&"OggS"===await t.ioReader.peekString(4);)s++,this.page.reset(),await this.page.read(t.ioReader);if(3===s)break}await t.ioReader.skip(1)}catch(t){break}if(i!==w.Dh){for(await t.ioReader.seek(i);1&(await t.ioReader.peekBuffer(6))[5];)this.page.reset(),await this.page.read(t.ioReader),e=this.page.granulePosition;this.currentPts=e-this.firstGranulePosition,this.curSegIndex=-1}}async seek(t,i,e,s){const r=t.ioReader.getPos();if(2&s){const i=await t.ioReader.fileSize();return i<=BigInt(0)?BigInt(g.E$):(e<BigInt(0)?e=BigInt(0):e>i&&(e=i),await t.ioReader.seek(e),4&s||await this.syncPage(t),r)}return(0,k.k)(e,i.timeBase,w.i0)<BigInt(1e4)?(h.Yz(`seek pts is earlier then 10s, seek to first packet pos(${this.firstPos}) directly`,v,564),await t.ioReader.seek(this.firstPos),this.currentPts=BigInt(0),r):(0,I.A)(t,i,e,this.firstPos,this.readAVPacket.bind(this),this.syncPage.bind(this))}getAnalyzeStreamsCount(){return 1}}},38743:(t,i,e)=>{e.d(i,{B:()=>h,h:()=>o});var s=e(134),r=e(77231),n=e(50011);class a{constructor(){(0,s.A)(this,"list",void 0),this.list=[]}read(t,i){for(let e=0;e<i;e++){const i=t.readUint32();this.list.push(t.readString(i))}}write(t){for(let i=0;i<this.list.length;i++){const e=n.encode(this.list[i]);t.writeUint32(e.length),t.writeBuffer(e)}}addComment(t){this.list.push(t)}}class h{constructor(){(0,s.A)(this,"capturePattern",void 0),(0,s.A)(this,"streamStructureVersion",void 0),(0,s.A)(this,"headerTypeFlag",void 0),(0,s.A)(this,"granulePosition",void 0),(0,s.A)(this,"serialNumber",void 0),(0,s.A)(this,"pageSequenceNumber",void 0),(0,s.A)(this,"crcCheckSum",void 0),(0,s.A)(this,"numberPageSegments",void 0),(0,s.A)(this,"segmentTable",void 0),(0,s.A)(this,"payload",void 0),(0,s.A)(this,"pos",void 0),this.reset()}reset(){this.capturePattern="OggS",this.streamStructureVersion=0,this.headerTypeFlag=0,this.granulePosition=r.Dh,this.serialNumber=0,this.pageSequenceNumber=0,this.crcCheckSum=0,this.numberPageSegments=0,this.segmentTable=[],this.pos=BigInt(0)}async read(t){this.pos=t.getPos(),await this.readPageHeader(t);const i=this.segmentTable.reduce(((t,i)=>t+i),0);i&&(this.payload=await t.readBuffer(i))}async readPageHeader(t){if(this.capturePattern=await t.readString(4),this.streamStructureVersion=await t.readUint8(),this.headerTypeFlag=await t.readUint8(),this.granulePosition=await t.readUint64(),this.serialNumber=await t.readUint32(),this.pageSequenceNumber=await t.readUint32(),this.crcCheckSum=await t.readUint32(),this.numberPageSegments=await t.readUint8(),this.numberPageSegments)for(let i=0;i<this.numberPageSegments;i++){const i=await t.readUint8();this.segmentTable.push(i)}}write(t){if(this.pos=t.getPos(),t.writeString(this.capturePattern),t.writeUint8(this.streamStructureVersion),t.writeUint8(this.headerTypeFlag),t.writeUint64(this.granulePosition),t.writeUint32(this.serialNumber),t.writeUint32(this.pageSequenceNumber),t.writeUint32(this.crcCheckSum),this.payload){this.numberPageSegments=Math.floor(this.payload.length/255)+1;const i=this.payload.length%255;t.writeUint8(this.numberPageSegments);for(let i=0;i<this.numberPageSegments-1;i++)t.writeUint8(255);t.writeUint8(i),t.writeBuffer(this.payload)}else t.writeUint8(0)}}class o{constructor(){(0,s.A)(this,"streamIndex",void 0),(0,s.A)(this,"signature",void 0),(0,s.A)(this,"vendorStringLength",void 0),(0,s.A)(this,"vendorString",void 0),(0,s.A)(this,"userCommentListLength",void 0),(0,s.A)(this,"comments",void 0),this.vendorString="v0.6.1",this.vendorStringLength=this.vendorString.length,this.userCommentListLength=0,this.comments=new a}read(t){this.vendorStringLength=t.readUint32(),this.vendorString=t.readString(this.vendorStringLength),this.userCommentListLength=t.readUint32(),this.userCommentListLength&&this.comments.read(t,this.userCommentListLength)}write(t){const i=n.encode(this.vendorString);t.writeUint32(i.length),t.writeBuffer(i),t.writeUint32(this.comments.list.length),this.comments.write(t)}addComment(t){this.comments.addComment(t)}setCodec(t){}}},54712:(t,i,e)=>{e.d(i,{o:()=>h,q:()=>a});var s=e(134),r=e(38743);class n{constructor(){(0,s.A)(this,"streamCount",void 0),(0,s.A)(this,"coupledStreamCount",void 0),(0,s.A)(this,"mapping",void 0),this.streamCount=1,this.coupledStreamCount=0,this.mapping=new Uint8Array(1)}read(t){this.streamCount=t.readUint8(),this.coupledStreamCount=t.readUint8(),this.mapping=t.readBuffer(this.streamCount+this.coupledStreamCount)}write(t){t.writeUint8(this.streamCount),t.writeUint8(this.coupledStreamCount),t.writeBuffer(this.mapping)}}class a{constructor(){(0,s.A)(this,"streamIndex",void 0),(0,s.A)(this,"signature",void 0),(0,s.A)(this,"version",void 0),(0,s.A)(this,"channels",void 0),(0,s.A)(this,"preSkip",void 0),(0,s.A)(this,"sampleRate",void 0),(0,s.A)(this,"outputGain",void 0),(0,s.A)(this,"channelMappingFamily",void 0),(0,s.A)(this,"channelMappingTable",void 0),this.signature="OpusHead",this.version=1,this.channels=1,this.preSkip=0,this.sampleRate=48e3,this.outputGain=0,this.channelMappingFamily=0,this.channelMappingTable=new n}read(t){this.signature=t.readString(8),this.version=t.readUint8(),this.channels=t.readUint8(),this.preSkip=t.readUint16(),this.sampleRate=t.readUint32(),this.outputGain=t.readInt16(),this.channelMappingFamily=t.readUint8(),0!==this.channelMappingFamily&&this.channelMappingTable.read(t)}write(t){t.writeString(this.signature),t.writeUint8(this.version),t.writeUint8(this.channels),t.writeUint16(this.preSkip),t.writeUint32(this.sampleRate),t.writeInt16(this.outputGain),t.writeUint8(this.channelMappingFamily),0!==this.channelMappingFamily&&this.channelMappingTable.write(t)}setCodec(t){this.sampleRate=t.sampleRate,this.channels=t.chLayout.nbChannels,this.channelMappingFamily=t.format}}class h extends r.h{constructor(){super(),this.signature="OpusTags"}read(t){this.signature=t.readString(8),super.read(t)}write(t){t.writeString(this.signature),super.write(t)}addComment(t){this.comments.addComment(t)}setCodec(t){}}},87400:(t,i,e)=>{e.d(i,{GM:()=>o,mS:()=>h,ol:()=>a});var s=e(134),r=e(38743);e(95335),e(34677);const n={album:"album",artist:"artist",description:"description",encoder:"encoder",title:"title",tracknumber:"track",date:"date",genre:"genre",comment:"comment",albumartist:"albumArtist",composer:"composer",performer:"performer",discnumber:"disc",organization:"vendor",copyright:"copyright",license:"license",isrc:"isrc",lyrics:"lyrics",language:"language",label:"vendor",script:"lyrics",encoded_by:"vendor"};function a(t,i){t&&t.forEach((t=>{const e=t.split("=");if(2===e.length){const t=e[0].trim().toLowerCase(),s=e[1].trim();n[t]?i[n[t]]=s:i[t.toLowerCase()]=s}}))}class h{constructor(t="vorbis"){(0,s.A)(this,"streamIndex",void 0),(0,s.A)(this,"packetType",void 0),(0,s.A)(this,"signature",void 0),(0,s.A)(this,"version",void 0),(0,s.A)(this,"channels",void 0),(0,s.A)(this,"sampleRate",void 0),(0,s.A)(this,"bitrateMaximum",void 0),(0,s.A)(this,"bitrateNominal",void 0),(0,s.A)(this,"bitrateMinimum",void 0),(0,s.A)(this,"blocksize0",void 0),(0,s.A)(this,"blocksize1",void 0),(0,s.A)(this,"framingFlag",void 0),this.signature=t,this.version=0,this.channels=1,this.sampleRate=48e3,this.bitrateMaximum=0,this.bitrateNominal=0,this.bitrateMinimum=0,this.blocksize0=2048,this.blocksize1=256}read(t){this.packetType=t.readUint8(),this.signature=t.readString(6),this.version=t.readUint32(),this.channels=t.readUint8(),this.sampleRate=t.readInt32(),this.bitrateMaximum=t.readInt32(),this.bitrateNominal=t.readInt32(),this.bitrateMinimum=t.readInt32();const i=255&t.readUint8();this.blocksize0=Math.pow(2,i>>>4),this.blocksize1=Math.pow(2,15&i),this.framingFlag=t.readUint8()}write(t){t.writeUint8(1),t.writeString(this.signature),t.writeUint32(this.version),t.writeUint8(this.channels),t.writeInt32(this.sampleRate),t.writeInt32(this.bitrateMaximum),t.writeInt32(this.bitrateNominal),t.writeInt32(this.bitrateMinimum),t.writeUint8(Math.log2(this.blocksize0)<<4|Math.log2(this.blocksize1)),t.writeUint8(1)}setCodec(t){this.sampleRate=t.sampleRate,this.channels=t.chLayout.nbChannels}}class o extends r.h{constructor(t="vorbis"){super(),(0,s.A)(this,"packetType",void 0),(0,s.A)(this,"framingFlag",void 0),this.signature=t,this.packetType=1,this.framingFlag=1}read(t){this.packetType=t.readUint8(),this.signature=t.readString(6),super.read(t),"vorbis"===this.signature&&(this.framingFlag=t.readUint8())}write(t){t.writeUint8(this.packetType),t.writeString(this.signature),super.write(t),"vorbis"===this.signature&&t.writeUint8(this.framingFlag)}addComment(t){this.comments.addComment(t)}setCodec(t){}}},2187:(t,i,e)=>{e.d(i,{d:()=>a});var s=e(72739),r=e(44328),n=e(77231);function a(t,i,e){let a=BigInt(0);return s.__(t,(t=>{a+=t.codecpar.bitrate*(0,r.k)(i,e,n.i0)/BigInt(8e3)})),a}},52071:(t,i,e)=>{e.d(i,{A:()=>l});var s=e(63939),r=(e(9599),e(77231)),n=e(44328),a=e(2187),h=e(71517),o=e(9705),d=e(4624);const g="src/avformat/function/seekInBytes.ts";async function l(t,i,e,l,p,u){const c=t.ioReader.getPos(),f=await t.ioReader.fileSize();let m=r.Dh,b=e;i.startTime!==r.Dh?b-=i.startTime:b-=i.firstDTS;const w=(0,n.k)(e,i.timeBase,r.i0);if(w<BigInt(1e4))return d.Yz(`seek pts is earlier then 10s, seek to first packet pos(${l}) directly`,g,62),await t.ioReader.seek(l),c;let I=(0,a.d)(t.streams,b,i.timeBase);const k=f-(0,a.d)(t.streams,BigInt(1e4),r.i0),S=(0,a.d)(t.streams,BigInt(1e4),r.i0);if(I>k&&(I=k),I<l)return await t.ioReader.seek(l),c;const B=(0,h._5)();let v=f,y=BigInt(0);for(;;){if(v-y<S){m=y;break}if(await t.ioReader.seek(I),await u(t),8&t.ioReader.flags)break;const i=t.ioReader.getPos();if(!(await p(t,B)>=0)){m=r.Dh;break}{const t=(0,n.Mr)(s.f[17](B+8),B+72,r.i0),e=t-w;if(d.Yz(`try to seek to pos: ${I}, got packet pts: ${s.f[17](B+8)}(${t}ms), diff: ${e}ms`,g,100),e<=BigInt(0)&&-e<BigInt(1e4)){m=i;break}e>BigInt(0)?(v=I,I=y+v>>BigInt(1)):(y=I,I=y+v>>BigInt(1))}if(8&t.ioReader.flags)break}return(0,h.Qe)(B),m!==r.Dh?(d.Yz(`finally seek to pos ${m}`,g,131),await t.ioReader.seek(m),await u(t),c):(await t.ioReader.seek(c),8&t.ioReader.flags?BigInt(o.LT):BigInt(o.E$))}},82348:(t,i,e)=>{e.d(i,{A:()=>h});var s=e(134),r=e(4624),n=e(50011);const a="src/common/io/IOReaderSync.ts";class h{constructor(t=1048576,i=!0,e){if((0,s.A)(this,"data",void 0),(0,s.A)(this,"buffer",void 0),(0,s.A)(this,"pointer",void 0),(0,s.A)(this,"endPointer",void 0),(0,s.A)(this,"pos",void 0),(0,s.A)(this,"size",void 0),(0,s.A)(this,"littleEndian",void 0),(0,s.A)(this,"fileSize_",void 0),(0,s.A)(this,"error",void 0),(0,s.A)(this,"onFlush",void 0),(0,s.A)(this,"onSeek",void 0),(0,s.A)(this,"onSize",void 0),(0,s.A)(this,"flags",void 0),this.pos=BigInt(0),this.pointer=0,this.error=0,this.endPointer=0,this.littleEndian=!i,this.flags=0,e&&e.view)this.size=e.length,this.buffer=e,this.data=e.view;else if(e&&!e.byteOffset)this.size=e.length,this.buffer=e,this.data=new DataView(this.buffer.buffer);else{if(e)throw new Error("not support subarray of ArrayBuffer");this.size=Math.max(t,102400),this.buffer=new Uint8Array(this.size),this.data=new DataView(this.buffer.buffer)}}readUint8(){this.remainingLength()<1&&this.flush(1);const t=this.data.getUint8(this.pointer);return this.pointer++,this.pos++,t}peekUint8(){return this.remainingLength()<1&&this.flush(1),this.data.getUint8(this.pointer)}readUint16(){this.remainingLength()<2&&this.flush(2);const t=this.data.getUint16(this.pointer,this.littleEndian);return this.pointer+=2,this.pos+=BigInt(2),t}peekUint16(){return this.remainingLength()<2&&this.flush(2),this.data.getUint16(this.pointer,this.littleEndian)}readUint24(){this.remainingLength()<3&&this.flush(3);const t=this.readUint16(),i=this.readUint8();return this.littleEndian?i<<16|t:t<<8|i}peekUint24(){this.remainingLength()<3&&this.flush(3);const t=this.pointer,i=this.pos,e=this.readUint16(),s=this.readUint8(),r=this.littleEndian?s<<16|e:e<<8|s;return this.pointer=t,this.pos=i,r}readUint32(){this.remainingLength()<4&&this.flush(4);const t=this.data.getUint32(this.pointer,this.littleEndian);return this.pointer+=4,this.pos+=BigInt(4),t}peekUint32(){return this.remainingLength()<4&&this.flush(4),this.data.getUint32(this.pointer,this.littleEndian)}readUint64(){this.remainingLength()<8&&this.flush(8);const t=this.data.getBigUint64(this.pointer,this.littleEndian);return this.pointer+=8,this.pos+=BigInt(8),t}peekUint64(){return this.remainingLength()<8&&this.flush(8),this.data.getBigUint64(this.pointer,this.littleEndian)}readInt8(){this.remainingLength()<1&&this.flush(1);const t=this.data.getInt8(this.pointer);return this.pointer++,this.pos++,t}peekInt8(){return this.remainingLength()<1&&this.flush(1),this.data.getInt8(this.pointer)}readInt16(){this.remainingLength()<2&&this.flush(2);const t=this.data.getInt16(this.pointer,this.littleEndian);return this.pointer+=2,this.pos+=BigInt(2),t}peekInt16(){return this.remainingLength()<2&&this.flush(2),this.data.getInt16(this.pointer,this.littleEndian)}readInt24(){const t=this.readUint24();return 8388608&t?t-16777216:t}peekInt24(){const t=this.peekUint24();return 8388608&t?t-16777216:t}readInt32(){this.remainingLength()<4&&this.flush(4);const t=this.data.getInt32(this.pointer,this.littleEndian);return this.pointer+=4,this.pos+=BigInt(4),t}peekInt32(){return this.remainingLength()<4&&this.flush(4),this.data.getInt32(this.pointer,this.littleEndian)}readInt64(){this.remainingLength()<8&&this.flush(8);const t=this.data.getBigInt64(this.pointer,this.littleEndian);return this.pointer+=8,this.pos+=BigInt(8),t}peekInt64(){return this.remainingLength()<8&&this.flush(8),this.data.getBigInt64(this.pointer,this.littleEndian)}readFloat(){this.remainingLength()<4&&this.flush(4);const t=this.data.getFloat32(this.pointer,this.littleEndian);return this.pointer+=4,this.pos+=BigInt(4),t}peekFloat(){return this.remainingLength()<4&&this.flush(4),this.data.getFloat32(this.pointer,this.littleEndian)}readDouble(){this.remainingLength()<8&&this.flush(8);const t=this.data.getFloat64(this.pointer,this.littleEndian);return this.pointer+=8,this.pos+=BigInt(8),t}peekDouble(){return this.remainingLength()<8&&this.flush(8),this.data.getFloat64(this.pointer,this.littleEndian)}readHex(t=1){let i="";for(let e=0;e<t;e++){const t=this.readUint8().toString(16);i+=1===t.length?"0"+t:t}return i}peekHex(t=1){t>this.size&&(this.error=-1048574,r.h2("peekHex, length too large",a,412)),this.remainingLength()<t&&this.flush(t);const i=this.pointer,e=this.pos;let s="";for(let i=0;i<t;i++){const t=this.readUint8().toString(16);s+=1===t.length?"0"+t:t}return this.pointer=i,this.pos=e,s}readBuffer(t,i){if(!t)return new Uint8Array(0);if(i||(i=new Uint8Array(t)),this.remainingLength()<t){let e=0;if(this.remainingLength()>0){const s=this.remainingLength();i.set(this.buffer.subarray(this.pointer,this.pointer+s),e),e+=s,this.pointer+=s,this.pos+=BigInt(s),t-=s}for(;t>0;){this.flush();const s=Math.min(this.endPointer-this.pointer,t);i.set(this.buffer.subarray(this.pointer,this.pointer+s),e),e+=s,this.pointer+=s,this.pos+=BigInt(s),t-=s}}else i.set(this.buffer.subarray(this.pointer,this.pointer+t),0),this.pointer+=t,this.pos+=BigInt(t);return i}peekBuffer(t,i){return t?(t>this.size&&(this.error=-1048574,r.h2("peekBuffer, length too large",a,505)),this.remainingLength()<t&&this.flush(t),i||(i=new Uint8Array(t)),i.set(this.buffer.subarray(this.pointer,this.pointer+t),0),i):new Uint8Array(0)}readToBuffer(t,i){if(this.remainingLength()<t){let e=0;if(this.remainingLength()>0){const s=this.remainingLength();i.set(this.buffer.subarray(this.pointer,this.pointer+s),e),e+=s,this.pointer+=s,this.pos+=BigInt(s),t-=s}for(;t>0;){try{this.flush()}catch(t){if(-1048576===this.error&&e)return e;throw t}const s=Math.min(this.endPointer-this.pointer,t);i.set(this.buffer.subarray(this.pointer,this.pointer+s),e),e+=s,this.pointer+=s,this.pos+=BigInt(s),t-=s}return e}return i.set(this.buffer.subarray(this.pointer,this.pointer+t),0),this.pointer+=t,this.pos+=BigInt(t),t}readString(t=1){const i=this.readBuffer(t);return n.decode(i)}peekString(t=1){const i=this.peekBuffer(t);return n.decode(i)}readLine(){let t="";for(;;){let i=!1;for(let e=this.pointer;e<this.endPointer;e++)if(10===this.buffer[e]||13===this.buffer[e]){e!==this.pointer&&(t+=this.readString(e-this.pointer)),i=!0;break}if(i)break;t+=this.readString(this.remainingLength()),this.flush()}let i=this.peekUint8();return 10!==i&&13!==i||(this.pointer++,13===i&&(i=this.peekUint8(),10===i&&this.pointer++)),t}peekLine(){this.remainingLength()<this.size&&this.flush();let t="",i=!1;for(let e=this.pointer;e<this.endPointer;e++)if(10===this.buffer[e]||13===this.buffer[e]){t+=this.peekString(e-this.pointer),i=!0;break}return i||(this.error=-1048574,r.h2("peekLine, out of buffer",a,656)),t}getPointer(){return this.pointer}getPos(){return this.pos}skip(t){const i=t;for(;this.remainingLength()<t;)t-=this.remainingLength(),this.pointer=this.endPointer,this.flush();this.remainingLength()>=t&&(this.pointer+=t),this.pos+=BigInt(i)}remainingLength(){return this.endPointer-this.pointer}flush(t=0){if(this.onFlush||(this.error=-1048574,r.h2("IOReader error, flush failed because of no flush callback",a,720)),!(this.size-this.remainingLength()<=0)){if(t=Math.min(t,this.size),this.pointer<this.endPointer?(this.buffer.set(this.buffer.subarray(this.pointer,this.endPointer),0),this.endPointer=this.endPointer-this.pointer):this.endPointer=0,this.pointer=0,t)for(;this.remainingLength()<t;){const t=this.onFlush(this.buffer.subarray(this.endPointer));if(t<0)throw this.error=t,new Error(`IOReader error, flush ${-1048576===t?"ended":"failed"}, ret: ${t}`);this.endPointer+=t}else{const t=this.onFlush(this.buffer.subarray(this.endPointer));if(t<0)throw this.error=t,new Error(`IOReader error, flush ${-1048576===t?"ended":"failed"}, ret: ${t}`);this.endPointer+=t}this.error=0}}seek(t,i=!1,e=!0){if(!i){const i=Number(t-this.pos);if(i<0&&Math.abs(i)<this.pointer)return this.pointer+=i,void(this.pos=t);if(i>0&&this.pointer+i<this.endPointer)return this.pointer+=i,void(this.pos=t);if(0===i)return}this.onSeek||(this.error=-1048574,r.h2("IOReader error, seek failed because of no seek callback",a,790)),this.pointer=this.endPointer=0,this.pos=t;const s=this.onSeek(t);0!==s&&(this.error=s,r.h2("IOReader error, seek failed",a,799)),e&&this.flush()}getBuffer(){return this.buffer}appendBuffer(t){if(this.size-this.endPointer>=t.length)this.buffer.set(t,this.endPointer),this.endPointer+=t.length;else if(this.buffer.set(this.buffer.subarray(this.pointer,this.endPointer),0),this.endPointer=this.endPointer-this.pointer,this.pointer=0,this.size-this.endPointer>=t.length)this.buffer.set(t,this.endPointer),this.endPointer+=t.length;else{const i=Math.min(this.size-this.endPointer,t.length);this.buffer.set(t.subarray(0,i),this.endPointer),this.endPointer+=i,r.R8("IOReader, call appendBuffer but the buffer's size is lagger then the remaining size",a,838)}}reset(){this.pointer=this.endPointer=0,this.pos=BigInt(0),this.error=0}setEndian(t){this.littleEndian=!t}fileSize(){if(this.fileSize_)return this.fileSize_;if(!this.onSize)return r.R8("IOReader error, fileSize failed because of no onSize callback",a,871),BigInt(0);try{this.fileSize_=this.onSize()}catch(t){r.R8(`IOReader error, call fileSize failed: ${t}`,a,878),this.fileSize_=BigInt(0)}return this.fileSize_}getBufferSize(){return this.size}pipe(t,i){if(i)if(this.remainingLength()<i){if(this.remainingLength()>0){const e=this.remainingLength();t.writeBuffer(this.buffer.subarray(this.pointer,this.pointer+e)),this.pointer+=e,this.pos+=BigInt(e),i-=e}for(;i>0;){this.flush();const e=Math.min(this.endPointer-this.pointer,i);t.writeBuffer(this.buffer.subarray(this.pointer,this.pointer+e)),this.pointer+=e,this.pos+=BigInt(e),i-=e}}else t.writeBuffer(this.buffer.subarray(this.pointer,this.pointer+i)),this.pointer+=i,this.pos+=BigInt(i);else{if(this.remainingLength()>0){const i=this.remainingLength();t.writeBuffer(this.buffer.subarray(this.pointer,this.pointer+i)),this.pointer+=i,this.pos+=BigInt(i)}for(;this.onFlush(this.buffer.subarray(0))>0;){const i=this.remainingLength();t.writeBuffer(this.buffer.subarray(this.pointer,this.pointer+i)),this.pointer+=i,this.pos+=BigInt(i)}}}}},35336:(t,i,e)=>{e.d(i,{A:()=>n});var s=e(134),r=e(50011);class n{constructor(t=1048576,i=!0,e){if((0,s.A)(this,"data",void 0),(0,s.A)(this,"buffer",void 0),(0,s.A)(this,"pointer",void 0),(0,s.A)(this,"pos",void 0),(0,s.A)(this,"size",void 0),(0,s.A)(this,"littleEndian",void 0),(0,s.A)(this,"error",void 0),(0,s.A)(this,"onFlush",void 0),(0,s.A)(this,"onSeek",void 0),this.pointer=0,this.pos=BigInt(0),this.size=t,this.littleEndian=!i,this.error=0,e&&e.view)this.size=e.length,this.buffer=e,this.data=e.view;else if(e&&!e.byteOffset)this.size=e.length,this.buffer=e,this.data=new DataView(this.buffer.buffer);else{if(e)throw new Error("not support subarray of ArrayBuffer");this.buffer=new Uint8Array(this.size),this.data=new DataView(this.buffer.buffer)}}writeUint8(t){this.remainingLength()<1&&this.flush(),this.data.setUint8(this.pointer,t),this.pointer++,this.pos++}writeUint16(t){this.remainingLength()<2&&this.flush(),this.data.setUint16(this.pointer,t,this.littleEndian),this.pointer+=2,this.pos+=BigInt(2)}writeUint24(t){this.remainingLength()<3&&this.flush();const i=(16711680&t)>>16,e=(65280&t)>>8,s=255&t;this.littleEndian?(this.writeUint8(s),this.writeUint8(e),this.writeUint8(i)):(this.writeUint8(i),this.writeUint8(e),this.writeUint8(s))}writeUint32(t){this.remainingLength()<4&&this.flush(),this.data.setUint32(this.pointer,t,this.littleEndian),this.pointer+=4,this.pos+=BigInt(4)}writeUint64(t){this.remainingLength()<8&&this.flush(),this.data.setBigUint64(this.pointer,t,this.littleEndian),this.pointer+=8,this.pos+=BigInt(8)}writeInt8(t){this.remainingLength()<1&&this.flush(),this.data.setInt8(this.pointer,t),this.pointer++,this.pos++}writeInt16(t){this.remainingLength()<2&&this.flush(),this.data.setInt16(this.pointer,t,this.littleEndian),this.pointer+=2,this.pos+=BigInt(2)}writeInt24(t){this.writeUint24(t<0?t+16777216:t)}writeInt32(t){this.remainingLength()<4&&this.flush(),this.data.setInt32(this.pointer,t,this.littleEndian),this.pointer+=4,this.pos+=BigInt(4)}writeInt64(t){this.remainingLength()<8&&this.flush(),this.data.setBigInt64(this.pointer,t,this.littleEndian),this.pointer+=8,this.pos+=BigInt(8)}writeFloat(t){this.remainingLength()<4&&this.flush(),this.data.setFloat32(this.pointer,t,this.littleEndian),this.pointer+=4,this.pos+=BigInt(4)}writeDouble(t){this.remainingLength()<8&&this.flush(),this.data.setFloat64(this.pointer,t,this.littleEndian),this.pointer+=8,this.pos+=BigInt(8)}getPointer(){return this.pointer}getPos(){return this.pos}remainingLength(){return this.size-this.pointer}writeBuffer(t){if(!t.length)return;let i=t.length;if(this.remainingLength()<i){let e=0;for(;i>0;){this.flush();const s=Math.min(this.size,i);this.buffer.set(t.subarray(e,e+s),this.pointer),this.pointer+=s,this.pos+=BigInt(s),e+=s,i-=s}}else this.buffer.set(t,this.pointer),this.pointer+=i,this.pos+=BigInt(i)}writeString(t){const i=r.encode(t);return this.writeBuffer(i),i.length}flush(){if(!this.onFlush)throw this.error=-1048574,Error("IOWriter error, flush failed because of no flush callback");if(this.pointer){const t=this.onFlush(this.buffer.subarray(0,this.pointer));if(0!==t)throw this.error=t,Error("IOWriter error, flush failed")}this.pointer=0}flushToPos(t){if(!this.onFlush)throw this.error=-1048574,Error("IOWriter error, flush failed because of no flush callback");if(this.pointer){const i=this.onFlush(this.buffer.subarray(0,this.pointer),t);if(0!==i)throw this.error=i,Error("IOWriter error, flush failed")}this.pointer=0}seek(t){if(!this.onSeek)throw this.error=-1048574,Error("IOWriter error, seek failed because of no seek callback");this.flush();const i=this.onSeek(t);if(0!==i)throw this.error=i,Error("IOWriter error, seek failed");this.pos=t}seekInline(t){const i=this.pointer;this.pointer=Math.max(0,Math.min(this.size,t)),this.pos+=BigInt(this.pointer-i)}skip(t){const i=this.pointer;this.pointer=Math.min(this.size,this.pointer+t),this.pos+=BigInt(this.pointer-i)}back(t){const i=this.pointer;this.pointer=Math.max(0,this.pointer-t),this.pos+=BigInt(this.pointer-i)}getBuffer(){return this.buffer.subarray(0,this.pointer)}setEndian(t){this.littleEndian=!t}reset(){this.pointer=0,this.pos=BigInt(0),this.error=0}getBufferSize(){return this.size}}}}]);
@@ -1 +1 @@
1
- (self.webpackChunklibmedia=self.webpackChunklibmedia||[]).push([[217],{50848:(e,t,a)=>{a.d(t,{A:()=>I});var i=a(134),s=a(63939),r=a(50932),n=a(77162),o=a(29170),c=a(64436),h=a(14686),d=a(4624),l=a(9705),f=a(77231),p=a(95832),u=a(44328),g=a(37837),m=a(71517),A=a(67672);class I extends c.A{constructor(...e){super(...e),(0,i.A)(this,"streamMuxConfig",void 0),(0,i.A)(this,"caches",void 0)}init(e,t){return super.init(e,t),this.caches=[],this.streamMuxConfig={profile:f.N_,sampleRate:f.N_,channels:f.N_},0}sendAVPacket(e){let t=0,a=s.f[17](e+16)!==f.Dh?s.f[17](e+16):s.f[17](e+8);const i=(0,h.s3)(s.f[20](e+24),s.f[15](e+28)).slice();for(;t<i.length;){const e=p.Bq(i.subarray(t));if(A.ai(e))return d.z3("AACADTSParser parse failed","src/avformat/bsf/aac/ADTS2RawFilter.ts",81),l.LR;const c={dts:a,buffer:null,extradata:null,duration:f.N_};c.buffer=i.subarray(t+e.headerLength,t+e.headerLength+e.framePayloadLength),this.streamMuxConfig.profile=e.profile,this.streamMuxConfig.sampleRate=e.sampleRate,this.streamMuxConfig.channels=e.channels;const m=s.f[15](this.inCodecpar+48)!==this.streamMuxConfig.profile||s.f[15](this.inCodecpar+136)!==this.streamMuxConfig.sampleRate||s.f[15](this.inCodecpar+116)!==this.streamMuxConfig.channels,I=(0,u.k)(BigInt(Math.floor(1024*(e.numberOfRawDataBlocksInFrame+1)/this.streamMuxConfig.sampleRate*f.SF)),f.KR,this.inTimeBase);if(c.duration=Number(I),m){r.M[15](this.inCodecpar+48,this.streamMuxConfig.profile),r.M[15](this.inCodecpar+136,this.streamMuxConfig.sampleRate),r.M[15](this.inCodecpar+116,this.streamMuxConfig.channels);const e=(0,p.Ij)((0,o.A)(this.inCodecpar,n.A));s.f[20](this.inCodecpar+12)&&(0,g.Eb)(s.f[20](this.inCodecpar+12)),r.M[20](this.inCodecpar+12,(0,g.sY)(e.length)),(0,h.lW)(s.f[20](this.inCodecpar+12),e.length,e),r.M[15](this.inCodecpar+16,e.length),c.extradata=e}this.caches.push(c),t+=e.aacFrameLength,a+=I}return 0}receiveAVPacket(e){if(this.caches.length){(0,m.Up)(e);const t=this.caches.shift(),a=(0,g.sY)(t.buffer.length);if((0,h.lW)(a,t.buffer.length,t.buffer),(0,m.NX)(e,a,t.buffer.length),r.M[17](e+16,t.dts),r.M[17](e+8,t.dts),r.M[17](e+48,BigInt(Math.floor(t.duration))),r.M[15](e+36,1|s.f[15](e+36)),t.extradata){const a=(0,g.sY)(t.extradata.length);(0,h.lW)(a,t.extradata.length,t.extradata),(0,m.Ow)(e,1,a,t.extradata.length)}return 0}return l.LT}reset(){return 0}}},85947:(e,t,a)=>{a.d(t,{A:()=>s});var i=a(134);class s{constructor(){(0,i.A)(this,"type",-1),(0,i.A)(this,"onStreamAdd",void 0)}async destroy(e){}}},51660:(e,t,a)=>{a.d(t,{A:()=>o});var i=a(77231),s=a(4624),r=a(9705);const n="src/avformat/formats/mpegts/function/parsePES.ts";function o(e){const t=e.data,a=t[3],o=t[4]<<8|t[5];let c=0,h=0,d=0;if(188!==a&&190!==a&&191!==a&&240!==a&&241!==a&&255!==a&&242!==a&&248!==a){let a=i.Dh,l=i.Dh;for(;;){if(6+h>=t.length)return;if(d=t[6+h],255!==d)break;h++}if(64==(192&d)&&(h+=2,d=t[6+h]),32==(224&d))c+=5,a=a=BigInt(Math.floor(536870912*(14&t[6+h])+4194304*(255&t[7+h])+16384*(254&t[8+h])+128*(255&t[9+h])+(254&t[10+h])/2)),16&d?(l=BigInt(Math.floor(536870912*(14&t[11+h])+4194304*(255&t[12+h])+16384*(254&t[13+h])+128*(255&t[14+h])+(254&t[15+h])/2)),c+=5):l=a;else if(128==(192&d)){const e=(192&t[7+h])>>>6;c=3+t[8+h],2!==e&&3!==e||(a=BigInt(Math.floor(536870912*(14&t[9+h])+4194304*(255&t[10+h])+16384*(254&t[11+h])+128*(255&t[12+h])+(254&t[13+h])/2)),l=3===e?BigInt(Math.floor(536870912*(14&t[14+h])+4194304*(255&t[15+h])+16384*(254&t[16+h])+128*(255&t[17+h])+(254&t[18+h])/2)):a)}else{if(15!==d)return s.z3("invalid data",n,121),r.LR;c=1}e.dts=l,e.pts=a;const f=6+h+c;let p=0;if(0!==o){if(o<h+c)return void s.z3("Malformed PES: PES_packet_length < 3 + PES_header_data_length",n,133);p=o-(h+c)}else p=t.byteLength-f;e.payload=t.subarray(f,f+p)}else if((188===a||191===a||240===a||241===a||255===a||242===a||248===a)&&6===e.streamId){const a=6;let i=0;i=0!==o?o:t.byteLength-a,e.payload=t.subarray(a,a+i)}return 0}},6403:(e,t,a)=>{a.d(t,{Cd:()=>d,I4:()=>f,am:()=>c,kJ:()=>l,pi:()=>h,xf:()=>p});var i=a(134),s=a(80662),r=a.n(s),n=a(77231);class o{constructor(){(0,i.A)(this,"discontinuityIndicator",0),(0,i.A)(this,"randomAccessIndicator",0),(0,i.A)(this,"elementaryStreamPriorityIndicator",0),(0,i.A)(this,"pcrFlag",0),(0,i.A)(this,"opcrFlag",0),(0,i.A)(this,"splicingPointFlag",0),(0,i.A)(this,"transportPrivateDataFlag",0),(0,i.A)(this,"adaptationFieldExtensionFlag",0),(0,i.A)(this,"pcr",BigInt(0)),(0,i.A)(this,"opcr",BigInt(0)),(0,i.A)(this,"spliceCountDown",0),(0,i.A)(this,"transportPrivateData",null),(0,i.A)(this,"extension",null)}}class c{constructor(){(0,i.A)(this,"pos",n.Dh),(0,i.A)(this,"payloadUnitStartIndicator",0),(0,i.A)(this,"transportPriority",0),(0,i.A)(this,"pid",n.N_),(0,i.A)(this,"adaptationFieldControl",0),(0,i.A)(this,"continuityCounter",0),(0,i.A)(this,"transportScramblingControl",0),(0,i.A)(this,"adaptationFieldInfo",new o),(0,i.A)(this,"payload",null)}}class h{constructor(){(0,i.A)(this,"slices",[]),(0,i.A)(this,"totalLength",0),(0,i.A)(this,"expectedLength",n.N_),(0,i.A)(this,"randomAccessIndicator",0),(0,i.A)(this,"pid",n.N_),(0,i.A)(this,"streamType",0),(0,i.A)(this,"pos",n.Dh)}}class d{constructor(){(0,i.A)(this,"versionNumber",0),(0,i.A)(this,"networkPid",n.N_),(0,i.A)(this,"program2PmtPid",new(r()))}}class l{constructor(){(0,i.A)(this,"tag",void 0),(0,i.A)(this,"buffer",void 0)}}class f{constructor(){(0,i.A)(this,"versionNumber",0),(0,i.A)(this,"programNumber",0),(0,i.A)(this,"pcrPid",0),(0,i.A)(this,"pid2StreamType",new(r())),(0,i.A)(this,"pid2ESDescriptor",new(r()))}}class p{constructor(){(0,i.A)(this,"pid",n.N_),(0,i.A)(this,"streamType",0),(0,i.A)(this,"streamId",n.N_),(0,i.A)(this,"dts",n.Dh),(0,i.A)(this,"pts",n.Dh),(0,i.A)(this,"pos",n.Dh),(0,i.A)(this,"payload",null),(0,i.A)(this,"data",null),(0,i.A)(this,"randomAccessIndicator",0)}}},2187:(e,t,a)=>{a.d(t,{d:()=>n});var i=a(72739),s=a(44328),r=a(77231);function n(e,t,a){let n=BigInt(0);return i.__(e,(e=>{n+=e.codecpar.bitrate*(0,s.k)(t,a,r.i0)/BigInt(8e3)})),n}},52071:(e,t,a)=>{a.d(t,{A:()=>l});var i=a(63939),s=(a(9599),a(77231)),r=a(44328),n=a(2187),o=a(71517),c=a(9705),h=a(4624);const d="src/avformat/function/seekInBytes.ts";async function l(e,t,a,l,f,p){const u=e.ioReader.getPos(),g=await e.ioReader.fileSize();let m=s.Dh,A=a;t.startTime!==s.Dh?A-=t.startTime:A-=t.firstDTS;const I=(0,r.k)(a,t.timeBase,s.i0);if(I<BigInt(1e4))return h.Yz(`seek pts is earlier then 10s, seek to first packet pos(${l}) directly`,d,62),await e.ioReader.seek(l),u;let b=(0,n.d)(e.streams,A,t.timeBase);const k=g-(0,n.d)(e.streams,BigInt(1e4),s.i0),y=(0,n.d)(e.streams,BigInt(1e4),s.i0);if(b>k&&(b=k),b<l)return await e.ioReader.seek(l),u;const C=(0,o._5)();let x=g,B=BigInt(0);for(;;){if(x-B<y){m=B;break}if(await e.ioReader.seek(b),await p(e),8&e.ioReader.flags)break;const t=e.ioReader.getPos();if(!(await f(e,C)>=0)){m=s.Dh;break}{const e=(0,r.Mr)(i.f[17](C+8),C+72,s.i0),a=e-I;if(h.Yz(`try to seek to pos: ${b}, got packet pts: ${i.f[17](C+8)}(${e}ms), diff: ${a}ms`,d,100),a<=BigInt(0)&&-a<BigInt(1e4)){m=t;break}a>BigInt(0)?(x=b,b=B+x>>BigInt(1)):(B=b,b=B+x>>BigInt(1))}if(8&e.ioReader.flags)break}return(0,o.Qe)(C),m!==s.Dh?(h.Yz(`finally seek to pos ${m}`,d,131),await e.ioReader.seek(m),await p(e),u):(await e.ioReader.seek(u),8&e.ioReader.flags?BigInt(c.LT):BigInt(c.E$))}},43290:(e,t,a)=>{a.d(t,{R:()=>h,u:()=>c});var i=a(37246),s=a(95073);const r=[1,2,2,2,2,3,3,4,4,5,6,6,6,7,8,8],n=[0,8e3,16e3,32e3,0,0,11025,22050,44100,0,0,12e3,24e3,48e3,96e3,192e3],o=[32e3,56e3,64e3,96e3,112e3,128e3,192e3,224e3,256e3,32e4,384e3,448e3,512e3,576e3,64e4,768e3,96e4,1024e3,1152e3,128e4,1344e3,1408e3,1411200,1472e3,1536e3,192e4,2048e3,3072e3,384e4,0,0,0],c=32;function h(e){const t=new i.A(e.length);t.appendBuffer(e);const a={syncWord:0,frameType:0,deficitSamples:0,crcFlag:0,sampleBlock:0,frameSize:0,channelIndex:0,sampleRateIndex:0,bitrateIndex:0,channels:0,sampleRate:0,bitrate:0};return a.syncWord=t.readU(32),2147385345!==a.syncWord&&4269736320!==a.syncWord?-1:(a.frameType=t.readU1(),a.deficitSamples=t.readU(5)+1,a.crcFlag=t.readU1(),a.sampleBlock=t.readU(7)+1,a.frameSize=(0,s.A)(t.readU(14)+1,4),a.channelIndex=t.readU(6),a.sampleRateIndex=t.readU(4),a.bitrateIndex=t.readU(5),a.channels=r[a.channelIndex],a.sampleRate=n[a.sampleRateIndex],a.bitrate=o[a.bitrateIndex],a)}},22576:(e,t,a)=>{a.d(t,{Ij:()=>h,XC:()=>c,kt:()=>o});var i=a(31865),s=a(729),r=a(44328);const n=[480,960,1920,2880,480,960,1920,2880,480,960,1920,2880,480,960,480,960,120,240,480,960,120,240,480,960,120,240,480,960,120,240,480,960];function o(e){let t=0,a=0,i=0;if(e.length<1)return 0;switch(t=e[0],a=n[t>>3],3&t){case 0:i=1;break;case 1:case 2:i=2;break;case 3:if(e.length<2)return 0;i=63&e[1]}return i*a}function c(e,t){if(!t&&e.sideData[1]&&(t=e.sideData[1]),t&&t.length>=19){const a=new i.A(t,!1);a.skip(9),e.codecpar.chLayout.nbChannels=a.readUint8(),e.codecpar.initialPadding=a.readUint16(),e.codecpar.sampleRate=a.readUint32(),e.codecpar.seekPreroll=Number((0,r.k)(BigInt(80),{den:1e3,num:1},{den:48e3,num:1}))}}function h(e){const t=new Uint8Array(19),a=new s.A(t,!1);return a.writeString("OpusHead"),a.writeUint8(1),a.writeUint8(e.chLayout.nbChannels),a.writeUint16(e.initialPadding),a.writeUint32(e.sampleRate),t}}}]);
1
+ (self.webpackChunklibmedia=self.webpackChunklibmedia||[]).push([[217],{50848:(e,t,a)=>{a.d(t,{A:()=>I});var i=a(134),s=a(63939),r=a(50932),n=a(77162),o=a(29170),c=a(64436),h=a(14686),d=a(4624),l=a(9705),f=a(77231),p=a(95832),u=a(44328),g=a(37837),m=a(71517),A=a(67672);class I extends c.A{constructor(...e){super(...e),(0,i.A)(this,"streamMuxConfig",void 0),(0,i.A)(this,"caches",void 0)}init(e,t){return super.init(e,t),this.caches=[],this.streamMuxConfig={profile:f.N_,sampleRate:f.N_,channels:f.N_},0}sendAVPacket(e){let t=0,a=s.f[17](e+16)!==f.Dh?s.f[17](e+16):s.f[17](e+8);const i=(0,h.s3)(s.f[20](e+24),s.f[15](e+28)).slice();for(;t<i.length;){const e=p.Bq(i.subarray(t));if(A.ai(e))return d.z3("AACADTSParser parse failed","src/avformat/bsf/aac/ADTS2RawFilter.ts",81),l.LR;const c={dts:a,buffer:null,extradata:null,duration:f.N_};c.buffer=i.subarray(t+e.headerLength,t+e.headerLength+e.framePayloadLength),this.streamMuxConfig.profile=e.profile,this.streamMuxConfig.sampleRate=e.sampleRate,this.streamMuxConfig.channels=e.channels;const m=s.f[15](this.inCodecpar+48)!==this.streamMuxConfig.profile||s.f[15](this.inCodecpar+136)!==this.streamMuxConfig.sampleRate||s.f[15](this.inCodecpar+116)!==this.streamMuxConfig.channels,I=(0,u.k)(BigInt(Math.floor(1024*(e.numberOfRawDataBlocksInFrame+1)/this.streamMuxConfig.sampleRate*f.SF)),f.KR,this.inTimeBase);if(c.duration=Number(I),m){r.M[15](this.inCodecpar+48,this.streamMuxConfig.profile),r.M[15](this.inCodecpar+136,this.streamMuxConfig.sampleRate),r.M[15](this.inCodecpar+116,this.streamMuxConfig.channels);const e=(0,p.Ij)((0,o.A)(this.inCodecpar,n.A));s.f[20](this.inCodecpar+12)&&(0,g.Eb)(s.f[20](this.inCodecpar+12)),r.M[20](this.inCodecpar+12,(0,g.sY)(e.length)),(0,h.lW)(s.f[20](this.inCodecpar+12),e.length,e),r.M[15](this.inCodecpar+16,e.length),c.extradata=e}this.caches.push(c),t+=e.aacFrameLength,a+=I}return 0}receiveAVPacket(e){if(this.caches.length){(0,m.Up)(e);const t=this.caches.shift(),a=(0,g.sY)(t.buffer.length);if((0,h.lW)(a,t.buffer.length,t.buffer),(0,m.NX)(e,a,t.buffer.length),r.M[17](e+16,t.dts),r.M[17](e+8,t.dts),r.M[17](e+48,BigInt(Math.floor(t.duration))),r.M[15](e+36,1|s.f[15](e+36)),t.extradata){const a=(0,g.sY)(t.extradata.length);(0,h.lW)(a,t.extradata.length,t.extradata),(0,m.Ow)(e,1,a,t.extradata.length)}return 0}return l.LT}reset(){return 0}}},85947:(e,t,a)=>{a.d(t,{A:()=>s});var i=a(134);class s{constructor(){(0,i.A)(this,"type",-1),(0,i.A)(this,"onStreamAdd",void 0)}async destroy(e){}}},51660:(e,t,a)=>{a.d(t,{A:()=>o});var i=a(77231),s=a(4624),r=a(9705);const n="src/avformat/formats/mpegts/function/parsePES.ts";function o(e){const t=e.data,a=t[3],o=t[4]<<8|t[5];let c=0,h=0,d=0;if(188!==a&&190!==a&&191!==a&&240!==a&&241!==a&&255!==a&&242!==a&&248!==a){let a=i.Dh,l=i.Dh;for(;;){if(6+h>=t.length)return r.LR;if(d=t[6+h],255!==d)break;h++}if(64==(192&d)&&(h+=2,d=t[6+h]),32==(224&d))c+=5,a=a=BigInt(Math.floor(536870912*(14&t[6+h])+4194304*(255&t[7+h])+16384*(254&t[8+h])+128*(255&t[9+h])+(254&t[10+h])/2)),16&d?(l=BigInt(Math.floor(536870912*(14&t[11+h])+4194304*(255&t[12+h])+16384*(254&t[13+h])+128*(255&t[14+h])+(254&t[15+h])/2)),c+=5):l=a;else if(128==(192&d)){const e=(192&t[7+h])>>>6;c=3+t[8+h],2!==e&&3!==e||(a=BigInt(Math.floor(536870912*(14&t[9+h])+4194304*(255&t[10+h])+16384*(254&t[11+h])+128*(255&t[12+h])+(254&t[13+h])/2)),l=3===e?BigInt(Math.floor(536870912*(14&t[14+h])+4194304*(255&t[15+h])+16384*(254&t[16+h])+128*(255&t[17+h])+(254&t[18+h])/2)):a)}else{if(15!==d)return s.z3("invalid data",n,121),r.LR;c=1}e.dts=l,e.pts=a;const f=6+h+c;let p=0;if(0!==o){if(o<h+c)return s.z3("Malformed PES: PES_packet_length < 3 + PES_header_data_length",n,133),r.LR;p=o-(h+c)}else p=t.byteLength-f;e.payload=t.subarray(f,f+p)}else if((188===a||191===a||240===a||241===a||255===a||242===a||248===a)&&6===e.streamId){const a=6;let i=0;i=0!==o?o:t.byteLength-a,e.payload=t.subarray(a,a+i)}return 0}},6403:(e,t,a)=>{a.d(t,{Cd:()=>d,I4:()=>f,am:()=>c,kJ:()=>l,pi:()=>h,xf:()=>p});var i=a(134),s=a(80662),r=a.n(s),n=a(77231);class o{constructor(){(0,i.A)(this,"discontinuityIndicator",0),(0,i.A)(this,"randomAccessIndicator",0),(0,i.A)(this,"elementaryStreamPriorityIndicator",0),(0,i.A)(this,"pcrFlag",0),(0,i.A)(this,"opcrFlag",0),(0,i.A)(this,"splicingPointFlag",0),(0,i.A)(this,"transportPrivateDataFlag",0),(0,i.A)(this,"adaptationFieldExtensionFlag",0),(0,i.A)(this,"pcr",BigInt(0)),(0,i.A)(this,"opcr",BigInt(0)),(0,i.A)(this,"spliceCountDown",0),(0,i.A)(this,"transportPrivateData",null),(0,i.A)(this,"extension",null)}}class c{constructor(){(0,i.A)(this,"pos",n.Dh),(0,i.A)(this,"payloadUnitStartIndicator",0),(0,i.A)(this,"transportPriority",0),(0,i.A)(this,"pid",n.N_),(0,i.A)(this,"adaptationFieldControl",0),(0,i.A)(this,"continuityCounter",0),(0,i.A)(this,"transportScramblingControl",0),(0,i.A)(this,"adaptationFieldInfo",new o),(0,i.A)(this,"payload",null)}}class h{constructor(){(0,i.A)(this,"slices",[]),(0,i.A)(this,"totalLength",0),(0,i.A)(this,"expectedLength",n.N_),(0,i.A)(this,"randomAccessIndicator",0),(0,i.A)(this,"pid",n.N_),(0,i.A)(this,"streamType",0),(0,i.A)(this,"pos",n.Dh)}}class d{constructor(){(0,i.A)(this,"versionNumber",0),(0,i.A)(this,"networkPid",n.N_),(0,i.A)(this,"program2PmtPid",new(r()))}}class l{constructor(){(0,i.A)(this,"tag",void 0),(0,i.A)(this,"buffer",void 0)}}class f{constructor(){(0,i.A)(this,"versionNumber",0),(0,i.A)(this,"programNumber",0),(0,i.A)(this,"pcrPid",0),(0,i.A)(this,"pid2StreamType",new(r())),(0,i.A)(this,"pid2ESDescriptor",new(r()))}}class p{constructor(){(0,i.A)(this,"pid",n.N_),(0,i.A)(this,"streamType",0),(0,i.A)(this,"streamId",n.N_),(0,i.A)(this,"dts",n.Dh),(0,i.A)(this,"pts",n.Dh),(0,i.A)(this,"pos",n.Dh),(0,i.A)(this,"payload",null),(0,i.A)(this,"data",null),(0,i.A)(this,"randomAccessIndicator",0)}}},2187:(e,t,a)=>{a.d(t,{d:()=>n});var i=a(72739),s=a(44328),r=a(77231);function n(e,t,a){let n=BigInt(0);return i.__(e,(e=>{n+=e.codecpar.bitrate*(0,s.k)(t,a,r.i0)/BigInt(8e3)})),n}},52071:(e,t,a)=>{a.d(t,{A:()=>l});var i=a(63939),s=(a(9599),a(77231)),r=a(44328),n=a(2187),o=a(71517),c=a(9705),h=a(4624);const d="src/avformat/function/seekInBytes.ts";async function l(e,t,a,l,f,p){const u=e.ioReader.getPos(),g=await e.ioReader.fileSize();let m=s.Dh,A=a;t.startTime!==s.Dh?A-=t.startTime:A-=t.firstDTS;const I=(0,r.k)(a,t.timeBase,s.i0);if(I<BigInt(1e4))return h.Yz(`seek pts is earlier then 10s, seek to first packet pos(${l}) directly`,d,62),await e.ioReader.seek(l),u;let b=(0,n.d)(e.streams,A,t.timeBase);const k=g-(0,n.d)(e.streams,BigInt(1e4),s.i0),y=(0,n.d)(e.streams,BigInt(1e4),s.i0);if(b>k&&(b=k),b<l)return await e.ioReader.seek(l),u;const C=(0,o._5)();let x=g,R=BigInt(0);for(;;){if(x-R<y){m=R;break}if(await e.ioReader.seek(b),await p(e),8&e.ioReader.flags)break;const t=e.ioReader.getPos();if(!(await f(e,C)>=0)){m=s.Dh;break}{const e=(0,r.Mr)(i.f[17](C+8),C+72,s.i0),a=e-I;if(h.Yz(`try to seek to pos: ${b}, got packet pts: ${i.f[17](C+8)}(${e}ms), diff: ${a}ms`,d,100),a<=BigInt(0)&&-a<BigInt(1e4)){m=t;break}a>BigInt(0)?(x=b,b=R+x>>BigInt(1)):(R=b,b=R+x>>BigInt(1))}if(8&e.ioReader.flags)break}return(0,o.Qe)(C),m!==s.Dh?(h.Yz(`finally seek to pos ${m}`,d,131),await e.ioReader.seek(m),await p(e),u):(await e.ioReader.seek(u),8&e.ioReader.flags?BigInt(c.LT):BigInt(c.E$))}},43290:(e,t,a)=>{a.d(t,{R:()=>h,u:()=>c});var i=a(37246),s=a(95073);const r=[1,2,2,2,2,3,3,4,4,5,6,6,6,7,8,8],n=[0,8e3,16e3,32e3,0,0,11025,22050,44100,0,0,12e3,24e3,48e3,96e3,192e3],o=[32e3,56e3,64e3,96e3,112e3,128e3,192e3,224e3,256e3,32e4,384e3,448e3,512e3,576e3,64e4,768e3,96e4,1024e3,1152e3,128e4,1344e3,1408e3,1411200,1472e3,1536e3,192e4,2048e3,3072e3,384e4,0,0,0],c=32;function h(e){const t=new i.A(e.length);t.appendBuffer(e);const a={syncWord:0,frameType:0,deficitSamples:0,crcFlag:0,sampleBlock:0,frameSize:0,channelIndex:0,sampleRateIndex:0,bitrateIndex:0,channels:0,sampleRate:0,bitrate:0};return a.syncWord=t.readU(32),2147385345!==a.syncWord&&4269736320!==a.syncWord?-1:(a.frameType=t.readU1(),a.deficitSamples=t.readU(5)+1,a.crcFlag=t.readU1(),a.sampleBlock=t.readU(7)+1,a.frameSize=(0,s.A)(t.readU(14)+1,4),a.channelIndex=t.readU(6),a.sampleRateIndex=t.readU(4),a.bitrateIndex=t.readU(5),a.channels=r[a.channelIndex],a.sampleRate=n[a.sampleRateIndex],a.bitrate=o[a.bitrateIndex],a)}},22576:(e,t,a)=>{a.d(t,{Ij:()=>h,XC:()=>c,kt:()=>o});var i=a(31865),s=a(729),r=a(44328);const n=[480,960,1920,2880,480,960,1920,2880,480,960,1920,2880,480,960,480,960,120,240,480,960,120,240,480,960,120,240,480,960,120,240,480,960];function o(e){let t=0,a=0,i=0;if(e.length<1)return 0;switch(t=e[0],a=n[t>>3],3&t){case 0:i=1;break;case 1:case 2:i=2;break;case 3:if(e.length<2)return 0;i=63&e[1]}return i*a}function c(e,t){if(!t&&e.sideData[1]&&(t=e.sideData[1]),t&&t.length>=19){const a=new i.A(t,!1);a.skip(9),e.codecpar.chLayout.nbChannels=a.readUint8(),e.codecpar.initialPadding=a.readUint16(),e.codecpar.sampleRate=a.readUint32(),e.codecpar.seekPreroll=Number((0,r.k)(BigInt(80),{den:1e3,num:1},{den:48e3,num:1}))}}function h(e){const t=new Uint8Array(19),a=new s.A(t,!1);return a.writeString("OpusHead"),a.writeUint8(1),a.writeUint8(e.chLayout.nbChannels),a.writeUint16(e.initialPadding),a.writeUint32(e.sampleRate),t}}}]);