Skip to content

Commit

Permalink
#2344 only load the codecs we now we need, simplify the loader code
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@23045 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jun 29, 2019
1 parent 396d06a commit cdb89b5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 36 deletions.
17 changes: 11 additions & 6 deletions src/xpra/client/mixins/encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import os

from xpra.codecs.codec_constants import PREFERED_ENCODING_ORDER, PROBLEMATIC_ENCODINGS
from xpra.codecs.loader import load_codecs, codec_versions, has_codec, get_codec
from xpra.codecs.loader import load_codec, codec_versions, has_codec, get_codec
from xpra.codecs.video_helper import getVideoHelper, NO_GFX_CSC_OPTIONS
from xpra.scripts.config import parse_bool_or_int
from xpra.net import compression
from xpra.util import envint, envbool, updict, csv
from xpra.client.mixins.stub_client_mixin import StubClientMixin
from xpra.log import Logger

log = Logger("client")
log = Logger("client", "encoding")

B_FRAMES = envbool("XPRA_B_FRAMES", True)
PAINT_FLUSH = envbool("XPRA_PAINT_FLUSH", True)
Expand Down Expand Up @@ -64,9 +64,14 @@ def init(self, opts, _extra_args=()):
self.min_quality = opts.min_quality
self.speed = opts.speed
self.min_speed = opts.min_speed
#until we add the ability to choose decoders, use all of them:
#(and default to non grahics card csc modules if not specified)
load_codecs(encoders=False, video=False)
load_codec("enc_pillow")
ae = self.allowed_encodings
if "jpeg" in ae:
#try to load the fast jpeg encoder:
load_codec("dec_jpeg")
if "webp" in ae:
#try to load the fast webp encoder:
load_codec("dec_webp")
vh = getVideoHelper()
vh.set_modules(video_decoders=opts.video_decoders, csc_modules=opts.csc_modules or NO_GFX_CSC_OPTIONS)
vh.init()
Expand Down Expand Up @@ -241,7 +246,7 @@ def do_get_core_encodings(self):
"""
#we always support rgb:
core_encodings = ["rgb24", "rgb32"]
for codec in ("dec_pillow", "dec_webp"):
for codec in ("dec_pillow", "dec_webp", "dec_jpeg"):
if has_codec(codec):
c = get_codec(codec)
for e in c.get_encodings():
Expand Down
15 changes: 7 additions & 8 deletions src/xpra/client/window_backing_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of Xpra.
# Copyright (C) 2008 Nathaniel Smith <[email protected]>
# Copyright (C) 2012-2018 Antoine Martin <[email protected]>
# Copyright (C) 2012-2019 Antoine Martin <[email protected]>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

Expand All @@ -10,7 +10,7 @@
from xpra.net.mmap_pipe import mmap_read
from xpra.net import compression
from xpra.util import typedict, csv, envint, envbool, repr_ellipsized
from xpra.codecs.loader import get_codec, is_loaded
from xpra.codecs.loader import get_codec
from xpra.codecs.video_helper import getVideoHelper
from xpra.os_util import bytestostr, _buffer
try:
Expand Down Expand Up @@ -97,12 +97,11 @@ def __init__(self, wid, window_alpha):
self.jpeg_decoder = None
self.webp_decoder = None
self.pil_decoder = None
if is_loaded():
self.pil_decoder = get_codec("dec_pillow")
if self.pil_decoder:
self._PIL_encodings = self.pil_decoder.get_encodings()
self.jpeg_decoder = get_codec("dec_jpeg")
self.webp_decoder = get_codec("dec_webp")
self.pil_decoder = get_codec("dec_pillow")
if self.pil_decoder:
self._PIL_encodings = self.pil_decoder.get_encodings()
self.jpeg_decoder = get_codec("dec_jpeg")
self.webp_decoder = get_codec("dec_webp")
self.draw_needs_refresh = True
self.mmap = None
self.mmap_enabled = False
Expand Down
16 changes: 0 additions & 16 deletions src/xpra/codecs/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,7 @@ def load_codec(name):
xpra_codec_import(name, description, top_module, class_module, classnames)


loaded = None
def load_codecs(encoders=True, decoders=True, csc=True, video=True):
global loaded
if loaded:
return
reload_codecs(encoders, decoders, csc, video)

def reload_codecs(encoders=True, decoders=True, csc=True, video=True):
global loaded
loaded = True
show = []
log("loading codecs")

Expand Down Expand Up @@ -219,23 +210,16 @@ def load(*names):
log("* %s : %s" % (name.ljust(20), version))


def is_loaded():
return loaded

def get_codec_error(name):
assert loaded
return codec_errors.get(name)

def get_codec(name):
assert loaded
return codecs.get(name)

def get_codec_version(name):
assert loaded
return codec_versions.get(name)

def has_codec(name):
assert loaded
return name in codecs


Expand Down
15 changes: 11 additions & 4 deletions src/xpra/server/mixins/encoding_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from xpra.scripts.config import parse_bool_or_int
from xpra.codecs.codec_constants import PREFERED_ENCODING_ORDER, PROBLEMATIC_ENCODINGS
from xpra.codecs.loader import load_codecs, reload_codecs, get_codec, has_codec, codec_versions
from xpra.codecs.loader import get_codec, has_codec, codec_versions, load_codec
from xpra.codecs.video_helper import getVideoHelper
from xpra.server.mixins.stub_server_mixin import StubServerMixin
from xpra.log import Logger
Expand Down Expand Up @@ -45,13 +45,20 @@ def init(self, opts):
getVideoHelper().set_modules(video_encoders=opts.video_encoders, csc_modules=opts.csc_modules)

def setup(self):
load_codecs(False, False, False, False)
self.init_encodings()

def threaded_setup(self):
#load video codecs:
getVideoHelper().init()
#re-init encodings now that we have video:
reload_codecs(decoders=False, video=False)
#and load the picture codecs:
load_codec("enc_pillow")
ae = self.allowed_encodings
if "jpeg" in ae:
#try to load the fast jpeg encoder:
load_codec("enc_jpeg")
if "webp" in ae:
#try to load the fast webp encoder:
load_codec("enc_webp")
self.init_encodings()

def cleanup(self):
Expand Down
5 changes: 3 additions & 2 deletions src/xpra/server/proxy/proxy_instance_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from xpra.net.compression import Compressed, compressed_wrapper
from xpra.net.protocol_classes import get_client_protocol_class, get_server_protocol_class
from xpra.net.protocol import Protocol
from xpra.codecs.loader import load_codecs, get_codec
from xpra.codecs.loader import load_codec, get_codec
from xpra.codecs.image_wrapper import ImageWrapper
from xpra.codecs.video_helper import getVideoHelper, PREFERRED_ENCODER_ORDER
from xpra.os_util import (
Expand Down Expand Up @@ -294,7 +294,8 @@ def run(self):

def video_init(self):
enclog("video_init() loading codecs")
load_codecs(decoders=False)
enclog("video_init() loading pillow encoder")
load_codec("enc_pillow")
enclog("video_init() will try video encoders: %s", csv(self.video_encoder_modules) or "none")
self.video_helper = getVideoHelper()
#only use video encoders (no CSC supported in proxy)
Expand Down

0 comments on commit cdb89b5

Please sign in to comment.