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

Cannot override GES.SourceClip virtual method #268

Open
jade-guiton opened this issue Jun 7, 2021 · 5 comments
Open

Cannot override GES.SourceClip virtual method #268

jade-guiton opened this issue Jun 7, 2021 · 5 comments

Comments

@jade-guiton
Copy link

jade-guiton commented Jun 7, 2021

I am attempting to make a simple video editor, using GES (GStreamer Editing Services) and Löve. One of my goals is to be able to run Lua code, which draws using Löve, and pushes buffers into a GES Pipeline.

Looking at the GES source code (and this very similar attempt in Python (code, discussion), but which seems to fail for different reasons), it seems the way to do that would be to draw into an Gst.AppSrc, wrap that into a subclass of GES.VideoSource, then wrap that into a subclass of GES.SourceClip.

GES.SourceClip has a create_track_element virtual method inherited from GES.Clip, which is where the custom VideoSource would be created.

The problem is that, when I override the virtual method as described in the guide, and make GES call it (via an add_clip call, see below), the resulting Clip does not work at all, and setting GST_DEBUG=1 reveals an error like the following:

0:00:00.040232023 441673 0x55a2eb5a7ef0 ERROR
ges ges-clip.c:898:ges_clip_create_track_element: No 'create_track_element' implementation available fo [sic] type MyTestMySourceClip

And of course, the method I defined is never called. Snooping inside the lgi code, it looks like the virtual method is simply not known to it. Any ideas why that might be, or how I might investigate this?

Feel free to close this issue if you think there are better places to ask about this problem.

Here is a minimal program reproducing the problem:

local lgi = require('lgi.init')
local GES = lgi.GES
GES.init()

local MyTest = lgi.package('MyTest')
MyTest:class('MySourceClip', GES.SourceClip)
function MyTest.MySourceClip.do_create_track_element(type)
	print('do_create_track_element was called!')
end

local timeline = GES.Timeline.new_audio_video()
local layer = timeline:append_layer()
local clip = MyTest.MySourceClip()
local res = layer:add_clip(clip)
assert(res)

I have tried this using Löve's LuaJIT 5.1 interpreter and a standard CLua 5.3 interpreter. I am running GStreamer v1.16.2 on Ubuntu 20.04.

@psychon
Copy link
Collaborator

psychon commented Jun 9, 2021

Uhm... you won't like what I will write.

I am on Debian Testing, using Lua 5.2.4. I just installed gir1.2-ges-1.0 just for you. The result:

$ lua /tmp/t.lua
do_create_track_element was called!
do_create_track_element was called!

Seems to work with every Lua version:

do_create_track_element was called!
do_create_track_element was called!
do_create_track_element was called!
do_create_track_element was called!
do_create_track_element was called!
do_create_track_element was called!
do_create_track_element was called!
do_create_track_element was called!

I get no extra output with GST_DEBUG=1.

Edit: I also tested with Lua 5.3 and lgi built from git. That works as well.

Edit: Oh and thanks a lot for providing a minimal reproducer. That is always great!

@jade-guiton
Copy link
Author

Alright then, I will try installing other versions of GStreamer and LGI. Thank you very much!

@psychon
Copy link
Collaborator

psychon commented Jun 9, 2021

Random idea: Try translating your example program above to C or C++. Since your Lua code works on my system, I would expect that the translated version would also fail on your system. And at this point it becomes a lot easier to ask the people from GES for help since you are not using "this weird programming language". ;-)

@jade-guiton
Copy link
Author

jade-guiton commented Jun 9, 2021

Alright, I checked that my versions of GStreamer and GES (with development libraries) + the GIR package were up to date, and I tried recompiling lgi from Git as well, but unfortunately, the Lua version still does not work.

I then translated my example into C, and, unexpectedly, it seems to work... GST_DEBUG=1 does not show any errors either.

Here is the C code, in case you would like to try it:

#include <glib.h>
#include <gst/gst.h>
#include <ges/ges.h>
#include <stdio.h>

typedef struct _MySourceClip {
	GESSourceClip parent;
} MySourceClip;
typedef struct _MySourceClipClass {
	GESSourceClipClass parent_class;
} MySourceClipClass;

G_DEFINE_TYPE(MySourceClip, my_source_clip, GES_TYPE_SOURCE_CLIP)
#define MY_TYPE_SOURCE_CLIP my_source_clip_get_type()


MySourceClip* my_source_clip_new(void) {
	return g_object_new(MY_TYPE_SOURCE_CLIP, NULL);
}
void my_source_clip_init(MySourceClip *clip) {}

GESTrackElement* my_source_clip_create_track_element(GESClip* clip, GESTrackType type) {
	printf("create_track_element was called!\n");
	return NULL;
}

void my_source_clip_class_init(MySourceClipClass* class) {
	GESClipClass* clip_class = GES_CLIP_CLASS(class);
	clip_class->create_track_element = my_source_clip_create_track_element;
}


int main(int argc, char* argv[]) {
	gst_init(&argc, &argv);
	ges_init();
	
	GESTimeline* timeline = ges_timeline_new_audio_video();
	GESLayer* layer = ges_timeline_append_layer(timeline);
	MySourceClip* clip = my_source_clip_new();
	ges_layer_add_clip(layer, &clip->parent.parent);

	return 0;
}

I compiled it with gcc -Wall test.c -o test $(pkg-config --cflags --libs gstreamer-1.0) -lges-1.0.

@psychon
Copy link
Collaborator

psychon commented Jun 9, 2021

$ ./test 
create_track_element was called!
create_track_element was called!

Hm... No idea why the Lua program works for me, but not for you. I'm also out of random ideas...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants