@meframe/core 0.0.6 → 0.0.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/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +1 -0
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/types.d.ts +1 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/orchestrator/Orchestrator.d.ts +0 -1
- package/dist/orchestrator/Orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/Orchestrator.js +24 -37
- package/dist/orchestrator/Orchestrator.js.map +1 -1
- package/dist/orchestrator/VideoClipSession.d.ts +1 -0
- package/dist/orchestrator/VideoClipSession.d.ts.map +1 -1
- package/dist/orchestrator/VideoClipSession.js +96 -82
- package/dist/orchestrator/VideoClipSession.js.map +1 -1
- package/dist/stages/compose/GlobalAudioSession.d.ts.map +1 -1
- package/dist/stages/compose/GlobalAudioSession.js +11 -3
- package/dist/stages/compose/GlobalAudioSession.js.map +1 -1
- package/dist/stages/load/ResourceLoader.js +1 -1
- package/dist/stages/load/ResourceLoader.js.map +1 -1
- package/dist/worker/WorkerPool.d.ts.map +1 -1
- package/dist/worker/WorkerPool.js +6 -2
- package/dist/worker/WorkerPool.js.map +1 -1
- package/dist/worker/types.d.ts +1 -1
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/types.js.map +1 -1
- package/dist/worker/worker-event-whitelist.d.ts.map +1 -1
- package/dist/workers/BaseDecoder.js +130 -0
- package/dist/workers/BaseDecoder.js.map +1 -0
- package/dist/workers/WorkerChannel.js.map +1 -1
- package/dist/workers/stages/compose/video-compose.worker.js +13 -9
- package/dist/workers/stages/compose/video-compose.worker.js.map +1 -1
- package/dist/workers/stages/decode/audio-decode.worker.js +243 -0
- package/dist/workers/stages/decode/audio-decode.worker.js.map +1 -0
- package/dist/workers/stages/decode/video-decode.worker.js +346 -0
- package/dist/workers/stages/decode/video-decode.worker.js.map +1 -0
- package/dist/workers/stages/encode/video-encode.worker.js +340 -0
- package/dist/workers/stages/encode/video-encode.worker.js.map +1 -0
- package/package.json +1 -1
- package/dist/workers/stages/decode/decode.worker.js +0 -826
- package/dist/workers/stages/decode/decode.worker.js.map +0 -1
- package/dist/workers/stages/encode/encode.worker.js +0 -547
- package/dist/workers/stages/encode/encode.worker.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decode.worker.js","sources":["../../../../src/stages/decode/BaseDecoder.ts","../../../../src/stages/decode/VideoChunkDecoder.ts","../../../../src/stages/decode/AudioChunkDecoder.ts","../../../../src/stages/decode/decode.worker.ts"],"sourcesContent":["/**\n * Base decoder class abstracting common WebCodecs decoder workflow.\n * Mirrors BaseEncoder but for decoding path.\n */\nimport { AudioDecoderConfig, DecodedVideoFrame, VideoDecoderConfig } from './types';\n\nexport abstract class BaseDecoder<\n TDecoder extends VideoDecoder | AudioDecoder,\n TConfig extends VideoDecoderConfig | AudioDecoderConfig,\n TInput extends EncodedVideoChunk | EncodedAudioChunk,\n TOutput extends VideoFrame | AudioData | DecodedVideoFrame,\n> {\n protected decoder?: TDecoder;\n protected config: TConfig;\n protected controller: TransformStreamDefaultController<TOutput> | null = null;\n\n constructor(config: TConfig) {\n this.config = config;\n }\n\n async initialize(): Promise<void> {\n if (this.decoder?.state === 'configured') {\n return;\n }\n const isSupported = await this.isConfigSupported(this.config);\n if (!isSupported.supported) {\n throw new Error(\n `Codec not supported: ${(this.config as any).codecString || (this.config as any).codec}`\n );\n }\n\n this.decoder = this.createDecoder({\n output: this.handleOutput.bind(this),\n error: this.handleError.bind(this),\n });\n\n await this.configureDecoder(this.config);\n }\n\n async reconfigure(config: Partial<TConfig>): Promise<void> {\n this.config = { ...this.config, ...config } as TConfig;\n\n if (!this.decoder) {\n await this.initialize();\n return;\n }\n\n // Flush before reconfiguring\n if (this.decoder.state === 'configured') {\n await this.decoder.flush();\n }\n\n const isSupported = await this.isConfigSupported(this.config);\n if (!isSupported.supported) {\n throw new Error(\n `New configuration not supported: ${(this.config as any).codecString || (this.config as any).codec}`\n );\n }\n\n await this.configureDecoder(this.config);\n }\n\n async flush(): Promise<void> {\n if (!this.decoder) return;\n await this.decoder.flush();\n }\n\n async reset(): Promise<void> {\n if (!this.decoder) return;\n this.decoder.reset();\n this.onReset();\n }\n\n async close(): Promise<void> {\n if (!this.decoder) return;\n\n if (this.decoder.state === 'configured') {\n await this.decoder.flush();\n }\n\n this.decoder.close();\n this.decoder = undefined;\n }\n\n get isReady(): boolean {\n return this.decoder?.state === 'configured';\n }\n\n get queueSize(): number {\n return (this.decoder as any)?.decodeQueueSize ?? 0;\n }\n\n protected handleOutput(data: TOutput): void {\n if (!this.controller) {\n this.closeIfPossible(data);\n return;\n }\n\n try {\n this.controller.enqueue(data);\n } catch (error) {\n if (\n error instanceof TypeError &&\n /Cannot enqueue a chunk into a readable stream that is closed/.test(error.message)\n ) {\n this.closeIfPossible(data);\n return;\n }\n\n throw error;\n }\n }\n\n protected handleError(error: DOMException): void {\n console.error(`${this.getDecoderType()} decoder error:`, error);\n this.controller?.error(error);\n }\n\n private closeIfPossible(data: TOutput): void {\n (data as any)?.close?.();\n (data as DecodedVideoFrame)?.frame?.close?.();\n }\n\n // Abstracts\n protected abstract isConfigSupported(config: TConfig): Promise<{ supported: boolean }>;\n protected abstract createDecoder(init: DecoderInit): TDecoder;\n protected abstract configureDecoder(config: TConfig): Promise<void>;\n protected abstract getDecoderType(): string;\n protected abstract decode(input: TInput): void;\n protected onReset(): void {}\n\n // Backpressure\n protected abstract readonly highWaterMark: number;\n protected abstract readonly decodeQueueThreshold: number;\n\n createStream(): TransformStream<TInput, TOutput> {\n return new TransformStream<TInput, TOutput>(\n {\n start: async (controller) => {\n this.controller = controller;\n if (!this.isReady) {\n await this.initialize();\n }\n },\n transform: async (input) => {\n if (!this.decoder || this.decoder.state !== 'configured') {\n throw new Error('Decoder not configured');\n }\n // backpressure\n if ((this.decoder as any).decodeQueueSize >= this.decodeQueueThreshold) {\n await new Promise<void>((resolve) => {\n const check = () => {\n if (\n !this.decoder ||\n (this.decoder as any).decodeQueueSize < this.decodeQueueThreshold - 1\n ) {\n resolve();\n } else {\n setTimeout(check, 10);\n }\n };\n check();\n });\n }\n this.decode(input);\n },\n flush: async () => {\n await this.flush();\n },\n },\n {\n highWaterMark: this.highWaterMark,\n size: () => 1,\n }\n );\n }\n}\n\ninterface DecoderInit {\n output: (data: any) => void;\n error: (error: DOMException) => void;\n}\n","import { VideoDecoderConfig } from './types';\nimport { BaseDecoder } from './BaseDecoder';\n\n/**\n * Video decoder with GOP tracking\n * Tracks keyframe boundaries and attaches GOP metadata to decoded frames\n */\nexport class VideoChunkDecoder extends BaseDecoder<\n VideoDecoder,\n VideoDecoderConfig,\n EncodedVideoChunk,\n VideoFrame\n> {\n private static readonly DEFAULT_HIGH_WATER_MARK = 4;\n private static readonly DEFAULT_DECODE_QUEUE_THRESHOLD = 16;\n\n readonly trackId: string;\n\n protected readonly highWaterMark: number;\n protected readonly decodeQueueThreshold: number;\n\n // GOP tracking (serial is derived from keyframe timestamp for idempotency)\n private currentGopSerial = -1;\n private isCurrentFrameKeyframe = false;\n\n // Buffering support for delayed configuration\n private bufferedChunks: EncodedVideoChunk[] = [];\n private isProcessingBuffer: boolean = false;\n\n constructor(trackId: string, config?: Partial<VideoDecoderConfig>) {\n super((config || {}) as VideoDecoderConfig);\n\n this.trackId = trackId;\n this.highWaterMark =\n config?.backpressure?.highWaterMark ?? VideoChunkDecoder.DEFAULT_HIGH_WATER_MARK;\n this.decodeQueueThreshold =\n config?.backpressure?.decodeQueueThreshold ??\n VideoChunkDecoder.DEFAULT_DECODE_QUEUE_THRESHOLD;\n }\n\n // Computed properties\n get isConfigured(): boolean {\n return this.isReady;\n }\n\n get state(): string {\n return this.decoder?.state || 'unconfigured';\n }\n\n /**\n * Update configuration - can be called before or after initialization\n */\n async updateConfig(config: Partial<VideoDecoderConfig>): Promise<void> {\n if (!this.isReady && config.codec) {\n await this.configure(config as VideoDecoderConfig);\n await this.processBufferedChunks();\n }\n }\n\n // Override createStream to handle GOP tracking and buffering\n // Always create new stream for each clip (ReadableStreams can only be consumed once)\n override createStream(): TransformStream<EncodedVideoChunk, VideoFrame> {\n return new TransformStream<EncodedVideoChunk, VideoFrame>(\n {\n start: async (controller) => {\n this.controller = controller;\n // Don't initialize if no codec config yet\n if (this.config?.codec && this.config?.description && !this.isReady) {\n await this.initialize();\n }\n },\n\n transform: async (chunk) => {\n // If not configured yet, buffer the chunk\n if (!this.isReady) {\n this.bufferedChunks.push(chunk);\n return; // Don't process yet\n }\n\n // If we're processing buffered chunks, add to buffer to maintain order\n if (this.isProcessingBuffer) {\n this.bufferedChunks.push(chunk);\n return;\n }\n\n // Normal processing\n await this.processChunk(chunk);\n },\n\n flush: async () => {\n if (this.isReady) {\n await this.flush();\n }\n },\n },\n {\n highWaterMark: this.highWaterMark,\n size: () => 1,\n }\n );\n }\n\n /**\n * Process a single chunk (extracted from transform for reuse)\n */\n private async processChunk(chunk: EncodedVideoChunk): Promise<void> {\n if (!this.decoder) {\n throw new Error('Decoder not initialized');\n }\n\n if (this.decoder.state !== 'configured') {\n console.error('[VideoChunkDecoder] Decoder in unexpected state:', this.decoder.state);\n throw new Error(`Decoder not configured, state: ${this.decoder.state}`);\n }\n\n // Track GOP boundaries\n if (chunk.type === 'key') {\n this.handleKeyFrame(chunk.timestamp);\n }\n\n // Check decoder queue pressure\n if (this.decoder.decodeQueueSize >= this.decodeQueueThreshold) {\n await new Promise<void>((resolve) => {\n const check = () => {\n if (!this.decoder || this.decoder.decodeQueueSize < this.decodeQueueThreshold - 1) {\n resolve();\n } else {\n setTimeout(check, 20);\n }\n };\n check();\n });\n }\n\n // Decode the chunk\n try {\n this.decode(chunk);\n } catch (error) {\n console.error(`[VideoChunkDecoder] decode error:`, error);\n throw error; // Re-throw to propagate\n }\n }\n\n // Override handleOutput to attach GOP metadata\n protected override handleOutput(frame: VideoFrame): void {\n // Wrap frame with GOP metadata as a plain object\n // The frame itself will be transferred, but metadata travels separately\n const wrappedFrame = {\n frame,\n gopSerial: this.currentGopSerial,\n isKeyframe: this.isCurrentFrameKeyframe,\n timestamp: frame.timestamp,\n };\n\n // Reset keyframe flag for subsequent frames\n this.isCurrentFrameKeyframe = false;\n\n // Call parent to enqueue wrapped frame\n super.handleOutput(wrappedFrame as any);\n }\n\n // Implement abstract methods\n protected async isConfigSupported(config: VideoDecoderConfig): Promise<{ supported: boolean }> {\n const result = await VideoDecoder.isConfigSupported({\n codec: config.codec,\n codedWidth: config.width,\n codedHeight: config.height,\n });\n return { supported: result.supported ?? false };\n }\n\n protected createDecoder(init: {\n output: (frame: VideoFrame) => void;\n error: (error: DOMException) => void;\n }): VideoDecoder {\n return new VideoDecoder(init);\n }\n\n protected getDecoderType(): string {\n return 'Video';\n }\n\n protected async configureDecoder(config: VideoDecoderConfig): Promise<void> {\n if (!this.decoder) return;\n\n const decoderConfig = {\n codec: config.codec,\n codedWidth: config.width,\n codedHeight: config.height,\n hardwareAcceleration: config.hardwareAcceleration || 'no-preference',\n optimizeForLatency: false,\n ...(config.description && { description: config.description }),\n ...(config.displayAspectWidth && { displayAspectWidth: config.displayAspectWidth }),\n ...(config.displayAspectHeight && { displayAspectHeight: config.displayAspectHeight }),\n };\n\n this.decoder.configure(decoderConfig as any);\n // console.log('[VideoChunkDecoder] Decoder configured, state:', this.decoder.state);\n }\n\n protected decode(chunk: EncodedVideoChunk): void {\n this.decoder?.decode(chunk);\n }\n\n // Override reset to clear GOP data\n protected override onReset(): void {\n this.currentGopSerial = -1;\n this.isCurrentFrameKeyframe = false;\n }\n\n // GOP management methods\n private handleKeyFrame(timestamp: number): void {\n // Use timestamp as gopSerial for idempotency (same keyframe = same serial)\n this.currentGopSerial = timestamp;\n this.isCurrentFrameKeyframe = true;\n }\n\n /**\n * Configure the decoder with codec info (can be called after creation)\n */\n async configure(config: VideoDecoderConfig): Promise<void> {\n // console.log('[VideoChunkDecoder] Configuring with:', config);\n\n if (this.isReady) {\n // If already configured, reconfigure\n await this.reconfigure(config);\n return;\n }\n\n this.config = config as any;\n\n // Initialize decoder with new config\n await this.initialize();\n }\n\n /**\n * Process any buffered chunks after configuration\n */\n async processBufferedChunks(): Promise<void> {\n if (!this.isReady || this.bufferedChunks.length === 0) {\n return;\n }\n\n // console.log('[VideoChunkDecoder] Processing', this.bufferedChunks.length, 'buffered chunks');\n this.isProcessingBuffer = true;\n\n // Process buffered chunks in order\n const chunks = [...this.bufferedChunks];\n this.bufferedChunks = [];\n\n for (const chunk of chunks) {\n try {\n await this.processChunk(chunk);\n } catch (error) {\n console.error('[VideoChunkDecoder] Error processing buffered chunk:', error);\n }\n }\n\n this.isProcessingBuffer = false;\n\n // Process any new chunks that arrived while processing buffer\n if (this.bufferedChunks.length > 0) {\n await this.processBufferedChunks();\n }\n }\n\n // Override close to clean up GOP data\n override async close(): Promise<void> {\n // Clear buffered chunks\n this.bufferedChunks = [];\n\n // Clean up GOP data first\n this.onReset();\n\n // Call parent close\n await super.close();\n }\n}\n","import { AudioDecoderConfig } from './types';\nimport { BaseDecoder } from './BaseDecoder';\n\n/**\n * Audio decoder with streaming support\n * Extends BaseDecoder for common WebCodecs operations\n */\nexport class AudioChunkDecoder extends BaseDecoder<\n AudioDecoder,\n AudioDecoderConfig,\n EncodedAudioChunk,\n AudioData\n> {\n // Default values\n private static readonly DEFAULT_HIGH_WATER_MARK = 20;\n private static readonly DEFAULT_DECODE_QUEUE_THRESHOLD = 16;\n\n // Exposed properties\n readonly trackId: string;\n\n // Backpressure configuration\n protected readonly highWaterMark: number;\n protected readonly decodeQueueThreshold: number;\n\n constructor(trackId: string, config?: Partial<AudioDecoderConfig>) {\n // Initialize with empty config, will be configured later\n super(config as AudioDecoderConfig);\n\n this.trackId = trackId;\n\n // Set backpressure configuration\n this.highWaterMark =\n config?.backpressure?.highWaterMark ?? AudioChunkDecoder.DEFAULT_HIGH_WATER_MARK;\n this.decodeQueueThreshold = AudioChunkDecoder.DEFAULT_DECODE_QUEUE_THRESHOLD;\n }\n\n // Computed properties\n get isConfigured(): boolean {\n return this.isReady;\n }\n\n get state(): string {\n return this.decoder?.state || 'unconfigured';\n }\n\n /**\n * Update configuration - can be called before or after initialization\n */\n async updateConfig(config: Partial<AudioDecoderConfig>): Promise<void> {\n // If decoder is not ready and we have codec info, configure it\n if (!this.isReady && config.codec) {\n await this.configure(config as AudioDecoderConfig);\n await this.processBufferedChunks();\n return;\n }\n\n // Note: AudioDecoder doesn't have many runtime-configurable options\n // Backpressure settings are readonly in this implementation\n // if (config.backpressure) {\n // console.warn('Backpressure settings cannot be changed at runtime');\n // }\n }\n\n // Implement abstract methods\n protected async isConfigSupported(config: AudioDecoderConfig): Promise<{ supported: boolean }> {\n const result = await AudioDecoder.isConfigSupported({\n codec: config.codec,\n sampleRate: config.sampleRate,\n numberOfChannels: config.numberOfChannels,\n });\n return { supported: result.supported ?? false };\n }\n\n protected createDecoder(init: {\n output: (data: AudioData) => void;\n error: (error: DOMException) => void;\n }): AudioDecoder {\n return new AudioDecoder(init);\n }\n\n protected getDecoderType(): string {\n return 'Audio';\n }\n\n protected async configureDecoder(config: AudioDecoderConfig): Promise<void> {\n if (!this.decoder) return;\n\n await this.decoder.configure({\n codec: config.codec,\n sampleRate: config.sampleRate,\n numberOfChannels: config.numberOfChannels,\n ...(config.description && { description: config.description }),\n });\n }\n\n protected decode(chunk: EncodedAudioChunk): void {\n this.decoder?.decode(chunk);\n }\n\n /**\n * Configure the decoder with codec info (can be called after creation)\n */\n async configure(config: AudioDecoderConfig): Promise<void> {\n if (this.isReady) {\n // If already configured, reconfigure\n await this.reconfigure(config);\n return;\n }\n\n this.config = config as any;\n\n // Initialize decoder with new config\n await this.initialize();\n }\n\n /**\n * Process any buffered chunks after configuration\n * Note: Audio doesn't buffer in current implementation, but keeping for interface consistency\n */\n async processBufferedChunks(): Promise<void> {\n // No-op for audio in current implementation\n }\n}\n","import { WorkerChannel } from '../../worker/WorkerChannel';\nimport { WorkerMessageType, WorkerState } from '../../worker/types';\nimport { VideoChunkDecoder } from './VideoChunkDecoder';\nimport { AudioChunkDecoder } from './AudioChunkDecoder';\nimport { VideoDecoderConfig, AudioDecoderConfig } from './types';\nimport type { AudioTrackConfig } from '../compose/types';\n\ninterface TrackMetadata {\n clipId: string;\n config: AudioTrackConfig;\n sampleRate?: number;\n numberOfChannels?: number;\n type: 'bgm' | 'voice' | 'sfx' | 'other';\n}\n\nconst normalizeDescription = (desc?: ArrayBuffer | ArrayBufferView): ArrayBuffer | undefined => {\n if (!desc) return undefined;\n\n if (desc instanceof ArrayBuffer) return desc;\n\n // Handle ArrayBufferView (Uint8Array, etc.)\n const view = desc as ArrayBufferView;\n return view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength) as ArrayBuffer;\n};\n\n/**\n * DecodeWorker - Third stage in the pipeline\n * Receives encoded chunks from DemuxWorkers and outputs decoded frames to ComposeWorker\n *\n * Pipeline: VideoDemuxWorker/AudioDemuxWorker → DecodeWorker → ComposeWorker\n *\n * Features:\n * - GOP-based caching for video (≤4 GOPs in memory)\n * - Stream-based processing with backpressure\n * - Direct streaming to ComposeWorker\n */\nexport class DecodeWorker {\n private channel: WorkerChannel;\n // Map of clipId -> decoder instance\n private videoDecoders = new Map<string, VideoChunkDecoder>();\n private audioDecoders = new Map<string, AudioChunkDecoder>();\n private registeredAudioTracks = new Set<string>();\n private deliveredAudioTracks = new Set<string>();\n private audioTrackMetadata = new Map<string, TrackMetadata>();\n\n /** Maximum number of active decoder pairs allowed at the same time */\n private static readonly MAX_ACTIVE_DECODERS = 8;\n\n // Cached default configs merged from orchestrator\n private defaultVideoConfig: Partial<VideoDecoderConfig> = {};\n private defaultAudioConfig: Partial<AudioDecoderConfig> = {};\n\n // Connections to other workers\n private composePorts = new Map<string, MessagePort>();\n private audioDownstreamPort: MessagePort | null = null;\n private demuxPorts = new Map<string, MessagePort>(); // Connections from demux workers\n\n constructor() {\n // Initialize WorkerChannel with MessagePort\n this.channel = new WorkerChannel(self as any, {\n name: 'DecodeWorker',\n timeout: 30000,\n });\n\n this.setupHandlers();\n }\n\n private setupHandlers(): void {\n // Register message handlers\n this.channel.registerHandler('configure', this.handleConfigure.bind(this));\n this.channel.registerHandler('connect' as any, this.handleConnect.bind(this));\n this.channel.registerHandler('flush', this.handleFlush.bind(this));\n this.channel.registerHandler('reset', this.handleReset.bind(this));\n this.channel.registerHandler('get_stats', this.handleGetStats.bind(this));\n this.channel.registerHandler(WorkerMessageType.Dispose, this.handleDispose.bind(this));\n }\n\n /**\n * Connect handler used by stream pipeline\n */\n private async handleConnect(payload: {\n direction: 'upstream' | 'downstream';\n port: MessagePort;\n streamType: 'video' | 'audio';\n sessionId?: string;\n clipStartUs?: number;\n clipDurationUs?: number;\n }): Promise<{ success: boolean }> {\n const { port, direction, sessionId } = payload;\n if (direction === 'upstream') {\n this.demuxPorts.set(sessionId || 'default', port);\n const channel = new WorkerChannel(port, {\n name: 'Demux-Decode',\n timeout: 30000,\n });\n channel.receiveStream((stream, metadata) => {\n this.handleReceiveStream(stream, {\n ...metadata,\n clipStartUs: payload.clipStartUs,\n clipDurationUs: payload.clipDurationUs,\n });\n });\n // Also register configure handler on upstream channel for codec info from demuxer\n channel.registerHandler('configure' as any, this.handleConfigure.bind(this));\n }\n if (direction === 'downstream') {\n if (payload.streamType === 'audio') {\n this.audioDownstreamPort?.close();\n this.audioDownstreamPort = port;\n } else {\n this.composePorts.set(sessionId || 'default', port);\n }\n }\n return { success: true };\n }\n\n /**\n * Handle configuration message from orchestrator\n * @param payload.initial - If true, initialize worker and recreate decoder instances; otherwise just update config\n */\n private async handleConfigure(payload: {\n config?: { video?: Partial<VideoDecoderConfig>; audio?: Partial<AudioDecoderConfig> };\n // Support direct codec info from demuxer\n sessionId?: string;\n streamType?: 'video' | 'audio';\n codec?: string;\n width?: number;\n height?: number;\n sampleRate?: number;\n numberOfChannels?: number;\n description?: ArrayBuffer | Uint8Array;\n }): Promise<{ success: boolean }> {\n // If this is codec info from demuxer (has sessionId and streamType)\n const {\n sessionId,\n streamType,\n codec,\n width,\n height,\n sampleRate,\n numberOfChannels,\n description,\n } = payload;\n if (sessionId && streamType) {\n try {\n if (streamType === 'video') {\n const decoder = this.videoDecoders.get(sessionId);\n if (decoder) {\n await decoder.updateConfig({\n codec,\n width,\n height,\n description: normalizeDescription(description),\n });\n }\n } else if (streamType === 'audio') {\n const decoder = this.audioDecoders.get(sessionId);\n if (decoder) {\n await decoder.updateConfig({\n codec,\n sampleRate,\n numberOfChannels,\n description: normalizeDescription(description),\n });\n }\n }\n } catch (error: any) {\n console.error('[DecodeWorker] Failed to configure decoder:', error);\n throw {\n code: 'CODEC_CONFIG_ERROR',\n message: error.message,\n };\n }\n return { success: true };\n }\n\n // Otherwise, this is a global config from orchestrator\n const { config } = payload;\n if (!config) {\n return { success: true };\n }\n\n // Ensure worker becomes ready once configured at least once\n this.channel.state = WorkerState.Ready;\n\n // Merge and cache default configs\n if (config.video) {\n Object.assign(this.defaultVideoConfig, config.video);\n }\n if (config.audio) {\n Object.assign(this.defaultAudioConfig, config.audio);\n }\n\n // Propagate updated config to existing decoders\n if (config.video) {\n for (const dec of this.videoDecoders.values()) {\n await dec.updateConfig(config.video);\n }\n }\n if (config.audio) {\n for (const dec of this.audioDecoders.values()) {\n await dec.updateConfig(config.audio);\n }\n }\n\n return { success: true };\n }\n\n private async handleReceiveStream(\n stream: ReadableStream,\n metadata?: Record<string, any>\n ): Promise<void> {\n const sessionId: string = metadata?.sessionId || 'default';\n const streamType = metadata?.streamType;\n\n if (streamType === 'video') {\n // For video, create decoder that will buffer chunks until configured\n const decoder = await this.getOrCreateDecoder('video', sessionId, metadata);\n const transform = decoder.createStream();\n\n // Forward decoded frames downstream if port exists\n const composePort = this.composePorts.get(sessionId);\n if (composePort) {\n const channel = new WorkerChannel(composePort, {\n name: 'Decode-Compose',\n timeout: 30000,\n });\n channel.sendStream(transform.readable as ReadableStream, {\n streamType: 'video',\n sessionId,\n });\n\n // Pipe encoded chunks into decoder (will buffer if not configured)\n stream\n .pipeTo(transform.writable)\n .catch((error) =>\n console.error('[DecodeWorker] Video stream pipe error:', sessionId, error)\n );\n }\n } else if (streamType === 'audio') {\n const decoder = await this.getOrCreateDecoder('audio', sessionId, metadata);\n const transform = decoder.createStream();\n stream.pipeTo(transform.writable).catch((error) => {\n console.error('[DecodeWorker] Audio stream pipe error:', error);\n });\n\n const trackId = metadata?.trackId ?? sessionId;\n await this.registerAudioTrack(trackId, sessionId, metadata);\n\n this.channel.sendStream(transform.readable as ReadableStream<AudioData>, {\n streamType: 'audio',\n sessionId,\n trackId,\n clipStartUs: metadata?.clipStartUs ?? 0,\n clipDurationUs: metadata?.clipDurationUs ?? 0,\n });\n\n this.deliveredAudioTracks.add(trackId);\n }\n }\n\n /**\n * Flush decoders\n */\n private async handleFlush(payload?: { type?: 'video' | 'audio' }): Promise<{ success: boolean }> {\n try {\n if (!payload?.type || payload.type === 'video') {\n for (const dec of this.videoDecoders.values()) {\n await dec.flush();\n }\n }\n if (!payload?.type || payload.type === 'audio') {\n for (const dec of this.audioDecoders.values()) {\n await dec.flush();\n }\n }\n\n return { success: true };\n } catch (error: any) {\n throw {\n code: 'FLUSH_ERROR',\n message: error.message,\n };\n }\n }\n\n /**\n * Reset decoders\n */\n private async handleReset(payload?: { type?: 'video' | 'audio' }): Promise<{ success: boolean }> {\n try {\n if (!payload?.type || payload.type === 'video') {\n for (const dec of this.videoDecoders.values()) {\n await dec.reset();\n }\n }\n if (!payload?.type || payload.type === 'audio') {\n for (const dec of this.audioDecoders.values()) {\n await dec.reset();\n }\n }\n\n // Notify reset complete\n this.channel.notify('reset_complete', {\n type: payload?.type || 'all',\n });\n\n return { success: true };\n } catch (error: any) {\n throw {\n code: 'RESET_ERROR',\n message: error.message,\n };\n }\n }\n\n /**\n * Get decoder statistics\n */\n private async handleGetStats(): Promise<{\n video?: any;\n audio?: any;\n }> {\n const stats: any = {};\n\n if (this.videoDecoders.size) {\n stats.video = Array.from(this.videoDecoders.entries()).map(([clipId, dec]) => ({\n clipId,\n configured: dec.isConfigured,\n queueSize: dec.queueSize,\n state: dec.state,\n }));\n }\n\n if (this.audioDecoders.size) {\n stats.audio = Array.from(this.audioDecoders.entries()).map(([clipId, dec]) => ({\n clipId,\n configured: dec.isConfigured,\n queueSize: dec.queueSize,\n state: dec.state,\n }));\n }\n\n return stats;\n }\n\n /**\n * Dispose worker and cleanup resources\n */\n private async handleDispose(): Promise<{ success: boolean }> {\n // Close all decoders\n for (const dec of this.videoDecoders.values()) {\n await dec.close();\n }\n for (const dec of this.audioDecoders.values()) {\n await dec.close();\n }\n\n this.videoDecoders.clear();\n this.audioDecoders.clear();\n\n // Close connections\n for (const port of this.composePorts.values()) {\n port.close();\n }\n this.composePorts.clear();\n\n if (this.audioDownstreamPort) {\n this.audioDownstreamPort.close();\n this.audioDownstreamPort = null;\n }\n\n this.registeredAudioTracks.clear();\n this.deliveredAudioTracks.clear();\n this.audioTrackMetadata.clear();\n\n for (const port of this.demuxPorts.values()) {\n port.close();\n }\n this.demuxPorts.clear();\n\n this.channel.state = WorkerState.Disposed;\n\n return { success: true };\n }\n\n /**\n * Get existing decoder for clip or create a new one (with LRU eviction)\n */\n private async getOrCreateDecoder(\n kind: 'video' | 'audio',\n sessionId: string,\n metadata?: Record<string, any> | null\n ): Promise<VideoChunkDecoder | AudioChunkDecoder> {\n if (kind === 'video') {\n let decoder = this.videoDecoders.get(sessionId);\n if (!decoder) {\n // Create decoder without configuration if metadata is null\n decoder = new VideoChunkDecoder(\n sessionId,\n metadata\n ? {\n ...this.defaultVideoConfig,\n codec: metadata.codec,\n width: metadata.width,\n height: metadata.height,\n description: normalizeDescription(metadata.description),\n }\n : undefined\n ); // Pass undefined to create unconfigured decoder\n\n this.evictIfNeeded('video');\n this.videoDecoders.set(sessionId, decoder);\n }\n // refresh LRU order\n this.videoDecoders.delete(sessionId);\n this.videoDecoders.set(sessionId, decoder);\n return decoder;\n } else {\n let decoder = this.audioDecoders.get(sessionId);\n if (!decoder) {\n decoder = new AudioChunkDecoder(\n sessionId,\n metadata\n ? {\n ...this.defaultAudioConfig,\n codec: metadata.codec,\n sampleRate: metadata.sampleRate,\n numberOfChannels: metadata.numberOfChannels,\n description: normalizeDescription(metadata.description),\n }\n : undefined\n );\n\n this.evictIfNeeded('audio');\n this.audioDecoders.set(sessionId, decoder);\n }\n // refresh LRU order\n this.audioDecoders.delete(sessionId);\n this.audioDecoders.set(sessionId, decoder);\n return decoder;\n }\n }\n\n /**\n * Evict least-recently-used decoder if we exceed MAX_ACTIVE_DECODERS.\n */\n private evictIfNeeded(kind: 'video' | 'audio'): void {\n const map = kind === 'video' ? this.videoDecoders : this.audioDecoders;\n if (map.size < DecodeWorker.MAX_ACTIVE_DECODERS) return;\n\n // Map preserves insertion order; first entry is LRU\n const [lrucId, lruDecoder] = map.entries().next().value as [string, any];\n lruDecoder.close().catch(() => undefined);\n map.delete(lrucId);\n }\n\n private async registerAudioTrack(\n trackId: string,\n clipId: string,\n metadata?: Record<string, any>\n ): Promise<void> {\n const record: TrackMetadata = {\n clipId,\n config: this.extractTrackConfig(metadata?.runtimeConfig),\n sampleRate: metadata?.sampleRate,\n numberOfChannels: metadata?.numberOfChannels,\n type: (metadata?.trackType as TrackMetadata['type']) ?? 'other',\n };\n\n this.audioTrackMetadata.set(trackId, record);\n\n if (this.registeredAudioTracks.has(trackId)) {\n await this.sendAudioTrackUpdate(trackId, record);\n return;\n }\n\n this.registeredAudioTracks.add(trackId);\n await this.sendAudioTrackAdd(trackId, record);\n }\n\n // private unregisterAudioTrack(trackId: string): void {\n // if (!this.registeredAudioTracks.delete(trackId)) {\n // return;\n // }\n\n // const record = this.audioTrackMetadata.get(trackId);\n // this.audioTrackMetadata.delete(trackId);\n\n // if (!record) {\n // return;\n // }\n\n // const channel = this.ensureComposeChannel();\n // channel\n // ?.send(WorkerMessageType.AudioTrackRemove, {\n // clipId: record.clipId,\n // trackId,\n // })\n // .catch((error) => {\n // console.warn('[DecodeWorker] Failed to notify track removal', error);\n // });\n // }\n\n private extractTrackConfig(config: any): AudioTrackConfig {\n return {\n startTimeUs: config?.startTimeUs ?? 0,\n durationUs: config?.durationUs,\n volume: config?.volume ?? 1,\n fadeIn: config?.fadeIn,\n fadeOut: config?.fadeOut,\n effects: config?.effects ?? [],\n duckingTag: config?.duckingTag,\n };\n }\n\n private async sendAudioTrackAdd(trackId: string, record: TrackMetadata): Promise<void> {\n const channel = this.ensureComposeChannel();\n if (!channel) {\n return;\n }\n\n await channel.send(WorkerMessageType.AudioTrackAdd, {\n clipId: record.clipId,\n trackId,\n config: record.config,\n sampleRate: record.sampleRate,\n numberOfChannels: record.numberOfChannels,\n type: record.type,\n });\n }\n\n private async sendAudioTrackUpdate(trackId: string, record: TrackMetadata): Promise<void> {\n const channel = this.ensureComposeChannel();\n if (!channel) {\n return;\n }\n\n if (!channel) {\n return;\n }\n\n await channel.send(WorkerMessageType.AudioTrackUpdate, {\n clipId: record.clipId,\n trackId,\n config: record.config,\n type: record.type,\n });\n }\n\n private ensureComposeChannel(): WorkerChannel | null {\n if (!this.audioDownstreamPort) {\n return null;\n }\n\n return new WorkerChannel(this.audioDownstreamPort, {\n name: 'Decode-AudioCompose',\n timeout: 30000,\n });\n }\n}\n\n// Initialize worker\nconst worker = new DecodeWorker();\n\n// Handle worker termination\nself.addEventListener('beforeunload', () => {\n worker['handleDispose']();\n});\n\nexport default null; // Required for TypeScript worker compilation\n"],"names":[],"mappings":";AAMO,MAAe,YAKpB;AAAA,EACU;AAAA,EACA;AAAA,EACA,aAA+D;AAAA,EAEzE,YAAY,QAAiB;AAC3B,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAM,aAA4B;AAChC,QAAI,KAAK,SAAS,UAAU,cAAc;AACxC;AAAA,IACF;AACA,UAAM,cAAc,MAAM,KAAK,kBAAkB,KAAK,MAAM;AAC5D,QAAI,CAAC,YAAY,WAAW;AAC1B,YAAM,IAAI;AAAA,QACR,wBAAyB,KAAK,OAAe,eAA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AAAA,EACH;AAAA,EAEA,MAAc,qBAAqB,SAAiB,QAAsC;AACxF,UAAM,UAAU,KAAK,qBAAA;AACrB,QAAI,CAAC,SAAS;AACZ;AAAA,IACF;AAEA,QAAI,CAAC,SAAS;AACZ;AAAA,IACF;AAEA,UAAM,QAAQ,KAAK,kBAAkB,kBAAkB;AAAA,MACrD,QAAQ,OAAO;AAAA,MACf;AAAA,MACA,QAAQ,OAAO;AAAA,MACf,MAAM,OAAO;AAAA,IAAA,CACd;AAAA,EACH;AAAA,EAEQ,uBAA6C;AACnD,QAAI,CAAC,KAAK,qBAAqB;AAC7B,aAAO;AAAA,IACT;AAEA,WAAO,IAAI,cAAc,KAAK,qBAAqB;AAAA,MACjD,MAAM;AAAA,MACN,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AACF;AAGA,MAAM,SAAS,IAAI,aAAA;AAGnB,KAAK,iBAAiB,gBAAgB,MAAM;AAC1C,SAAO,eAAe,EAAA;AACxB,CAAC;AAED,MAAA,gBAAe;"}
|
|
@@ -1,547 +0,0 @@
|
|
|
1
|
-
import { W as WorkerChannel, a as WorkerMessageType, b as WorkerState } from "../../WorkerChannel.js";
|
|
2
|
-
class BaseEncoder {
|
|
3
|
-
encoder;
|
|
4
|
-
config;
|
|
5
|
-
controller = null;
|
|
6
|
-
constructor(config) {
|
|
7
|
-
this.config = config;
|
|
8
|
-
}
|
|
9
|
-
getConfig() {
|
|
10
|
-
return { ...this.config };
|
|
11
|
-
}
|
|
12
|
-
get currentConfig() {
|
|
13
|
-
return this.config;
|
|
14
|
-
}
|
|
15
|
-
shouldReconfigure(partial) {
|
|
16
|
-
const next = { ...this.config, ...partial };
|
|
17
|
-
const keys = Object.keys(partial ?? {});
|
|
18
|
-
for (const key of keys) {
|
|
19
|
-
if (partial[key] !== void 0 && next[key] !== this.config[key]) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
hasConfigChanged(next) {
|
|
26
|
-
const currentEntries = Object.entries(this.config);
|
|
27
|
-
for (const [key, value] of currentEntries) {
|
|
28
|
-
if (next[key] !== value) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
for (const key of Object.keys(next)) {
|
|
33
|
-
if (this.config[key] !== next[key]) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
configsEqual(a, b) {
|
|
40
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
41
|
-
}
|
|
42
|
-
async initialize() {
|
|
43
|
-
if (this.encoder?.state === "configured") {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const isSupported = await this.isConfigSupported(this.config);
|
|
47
|
-
if (!isSupported.supported) {
|
|
48
|
-
throw new Error(`Codec not supported: ${JSON.stringify(this.config)}`);
|
|
49
|
-
}
|
|
50
|
-
this.encoder = this.createEncoder({
|
|
51
|
-
output: this.handleOutput.bind(this),
|
|
52
|
-
error: this.handleError.bind(this)
|
|
53
|
-
});
|
|
54
|
-
this.encoder.configure(this.config);
|
|
55
|
-
}
|
|
56
|
-
async reconfigure(config) {
|
|
57
|
-
if (!config || Object.keys(config).length === 0) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const nextConfig = { ...this.config, ...config };
|
|
61
|
-
if (this.configsEqual(this.config, nextConfig)) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (!this.encoder) {
|
|
65
|
-
this.config = nextConfig;
|
|
66
|
-
await this.initialize();
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (this.encoder.state === "configured") {
|
|
70
|
-
await this.encoder.flush();
|
|
71
|
-
}
|
|
72
|
-
const isSupported = await this.isConfigSupported(nextConfig);
|
|
73
|
-
if (!isSupported.supported) {
|
|
74
|
-
throw new Error(`New configuration not supported: ${nextConfig.codec}`);
|
|
75
|
-
}
|
|
76
|
-
this.config = nextConfig;
|
|
77
|
-
this.encoder.configure(this.config);
|
|
78
|
-
}
|
|
79
|
-
async flush() {
|
|
80
|
-
if (!this.encoder) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
await this.encoder.flush();
|
|
84
|
-
}
|
|
85
|
-
async reset() {
|
|
86
|
-
if (!this.encoder) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
this.encoder.reset();
|
|
90
|
-
this.onReset();
|
|
91
|
-
}
|
|
92
|
-
async close() {
|
|
93
|
-
if (!this.encoder) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (this.encoder.state === "configured") {
|
|
97
|
-
await this.encoder.flush();
|
|
98
|
-
}
|
|
99
|
-
this.encoder.close();
|
|
100
|
-
this.encoder = void 0;
|
|
101
|
-
}
|
|
102
|
-
get isReady() {
|
|
103
|
-
return this.encoder?.state === "configured";
|
|
104
|
-
}
|
|
105
|
-
get queueSize() {
|
|
106
|
-
return this.encoder?.encodeQueueSize ?? 0;
|
|
107
|
-
}
|
|
108
|
-
handleOutput(chunk, metadata) {
|
|
109
|
-
if (this.controller) {
|
|
110
|
-
try {
|
|
111
|
-
this.controller.enqueue({ chunk, metadata });
|
|
112
|
-
} catch (error) {
|
|
113
|
-
if (!(error instanceof TypeError && error.message.includes("closed"))) {
|
|
114
|
-
throw error;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
handleError(error) {
|
|
120
|
-
console.error(`${this.getEncoderType()} encoder error:`, error);
|
|
121
|
-
this.controller?.error(error);
|
|
122
|
-
}
|
|
123
|
-
// Hook for subclasses to handle reset
|
|
124
|
-
onReset() {
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Create transform stream for encoding
|
|
128
|
-
* Implements common stream logic with backpressure handling
|
|
129
|
-
*/
|
|
130
|
-
createStream() {
|
|
131
|
-
return new TransformStream(
|
|
132
|
-
{
|
|
133
|
-
start: async (controller) => {
|
|
134
|
-
this.controller = controller;
|
|
135
|
-
if (!this.isReady) {
|
|
136
|
-
await this.initialize();
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
transform: async (input) => {
|
|
140
|
-
if (!this.encoder || this.encoder.state !== "configured") {
|
|
141
|
-
throw new Error("Encoder not configured");
|
|
142
|
-
}
|
|
143
|
-
if (this.encoder.encodeQueueSize >= this.encodeQueueThreshold) {
|
|
144
|
-
await new Promise((resolve) => {
|
|
145
|
-
const check = () => {
|
|
146
|
-
if (!this.encoder || this.encoder.encodeQueueSize < this.encodeQueueThreshold - 1) {
|
|
147
|
-
resolve();
|
|
148
|
-
} else {
|
|
149
|
-
setTimeout(check, 10);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
check();
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
const frame = input.frame || input;
|
|
156
|
-
this.encode(frame);
|
|
157
|
-
},
|
|
158
|
-
flush: async () => {
|
|
159
|
-
await this.flush();
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
// Queuing strategy with backpressure configuration
|
|
163
|
-
{
|
|
164
|
-
highWaterMark: this.highWaterMark,
|
|
165
|
-
size: () => 1
|
|
166
|
-
// Count-based
|
|
167
|
-
}
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
class VideoChunkEncoder extends BaseEncoder {
|
|
172
|
-
static DEFAULT_HIGH_WATER_MARK = 2;
|
|
173
|
-
static DEFAULT_ENCODE_QUEUE_THRESHOLD = 8;
|
|
174
|
-
highWaterMark;
|
|
175
|
-
encodeQueueThreshold;
|
|
176
|
-
frameCount = 0;
|
|
177
|
-
keyFrameInterval = 60;
|
|
178
|
-
// 2 seconds at 30fps
|
|
179
|
-
constructor(config) {
|
|
180
|
-
super(config);
|
|
181
|
-
this.highWaterMark = config.backpressure?.highWaterMark ?? VideoChunkEncoder.DEFAULT_HIGH_WATER_MARK;
|
|
182
|
-
this.encodeQueueThreshold = config.backpressure?.encodeQueueThreshold ?? VideoChunkEncoder.DEFAULT_ENCODE_QUEUE_THRESHOLD;
|
|
183
|
-
}
|
|
184
|
-
async isConfigSupported(config) {
|
|
185
|
-
const result = await VideoEncoder.isConfigSupported(config);
|
|
186
|
-
return { supported: result.supported ?? false };
|
|
187
|
-
}
|
|
188
|
-
createEncoder(init) {
|
|
189
|
-
return new VideoEncoder(init);
|
|
190
|
-
}
|
|
191
|
-
getEncoderType() {
|
|
192
|
-
return "Video";
|
|
193
|
-
}
|
|
194
|
-
onReset() {
|
|
195
|
-
this.frameCount = 0;
|
|
196
|
-
}
|
|
197
|
-
encode(frame) {
|
|
198
|
-
const keyFrame = this.shouldGenerateKeyFrame();
|
|
199
|
-
const encodeOptions = {
|
|
200
|
-
keyFrame
|
|
201
|
-
};
|
|
202
|
-
this.encoder.encode(frame, encodeOptions);
|
|
203
|
-
this.frameCount++;
|
|
204
|
-
frame.close();
|
|
205
|
-
}
|
|
206
|
-
setKeyFrameInterval(interval) {
|
|
207
|
-
this.keyFrameInterval = Math.max(1, interval);
|
|
208
|
-
}
|
|
209
|
-
shouldGenerateKeyFrame() {
|
|
210
|
-
if (this.frameCount === 0) {
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
return this.frameCount % this.keyFrameInterval === 0;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
class AudioChunkEncoder extends BaseEncoder {
|
|
217
|
-
static DEFAULT_HIGH_WATER_MARK = 4;
|
|
218
|
-
static DEFAULT_ENCODE_QUEUE_THRESHOLD = 16;
|
|
219
|
-
static DEFAULT_CONFIG = {
|
|
220
|
-
codec: "mp4a.40.2",
|
|
221
|
-
// AAC-LC
|
|
222
|
-
sampleRate: 48e3,
|
|
223
|
-
numberOfChannels: 2,
|
|
224
|
-
bitrate: 128e3
|
|
225
|
-
};
|
|
226
|
-
highWaterMark;
|
|
227
|
-
encodeQueueThreshold;
|
|
228
|
-
constructor(config) {
|
|
229
|
-
const fullConfig = { ...AudioChunkEncoder.DEFAULT_CONFIG, ...config };
|
|
230
|
-
super(fullConfig);
|
|
231
|
-
this.highWaterMark = fullConfig.backpressure?.highWaterMark ?? AudioChunkEncoder.DEFAULT_HIGH_WATER_MARK;
|
|
232
|
-
this.encodeQueueThreshold = fullConfig.backpressure?.encodeQueueThreshold ?? AudioChunkEncoder.DEFAULT_ENCODE_QUEUE_THRESHOLD;
|
|
233
|
-
}
|
|
234
|
-
async isConfigSupported(config) {
|
|
235
|
-
const result = await AudioEncoder.isConfigSupported(config);
|
|
236
|
-
return { supported: result.supported ?? false };
|
|
237
|
-
}
|
|
238
|
-
createEncoder(init) {
|
|
239
|
-
return new AudioEncoder(init);
|
|
240
|
-
}
|
|
241
|
-
getEncoderType() {
|
|
242
|
-
return "Audio";
|
|
243
|
-
}
|
|
244
|
-
encode(data) {
|
|
245
|
-
if (this.encoder?.state !== "configured") {
|
|
246
|
-
throw new Error("Audio encoder not configured");
|
|
247
|
-
}
|
|
248
|
-
this.encoder.encode(data);
|
|
249
|
-
data.close();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
class ClipEncoderManager {
|
|
253
|
-
videoEncoders = /* @__PURE__ */ new Map();
|
|
254
|
-
audioEncoders = /* @__PURE__ */ new Map();
|
|
255
|
-
videoCreationOrder = [];
|
|
256
|
-
audioCreationOrder = [];
|
|
257
|
-
maxEncoders;
|
|
258
|
-
constructor(maxEncoders = 6) {
|
|
259
|
-
this.maxEncoders = maxEncoders;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Acquire a video encoder for the given sessionId
|
|
263
|
-
* Creates new encoder if not exists; returns existing one if already created
|
|
264
|
-
*/
|
|
265
|
-
async acquireVideo(sessionId, config) {
|
|
266
|
-
let encoder = this.videoEncoders.get(sessionId);
|
|
267
|
-
if (!encoder) {
|
|
268
|
-
if (this.videoEncoders.size >= this.maxEncoders) {
|
|
269
|
-
throw new Error(
|
|
270
|
-
`[ClipEncoderManager] Video encoder limit reached (${this.maxEncoders}). Active clips: ${Array.from(this.videoEncoders.keys()).join(", ")}. Please release unused encoders before acquiring new ones.`
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
encoder = new VideoChunkEncoder(config);
|
|
274
|
-
await encoder.initialize();
|
|
275
|
-
this.videoEncoders.set(sessionId, encoder);
|
|
276
|
-
this.videoCreationOrder.push(sessionId);
|
|
277
|
-
}
|
|
278
|
-
return encoder;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Acquire an audio encoder for the given sessionId
|
|
282
|
-
*/
|
|
283
|
-
async acquireAudio(sessionId, config) {
|
|
284
|
-
let encoder = this.audioEncoders.get(sessionId);
|
|
285
|
-
if (!encoder) {
|
|
286
|
-
if (this.audioEncoders.size >= this.maxEncoders) {
|
|
287
|
-
throw new Error(
|
|
288
|
-
`[ClipEncoderManager] Audio encoder limit reached (${this.maxEncoders}). Active clips: ${Array.from(this.audioEncoders.keys()).join(", ")}. Please release unused encoders before acquiring new ones.`
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
encoder = new AudioChunkEncoder(config);
|
|
292
|
-
await encoder.initialize();
|
|
293
|
-
this.audioEncoders.set(sessionId, encoder);
|
|
294
|
-
this.audioCreationOrder.push(sessionId);
|
|
295
|
-
}
|
|
296
|
-
return encoder;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Release video encoder for the given sessionId
|
|
300
|
-
*/
|
|
301
|
-
async releaseVideo(sessionId) {
|
|
302
|
-
const encoder = this.videoEncoders.get(sessionId);
|
|
303
|
-
if (encoder) {
|
|
304
|
-
await encoder.close();
|
|
305
|
-
this.videoEncoders.delete(sessionId);
|
|
306
|
-
const index = this.videoCreationOrder.indexOf(sessionId);
|
|
307
|
-
if (index !== -1) {
|
|
308
|
-
this.videoCreationOrder.splice(index, 1);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Release audio encoder for the given sessionId
|
|
314
|
-
*/
|
|
315
|
-
async releaseAudio(sessionId) {
|
|
316
|
-
const encoder = this.audioEncoders.get(sessionId);
|
|
317
|
-
if (encoder) {
|
|
318
|
-
await encoder.close();
|
|
319
|
-
this.audioEncoders.delete(sessionId);
|
|
320
|
-
const index = this.audioCreationOrder.indexOf(sessionId);
|
|
321
|
-
if (index !== -1) {
|
|
322
|
-
this.audioCreationOrder.splice(index, 1);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Release both video and audio encoders for the given sessionId
|
|
328
|
-
*/
|
|
329
|
-
async releaseClip(sessionId) {
|
|
330
|
-
await Promise.all([this.releaseVideo(sessionId), this.releaseAudio(sessionId)]);
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Close all encoders and clear state
|
|
334
|
-
*/
|
|
335
|
-
async closeAll() {
|
|
336
|
-
const promises = [
|
|
337
|
-
...Array.from(this.videoEncoders.values()).map((e) => e.close()),
|
|
338
|
-
...Array.from(this.audioEncoders.values()).map((e) => e.close())
|
|
339
|
-
];
|
|
340
|
-
await Promise.all(promises);
|
|
341
|
-
this.videoEncoders.clear();
|
|
342
|
-
this.audioEncoders.clear();
|
|
343
|
-
this.videoCreationOrder = [];
|
|
344
|
-
this.audioCreationOrder = [];
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* Check if encoders exist for the given sessionId
|
|
348
|
-
*/
|
|
349
|
-
has(sessionId) {
|
|
350
|
-
return this.videoEncoders.has(sessionId) || this.audioEncoders.has(sessionId);
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Get statistics about current encoder state
|
|
354
|
-
*/
|
|
355
|
-
getStats() {
|
|
356
|
-
return {
|
|
357
|
-
videoEncoders: this.videoEncoders.size,
|
|
358
|
-
audioEncoders: this.audioEncoders.size,
|
|
359
|
-
maxEncoders: this.maxEncoders,
|
|
360
|
-
videoCreationOrder: [...this.videoCreationOrder],
|
|
361
|
-
audioCreationOrder: [...this.audioCreationOrder]
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
class EncodeWorker {
|
|
366
|
-
channel;
|
|
367
|
-
encoderManager = new ClipEncoderManager(12);
|
|
368
|
-
// Increased to prevent eviction during active streams
|
|
369
|
-
// Default encoder configs
|
|
370
|
-
defaultVideoConfig = null;
|
|
371
|
-
defaultAudioConfig = null;
|
|
372
|
-
// Connections to other workers
|
|
373
|
-
muxPort = null;
|
|
374
|
-
composePorts = /* @__PURE__ */ new Map();
|
|
375
|
-
// Connections from compose workers
|
|
376
|
-
constructor() {
|
|
377
|
-
this.channel = new WorkerChannel(self, {
|
|
378
|
-
name: "EncodeWorker",
|
|
379
|
-
timeout: 3e4
|
|
380
|
-
});
|
|
381
|
-
this.setupHandlers();
|
|
382
|
-
}
|
|
383
|
-
setupHandlers() {
|
|
384
|
-
this.channel.registerHandler("configure", this.handleConfigure.bind(this));
|
|
385
|
-
this.channel.registerHandler("connect", this.handleConnect.bind(this));
|
|
386
|
-
this.channel.registerHandler("configure_video", this.handleConfigureVideo.bind(this));
|
|
387
|
-
this.channel.registerHandler("flush", this.handleFlush.bind(this));
|
|
388
|
-
this.channel.registerHandler("reset", this.handleReset.bind(this));
|
|
389
|
-
this.channel.registerHandler("release_clip_encoder", this.handleReleaseClipEncoder.bind(this));
|
|
390
|
-
this.channel.registerHandler("get_stats", this.handleGetStats.bind(this));
|
|
391
|
-
this.channel.registerHandler(WorkerMessageType.Dispose, this.handleDispose.bind(this));
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Connect handler used by stream pipeline
|
|
395
|
-
*/
|
|
396
|
-
async handleConnect(payload) {
|
|
397
|
-
const { port, streamType, sessionId } = payload;
|
|
398
|
-
if (streamType === "video") {
|
|
399
|
-
return this.handleConnectComposer({ composeType: "video", port, sessionId });
|
|
400
|
-
}
|
|
401
|
-
if (streamType === "audio") {
|
|
402
|
-
return this.handleConnectComposer({ composeType: "audio", port, sessionId });
|
|
403
|
-
}
|
|
404
|
-
if (streamType === "chunk") return this.handleConnectMux({ port });
|
|
405
|
-
return { success: true };
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Handle configuration message from orchestrator
|
|
409
|
-
* @param payload.initial - If true, initialize worker; saves default encoder configs
|
|
410
|
-
*/
|
|
411
|
-
async handleConfigure(payload) {
|
|
412
|
-
const { config, initial = false } = payload;
|
|
413
|
-
if (initial) {
|
|
414
|
-
this.channel.state = WorkerState.Ready;
|
|
415
|
-
}
|
|
416
|
-
if (config.video) {
|
|
417
|
-
this.defaultVideoConfig = config.video;
|
|
418
|
-
}
|
|
419
|
-
if (config.audio) {
|
|
420
|
-
this.defaultAudioConfig = config.audio;
|
|
421
|
-
}
|
|
422
|
-
return { success: true };
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Connect to a compose worker to receive frames/audio data
|
|
426
|
-
*/
|
|
427
|
-
async handleConnectComposer(payload) {
|
|
428
|
-
const { composeType, port, sessionId } = payload;
|
|
429
|
-
this.composePorts.set(composeType, port);
|
|
430
|
-
const composeChannel = new WorkerChannel(port, {
|
|
431
|
-
name: `Encode-${composeType}Compose`,
|
|
432
|
-
timeout: 3e4
|
|
433
|
-
});
|
|
434
|
-
composeChannel.receiveStream(async (stream, metadata) => {
|
|
435
|
-
const streamSessionId = metadata?.sessionId || sessionId || "unknown";
|
|
436
|
-
if (metadata?.streamType === "video" && this.defaultVideoConfig) {
|
|
437
|
-
const encoder = await this.encoderManager.acquireVideo(
|
|
438
|
-
streamSessionId,
|
|
439
|
-
this.defaultVideoConfig
|
|
440
|
-
);
|
|
441
|
-
const encodingTransform = encoder.createStream();
|
|
442
|
-
const encodedStream = stream.pipeThrough(
|
|
443
|
-
encodingTransform
|
|
444
|
-
);
|
|
445
|
-
this.channel.sendStream(encodedStream, {
|
|
446
|
-
streamType: "video",
|
|
447
|
-
track: "video",
|
|
448
|
-
sessionId: streamSessionId
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
});
|
|
452
|
-
return { success: true };
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Connect to cache manager for output streaming
|
|
456
|
-
*/
|
|
457
|
-
// private async handleConnectCache(payload: { port: MessagePort }): Promise<{ success: boolean }> {
|
|
458
|
-
// this.cachePort = payload.port;
|
|
459
|
-
// return { success: true };
|
|
460
|
-
// }
|
|
461
|
-
/**
|
|
462
|
-
* Connect to mux worker for output streaming
|
|
463
|
-
*/
|
|
464
|
-
async handleConnectMux(payload) {
|
|
465
|
-
this.muxPort = payload.port;
|
|
466
|
-
return { success: true };
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Configure video encoder with specific settings
|
|
470
|
-
*/
|
|
471
|
-
async handleConfigureVideo(config) {
|
|
472
|
-
try {
|
|
473
|
-
this.defaultVideoConfig = config;
|
|
474
|
-
this.channel.notify("video_configured", {
|
|
475
|
-
codec: config.codec,
|
|
476
|
-
width: config.width,
|
|
477
|
-
height: config.height,
|
|
478
|
-
bitrate: config.bitrate
|
|
479
|
-
});
|
|
480
|
-
return { success: true };
|
|
481
|
-
} catch (error) {
|
|
482
|
-
throw {
|
|
483
|
-
code: "VIDEO_CONFIG_ERROR",
|
|
484
|
-
message: error.message
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Flush encoders (deprecated with per-clip encoder architecture)
|
|
490
|
-
*/
|
|
491
|
-
async handleFlush(_payload) {
|
|
492
|
-
console.warn("[EncodeWorker] handleFlush is deprecated with per-clip encoder architecture");
|
|
493
|
-
return {};
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Reset encoders (deprecated with per-clip encoder architecture)
|
|
497
|
-
*/
|
|
498
|
-
async handleReset(payload) {
|
|
499
|
-
console.warn("[EncodeWorker] handleReset is deprecated with per-clip encoder architecture");
|
|
500
|
-
this.channel.notify("reset_complete", {
|
|
501
|
-
type: payload?.type || "all"
|
|
502
|
-
});
|
|
503
|
-
return { success: true };
|
|
504
|
-
}
|
|
505
|
-
/**
|
|
506
|
-
* Release encoder for a specific clip
|
|
507
|
-
*/
|
|
508
|
-
async handleReleaseClipEncoder(payload) {
|
|
509
|
-
const { sessionId } = payload;
|
|
510
|
-
await this.encoderManager.releaseClip(sessionId);
|
|
511
|
-
return { success: true };
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* Get encoder statistics
|
|
515
|
-
*/
|
|
516
|
-
async handleGetStats() {
|
|
517
|
-
const stats = {
|
|
518
|
-
encoders: this.encoderManager.getStats()
|
|
519
|
-
};
|
|
520
|
-
return stats;
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Dispose worker and cleanup resources
|
|
524
|
-
*/
|
|
525
|
-
async handleDispose() {
|
|
526
|
-
await this.encoderManager.closeAll();
|
|
527
|
-
this.defaultVideoConfig = null;
|
|
528
|
-
this.defaultAudioConfig = null;
|
|
529
|
-
this.muxPort?.close();
|
|
530
|
-
this.muxPort = null;
|
|
531
|
-
for (const port of this.composePorts.values()) {
|
|
532
|
-
port.close();
|
|
533
|
-
}
|
|
534
|
-
this.composePorts.clear();
|
|
535
|
-
this.channel.state = WorkerState.Disposed;
|
|
536
|
-
return { success: true };
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
const worker = new EncodeWorker();
|
|
540
|
-
self.addEventListener("beforeunload", () => {
|
|
541
|
-
worker["handleDispose"]();
|
|
542
|
-
});
|
|
543
|
-
const encode_worker = null;
|
|
544
|
-
export {
|
|
545
|
-
encode_worker as default
|
|
546
|
-
};
|
|
547
|
-
//# sourceMappingURL=encode.worker.js.map
|