Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web-wasm] Return MP4 duration on creation #921

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Review suggestions
noituri committed Jan 15, 2025
commit 8d16f4827a21e0a6bd4d5a4cd025d5b444c7ed91
10 changes: 5 additions & 5 deletions ts/@live-compositor/web-wasm/src/input/mp4/source.ts
Original file line number Diff line number Diff line change
@@ -23,11 +23,11 @@ export default class MP4Source implements InputSource {
}

public async start(): Promise<void> {
if (!this.fileData) {
throw new Error('MP4Source has to be initialized first before processing can be started');
}

await new Promise<void>(resolve => {
if (!this.fileData) {
throw new Error('MP4Source has to be initialized first before processing can be started');
}

this.demuxer = new MP4Demuxer({
onReady: data => {
this.callbacks?.onDecoderConfig(data.decoderConfig);
@@ -38,7 +38,7 @@ export default class MP4Source implements InputSource {
onPayload: payload => this.handlePayload(payload),
});

this.demuxer.demux(this.fileData!);
this.demuxer.demux(this.fileData);
this.demuxer.flush();
});
}
46 changes: 30 additions & 16 deletions ts/@live-compositor/web-wasm/src/manager/wasmInstance.ts
Original file line number Diff line number Diff line change
@@ -45,11 +45,11 @@ class WasmInstance implements CompositorManager {
}

if (route.type == 'input') {
return this.handleInputRequest(route.id, route.operation, request.body);
return await this.handleInputRequest(route.id, route.operation, request.body);
} else if (route.type === 'output') {
return this.handleOutputRequest(route.id, route.operation, request.body);
} else if (route.type === 'image') {
return this.handleImageRequest(route.id, route.operation, request.body);
return await this.handleImageRequest(route.id, route.operation, request.body);
} else if (route.type === 'shader') {
throw new Error('Shaders are not supported');
} else if (route.type === 'web-renderer') {
@@ -84,26 +84,24 @@ class WasmInstance implements CompositorManager {
body?: object
): Promise<object> {
if (operation === 'register') {
return this.registerInput(inputId, body! as RegisterInputRequest);
return await this.registerInput(inputId, body! as RegisterInputRequest);
} else if (operation === 'unregister') {
this.queue.removeInput(inputId);
this.renderer.unregisterInput(inputId);
return this.unregisterInput(inputId);
} else {
return {};
}

return {};
}

private handleOutputRequest(outputId: string, operation: string, body?: object): object {
if (operation === 'register') {
this.registerOutput(outputId, body! as RegisterOutputRequest);
return this.registerOutput(outputId, body! as RegisterOutputRequest);
} else if (operation === 'unregister') {
this.queue.removeOutput(outputId);
this.renderer.unregisterOutput(outputId);
return this.unregisterOutput(outputId);
} else if (operation === 'update') {
this.updateScene(outputId, body! as Api.UpdateOutputRequest);
return this.updateScene(outputId, body! as Api.UpdateOutputRequest);
} else {
return {};
}

return {};
}

private async handleImageRequest(
@@ -138,7 +136,13 @@ class WasmInstance implements CompositorManager {
};
}

private registerOutput(outputId: string, request: RegisterOutputRequest) {
private unregisterInput(inputId: string): object {
this.queue.removeInput(inputId);
this.renderer.unregisterInput(inputId);
return {};
}

private registerOutput(outputId: string, request: RegisterOutputRequest): object {
if (request.video) {
const output = new Output(request);
this.queue.addOutput(outputId, output);
@@ -156,17 +160,27 @@ class WasmInstance implements CompositorManager {
throw e;
}
}

return {};
}

private updateScene(outputId: string, request: Api.UpdateOutputRequest) {
private unregisterOutput(outputId: string): object {
this.queue.removeOutput(outputId);
this.renderer.unregisterOutput(outputId);
return {};
}

private updateScene(outputId: string, request: Api.UpdateOutputRequest): object {
if (!request.video) {
return;
return {};
}
const output = this.queue.getOutput(outputId);
if (!output) {
throw `Unknown output "${outputId}"`;
}
this.renderer.updateScene(outputId, output.resolution, request.video.root as Component);

return {};
}
}