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

Registering a custom Element #133

Open
hauges opened this issue Jan 14, 2019 · 6 comments
Open

Registering a custom Element #133

hauges opened this issue Jan 14, 2019 · 6 comments

Comments

@hauges
Copy link

hauges commented Jan 14, 2019

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?

@neilcsmith-net
Copy link
Member

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?

@hauges
Copy link
Author

hauges commented Jan 14, 2019

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?

@neilcsmith-net
Copy link
Member

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.

@hauges
Copy link
Author

hauges commented Jan 14, 2019

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
Copy link
Author

hauges commented Jan 15, 2019

@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?

@neilcsmith-net
Copy link
Member

@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.

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