2016-07-05 50 views
0

定义的GStreamer视频窗口中使用的Gstreamer“playbin”在Python中“set_window_handle”代码告诉的Gstreamer在窗口ID来呈现视频:问题上Raspbian

这个工作在标准Linux的伴侣,并在树莓派3运行Ubuntu-Mate。然而,运行在相同的Raspberry上但运行最新的Raspbian操作系统,Gstreamer完全忽略了在特定窗口中运行的指令,而是创建了自己的窗口,在屏幕中间出现。
如果新窗口能够被操纵,移动和/或调整大小,但不能这样做,那么这不成问题。它不能移动,不能关闭,鼠标指针消失。
有谁知道这是Raspbian,X windows还是Gstreamer中的一个bug,还是我没有发现为了在Raspbian OS上工作而必须实施的一些改变?
这是一个最小的工作示例,它说明了上述行为。

#!/usr/bin/env python 
import os,time 
import wx 
import gi 
gi.require_version('Gst', '1.0') 
gi.require_version('GstVideo', '1.0') 
from gi.repository import Gst 
from gi.repository import GstVideo 

class Player(wx.App): 

    def OnInit(self): 
     window = wx.Frame(None) 
     window.SetTitle("Gstreamer Player Test") 
     window.SetSize((-1,-1)) 
     window.Bind(wx.EVT_CLOSE,self.close) 
     vbox = wx.BoxSizer(wx.VERTICAL) 
     hbox = wx.BoxSizer(wx.HORIZONTAL) 
     self.fileid = wx.TextCtrl(window,style=wx.TE_PROCESS_ENTER) 
     self.fileid.SetToolTipString("Enter full path to media file") 
     hbox.Add(self.fileid, 1) 
     self.start = wx.Button(window,label="Start") 
     hbox.Add(self.start, 0) 
     self.start.Bind(wx.EVT_BUTTON, self.control) 
     self.fileid.Bind(wx.EVT_TEXT_ENTER, self.control) 
     vbox.Add(hbox, 0, wx.EXPAND, 0) 
     self.video_window = wx.Panel(window) 
     vbox.Add(self.video_window,1,wx.EXPAND,5) 
     window.SetSizer(vbox) 
     window.Layout() 
     window.Show() 
     self.SetTopWindow(window) 
     Gst.init(None) #initialise gstreamer 
     self.player = Gst.ElementFactory.make("playbin", "player") 
     bus = self.player.get_bus() 
     bus.add_signal_watch() #hook up bus to signals from gstreamer 
     bus.enable_sync_message_emission() 
     bus.connect('message', self.on_message) 
     bus.connect('sync-message::element', self.on_sync_message) 
     return True 

    def control(self, event): 
     if self.start.GetLabel() == "Start": 
      fileid = self.fileid.GetValue() 
      if os.path.exists(fileid): 
       self.start.SetLabel("Stop") 
       fileid = "file://"+unicode(fileid) 
       self.player.set_property('uri', fileid) 
       self.player.set_state(Gst.State.PLAYING) 
      else: 
       print "File error - No such file" 
     else: 
      self.player.set_state(Gst.State.NULL) 
      self.start.SetLabel("Start") 

    def on_message(self, bus, message): 
     t = message.type 
     if t == Gst.MessageType.EOS: # media has ended 
      self.player.set_state(Gst.State.NULL) 
      self.button.SetLabel("Start") 
     elif t == Gst.MessageType.ERROR: 
      print "Player error" 
      self.player.set_state(Gst.State.NULL) 
      self.start.SetLabel("Start") 

    def on_sync_message(self, bus, message): 
     if message.get_structure() is None: 
      return True 
     message_name = message.get_structure().get_name() 
     if message_name == 'prepare-window-handle': #Assign the window id to display in 
      imagesink = message.src 
      imagesink.set_property('force-aspect-ratio', True) #Force size to fit window 
      X_id = self.video_window.GetHandle() 
      print ("Window Id:", X_id) 
      imagesink.set_window_handle(X_id) 
     return True 

    def close(self,event): 
     self.player.set_state(Gst.State.NULL) 
     time.sleep(0.1) #Allow a little time to reach Null state 
     event.Skip() 

app = Player() 
app.MainLoop() 

回答

0

答案是这是一个错误。
Bugzilla link

无论是在gstreamer还是Rpi堆栈似乎都是一个有争议的问题。
解决方法是指定playbin管道中的videosink。
因此,对于这个特定的程序应如下:

#!/usr/bin/env python 
import os,time 
import wx 
import gi 
gi.require_version('Gst', '1.0') 
gi.require_version('GstVideo', '1.0') 
from gi.repository import Gst 
from gi.repository import GstVideo 

class Player(wx.App): 

    def OnInit(self): 
     window = wx.Frame(None) 
     window.SetTitle("Gstreamer Player Test") 
     window.SetSize((-1,-1)) 
     window.Bind(wx.EVT_CLOSE,self.close) 
     vbox = wx.BoxSizer(wx.VERTICAL) 
     hbox = wx.BoxSizer(wx.HORIZONTAL) 
     self.fileid = wx.TextCtrl(window,style=wx.TE_PROCESS_ENTER) 
     self.fileid.SetToolTipString("Enter full path to media file") 
     hbox.Add(self.fileid, 1) 
     self.start = wx.Button(window,label="Start") 
     hbox.Add(self.start, 0) 
     self.start.Bind(wx.EVT_BUTTON, self.control) 
     self.fileid.Bind(wx.EVT_TEXT_ENTER, self.control) 
     vbox.Add(hbox, 0, wx.EXPAND, 0) 
     video_window = wx.Panel(window) 
     vbox.Add(video_window,1,wx.EXPAND,5) 
     window.SetSizer(vbox) 
     window.Layout() 
     window.Show() 
     self.SetTopWindow(window) 
     Gst.init(None) #initialise gstreamer 
     self.X_id = video_window.GetHandle() 
     self.player = Gst.ElementFactory.make("playbin", "player") 
#  self.ximagesink = Gst.ElementFactory.make("xvimagesink", None) 
     self.ximagesink = Gst.ElementFactory.make("ximagesink", None) 
     self.player.set_property('video-sink', self.ximagesink) 
     bus = self.player.get_bus() 
     bus.add_signal_watch() #hook up bus to signals from gstreamer 
     bus.enable_sync_message_emission() 
     bus.connect('message', self.on_message) 
     bus.connect('sync-message::element', self.on_sync_message) 
     return True 

    def control(self, event): 
     if self.start.GetLabel() == "Start": 
      fileid = self.fileid.GetValue() 
      if os.path.exists(fileid): 
       self.start.SetLabel("Stop") 
       fileid = "file://"+unicode(fileid) 
       self.player.set_property('uri', fileid) 
       self.player.set_state(Gst.State.PLAYING) 
      else: 
       print "File error - No such file" 
     else: 
      self.player.set_state(Gst.State.NULL) 
      self.start.SetLabel("Start") 

    def on_message(self, bus, message): 
     t = message.type 
     if t == Gst.MessageType.EOS: # media has ended 
      self.player.set_state(Gst.State.NULL) 
      self.button.SetLabel("Start") 
     elif t == Gst.MessageType.ERROR: 
      print "Player error" 
      self.player.set_state(Gst.State.NULL) 
      self.start.SetLabel("Start") 

    def on_sync_message(self, bus, message): 
     if message.get_structure() is None: 
      return True 
     message_name = message.get_structure().get_name() 
     if message_name == 'prepare-window-handle': #Assign the window id to display in 
      imagesink = message.src 
     #  imagesink.set_property('force-aspect-ratio', True) #Defaults anyway 
      imagesink.set_window_handle(self.X_id) 
     return True 

    def close(self,event): 
     self.player.set_state(Gst.State.NULL) 
     time.sleep(0.1) #Allow a little time to reach Null state 
     event.Skip() 

app = Player() 
app.MainLoop() 

但是,如果你得到一个宏观的LibreOffice使用“com.sun.star.comp.avmedia.Manager_GStreamer”同样的问题,这确实你没什么好处,因为Libreoffice开发者做出了和我一样的假设,并且似乎没有办法从Libreoffice中定义videosink。在这种情况下,我们只需要等到bug修复程序进入一个通用版本。

注:使用ximagesink
使用xvimagesink给出Raspbian一个错误,因为是Xv软件具有在没有适配器有一个问题。
使用glimagesink给我们留下了屏障中间的可怕窗口,看起来eglesssink已经悄悄退出服务,因为它不再包含在Raspberry的gstreamer插件中。