Skip to content

Commit f6388a5

Browse files
committed
Refactor media options types to unify Demuxer and Muxer configurations
1 parent 2e6d1d7 commit f6388a5

File tree

6 files changed

+45
-42
lines changed

6 files changed

+45
-42
lines changed

src/api/demuxer.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { StreamingUtils } from './utilities/streaming.js';
3535

3636
import type { AVMediaType, AVSeekFlag, AVSeekWhence } from '../constants/index.js';
3737
import type { Stream } from '../lib/stream.js';
38-
import type { IOInputCallbacks, MediaInputOptions, RawData, RTPMediaInput } from './types.js';
38+
import type { DemuxerOptions, IOInputCallbacks, RawData, RTPDemuxer } from './types.js';
3939

4040
/**
4141
* Per-stream timestamp processing state.
@@ -96,7 +96,7 @@ export class Demuxer implements AsyncDisposable, Disposable {
9696
private _streams: Stream[] = [];
9797
private ioContext?: IOContext;
9898
private isClosed = false;
99-
private options: Required<MediaInputOptions>;
99+
private options: Required<DemuxerOptions>;
100100

101101
// Timestamp processing state (per-stream)
102102
private streamStates = new Map<number, StreamState>();
@@ -122,7 +122,7 @@ export class Demuxer implements AsyncDisposable, Disposable {
122122
*
123123
* @internal
124124
*/
125-
private constructor(formatContext: FormatContext, options: Required<MediaInputOptions>, ioContext?: IOContext) {
125+
private constructor(formatContext: FormatContext, options: Required<DemuxerOptions>, ioContext?: IOContext) {
126126
this.formatContext = formatContext;
127127
this.ioContext = ioContext;
128128
this._streams = formatContext.streams ?? [];
@@ -382,18 +382,18 @@ export class Demuxer implements AsyncDisposable, Disposable {
382382
* });
383383
* ```
384384
*
385-
* @see {@link MediaInputOptions} For configuration options
385+
* @see {@link DemuxerOptions} For configuration options
386386
* @see {@link RawData} For raw data input
387387
* @see {@link IOInputCallbacks} For custom I/O interface
388388
*/
389-
static async open(input: string | Buffer, options?: MediaInputOptions): Promise<Demuxer>;
390-
static async open(input: IOInputCallbacks, options: (MediaInputOptions | undefined) & { format: string }): Promise<Demuxer>;
391-
static async open(rawData: RawData, options?: MediaInputOptions): Promise<Demuxer>;
392-
static async open(input: string | Buffer | RawData | IOInputCallbacks, options: MediaInputOptions = {}): Promise<Demuxer> {
389+
static async open(input: string | Buffer, options?: DemuxerOptions): Promise<Demuxer>;
390+
static async open(input: IOInputCallbacks, options: (DemuxerOptions | undefined) & { format: string }): Promise<Demuxer>;
391+
static async open(rawData: RawData, options?: DemuxerOptions): Promise<Demuxer>;
392+
static async open(input: string | Buffer | RawData | IOInputCallbacks, options: DemuxerOptions = {}): Promise<Demuxer> {
393393
// Check if input is raw data
394394
if (typeof input === 'object' && 'type' in input && ('width' in input || 'sampleRate' in input)) {
395395
// Build options for raw data
396-
const rawOptions: MediaInputOptions & { format: string } = {
396+
const rawOptions: DemuxerOptions & { format: string } = {
397397
bufferSize: options.bufferSize,
398398
format: options.format ?? (input.type === 'video' ? 'rawvideo' : 's16le'),
399399
options: {
@@ -513,7 +513,7 @@ export class Demuxer implements AsyncDisposable, Disposable {
513513
}
514514

515515
// Apply defaults to options
516-
const fullOptions: Required<MediaInputOptions> = {
516+
const fullOptions: Required<DemuxerOptions> = {
517517
bufferSize,
518518
format: options.format ?? '',
519519
skipStreamInfo: options.skipStreamInfo ?? false,
@@ -614,14 +614,14 @@ export class Demuxer implements AsyncDisposable, Disposable {
614614
* @see {@link open} For async version
615615
* @see {@link IOInputCallbacks} For custom I/O interface
616616
*/
617-
static openSync(input: string | Buffer, options?: MediaInputOptions): Demuxer;
618-
static openSync(input: IOInputCallbacks, options: (MediaInputOptions | undefined) & { format: string }): Demuxer;
619-
static openSync(rawData: RawData, options?: MediaInputOptions): Demuxer;
620-
static openSync(input: string | Buffer | RawData | IOInputCallbacks, options: MediaInputOptions = {}): Demuxer {
617+
static openSync(input: string | Buffer, options?: DemuxerOptions): Demuxer;
618+
static openSync(input: IOInputCallbacks, options: (DemuxerOptions | undefined) & { format: string }): Demuxer;
619+
static openSync(rawData: RawData, options?: DemuxerOptions): Demuxer;
620+
static openSync(input: string | Buffer | RawData | IOInputCallbacks, options: DemuxerOptions = {}): Demuxer {
621621
// Check if input is raw data
622622
if (typeof input === 'object' && 'type' in input && ('width' in input || 'sampleRate' in input)) {
623623
// Build options for raw data
624-
const rawOptions: MediaInputOptions & { format: string } = {
624+
const rawOptions: DemuxerOptions & { format: string } = {
625625
bufferSize: options.bufferSize,
626626
format: options.format ?? (input.type === 'video' ? 'rawvideo' : 's16le'),
627627
options: {
@@ -727,7 +727,7 @@ export class Demuxer implements AsyncDisposable, Disposable {
727727
}
728728

729729
// Apply defaults to options
730-
const fullOptions: Required<MediaInputOptions> = {
730+
const fullOptions: Required<DemuxerOptions> = {
731731
bufferSize,
732732
format: options.format ?? '',
733733
skipStreamInfo: options.skipStreamInfo ?? false,
@@ -808,7 +808,7 @@ export class Demuxer implements AsyncDisposable, Disposable {
808808
*
809809
* @see {@link StreamingUtils.createInputSDP} to generate SDP content.
810810
*/
811-
static async openSDP(sdpContent: string): Promise<RTPMediaInput> {
811+
static async openSDP(sdpContent: string): Promise<RTPDemuxer> {
812812
// Extract all ports from SDP (supports multi-stream: video + audio)
813813
const ports = StreamingUtils.extractPortsFromSDP(sdpContent);
814814
if (ports.length === 0) {
@@ -933,7 +933,7 @@ export class Demuxer implements AsyncDisposable, Disposable {
933933
* @see {@link StreamingUtils.createInputSDP} to generate SDP content.
934934
* @see {@link openSDP} For async version
935935
*/
936-
static openSDPSync(sdpContent: string): RTPMediaInput {
936+
static openSDPSync(sdpContent: string): RTPDemuxer {
937937
// Extract all ports from SDP (supports multi-stream: video + audio)
938938
const ports = StreamingUtils.extractPortsFromSDP(sdpContent);
939939
if (ports.length === 0) {

src/api/fmp4-stream.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { pipeline } from './pipeline.js';
2222

2323
import type { AVCodecID, AVHWDeviceType, FFHWDeviceType } from '../constants/index.js';
2424
import type { PipelineControl } from './pipeline.js';
25-
import type { EncoderOptions, IOOutputCallbacks, MediaInputOptions } from './types.js';
25+
import type { DemuxerOptions, EncoderOptions, IOOutputCallbacks } from './types.js';
2626

2727
export type MP4BoxType =
2828
// Top-level structure
@@ -148,7 +148,7 @@ export interface FMP4StreamOptions {
148148
/**
149149
* Input media options passed to Demuxer.
150150
*/
151-
inputOptions?: MediaInputOptions;
151+
inputOptions?: DemuxerOptions;
152152

153153
/**
154154
* Buffer size for I/O operations in bytes (output).
@@ -231,7 +231,7 @@ export const FMP4_CODECS = {
231231
export class FMP4Stream {
232232
private options: Required<FMP4StreamOptions>;
233233
private inputUrl: string;
234-
private inputOptions: MediaInputOptions;
234+
private inputOptions: DemuxerOptions;
235235
private input?: Demuxer;
236236
private output?: Muxer;
237237
private hardwareContext?: HardwareContext | null;

src/api/io-stream.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IOContext } from '../lib/index.js';
33
import { IO_BUFFER_SIZE } from './constants.js';
44

55
import type { AVSeekWhence } from '../constants/index.js';
6-
import type { IOInputCallbacks, MediaInputOptions } from './types.js';
6+
import type { DemuxerOptions, IOInputCallbacks } from './types.js';
77

88
/**
99
* Factory for creating custom I/O contexts.
@@ -67,7 +67,7 @@ export class IOStream {
6767
* });
6868
* ```
6969
*/
70-
static create(buffer: Buffer, options?: MediaInputOptions): IOContext;
70+
static create(buffer: Buffer, options?: DemuxerOptions): IOContext;
7171
/**
7272
* Create I/O context from callbacks.
7373
*
@@ -94,8 +94,8 @@ export class IOStream {
9494
* });
9595
* ```
9696
*/
97-
static create(callbacks: IOInputCallbacks, options?: MediaInputOptions): IOContext;
98-
static create(input: Buffer | IOInputCallbacks, options: MediaInputOptions = {}): IOContext | Promise<IOContext> {
97+
static create(callbacks: IOInputCallbacks, options?: DemuxerOptions): IOContext;
98+
static create(input: Buffer | IOInputCallbacks, options: DemuxerOptions = {}): IOContext | Promise<IOContext> {
9999
const { bufferSize = IO_BUFFER_SIZE } = options;
100100

101101
// Handle Buffer

src/api/muxer.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { Encoder } from './encoder.js';
3131
import { AsyncQueue } from './utilities/async-queue.js';
3232

3333
import type { IRational, OutputFormat, Stream } from '../lib/index.js';
34-
import type { IOOutputCallbacks, MediaOutputOptions } from './types.js';
34+
import type { IOOutputCallbacks, MuxerOptions } from './types.js';
3535

3636
export interface AddStreamOptionsWithEncoder {
3737
encoder?: Encoder;
@@ -114,7 +114,7 @@ interface WriteJob {
114114
*/
115115
export class Muxer implements AsyncDisposable, Disposable {
116116
private formatContext: FormatContext;
117-
private options: MediaOutputOptions;
117+
private options: MuxerOptions;
118118
private _streams = new Map<number, StreamDescription>();
119119
private ioContext?: IOContext;
120120
private headerWritten = false;
@@ -132,7 +132,7 @@ export class Muxer implements AsyncDisposable, Disposable {
132132
*
133133
* @internal
134134
*/
135-
private constructor(options?: MediaOutputOptions) {
135+
private constructor(options?: MuxerOptions) {
136136
this.options = {
137137
copyInitialNonkeyframes: false,
138138
exitOnError: true,
@@ -197,12 +197,12 @@ export class Muxer implements AsyncDisposable, Disposable {
197197
* });
198198
* ```
199199
*
200-
* @see {@link MediaOutputOptions} For configuration options
200+
* @see {@link MuxerOptions} For configuration options
201201
* @see {@link IOOutputCallbacks} For custom I/O interface
202202
*/
203-
static async open(target: string, options?: MediaOutputOptions): Promise<Muxer>;
204-
static async open(target: IOOutputCallbacks, options: MediaOutputOptions & { format: string }): Promise<Muxer>;
205-
static async open(target: string | IOOutputCallbacks, options?: MediaOutputOptions): Promise<Muxer> {
203+
static async open(target: string, options?: MuxerOptions): Promise<Muxer>;
204+
static async open(target: IOOutputCallbacks, options: MuxerOptions & { format: string }): Promise<Muxer>;
205+
static async open(target: string | IOOutputCallbacks, options?: MuxerOptions): Promise<Muxer> {
206206
const output = new Muxer(options);
207207

208208
try {
@@ -328,9 +328,9 @@ export class Muxer implements AsyncDisposable, Disposable {
328328
*
329329
* @see {@link open} For async version
330330
*/
331-
static openSync(target: string, options?: MediaOutputOptions): Muxer;
332-
static openSync(target: IOOutputCallbacks, options: MediaOutputOptions & { format: string }): Muxer;
333-
static openSync(target: string | IOOutputCallbacks, options?: MediaOutputOptions): Muxer {
331+
static openSync(target: string, options?: MuxerOptions): Muxer;
332+
static openSync(target: IOOutputCallbacks, options: MuxerOptions & { format: string }): Muxer;
333+
static openSync(target: string | IOOutputCallbacks, options?: MuxerOptions): Muxer {
334334
const output = new Muxer(options);
335335

336336
try {

src/api/rtp-stream.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { pipeline } from './pipeline.js';
1515

1616
import type { AVCodecID, AVHWDeviceType, AVSampleFormat, FFAudioEncoder, FFHWDeviceType, FFVideoEncoder } from '../constants/index.js';
1717
import type { PipelineControl } from './pipeline.js';
18-
import type { EncoderOptions, MediaInputOptions } from './types.js';
18+
import type { DemuxerOptions, EncoderOptions } from './types.js';
1919

2020
/**
2121
* Options for configuring RTP streaming.
@@ -71,7 +71,7 @@ export interface RTPStreamOptions {
7171
/**
7272
* Input media options passed to Demuxer.
7373
*/
74-
inputOptions?: MediaInputOptions;
74+
inputOptions?: DemuxerOptions;
7575

7676
/**
7777
* Video stream configuration.
@@ -133,7 +133,7 @@ export interface RTPStreamOptions {
133133
export class RTPStream {
134134
private options: Required<RTPStreamOptions>;
135135
private inputUrl: string;
136-
private inputOptions: MediaInputOptions;
136+
private inputOptions: DemuxerOptions;
137137
private input?: Demuxer;
138138
private videoOutput?: Muxer;
139139
private audioOutput?: Muxer;

src/api/types.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export type RawData = VideoRawData | AudioRawData;
120120
* Configures how media files are opened and packets are read.
121121
* Supports format detection, buffering, and FFmpeg options.
122122
*/
123-
export interface MediaInputOptions {
123+
export interface DemuxerOptions {
124124
/**
125125
* Buffer size for reading/writing operations.
126126
*
@@ -211,7 +211,7 @@ export interface MediaInputOptions {
211211
*
212212
* Configures output container format and buffering.
213213
*/
214-
export interface MediaOutputOptions {
214+
export interface MuxerOptions {
215215
/**
216216
* Input media for automatic metadata and property copying.
217217
*
@@ -223,7 +223,7 @@ export interface MediaOutputOptions {
223223
*
224224
* This matches FFmpeg CLI behavior which copies metadata by default.
225225
*/
226-
input?: Demuxer | RTPMediaInput;
226+
input?: Demuxer | RTPDemuxer;
227227

228228
/**
229229
* Preferred output format.
@@ -727,7 +727,10 @@ export interface IOOutputCallbacks {
727727
read?: (size: number) => Buffer | null | number;
728728
}
729729

730-
export interface RTPMediaInput {
730+
/**
731+
* RTP Demuxer interface.
732+
*/
733+
export interface RTPDemuxer {
731734
/**
732735
* Demuxer configured for RTP/SRTP reception.
733736
*

0 commit comments

Comments
 (0)