GStreamer Java:RTSP源到UDP接收器

GStreamer Java:RTSP源到UDP接收器,java,gstreamer,pipeline,Java,Gstreamer,Pipeline,我目前正在做一个项目,在视频通话中把一个RTP流从一个IP网络摄像头转发给一个SIP用户 我提出了以下gstreamer管道: 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 它工作得很好。现在我想用j

我目前正在做一个项目,在视频通话中把一个RTP流从一个IP网络摄像头转发给一个SIP用户

我提出了以下gstreamer管道:

  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
它工作得很好。现在我想用java创建这个管道。这是我创建管道的代码:

    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;
当我启动/设置管道时,我可以使用wireshark查看摄像头的输入,但不幸的是,没有发送到UDP接收器。我已经检查了几次代码中的错误,甚至设置了一个从文件(filesrc)到同一个udpsink的流的管道,它也可以正常工作


但是为什么IP Cam到UDP接收器的“转发”不适用于此Java管道?

我没有使用过Java版本的GStreamer,但是在链接时需要注意的是,有时元素的源pad不是立即可用的

如果您检查rtspsrc,并查看焊盘,您将看到:

Pad Templates: 
  SRC template: 'stream_%u'
    Availability: Sometimes
    Capabilities:
      application/x-rtp
      application/x-rdt
“可用性:有时”意味着您的初始链接将失败。您想要的源焊盘只有在一些RTP数据包到达后才会出现

对于这种情况,您需要通过等待添加的pad事件手动链接元素,或者我喜欢在C中使用gst\u parse\u bin\u from\u description函数。Java中可能也有类似的东西。它会自动为pad添加的事件添加侦听器,并链接管道


我相信gst启动使用了这些相同的parse_bin函数。这就是为什么它总是把事情联系得很好。

PAD_附加事件实际上解决了这个问题。我需要将源代码链接到以下元素。谢谢你的解决方案!稍后我可能会发布一些代码示例。