Commit 22ef3393 authored by Jan Kiene's avatar Jan Kiene
Browse files

make win binaries with wine the default on linux

parent 20f30f75
Loading
Loading
Loading
Loading
+1 −16
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ DEFAULT_CONFIG = {
    "date": f"{datetime.now().strftime('%Y%m%d_%H.%M.%S')}",
    "git_sha": f"{get_gitsha()}",
    "multiprocessing": True,
    "use_windows_codec_binaries": True,
    "delete_tmp": False,
    "master_seed": 0,
    "prerun_seed": 0,
@@ -69,22 +70,6 @@ DEFAULT_CONFIG = {
    },
    "condition_in_output_filename": False,
}
DEFAULT_CONFIG_EVS = {
    "cod": {
        "bin": find_binary("EVS_cod", raise_error=False),
    },
    "dec": {
        "bin": find_binary("EVS_dec", raise_error=False),
    },
}
DEFAULT_CONFIG_IVAS = {
    "cod": {
        "bin": find_binary("IVAS_cod", raise_error=False),
    },
    "dec": {
        "bin": find_binary("IVAS_dec", raise_error=False),
    },
}

DEFAULT_CONFIG_BINARIES = {
    "binary_paths": get_binary_paths(
+2 −0
Original line number Diff line number Diff line
@@ -323,6 +323,7 @@ def get_processing_chain(
                    "preamble": preamble,
                    "evs_lfe_9k6bps_nb": evs_lfe_9k6bps_nb,
                    "sba_fmt": cond_cfg.get("sba_fmt", tmp_in_fmt),
                    "use_windows_codec_binaries": cfg.use_windows_codec_binaries,
                }
            )
        )
@@ -408,6 +409,7 @@ def get_processing_chain(
                    "multiprocessing": cfg.multiprocessing,
                    "tx": tx_cfg,
                    "preamble": preamble,
                    "use_windows_codec_binaries": cfg.use_windows_codec_binaries,
                }
            )
        )
+28 −7
Original line number Diff line number Diff line
@@ -34,11 +34,10 @@ from copy import deepcopy
from pathlib import Path

import yaml
import platform

from ivas_processing_scripts.constants import (
    DEFAULT_CONFIG,
    DEFAULT_CONFIG_EVS,
    DEFAULT_CONFIG_IVAS,
    REQUIRED_KEYS,
    REQUIRED_KEYS_ESDRU,
    REQUIRED_KEYS_EVS,
@@ -46,7 +45,7 @@ from ivas_processing_scripts.constants import (
    REQUIRED_KEYS_MNRU,
    SUPPORTED_CONDITIONS,
)
from ivas_processing_scripts.utils import get_abs_path
from ivas_processing_scripts.utils import get_abs_path, find_binary


def merge_dicts(base: dict, other: dict) -> None:
@@ -64,6 +63,21 @@ def merge_dicts(base: dict, other: dict) -> None:
            base[k] = other[k]


def get_default_config_for_codecs(codec_name: str, ext_with_dot: str = "") -> dict:
    cod_bin = f"{codec_name}_cod{ext_with_dot}"
    dec_bin = f"{codec_name}_dec{ext_with_dot}"

    cfg = {
        "cod": {
            "bin": find_binary(cod_bin, raise_error=False),
        },
        "dec": {
            "bin": find_binary(dec_bin, raise_error=False),
        },
    }
    return cfg


class TestConfig:
    # avoid confusion with pytest tests due to naming
    __test__ = False
@@ -82,10 +96,11 @@ class TestConfig:
        file_cfg = self._parse_yaml(filename)

        # validate configuration from file
        self._validate(file_cfg)
        self._validate_file_cfg(file_cfg, cfg["use_windows_codec_binaries"])

        # merge dictionaries, overriding from config file
        merge_dicts(cfg, file_cfg)
        self._validate_merged_config(cfg)

        # set attributes from merged dictionary
        self.__dict__.update(cfg)
@@ -117,7 +132,7 @@ class TestConfig:

        return cfg

    def _validate(self, cfg: dict):
    def _validate_file_cfg(self, cfg: dict, use_windows_codec_binaries: bool):
        """ensure configuration contains required keys"""
        MISSING_KEYS = []
        # check required keys
@@ -170,6 +185,7 @@ class TestConfig:
                        "Background noise file has to be placed outside the input folder!"
                    )

        codec_bin_extension = ".exe" if platform.system() == "Linux" and use_windows_codec_binaries else ""
        for cond_name, cond_cfg in cfg.get("conditions_to_generate").items():
            type = cond_cfg.get("type")
            if not type:
@@ -181,7 +197,7 @@ class TestConfig:
                    f"Condition type {cond_cfg.get('type')} is unsuported! Must be one of '{SUPPORTED_CONDITIONS}'"
                )
            elif type == "evs":
                merged_cfg = deepcopy(DEFAULT_CONFIG_EVS)
                merged_cfg = get_default_config_for_codecs("EVS", codec_bin_extension)
                merge_dicts(merged_cfg, cond_cfg)
                cfg["conditions_to_generate"][cond_name] = merged_cfg
                if REQUIRED_KEYS_EVS.difference(
@@ -191,7 +207,7 @@ class TestConfig:
                        f"The following key(s) must be specified for EVS: {REQUIRED_KEYS_EVS}"
                    )
            elif type == "ivas":
                merged_cfg = deepcopy(DEFAULT_CONFIG_IVAS)
                merged_cfg = get_default_config_for_codecs("IVAS", codec_bin_extension)
                merge_dicts(merged_cfg, cond_cfg)
                cfg["conditions_to_generate"][cond_name] = merged_cfg
                if REQUIRED_KEYS_IVAS.difference(
@@ -214,3 +230,8 @@ class TestConfig:
                    raise KeyError(
                        f"The following key must be specified for ESDRU: {REQUIRED_KEYS_ESDRU}"
                    )

    def _validate_merged_config(self, cfg: dict):
        # if not on windows, but "use_windows_codec_binaries" is given, assure that wine is there
        if platform.system() == "Linux" and cfg["use_windows_codec_binaries"] and find_binary("wine") is None:
            raise FileNotFoundError("Using windows binaries on Linux requires wine")
 No newline at end of file
+8 −2
Original line number Diff line number Diff line
@@ -64,12 +64,14 @@ class EVS(Processing):
        self.name = "evs"
        self.in_fmt = audio.fromtype(self.in_fmt)
        self._validate()
        self._use_wine = platform.system() == "Linux" and self.use_windows_codec_binaries

    def _validate(
        self,
    ):
        need_exe_suffix = platform.system() == "Windows" or self.use_windows_codec_binaries
        if not self.cod_bin or not Path(self.cod_bin).exists():
            if platform.system() == "Windows" and (
            if need_exe_suffix and (
                self.cod_bin and Path(self.cod_bin).with_suffix(".exe").exists()
            ):
                self.cod_bin = Path(self.cod_bin).with_suffix(".exe")
@@ -78,7 +80,7 @@ class EVS(Processing):
                    "The EVS encoder binary was not found! Please check the configuration."
                )
        if not self.dec_bin or not Path(self.dec_bin).exists():
            if platform.system() == "Windows" and (
            if need_exe_suffix and (
                self.dec_bin and Path(self.dec_bin).with_suffix(".exe").exists()
            ):
                self.dec_bin = Path(self.dec_bin).with_suffix(".exe")
@@ -286,6 +288,8 @@ class EVS(Processing):
        logger: Optional[logging.Logger] = None,
    ) -> None:
        cmd = [self.cod_bin]
        if self._use_wine:
            cmd.insert(0, "wine")

        # in case of LFE 9.6 kbps NB processing strip any "-max_band XX" from cmd.extend and amend by "-max_band NB"
        if proc_chan_lfe_9k6bps_nb is True:
@@ -381,6 +385,8 @@ class EVS(Processing):
        logger: Optional[logging.Logger] = None,
    ) -> None:
        cmd = [self.dec_bin]
        if self._use_wine:
            cmd.insert(0, "wine")

        if self.dec_opts:
            cmd.extend(self.dec_opts)
+9 −2
Original line number Diff line number Diff line
@@ -60,10 +60,12 @@ class IVAS(Processing):
        self.out_fmt = audio.fromtype(self.out_fmt)
        if not hasattr(self, "dec_opts"):
            self.dec_opts = None
        self._use_wine = platform.system() == "Linux" and self.use_windows_codec_binaries

    def _validate(self):
        need_exe_suffix = platform.system() == "Windows" or self.use_windows_codec_binaries
        if not self.cod_bin or not Path(self.cod_bin).exists():
            if platform.system() == "Windows" and (
            if need_exe_suffix and (
                self.cod_bin and Path(self.cod_bin).with_suffix(".exe").exists()
            ):
                self.cod_bin = Path(self.cod_bin).with_suffix(".exe")
@@ -72,7 +74,7 @@ class IVAS(Processing):
                    "The IVAS encoder binary was not found! Please check the configuration."
                )
        if not self.dec_bin or not Path(self.dec_bin).exists():
            if platform.system() == "Windows" and (
            if need_exe_suffix and (
                self.dec_bin and Path(self.dec_bin).with_suffix(".exe").exists()
            ):
                self.dec_bin = Path(self.dec_bin).with_suffix(".exe")
@@ -181,6 +183,8 @@ class IVAS(Processing):
            raise ValueError(f"IVAS: invalid audio input extension: {in_file.suffix}")

        cmd = [self.cod_bin]
        if self._use_wine:
            cmd.insert(0, "wine")

        if self.cod_opts:
            cmd.extend(self.cod_opts)
@@ -272,6 +276,9 @@ class IVAS(Processing):
        logger.debug(f"IVAS decoder {bitstream} -> {out_file}")

        cmd = [self.dec_bin]
        if self._use_wine:
            cmd.insert(0, "wine")

        if hasattr(self, "trajectory"):
            cmd.extend(["-T", self.trajectory])