Skip to content

test-case: add FFmpeg compressed audio decode, encode, and roundtrip tests - #1364

Draft
lgirdwood wants to merge 4 commits into
thesofproject:mainfrom
lgirdwood:topic/ffmpeg-compr-tests
Draft

lgirdwood wants to merge 4 commits into
thesofproject:mainfrom
lgirdwood:topic/ffmpeg-compr-tests

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Summary

Add cplay / crecord and ALSA compress ioctl (tools/sof-compr-tool.py) test cases for upstream FFmpeg compressed audio decoders and encoders (ffmpeg_dec / ffmpeg_enc):

  • tools/sof-tplgreader.py, case-lib/pipeline.sh, test-case/verify-pcm-list.sh:
    • Expose compress pipeline metadata and map compress:1 nodes to /dev/snd/comprC*D*.
    • Block compress:1 pipelines by default in regular PCM test filters and exclude them from /proc/asound/pcm comparison in verify-pcm-list.sh.
  • tools/sof-compr-tool.py:
    • Self-contained ALSA compress ioctl utility (play, record, caps) supporting pause/resume stress, SND_AUDIOCODEC_BESPOKE framing, and GET_CAPS across flac, mp3, aac, opus, alac, sbc, msbc, g722, and aptx.
  • case-lib/compress.sh:
    • Shared codec defaults/capabilities, ffmpeg vector generation, encoded header/container validation (including raw 36-byte QuickTime 'alac' atom captures), and cplay/crecord mode routing.
  • test-case/check-compr-decode.sh, check-compr-encode.sh, check-compr-roundtrip.sh:
    • Decode, encode, and concurrent roundtrip tests with -m cplay|crecord|compr-tool|auto|all and optional -P pause/resume cycles.

Validation Status (Ladybird / WCL-U)

Tested on Ladybird (WCL-U, sof-wcl-rt722-ffmpeg.tplg, FW 2.15.99.1 built with CONFIG_COMP_FFMPEG_DEC=y / CONFIG_SOF_ZEPHYR_HEAP_SIZE=0x84000 / Core 0 test topology):

  • Encode (check-compr-encode.sh -m all -d 2): PASS across all 9 runs (mp3, aac, flac via crecord & sof-compr-tool.py, alac, sbc, msbc, g722, aptx), 0 mtrace errors.
  • Decode (check-compr-decode.sh -C opus,alac -m compr-tool -P 1 -d 2): PASS (0 mtrace errors).
  • Decode (cplay / compr-tool) remaining FW items:
    • flac, mp3, aac, sbc, msbc play through EOS: compress drain complete cleanly in both cplay and sof-compr-tool.py, but DSP FW currently logs EOS flush <err> lines (avcodec_send_packet / avcodec_receive_frame) that trigger mtrace check failure.
    • g722 decode currently hangs in SNDRV_COMPRESS_DRAIN in FW (ffmpeg_dec_is_ready_to_process() does not re-enter when pcm_avail == 0 && avail == 0 at EOS).
    • aptx decode currently fails on packet test-case: add verify-ucm-config.sh #1 in FW (unparsed packet reassembly buffer full or invalid block / -5).
  • Roundtrip (check-compr-roundtrip.sh -d 2): blocked by non-modular builtin FW memory OOM (-ENOMEM) during concurrent compress playback + capture (requires modular =m LLEXT z_errno_wrap shim fix in SOF FW).
  • PCM regression (check-playback.sh -d 1 -l 1 -S id:0): PASS.

Marked Draft while tracking the corresponding SOF firmware fixes before CI promotion.

Signed-off-by: Liam Girdwood liam.r.girdwood@linux.intel.com

…pers

Add compress pipeline tracking across sof-tplgreader.py, case-lib/pipeline.sh,
and test-case/verify-pcm-list.sh:
- Expose pipeline['compress'] and map compress:1 nodes to /dev/snd/comprC*D*.
- Exclude compress:1 streams from default PCM pipeline blocks and from
  /proc/asound/pcm matching in verify-pcm-list.sh.
- Preserve the compress field when deduplicating or sorting pipelines.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add compressed audio testing infrastructure and test cases for upstream
FFmpeg decoders/encoders (ffmpeg_dec / ffmpeg_enc):
- tools/sof-compr-tool.py: Python ALSA compress ioctl helper supporting
  playback, capture, pause/resume, SND_AUDIOCODEC_BESPOKE framing, and
  GET_CAPS queries across flac, mp3, aac, opus, alac, sbc, msbc, g722,
  and aptx.
- case-lib/compress.sh: shared codec capability/default mapping, ffmpeg
  test vector generation, header/container verification, and cplay/crecord
  mode selection.
- test-case/check-compr-decode.sh: compressed decode test across cplay and
  sof-compr-tool.py with optional pause/resume stress.
- test-case/check-compr-encode.sh: compressed capture test across crecord
  and sof-compr-tool.py with header and host decode verification.
- test-case/check-compr-roundtrip.sh: concurrent compress playback and
  capture validation.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The Python playback drain has no deadline, so a hang can stall the default decode run indefinitely instead of reporting failure and collecting logs.

7 open issues
What changed in this PR

Adds compressed-audio testing for SOF’s FFmpeg decoders and encoders, while keeping compressed devices separate from regular PCM tests. The PR remains draft pending the firmware fixes described in its validation notes.

Changes:

  • Expose compressed pipeline metadata and exclude compressed devices from regular PCM checks.
  • Add a direct ALSA compress ioctl utility and shared codec generation, routing, and validation helpers.
  • Add decode, encode, and concurrent playback/capture tests, with optional decode pause/resume and loopback checks.
File Description
tools/​sof-tplgreader.py Exposes compress metadata, maps device nodes, and updates filtering.
tools/​sof-compr-tool.py Adds capability queries, compressed playback, and capture through ioctls.
test-case/​verify-pcm-list.sh Excludes compressed devices from PCM-list comparisons.
test-case/​check-compr-roundtrip.sh Tests concurrent compressed playback and capture.
test-case/​check-compr-encode.sh Tests encoding, stream validation, and optional loopback tone checks.
test-case/​check-compr-decode.sh Tests decoding, pause/resume, and optional loopback capture.
case-lib/​pipeline.sh Preserves compress metadata during pipeline copying and sorting.
case-lib/​compress.sh Provides shared codec defaults, vectors, validation, and backend routing.

Review effort: Balanced

Comment thread tools/sof-compr-tool.py Outdated
fcntl.ioctl(fd, SNDRV_COMPRESS_RESUME)
paused_done += 1

fcntl.ioctl(fd, SNDRV_COMPRESS_DRAIN)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9283c3e: sof-compr-tool.py play now bounds SNDRV_COMPRESS_DRAIN with --drain-timeout-ms (default 15000 ms) via SIGALRM + ITIMER_REAL, triggering SNDRV_COMPRESS_STOP on timeout, and func_compr_run_play also wraps Python playback in an outer timeout -k 5 watchdog. Verified against the G.722 hang on Ladybird (~2.47s clean failure).

Comment thread case-lib/compress.sh Outdated
Comment on lines +82 to +83
python3 "$COMPR_TOOL" caps -D "$snd_dev" --direction "$direction" \
--has-codec "$codec" >/dev/null 2>&1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9283c3e: func_compr_dev_supports_codec now captures tool output and returns 1 only when sof-compr-tool.py caps exits 2 (unsupported codec); any other non-zero exit logs diagnostics and returns 2 so check-compr-decode.sh, check-compr-encode.sh, and check-compr-roundtrip.sh fail instead of silently skipping.

Comment thread case-lib/compress.sh Outdated
Comment on lines +312 to +314
if [ "${alac_mode%% *}" != "caf" ]; then
dlogi "Verified alac magic cookie + raw frames ($fsize B, ${alac_mode#raw })"
return 0

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9283c3e: func_compr_verify_encoded_file now returns 2 for raw header-only ALAC verification (and removes any stale target WAV), allowing check-compr-encode.sh to fail explicitly if -L tone verification was requested and check-compr-roundtrip.sh to treat rc=2 as valid header-only capture without requesting a WAV.

Comment thread case-lib/compress.sh
local rate ch bitrate fmt cplay_codec _
read -r rate ch bitrate fmt cplay_codec _ <<< "$defaults"

if [ "$tool_mode" = "cplay" ] || { [ "$tool_mode" = "auto" ] && [ "$pause_cycles" -eq 0 ] && func_compr_cplay_supports "$codec"; }; then

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9283c3e: check-compr-decode.sh and func_compr_run_play now reject cplay mode when --pause_resume > 0, and -m all -P >0 skips cplay cleanly while still exercising compr-tool.

Comment thread case-lib/compress.sh Outdated
return 1
}
dlogc "timeout -s INT 30 cplay -c $COMPR_CARD -d $COMPR_DEV -I $cplay_codec $in_file"
timeout -s INT 30 cplay -c "$COMPR_CARD" -d "$COMPR_DEV" -I "$cplay_codec" "$in_file"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9283c3e: func_compr_run_play now takes duration and computes the timeout -k 5 watchdog as duration + 30 + pause_cycles * 2 seconds for both cplay and sof-compr-tool.py (callers in check-compr-decode.sh and check-compr-roundtrip.sh pass $duration).

Comment thread case-lib/compress.sh Outdated
Comment on lines +475 to +476
"${rec_cmd[@]}" > "$out_file"
local rc=$?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9283c3e: func_compr_run_record now captures crecord exit status via "${rec_cmd[@]}" > "$out_file" || rc=$? so normal timeout status 124/130 is normalized cleanly even under set -e background invocations.

Comment thread test-case/check-compr-decode.sh Outdated
Comment on lines +129 to +133
vec_file="${work_dir}/dec_${codec}_${rate}hz_${ch}ch.${codec}"
if [ "$codec" = "alac" ]; then
vec_file="${work_dir}/dec_alac_${rate}hz_${ch}ch.m4a"
elif [ "$codec" = "msbc" ]; then
vec_file="${work_dir}/dec_msbc_${rate}hz_${ch}ch.sbc"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9283c3e: check-compr-decode.sh (and check-compr-roundtrip.sh) now include ${duration}s in cached codec vector filenames.

- tools/sof-compr-tool.py: bound blocking SNDRV_COMPRESS_DRAIN with SIGALRM
  (--drain-timeout-ms), add StreamConfig dataclass and per-codec default
  bitrates, and satisfy pylint rules cleanly.
- tools/sof-tplgreader.py: wrap CLI entrypoint in main(), extract helpers,
  use sys.exit, and satisfy pylint rules cleanly.
- case-lib/compress.sh: export codec list globals (SC2034), distinguish
  device/ioctl errors (rc != 2) from unsupported codecs in GET_CAPS checks,
  return rc=2 for raw ALAC header-only validation when no WAV is produced,
  reject cplay mode when pause_cycles > 0, derive playback watchdog from
  duration, and normalize timeout status safely under set -e.
- test-case/check-compr-{decode,encode,roundtrip}.sh: include duration in
  cached vector names, handle GET_CAPS errors and raw ALAC tone checks
  explicitly, skip/reject cplay with -P > 0, and avoid SC2015 warnings.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…eader

- tools/sof-compr-tool.py: split BufferConfig out of StreamConfig to keep
  instance attributes within pylint limits (R0902).
- tools/sof-tplgreader.py: extract _build_arg_parser and
  _print_pipeline_output helpers from main() to reduce branches (R0912).

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants