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

first encoder testcase

parent 17a3401a
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
__copyright__ = """
(C) 2022-2023 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.
"""

import os
from pathlib import Path
import filecmp
import subprocess
from ..testconfig import MD5_REF_DICT

HERE = Path(__file__).parent
TESTV_PATH = Path(os.environ.get("BE_TESTV_DIR", HERE.joinpath("testv")))
REF_PATH = Path(os.environ.get("BE_REF_DIR", HERE.joinpath("ref")))
DUT_PATH = HERE.joinpath("dut")


def is_be_to_ref(dut_file):
    """
    Check bitexactness either by comparing files directly or by comparing MD5 sums
    """
    if MD5_REF_DICT == dict():
        ref_file = REF_PATH.joinpath(dut_file.name)
        is_be = filecmp.cmp(dut_file, ref_file)
    else:
        md5_ref = MD5_REF_DICT[dut_file.name]
        cmd = f"powershell.exe (Get-FileHash {str(dut_file)} -Algorithm MD5).Hash"
        md5_dut = subprocess.check_output(cmd, shell=True).decode().splitlines()[-1]
        is_be = md5_ref == md5_dut

    return is_be
+118 −0
Original line number Diff line number Diff line
__copyright__ = """
(C) 2022-2023 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.
"""

DTX_ON = "DTXon"
DTX_OFF = "DTXoff"

TESTVECTOR_FOR_INPUT_FORMAT = {
    "STEREO": "ltv{fs}_STEREO.wav",
    "MC_5_1": "ltv{fs}_MC51.wav",
    "MC_5_1_2": "ltv{fs}_MC512.wav",
    "MC_5_1_4": "ltv{fs}_MC514.wav",
    "MC_7_1": "ltv{fs}_MC71.wav",
    "MC_7_1_4": "ltv{fs}_MC714.wav",
    "FOA": "ltv{fs}_FOA.wav",
    "HOA2": "ltv{fs}_HOA2.wav",
    "HOA3": "ltv{fs}_HOA3.wav",
    "ISM1": "ltv{fs}_1ISM.wav",
    "ISM2": "ltv{fs}_2ISM.wav",
    "ISM3": "ltv{fs}_3ISM.wav",
    "ISM4": "ltv{fs}_4ISM.wav",
    # TODO: MASA, once created
}
METADATA_FOR_INPUT_FORMAT = {
    "ISM1": ["ltvISM1.csv"],
    "ISM2": ["ltvISM1.csv", "ltvISM2.csv"],
    "ISM3": ["ltvISM1.csv", "ltvISM2.csv", "ltvISM3.csv"],
    "ISM4": ["ltvISM1.csv", "ltvISM2.csv", "ltvISM3.csv", "ltvISM4.csv"],
    # TODO: MASA, once created
}
CMDL_OPTIONS_FOR_INPUT_FORMAT = {
    "STEREO": ["-stereo"],
    "MC_5_1": ["-mc", "5_1"],
    "MC_5_1_2": ["-mc", "5_1_2"],
    "MC_5_1_4": ["-mc", "5_1_4"],
    "MC_7_1": ["-mc", "7_1"],
    "MC_7_1_4": ["-mc", "7_1_4"],
    "FOA": ["-sba", "+1"],
    "HOA2": ["-sba", "+2"],
    "HOA3": ["-sba", "+3"],
    "PlanarFOA": ["-sba", "-1"],
    "PlanarHOA2": ["-sba", "-2"],
    "PlanarHOA3": ["-sba", "-3"],
    "ISM1": ["-ism", "1"],
    "ISM2": ["-ism", "2"],
    "ISM3": ["-ism", "3"],
    "ISM4": ["-ism", "4"],
}

### Test case parameters

# Input format IDs
INPUT_FORMATS_MC = ["MC_5_1", "MC_5_1_2", "MC_5_1_4", "MC_7_1", "MC_7_1_4"]
INPUT_FORMATS_CHANNEL_BASED = ["STEREO"] + INPUT_FORMATS_MC
INPUT_FORMATS_SCENE_BASED = ["FOA", "HOA2", "HOA3"]
INPUT_FORMATS_OBJECT_BASED = ["ISM1", "ISM2", "ISM3", "ISM4"]
INPUT_FORMATS_MASA = [
    "MASA_1TC_1DIR",
    "MASA_2TC_1DIR",
    "MASA_1TC_2DIR",
    "MASA_2TC_2DIR",
]
# TODO: add MASA back
INPUT_FORMATS_SINGLE = (
    INPUT_FORMATS_CHANNEL_BASED + INPUT_FORMATS_SCENE_BASED + INPUT_FORMATS_OBJECT_BASED
)  # + INPUT_FORMATS_MASA
# TODO: combined formats

# bitrates
BITRATES_ALL = [
    13200,
    16400,
    24400,
    32000,
    48000,
    64000,
    80000,
    96000,
    128000,
    192000,
    256000,
    384000,
    512000,
]
BITRATES_STEREO = BITRATES_ALL[:10]
BITRATES_ISM1 = BITRATES_ALL[:9]
BITRATES_ISM2 = BITRATES_ALL[1:10]
BITRATES_ISM3 = BITRATES_ALL[2:11]
BITRATES_ISM4 = BITRATES_ALL[2:]

# sampling rates
SAMPLING_RATES_ALL = [16, 32, 48]
+120 −0
Original line number Diff line number Diff line
__copyright__ = """
(C) 2022-2023 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.
"""

import pytest
from itertools import product
from .constants import *
from . import TESTV_PATH, DUT_PATH, is_be_to_ref


def get_testv(input_format, sampling_rate):
    testv = TESTVECTOR_FOR_INPUT_FORMAT[input_format].format(fs=sampling_rate)
    return TESTV_PATH.joinpath(testv)


def get_md(input_format):
    md_files = METADATA_FOR_INPUT_FORMAT.get(input_format, list())
    return [str(TESTV_PATH.joinpath(f)) for f in md_files]


def get_options(input_format):
    return list(CMDL_OPTIONS_FOR_INPUT_FORMAT[input_format])


def run_check(
    input_format, bitrate, sampling_rate, dtx, encoder_frontend, is_ref_creation
):
    testv = get_testv(input_format, sampling_rate)
    options = get_options(input_format)
    md_files = get_md(input_format)
    options.extend(md_files)

    bitstream = DUT_PATH.joinpath(
        f"{testv.stem}-{input_format}-{bitrate}kbps-{sampling_rate}kHz-{dtx}.192"
    )

    encoder_frontend.run(
        bitrate,
        sampling_rate,
        str(testv),
        str(bitstream),
        dtx_mode=dtx == DTX_ON,
        add_option_list=options,
    )

    if not is_ref_creation:
        if not is_be_to_ref(bitstream):
            pytest.fail(f"Bitstream file differs from reference")


STEREO_PARAMS = list(
    product(["STEREO"], BITRATES_STEREO, SAMPLING_RATES_ALL, [False, True])
)
MC_PARAMS = list(product(INPUT_FORMATS_MC, BITRATES_ALL, SAMPLING_RATES_ALL, [False]))
SBA_PARAMS = list(
    (
        product(
            INPUT_FORMATS_SCENE_BASED,
            BITRATES_ALL[:7],
            SAMPLING_RATES_ALL,
            [False, True],
        )
    )
) + list(
    (product(INPUT_FORMATS_SCENE_BASED, BITRATES_ALL[7:], SAMPLING_RATES_ALL, [False]))
)
ISM1_PARAMS = list(product(["ISM1"], BITRATES_ISM1, SAMPLING_RATES_ALL, [False, True]))
ISM2_PARAMS = list(product(["ISM2"], BITRATES_ISM2, SAMPLING_RATES_ALL, [False, True]))
ISM3_PARAMS = list(product(["ISM3"], BITRATES_ISM3, SAMPLING_RATES_ALL, [False, True]))
ISM4_PARAMS = list(product(["ISM4"], BITRATES_ISM4, SAMPLING_RATES_ALL, [False, True]))
# TODO: MASA
ENCODER_PARAMS = (
    STEREO_PARAMS
    + MC_PARAMS
    + SBA_PARAMS
    + ISM1_PARAMS
    + ISM2_PARAMS
    + ISM3_PARAMS
    + ISM4_PARAMS
)


@pytest.mark.parametrize("input_format,bitrate,sampling_rate,dtx", ENCODER_PARAMS)
def test_encoder(
    input_format,
    bitrate,
    sampling_rate,
    dtx,
    dut_encoder_frontend,
    update_ref,
):
    run_check(
        input_format, bitrate, sampling_rate, dtx, dut_encoder_frontend, update_ref == 1
    )