pup-recorder 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build.ts CHANGED
@@ -38,3 +38,10 @@ await build({
38
38
  format: "cjs",
39
39
  outDir: "dist",
40
40
  });
41
+
42
+ await build({
43
+ ...common,
44
+ entry: ["src/audio_preload.ts"],
45
+ format: "cjs",
46
+ outDir: "dist",
47
+ });
@@ -20,6 +20,7 @@ import { Size } from 'electron';
20
20
  import { SoftwareScaleContext } from 'node-av';
21
21
  import { SpawnOptions } from 'child_process';
22
22
  import { Stream } from 'node-av';
23
+ import { WebContents } from 'electron';
23
24
  import type { WebFrameMain } from 'electron';
24
25
  import z from 'zod';
25
26
 
@@ -30,15 +31,13 @@ export declare function advanceVirtualTime(cdp: Debugger, budget: number): Promi
30
31
 
31
32
  export declare const ANNEX_B_START_CODE: Buffer<ArrayBuffer>;
32
33
 
33
- export declare interface AudioCapture {
34
- teardown(): Promise<void>;
35
- }
34
+ export declare function attachAudioListeners({ wc, encoder, getVideoTimeMs, onError }: AudioListenerOptions): AudioDisposal;
36
35
 
37
- export declare interface AudioCaptureOptions {
38
- encoder: EncoderPipeline;
39
- getVideoTimeMs: () => number;
40
- onError: (error: Error) => void;
41
- }
36
+ export declare const AUDIO_CHUNK_CHANNEL = "audio-chunk";
37
+
38
+ export declare const AUDIO_META_CHANNEL = "audio-meta";
39
+
40
+ export declare type AudioDisposal = () => void;
42
41
 
43
42
  declare class AudioEncoder_2 implements Disposable {
44
43
  private _ctx;
@@ -73,6 +72,13 @@ export declare interface AudioEncoderOptions {
73
72
  muxer: FormatMuxer;
74
73
  }
75
74
 
75
+ export declare interface AudioListenerOptions {
76
+ wc: WebContents;
77
+ encoder: EncoderPipeline;
78
+ getVideoTimeMs: () => number;
79
+ onError: (error: Error) => void;
80
+ }
81
+
76
82
  export declare class BitReader {
77
83
  private _bits;
78
84
  pos: number;
@@ -106,6 +112,11 @@ export declare function buildStegoHTML(targetURL: string, size: Size): string;
106
112
 
107
113
  export declare function buildUnifiedExtradata(opts: UnifiedExtradataOptions): Buffer;
108
114
 
115
+ export declare interface CancelMsg {
116
+ type: IpcMsgType.CANCEL;
117
+ reason?: string;
118
+ }
119
+
109
120
  export declare const canIUseGPU: Promise<boolean>;
110
121
 
111
122
  export declare function checkHTML(source: string): void;
@@ -114,7 +125,6 @@ export declare function chromiumOptions(disableGpu: boolean): Promise<string[]>;
114
125
 
115
126
  export declare interface CLIOptions {
116
127
  name: string;
117
- defaults: RenderOptions;
118
128
  run: (source: string, options: RenderOptions) => Promise<unknown>;
119
129
  }
120
130
 
@@ -156,6 +166,16 @@ declare class ConcurrencyLimiter {
156
166
  export { ConcurrencyLimiter }
157
167
  export { ConcurrencyLimiter as ConcurrencyLimiter_alias_1 }
158
168
 
169
+ declare type ConsoleCallback = (level: string, message: string) => void;
170
+ export { ConsoleCallback }
171
+ export { ConsoleCallback as ConsoleCallback_alias_1 }
172
+
173
+ export declare interface ConsoleMsg {
174
+ type: IpcMsgType.CONSOLE;
175
+ level: string;
176
+ message: string;
177
+ }
178
+
159
179
  export declare function createHwVideoEncoder(opts: HwVideoFactoryOptions, muxer: FormatMuxer): Promise<VideoSetup>;
160
180
 
161
181
  export declare function createStegoURL(src: string, size: Size): string;
@@ -176,7 +196,7 @@ declare const DEFAULT_HEIGHT = 1080;
176
196
  export { DEFAULT_HEIGHT }
177
197
  export { DEFAULT_HEIGHT as DEFAULT_HEIGHT_alias_1 }
178
198
 
179
- declare const DEFAULT_OUT_FILE = "output.mp4";
199
+ declare const DEFAULT_OUT_FILE = "out/html.mp4,out/html.webm";
180
200
  export { DEFAULT_OUT_FILE }
181
201
  export { DEFAULT_OUT_FILE as DEFAULT_OUT_FILE_alias_1 }
182
202
 
@@ -238,6 +258,8 @@ export declare interface ErrorMsg {
238
258
  error: string;
239
259
  }
240
260
 
261
+ export declare function evalIn(cdp: Debugger, expression: string): Promise<unknown>;
262
+
241
263
  declare function exec(cmd: string, options?: SpawnOptions): ProcessHandle;
242
264
  export { exec }
243
265
  export { exec as exec_alias_1 }
@@ -320,7 +342,7 @@ export declare interface HwVideoFactoryOptions {
320
342
  sharedHw?: HardwareContext;
321
343
  }
322
344
 
323
- export declare function interleaveAccessUnits(baseNals: NalUnit[], alphaNals: NalUnit[]): Buffer;
345
+ export declare function interleaveAccessUnits(baseNals: NalUnit[], alphaNals: NalUnit[], cfg: NvencHevcConfig): Buffer;
324
346
 
325
347
  export declare interface IpcDonePayload {
326
348
  written: number;
@@ -330,25 +352,37 @@ export declare interface IpcDonePayload {
330
352
 
331
353
  export declare interface IpcEvents {
332
354
  progress: [value: number];
333
- message: [msg: IpcMsg];
355
+ console: [level: string, msg: string];
334
356
  done: [payload: IpcDonePayload];
335
357
  error: [error: Error];
336
358
  close: [code: number | null];
337
359
  }
338
360
 
339
- export declare type IpcMsg = ProgressMsg | DoneMsg | ErrorMsg;
361
+ export declare type IpcMsg = ConsoleMsg | ProgressMsg | DoneMsg | ErrorMsg | CancelMsg;
340
362
 
341
363
  export declare const enum IpcMsgType {
364
+ CONSOLE = "console",
342
365
  PROGRESS = "progress",
343
366
  DONE = "done",
344
- ERROR = "error"
367
+ ERROR = "error",
368
+ CANCEL = "cancel"
345
369
  }
346
370
 
347
371
  export declare class IpcReader extends EventEmitter<IpcEvents> {
348
372
  constructor(child: ChildProcess);
349
373
  }
350
374
 
375
+ declare interface IPCRenderOptions extends RenderOptions {
376
+ source: string;
377
+ signal: AbortSignal;
378
+ onProgress: ProgressCallback;
379
+ onConsole: ConsoleCallback;
380
+ }
381
+ export { IPCRenderOptions }
382
+ export { IPCRenderOptions as IPCRenderOptions_alias_1 }
383
+
351
384
  export declare class IpcWriter {
385
+ writeConsole(level: string, message: string): void;
352
386
  writeProgress(value: number): void;
353
387
  writeError(error: string): Promise<void>;
354
388
  writeDone(payload: IpcDonePayload): Promise<void>;
@@ -368,7 +402,7 @@ declare class Lazy<T> {
368
402
  export { Lazy }
369
403
  export { Lazy as Lazy_alias_1 }
370
404
 
371
- export declare function loadWindow({ source, onCreated, renderer }: WindowOptions): Promise<BrowserWindow>;
405
+ export declare function loadWindow({ source, renderer, preload, onCreated, signal, }: WindowOptions): Promise<BrowserWindow>;
372
406
 
373
407
  declare class Logger implements LoggerLike {
374
408
  private _level;
@@ -408,8 +442,28 @@ export declare function makeFrame(width: number, height: number, pixFmt: AVPixel
408
442
 
409
443
  export declare function makePacket(): Packet;
410
444
 
445
+ export declare const MAX_RENDER_ATTEMPTS = 3;
446
+
447
+ export declare const NAL_BLA_W_LP = 16;
448
+
411
449
  export declare const NAL_HEADER_SIZE = 2;
412
450
 
451
+ export declare const NAL_IDR_N_LP = 20;
452
+
453
+ export declare const NAL_IDR_W_RADL = 19;
454
+
455
+ export declare const NAL_PPS = 34;
456
+
457
+ export declare const NAL_RSV_IRAP_VCL23 = 23;
458
+
459
+ export declare const NAL_SEI_PREFIX = 39;
460
+
461
+ export declare const NAL_SEI_SUFFIX = 40;
462
+
463
+ export declare const NAL_SPS = 33;
464
+
465
+ export declare const NAL_VPS = 32;
466
+
413
467
  export declare interface NalUnit {
414
468
  type: number;
415
469
  layerId: number;
@@ -428,9 +482,7 @@ export { noerr as noerr_alias_1 }
428
482
 
429
483
  export declare class NvencDualLayerEncoder implements Disposable {
430
484
  private _s;
431
- private _seiBuffer;
432
485
  private _pts;
433
- private _seiInjected;
434
486
  private constructor();
435
487
  static create(opts: HwVideoEncoderOptions): Promise<NvencDualLayerEncoder>;
436
488
  encode(bgraFrame: Frame, muxer: FormatMuxer): Promise<void>;
@@ -439,6 +491,17 @@ export declare class NvencDualLayerEncoder implements Disposable {
439
491
  private drainInterleaved;
440
492
  }
441
493
 
494
+ export declare interface NvencHevcConfig {
495
+ log2MaxPocLsb: number;
496
+ numShortTermRefPicSets: number;
497
+ numDeltaPocsSet0: number;
498
+ longTermRefPicsPresent: boolean;
499
+ spsTemporalMvpEnabled: boolean;
500
+ saoEnabled: boolean;
501
+ cabacInitPresent: boolean;
502
+ ppsHasLoopFilterAcrossSlicesFlag: boolean;
503
+ }
504
+
442
505
  export declare function openVideoCtx(opts: VideoCtxOptions, label: string): Promise<CodecContext>;
443
506
 
444
507
  export declare class OutputSink implements AsyncDisposable {
@@ -469,10 +532,15 @@ declare function parseNumber(x: unknown): number;
469
532
  export { parseNumber }
470
533
  export { parseNumber as parseNumber_alias_1 }
471
534
 
535
+ export declare function parseNvencHevcConfig(extradata: Buffer): NvencHevcConfig;
536
+
472
537
  declare function parseString(x: unknown): string;
473
538
  export { parseString }
474
539
  export { parseString as parseString_alias_1 }
475
540
 
541
+ /** Patch every VPS/SPS NAL in an Annex B bitstream so PTL matches Apple/x265. */
542
+ export declare function patchHevcAlphaPtl(bitstream: Buffer): Buffer;
543
+
476
544
  export declare function pauseVirtualTime(cdp: Debugger): Promise<void>;
477
545
 
478
546
  declare function penv<T>(name: string, parser: EnvParser<T>, defaultValue: T): T;
@@ -494,6 +562,10 @@ declare interface ProcessHandle {
494
562
  export { ProcessHandle }
495
563
  export { ProcessHandle as ProcessHandle_alias_1 }
496
564
 
565
+ declare type ProgressCallback = (progress: number) => void;
566
+ export { ProgressCallback }
567
+ export { ProgressCallback as ProgressCallback_alias_1 }
568
+
497
569
  export declare interface ProgressMsg {
498
570
  type: IpcMsgType.PROGRESS;
499
571
  value: number;
@@ -513,17 +585,9 @@ declare const pupApp: string;
513
585
  export { pupApp }
514
586
  export { pupApp as pupApp_alias_1 }
515
587
 
516
- declare const pupDeterministic: boolean;
517
- export { pupDeterministic }
518
- export { pupDeterministic as pupDeterministic_alias_1 }
519
-
520
- declare const pupDisableGPU: boolean;
521
- export { pupDisableGPU }
522
- export { pupDisableGPU as pupDisableGPU_alias_1 }
523
-
524
- declare const pupDisableHwCodec: boolean;
525
- export { pupDisableHwCodec }
526
- export { pupDisableHwCodec as pupDisableHwCodec_alias_1 }
588
+ declare const pupAudioPreload: string;
589
+ export { pupAudioPreload }
590
+ export { pupAudioPreload as pupAudioPreload_alias_1 }
527
591
 
528
592
  declare const pupLogLevel: number;
529
593
  export { pupLogLevel }
@@ -531,7 +595,8 @@ export { pupLogLevel as pupLogLevel_alias_1 }
531
595
 
532
596
  declare interface PupOptions extends Partial<RenderOptions> {
533
597
  signal?: AbortSignal;
534
- onProgress?: PupProgressCallback;
598
+ onProgress?: ProgressCallback;
599
+ onConsole?: ConsoleCallback;
535
600
  }
536
601
  export { PupOptions }
537
602
  export { PupOptions as PupOptions_alias_1 }
@@ -540,27 +605,15 @@ declare const pupPkgRoot: string;
540
605
  export { pupPkgRoot }
541
606
  export { pupPkgRoot as pupPkgRoot_alias_1 }
542
607
 
543
- declare type PupProgressCallback = (progress: number) => Promise<void> | void;
544
- export { PupProgressCallback }
545
- export { PupProgressCallback as PupProgressCallback_alias_1 }
546
-
547
608
  declare interface PupResult extends RenderResult {
548
609
  }
549
610
  export { PupResult }
550
611
  export { PupResult as PupResult_alias_1 }
551
612
 
552
- declare const pupUseInnerProxy: boolean;
553
- export { pupUseInnerProxy }
554
- export { pupUseInnerProxy as pupUseInnerProxy_alias_1 }
555
-
556
- declare const pupWindowTolerant: boolean;
557
- export { pupWindowTolerant }
558
- export { pupWindowTolerant as pupWindowTolerant_alias_1 }
559
-
560
613
  /** Remove emulation prevention bytes (00 00 03 → 00 00) from RBSP. */
561
614
  export declare function removeEmulationPrevention(data: Buffer): Buffer;
562
615
 
563
- export declare function render(writer: IpcWriter, source: string, options: RenderOptions): Promise<IpcDonePayload>;
616
+ export declare function render(options: IPCRenderOptions): Promise<IpcDonePayload>;
564
617
 
565
618
  declare type RenderOptions = z.infer<typeof RenderSchema>;
566
619
  export { RenderOptions }
@@ -591,19 +644,40 @@ declare const RenderSchema: z.ZodObject<{
591
644
  export { RenderSchema }
592
645
  export { RenderSchema as RenderSchema_alias_1 }
593
646
 
647
+ export declare class RerenderError extends Error {
648
+ constructor(message: string);
649
+ }
650
+
594
651
  export declare function resizeDrawable(cdp: Debugger, size: Size): Promise<void>;
595
652
 
596
653
  declare interface RetryOptions<Args extends any[], Ret> {
597
654
  fn: (...args: Args) => Promise<Ret>;
598
655
  maxAttempts?: number;
599
656
  timeout?: number;
657
+ signal?: AbortSignal;
600
658
  }
601
659
  export { RetryOptions }
602
660
  export { RetryOptions as RetryOptions_alias_1 }
603
661
 
662
+ /** Alpha PPS: pps_pic_parameter_set_id 0 → 1, pps_seq_parameter_set_id 0 → 1. */
663
+ export declare function rewriteAlphaPps(pps: Buffer): Buffer;
664
+
665
+ /**
666
+ * Rewrite alpha slice header: slice_pic_parameter_set_id 0 → 1.
667
+ * The +2-bit shift is absorbed by emitting a fresh byte_alignment then appending the
668
+ * original CABAC slice_segment_data bytes verbatim. CABAC byte boundary is preserved.
669
+ */
670
+ export declare function rewriteAlphaSliceHeader(slice: Buffer, nalType: number, cfg: NvencHevcConfig): Buffer;
671
+
672
+ /** Alpha SPS: sps_seq_parameter_set_id 0 → 1. */
673
+ export declare function rewriteAlphaSps(sps: Buffer): Buffer;
674
+
604
675
  /** Rewrite nuh_layer_id in a NAL unit (returns copy). */
605
676
  export declare function rewriteNalLayerId(nal: Buffer, layerId: number): Buffer;
606
677
 
678
+ /** Rewrite nal_unit_type in a NAL unit (returns copy). */
679
+ export declare function rewriteNalType(nal: Buffer, newType: number): Buffer;
680
+
607
681
  export declare function runElectronApp({ args }: RunElectronAppOptions): Promise<ProcessHandle>;
608
682
 
609
683
  export declare interface RunElectronAppOptions {
@@ -614,11 +688,9 @@ export declare function send(cdp: Debugger, method: string, params?: object): Pr
614
688
 
615
689
  export declare function setInterceptor({ source, window, useInnerProxy }: NetworkOptions): void;
616
690
 
617
- export declare function setupAudioCapture({ encoder, getVideoTimeMs, onError, }: AudioCaptureOptions): Promise<AudioCapture>;
618
-
619
691
  export declare function setupPupProtocol(): void;
620
692
 
621
- export declare function shoot(writer: IpcWriter, source: string, options: RenderOptions): Promise<IpcDonePayload>;
693
+ export declare function shoot(options: IPCRenderOptions): Promise<IpcDonePayload>;
622
694
 
623
695
  export declare type SinkKind = "mp4" | "webm";
624
696
 
@@ -644,13 +716,13 @@ export declare function splitNalUnits(bitstream: Buffer): NalUnit[];
644
716
 
645
717
  export declare function startElectronCrashReporter(): void;
646
718
 
647
- export declare function startStego(cdp: Debugger): Promise<void>;
719
+ export declare function startStego(cdp: Debugger): Promise<unknown>;
648
720
 
649
721
  export declare const STEGO_TICK_CHANNEL = "stego-tick";
650
722
 
651
- export declare function stopStego(cdp: Debugger): Promise<void>;
723
+ export declare function stopStego(cdp: Debugger): Promise<unknown>;
652
724
 
653
- export declare function swapBuffer(cdp: Debugger, expected: number): Promise<void>;
725
+ export declare function swapBuffer(wc: WebContents, expected: number, interval: number): Promise<void>;
654
726
 
655
727
  export declare function tick(frame: WebFrameMain | undefined, timestampMs: number): Promise<void>;
656
728
 
@@ -665,7 +737,7 @@ export declare interface UnifiedExtradataOptions {
665
737
 
666
738
  export declare function unsetInterceptor(window: BrowserWindow): void;
667
739
 
668
- declare function useRetry<Args extends any[], Ret>({ fn, maxAttempts, timeout }: RetryOptions<Args, Ret>): (...args: Args) => Promise<Ret>;
740
+ declare function useRetry<Args extends any[], Ret>({ fn, maxAttempts, timeout, signal }: RetryOptions<Args, Ret>): (...args: Args) => Promise<Ret>;
669
741
  export { useRetry }
670
742
  export { useRetry as useRetry_alias_1 }
671
743
 
@@ -742,14 +814,19 @@ export declare interface WaitOptions {
742
814
  onTimeout?: () => void;
743
815
  }
744
816
 
817
+ export declare type WindowCreatedCallback = (window: BrowserWindow) => void | Promise<void>;
818
+
745
819
  export declare interface WindowOptions {
746
820
  source: string;
747
- onCreated?: (window: BrowserWindow) => Promise<void>;
748
- renderer: RenderOptions;
749
- warmup?: boolean;
821
+ renderer: IPCRenderOptions;
750
822
  tolerant?: boolean;
823
+ preload?: string;
824
+ onCreated?: WindowCreatedCallback;
825
+ signal?: AbortSignal;
751
826
  }
752
827
 
828
+ export declare function withRerender<T>(action: () => Promise<T>): Promise<T>;
829
+
753
830
  declare function withTimeout<T>(p: Promise<T>, ms: number, label: string): Promise<T>;
754
831
  export { withTimeout }
755
832
  export { withTimeout as withTimeout_alias_1 }