Skip to content

audio: ffmpeg_dec: add aptX HD, ITU-T G.726, and ITU-T G.711 codecs - #11462

Draft
lgirdwood wants to merge 2 commits into
thesofproject:mainfrom
lgirdwood:topic/ffmpeg-tier1
Draft

lgirdwood wants to merge 2 commits into
thesofproject:mainfrom
lgirdwood:topic/ffmpeg-tier1

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Extends ffmpeg_dec and ffmpeg_enc with three pure-integer, streaming audio codecs alongside IPC capability advertisement and a 6:1 mono decimator:

  • Bluetooth aptX HD (CONFIG_FFMPEG_DEC_APTX_HD, CONFIG_FFMPEG_ENC_APTX_HD, SND_AUDIOCODEC_APTX_HD = 0x15):
    • Parameterized ffmpeg_dec-aptx.c and ffmpeg-enc-aptx.c to share core logic between aptX and aptX HD (AV_SAMPLE_FMT_S32P stereo, 6-byte block alignment clamped at 1020 bytes per unparsed packet).
  • ITU-T G.726 / G.726LE ADPCM (CONFIG_FFMPEG_DEC_G726, CONFIG_FFMPEG_ENC_G726, SND_AUDIOCODEC_G726 = 0x16):
    • Supports big-endian (profile=0, adpcm_g726) and little-endian (profile=1, adpcm_g726le), 2/3/4/5 bits per sample (default 4), byte/block-aligned unparsed framing (1/3/5 bytes), FF_COMPLIANCE_UNOFFICIAL for 8/16/48 kHz streams, and 160-sample encode framing.
  • ITU-T G.711 A-law & mu-law (CONFIG_FFMPEG_DEC_ALAW/MULAW, CONFIG_FFMPEG_ENC_ALAW/MULAW, SND_AUDIOCODEC_ALAW = 0x17, SND_AUDIOCODEC_MULAW = 0x18):
    • Shared decode and encode paths in ffmpeg_dec-g711.c and ffmpeg-enc-g711.c covering mono and stereo streams at 8/16/48 kHz.
  • 6:1 Mono Decimator & Capability Flags:
    • Extracted decim_3to1_step() and added ffmpeg_dec_pcm_decimate_6to1_s16_mono() (48 kHz -> 8 kHz) in ffmpeg_dec-convert.c.
    • Replaced hardcoded G.722/SBC rate and channel checks in ffmpeg-encode.c with supports_mono_downmix, supports_decim_3to1, and supports_decim_6to1 on struct ffmpeg_enc_codec_ops.

Commits

  • 9b1a1f67a ipc: compress: add aptX HD, ITU-T G.726, and ITU-T G.711 codec IDs
  • a710769cd ffmpeg_dec: add aptX HD, G.726/G.726LE, and G.711 A-law/mu-law codecs

Testing

  • Checkpatch (post-rebase): zephyr/scripts/checkpatch.pl --no-tree -g origin/main..HEAD --ignore C99_COMMENTS (with Zephyr .checkpatch.conf) — 0 errors, 0 warnings for both 9b1a1f67a510 and a710769cd2c9.
  • Builds (post-rebase):
    • PTL stub (intel_adsp/ace30/ptl, CONFIG_COMP_FFMPEG_DEC_STUB=y): passed.
    • TGL (intel_adsp/cavs25) and PTL (intel_adsp/ace30/ptl) with all Tier 1 codecs enabled + west sign: passed.
  • Hardware (Spider / TGL):
    • Post-rebase verification (FAIL=0 across 5 capture + playback pairs):
      • aptx_hd_48k_2c (id=21, 48000 Hz 2 ch): capture decoded with ffmpeg/ffprobe (pcm_s16le,48000,2) and playback verified.
      • g726_8k_32k (id=22, 8000 Hz 1 ch prof=0) and g726le_8k_24k (id=22, 8000 Hz 1 ch prof=1): capture decoded (pcm_s16le,8000,1) and playback verified.
      • alaw_8k_1c (id=23, 8000 Hz 1 ch) and mulaw_8k_1c (id=24, 8000 Hz 1 ch): capture decoded (pcm_s16le,8000,1) and playback verified.
    • Pre-rebase full matrix (505ec0c1e, identical codec code): 13 capture + playback configurations (FAIL=0), additionally covering G.726 at 16/40 kbps (8k), 64k (16k, 3:1 decimator), and 192k (48k), plus A-law/mu-law at 16k mono and 48k stereo.

Define SND_AUDIOCODEC_APTX_HD (0x15), SND_AUDIOCODEC_G726 (0x16),
SND_AUDIOCODEC_ALAW (0x17), and SND_AUDIOCODEC_MULAW (0x18) in
compress_params.h and advance SND_AUDIOCODEC_MAX.

Advertise playback/capture support for the new codecs in base_fw.c
get_codec_info() with bounds-checked helper add_codec_info_item(), and
extend the BESPOKE capability guards to cover them.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Extend ffmpeg_dec and ffmpeg_enc with three pure-integer audio codecs:
- Bluetooth aptX HD (24-bit S32P, 6-byte block-aligned decode and encode)
- ITU-T G.726 ADPCM (big-endian profile=0 and little-endian profile=1,
  2/3/4/5 bits/sample at 8/16/48 kHz with FF_COMPLIANCE_UNOFFICIAL)
- ITU-T G.711 A-law and mu-law companded PCM (mono/stereo at 8/16/48 kHz)

Also extract decim_3to1_step(), add an anti-aliased 6:1 (48->8 kHz) mono
decimator in ffmpeg_dec-convert.c, and replace hardcoded G.722/SBC rate
and channel conversion checks in ffmpeg-encode.c with per-codec
supports_mono_downmix, supports_decim_3to1, and supports_decim_6to1 flags.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

G.726 encoding and decoding accept unsupported multichannel requests as mono, while the 16→8 kHz decimation filter provides insufficient stopband rejection and introduces audible-band aliasing.

3 open issues
What changed in this PR

Extends SOF’s FFmpeg-based compressed playback and capture with aptX HD, G.726/G.726LE, and G.711, building on the lossless codec support in #11427.

Changes:

  • Adds codec implementations, format selection, and packet framing.
  • Adds 48→8 kHz mono decimation and encoder conversion capability flags.
  • Integrates the codecs into configuration, builds, and IPC capability reporting.
File Description
src/​kernel/​audio/​base_fw.c Advertises new codec capabilities using bounded insertion.
src/​include/​ipc/​compress_params.h Defines new compressed-audio codec IDs.
src/​audio/​ffmpeg_dec/​llext/​CMakeLists.txt Includes new codecs in loadable-module builds.
src/​audio/​ffmpeg_dec/​Kconfig Adds decoder and encoder selection options.
src/​audio/​ffmpeg_dec/​ffmpeg.cmake Enables selected codecs in libavcodec.
src/​audio/​ffmpeg_dec/​ffmpeg-encode.c Registers encoders and uses conversion capability flags.
src/​audio/​ffmpeg_dec/​ffmpeg-enc-sbc.c Declares SBC conversion capabilities.
src/​audio/​ffmpeg_dec/​ffmpeg-enc-g726.c Implements G.726/G.726LE encoding.
src/​audio/​ffmpeg_dec/​ffmpeg-enc-g722.c Declares G.722 conversion capabilities.
src/​audio/​ffmpeg_dec/​ffmpeg-enc-g711.c Implements shared A-law and mu-law encoding.
src/​audio/​ffmpeg_dec/​ffmpeg-enc-aptx.c Shares encoder logic with aptX HD.
src/​audio/​ffmpeg_dec/​ffmpeg_dec.h Adds codec definitions, request fields, and conversion state.
src/​audio/​ffmpeg_dec/​ffmpeg_dec.c Registers decoders and stores IPC stream parameters.
src/​audio/​ffmpeg_dec/​ffmpeg_dec-g726.c Configures G.726 decoding and aligned packet limits.
src/​audio/​ffmpeg_dec/​ffmpeg_dec-g711.c Configures G.711 decoding and channel-aligned packets.
src/​audio/​ffmpeg_dec/​ffmpeg_dec-ffmpeg.c Maps new codecs and G.726 profiles to libavcodec.
src/​audio/​ffmpeg_dec/​ffmpeg_dec-convert.h Declares the 6:1 mono decimator.
src/​audio/​ffmpeg_dec/​ffmpeg_dec-convert.c Extracts the 3:1 filter step and adds 6:1 decimation.
src/​audio/​ffmpeg_dec/​ffmpeg_dec-aptx.c Adds aptX HD selection and six-byte block alignment.
src/​audio/​ffmpeg_dec/​CMakeLists.txt Includes new codecs in built-in builds.

Review effort: Balanced

g726->enc_rate = enc_rate;
g726->avctx->strict_std_compliance = FF_COMPLIANCE_UNOFFICIAL;
g726->avctx->sample_rate = enc_rate;
av_channel_layout_default(&g726->avctx->ch_layout, 1);
Comment on lines +515 to +517
int32_t acc = (int32_t)hist[12] + 2 * (int32_t)y0 + (int32_t)y1 + 2;

dst[i] = sat_int16(acc >> 2);
}

avctx->sample_rate = rate;
av_channel_layout_default(&avctx->ch_layout, 1);
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