Skip to content

Commit

Permalink
#3070 add encoding selection
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Apr 14, 2021
1 parent 0ab4ac4 commit 4418c7e
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 56 deletions.
68 changes: 35 additions & 33 deletions xpra/client/mixins/encodings.py
Expand Up @@ -28,10 +28,41 @@
DEFAULT_ENCODINGS = os.environ.get("XPRA_DEFAULT_ENCODINGS", "rgb32,rgb24,jpeg,png").split(",")


"""
Mixin for adding encodings to a client
"""
def get_core_encodings():
"""
This method returns the actual encodings supported.
ie: ["rgb24", "vp8", "webp", "png", "png/L", "png/P", "jpeg", "h264", "vpx"]
It is often overriden in the actual client class implementations,
where extra encodings can be added (generally just 'rgb32' for transparency),
or removed if the toolkit implementation class is more limited.
"""
#we always support rgb:
core_encodings = ["rgb24", "rgb32"]
for codec in ("dec_pillow", "dec_webp", "dec_jpeg"):
if has_codec(codec):
c = get_codec(codec)
encs = c.get_encodings()
log("%s.get_encodings()=%s", codec, encs)
for e in encs:
if e not in core_encodings:
core_encodings.append(e)
if SCROLL_ENCODING:
core_encodings.append("scroll")
#we enable all the video decoders we know about,
#what will actually get used by the server will still depend on the csc modes supported
video_decodings = getVideoHelper().get_decodings()
log("video_decodings=%s", video_decodings)
for encoding in video_decodings:
if encoding not in core_encodings:
core_encodings.append(encoding)
#remove duplicates and use prefered encoding order:
return [x for x in PREFERRED_ENCODING_ORDER if x in set(core_encodings)]


class Encodings(StubClientMixin):
"""
Mixin for adding encodings to a client
"""

def __init__(self):
StubClientMixin.__init__(self)
Expand Down Expand Up @@ -255,36 +286,7 @@ def get_window_icon_encodings(self):
return e

def get_core_encodings(self):
"""
This method returns the actual encodings supported.
ie: ["rgb24", "vp8", "webp", "png", "png/L", "png/P", "jpeg", "h264", "vpx"]
It is often overriden in the actual client class implementations,
where extra encodings can be added (generally just 'rgb32' for transparency),
or removed if the toolkit implementation class is more limited.
"""
#we always support rgb:
core_encodings = ["rgb24", "rgb32"]
for codec in ("dec_pillow", "dec_webp", "dec_jpeg"):
if has_codec(codec):
c = get_codec(codec)
encs = c.get_encodings()
log("%s.get_encodings()=%s", codec, encs)
for e in encs:
if e not in core_encodings:
core_encodings.append(e)
if SCROLL_ENCODING:
core_encodings.append("scroll")
#we enable all the video decoders we know about,
#what will actually get used by the server will still depend on the csc modes supported
video_decodings = getVideoHelper().get_decodings()
log("video_decodings=%s", video_decodings)
for encoding in video_decodings:
if encoding not in core_encodings:
core_encodings.append(encoding)
#remove duplicates and use prefered encoding order:
core_encodings = [x for x in PREFERRED_ENCODING_ORDER
if x in set(core_encodings) and x in self.allowed_encodings]
return core_encodings
return [x for x in get_core_encodings() if x in self.allowed_encodings]

def set_encoding(self, encoding):
log("set_encoding(%s)", encoding)
Expand Down
78 changes: 55 additions & 23 deletions xpra/gtk_common/start_gui.py
Expand Up @@ -28,6 +28,7 @@
BANDWIDTH_MENU_OPTIONS,
MIN_QUALITY_OPTIONS, MIN_SPEED_OPTIONS,
)
from xpra.make_thread import start_thread
from xpra.platform.paths import get_xpra_command
from xpra.log import Logger

Expand Down Expand Up @@ -72,7 +73,6 @@ def open_link():
webbrowser.open(link)
def help_clicked(*args):
log("help_clicked%s opening '%s'", args, link)
from xpra.make_thread import start_thread
start_thread(open_link, "open-link", True)
icon = get_icon_pixbuf(icon_name)
btn = imagebutton("" if icon else label, icon, label, help_clicked, 12, False)
Expand Down Expand Up @@ -267,6 +267,17 @@ def btn(label, tooltip, callback, default=False):

vbox.show_all()
self.add(vbox)
#load encodings in the background:
self.loader_thread = start_thread(self.load_codecs, "load-codecs", daemon=True)

def load_codecs(self):
from xpra.codecs.video_helper import getVideoHelper, NO_GFX_CSC_OPTIONS
vh = getVideoHelper()
vh.set_modules(video_decoders=self.session_options.video_decoders,
csc_modules=self.session_options.csc_modules or NO_GFX_CSC_OPTIONS)
vh.init()
from xpra.codecs.loader import load_codecs
load_codecs()

def set_options(self, options):
#cook some attributes,
Expand Down Expand Up @@ -302,6 +313,9 @@ def configure_features(self, *_args):
def configure_network(self, *_args):
self.run_dialog(NetworkWindow)
def configure_encoding(self, *_args):
if self.loader_thread.is_alive():
log("waiting for loader thread to complete")
self.loader_thread.join()
self.run_dialog(EncodingWindow)
def configure_keyboard(self, *_args):
self.run_dialog(KeyboardWindow)
Expand Down Expand Up @@ -622,6 +636,15 @@ def close(self, *_args): #pylint: disable=arguments-differ
self.set_value_from_widgets()
self.destroy()

def sep(self, tb):
tb.inc()
hsep = Gtk.HSeparator()
hsep.set_size_request(-1, 2)
al = Gtk.Alignment(xalign=0.5, yalign=0.5, xscale=1, yscale=0)
al.set_size_request(-1, 10)
al.add(hsep)
tb.attach(al, 0, 2)
tb.inc()

def bool_cb(self, table, label, option_name, tooltip_text=None, link=None):
attach_label(table, label, tooltip_text, link)
Expand Down Expand Up @@ -752,7 +775,7 @@ def __init__(self, *args):

def populate_form(self):
btn = link_btn("https://github.com/Xpra-org/xpra/blob/master/docs/Features/README.md",
label="Features Documentation", icon_name=None)
label="Open Features Documentation", icon_name=None)
self.vbox.pack_start(btn, expand=True, fill=False, padding=20)

tb = self.table()
Expand All @@ -762,20 +785,23 @@ def populate_form(self):
"force" : ("force",),
})
self.bool_cb(tb, "Splash Screen", "splash")
self.bool_cb(tb, "Notifications", "notifications", None,
"https://github.com/Xpra-org/xpra/blob/master/docs/Features/Notifications.md")
self.bool_cb(tb, "System Tray", "system-tray", None,
"https://github.com/Xpra-org/xpra/blob/master/docs/Features/System-Tray.md")
self.bool_cb(tb, "Cursors", "cursors")
self.bool_cb(tb, "Bell", "bell")
self.sep(tb)
#"https://github.com/Xpra-org/xpra/blob/master/docs/Features/Notifications.md")
self.bool_cb(tb, "Xpra's System Tray", "tray")
self.bool_cb(tb, "Forward System Trays", "system-tray")
self.bool_cb(tb, "Notifications", "notifications")
#"https://github.com/Xpra-org/xpra/blob/master/docs/Features/System-Tray.md")
#self.bool_cb(tb, "Cursors", "cursors")
#self.bool_cb(tb, "Bell", "bell")
self.bool_cb(tb, "Modal Windows", "modal-windows")
pixel_depths = {0 : "auto"}
if self.run_mode=="shadow":
pixel_depths[8] = 8
for pd in (16, 24, 30, 32):
pixel_depths[pd] = pd
self.combo(tb, "Pixel Depth", "pixel-depth", pixel_depths,
"https://github.com/Xpra-org/xpra/blob/master/docs/Features/Image-Depth.md")
self.sep(tb)
self.combo(tb, "Pixel Depth", "pixel-depth", pixel_depths)
#"https://github.com/Xpra-org/xpra/blob/master/docs/Features/Image-Depth.md")
self.combo(tb, "Mouse Wheel", "mousewheel", {
"on" : "on",
"no" : "disabled",
Expand Down Expand Up @@ -804,12 +830,11 @@ def populate_form(self):
self.vbox.pack_start(btn, expand=True, fill=False, padding=20)

tb = self.table()
self.bool_cb(tb, "Multicast DNS", "mdns", "Publish the session via mDNS",
"https://github.com/Xpra-org/xpra/blob/master/docs/Network/Multicast-DNS.md")
#"https://github.com/Xpra-org/xpra/blob/master/docs/Network/Multicast-DNS.md")
self.radio_cb_auto(tb, "Session Sharing", "sharing")
self.radio_cb_auto(tb, "Session Lock", "lock", "Prevent sessions from being taken over by new clients")
tb.attach(Gtk.Label(""))
tb.inc()
self.sep(tb)
self.bool_cb(tb, "Multicast DNS", "mdns", "Publish the session via mDNS")
self.bool_cb(tb, "Bandwidth Detection", "bandwidth-detection", "Automatically detect runtime bandwidth limits")
bwoptions = {}
for bwlimit in BANDWIDTH_MENU_OPTIONS:
Expand Down Expand Up @@ -853,15 +878,22 @@ def populate_form(self):
0.15 : "normal",
0.5 : "slow",
})
tb.attach(Gtk.Label(""), 0, 2)
tb.inc()
tb.attach(Gtk.HSeparator(), 0, 2)
tb.inc()
tb.attach(Gtk.Label("Colourspace Modules"), 0)
tb.inc()
tb.attach(Gtk.Label("Video Encoders"), 0)
tb.inc()
tb.attach(Gtk.Label("Video Decoders"), 0)
self.sep(tb)
from xpra.client.mixins.encodings import get_core_encodings
encodings = ["auto", "rgb"] + get_core_encodings()
encodings.remove("rgb24")
encodings.remove("rgb32")
if "grayscale" not in encodings:
encodings.append("grayscale")
from xpra.codecs.loader import get_encoding_name
encoding_options = dict((encoding, get_encoding_name(encoding)) for encoding in encodings)
#opts.encodings
self.combo(tb, "Encoding", "encoding", encoding_options)
#tb.attach(Gtk.Label("Colourspace Modules"), 0)
#tb.inc()
#tb.attach(Gtk.Label("Video Encoders"), 0)
#tb.inc()
#tb.attach(Gtk.Label("Video Decoders"), 0)
self.vbox.show_all()


Expand Down

0 comments on commit 4418c7e

Please sign in to comment.