camera: improve performance and latency and also fixes #1003
This commit is contained in:
parent
b74b1b600f
commit
fa73daaf71
@ -1,9 +1,10 @@
|
|||||||
|
import contextlib
|
||||||
import mpv
|
import mpv
|
||||||
import logging
|
import logging
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gtk, Gdk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
from ks_includes.screen_panel import ScreenPanel
|
from ks_includes.screen_panel import ScreenPanel
|
||||||
|
|
||||||
@ -29,12 +30,7 @@ class CameraPanel(ScreenPanel):
|
|||||||
self.content.add(box)
|
self.content.add(box)
|
||||||
self.content.show_all()
|
self.content.show_all()
|
||||||
self.url = self.ks_printer_cfg.get("camera_url", "http://127.0.0.1/webcam/?action=stream").replace('"', '')
|
self.url = self.ks_printer_cfg.get("camera_url", "http://127.0.0.1/webcam/?action=stream").replace('"', '')
|
||||||
# wayland has no primary monitor with that we can detect it
|
logging.debug(f"Camera URL: {self.url}")
|
||||||
self.wayland = Gdk.Display.get_default().get_primary_monitor() is None
|
|
||||||
# gpu output driver doesn't work on a pi3 and the autoselected sdl doesn't size correctly
|
|
||||||
# consider adding a software switch to enable the gpu backend if set by the user
|
|
||||||
self.vo = 'wlshm' if self.wayland else 'x11'
|
|
||||||
logging.debug(f"Camera URL: {self.url} vo: {self.vo} wayland: {self.wayland}")
|
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
self.play()
|
self.play()
|
||||||
@ -49,20 +45,20 @@ class CameraPanel(ScreenPanel):
|
|||||||
self.mpv.terminate()
|
self.mpv.terminate()
|
||||||
self.mpv = None
|
self.mpv = None
|
||||||
# Create mpv after show or the 'window' property will be None
|
# Create mpv after show or the 'window' property will be None
|
||||||
try:
|
self.mpv = mpv.MPV(log_handler=self.log, vo='gpu,wlshm,xv,x11')
|
||||||
self.mpv = mpv.MPV(
|
|
||||||
log_handler=self.log,
|
with contextlib.suppress(Exception):
|
||||||
vo=self.vo,
|
self.mpv.profile = 'sw-fast'
|
||||||
profile='sw-fast',
|
|
||||||
)
|
# LOW LATENCY PLAYBACK
|
||||||
except ValueError:
|
with contextlib.suppress(Exception):
|
||||||
self.mpv = mpv.MPV(
|
self.mpv.profile = 'low-latency'
|
||||||
log_handler=self.log,
|
self.mpv.untimed = True
|
||||||
vo=self.vo,
|
self.mpv.audio = 'no'
|
||||||
)
|
|
||||||
# On wayland mpv cannot be embedded at least for now
|
# On wayland mpv cannot be embedded at least for now
|
||||||
# https://github.com/mpv-player/mpv/issues/9654
|
# https://github.com/mpv-player/mpv/issues/9654
|
||||||
# if fs or self.wayland:
|
# if fs:
|
||||||
self.mpv.fullscreen = True
|
self.mpv.fullscreen = True
|
||||||
|
|
||||||
@self.mpv.on_key_press('MBTN_LEFT' or 'MBTN_LEFT_DBL')
|
@self.mpv.on_key_press('MBTN_LEFT' or 'MBTN_LEFT_DBL')
|
||||||
@ -75,7 +71,7 @@ class CameraPanel(ScreenPanel):
|
|||||||
# def clicked():
|
# def clicked():
|
||||||
# self._screen.show_popup_message(self.url, level=1)
|
# self._screen.show_popup_message(self.url, level=1)
|
||||||
self.mpv.play(self.url)
|
self.mpv.play(self.url)
|
||||||
# if fs or self.wayland:
|
# if fs:
|
||||||
try:
|
try:
|
||||||
self.mpv.wait_for_playback()
|
self.mpv.wait_for_playback()
|
||||||
except mpv.ShutdownError:
|
except mpv.ShutdownError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user