node-gtk icon indicating copy to clipboard operation
node-gtk copied to clipboard

Any way to trigger g_signal_emit_by_name with returnValue?

Open yuijzeon opened this issue 11 months ago • 1 comments

Hi everyone,

I am trying writing Playback tutorial 1: Playbin usage to TypeScript with node-gtk

But g_signal_emit_by_name does not exist in node-gtk

GstTagList *tags;
g_signal_emit_by_name (data->playbin, "get-text-tags", i, &tags);

I use g_signal_emitv instead

Works great in C

GType itype = g_type_from_name("GstPlayBin");
GValue instance_and_params[2] = {G_VALUE_INIT, G_VALUE_INIT};
g_value_init(&instance_and_params[0], itype);
g_value_set_object(&instance_and_params[0], data->playbin);
g_value_init(&instance_and_params[1], G_TYPE_INT);
g_value_set_int(&instance_and_params[1], i);
guint signal_id = g_signal_lookup("get-video-tags", itype);
GValue return_value = G_VALUE_INIT;
g_value_init(&return_value, g_type_from_name("GstTagList"));
g_signal_emitv(instance_and_params, signal_id, 0, &return_value);
GstTagList* tags = g_value_get_boxed(&return_value);

But it doesn't work in node-gtk

const itype = GObject.typeFromName('GstPlayBin');
const instanceAndParams = [new GObject.Value(), new GObject.Value()];
instanceAndParams[0].init(itype);
instanceAndParams[0].setObject(data.playbin);
instanceAndParams[1].init(GObject.TYPE_INT);
instanceAndParams[1].setInt(i);
const signalId = GObject.signalLookup('get-video-tags', itype);
const returnValue = new GObject.Value();
returnValue.init(GObject.typeFromName('GstTagList'));
GObject.signalEmitv(instanceAndParams, signalId, 0, returnValue);
const tags = returnValue.getBoxed<Gst.TagList>();

Execution log:

(node:538554): GLib-GObject-CRITICAL **: 22:34:52.348: can't peek value table for type '(null)' which is not currently referenced
(node:538554): GLib-GObject-CRITICAL **: 22:34:52.349: g_value_peek_pointer: assertion 'value_table' failed
(node:538554): GLib-GObject-CRITICAL **: 22:34:52.349: invalid (NULL) pointer instance
(node:538554): GLib-GObject-CRITICAL **: 22:34:52.349: signal_emitv_unlocked: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
** (node:538554): CRITICAL **: 22:34:52.349: Unable to determine array length for 0x3dd05680

Each line of code corresponds to C

I don't understand why I still can't get the GstTagList

yuijzeon avatar Feb 15 '25 17:02 yuijzeon

GST tends to use gobject features that are more low-level than the rest of the ecosystem.

In this case, node-gtk has no way of knowing that getBoxed() needs to return a GST.TagList, but it seems to be failing even before that.

Tbh I don't have enough time to allocate to debug this issue, but a PR would be welcomed. If you're interested, most of the code of interest for this issue would be in lib/bootstrap.js and src/function.cc.

romgrk avatar Feb 18 '25 18:02 romgrk