From 302c07ce1698178278548a1523674c639915ad35 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Mon, 15 Sep 2025 14:36:53 +0200 Subject: [PATCH] rework logic around binary paths for codecs --- .../audiotools/wrappers/masaRenderer.py | 6 ++- ivas_processing_scripts/processing/evs.py | 31 ++++----------- ivas_processing_scripts/processing/ivas.py | 38 ++----------------- .../processing/ivas_combined.py | 26 ++----------- ivas_processing_scripts/utils.py | 16 ++++++++ 5 files changed, 35 insertions(+), 82 deletions(-) diff --git a/ivas_processing_scripts/audiotools/wrappers/masaRenderer.py b/ivas_processing_scripts/audiotools/wrappers/masaRenderer.py index 198db6f4..b0f6f853 100755 --- a/ivas_processing_scripts/audiotools/wrappers/masaRenderer.py +++ b/ivas_processing_scripts/audiotools/wrappers/masaRenderer.py @@ -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, diff --git a/ivas_processing_scripts/processing/evs.py b/ivas_processing_scripts/processing/evs.py index d2aec675..ea0a4a52 100755 --- a/ivas_processing_scripts/processing/evs.py +++ b/ivas_processing_scripts/processing/evs.py @@ -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): diff --git a/ivas_processing_scripts/processing/ivas.py b/ivas_processing_scripts/processing/ivas.py index 9ee079a3..f427d2e2 100755 --- a/ivas_processing_scripts/processing/ivas.py +++ b/ivas_processing_scripts/processing/ivas.py @@ -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, diff --git a/ivas_processing_scripts/processing/ivas_combined.py b/ivas_processing_scripts/processing/ivas_combined.py index b7374907..f1b9c84b 100755 --- a/ivas_processing_scripts/processing/ivas_combined.py +++ b/ivas_processing_scripts/processing/ivas_combined.py @@ -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: diff --git a/ivas_processing_scripts/utils.py b/ivas_processing_scripts/utils.py index af55590a..08c7bbe2 100755 --- a/ivas_processing_scripts/utils.py +++ b/ivas_processing_scripts/utils.py @@ -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, -- GitLab