Commit 0b5515d7 authored by Jan Kiene's avatar Jan Kiene
Browse files

add -max_band parameter in encoder

parent 2fe19f7a
Loading
Loading
Loading
Loading
+33 −3
Original line number Diff line number Diff line
@@ -30,8 +30,15 @@ the United Nations Convention on Contracts on the International Sales of Goods.

import filecmp
import subprocess
from itertools import product
from ..testconfig import MD5_REF_DICT
from .constants import TESTVECTOR_FOR_INPUT_FORMAT, TESTV_PATH, REF_PATH
from .constants import (
    TESTVECTOR_FOR_INPUT_FORMAT,
    TESTV_PATH,
    REF_PATH,
    SAMPLING_RATES_ALL,
    MAX_BAND_ALL,
)


def is_be_to_ref(dut_file):
@@ -51,12 +58,35 @@ def is_be_to_ref(dut_file):


def get_bitstream_path(
    base_path, testv_name, encoder_format, bitrate, sampling_rate, dtx, suffix=""
    base_path,
    testv_name,
    encoder_format,
    bitrate,
    sampling_rate,
    max_band,
    dtx,
    suffix="",
):
    bs_name = f"{testv_name}-{encoder_format}-{bitrate}kbps-{sampling_rate}kHz-{dtx}{suffix}.192"
    bs_name = f"{testv_name}-{encoder_format}-{bitrate}kbps-{sampling_rate}kHz-max_band_{max_band}-{dtx}{suffix}.192"
    return base_path.joinpath(bs_name)


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


def get_valid_fs_max_band_pairs(add_narrow_band: bool = False):
    """
    Get all sensible sampling rate and max_band value combinations, i.e. pair each sampling rate
    with all bw options which indicate the same or lower bandwidth (codec will "crop" if bw
    given is higher than sampling rate).

    add_narrow_band: include NB in max_band values, this only applies for stereo_dmx_evs
    """
    fs, mb = SAMPLING_RATES_ALL, list(MAX_BAND_ALL)
    if add_narrow_band:
        mb.insert(0, "NB")

    params = [(r, b) for r, b in product(fs, mb) if fs.index(r) >= mb.index(b)]
    return params
+8 −23
Original line number Diff line number Diff line
@@ -154,6 +154,7 @@ CMDL_OPTIONS_FOR_INPUT_FORMAT = {
    "MASA_2TC_2DIR": ["-masa", "2"],
    "OMASA": ["-ism_masa"],
    "OSBA": ["-ism_sba"],
    "STEREO_DMX_EVS": ["-stereo_dmx_evs"],
}

### Test case parameters
@@ -205,6 +206,7 @@ BITRATES_ISM4_EXTENDED = [b for b in BITRATES_ISM4 if b > 64000]
BITRATES_EVS = [5900, 7200, 8000, 9600] + BITRATES_ALL[:6] + BITRATES_ALL[7:9]

SAMPLING_RATES_ALL = [16, 32, 48]
MAX_BAND_ALL = ["WB", "SWB", "FB"]

OUTPUT_FORMATS_ALL = [
    "MONO",
@@ -228,13 +230,9 @@ OUTPUT_FORMATS_NON_BINAURAL = OUTPUT_FORMATS_ALL[:11]

### -------------- encoder parameter lists --------------

STEREO_PARAMS = list(
    product(["STEREO"], BITRATES_STEREO, SAMPLING_RATES_ALL, [DTX_OFF, DTX_ON])
)
MC_PARAMS = list(product(INPUT_FORMATS_MC, BITRATES_ALL, SAMPLING_RATES_ALL, [DTX_OFF]))
MASA_PARAMS = list(
    product(INPUT_FORMATS_MASA, BITRATES_ALL, SAMPLING_RATES_ALL, [DTX_OFF, DTX_ON])
)
STEREO_PARAMS = list(product(["STEREO"], BITRATES_STEREO, [DTX_OFF, DTX_ON]))
MC_PARAMS = list(product(INPUT_FORMATS_MC, BITRATES_ALL, [DTX_OFF]))
MASA_PARAMS = list(product(INPUT_FORMATS_MASA, BITRATES_ALL, [DTX_OFF, DTX_ON]))
ENCODER_CHANNEL_BASED_AND_MASA_PARAMS = STEREO_PARAMS + MC_PARAMS + MASA_PARAMS


@@ -244,7 +242,6 @@ ISM1_BASIC_NULL_PARAMS = list(
    product(
        ["ISM1"],
        BITRATES_ISM1,
        SAMPLING_RATES_ALL,
        [DTX_OFF, DTX_ON],
        [ISM_MD_BASIC, ISM_MD_NULL],
    )
@@ -253,7 +250,6 @@ ISM2_BASIC_NULL_PARAMS = list(
    product(
        ["ISM2"],
        BITRATES_ISM2,
        SAMPLING_RATES_ALL,
        [DTX_OFF, DTX_ON],
        [ISM_MD_BASIC, ISM_MD_NULL],
    )
@@ -262,7 +258,6 @@ ISM3_BASIC_NULL_PARAMS = list(
    product(
        ["ISM3"],
        BITRATES_ISM3,
        SAMPLING_RATES_ALL,
        [DTX_OFF, DTX_ON],
        [ISM_MD_BASIC, ISM_MD_NULL],
    )
@@ -271,7 +266,6 @@ ISM4_BASIC_NULL_PARAMS = list(
    product(
        ["ISM4"],
        BITRATES_ISM4,
        SAMPLING_RATES_ALL,
        [DTX_OFF, DTX_ON],
        [ISM_MD_BASIC, ISM_MD_NULL],
    )
@@ -280,7 +274,6 @@ ISM1_EXTENDED_PARAMS = list(
    product(
        ["ISM1"],
        BITRATES_ISM1_EXTENDED,
        SAMPLING_RATES_ALL,
        [DTX_OFF, DTX_ON],
        [ISM_MD_EXTENDED],
    )
@@ -289,7 +282,6 @@ ISM2_EXTENDED_PARAMS = list(
    product(
        ["ISM2"],
        BITRATES_ISM2_EXTENDED,
        SAMPLING_RATES_ALL,
        [DTX_OFF, DTX_ON],
        [ISM_MD_EXTENDED],
    )
@@ -298,7 +290,6 @@ ISM3_EXTENDED_PARAMS = list(
    product(
        ["ISM3"],
        BITRATES_ISM3_EXTENDED,
        SAMPLING_RATES_ALL,
        [DTX_OFF, DTX_ON],
        [ISM_MD_EXTENDED],
    )
@@ -307,7 +298,6 @@ ISM4_EXTENDED_PARAMS = list(
    product(
        ["ISM4"],
        BITRATES_ISM4_EXTENDED,
        SAMPLING_RATES_ALL,
        [DTX_OFF, DTX_ON],
        [ISM_MD_EXTENDED],
    )
@@ -330,7 +320,6 @@ SBA_LOW_BITRATES_PARAMS = list(
        product(
            INPUT_FORMATS_SCENE_BASED,
            BITRATES_ALL[:7],
            SAMPLING_RATES_ALL,
            [DTX_OFF, DTX_ON],
            [SBA_FOA_PCA_OFF],
        )
@@ -341,7 +330,6 @@ SBA_HIGH_BITRATES_PARAMS = list(
        product(
            INPUT_FORMATS_SCENE_BASED,
            BITRATES_ALL[7:],
            SAMPLING_RATES_ALL,
            [DTX_OFF],
            [SBA_FOA_PCA_OFF],
        )
@@ -351,7 +339,6 @@ SBA_FOA_PCA_PARAMS = list(
    product(
        [f for f in INPUT_FORMATS_SCENE_BASED if "FOA" in f],
        [256000],
        SAMPLING_RATES_ALL,
        [DTX_OFF],
        [SBA_FOA_PCA_ON],
    )
@@ -360,9 +347,9 @@ SBA_PARAMS = SBA_LOW_BITRATES_PARAMS + SBA_HIGH_BITRATES_PARAMS + SBA_FOA_PCA_PA


# All EVS bitrates, 5900 VBR always needs -dtx
STEREO_DMX_EVS_PARAMS = list(
    product(BITRATES_EVS[1:], SAMPLING_RATES_ALL, [DTX_OFF, DTX_ON])
) + list(product(BITRATES_EVS[:1], SAMPLING_RATES_ALL, [DTX_ON]))
STEREO_DMX_EVS_PARAMS = list(product(BITRATES_EVS[1:], [DTX_OFF, DTX_ON])) + list(
    product(BITRATES_EVS[:1], [DTX_ON])
)


OSBA_PARAMS = list(
@@ -372,7 +359,6 @@ OSBA_PARAMS = list(
            f for f in INPUT_FORMATS_SCENE_BASED if not f.startswith("Planar")
        ],  # TODO: enable planar once clarified
        BITRATES_ALL,
        SAMPLING_RATES_ALL,
        [ISM_MD_BASIC, ISM_MD_NULL, ISM_MD_EXTENDED],
    )
)
@@ -381,7 +367,6 @@ OMASA_PARAMS = list(
        INPUT_FORMATS_OBJECT_BASED,
        INPUT_FORMATS_MASA,
        BITRATES_ALL,
        SAMPLING_RATES_ALL,
        [ISM_MD_BASIC, ISM_MD_NULL, ISM_MD_EXTENDED],
    )
)
+11 −1
Original line number Diff line number Diff line
@@ -106,13 +106,18 @@ def get_md(input_format, md_type=None):
    return md_files


def get_options(input_format, md_type=None):
def get_options(input_format, max_band=None, md_type=None):
    options = list(CMDL_OPTIONS_FOR_INPUT_FORMAT[input_format])

    if md_type == ISM_MD_EXTENDED:
        assert input_format in INPUT_FORMATS_OBJECT_BASED
        options[1] = f"+{options[1]}"
    md_options = get_md(input_format, md_type)
    options.extend(md_options)

    if max_band is not None:
        options.extend(["-max_band", max_band])

    return options


@@ -128,15 +133,20 @@ def run_check(
    bitstream_suffix="",
):
    bs_path = REF_PATH if is_ref_creation else DUT_PATH

    max_band = options[options.index("-max_band") + 1]

    bitstream = get_bitstream_path(
        bs_path,
        testv.stem,
        input_format,
        bitrate,
        sampling_rate,
        max_band,
        dtx,
        suffix=bitstream_suffix,
    )
    print(options)
    encoder_frontend.run(
        bitrate,
        sampling_rate,
+25 −15
Original line number Diff line number Diff line
@@ -40,26 +40,33 @@ from ..constants import (
    SBA_FOA_PCA_ON,
    STEREO_DMX_EVS_PARAMS,
    COMBINED_FORMATS_PARAMS,
    DUT_PATH,
)
from . import get_options, run_check
from .. import get_testv_path, get_bitstream_path
from .. import get_testv_path, get_valid_fs_max_band_pairs


def pytest_generate_tests(metafunc):
    if "max_band" in metafunc.fixturenames and "sampling_rate" in metafunc.fixturenames:
        add_narrow_band = "stereo_dmx_evs" in metafunc.function.__name__
        params = get_valid_fs_max_band_pairs(add_narrow_band)
        metafunc.parametrize("sampling_rate,max_band", params)


# channel-based modes + MASA
@pytest.mark.parametrize(
    "input_format,bitrate,sampling_rate,dtx", ENCODER_CHANNEL_BASED_AND_MASA_PARAMS
    "input_format,bitrate,dtx", ENCODER_CHANNEL_BASED_AND_MASA_PARAMS
)
def test_encoder_const_br_channel_based_and_masa_modes(
    input_format,
    bitrate,
    sampling_rate,
    max_band,
    dtx,
    dut_encoder_frontend,
    update_ref,
):
    testv = get_testv_path(input_format, sampling_rate)
    options = get_options(input_format)
    options = get_options(input_format, max_band)
    run_check(
        input_format,
        bitrate,
@@ -72,18 +79,19 @@ def test_encoder_const_br_channel_based_and_masa_modes(
    )


@pytest.mark.parametrize("input_format,bitrate,sampling_rate,dtx,md_type", ISM_PARAMS)
@pytest.mark.parametrize("input_format,bitrate,dtx,md_type", ISM_PARAMS)
def test_encoder_const_br_object_based_modes(
    input_format,
    bitrate,
    sampling_rate,
    max_band,
    dtx,
    md_type,
    dut_encoder_frontend,
    update_ref,
):
    testv = get_testv_path(input_format, sampling_rate)
    options = get_options(input_format, md_type)
    options = get_options(input_format, max_band, md_type=md_type)
    bitstream_suffix = "_basic_MD"
    if md_type == ISM_MD_EXTENDED:
        bitstream_suffix = "_ext_MD"
@@ -102,18 +110,19 @@ def test_encoder_const_br_object_based_modes(
    )


@pytest.mark.parametrize("input_format,bitrate,sampling_rate,dtx,pca", SBA_PARAMS)
@pytest.mark.parametrize("input_format,bitrate,dtx,pca", SBA_PARAMS)
def test_encoder_const_br_scenebased(
    input_format,
    bitrate,
    sampling_rate,
    max_band,
    dtx,
    pca,
    dut_encoder_frontend,
    update_ref,
):
    testv = get_testv_path(input_format, sampling_rate)
    options = get_options(input_format)
    options = get_options(input_format, max_band)
    bitstream_suffix = ""
    if pca == SBA_FOA_PCA_ON:
        options.extend(["-bypass", "2"])
@@ -131,13 +140,13 @@ def test_encoder_const_br_scenebased(
    )


@pytest.mark.parametrize("bitrate,sampling_rate,dtx", STEREO_DMX_EVS_PARAMS)
@pytest.mark.parametrize("bitrate,dtx", STEREO_DMX_EVS_PARAMS)
def test_encoder_const_br_stereo_dmx_evs(
    bitrate, sampling_rate, dtx, dut_encoder_frontend, update_ref
    bitrate, sampling_rate, max_band, dtx, dut_encoder_frontend, update_ref
):
    testv = get_testv_path("STEREO", sampling_rate)
    options = ["-stereo_dmx_evs"]
    input_format = "StereoDmxEvs"
    input_format = "STEREO_DMX_EVS"
    options = get_options(input_format, max_band)
    run_check(
        input_format,
        bitrate,
@@ -151,7 +160,7 @@ def test_encoder_const_br_stereo_dmx_evs(


@pytest.mark.parametrize(
    "input_format_ism,input_format_other,bitrate,sampling_rate,md_type",
    "input_format_ism,input_format_other,bitrate,md_type",
    COMBINED_FORMATS_PARAMS,
)
def test_encoder_const_br_combined_formats(
@@ -159,6 +168,7 @@ def test_encoder_const_br_combined_formats(
    input_format_other,
    bitrate,
    sampling_rate,
    max_band,
    md_type,
    dut_encoder_frontend,
    update_ref,
@@ -168,9 +178,9 @@ def test_encoder_const_br_combined_formats(
        f"{input_format_combined}_{input_format_ism}_{input_format_other}",
        sampling_rate,
    )
    options_ism = get_options(input_format_ism, md_type)
    options_ism = get_options(input_format_ism, md_type=md_type)
    options_other = get_options(input_format_other)
    options_combined = get_options(input_format_combined)
    options_combined = get_options(input_format_combined, max_band)
    # glue together: combined mode option, ism num, SBA order/MASA TCs, ISM MD files, MASA MD files (slice results in empty list for OSBA)
    options = (
        options_combined