我有一个回调,由 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/