Unusual intermittent error in video (GStreamer)

I have a project that runs Python 2.7, PyGTK 2.24 and the latest version of PyGST.

I get a weird intermittent error in the following code. At the first longer error, the video will play just fine, and the error will only appear after I close the video window. The second prevents the opening of the window.

import pygtk pygtk.require('2.0') import gtk, pango import pygst pygst.require('0.10') import gst import Trailcrest import os, sys class Video: def __init__(self): def on_message(bus, message): if message.type == gst.MESSAGE_EOS: # End of Stream player.set_state(gst.STATE_NULL) elif message.type == gst.MESSAGE_ERROR: player.set_state(gst.STATE_NULL) (err, debug) = message.parse_error() print "Error: %s" % err, debug def on_sync_message(bus, message): if message.structure is None: return False if message.structure.get_name() == "prepare-xwindow-id": if sys.platform == "win32": win_id = videowidget.window.handle else: win_id = videowidget.window.xid assert win_id imagesink = message.src imagesink.set_property("force-aspect-ratio", True) imagesink.set_xwindow_id(win_id) win = gtk.Window() win.set_resizable(False) win.set_has_frame(False) win.set_position(gtk.WIN_POS_CENTER) fixed = gtk.Fixed() win.add(fixed) fixed.show() videowidget = gtk.DrawingArea() fixed.put(videowidget, 0, 0) videowidget.set_size_request(640, 480) videowidget.show() # Setup GStreamer player = gst.element_factory_make("playbin", "MultimediaPlayer") bus = player.get_bus() bus.add_signal_watch() bus.enable_sync_message_emission() #used to get messages that GStreamer emits bus.connect("message", on_message) #used for connecting video to your application bus.connect("sync-message::element", on_sync_message) player.set_property("uri", "file://" + os.getcwd() + "/VID/SEQ-GAME-OPEN.ogv") player.set_state(gst.STATE_PLAYING) win.show() def main(): gtk.gdk.threads_init() gtk.main() return 0 if __name__ == "__main__": Video() main() 

The program "Video.py" received an error of the X Window system. This probably reflects a bug in the program. Error: β€œBadIDChoice (invalid resource identifier selected for this connection) '. (More: serial number 373 error_code 14 request_code 1 minor_code 0) (Note for programmers: usually X errors are reported asynchronously; that is, after an error you will receive a message about to debug your program, run it with the --sync command line switch to change this behavior, then you can get a meaningful return line from your debugger if you break the gdk_x_error () function.)

Quick note about this ... I followed the instructions and ran "python Video.py --sync" on the command line (I'm on Kubuntu), and I got this message "AGAIN."

Here's another mistake - one that generally prevents playback.

python: ../../ src / xcb_io.c: 221: poll_for_event: Assertion `(((long) (event_sequence) - (long) (dpy-> request)) <= 0) 'failed. Canceled

They will literally alternate, although not perfectly. I could get the first three, two second, one first, one second, two first, etc. It is always different.

What is the devil here?

+4
source share
1 answer

You need to sync with server X to get xid windows.

Here's how:

  def on_sync_message(bus, message): if message.structure is None: return False if message.structure.get_name() == "prepare-xwindow-id": gtk.gdk.threads_enter() gtk.gdk.display_get_default().sync() win_id = videowidget.window.xid imagesink = message.src imagesink.set_property("force-aspect-ratio", True) imagesink.set_xwindow_id(win_id) gtk.gdk.threads_leave() 
+3
source

All Articles