Commit 8dfc3196 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

rework logic around binary paths for codecs

parent 6937f0d2
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ from ivas_processing_scripts.audiotools import audio
from ivas_processing_scripts.audiotools.audiofile import read, write
from ivas_processing_scripts.audiotools.wrappers.filter import resample_itu
from ivas_processing_scripts.constants import DEFAULT_CONFIG_BINARIES
from ivas_processing_scripts.utils import find_binary, run
from ivas_processing_scripts.utils import find_binary, get_binary_path, run


def ivasRendMasa(
@@ -51,7 +51,7 @@ def ivasRendMasa(
    logger: Optional[logging.Logger] = None,
) -> np.ndarray:
    """
    Wrapper for IVAS_Rend MASA Rendering
    Wrapper for IVAS_rend MASA Rendering

    Parameters
    ----------
@@ -78,6 +78,8 @@ def ivasRendMasa(
    else:
        binary = find_binary("IVAS_rend")

    binary = get_binary_path(binary, False)

    rend = IVAS_rend(
        {
            "bin": binary,
+8 −23
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@

import logging
import os.path
import platform
from itertools import repeat
from pathlib import Path
from shutil import copyfile
@@ -55,7 +54,12 @@ from ivas_processing_scripts.audiotools.wrappers.eid_xor import (
    validate_error_pattern_application,
)
from ivas_processing_scripts.processing.processing import Processing
from ivas_processing_scripts.utils import apply_func_parallel, run, use_wine
from ivas_processing_scripts.utils import (
    apply_func_parallel,
    get_binary_path,
    run,
    use_wine,
)


class EVS(Processing):
@@ -69,27 +73,8 @@ class EVS(Processing):
    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 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")
            else:
                raise FileNotFoundError(
                    "The EVS encoder binary was not found! Please check the configuration."
                )
        if not self.dec_bin or not Path(self.dec_bin).exists():
            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")
            else:
                raise FileNotFoundError(
                    "The EVS decoder binary was not found! Please check the configuration."
                )
        self.cod_bin = get_binary_path(self.cod_bin, self.use_windows_codec_binaries)
        self.dec_bin = get_binary_path(self.dec_bin, self.use_windows_codec_binaries)

        # configure per-channel bitrate if specified, otherwise simply repeat
        if not isinstance(self.bitrate, list):
+4 −34
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ from ivas_processing_scripts.audiotools.wrappers.networkSimulator import (
)
from ivas_processing_scripts.audiotools.wrappers.random_seed import random_seed
from ivas_processing_scripts.processing.processing import Processing
from ivas_processing_scripts.utils import run, use_wine
from ivas_processing_scripts.utils import get_binary_path, run, use_wine


class IVAS(Processing):
@@ -68,27 +68,8 @@ class IVAS(Processing):
        self._validate()

    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 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")
            else:
                raise FileNotFoundError(
                    "The IVAS encoder binary was not found! Please check the configuration."
                )
        if not self.dec_bin or not Path(self.dec_bin).exists():
            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")
            else:
                raise FileNotFoundError(
                    "The IVAS decoder binary was not found! Please check the configuration."
                )
        self.cod_bin = get_binary_path(self.cod_bin, self.use_windows_codec_binaries)
        self.dec_bin = get_binary_path(self.dec_bin, self.use_windows_codec_binaries)

        # existence of error pattern files (if given) already here
        if self.tx is not None:
@@ -497,18 +478,7 @@ class IVAS_rend(Processing):
        )

    def _validate(self):
        need_exe_suffix = (
            platform.system() == "Windows" or self.use_windows_codec_binaries
        )
        if not Path(self.bin).exists():
            if need_exe_suffix and (
                self.bin and Path(self.bin).with_suffix(".exe").exists()
            ):
                self.bin = Path(self.bin).with_suffix(".exe")
            else:
                raise FileNotFoundError(
                    "The IVAS renderer binary was not found! Please check the configuration."
                )
        self.bin = get_binary_path(self.bin, self.use_windows_codec_binaries)

    def process(
        self,
+3 −23
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@
#

import logging
import platform
from pathlib import Path
from warnings import warn

@@ -45,7 +44,7 @@ from ivas_processing_scripts.audiotools.wrappers.networkSimulator import (
)
from ivas_processing_scripts.processing.ivas import IVAS
from ivas_processing_scripts.processing.processing import Processing
from ivas_processing_scripts.utils import use_wine
from ivas_processing_scripts.utils import get_binary_path, use_wine


class IVASCombined(Processing):
@@ -68,27 +67,8 @@ class IVASCombined(Processing):
        )

    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 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")
            else:
                raise FileNotFoundError(
                    "The IVAS encoder binary was not found! Please check the configuration."
                )
        if not self.dec_bin or not Path(self.dec_bin).exists():
            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")
            else:
                raise FileNotFoundError(
                    "The IVAS decoder binary was not found! Please check the configuration."
                )
        self.cod_bin = get_binary_path(self.cod_bin, self.use_windows_codec_binaries)
        self.dec_bin = get_binary_path(self.dec_bin, self.use_windows_codec_binaries)

        # existence of error pattern files (if given) already here
        if self.tx is not None:
+16 −0
Original line number Diff line number Diff line
@@ -152,6 +152,22 @@ def use_wine(use_windows_codec_binaries: bool):
    return linux_system and not wsl and use_windows_codec_binaries


def get_binary_path(binary: str, use_windows_codec_binaries: bool) -> Path:
    need_exe_suffix = platform.system() == "Windows" or use_windows_codec_binaries

    if need_exe_suffix and binary:
        binary = Path(binary).with_suffix(".exe")

    if not binary or not binary.exists():
        raise FileNotFoundError(
            f"The binary {binary.name} was not found!"
            f"\nProvided path was '{binary}'."
            "\nPlease check the configuration."
        )

    return binary


def find_binary(
    binary: str,
    raise_error: Optional[bool] = True,