Python-GStreamer:使用固定参数访问回调函数内的类成员

标签 python python-3.x gstreamer python-gstreamer

我有一个回调,由 GStreamer-Python 绑定(bind)提供,它接受固定数量的参数。这是API:add_probe 我从类函数内部调用这个函数。下面是伪代码:

class Example:
   def __init__(self):
        thread = threading.Thread(target=self.run)
        thread.start()

   def run(self):
        #if external event
        self.idsrcpad = identity.get_static_pad("src")  #get source pad 
        self.idsrcpad.add_probe(Gst.PadProbeType.IDLE,self.modify_pipeline)


   def modify_pipeline(pad,info,self):
        #access self.idsrcpad
        self.idsrcpad.unlink(...)

访问 self.idsrcpad 时出现错误,指出 idsrcpad 不是 self 的成员。

以下question地址,一个类似的问题,但是问题中的回调函数没有固定数量的参数。就我而言,回调函数的参数是固定的。这是 add_probe 的更详细描述功能。

谁能告诉我我在这里做错了什么。

最佳答案

回调的正确语法是:

 def modify_pipeline(self,pad,info):

通过这个新定义,self 可以在函数内部使用。

关于Python-GStreamer:使用固定参数访问回调函数内的类成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51893053/

相关文章:

python-3.x - 通过计算数组中的字符串并添加数组中的值来填充 pandas 数据框

python - 如何只为python3.7安装pip?

c++ - FreeImage 图像颜色错误

android - 如何使用gradle以编程方式将libc++ _ shared.so包含到我的APK中?

python - 如何从列表中检索项目 'n'?

Python - 用户通过 CGI 输入。线程和读取文件

python - 当我尝试以客户端身份请求时,DRF 通过 403 错误响应我 [客户端凭据授予]

Python 脚本无法通过 Apache2 上的 CGI 运行

python-3.x - liblas:如何获取 las 格式的点云点的颜色

python - GStreamer 如何从流中提取视频帧?