Lambdas don't currently work with val. You could do something like this:
struct Init {
void output(val frame) {
EM_ASM(
console.log("Got frame: ", frame);
);
}
void error(val e) {
EM_ASM(
console.error("Error initializing decoder: ", e);
);
}
};
EMSCRIPTEN_BINDINGS(xxx) {
class_<Init>("Init")
.function("output", &Init::output)
.function("error", &Init::error)
;
}
....
// This needs to be deleted at some pointed...
Init* init = new Init();
val decoder = VideoDecoder.new_(init);
On Tuesday, July 2, 2024 at 7:25:22 AM UTC-7 [email protected] wrote:
> I'm quite new to emscripten, so please be patient with me :)
>
> My goal is to create a wrapper class with an instance of a VideoDecoder
> object from WebCodecs API and pass some configurations inside it from C++.
>
> I'm trying to pass an object called 'init' on the global "VideoDecoder"
> object, which accepts a callback function on its members: output and error:
>
> LVideoDecoderWebCodecs::LVideoDecoderWebCodecs()
> {
> val VideoDecoder = val::global("VideoDecoder");
>
> if (!VideoDecoder.as<bool>()) {
> EM_ASM(
> console.error("WebCodecs API not available");
> );
> }
>
> val config = val::object();
> config.set("codec", val("vp8"));
> config.set("codedWidth", val(640));
> config.set("codedHeight", val(480));
>
> val init = val::object();
> init.set("output", [](val frame) {
> EM_ASM(
> console.log("Got frame: ", frame);
> );
> });
>
> init.set("error", [](val e) {
> EM_ASM(
> console.error("Error initializing decoder: ", e);
> );
> });
>
> val decoder = VideoDecoder.new_(init);
> decoder.call<void>("configure", config);
> }
>
> The module compiles successfully but when I run it on the browser it says,
> wasmapi.js:4543 Uncaught BindingError: _emval_take_value has unknown type
>
> It seems that I can't set a callback function on the init object.
>
> Is there a solution to this? Or what can you suggest I handle this one.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/emscripten-discuss/e2e02c70-f50f-4440-a68b-fafbd9874cb0n%40googlegroups.com.