Skip to content

Audio: FLAC decoded in the app and fed as PCM (stereo, up to 48 kHz) - #950

Merged
GLinnik21 merged 11 commits into
plxnative:mainfrom
paulorichards:flac-pcm
Oct 24, 2026
Merged

GLinnik21 merged 11 commits into
plxnative:mainfrom
paulorichards:flac-pcm

Conversation

@paulorichards

@paulorichards paulorichards commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #917. Part of #918.

libpf has no FLAC input (its Load vocabulary is AAC, AC3, AC3 PLUS, DTS, MP3, MPEG, OPUS, VORBIS, WMA and PCM), but it takes raw PCM through contents.pcmInfo. This decodes FLAC in the demuxer with the bundled FFmpeg and feeds it as PCM, so a stereo FLAC track direct-plays in Auto and in Force Direct Play instead of being converted by the server.

Change

  • ci/build-ffmpeg.sh enables the FLAC parser and decoder (LGPL). No encoder, no libswresample, no new library. THIRD-PARTY-NOTICES.md says so.
  • ff_pcm opens FFmpeg's FLAC decoder and turns its frames into interleaved little-endian PCM: up to 16 bits as S16LE, anything deeper (or unstated) as S32LE, left-justified as the decoder produces it. Both are bit-exact. The decoder refuses a stream whose own rate or channel count contradicts what the Load declared.
  • The Load for a FLAC track says PCM and carries pcmInfo (format, channelMode, layout, sampleRate, bitsPerSample), built from the PMS track facts (route::stream_pcm). Stream and CarriedAudio now carry samplingRate and bitDepth from PMS.
  • The PCM path's limits live in devcaps: PCM_MAX_CHANNELS = 2 (channelMode has nothing wider) and PCM_SAMPLE_RATES, the rates that play at their own speed (libpf's LUT_SampleRateType: 8, 12, 16, 22.05, 24, 32, 48 kHz, plus 44.1 kHz). pcm_track_fits checks a track against both.
  • The planner applies pcm_track_fits in Auto and in Force Direct Play. These are limits of our decoder and LG's PCM input, not of a hardware decoder that Forced may trust past its table, so a 5.1 or 96 kHz FLAC is refused under Forced with the codec named (as for TrueHD) instead of failing at the Load. The audio gates take the track's sampling rate alongside its channels.
  • The profile offers flac for direct play only when the device table was read (Caps::assumed() is unchanged), with audio.channels ≤ 2 and audio.samplingRate ≤ 48000, so PMS converts anything wider or faster. FLAC is never a transcode target.
  • AVFrame.nb_samples joins the shared offsets in ff.rs and is pinned in ci/ffabi-assert.c; ff_pcm is in the media layer.

Verification

  • On the committed tree (git status empty before and after): make check ok (104 steps — all ok, its hostsim pass 1872 passed; 0 failed; 64 ignored), make check-nodef ok, ARM make FLAVOR=stable RELEASE=1 ipk ok (check-packaged-elf.py PASS).
  • New tests: ff_pcm interleaving (packed and planar, 16 to 32 widening, 24-bit in S32 kept exact); pcm_format_of and with_pcm_info; devcaps flac_is_pcm_decoded_stereo_only_and_only_on_a_read_table and the_pcm_path_admits_only_the_rates_and_channels_it_plays_correctly; planner flac_is_gated_by_the_pcm_paths_own_limits_in_both_modes; transcoder flac_is_offered_for_direct_play_up_to_stereo_and_never_as_a_target. They were written alongside the code, so I haven't seen them red.

TV check (LG OLED55B8, webOS 4.4.3, RELEASE build of this branch, real PMS 1.43.4)

Test clips: 2 minutes of Tears of Steel (CC BY 3.0, Blender Foundation), the same 1080p H.264 video with the audio re-encoded from Blender's 24-bit / 48 kHz masters. Force Direct Play unless noted.

Clip Result Sound Process CPU demux thread
FLAC 24/48 stereo DIRECT PLAY, PCM 48 kHz S32 right 24.0 % 4.4 %
FLAC 16/44.1 stereo DIRECT PLAY, PCM 44.1 kHz S16 right 23.9 % 4.3 %
FLAC 24/48 mono DIRECT PLAY, PCM 48 kHz mono right 23.1 % 3.7 %
DTS 5.1 (reference) DIRECT PLAY, DTS core right 27.6 % 2.8 %
FLAC 24/96 stereo refused, FLAC named
FLAC 24/192 stereo refused, FLAC named
FLAC 24/48 5.1 refused, FLAC named; in Auto the server converts it and it plays right

CPU is per thread from /proc over 90 s, % of one core. Every PCM feed was accepted (reply=O). Three seeks on the 48 kHz clip (forward, back, near the end) returned rv=0 in 137 to 301 ms, with audio back and in sync.

The 96 and 192 kHz rows are what made me add the rate limit. Before it, both were declared in pcmInfo and played audibly slow (192 kHz slower), with no error anywhere. smp_cb reports 44.099998 for every PCM Load, including 48 kHz ones that play right, so it doesn't show the rate in use.

Not verified:

🤖 Generated with Claude Code

https://claude.ai/code/session_01BNxR112kqmb5uZjUzXgND1

paulorichards and others added 11 commits October 22, 2026 17:10
libpf has no FLAC input, but takes raw PCM through contents.pcmInfo. A
FLAC track of up to two channels is decoded with the bundled FFmpeg's
flac decoder and fed as S16LE/S32LE at the rate PMS reports; the Load
refuses when the facts are missing or the file contradicts them.
devcaps admits flac only on a read table, capped at 2 channels, so PMS
still converts a 5.1 FLAC. Verified on an OLED55B8 (webOS 4.4.3): a
24-bit/48 kHz FLAC direct-plays, PMS reports no transcode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BNxR112kqmb5uZjUzXgND1
Signed-off-by: Paulo Richards <[email protected]>
- ff_pcm reads AVFrame through ff.rs's offsets; nb_samples joins them and
  ci/ffabi-assert.c pins it on both pointer widths.
- pcm_info_tests no longer splits sink_envelope_tests from its doc comment.
- devcaps says what was verified (webOS 4.4.3) instead of every set.
- ci/list-caps.ini classifies PCM_MAX_CHANNELS as a format limit.
- THIRD-PARTY-NOTICES: the bundled FFmpeg now enables the FLAC decoder.

Signed-off-by: Paulo Richards <[email protected]>
Measured on an OLED55B8 (webOS 4.4.3) with test clips:

- A 96 kHz or 192 kHz FLAC, declared as such in pcmInfo, played audibly
  slow (192 kHz slower still) with no error from the pipeline; 44.1 and
  48 kHz played right. libpf's LUT_SampleRateType lists 8/12/16/22.05/
  24/32/48 kHz. devcaps::PCM_SAMPLE_RATES holds that set plus 44.1 kHz;
  the profile caps FLAC at audio.samplingRate=48000 so PMS converts
  above it.
- Under Force Direct Play a 5.1 FLAC direct-played and the Load was then
  refused. The PCM path's limits (two channels, the rate set) are the
  app decoder's and LG's PCM input's, not a hardware decoder's, so the
  planner applies them in both modes (devcaps::pcm_track_fits) and a
  forced start refuses with the codec named, as for TrueHD.

The audio gates take the track's sampling rate alongside its channels.

Signed-off-by: Paulo Richards <[email protected]>
…ose the decoder made false

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Drop the duplicate avcodec send/receive entries, the duplicate nb_samples
offset and its ffabi-assert lines (the speed decoder's OFF_AFRAME_NB_SAMPLES
serves both). At a speed other than 1x the speed decoder takes FLAC too: the
FLAC PcmDecoder is not opened and the Load carries only the speed decoder's
pcmInfo. Reword the decoder comments and docs that this made false.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit e87ca65 into plxnative:main Oct 24, 2026
13 checks passed
@GLinnik21

Copy link
Copy Markdown
Collaborator

Thanks for the FLAC work, @paulorichards, and for the patience while it was brought up to date with main. Merged. Changes made on the way in: FLAC at a speed other than 1x now goes through the playback-speed decoder instead of opening a second one, the Load payload carries exactly one pcmInfo node, and the EAGAIN constant follows the host libc so the macOS simulator works. One open item: the FLAC sampleRate is in Hz while the speed path uses kHz, and neither has been confirmed on webOS 4.5.0. If you can play a 48 kHz FLAC on a 4.5 set and it runs slow, please say so.

Dr-Amp pushed a commit to Dr-Amp/plx-native that referenced this pull request Oct 24, 2026
Brings upstream main (e87ca65: FLAC decoded in the app and fed as PCM, plxnative#950) into
the Opus branch. Conflicts, each resolved by keeping both sides:

- Load audio code: upstream's FLAC PCM already takes 5, so Opus moves to 6
  (audio_payload_codec, load_a_str, and the Opus Load test).
- devcaps: forced_feeds_audio admits pipeline-only Opus and app-decoded FLAC on a
  read table. The audio list is DP_AUDIO_CODECS's subset, then Opus, then flac.
  OPUS_AUTO_MAX_CHANNELS and PCM_MAX_CHANNELS are both classified in ci/list-caps.ini.
- engine: the opusInfo helpers and upstream's pcmInfo helpers are both kept.

Signed-off-by: Dr-Amp <[email protected]>
Dr-Amp pushed a commit to Dr-Amp/plx-native that referenced this pull request Oct 24, 2026
Brings upstream main (e87ca65: FLAC decoded in the app and fed as PCM, plxnative#950) into
the Live TV branch. The Opus-side conflicts are the ones the Opus branch resolved
(its merge commit 9011407): Opus load code 6, FLAC PCM code 5, both list-caps
entries, both devcaps gates, both engine helper sets. The Live TV side only adds
the live-channel seek refusal in player/mod.rs.

Replay recordings are not re-recorded for the screen pin. That still needs the
macOS simulator, so the replay gate is not green on this branch.

Signed-off-by: Dr-Amp <[email protected]>
GLinnik21 added a commit that referenced this pull request Oct 24, 2026
Brings in the Browse B-A section-hubs job and the other changes main gained
since fba7a81 (#1017, #1021, #950). Five files conflicted and every one
keeps both sides: the Direct arm of StoreJob::admission() lists BrowseHubs,
MetaSeason and MetaEpisodes; the runner and the Held docs name both the
Browse and the Metadata kinds; bridge.rs's late-job messages name every
drain of both stores; docs/sans-io.md numbers Metadata as the tenth store;
PINNED_LEDGER_TOTALS is the real sum of the # count: headers (the textual
merge produced a wrong-looking pair).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@paulorichards paulorichards mentioned this pull request Oct 25, 2026
5 tasks done
GLinnik21 pushed a commit that referenced this pull request Oct 25, 2026
The FLAC path (#950) declared `pcmInfo.sampleRate` in Hz (`48000`). libpf matches that field against a kilohertz table (`48`, `44.1`, `32`, ...) and falls back to 44.1 for a value it cannot match, so every FLAC that was not 44.1 kHz played at the wrong pitch: on a B8 a 1 kHz tone in a 48 kHz file came back at 918.8 Hz. `with_pcm_info` now declares the rate in kHz, as the speed path already did, and the measured tone comes back at 999.96-999.99 Hz at 48, 44.1, 32 and 22.05 kHz.

- `pcm_rate_khz` converts the rate (`48000` -> `48`, `44100` -> `44.1`, `22050` -> `22.05`).
- New test `the_sample_rate_is_declared_in_kilohertz` covers every rate in `PCM_SAMPLE_RATES`; the two payload tests now expect `48` and `44.1`.
- `PCM_SAMPLE_RATES` keeps its 48 kHz ceiling: a test build declaring 88.2-192 kHz in kHz still played at 44.1, because libpf's table stops at 48.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tiper added a commit to tiper/fin-native that referenced this pull request Oct 26, 2026
…f alone

Upstream's plxnative#992 and plxnative#1034 now feed stereo Opus to the television's own decoder, with the
per-firmware exclusions and the learned refusals, and plxnative#950 feeds FLAC as PCM. That replaces
FinNative's own native FLAC, Opus and Vorbis feed, which this commit used to carry: on the C1
its native FLAC was stereo only, where the PCM route already plays it, and Vorbis was refused at
every channel count.

What remains is the one rule the conversion needs beside them: with Convert audio on the TV, a
track the TV's table decodes at its channel count is fed as it is, not converted to AC3.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.

FLAC: decode to PCM in the app, up to stereo

2 participants