GStreamer-Java: RTSP-Source to UDP-Sink

眉间皱痕 提交于 2019-12-24 07:02:02

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/24219852/gstreamer-java-rtsp-source-to-udp-sink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!