-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[web-wasm] Decouple frame production from input implementation (#906)
- Loading branch information
Showing
10 changed files
with
1,258 additions
and
909 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
ts/@live-compositor/web-wasm/src/input/inputFrameProducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { RegisterInputRequest } from '@live-compositor/core'; | ||
import type { FrameRef } from './frame'; | ||
import DecodingFrameProducer from './producer/decodingFrameProducer'; | ||
import MP4Source from './mp4/source'; | ||
|
||
export type InputFrameProducerCallbacks = { | ||
onReady(): void; | ||
}; | ||
|
||
export default interface InputFrameProducer { | ||
init(): Promise<void>; | ||
/** | ||
* Starts resources required for producing frames. `init()` has to be called beforehand. | ||
*/ | ||
start(): void; | ||
registerCallbacks(callbacks: InputFrameProducerCallbacks): void; | ||
/** | ||
* Produce next frame. | ||
* @param framePts - Desired PTS of the frame in milliseconds. | ||
*/ | ||
produce(framePts?: number): Promise<void>; | ||
getFrameRef(framePts: number): FrameRef | undefined; | ||
/** | ||
* if `true` no more frames will be produced. | ||
*/ | ||
isFinished(): boolean; | ||
close(): void; | ||
} | ||
|
||
export function producerFromRequest(request: RegisterInputRequest): InputFrameProducer { | ||
if (request.type === 'mp4') { | ||
return new DecodingFrameProducer(new MP4Source(request.url!)); | ||
} else { | ||
throw new Error(`Unknown input type ${(request as any).type}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.