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

some refactoring for clarity and reuse in decoder tests

parent 9311766a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -54,3 +54,10 @@ def is_be_to_ref(dut_file):
        is_be = md5_ref == md5_dut

    return is_be


def get_bitstream_path(
    base_path, testv_name, encoder_format, bitrate, sampling_rate, dtx, suffix=""
):
    bs_name = f"{testv_name}-{encoder_format}-{bitrate}kbps-{sampling_rate}kHz-{dtx}{suffix}.192"
    return base_path.joinpath(bs_name)
+19 −22
Original line number Diff line number Diff line
@@ -31,13 +31,13 @@ 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
from . import TESTV_PATH, DUT_PATH, is_be_to_ref, get_bitstream_path


### --------------- Helper functions ---------------


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

@@ -56,17 +56,11 @@ def get_options(input_format, md_type=None):
    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)
    return options


def get_encoder_inputs(input_format, sampling_rate, md_type=None):
    testv = get_testv(input_format, sampling_rate)
    options = get_options(input_format, md_type)
    md_files = get_md(input_format, md_type)
    options.extend(md_files)
    return testv, options


def run_check(
    dut_bitstream,
    bitrate,
@@ -116,9 +110,10 @@ def test_encoder_channel_based_and_masa_modes(
    dut_encoder_frontend,
    update_ref,
):
    testv, options = get_encoder_inputs(input_format, sampling_rate)
    bitstream = DUT_PATH.joinpath(
        f"{testv.stem}-{input_format}-{bitrate}kbps-{sampling_rate}kHz-{dtx}.192"
    testv = get_testv_path(input_format, sampling_rate)
    options = get_options(input_format)
    bitstream = get_bitstream_path(
        DUT_PATH, testv.stem, input_format, bitrate, sampling_rate, dtx
    )
    run_check(
        bitstream,
@@ -229,13 +224,14 @@ def test_encoder_object_based_modes(
    dut_encoder_frontend,
    update_ref,
):
    testv, options = get_encoder_inputs(input_format, sampling_rate, md_type)
    testv = get_testv_path(input_format, sampling_rate)
    options = get_options(input_format, md_type)
    if md_type == ISM_MD_EXTENDED:
        input_format += "_ext_MD"
    elif md_type == ISM_MD_NULL:
        input_format += "_null_MD"
    bitstream = DUT_PATH.joinpath(
        f"{testv.stem}-{input_format}-{bitrate}kbps-{sampling_rate}kHz-{dtx}.192"
    bitstream = get_bitstream_path(
        DUT_PATH, testv.stem, input_format, bitrate, sampling_rate, dtx
    )
    run_check(
        bitstream,
@@ -284,11 +280,12 @@ SBA_PARAMS = SBA_LOW_BITRATES_PARAMS + SBA_HIGH_BITRATES_PARAMS + SBA_FOA_PCA_PA
def test_encoder_sba(
    input_format, bitrate, sampling_rate, dtx, pca, dut_encoder_frontend, update_ref
):
    testv, options = get_encoder_inputs(input_format, sampling_rate)
    testv = get_testv_path(input_format, sampling_rate)
    options = get_options(input_format)
    if pca == SBA_FOA_PCA_ON:
        options.extend(["-bypass", "2"])
    bitstream = DUT_PATH.joinpath(
        f"{testv.stem}-{input_format}-{bitrate}kbps-{sampling_rate}kHz-{dtx}-{pca}.192"
    bitstream = get_bitstream_path(
        DUT_PATH, testv.stem, input_format, bitrate, sampling_rate, dtx, "-pca"
    )
    run_check(
        bitstream,
@@ -311,10 +308,10 @@ STEREO_DMX_EVS_PARAMS = list(
def test_encoder_stereo_dmx_evs(
    bitrate, sampling_rate, dtx, dut_encoder_frontend, update_ref
):
    testv, _ = get_encoder_inputs("STEREO", sampling_rate)
    testv = get_testv_path("STEREO", sampling_rate)
    options = ["-stereo_dmx_evs"]
    bitstream = DUT_PATH.joinpath(
        f"{testv.stem}-{'StereoDmxEvs'}-{bitrate}kbps-{sampling_rate}kHz-{dtx}.192"
    bitstream = get_bitstream_path(
        DUT_PATH, testv.stem, "StereoDmxEvs", bitrate, sampling_rate, dtx
    )
    run_check(
        bitstream,