Commit 06472228 authored by Jan Kiene's avatar Jan Kiene
Browse files

remove old format switching tests

parent ede69ff2
Loading
Loading
Loading
Loading
+0 −155
Original line number Diff line number Diff line
#!/usr/bin/env python3

__copyright__ = """
(C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
contributors to this repository. All Rights Reserved.

This software is protected by copyright law and by international treaties.
The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
contributors to this repository retain full ownership rights in their respective contributions in
the software. This notice grants no license of any kind, including but not limited to patent
license, nor is any license granted by implication, estoppel or otherwise.

Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
contributions.

This software is provided "AS IS", without any express or implied warranties. The software is in the
development stage. It is intended exclusively for experts who have experience with such software and
solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
and fitness for a particular purpose are hereby disclaimed and excluded.

Any dispute, controversy or claim arising under or in relation to providing this software shall be
submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
the United Nations Convention on Contracts on the International Sales of Goods.
"""

__doc__ = """
To configure test modules.
"""

import os
import sys
from tempfile import TemporaryDirectory
from pathlib import Path

ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
sys.path.append(ROOT_DIR)

from tests.conftest import EncoderFrontend, DecoderFrontend
from tests.renderer.constants import (
    FORMAT_TO_FILE_COMPARETEST,
    FORMAT_TO_METADATA_FILES,
)
import platform

BIN_EXT = ".exe" if platform.system() == "Windows" else ""

FORMAT_ARGUMENT_MAPPING = {
    "MONO": [],
    "STEREO": ["-stereo"],
    "5_1": ["-mc", "5_1"],
    "7_1": ["-mc", "7_1"],
    "5_1_2": ["-mc", "5_1_2"],
    "5_1_4": ["-mc", "5_1_4"],
    "7_1_4": ["-mc", "7_1_4"],
    "FOA": ["-sba", "+1"],
    "HOA2": ["-sba", "+2"],
    "HOA3": ["-sba", "+3"],
    "ISM1": ["-ism", "1"],
    "ISM2": ["-ism", "2"],
    "ISM3": ["-ism", "3"],
    "ISM4": ["-ism", "4"],
    "MASA1": ["-masa", "1"],
    "MASA2": ["-masa", "2"],
    "ISM1MASA1": ["-ism_masa", "1", "1"],
    "ISM2MASA1": ["-ism_masa", "2", "1"],
    "ISM3MASA1": ["-ism_masa", "3", "1"],
    "ISM4MASA1": ["-ism_masa", "4", "1"],
    "ISM1MASA2": ["-ism_masa", "1", "2"],
    "ISM2MASA2": ["-ism_masa", "2", "2"],
    "ISM3MASA2": ["-ism_masa", "3", "2"],
    "ISM4MASA2": ["-ism_masa", "4", "2"],
    "ISM1SBA1": ["-ism_sba", "1", "+1"],
    "ISM1SBA2": ["-ism_sba", "1", "+2"],
    "ISM1SBA3": ["-ism_sba", "1", "+3"],
    "ISM2SBA1": ["-ism_sba", "2", "+1"],
    "ISM2SBA2": ["-ism_sba", "2", "+2"],
    "ISM2SBA3": ["-ism_sba", "2", "+3"],
    "ISM3SBA1": ["-ism_sba", "3", "+1"],
    "ISM3SBA2": ["-ism_sba", "3", "+2"],
    "ISM3SBA3": ["-ism_sba", "3", "+3"],
    "ISM4SBA1": ["-ism_sba", "4", "+1"],
    "ISM4SBA2": ["-ism_sba", "4", "+2"],
    "ISM4SBA3": ["-ism_sba", "4", "+3"],
}

def test_format_switching_new_encoder (
    record_property,
    dut_decoder_frontend: DecoderFrontend
):
    bitrate = 48000
    fs = 48
    outMode = ""
    cut_suffix = "_cut.wav"

    dut_encoder_path = Path(ROOT_DIR).joinpath(f"IVAS_cod{BIN_EXT}")
    dut_encoder_fmtsw_path = Path(ROOT_DIR).joinpath(f"IVAS_cod_fmtsw{BIN_EXT}")
    dut_encoder_fmtsw_frontend = EncoderFrontend(
        dut_encoder_fmtsw_path, "DUT", record_property
    )

    with TemporaryDirectory() as tmp_dir:

        # Create file for encoding commands
        temp_format_switching_file = Path(tmp_dir).joinpath("format_switching_input.txt").absolute()
        temp_rtpdump = Path(tmp_dir).joinpath("output_concatenated.rtpdump").absolute()
        with open (temp_format_switching_file, mode="a") as outFile:
            for key, audioFile in FORMAT_TO_FILE_COMPARETEST.items():
                if key in ["META", "16ch_8+4+4", "4d4", "t_design_4"]:
                    break

                encoder_args = []
                encoder_args += [str(dut_encoder_path)]
                encoder_args += ["-rtpdump", "1"]
                encoder_args += FORMAT_ARGUMENT_MAPPING[key]
                if key in FORMAT_TO_METADATA_FILES:
                    encoder_args += FORMAT_TO_METADATA_FILES[key]
                elif "SBA" in key:
                    # ISM metadata files for OSBA
                    encoder_args += FORMAT_TO_METADATA_FILES[key[:4]]
                encoder_args += [str(bitrate)]
                encoder_args += [str(fs)]
                cutFile = Path( str(audioFile).replace(".wav", cut_suffix) )
                encoder_args += [str(cutFile)]
                encoder_args += [str(temp_rtpdump)]

                outFile.write(' '.join(encoder_args))
                outFile.write("\n")

        # Encode with the format switch encoder
        dut_encoder_fmtsw_frontend.run(
            bitrate='',
            input_sampling_rate='',
            input_path=temp_format_switching_file,
            output_bitstream_path='',
            quiet_mode=False,
            fmtsw_command=True
        )

        # Decode the combined bitstreams
        cat_output_rtpdump = Path(tmp_dir).joinpath(f"output_concatenated.wav").absolute()

        dut_decoder_frontend.run(
            output_config=outMode,
            output_sampling_rate=48,
            input_bitstream_path=temp_rtpdump,
            output_path=cat_output_rtpdump,
            add_option_list= ["-VOIP_HF_ONLY=1"]
        )