0

I'm trying to display different gstreamer pipelines output in the same window with tkinter. I tried to create my own Frame that adds the gstreamer pipeline. I supposed I can subclass

frames.py

from tkinter import Frame, NW

import gi

# Needed for set_window_handle():
gi.require_version('GstVideo', '1.0')
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GObject, GstVideo


class GstFrame(Frame):
    def __init__(self, gst_launch_string, x, y, width, height, master=None, cnf=dict(), **kwargs):
        super(GstFrame, self).__init__(master=master, cnf=cnf, **kwargs)

        self.place(relx=x, rely=y, anchor=NW, relwidth=width, relheight=height)

        self.frame_id = self.winfo_id()

        self.player = Gst.parse_launch(gst_launch_string)
        self.player.set_state(Gst.State.PLAYING)

        self.bus = self.player.get_bus()
        self.bus.enable_sync_message_emission()
        self.bus.connect('sync-message::element', self.set_frame_handle)

    def play(self):
        self.player.set_state(Gst.State.PLAYING)

    def set_frame_handle(self, bus, message):
        if message.get_structure().get_name() == 'prepare-window-handle':
            frame = message.src
            frame.set_property('force-aspect-ratio', True)
            frame.set_window_handle(self.frame_id)


class SensorStreamFrame(GstFrame):
    def __init__(self, stream, master=None, cnf=dict(), **kwargs):
        gstreamer_launch_string = 'tcpclientsrc host={} port={} ! gdpdepay ! '\
                                  'rtph264depay ! avdec_h264 ! videoconvert ! '\
                                  'autovideosink sync=false'.format(stream.host, stream.port)

        x = stream.x
        y = stream.y
        width = stream.width
        height = stream.height

        super(SensorStreamFrame, self).__init__(gstreamer_launch_string, x, y, width, height, master, cnf, **kwargs)

utils.py from lib.frames import SensorStreamFrame

def init_players(streams, window):
    for stream in streams:
        SensorStreamFrame(stream, window)

main.py

from tkinter import Tk

from lib.frames import SensorStreamFrame
from lib.utils import init_configuration
import gi

gi.require_version('Gst', '1.0')
# Needed for set_window_handle():
gi.require_version('GstVideo', '1.0')
from gi.repository import Gst, GObject, GstVideo


window = Tk()
window.title('Eye-Track visualizer')
window.geometry('1280x960')

# Initialize Gstreamer
Gst.init(None)
GObject.threads_init()


init_configuration(window)

window.mainloop()

the init_confiuration just reads a config file and calculates sizes and positions, and the end calls init_players

I get two kinds of error like

X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)
  Major opcode of failed request:  150 (XVideo)
  Minor opcode of failed request:  19 ()
  Resource id in failed request:  0x5200006
  Serial number of failed request:  384
  Current serial number in output stream:  385

and

X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)
  Major opcode of failed request:  150 (XVideo)
  Minor opcode of failed request:  19 ()
  Resource id in failed request:  0x5200006
  Serial number of failed request:  536
  Current serial number in output stream:  537

I don't know where to begin debugging this, and lots of research on google didn't help. Can someone help me or explain what the errors are about?

WisdomPill
  • 720
  • 4
  • 11
  • 25
  • Can you build a `windows` with this `from tkinter import Frame, NW` ? How ? – dsgdfg Sep 08 '17 at 09:10
  • I didn't add the main window because it's a lot of code, now I've edited my question and added the window creation too – WisdomPill Sep 08 '17 at 09:13
  • `mainloop` is not iterable window on tkinter app [check this](https://stackoverflow.com/questions/4937955/video-output-in-tkinter-from-gstreamer) – dsgdfg Sep 08 '17 at 09:17
  • I didn't understand your answer, I do everything that is the answer you linked me. Maybe I created the subclass in the wrong way? I would appreciate to find a solution based on classes to keep the code structured. – WisdomPill Sep 08 '17 at 09:41
  • mean `mainloop` is your app_body don't iterate, you need for `exit,refresh, etc`. Create a new `Frame` and push in data. – dsgdfg Sep 08 '17 at 09:44
  • I found the problem but it does not remove the errors of xserver. – WisdomPill Sep 08 '17 at 10:23
  • Now the pipeline works but I the errors still show up. – WisdomPill Sep 08 '17 at 10:25

0 Answers0