linux-sound.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
To: "Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>,
	"Vinod Koul" <vkoul@kernel.org>
Cc: Mark Brown <broonie@kernel.org>,
	perex@perex.cz, tiwai@suse.com, lgirdwood@gmail.com,
	srinivas.kandagatla@oss.qualcomm.com,
	linux-sound@vger.kernel.org, kai.vehmanen@linux.intel.com,
	yung-chuan.liao@linux.intel.com, daniel.baluta@nxp.com,
	Vijendar.Mukunda@amd.com
Subject: Re: [PATCH 04/23] ASoC: soc-compress: Implement trigger FE-BE sequencing as with normal PCMs
Date: Wed, 9 Sep 2026 22:22:10 +0200	[thread overview]
Message-ID: <e0ca888d-6607-47b4-a470-564c34cfa0cd@linux.dev> (raw)
In-Reply-To: <9b2eea34-a04d-4124-8f76-ebfde6df67fc@linux.intel.com>


>>> I see, the issue is that I cannot find any way to give the metadata to
>>> the decoder module, it is a black box to us.
>>
>> The metadata is typically handled *outside* of the decoder library by a
>> memcpy-based wrapper or modulo pointers.
>>
>> For example due to the filterbank, the decoder will generate N zero
>> samples in the first frame. If you know the value of N thanks to the
>> METADATA ioctl, you can discard the first N samples in the wrapper.
>>
>> Likewise at the end of the track the wrapper can skip the last M samples
>> which were padded to make the initial soundtrack a multiple of the frame
>> size (e.g. 1152 for MP3). the value M is the encoder padding.
> 
> I got this part, but I have no idea how the wrapper could know this.
> It can be only _after_ the decoder to do the fade out/in/mixing, but so
> far I have not seen any way to actually pin-point the exact time.
> And not just exact time, but T minus something to T plus something.

It's not time you need to track but bytes, and the accuracy of the
next-track position is exactly a byte. If you're off by even one byte,
you probably lost a minimum of one frame until the decoder re-syncs for
an elementary stream, and the whole scheme is down the drain if there's
a header.

Also the decoder has to in a wrapper anyways, even without gapless
playback: the fragments used by the compressed framework may contain
more or less than a frame, so the decoder needs to deal with all cases
of 'no enough data available' and 'more than one frame provided'.
Likewise some decoder may not be able to generate data on initial calls,
and need to be called without new input to full internal PCM buffers.

then the logic should be:

(a) On a new track, for the first decoder you skip the first N samples.

(b) The end of track happens when all the bytes have been provided to
the decoder, and the decoder cannot generate more data. At that point
you would discard the last M padding samples.

(c) if there was a NEXT_TRACK, eset the byte counting for the track and
go back to (a)

That's the high level logic. Now for the positioning, I may be wrong but
I think there is a requirement that the NEXT_TRACK is only signaled when
all the bytes for the current track were provided to the driver. So on
the NEXT_TRACK you would need to record the number of bytes provided so
far by userspace, and forward that information to firmware. Then the
next write would be with the content for the next track. It could also
be the PARTIAL_DRAIN that does this, since at that point no new data
should be provided by userspace. Either way, do no write data in the
ring buffer until the firmware knows the total number of bytes in the
current track. If the app doesn't respect that then the accounting will
go sideways.

The last time I saw DSP code for this was in 2013 or so, take this with
a grain of salt. Vinod, if you have a better memory please do chime in...

>>> Also I'm not sure how the fw could get any idea where one
>>> flac/vorbis/aac/mp3 ends and where it starts, the black box does not
>>> seam to be able to detect this or if it does, it will not emit this
>>> information to outside.
>> I must admit I don't fully remember the details on the start/end
>> position. IIRC this isn't strictly required for elementary streams such
>> as MP3 or AAC ADTS, you could cat the streams together and that'd be
>> just fine. you would have a slightly different transition by blending
>> the two streams in a common filterbank history buffer but that'd be
>> nearly impossible to detect...
> 
> and there is still the monitoring of the progress of let's say 6th track
> in the stream.
> 
> I was planning to revisit this sooner than later when I have a moment of
> 'free' time, but for this initial series, it is not promised and should
> not work at all.
> 
>> But for streams with a header such as WMA not sure how this might work,
>> I think you do need to know the buffer position, reset the decoder and
>> restart from that position.
> 
> Luckily no one has such files anymore ;)

Hehe, the Zune music service only stopped in 2017...

  reply	other threads:[~2026-09-09 20:22 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04  7:31 [PATCH 00/23] ALSA compress / ASoC compress / SOF: Compressed audio support with IPC4 Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 01/23] ALSA: compress: pin card module while stream is open Peter Ujfalusi
2026-09-04  7:50   ` Takashi Iwai
2026-09-04  8:03     ` Péter Ujfalusi
2026-09-04  7:31 ` [PATCH 02/23] ALSA: compress: stop active streams on disconnect Peter Ujfalusi
2026-09-04  7:51   ` Takashi Iwai
2026-09-04  7:31 ` [PATCH 03/23] ASoC: soc-compress: Provide a runtime for the compressed FE substream Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 04/23] ASoC: soc-compress: Implement trigger FE-BE sequencing as with normal PCMs Peter Ujfalusi
2026-09-04 19:45   ` Mark Brown
2026-09-07  5:25     ` Péter Ujfalusi
2026-09-07 11:26       ` Pierre-Louis Bossart
2026-09-07 14:03         ` Péter Ujfalusi
2026-09-07 16:53           ` Vinod Koul
2026-09-07 19:55             ` Pierre-Louis Bossart
2026-09-08  6:37               ` Péter Ujfalusi
2026-09-08  6:58                 ` Vinod Koul
2026-09-08  8:41                   ` Péter Ujfalusi
2026-09-08 12:06                     ` Pierre-Louis Bossart
2026-09-08 14:04                       ` Péter Ujfalusi
2026-09-08 12:37                     ` Vinod Koul
2026-09-08 14:13                       ` Péter Ujfalusi
2026-09-08 14:54                         ` Pierre-Louis Bossart
2026-09-09 13:53                           ` Péter Ujfalusi
2026-09-09 20:22                             ` Pierre-Louis Bossart [this message]
2026-09-08 17:12                         ` Vinod Koul
2026-09-09 14:09                           ` Péter Ujfalusi
2026-09-08  6:52               ` Vinod Koul
2026-09-04  7:31 ` [PATCH 05/23] ASoC: soc-compress: Stop running dpcm on free Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 06/23] ASoC: SOF: compress: Rename compress ops with ipc3 prefix Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 07/23] ASoC: SOF: ipc4-pcm: harden pipeline teardown races Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 08/23] ASoC: SOF: sof-audio: do not dereference swidget->spipe unconditionally on free Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 09/23] ASoC: SOF: sof-audio: Expose a couple of functions Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 10/23] ASoC: SOF: pcm: Modify the signature of a couple of PCM IPC ops Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 11/23] ASoC: SOF: intel: hda-stream: Clear the current position when releasing stream Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 12/23] ASoC: SOF: ops: Add new platform-specific ops for compress Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 13/23] ASoC: SOF: ipc4: Add definition of module data in init_ext object type Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 14/23] ASoC: SOF: ipc4-topology: Support init_ext_module_data for process modules Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 15/23] ASoC: SOF: ipc4-pcm: Make the timestamp info usable outside of ipc4-pcm.c Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 16/23] ASoC: SOF: ipc4/ipc4-loader: Add SOF_INFO and CODEC_INFO to fw_config_params Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 17/23] ASoC: SOF: ipc4-pcm: Handle COMPR DRAIN triggers as EOS pipeline state Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 18/23] ASoC: SOF: ipc4-topology: Set FAST_MODE for host copier in compr mode Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 19/23] ASoC: SOF: Add support for IPC4 compressed Peter Ujfalusi
2026-09-04 20:08   ` Mark Brown
2026-09-07  5:15     ` Péter Ujfalusi
2026-09-09  6:48       ` Péter Ujfalusi
2026-09-04  7:31 ` [PATCH 20/23] ASoC: SOF: ipc4: Handle compressed drain done notification from firmware Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 21/23] ASoC: SOF: Intel: Kconfig: Remove redundant IPC version selects Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 22/23] ASoC: SOF: Intel: Kconfig: Select compress support for TGL+ platforms Peter Ujfalusi
2026-09-04  7:31 ` [PATCH 23/23] ASoC: SOF: topology: Add support for decoder and encoder widgets Peter Ujfalusi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e0ca888d-6607-47b4-a470-564c34cfa0cd@linux.dev \
    --to=pierre-louis.bossart@linux.dev \
    --cc=Vijendar.Mukunda@amd.com \
    --cc=broonie@kernel.org \
    --cc=daniel.baluta@nxp.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=srinivas.kandagatla@oss.qualcomm.com \
    --cc=tiwai@suse.com \
    --cc=vkoul@kernel.org \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).