Skip to content

Commit

Permalink
make a deep copy of the video helper if we are going to change the da…
Browse files Browse the repository at this point in the history
…ta it contains (cloning is not enough!)

git-svn-id: https://xpra.org/svn/Xpra/trunk@5307 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jan 29, 2014
1 parent 5aa7471 commit ddbf6f1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
40 changes: 21 additions & 19 deletions src/xpra/codecs/video_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,38 @@
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import copy
from threading import Lock
from xpra.log import Logger, debug_if_env
log = Logger()
debug = debug_if_env(log, "XPRA_VIDEOPIPELINE_DEBUG")

from xpra.codecs.loader import get_codec

singleton = None
instance = None


class VideoHelper(object):

def __init__(self):
self._video_encoder_specs = {}
self._csc_encoder_specs = {}
def __init__(self, vspecs={}, cscspecs={}, init=False):
self._video_encoder_specs = vspecs
self._csc_encoder_specs = cscspecs
#bits needed to ensure we can initialize just once
#even when called from multiple threads:
self._initialized = False
self._initialized = init
self._lock = Lock()

def clone(self):
assert self._initialized
clone = VideoHelper()
clone._video_encoder_specs = self._video_encoder_specs.copy()
clone._csc_encoder_specs = self._csc_encoder_specs.copy()
clone._initialized = True
return clone
def clone(self, deep=False):
if not self._initialized:
self.init()
if deep:
ves = copy.deepcopy(self._video_encoder_specs)
ces = copy.deepcopy(self._csc_encoder_specs)
else:
ves = self._video_encoder_specs.copy()
ces = self._csc_encoder_specs.copy()
#make a deep copy:
return VideoHelper(ves, ces, True)

def get_info(self):
d = {}
Expand All @@ -43,10 +48,7 @@ def get_info(self):
d.setdefault("encoding."+in_csc+"_to_"+encoding, []).append(spec.codec_type)
return d

def may_init(self):
#check without lock (usual fast path):
if self._initialized:
return
def init(self):
try:
self._lock.acquire()
#check again with lock held (in case of race):
Expand Down Expand Up @@ -160,7 +162,7 @@ def add_csc_spec(self, in_csc, out_csc, spec):
self._csc_encoder_specs.setdefault(in_csc, []).append(item)


singleton = VideoHelper()
instance = VideoHelper()
def getVideoHelper():
global singleton
return singleton
global instance
return instance
2 changes: 1 addition & 1 deletion src/xpra/server/proxy_instance_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def filter_client_caps(self, caps):
#pass list of encoding specs to client:
from xpra.codecs.video_helper import getVideoHelper
self.video_helper = getVideoHelper()
self.video_helper.may_init()
self.video_helper.init()
#serialize encodings defs into a dict:
encoding_defs = {}
e_found = []
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/server/server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def init(self, opts):
def threaded_init(self):
log("threaded_init() start")
#try to load video encoders in advance as this can take some time:
getVideoHelper().may_init()
getVideoHelper().init()
log("threaded_init() end")

def init_encodings(self):
Expand Down
8 changes: 4 additions & 4 deletions src/xpra/server/window_video_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class WindowVideoSource(WindowSource):
A WindowSource that handles video codecs.
"""

_video_helper = getVideoHelper()

def __init__(self, *args):
WindowSource.__init__(self, *args)
#client uses uses_swscale (has extra limits on sizes)
Expand Down Expand Up @@ -89,9 +87,11 @@ def __init__(self, *args):

self.last_pipeline_params = None
self.last_pipeline_scores = []
WindowVideoSource._video_helper.may_init()
self.video_helper = WindowVideoSource._video_helper.clone()
self.video_helper = getVideoHelper()
if self.encoding_options.get("proxy.video", False):
#if we "proxy video", we will modify the video helper to add
#new encoders, so we must make a deep copy to preserve the original:
self.video_helper = getVideoHelper().clone(deep=True)
#enabling video proxy:
try:
self.parse_proxy_video()
Expand Down

0 comments on commit ddbf6f1

Please sign in to comment.