【问题标题】:Using pygi, how can I override a virtual method from a GObject class that has the same name as a virtual method in its base class?使用 pygi,如何从 GObject 类中覆盖与其基类中的虚拟方法同名的虚拟方法?
【发布时间】:2023-03-12 22:00:01
【问题描述】:

在 Python 中使用 GObject Introspection,我正在尝试创建一个自定义 PushSrc 元素,该元素需要覆盖 createfill 虚拟方法,但没有成功。

问题似乎在于PushSrc 及其基类BaseSrc 都具有这些虚拟方法。

换句话说,这段代码:

import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstBase', '1.0')
from gi.repository import GstBase, Gst, GObject
Gst.init(None)


class MyPushSrc(GstBase.PushSrc):
    def __init__(self):
        self.add_pad_template(Gst.PadTemplate.new("src",
                                                  Gst.PadDirection.SRC,
                                                  Gst.PadPresence.ALWAYS,
                                                  Gst.Caps.new_any()))
        GstBase.PushSrc.__init__(self)

    def do_fill(self, buf):
        return Gst.FlowReturn.OK


GObject.type_register(MyPushSrc)

结果如下:

Traceback (most recent call last):
  File "mypushsrc.py", line 8, in <module>
    class MyPushSrc(GstBase.PushSrc):
  File "/usr/lib/python3/dist-packages/gi/types.py", line 223, in __init__
    cls._setup_vfuncs()
  File "/usr/lib/python3/dist-packages/gi/types.py", line 120, in _setup_vfuncs
    ambiguous_base.__info__.get_name()
TypeError: Method do_fill() on class GstBase.PushSrc is ambiguous with methods in base classes GstBase.PushSrc and GstBase.BaseSrc

不幸的是,PushSrc 中的do_fillBaseSrc 中只有一个参数,而BaseSrc 中只有三个参数这一事实不足以自省区分这些虚拟方法。那么,我该怎么做才能覆盖这个方法呢?

【问题讨论】:

    标签: python gstreamer gobject python-gstreamer gobject-introspection


    【解决方案1】:

    我认为这是 GStreamer Python 绑定中的一个错误,目前无法解决。请参阅upstream bug report。如果有人解决这个问题,那里可能会提供解决方案。

    【讨论】:

      猜你喜欢
      • 2015-06-13
      • 1970-01-01
      • 2011-09-30
      • 2013-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多