pup-recorder 0.3.5 → 0.3.6

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,26 @@ 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 NAL_BLA_W_LP = 16;
446
+
411
447
  export declare const NAL_HEADER_SIZE = 2;
412
448
 
449
+ export declare const NAL_IDR_N_LP = 20;
450
+
451
+ export declare const NAL_IDR_W_RADL = 19;
452
+
453
+ export declare const NAL_PPS = 34;
454
+
455
+ export declare const NAL_RSV_IRAP_VCL23 = 23;
456
+
457
+ export declare const NAL_SEI_PREFIX = 39;
458
+
459
+ export declare const NAL_SEI_SUFFIX = 40;
460
+
461
+ export declare const NAL_SPS = 33;
462
+
463
+ export declare const NAL_VPS = 32;
464
+
413
465
  export declare interface NalUnit {
414
466
  type: number;
415
467
  layerId: number;
@@ -428,9 +480,7 @@ export { noerr as noerr_alias_1 }
428
480
 
429
481
  export declare class NvencDualLayerEncoder implements Disposable {
430
482
  private _s;
431
- private _seiBuffer;
432
483
  private _pts;
433
- private _seiInjected;
434
484
  private constructor();
435
485
  static create(opts: HwVideoEncoderOptions): Promise<NvencDualLayerEncoder>;
436
486
  encode(bgraFrame: Frame, muxer: FormatMuxer): Promise<void>;
@@ -439,6 +489,17 @@ export declare class NvencDualLayerEncoder implements Disposable {
439
489
  private drainInterleaved;
440
490
  }
441
491
 
492
+ export declare interface NvencHevcConfig {
493
+ log2MaxPocLsb: number;
494
+ numShortTermRefPicSets: number;
495
+ numDeltaPocsSet0: number;
496
+ longTermRefPicsPresent: boolean;
497
+ spsTemporalMvpEnabled: boolean;
498
+ saoEnabled: boolean;
499
+ cabacInitPresent: boolean;
500
+ ppsHasLoopFilterAcrossSlicesFlag: boolean;
501
+ }
502
+
442
503
  export declare function openVideoCtx(opts: VideoCtxOptions, label: string): Promise<CodecContext>;
443
504
 
444
505
  export declare class OutputSink implements AsyncDisposable {
@@ -469,10 +530,15 @@ declare function parseNumber(x: unknown): number;
469
530
  export { parseNumber }
470
531
  export { parseNumber as parseNumber_alias_1 }
471
532
 
533
+ export declare function parseNvencHevcConfig(extradata: Buffer): NvencHevcConfig;
534
+
472
535
  declare function parseString(x: unknown): string;
473
536
  export { parseString }
474
537
  export { parseString as parseString_alias_1 }
475
538
 
539
+ /** Patch every VPS/SPS NAL in an Annex B bitstream so PTL matches Apple/x265. */
540
+ export declare function patchHevcAlphaPtl(bitstream: Buffer): Buffer;
541
+
476
542
  export declare function pauseVirtualTime(cdp: Debugger): Promise<void>;
477
543
 
478
544
  declare function penv<T>(name: string, parser: EnvParser<T>, defaultValue: T): T;
@@ -494,6 +560,10 @@ declare interface ProcessHandle {
494
560
  export { ProcessHandle }
495
561
  export { ProcessHandle as ProcessHandle_alias_1 }
496
562
 
563
+ declare type ProgressCallback = (progress: number) => void;
564
+ export { ProgressCallback }
565
+ export { ProgressCallback as ProgressCallback_alias_1 }
566
+
497
567
  export declare interface ProgressMsg {
498
568
  type: IpcMsgType.PROGRESS;
499
569
  value: number;
@@ -513,17 +583,9 @@ declare const pupApp: string;
513
583
  export { pupApp }
514
584
  export { pupApp as pupApp_alias_1 }
515
585
 
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 }
586
+ declare const pupAudioPreload: string;
587
+ export { pupAudioPreload }
588
+ export { pupAudioPreload as pupAudioPreload_alias_1 }
527
589
 
528
590
  declare const pupLogLevel: number;
529
591
  export { pupLogLevel }
@@ -531,7 +593,8 @@ export { pupLogLevel as pupLogLevel_alias_1 }
531
593
 
532
594
  declare interface PupOptions extends Partial<RenderOptions> {
533
595
  signal?: AbortSignal;
534
- onProgress?: PupProgressCallback;
596
+ onProgress?: ProgressCallback;
597
+ onConsole?: ConsoleCallback;
535
598
  }
536
599
  export { PupOptions }
537
600
  export { PupOptions as PupOptions_alias_1 }
@@ -540,27 +603,15 @@ declare const pupPkgRoot: string;
540
603
  export { pupPkgRoot }
541
604
  export { pupPkgRoot as pupPkgRoot_alias_1 }
542
605
 
543
- declare type PupProgressCallback = (progress: number) => Promise<void> | void;
544
- export { PupProgressCallback }
545
- export { PupProgressCallback as PupProgressCallback_alias_1 }
546
-
547
606
  declare interface PupResult extends RenderResult {
548
607
  }
549
608
  export { PupResult }
550
609
  export { PupResult as PupResult_alias_1 }
551
610
 
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
611
  /** Remove emulation prevention bytes (00 00 03 → 00 00) from RBSP. */
561
612
  export declare function removeEmulationPrevention(data: Buffer): Buffer;
562
613
 
563
- export declare function render(writer: IpcWriter, source: string, options: RenderOptions): Promise<IpcDonePayload>;
614
+ export declare function render(options: IPCRenderOptions): Promise<IpcDonePayload>;
564
615
 
565
616
  declare type RenderOptions = z.infer<typeof RenderSchema>;
566
617
  export { RenderOptions }
@@ -601,9 +652,25 @@ declare interface RetryOptions<Args extends any[], Ret> {
601
652
  export { RetryOptions }
602
653
  export { RetryOptions as RetryOptions_alias_1 }
603
654
 
655
+ /** Alpha PPS: pps_pic_parameter_set_id 0 → 1, pps_seq_parameter_set_id 0 → 1. */
656
+ export declare function rewriteAlphaPps(pps: Buffer): Buffer;
657
+
658
+ /**
659
+ * Rewrite alpha slice header: slice_pic_parameter_set_id 0 → 1.
660
+ * The +2-bit shift is absorbed by emitting a fresh byte_alignment then appending the
661
+ * original CABAC slice_segment_data bytes verbatim. CABAC byte boundary is preserved.
662
+ */
663
+ export declare function rewriteAlphaSliceHeader(slice: Buffer, nalType: number, cfg: NvencHevcConfig): Buffer;
664
+
665
+ /** Alpha SPS: sps_seq_parameter_set_id 0 → 1. */
666
+ export declare function rewriteAlphaSps(sps: Buffer): Buffer;
667
+
604
668
  /** Rewrite nuh_layer_id in a NAL unit (returns copy). */
605
669
  export declare function rewriteNalLayerId(nal: Buffer, layerId: number): Buffer;
606
670
 
671
+ /** Rewrite nal_unit_type in a NAL unit (returns copy). */
672
+ export declare function rewriteNalType(nal: Buffer, newType: number): Buffer;
673
+
607
674
  export declare function runElectronApp({ args }: RunElectronAppOptions): Promise<ProcessHandle>;
608
675
 
609
676
  export declare interface RunElectronAppOptions {
@@ -614,11 +681,9 @@ export declare function send(cdp: Debugger, method: string, params?: object): Pr
614
681
 
615
682
  export declare function setInterceptor({ source, window, useInnerProxy }: NetworkOptions): void;
616
683
 
617
- export declare function setupAudioCapture({ encoder, getVideoTimeMs, onError, }: AudioCaptureOptions): Promise<AudioCapture>;
618
-
619
684
  export declare function setupPupProtocol(): void;
620
685
 
621
- export declare function shoot(writer: IpcWriter, source: string, options: RenderOptions): Promise<IpcDonePayload>;
686
+ export declare function shoot(options: IPCRenderOptions): Promise<IpcDonePayload>;
622
687
 
623
688
  export declare type SinkKind = "mp4" | "webm";
624
689
 
@@ -644,13 +709,13 @@ export declare function splitNalUnits(bitstream: Buffer): NalUnit[];
644
709
 
645
710
  export declare function startElectronCrashReporter(): void;
646
711
 
647
- export declare function startStego(cdp: Debugger): Promise<void>;
712
+ export declare function startStego(cdp: Debugger): Promise<unknown>;
648
713
 
649
714
  export declare const STEGO_TICK_CHANNEL = "stego-tick";
650
715
 
651
- export declare function stopStego(cdp: Debugger): Promise<void>;
716
+ export declare function stopStego(cdp: Debugger): Promise<unknown>;
652
717
 
653
- export declare function swapBuffer(cdp: Debugger, expected: number): Promise<void>;
718
+ export declare function swapBuffer(wc: WebContents, expected: number, interval: number): Promise<void>;
654
719
 
655
720
  export declare function tick(frame: WebFrameMain | undefined, timestampMs: number): Promise<void>;
656
721
 
@@ -742,12 +807,15 @@ export declare interface WaitOptions {
742
807
  onTimeout?: () => void;
743
808
  }
744
809
 
810
+ export declare type WindowCreatedCallback = (window: BrowserWindow) => void | Promise<void>;
811
+
745
812
  export declare interface WindowOptions {
746
813
  source: string;
747
- onCreated?: (window: BrowserWindow) => Promise<void>;
748
- renderer: RenderOptions;
749
- warmup?: boolean;
814
+ renderer: IPCRenderOptions;
750
815
  tolerant?: boolean;
816
+ preload?: string;
817
+ onCreated?: WindowCreatedCallback;
818
+ signal?: AbortSignal;
751
819
  }
752
820
 
753
821
  declare function withTimeout<T>(p: Promise<T>, ms: number, label: string): Promise<T>;