0

我可以从命令行运行一个非常简单的启动管道,因此:

gst-launch-1.0 videotestsrc ! ximagesink

并且,从 开始gst-inspect-1.0ximagesink似乎支持该GstVideoOverlay界面,以便我可以将其绑定到特定的 Gtk 小部件。

但是,当尝试从我碰巧在网上发现的一些代码中执行此操作时,似乎管道不被视为垃圾箱(因此,没有为其提供小部件 ID)。

执行此操作的代码如下,首先创建管道并将其设置为捕获总线消息:

Gst.Element playbin = Gst.Parse.Launch("videotestsrc ! ximagesink");
Gst.Bus bus = playbin.Bus;
bus.AddSignalWatch();
bus.Message += MsgCallback;

然后实际处理总线消息:

private void MsgCallback(object o, MessageArgs args) {
    // Only care about window ID binding requests.

    Gst.Message msg = args.Message;
    if (! Gst.Video.Global.IsVideoOverlayPrepareWindowHandleMessage(msg))
        return;

    // Get source of message.

    Gst.Element src = msg.Src as Gst.Element;
    if (src == null)
        return;

    // Find element supporting interface and notify it to bind.

    Gst.Element ov = null;
    if (src is Gst.Bin) {
        ov = ((Gst.Bin) src).GetByInterface(VideoOverlayAdapter.GType);
        VideoOverlayAdapter ad = new VideoOverlayAdapter(ov.Handle);
        ad.WindowHandle = windowXId;
    }
}

现在,由于某种原因,src is Gst.Bin是错误的,这意味着windowXId(我之前设置的小部件 ID)永远不会与 GStreamer 通信。

但是,如果我提供playbin管道(playbin uri=XYZZY videosink='videoconvert ! videoflip method=none ! videoconvert ! autovideosink'如果您有兴趣),它可以正常工作。

据我从文档中可以看出Gst.Parse.Launch(),它应该给我一个管道,它是一个 bin 的特例,按照这里(在修复了残暴的语法之后):

NULL成功或失败时返回一个新元素。如果管道描述指定了多个顶级元素,则将所有元素放入 aGstPipeline中,然后返回。

我很确定,videotestsrc并且ximagesink是两个独立的顶级元素,但是,当我添加以下代码时,在检查之后srcnull

Console.WriteLine("is bin      " + (src is Gst.Bin));
Console.WriteLine("is element  " + (src is Gst.Element));
Console.WriteLine("is pipeline " + (src is Gst.Pipeline));
Console.WriteLine(type is      " + src.GetType());

我懂了:

is bin      False
is element  True
is pipeline False
type is     Gst.Element

对于有问题的videotestsrc管道,以下是好的管道playbin

is bin      True
is element  True
is pipeline False
type is     Gst.Bin

因此,尽管文档说明了什么,但一切都指向给出元素而不是垃圾箱的问题。

我在这里想念什么?会导致不同行为的两条管道之间有什么区别?

4

1 回答 1

1

好的,事实证明该Gst.Parse.Launch函数实际上在返回一个管道。如果您在创建 bin 后立即复制这些检查语句,则可以看到这一点:

Gst.Element playbin = Gst.Parse.Launch("videotestsrc ! ximagesink");
Console.WriteLine("is bin      " + (playbin is Gst.Bin));
Console.WriteLine("is element  " + (playbin is Gst.Element));
Console.WriteLine("is pipeline " + (playbin is Gst.Pipeline));
Console.WriteLine(type is      " + playbin.GetType());

你会看到:

is bin      True
is element  True
is pipeline True
type is     Gst.Pipeline

只是,当我们在回调中获取消息时,源似乎被设置为一个元素。我实际上还没有弄清楚为什么消息源作为一个元素(甚至它是哪个元素)通过,但我至少有一个解决方法,部分归功于我的高级智能,但主要是因为偷偷地看看 Banshee 的方式它 :-)

事实证明,回调可以简单地直接访问 bin,而不是试图将其从源中取出。这适用于我的情况,因为我每个实例只有一个视频流(bin)。如果你有多个,这可能会有点困难。

为此,您首先创建playbin一个成员变量(如果还没有),然后您可以修改回调:

private void MsgCallback(object o, MessageArgs args) {
    // Only care about window ID binding requests.

    Gst.Message msg = args.Message;
    if (! Gst.Video.Global.IsVideoOverlayPrepareWindowHandleMessage(msg))
        return;

    // Get instance bin, interface element, then notify it to bind.

    Gst.Bin src = (Gst.Bin)(this.playbin);
    if (src == null) return;

    Gst.Element ov = src.GetByInterface(VideoOverlayAdapter.GType);
    if (ov == null) return;

    VideoOverlayAdapter ad = new VideoOverlayAdapter(ov.Handle);
    if (ad == null) return;

    ad.WindowHandle = windowXId;
}
于 2016-03-01T01:59:46.670 回答