Melonski
Melonski

Reputation: 35

GStreamer-Java: RTSP-Source to UDP-Sink

I'm currently working on a project to forward (and later transcode) a RTP-Stream from a IP-Webcam to a SIP-User in a videocall.

I came up with the following gstreamer pipeline:

  gst-launch -v rtspsrc location="rtsp://user:pw@ip:554/axis-media/media.amp?videocodec=h264" ! rtph264depay ! rtph264pay ! udpsink sync=false host=xxx.xxx.xx.xx port=xxxx

It works very fine. Now I want to create this pipeline using java. This is my code for creating the pipe:

    Pipeline pipe = new Pipeline("IPCamStream");

    // Source
    Element source = ElementFactory.make("rtspsrc", "source");
    source.set("location", ipcam);

    //Elements
    Element rtpdepay = ElementFactory.make("rtph264depay", "rtpdepay");
    Element rtppay = ElementFactory.make("rtph264pay", "rtppay");

    //Sink
    Element udpsink = ElementFactory.make("udpsink", "udpsink");
    udpsink.set("sync", "false");
    udpsink.set("host", sinkurl);
    udpsink.set("port", sinkport);


    //Connect
    pipe.addMany(source, rtpdepay, rtppay, udpsink);
    Element.linkMany(source, rtpdepay, rtppay, udpsink);


    return pipe;

When I start/set up the pipeline, I'm able to see the input of the camera using wireshark, but unfortunately there is no sending to the UDP-Sink. I have checked the code for mistakes a couple of times, I even set a pipeline for streaming from a file (filesrc) to the same udpsink, and it also works fine.

But why is the "forwarding" of the IP-Cam to the UDP-Sink not working with this Java-Pipeline?

Upvotes: 1

Views: 3419

Answers (1)

mpr
mpr

Reputation: 3378

I haven't used the Java version of GStreamer, but something you need to be aware of when linking is that sometimes the source pad of an element is not immediately available.

If you do gst-inspect rtspsrc, and look at the pads, you'll see this:

Pad Templates: 
  SRC template: 'stream_%u'
    Availability: Sometimes
    Capabilities:
      application/x-rtp
      application/x-rdt

That "Availability: Sometimes" means your initial link will fail. The source pad you want will only appear after some number of RTP packets have arrived.

For this case you need to either link the elements manually by waiting for the pad-added event, or what I like to do in C is use the gst_parse_bin_from_description function. There is probably something similar in Java. It automatically adds listeners for the pad-added events and links up the pipeline.

gst-launch uses these same parse_bin functions, I believe. That's why it always links things up fine.

Upvotes: 3

Related Questions