From 765ac67763823ea4e65f7dd52cbfe8bd7e4478c7 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Wed, 8 Apr 2015 05:39:05 +0000 Subject: [PATCH] #832: allow us to build the vpx encoder against libvpx versions older than 1.4: add IFdef statement via constant file git-svn-id: https://xpra.org/svn/Xpra/trunk@8960 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- src/setup.py | 49 ++++++++++++++++--------------- src/xpra/codecs/vpx/constants.txt | 8 +++++ src/xpra/codecs/vpx/encoder.pyx | 13 +++++--- 3 files changed, 43 insertions(+), 27 deletions(-) create mode 100644 src/xpra/codecs/vpx/constants.txt diff --git a/src/setup.py b/src/setup.py index f6800c2bef..dd892d13b6 100755 --- a/src/setup.py +++ b/src/setup.py @@ -456,31 +456,33 @@ def make_constants_pxi(constants_path, pxi_path, **kwargs): constants.append(data) with open(pxi_path, "w") as out: - out.write("cdef extern from *:\n") - ### Apparently you can't use | on enum's?! - # out.write(" enum MagicNumbers:\n") - # for const in constants: - # if isinstance(const, tuple): - # out.write(' %s %s\n' % const) - # else: - # out.write(' %s\n' % (const,)) - for const in constants: - if isinstance(const, tuple): - out.write(' unsigned int %s %s\n' % const) - else: - out.write(' unsigned int %s\n' % (const,)) - - out.write("constants = {\n") - for const in constants: - if isinstance(const, tuple): - pyname = const[0] - else: - pyname = const - out.write(' "%s": %s,\n' % (pyname, pyname)) - out.write("}\n") + if constants: + out.write("cdef extern from *:\n") + ### Apparently you can't use | on enum's?! + # out.write(" enum MagicNumbers:\n") + # for const in constants: + # if isinstance(const, tuple): + # out.write(' %s %s\n' % const) + # else: + # out.write(' %s\n' % (const,)) + for const in constants: + if isinstance(const, tuple): + out.write(' unsigned int %s %s\n' % const) + else: + out.write(' unsigned int %s\n' % (const,)) + + out.write("constants = {\n") + for const in constants: + if isinstance(const, tuple): + pyname = const[0] + else: + pyname = const + out.write(' "%s": %s,\n' % (pyname, pyname)) + out.write("}\n") + if kwargs: + out.write("\n\n") if kwargs: - out.write("\n\n") for k, v in kwargs.items(): out.write('DEF %s = %s\n' % (k, v)) @@ -1893,6 +1895,7 @@ def cython_add(*args, **kwargs): toggle_packages(vpx_ENABLED, "xpra.codecs.vpx") if vpx_ENABLED: + make_constants("xpra", "codecs", "vpx", "constants", LIBVPX14=pkg_config_ok("--atleast-version=1.4", "libvpx")) vpx_pkgconfig = pkgconfig("vpx") cython_add(Extension("xpra.codecs.vpx.encoder", ["xpra/codecs/vpx/encoder.pyx"]+membuffers_c, diff --git a/src/xpra/codecs/vpx/constants.txt b/src/xpra/codecs/vpx/constants.txt new file mode 100644 index 0000000000..2d0aea5513 --- /dev/null +++ b/src/xpra/codecs/vpx/constants.txt @@ -0,0 +1,8 @@ +# This file is part of Xpra. +# Copyright (C) 2015 Antoine Martin +# Xpra is released under the terms of the GNU GPL v2, or, at your option, any +# later version. See the file COPYING for details. + +## This file is processed by setup.py to create a .pxi +## It is empty because the only constant we are interested in is +## 'LIBVPX14' which is generated by setup.py on the fly using a pkgconfig version check \ No newline at end of file diff --git a/src/xpra/codecs/vpx/encoder.pyx b/src/xpra/codecs/vpx/encoder.pyx index e57685fc75..2158cf5cdd 100644 --- a/src/xpra/codecs/vpx/encoder.pyx +++ b/src/xpra/codecs/vpx/encoder.pyx @@ -25,6 +25,7 @@ VPX_THREADS = os.environ.get("XPRA_VPX_THREADS", max(1, cpus-1)) DEF ENABLE_VP8 = True DEF ENABLE_VP9 = True +include "constants.pxi" ENABLE_VP9_YUV444 = os.environ.get("XPRA_VP9_YUV444", "1")=="1" ENABLE_VP9_TILING = os.environ.get("XPRA_VP9_TILING", "0")=="1" @@ -99,8 +100,9 @@ cdef extern from "vpx/vpx_encoder.h": int VP9E_SET_TILE_COLUMNS #function to set encoder internal speed settings: int VP8E_SET_CPUUSED - #function to enable/disable periodic Q boost: - int VP9E_SET_FRAME_PERIODIC_BOOST + IF LIBVPX14: + #function to enable/disable periodic Q boost: + int VP9E_SET_FRAME_PERIODIC_BOOST int VP9E_SET_LOSSLESS #vpx_enc_pass: int VPX_RC_ONE_PASS @@ -255,6 +257,8 @@ def get_info(): "build_config" : vpx_codec_build_config()} for k,v in COLORSPACES.items(): info["%s.colorspaces" % k] = v + IF LIBVPX14: + info["libvpx14"] = True return info @@ -386,8 +390,9 @@ cdef class Encoder: elif width>=1024: tile_columns = 3 self.codec_control("tile columns", VP9E_SET_TILE_COLUMNS, tile_columns) - #disable periodic Q boost which causes latency spikes: - self.codec_control("periodic Q boost", VP9E_SET_FRAME_PERIODIC_BOOST, 0) + IF LIBVPX14: + #disable periodic Q boost which causes latency spikes: + self.codec_control("periodic Q boost", VP9E_SET_FRAME_PERIODIC_BOOST, 0) def codec_control(self, info, int attr, int value):