Callback from RTSP Stream

257 views
Skip to first unread message

Yeipi

unread,
Apr 21, 2010, 1:32:34 PM4/21/10
to gstreamer-java
Hi everybody,

I'm trying to generate a callback triggered when new frame is
generated on gstr-java, anybody has an example doing something
similar? The source is an RTSP+HTTP video.

Thanks in advance,

Yeipi

--
You received this message because you are subscribed to the Google Groups "gstreamer-java" group.
To post to this group, send email to gstream...@googlegroups.com.
To unsubscribe from this group, send email to gstreamer-jav...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gstreamer-java?hl=en.

Tal Shalif

unread,
Apr 21, 2010, 2:09:58 PM4/21/10
to gstream...@googlegroups.com

You can use an identity element just before the video sink and set a HANDOFF listener on it to get access to data buffers.

Juan Pablo Sabadini

unread,
May 4, 2010, 5:50:17 PM5/4/10
to gstream...@googlegroups.com
Tal and everybody,

First of all thanks to anybody who spend some time to read this post. Any help would be appreciated .

It's being a while from my last comment in this post. I was reading gstreamer docs. Now it's more clear what I must do (theorically speaking, I have no implementation expirience with gstreamer-java).

Briefly, I want "to be called" by a method that I observe (or listen) when a complete frame is arrived from a network source. This source is a network camera, that delivers the video stream from an URL like this: rtsp://root:ro...@10.0.10.25/mpeg4/1/media.amp .

So basically must create a src element, a decodebin element, a ffmpegcolorspace element, an identity element and finally a videosink element (for video rendering on screen). Once created these elements I must link this elements (addMany() method needed here?) in order to create the desired pipeline. At this point I must set "signals-handoff" property to true to enable handoff callbacks. As I see in many examples I must implement org.gstreamer.Element.HANDOFF interface and implement the "public void handoff(Element element, Buffer buffer, Pad pad)" to add my custom procedure in handoff callback. At this point I am right?

I have two questions: 1) How I should connect the identity element before the video sink? and 2) Gstreamer docs said that Probe callback signal is functionally a very similar to Identity, they differ mainly on implementation and dynamic behaviors and overheading (Probe have less overhead and are more dynamic because their removing/adding handlers). So the question is: Is better to implement the frame grabbing with Probe? I such case, is there any examples with a callback implemented with Probe?

I try, with no success, connect a handoff to a pipeline. Here is the code:

Main class:

public class RTSPClient2 {
   
    public static void main(String[] args) {

        args = Gst.init("PipelineLauncher", args);

        final String def = "rtspsrc location=rtsp://root:ro...@10.0.10.25/mpeg4/1/media.amp latency=0 ! decodebin ! ffmpegcolorspace name=testp";
        final Pipeline pipe = Pipeline.launch(def);
        RtspHandoff rtspHandoff = new RtspHandoff(320, 240);
        pipe.set("signals-handoff", Boolean.TRUE);
        pipe.connect(rtspHandoff);
       
//        final Element rtsp = pipe.getElementByName("src");
//        rtsp.set("latency", 6000);

        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                // Create the video component and link it in
                VideoComponent videoComponent = new VideoComponent();
                Element videosink = videoComponent.getElement();
               

                pipe.add(videosink);
                pipe.getElementByName("testp").link(videosink);
                pipe.setState(State.PAUSED);
               
                if(pipe.isPlaying())
                    System.out.println("Pipeline playing");
                else
                    System.out.println("Pipeline not playing");
               
                // Start the pipeline processing
                pipe.play();
                pipe.setState(State.PLAYING);

                if(pipe.isPlaying())
                    System.out.println("Pipeline playing");
                else
                    System.out.println("Pipeline not playing");
               

                // Now create a JFrame to display the video output
                JFrame frame = new JFrame("Swing Video Test");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(videoComponent, BorderLayout.CENTER);
                videoComponent.setPreferredSize(new Dimension(320, 240));
                frame.pack();
                frame.setVisible(true);
            }
        });
        Gst.main();
        pipe.setState(State.NULL);
    }
}

RtspHandoff class:

import java.util.Arrays;

import org.gstreamer.Buffer;
import org.gstreamer.Element;
import org.gstreamer.Pad;
import org.gstreamer.Element.HANDOFF;

public class RtspHandoff implements HANDOFF{
    private int width;
    private int height;
   
    public RtspHandoff(int width, int height){
        this.width = width;
        this.height = height;
    }
   
    @Override
    public void handoff(Element element, Buffer buffer, Pad pad) {
        byte color = 0;
        byte[] data = new byte[width * height * 2];
        System.out.println("HANDOFF: Element=" + element.getNativeAddress()
                + " buffer=" + buffer.getNativeAddress()
                + " pad=" + pad.getNativeAddress());
        Arrays.fill(data, color++);
        buffer.getByteBuffer().put(data, 0, data.length);
    }

    //GETTERS AND SETTERS
   
    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }
}

And I'm getting the following exception:

Exception in thread "main" java.lang.NullPointerException
    at com.sun.jna.Structure.useMemory(Structure.java:224)
    at com.sun.jna.Structure.useMemory(Structure.java:212)
    at org.gstreamer.lowlevel.GObjectAPI$GParamSpec.<init>(GObjectAPI.java:396)
    at org.gstreamer.GObject.findProperty(GObject.java:628)
    at org.gstreamer.GObject.set(GObject.java:85)
    at ar.example.rtsp.client.RTSPClient2.main(RTSPClient2.java:29)

I know that I missing something obvious, but still don't get it...

Regards,

2010/4/21 Tal Shalif <tsh...@gmail.com>

Tal Shalif

unread,
May 5, 2010, 3:28:05 AM5/5/10
to gstream...@googlegroups.com
Your handoff listener you connect to the identity element, not the
pipeline. Also, please use Pipeline.launch() to make your code less
verbose.
Reply all
Reply to author
Forward
0 new messages