首页 > 解决方案 > GStreamer:动态删除混合器 src 元素冻结管道

问题描述

我正在尝试使用 gstaudiomixer 从我动态添加和删除的两个源元素中混合音频。

+---------+    +------------+
| source1 |--->|            |
+---------+    |            |    +-----------+
               | audiomixer |--->| audiosink |
+---------+    |            |    +-----------+
| source2 |--->|            |
+---------+    +------------+

动态添加元素(使用请求垫和垫模板)似乎按预期工作。但是,当动态移除焊盘时会导致管道冻结。

这是我用来删除元素的代码:

public void remove(Gst.Element? element)
{
    /* Removes the element from the pipeline */
    if (element == null) return;

    element.set_state(Gst.State.NULL);  // Stop it from streaming data
    element.unlink(this.mixer);
    this.pipeline.remove(element);
}

这是我的第二次尝试,试图阻止垫:

public void remove(Gst.Element? element)
{
    /* Removes the element from the pipeline */
    if (element == null) return;

    element.get_static_pad("src").get_peer().add_probe(Gst.PadProbeType.IDLE, (pad, info) => {
        element.set_state(Gst.State.NULL);  // Stop it from streaming data
        element.unlink(this.mixer);
        this.pipeline.remove(element);
        return Gst.PadProbeReturn.REMOVE;
    });
}

这样做的正确方法是什么?

标签: gstreamervala

解决方案


如果要从管道中更改或删除元素,请确保停止将缓冲区推送到元素,向元素发送 eos 并添加新元素并继续。它在这个链接中得到了很好的解释


推荐阅读