Skip to content

Commit

Permalink
* prevent filename clashes between encoders that can generate the sam…
Browse files Browse the repository at this point in the history
…e extension (ie: mpeg4)

* suspend save-to-file whilst running self tests

git-svn-id: https://xpra.org/svn/Xpra/trunk@12161 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Mar 18, 2016
1 parent a3ca509 commit 2832d93
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
24 changes: 15 additions & 9 deletions src/xpra/codecs/enc_x264/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ cdef class Encoder:
self.init_encoder()
gen = generation.increase()
if SAVE_TO_FILE is not None:
filename = SAVE_TO_FILE+str(gen)+".%s" % encoding
filename = SAVE_TO_FILE+"x264-"+str(gen)+".%s" % encoding
self.file = open(filename, 'wb')
log.info("saving %s stream to %s", encoding, filename)

Expand Down Expand Up @@ -702,13 +702,19 @@ cdef class Encoder:


def selftest(full=False):
global SAVE_TO_FILE
from xpra.codecs.codec_checks import testencoder, get_encoder_max_sizes
from xpra.codecs.enc_x264 import encoder
assert testencoder(encoder, full)
#this is expensive, so don't run it unless "full" is set:
if full:
global MAX_WIDTH, MAX_HEIGHT
maxw, maxh = get_encoder_max_sizes(encoder)
assert maxw>=MAX_WIDTH and maxh>=MAX_HEIGHT, "%s is limited to %ix%i and not %ix%i" % (encoder, maxw, maxh, MAX_WIDTH, MAX_HEIGHT)
MAX_WIDTH, MAX_HEIGHT = maxw, maxh
log.info("%s max dimensions: %ix%i", encoder, MAX_WIDTH, MAX_HEIGHT)
temp = SAVE_TO_FILE
try:
SAVE_TO_FILE = None
assert testencoder(encoder, full)
#this is expensive, so don't run it unless "full" is set:
if full:
global MAX_WIDTH, MAX_HEIGHT
maxw, maxh = get_encoder_max_sizes(encoder)
assert maxw>=MAX_WIDTH and maxh>=MAX_HEIGHT, "%s is limited to %ix%i and not %ix%i" % (encoder, maxw, maxh, MAX_WIDTH, MAX_HEIGHT)
MAX_WIDTH, MAX_HEIGHT = maxw, maxh
log.info("%s max dimensions: %ix%i", encoder, MAX_WIDTH, MAX_HEIGHT)
finally:
SAVE_TO_FILE = temp
53 changes: 29 additions & 24 deletions src/xpra/codecs/vpx/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ cdef class Encoder:
self.do_set_encoding_quality(quality)
gen = generation.increase()
if SAVE_TO_FILE is not None:
filename = SAVE_TO_FILE+str(gen)+".%s" % encoding
filename = SAVE_TO_FILE+"vpx-"+str(gen)+".%s" % encoding
self.file = open(filename, 'wb')
log.info("saving %s stream to %s", encoding, filename)

Expand Down Expand Up @@ -714,28 +714,33 @@ cdef class Encoder:


def selftest(full=False):
global CODECS, SAVE_TO_FILE
from xpra.codecs.codec_checks import testencoder, get_encoder_max_size
from xpra.codecs.vpx import encoder
global CODECS
CODECS = testencoder(encoder, full)
#this is expensive, so don't run it unless "full" is set:
if full and os.name=="posix":
#but first, try to figure out if we have enough memory to do this
import subprocess
p = subprocess.Popen("free -b | grep ^Mem:", shell=True, stdout=subprocess.PIPE)
stdout = p.communicate()[0]
out = stdout.decode('utf-8')
freemem_MB = int(out.split(" ")[-1])//1024//1024
if freemem_MB<=4096:
log.info("system has only %iMB of memory available, skipping vpx max-size tests", freemem_MB)
full = False
else:
log.info("system has %.1fGB of memory available, running full tests", freemem_MB/1024.0)
if full:
global MAX_SIZE
for encoding in get_encodings():
maxw, maxh = get_encoder_max_size(encoder, encoding, limit_w=8192, limit_h=4096)
dmaxw, dmaxh = MAX_SIZE[encoding]
assert maxw>=dmaxw and maxh>=dmaxh, "%s is limited to %ix%i and not %ix%i" % (encoder, maxw, maxh, dmaxw, dmaxh)
MAX_SIZE[encoding] = maxw, maxh
log("%s max dimensions: %s", encoder, MAX_SIZE)
temp = SAVE_TO_FILE
try:
SAVE_TO_FILE = None
CODECS = testencoder(encoder, full)
#this is expensive, so don't run it unless "full" is set:
if full and os.name=="posix":
#but first, try to figure out if we have enough memory to do this
import subprocess
p = subprocess.Popen("free -b | grep ^Mem:", shell=True, stdout=subprocess.PIPE)
stdout = p.communicate()[0]
out = stdout.decode('utf-8')
freemem_MB = int(out.split(" ")[-1])//1024//1024
if freemem_MB<=4096:
log.info("system has only %iMB of memory available, skipping vpx max-size tests", freemem_MB)
full = False
else:
log.info("system has %.1fGB of memory available, running full tests", freemem_MB/1024.0)
if full:
global MAX_SIZE
for encoding in get_encodings():
maxw, maxh = get_encoder_max_size(encoder, encoding, limit_w=8192, limit_h=4096)
dmaxw, dmaxh = MAX_SIZE[encoding]
assert maxw>=dmaxw and maxh>=dmaxh, "%s is limited to %ix%i and not %ix%i" % (encoder, maxw, maxh, dmaxw, dmaxh)
MAX_SIZE[encoding] = maxw, maxh
log("%s max dimensions: %s", encoder, MAX_SIZE)
finally:
SAVE_TO_FILE = temp
26 changes: 16 additions & 10 deletions src/xpra/codecs/xvid/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ cdef class Encoder:
self.init_encoder()
gen = generation.increase()
if SAVE_TO_FILE is not None:
filename = SAVE_TO_FILE+str(gen)+".%s" % encoding
filename = SAVE_TO_FILE+"xvid-"+str(gen)+".%s" % encoding
self.file = open(filename, 'wb')
log.info("saving %s stream to %s", encoding, filename)

Expand Down Expand Up @@ -519,14 +519,20 @@ cdef class Encoder:


def selftest(full=False):
global SAVE_TO_FILE
from xpra.codecs.codec_checks import testencoder, get_encoder_max_sizes
from xpra.codecs.xvid import encoder
init_module()
assert testencoder(encoder, full)
#this is expensive, so don't run it unless "full" is set:
if full:
global MAX_WIDTH, MAX_HEIGHT
maxw, maxh = get_encoder_max_sizes(encoder)
assert maxw>=MAX_WIDTH and maxh>=MAX_HEIGHT, "%s is limited to %ix%i and not %ix%i" % (encoder, maxw, maxh, MAX_WIDTH, MAX_HEIGHT)
MAX_WIDTH, MAX_HEIGHT = maxw, maxh
log.info("%s max dimensions: %ix%i", encoder, MAX_WIDTH, MAX_HEIGHT)
temp = SAVE_TO_FILE
try:
SAVE_TO_FILE = None
init_module()
assert testencoder(encoder, full)
#this is expensive, so don't run it unless "full" is set:
if full:
global MAX_WIDTH, MAX_HEIGHT
maxw, maxh = get_encoder_max_sizes(encoder)
assert maxw>=MAX_WIDTH and maxh>=MAX_HEIGHT, "%s is limited to %ix%i and not %ix%i" % (encoder, maxw, maxh, MAX_WIDTH, MAX_HEIGHT)
MAX_WIDTH, MAX_HEIGHT = maxw, maxh
log.info("%s max dimensions: %ix%i", encoder, MAX_WIDTH, MAX_HEIGHT)
finally:
SAVE_TO_FILE = temp

0 comments on commit 2832d93

Please sign in to comment.