Hi everyone,

I am migrating a old code written with GTK+ 2.X to GTK 3+ for play a .ogv
video with gstreamer.

The problem seems that the signal "sync-message::element" is never launched
(but if it is launched sync-message).
So, as result we cannot attach a Gtk.DrawingArea() inside of another window
because I dont get never the window.xid

This is the old code for GTK+ 2.x working perfectly:


import pygtk
pygtk.require('2.0')
import gtk
import pygst
pygst.require('0.10')
import gst
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

                gtk.gdk.threads_enter()
                gtk.gdk.display_get_default().sync()
                imagesink = message.src
                imagesink.set_property("force-aspect-ratio", True)
                imagesink.set_xwindow_id(win_id)
                gtk.gdk.threads_leave()

        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://" + "/SOME/PATH/SOMEFILE.ogv")
        player.set_state(gst.STATE_PLAYING)

        win.show()

def main():
    gtk.gdk.threads_init()
    gtk.main()
    return 0

if __name__ == "__main__":
    Video()
    main()
------------------------

And this is the new code for GTK+ 3 not working properly because xid it is
not attached creating another window:

import gi
gi.require_version('Gtk', '3.0')

from gi.repository import Gtk
from gi.repository import Gst
from gi.repository import Gdk

import os, sys

class Video:

    def __init__(self):

        win = Gtk.Window()
        win.set_resizable(False)
        #win.set_has_frame(False) I dont know the name of method on gtk3 so
comment this
        #win.set_position(Gtk.WIN_POS_CENTER) same but with the constant

        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
        Gst.init_check(None)
        self.player = Gst.ElementFactory.make("playbin", "MultimediaPlayer")
        self.player.set_state(Gst.State.NULL)
        bus = self.player.get_bus()
        bus.add_signal_watch()
        bus.enable_sync_message_emission()
        #used to get messages that GStreamer emits
        bus.connect('message::eos', self.on_message_eos)
        bus.connect('message::error', self.on_message_error)
        #used for connecting video to your application
        bus.connect("sync-message::element", self.on_sync_message)
        self.player.set_property("uri", "file://" +
"/SOME/PATH/SOMEFILE.ogv")
        self.player.set_state(Gst.State.PLAYING)

        win.show()
    def on_message_eos(self, bus, message):
        # End of Stream
        self.player.set_state(Gst.State.NULL)

    def on_message_error(self, bus, message):
        # End of Stream
        self.player.set_state(Gst.State.NULL)
        print 'Error'

    def on_sync_message(self, bus, message):
        print "hola"
        """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

            Gdk.threads_enter()
            Gdk.display_get_default().sync()
            imagesink = message.src
            imagesink.set_property("force-aspect-ratio", True)
            imagesink.set_xwindow_id(win_id)
            Gdk.threads_leave()"""

def main():
    Gdk.threads_init()
    Gtk.main()
    return 0

if __name__ == "__main__":
    Video()
    main()
---

So why GTK+ 3 not launch properly the sync-message::element?

Regards
Angel
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to