我如何检测 .connect_pad_added() template = video_%u?

How do I detect .connect_pad_added() template = video_%u?

使用 gstreamer Rust 绑定,我如何测试已添加的 sometimes pad 是否来自模板 video_%uaudio_%u

例如,使用qtdemuxm,下面添加的pad为视频调用一次,为音频调用一次

.connect_pad_added(move |demux, src_pad| {

根据绑定文档看来

get_property_name_template(&self)

但这失败了

.connect_pad_added(move |demux, src_pad| {
let templateName = get_property_name_template(&src_pad);
|                  ^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

更手动的方法是先获取名称,然后再获取名称,但是有没有更直接的方法?

println!(
        "Received new pad {}",
        src_pad.get_name()
    );

我也试过将垫子与模板匹配

.connect_pad_created('video_%u', src_pad{ ....

但我找不到匹配模板字符串的方法。

您至少有两个选择:

  1. 您检查 pad 名称是否以 audio_video_ 开头。您可以通过 get_name()
  2. 获取名称
  3. 您通过 get_pad_template() and then check the name template via get_property_name_template()
  4. 从 pad 中获取 pad 模板

理想情况下,您不会依赖于模板名称(除非您明确使用特定的元素工厂,例如此处的 qtdemux),而是通过 get_current_caps() and if they are not available yet get notified once they change via connect_notify(Some("caps"), ...) 查看 pad 上的大写字母。