gst1-java-core icon indicating copy to clipboard operation
gst1-java-core copied to clipboard

Registering a custom Element

Open hauges opened this issue 7 years ago • 6 comments

I have created a custom Element, and now I am trying to register it so I can call ElementFactory.make to get the element. I have called Gst.registerClass(CustomElement.class) to register it, and I have a GTYPE_NAME and GST_NAME field in the class, but when I call ElementFactory.make with the proper factoryName, I get the following exception:

java.lang.IllegalArgumentException: No such Gstreamer factory: <custom element name>

How do I go about instantiating a custom element?

hauges avatar Jan 14 '19 18:01 hauges

Sorry, this isn't currently supported. Is the element written in C with a Java wrapper, or are you trying to write it entirely in Java?

neilcsmith-net avatar Jan 14 '19 19:01 neilcsmith-net

The element is written entirely in Java. It is based on an element I have written in python. Would it be possible to use that element if I create a Java wrapper for that?

hauges avatar Jan 14 '19 19:01 hauges

OK, will need to look into how we support this, or whether we already can. I won't be working on the library until next week, so if you can get me a basic example of what you're trying to do (could be a simple pass-through element, but in the way you're trying to do this) I'll take a look.

neilcsmith-net avatar Jan 14 '19 19:01 neilcsmith-net

Ok, here is a very basic version of what I am trying to do:

public class CustomElement extends Element {

    public static final String GTYPE_NAME = "CustomElement";
    public static final String GST_NAME = "customelement";

    public CustomElement(Initializer init) {
        super(init);
    }

    public CustomElement(String name) {
        this(makeRawElement(GST_NAME, name));
    }

    // Method overrides hidden
}
public class PipelineRunner implements Runnable {

    @Override
    public void run() {
        Gst.init();
        Gst.registerClass(CustomElement.class);

        Element appSrc = ElementFactory.make(AppSrc.GST_NAME, AppSrc.GST_NAME);
        Element customElement = ElementFactory.make(CustomElement.GST_NAME, CustomElement.GST_NAME);
        Element appSink = ElementFactory.make(AppSink.GST_NAME, AppSink.GST_NAME);

        Pipeline pipeline = new Pipeline();
        pipeline.addMany(appSrc, customElement, appSink);
        Element.linkMany(appSrc, customElement, appSink);

        pipeline.play();
    }
}

hauges avatar Jan 14 '19 19:01 hauges

@neilcsmith-net, I wasn't entirely certain as to whether you saying "will need to look into how we support this, or whether we already can" was in reference to creating a custom element entirely in java, or to creating a java wrapper for an element written in C or python. If I already have a python custom element, do you know if I could load this into the gstreamer java library?

EDIT: I realize now that a python element could not work, but what about loading a custom element written in C?

hauges avatar Jan 15 '19 12:01 hauges

@hauges you can load any registered element via ElementFactory.make(..) and interact with it. You can of course wrap the returned Element to provide your own API. It is not currently possible to create custom Element sub-classes from outside the library, but it is being worked on.

We should be able to provide the ability to create a custom element from Java, but I think we're missing some necessary things here, or at least I definitely haven't looked at doing this since the 0.10 bindings were forked.

neilcsmith-net avatar Jan 21 '19 14:01 neilcsmith-net