【发布时间】:2019-10-27 07:35:10
【问题描述】:
我有一个 PyQt 应用程序,当用户按下按钮并侦听该管道总线上的消息时,它会创建一个 GStreamer 管道。
import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst, GLib
from PyQt5.QtWidgets import QApplication, QPushButton
Gst.init()
pipeline = None
def on_pipeline_message(bus, message):
print("Got a message from pipeline:", message.type)
return True
def on_button_press():
global pipeline
pipeline = Gst.parse_launch("videotestsrc ! xvimagesink")
pipeline.bus.add_watch(GLib.PRIORITY_DEFAULT, on_pipeline_message)
pipeline.set_state(Gst.State.PLAYING)
app = QApplication([])
playback_button = QPushButton("Press to Start Playback", None)
playback_button.clicked.connect(on_button_press)
playback_button.show()
app.exec()
上面的代码按预期工作,我的on_pipeline_message 回调函数被调用。但是,如果我决定将管道创建代码移动到单独的 QThread:
class MakePipelineThread(QThread):
def run(self):
global pipeline
pipeline = Gst.parse_launch("videotestsrc ! xvimagesink")
pipeline.bus.add_watch(GLib.PRIORITY_DEFAULT, on_pipeline_message)
pipeline.set_state(Gst.State.PLAYING)
...并在按下按钮时启动 QThread:
make_pipeline_thread = MakePipelineThread()
def on_button_press():
make_pipeline_thread.start()
我的on_pipeline_message 回调不再运行。为什么我在单独的 QThread 中创建管道很重要?如何继续接收消息?
【问题讨论】:
标签: python pyqt gstreamer glib pygobject