Chaining pad_added callback for multiple dynamic pad elements

问题描述 投票:0回答:0

我正在使用 rtsp 流,其中一个频道是视频,其他频道可以是音频或 onvif 数据。

我需要检测第二个 rtspsrc pad(channel) 是否是音频,然后设置管道来解码音频流。

首先我通过添加

connect_pad_added
来检测rtspsrc中新添加的pad是否是音频。当它是音频时,我创建一个 decodebin,然后附加到
src_pad
并添加另一个
connect_pad_added
到 decodebin 这次接收
src_pad
,然后创建其余的管道。

不知何故第一个

connect_pad_added
被调用但不是我连接到解码箱的那个。

像那样链接

pad_added
连接不好吗?在这种情况下,更好的方法是什么?

这是我正在做的代码片段。

从通过

parse_launch
启动的管道中,我得到了 rtspsrc 元素
let rtspsrc=pipeline.by_name("basesrc")
.

rtspsrc.connect_pad_added(|src, src_pad| {
    // get the pad struct and detect media type
    let media_type = src_pad.current_caps().and_then(|caps| {
        let new_pad_struct = caps
            .structure(0)
            .expect("Failed to get first structure of caps for audio");
        for i in 0..new_pad_struct.n_fields() {
            match new_pad_struct.nth_field_name(i).unwrap() {
                "media" => {
                    // check if field value starts with audio
                    audio = true
                }
                _ => {}
            }
        }
        Some(audio)
    });

    match media_type {
        Some(is_audio) => {
            if is_audio {
                let audio_decode = gst::ElementFactory::make("decodebin", None)
                    .expect("unable to create decodebin");
                pipeline
                    .add_many(&[&audio_decode])
                    .expect("unable to add audio decoder to pipeline bin");
                let sink_pad = audio_decode.static_pad("sink").ok_or(/*...*/);
                src_pad
                    .link(&sink_pad)
                    .expect("unable to link src_pad to audio_decode sinkpad");
                audio_decode.connect_pad_added(move |dbin, audio_src_pad| {
                    // setup the rest of pipeline audiodecoder ! encoder ! tee name=t t.! hlssink2.. t. ! hlssink2
                    //.....
                });
            }
        }
        None => {
            log::warn!("failed to get media_type from pad after pad added");
        }
    }
});
rust gstreamer gstreamer-rs
© www.soinside.com 2019 - 2024. All rights reserved.