首页 > 解决方案 > 有没有办法通过 udp 检查来自源的 rtp 流?

问题描述

我已经实现了通过UDP从摄像头源获取视频流的代码。我需要检查源(相机)是否发送数据或活着。有没有办法检查使用Gstreamer或其他与套接字编程相关的方式?

在 Gstreamer 中,有几个有用的侦听器来检查管道状态。其中之一是流结束通知,但它无法检查 udp 源管道状态。

来自文档:

流结束通知:当流结束时发出。管道的状态不会改变,但进一步的媒体处理将停止。应用程序可以使用它跳到播放列表中的下一首歌曲。在流结束后,也可以在流中回溯。播放将自动继续。此消息没有特定参数。

    Pipeline pipeline = new Pipeline("monitoring-pipe");

    pipeline.getBus().connect((Bus.ERROR) this);
    pipeline.getBus().connect((Bus.WARNING) this);
    pipeline.getBus().connect((Bus.STATE_CHANGED) this);
    pipeline.getBus().connect((Bus.EOS) this);

    Element udpsrc = ElementFactory.make("udpsrc", "udpsrc");
    udpsrc.set("port", monitoringPort);

    vc.getElement().set("sync", false);

    udpsrc.setCaps(Caps
            .fromString("application/x-rtp, media=(string)video, encoding-name=(string)H264, payload=(int)101"));

    Bin bin = Gst.parseBinFromDescription(
            "rtph264depay ! video/x-h264, stream-format=byte-stream, profile=high ! h264parse ! queue ! avdec_h264 ! queue2 ! videoconvert",
            true);

    pipeline.addMany(udpsrc, bin, vc.getElement());
    Element.linkMany(udpsrc, bin, vc.getElement());

    pipeline.play();
    pipeline.setState(State.PLAYING);

提前致谢。

标签: udpgstreamergstreamer-1.0

解决方案


The watchdog element watches buffers and events flowing through a pipeline. If no buffers are seen for a configurable amount of time, a error message is sent to the bus.

To use this element, insert it into a pipeline as you would an identity element. Once activated, any pause in the flow of buffers through the element will cause an element error. The maximum allowed pause is determined by the timeout property.

This element is currently intended for transcoding pipelines, although may be useful in other contexts.

watchdog element could be used to detect an error on stream. Bus.MESSAGE listener catch if the server side streaming dead or closed. Unfortunately it is triggered only when stream is closed. It won't be triggered when stream starts again but still it can be utilized with few changes (trigger another listener in that)

here is the code which has few changes:

Bin bin = Gst.parseBinFromDescription(
            "watchdog ! rtph264depay ! video/x-h264, stream-format=byte-stream, 
            profile=high ! h264parse ! queue ! avdec_h264 ! queue2 ! videoconvert",
            true);


pipeline.getBus().connect((Bus.MESSAGE) this);



@Override
public void busMessage(Bus bus, Message message) {
    if (message.getType().equals(MessageType.ERROR)) {
        //here you can get when stream has stopped 
        //and trigger another listener like 
        //state change listener to check or establish connection

        pipeline.setState(State.PAUSED);
        pipeline.setState(State.PLAYING);
    }
}

推荐阅读