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,