Skip to content

Preset reorder #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion voctogui/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
gi.require_version('Gst', '1.0')
gi.require_version('GstVideo', '1.0')
gi.require_version('GstNet', '1.0')
from gi.repository import Gtk, Gdk, Gst, GstVideo
from gi.repository import Gtk, Gdk, Gst, GstVideo, GLib

import signal
import logging
Expand All @@ -30,6 +30,9 @@
Gdk.init([])
Gtk.init([])

# select window icon on wayland
GLib.set_prgname("voctogui.desktop")

# select Awaita:Dark theme
settings = Gtk.Settings.get_default()
settings.set_property("gtk-theme-name", "Adwaita")
Expand Down
6 changes: 5 additions & 1 deletion voctogui/lib/ui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
from typing import cast

from gi.repository import Gtk, Gdk

from voctogui.lib.config import Config
Expand Down Expand Up @@ -79,12 +81,14 @@ def setup(self):
self.mix_audio_display = AudioDisplay(audio_box, "mix", uibuilder=self)

# Create Main-Video Display
video_main = cast(Gtk.Box, self.find_widget_recursive(self.win, 'video_main'))
self.mix_video_display = VideoDisplay(
self.find_widget_recursive(self.win, 'video_main'),
self.mix_audio_display,
port=Port.MIX_PREVIEW if Config.getPreviewsEnabled() else Port.MIX_OUT,
name="MIX"
)
video_main.pack_start(self.mix_video_display.widget, fill=True, expand=True, padding=0)
self.mix_video_display.play()

for idx, livepreview in enumerate(Config.getLivePreviews()):
if Config.getPreviewsEnabled():
Expand Down
73 changes: 21 additions & 52 deletions voctogui/lib/videodisplay.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
import sys
from typing import cast

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

from voctogui.lib.args import Args
from voctogui.lib.config import Config
Expand All @@ -15,12 +16,14 @@

class VideoDisplay(object):
"""Displays a Voctomix-Video-Stream into a GtkWidget"""
imagesink: Gst.Element
widget: Gtk.Widget
pipeline: Gst.Pipeline

def __init__(self, video_drawing_area, audio_display, port, name, width=None, height=None,
def __init__(self, audio_display, port, name, width=None, height=None,
has_audio=True, play_audio=False):
self.log = logging.getLogger('VideoDisplay:%s' % name)
self.name = name
self.video_drawing_area = video_drawing_area
self.level_callback = None if audio_display is None else audio_display.callback
video_decoder = None

Expand Down Expand Up @@ -79,28 +82,16 @@ def __init__(self, video_drawing_area, audio_display, port, name, width=None, he
# Video Display
videosystem = Config.getVideoSystem()
self.log.debug('Configuring for Video-System %s', videosystem)
if videosystem == 'gtk':
pipe += """ ! gtksink
name=imagesink-{name} sync=false
""".format(name=name)

if videosystem == 'gl':
elif videosystem == 'gtkgl':
pipe += """ ! glupload
! glcolorconvert
! glimagesinkelement
name=imagesink-{name}
""".format(name=name)

elif videosystem == 'xv':
pipe += """ ! xvimagesink
name=imagesink-{name}
""".format(name=name)

elif videosystem == 'x':
pipe += """ ! ximagesink
name=imagesink-{name}
""".format(name=name)

elif videosystem == 'vaapi':
pipe += """ ! vaapisink
name=imagesink-{name}
""".format(name=name)
! gtkglsink
name=imagesink-{name} sync=false
""".format(name=name)

else:
raise Exception(
Expand Down Expand Up @@ -135,48 +126,27 @@ def __init__(self, video_drawing_area, audio_display, port, name, width=None, he
self.log.info("Creating Display-Pipeline:\n%s", pretty(pipe))
try:
# launch gstreamer pipeline
self.pipeline = Gst.parse_launch(pipe)
self.pipeline = cast(Gst.Pipeline, Gst.parse_launch(pipe))
self.log.info("pipeline launched successfuly")
except:
self.log.error("Can not launch pipeline")
sys.exit(-1)

self.imagesink = cast(Gst.Element, self.pipeline.get_by_name('imagesink-{name}'.format(name=self.name)))
self.widget = cast(Gtk.Widget, self.imagesink.get_property("widget"))

if Args.dot:
self.log.debug("Generating DOT image of videodisplay pipeline")
gst_generate_dot(self.pipeline, "gui.videodisplay.{}".format(name), Args.gst_debug_details)

self.pipeline.use_clock(Clock)

self.video_drawing_area.add_events(
Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK)
self.video_drawing_area.connect("realize", self.on_realize)
self.pipeline.set_clock(Clock)
bus = self.pipeline.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()

bus.connect('message::error', self.on_error)
bus.connect('sync-message::element', self.on_syncmsg)
bus.connect('message::state-changed', self.on_state_changed)
bus.connect("message::element", self.on_level)

def on_realize(self, win):
self.imagesink = self.pipeline.get_by_name(
'imagesink-{name}'.format(name=self.name))
self.xid = self.video_drawing_area.get_property('window').get_xid()

self.log.debug('Realized Drawing-Area with xid %u', self.xid)
self.video_drawing_area.realize()

self.log.info("Launching Display-Pipeline")
self.pipeline.set_state(Gst.State.PLAYING)

def on_syncmsg(self, bus, msg):
if type(msg) == Gst.Message and self.imagesink:
if msg.get_structure().get_name() == "prepare-window-handle":
self.log.info(
'Setting imagesink window-handle to 0x%x', self.xid)
self.imagesink.set_window_handle(self.xid)

def on_error(self, bus, message):
(error, debug) = message.parse_error()
self.log.error(
Expand All @@ -193,6 +163,5 @@ def on_level(self, bus, msg):
decay = msg.get_structure().get_value('decay')
self.level_callback(rms, peak, decay)

def on_state_changed(self, bus, message):
if message.parse_state_changed().newstate == Gst.State.PLAYING:
self.video_drawing_area.show()
def play(self):
self.pipeline.set_state(Gst.State.PLAYING)
26 changes: 26 additions & 0 deletions voctogui/lib/videopreviewframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from gi.repository import Gtk
from gi.repository.Gtk import Requisition

class VideoPreviewFrame(Gtk.Bin):
"""
Custom helper class to force a specific size for a child widget
"""
natural_width: int
natural_height: int

def __init__(self, natural_width: int, natural_height: int):
super().__init__()
self.natural_width = natural_width
self.natural_height = natural_height

def do_get_preferred_size(self) -> tuple[Requisition, Requisition]:
natural_size = Requisition.new()
natural_size.width = self.natural_width
natural_size.height = self.natural_height
return natural_size, natural_size

def do_get_preferred_height(self) -> tuple[int, int]:
return self.natural_height, self.natural_height

def do_get_preferred_width(self) -> tuple[int, int]:
return self.natural_width, self.natural_width
18 changes: 9 additions & 9 deletions voctogui/lib/videopreviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import math
import os
from configparser import NoOptionError
from typing import cast

from gi.repository import Gtk, Gdk, GObject
from gi.repository import Gst, Gtk, Gdk, GObject
from voctogui.lib.videopreviewframe import VideoPreviewFrame
from voctogui.lib.videodisplay import VideoDisplay
from voctogui.lib.audioonlydisplay import AudioOnlyDisplay
from voctogui.lib.audiodisplay import AudioDisplay
Expand Down Expand Up @@ -60,18 +62,16 @@ def addPreview(self, uibuilder, source, port, has_volume=True):
if has_audio and Config.getAudioStreams().get_source_streams(source):
mix_audio_display = AudioDisplay(self.audio_box, source, uibuilder, has_volume)
if source in Config.getVideoSources(internal=True):
video = uibuilder.load_check_widget('video',
os.path.dirname(uibuilder.uifile) +
"/widgetpreview.ui")
video.set_size_request(*self.previewSize)
self.video_box.pack_start(video, fill=False,
expand=False, padding=0)

player = VideoDisplay(video, mix_audio_display, port=port,
player = VideoDisplay(audio_display=mix_audio_display, port=port,
width=self.previewSize[0],
height=self.previewSize[1],
name=source.upper(),
has_audio=has_audio,
)
video = cast(Gtk.Widget, player.widget)
frame = VideoPreviewFrame(*self.previewSize)
frame.add(video)
self.video_box.pack_start(frame, False, False, 0)
player.play()
elif has_audio and Config.getAudioStreams().get_source_streams(source):
player = AudioOnlyDisplay(mix_audio_display, port=port, name=source.upper())
Loading