Commit ac3f9845 authored by vaclav's avatar vaclav
Browse files

Merge remote-tracking branch 'remotes/origin/main' into 20231020_maintenance

parents b1337a21 21485f9a
Loading
Loading
Loading
Loading
Loading
+103 −36
Original line number Diff line number Diff line
#! /usr/bin/bash

### This test assures that for all DTX modes, decoding a bitstream that starts with an SID frame does not crash the decoder or cause a sanitizer error

set -euo pipefail

collect_failed_logs() {
  local console_output="$1"
  local log_dir="${2:-logs}"
  local output_dir="${3:-failed_logs}"
  local temp_failures=$(mktemp)

  if [ ! -f "$console_output" ]; then
    echo "Error: Console output file '$console_output' not found" >&2
    rm -f "$temp_failures"
    return 1
  fi

  mkdir -p "$output_dir"

  # Extract filenames from failed enc/dec chains from the console log
  # turn off fail on non-zero exit code to not fail on grep not matching any line (which is the case if everything is ok)
  set +e
  grep -iE '(encoding|decoding).*failed|failed.*(encoding|decoding)' "$console_output" |
    grep -oE '[^[:space:]]+\.(192|wav|pcm)' |
    while IFS= read -r filepath; do
      # need basename wihtou suffix only for matching
      filename=$(basename "$filepath")
      filename_no_ext="${filename%.*}"
      echo "$filename_no_ext"
    done | sort -u >"$temp_failures"
  set -e

  # Copy matching log files to output directory
  if [ -s "$temp_failures" ]; then
    echo "Copying log files for failed tasks to $output_dir..."
    while IFS= read -r basename_pattern; do
      # Find log files starting with this basename
      while IFS= read -r logfile; do
        cp -v "$logfile" "$output_dir/"
      done < <(find "$log_dir" -type f -name "${basename_pattern}*")
    done <"$temp_failures"

    echo "Done."
  else
    echo "No failures detected in $console_output"
  fi

  # Cleanup
  rm -f "$temp_failures"

  return 0
}

# build encoder without sanitizers for faster runtime
make clean
make -j IVAS_cod
mv IVAS_cod IVAS_cod_nosan

# run all modes and cut bitstream to start with an SID. Use mono output to limit runtime, test is only about decoding the first frame
modes_no_sba=$(scripts/runIvasCodec.py -l | grep dtx | grep -vE "stereo|FOA|HOA" )
modes_hoa=$(scripts/runIvasCodec.py -l | grep dtx | grep -E "HOA")
modes_foa=$(scripts/runIvasCodec.py -l | grep dtx | grep "FOA")
modes_stereo=$(scripts/runIvasCodec.py -l | grep dtx | grep "stereo")
# collect DTX modes to run
# stereo modes are run separately from the rest
# reason: the stv signal does not trigger DTX for the highest stereo bitrates. We use the ltv signal cut to a different length than the other signal
modes_no_stereo=$(scripts/runIvasCodec.py -l | grep dtx | grep -v stereo)
modes_stereo=$(scripts/runIvasCodec.py -l | grep dtx | grep stereo)

# config vars
testcase_timeout=20
bitstream_cut_length=5
common_args="-z console -p scripts/config/ci_linux_sidstart_test.json -s --oc mono --timeout $testcase_timeout --bs_length $bitstream_cut_length"
common_args="-z console -p scripts/config/ci_linux_sidstart_test.json -s --oc mono --bs_length $bitstream_cut_length"

# first encoder + MSAN decoder
# hack to use the encoder with no sanitizers
@@ -24,38 +75,54 @@ make IVAS_dec -j CLANG=1
cp IVAS_dec CLANG1/IVAS_dec
cp IVAS_cod_nosan CLANG1/IVAS_cod

exit_code_msan=0
exit_code_msan_no_stereo=0
exit_code_msan_stereo=0
echo "-------------- 1. Encoder + Msan decoder -------------- "
echo "-------------- 1.1 all DTX modes except SBA and stereo -------------- "
scripts/IvasBuildAndRunChecks.py --checks CLANG1 -m $modes_no_sba -U 0:20 $common_args || exit_code_msan=$?
echo "-------------- 1.2 HOA2 + HOA3 DTX modes -------------- "
scripts/IvasBuildAndRunChecks.py --checks CLANG1 -m $modes_hoa -U 70:80 $common_args || exit_code_msan=$?
echo "-------------- 1.3 FOA DTX modes -------------- "
scripts/IvasBuildAndRunChecks.py --checks CLANG1 -m $modes_foa -U 75:110 $common_args || exit_code_msan=$?
echo "-------------- 1.4 stereo DTX modes -------------- "
scripts/IvasBuildAndRunChecks.py --checks CLANG1 -m $modes_stereo -U 40:60 $common_args || exit_code_msan=$?
# archive encoder logs separately
mkdir logs_enc logs_dec_msan
mv CLANG1/logs/*.enc.txt logs_enc/
mv CLANG1/logs/*.dec*.txt logs_dec_msan/

# ASAN and USAN can be done in one go and decoder only
echo "-------------- 1.1 all DTX modes except stereo -------------- "
scripts/IvasBuildAndRunChecks.py --checks CLANG1 -m $modes_no_stereo -U 0:20 $common_args 2>&1 | tee "console_log_msan.txt" || exit_code_msan_no_stereo=$?
echo "-------------- 1.2 stereo DTX modes -------------- "
scripts/IvasBuildAndRunChecks.py --checks CLANG1 -m $modes_stereo -U 40:60 $common_args 2>&1 | tee -a "console_log_msan.txt" || exit_code_msan_stereo=$?

# sanity check: ensure that we have DTX frames in the cut bitstreams
# only need to do this once here as encoder is not run again after this
grep_exit_code=0
grep -r "Extracted 0 frames!" CLANG1/logs/ || grep_exit_code=$?
if [ $grep_exit_code -ne 1 ]; then
  echo "Some bitstreams did not contain any SID frame!"
  echo -e "Check the input signals and/or the VAD performance!\n"
  echo "$grep_result"
  exit 1
fi

# ASAN and USAN can be done decoder only
# copy encoder output from CLANG1 dir
mkdir CLANG2 CLANG3
cp -r CLANG1/enc CLANG2/enc
cp -r CLANG1/enc CLANG3/enc

exit_code_asan_usan=0
echo "-------------- 2. Asan + Usan decoder -------------- "
echo "-------------- 2.1 all DTX modes except SBA and stereo -------------- "
scripts/IvasBuildAndRunChecks.py --checks CLANG2 CLANG3 --decoder_only -m $modes_no_sba -U 0:20 $common_args || exit_code_asan_usan=$?
echo "-------------- 2.2 HOA2 + HOA3 DTX modes -------------- "
scripts/IvasBuildAndRunChecks.py --checks CLANG2 CLANG3 --decoder_only -m $modes_hoa -U 70:80 $common_args || exit_code_asan_usan=$?
echo "-------------- 2.3 FOA DTX modes -------------- "
scripts/IvasBuildAndRunChecks.py --checks CLANG2 CLANG3 --decoder_only -m $modes_foa -U 75:110 $common_args || exit_code_asan_usan=$?
echo "-------------- 2.4 stereo DTX modes -------------- "
scripts/IvasBuildAndRunChecks.py --checks CLANG2 CLANG3 --decoder_only -m $modes_stereo -U 40:60 $common_args || exit_code_asan_usan=$?
mv CLANG2/logs logs_dec_asan
mv CLANG3/logs logs_dec_usan

if [ $exit_code_msan -ne 0 ] || [ $exit_code_asan_usan -ne 0 ]; then echo "There was either a crash or a sanitizer error encountered when decoding a bitstream that starts with an SID. Check the artifacts for the logfiles."; exit 1; fi
# In the next runs, we can do all the dtx modes together - we only run the decoder, so no cutting of input files needed
# the script does no put the cut length into the bitstream name, so the decoder can find the existing bitstreams this way
modes_all=$(scripts/runIvasCodec.py -l | grep dtx)
exit_code_asan=0
echo "-------------- 2. Asan decoder -------------- "
scripts/IvasBuildAndRunChecks.py --checks CLANG2 --decoder_only -m $modes_all $common_args 2>&1 | tee "console_log_asan.txt" || exit_code_asan=$?

exit_code_usan=0
echo "-------------- 3. Usan decoder -------------- "
scripts/IvasBuildAndRunChecks.py --checks CLANG3 --decoder_only -m $modes_all $common_args 2>&1 | tee "console_log_usan.txt" || exit_code_usan=$?

echo "-------------- 4. Collect logs -------------- "

# everything went as expected, now collect logs
collect_failed_logs console_log_msan.txt CLANG1/logs logs/msan
collect_failed_logs console_log_asan.txt CLANG2/logs logs/asan
collect_failed_logs console_log_usan.txt CLANG3/logs logs/usan

echo "-------------- 5. Check for errors -------------- "
if [ $exit_code_msan_no_stereo -ne 0 ] || [ $exit_code_msan_stereo -ne 0 ] || [ $exit_code_asan -ne 0 ] || [ $exit_code_usan -ne 0 ]; then
  echo "There was either a crash or a sanitizer error encountered when decoding a bitstream that starts with an SID. Check the artifacts for the logfiles."
  exit 1
fi

echo "No errors occured."
exit 0
+18 −0
Original line number Diff line number Diff line
@@ -259,19 +259,37 @@ uint32_t ivas_syn_output(
    int16_t *synth_out                                          /* o  : integer 16 bits synthesis signal        */
);

#ifdef FIX_BASOP_2396_CONSTANT_STRIDE_IN_TC_BUFFER
void ivas_buffer_interleaved_to_deinterleaved(
    float *audio_in,                                            /* i  : interleaved audio buffer                                 */
    float *audio_out[],                                         /* o  : pointers to each channel of deinterleaved audio buffer   */
    const int16_t n_channels,                                   /* i  : number of channels                                       */
    const int16_t frame_length                                  /* i  : frame length (one channel)                               */
);
#else
void ivas_buffer_interleaved_to_deinterleaved(
    float *audio,                                               /* i/o: audio buffer                            */
    const int16_t n_channels,                                   /* i  : number of channels                      */
    const int16_t frame_length,                                 /* i  : frame length (one channel)              */
    const int16_t n_samp_full                                   /* i  : full frame length (one channel)         */
);
#endif

#ifdef FIX_BASOP_2396_CONSTANT_STRIDE_IN_TC_BUFFER
void ivas_buffer_deinterleaved_to_interleaved(
    float *audio_in[],                                          /* i  : pointers to each channel of deinterleaved audio buffer  */
    float *audio_out,                                           /* o  : interleaved audio buffer                                */
    const int16_t n_channels,                                   /* i  : number of channels                                      */
    const int16_t frame_length                                  /* i  : frame length (one channel)                              */
);
#else
void ivas_buffer_deinterleaved_to_interleaved(
    float *audio[],                                             /* i  : deinterleaved audio buffer              */
    const int16_t n_channels,                                   /* i  : number of channels                      */
    const int16_t frame_length,                                 /* i  : frame length (one channel)              */
    float *audio_out                                            /* o  : interleaved audio buffer                */
);
#endif

void ivas_initialize_handles_enc(
    Encoder_Struct *st_ivas                                     /* i/o: IVAS encoder structure                  */
+62 −1
Original line number Diff line number Diff line
@@ -155,6 +155,36 @@ uint32_t ivas_syn_output(
 * Convert an interleaved buffer of audio channels to deinterleaved one
 *-------------------------------------------------------------------*/

#ifdef FIX_BASOP_2396_CONSTANT_STRIDE_IN_TC_BUFFER
void ivas_buffer_interleaved_to_deinterleaved(
    float *audio_in,           /* i  : interleaved audio buffer                                 */
    float *audio_out[],        /* o  : pointers to each channel of deinterleaved audio buffer   */
    const int16_t n_channels,  /* i  : number of channels                                       */
    const int16_t frame_length /* i  : frame length (one channel)                               */
)
{
    int16_t ch, s;
    float buffer[MAX_TRANSPORT_CHANNELS][MAX_JBM_L_FRAME48k]; /* temp buffer needed when "*audio_in" and "*audio_out[]" point to the same memory */

    for ( ch = 0; ch < n_channels; ch++ )
    {
        for ( s = 0; s < frame_length; s++ )
        {
            buffer[ch][s] = audio_in[s * n_channels + ch];
        }
    }

    for ( ch = 0; ch < n_channels; ch++ )
    {
        for ( s = 0; s < frame_length; s++ )
        {
            audio_out[ch][s] = buffer[ch][s];
        }
    }

    return;
}
#else
void ivas_buffer_interleaved_to_deinterleaved(
    float *audio,               /* i/o: audio buffer                    */
    const int16_t n_channels,   /* i  : number of channels              */
@@ -182,7 +212,7 @@ void ivas_buffer_interleaved_to_deinterleaved(

    return;
}

#endif

/*-------------------------------------------------------------------*
 * ivas_buffer_deinterleaved_to_interleaved()
@@ -190,6 +220,36 @@ void ivas_buffer_interleaved_to_deinterleaved(
 * Convert a deinterleaved buffer of audio channels to interleaved one
 *-------------------------------------------------------------------*/

#ifdef FIX_BASOP_2396_CONSTANT_STRIDE_IN_TC_BUFFER
void ivas_buffer_deinterleaved_to_interleaved(
    float *audio_in[],         /* i  : pointers to each channel of deinterleaved audio buffer  */
    float *audio_out,          /* o  : interleaved audio buffer                                */
    const int16_t n_channels,  /* i  : number of channels                                      */
    const int16_t frame_length /* i  : frame length (one channel)                              */
)
{
    int16_t ch, s;
    float buffer[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; /* temp buffer needed when "*audio_in[]" and "*audio_out" point to the same memory */

    for ( ch = 0; ch < n_channels; ch++ )
    {
        for ( s = 0; s < frame_length; s++ )
        {
            buffer[ch][s] = audio_in[ch][s];
        }
    }

    for ( ch = 0; ch < n_channels; ch++ )
    {
        for ( s = 0; s < frame_length; s++ )
        {
            audio_out[s * n_channels + ch] = buffer[ch][s];
        }
    }

    return;
}
#else
void ivas_buffer_deinterleaved_to_interleaved(
    float *audio[],             /* i/o: deinterleaved audio buffer      */
    const int16_t n_channels,   /* i  : number of channels              */
@@ -215,6 +275,7 @@ void ivas_buffer_deinterleaved_to_interleaved(

    return;
}
#endif


/*-------------------------------------------------------------------*
+1 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@
#define FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION         /* Dolby: issue 1465: Fix constant in create_random_vector() to allow more reliable fixed point port */
#define FIX_BASOP_2317_UNINIT_VALUE_IN_STEREO_CNG       /* Eri: Basop issue 2317: Uninitialized value read in case of DTX and BW switching   */
#define FIX_1283_STEREO_DFT_COLLAPSE                    /* FhG: issue 1283: fix for critical issue with DFT stereo core coder */
#define FIX_BASOP_2396_CONSTANT_STRIDE_IN_TC_BUFFER     /* FhG/VA: basop issue 2396: keep TC channel pointers in one constant place during decoding and rendering */
/* ##################### End NON-BE switches ########################### */

/* ################## End MAINTENANCE switches ######################### */
+14 −0
Original line number Diff line number Diff line
@@ -73,8 +73,12 @@ void ivas_dec_feed_tc_to_renderer(
{
    float tmp_buf[MAX_JBM_L_FRAME48k];
    float *p_data_f[FOA_CHANNELS + MAX_NUM_OBJECTS];
#ifdef FIX_BASOP_2396_CONSTANT_STRIDE_IN_TC_BUFFER
    int16_t n, n_render_timeslots, n_ch_cldfb, ch;
#else
    int16_t n, n_render_timeslots, n_ch_cldfb;
    int16_t ch, offset, len_offset;
#endif
    DECODER_TC_BUFFER_HANDLE hTcBuffer;

    hTcBuffer = st_ivas->hTcBuffer;
@@ -92,6 +96,7 @@ void ivas_dec_feed_tc_to_renderer(
        n_ch_full_copy = min( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full );
        n_ch_res_copy = hTcBuffer->nchan_transport_rend - hTcBuffer->nchan_buffer_full;

#ifndef FIX_BASOP_2396_CONSTANT_STRIDE_IN_TC_BUFFER
        /* buffers are shared between 'hTcBuffer->tc[]' and 'p_output_f[]':
           in case of 'length(hTcBuffer->tc[]) < length(p_output_f[])', reset of TC buffer
           pointers is needed after ivas_buffer_interleaved_to_deinterleaved() */
@@ -107,6 +112,7 @@ void ivas_dec_feed_tc_to_renderer(
            }
        }

#endif
        for ( ch = 0; ch < n_ch_full_copy; ch++ )
        {
            mvr2r( hTcBuffer->tc[ch], tmp_buf, nSamplesForRendering );
@@ -676,7 +682,11 @@ ivas_error ivas_dec_render(

            break;
        case PCM_FLOAT32:
#ifdef FIX_BASOP_2396_CONSTANT_STRIDE_IN_TC_BUFFER
            ivas_buffer_deinterleaved_to_interleaved( p_output, (float *) data, nchan_out_syn_output, *nSamplesRendered );
#else
            ivas_buffer_deinterleaved_to_interleaved( p_output, nchan_out_syn_output, *nSamplesRendered, (float *) data );
#endif
            break;
        default:
            error = IVAS_ERR_UNKNOWN;
@@ -978,7 +988,11 @@ ivas_error ivas_jbm_dec_flush_renderer(
                ivas_syn_output( p_output, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, (int16_t *) data );
            break;
        case PCM_FLOAT32:
#ifdef FIX_BASOP_2396_CONSTANT_STRIDE_IN_TC_BUFFER
            ivas_buffer_deinterleaved_to_interleaved( p_output, (float *) data, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered );
#else
            ivas_buffer_deinterleaved_to_interleaved( p_output, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, (float *) data );
#endif
            break;
        default:
            error = IVAS_ERR_UNKNOWN;
Loading