mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jaroslav Kysela <perex@perex.cz>
To: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Shengjiu Wang <shengjiu.wang@gmail.com>
Cc: Shengjiu Wang <shengjiu.wang@nxp.com>,
	vkoul@kernel.org, tiwai@suse.com, alsa-devel@alsa-project.org,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	Xiubo.Lee@gmail.com, festevam@gmail.com, nicoleotsuka@gmail.com,
	lgirdwood@gmail.com, broonie@kernel.org,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [RFC PATCH 1/6] ALSA: compress: add Sample Rate Converter codec support
Date: Wed, 14 Aug 2024 16:48:30 +0200	[thread overview]
Message-ID: <bf85656b-5b12-4101-adfa-1a8c6afb6084@perex.cz> (raw)
In-Reply-To: <55a82ba3-1c33-4d1b-9f5f-8af33d76222f@linux.intel.com>

On 14. 08. 24 13:58, Pierre-Louis Bossart wrote:
> 
> 
> On 8/14/24 13:12, Shengjiu Wang wrote:
>> On Wed, Aug 14, 2024 at 5:40 PM Pierre-Louis Bossart
>> <pierre-louis.bossart@linux.intel.com> wrote:
>>>
>>>
>>>> Yes, to go further, I think we can use SND_AUDIOCODEC_PCM, then
>>>> the SRC type will be dropped.
>>>
>>> sounds good.
>>>
>>>> But my understanding of the control means the .set_metadata() API, right?
>>>> As I said, the output rate, output format, and ratio modifier are applied to
>>>> the instances of ASRC,  which is the snd_compr_stream in driver.
>>>> so only the .set_metadata() API can be used for these purposes.
>>>
>>> Humm, this is more controversial.
>>>
>>> The term 'metadata' really referred to known information present in
>>> headers or additional ID3 tags and not in the compressed file itself.
>>> The .set_metadata was assumed to be called ONCE before decoding.
>>>
>>> But here you have a need to update the ratio modifier on a regular basis
>>> to compensate for the drift. This isn't what this specific callback was
>>> designed for. We could change and allow this callback to be used
>>> multiple times, but then this could create problems for existing
>>> implementations which cannot deal with modified metadata on the fly.
>>
>> .set_metadata can be called multi times now, no need to change currently.
> 
> Not really, this set_metadata() callback is used only for gapless
> transitions between tracks, see fcplay.c in tinycompress.
> 
> And now I am really confused because tinycompress uses an IOCTL directly:
> 
> 	metadata.key = SNDRV_COMPRESS_ENCODER_PADDING;
> 	metadata.value[0] = mdata->encoder_padding;
> 	if (ioctl(compress->fd, SNDRV_COMPRESS_SET_METADATA, &metadata))
> 
> Whereas you want to use the ops callback directly from the control layer?
> 
> What would present a userspace program from using the ioctl directly
> then? In that case, why do we need the control? I must be missing something.

The whole discussion is which place is more appropriate for the runtime 
controls (like the frequency shift). My opinion is, if we have a layer for 
this which can be used for presence of those controls and even range / type / 
notifications, we should use it.

The new/updated ioctls bounded only to active file descriptor does not allow 
to monitor those values outside.

>>> And then there's the problem of defining a 'key' for the metadata. the
>>> definition of the key is a u32, so there's plenty of space for different
>>> implementations, but a collision is possible. We'd need an agreement on
>>> how to allocate keys to different solutions without changing the header
>>> file for every implementation.
>>
>> Can we define a private space for each case?   For example the key larger
>> than 0x80000000 is private, each driver can define it by themself?
> 
> that would be a possibility indeed - provided that the opens above are
> straightened out.
> 
>>> It sounds like we'd need a 'runtime params' callback - unless there's a
>>> better trick to tie the control and compress layers?

I don't follow. If the compress driver code uses card/device/subdevice 
numbers, we can address the control properly. The problem is just that 
subdevice support in missing the current compress code / API.

For me, the compress_params.h changes may also require to pay attention to the 
encoding/decoding of the current compressed streams. So something like this 
may be more appropriate for the first step:

diff --git a/include/uapi/sound/compress_params.h 
b/include/uapi/sound/compress_params.h
index ddc77322d571..c664d15410eb 100644
--- a/include/uapi/sound/compress_params.h
+++ b/include/uapi/sound/compress_params.h
@@ -347,6 +347,8 @@ union snd_codec_options {
   * @modes: Supported modes. See SND_AUDIOMODE defines
   * @formats: Supported formats. See SND_AUDIOSTREAMFORMAT defines
   * @min_buffer: Minimum buffer size handled by codec implementation
+ * @pcm_formats: Output (for decoders) or input (for encoders)
+ *               PCM formats (required to accel mode, 0 for other modes)
   * @reserved: reserved for future use
   *
   * This structure provides a scalar value for profiles, modes and stream
@@ -370,7 +372,8 @@ struct snd_codec_desc {
         __u32 modes;
         __u32 formats;
         __u32 min_buffer;
-       __u32 reserved[15];
+       __u32 pcm_formats;
+       __u32 reserved[14];
  } __attribute__((packed, aligned(4)));

  /** struct snd_codec
@@ -395,6 +398,8 @@ struct snd_codec_desc {
   * @align: Block alignment in bytes of an audio sample.
   *             Only required for PCM or IEC formats.
   * @options: encoder-specific settings
+ * @pcm_format: Output (for decoders) or input (for encoders)
+ *               PCM formats (required to accel mode, 0 for other modes)
   * @reserved: reserved for future use
   */

@@ -411,7 +416,8 @@ struct snd_codec {
         __u32 format;
         __u32 align;
         union snd_codec_options options;
-       __u32 reserved[3];
+       __u32 pcm_format;
+       __u32 reserved[2];
  } __attribute__((packed, aligned(4)));

  #endif

Then the SRC extension may be like:

diff --git a/include/uapi/sound/compress_params.h 
b/include/uapi/sound/compress_params.h
index c664d15410eb..5d51ecba6d55 100644
--- a/include/uapi/sound/compress_params.h
+++ b/include/uapi/sound/compress_params.h
@@ -334,6 +334,14 @@ union snd_codec_options {
  	struct snd_dec_wma wma_d;
  	struct snd_dec_alac alac_d;
  	struct snd_dec_ape ape_d;
+	struct {
+		__u32 out_sample_rate;
+	} src_d;
+} __attribute__((packed, aligned(4)));
+
+struct snd_codec_desc_src {
+	__u32 out_sample_rate_min;
+	__u32 out_sample_rate_max;
  } __attribute__((packed, aligned(4)));

  /** struct snd_codec_desc - description of codec capabilities
@@ -349,6 +357,7 @@ union snd_codec_options {
   * @min_buffer: Minimum buffer size handled by codec implementation
   * @pcm_formats: Output (for decoders) or input (for encoders)
   *               PCM formats (required to accel mode, 0 for other modes)
+ * @u_space: union space (for codec dependent date)
   * @reserved: reserved for future use
   *
   * This structure provides a scalar value for profiles, modes and stream
@@ -373,7 +382,11 @@ struct snd_codec_desc {
  	__u32 formats;
  	__u32 min_buffer;
  	__u32 pcm_formats;
-	__u32 reserved[14];
+	union {
+		__u32 u_space[6];
+		struct snd_codec_desc_src src;
+	} __attribute__((packed, aligned(4)));
+	__u32 reserved[8];
  } __attribute__((packed, aligned(4)));

  /** struct snd_codec

This will allow to handshake the output rate between user space and kernel 
driver. Eventually we can use a rate bitmap to be more precise in "struct 
snd_codec_desc_src" (or combination of range/bitmap).

						Jaroslav

-- 
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.


  reply	other threads:[~2024-08-14 14:48 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-06 10:26 [RFC PATCH 0/6] ASoC: fsl: add memory to memory function for ASRC Shengjiu Wang
2024-08-06 10:26 ` [RFC PATCH 1/6] ALSA: compress: add Sample Rate Converter codec support Shengjiu Wang
2024-08-06 11:16   ` Pierre-Louis Bossart
2024-08-06 11:39     ` Jeff Brower
2024-08-08  9:17     ` Shengjiu Wang
2024-08-08 11:27       ` Pierre-Louis Bossart
2024-08-08 12:02         ` Jaroslav Kysela
2024-08-08 12:19           ` Pierre-Louis Bossart
2024-08-08 15:51             ` Jaroslav Kysela
2024-08-09  7:19               ` Pierre-Louis Bossart
2024-08-09 10:14                 ` Shengjiu Wang
2024-08-09 12:52                   ` Pierre-Louis Bossart
2024-08-09 14:00                     ` Jaroslav Kysela
2024-08-09 19:20                       ` Pierre-Louis Bossart
2024-08-12 10:24                       ` Shengjiu Wang
2024-08-12 13:31                         ` Jaroslav Kysela
2024-08-12 13:43                           ` Pierre-Louis Bossart
2024-08-14  2:22                             ` Shengjiu Wang
2024-08-14  9:40                               ` Pierre-Louis Bossart
2024-08-14 11:12                                 ` Shengjiu Wang
2024-08-14 11:58                                   ` Pierre-Louis Bossart
2024-08-14 14:48                                     ` Jaroslav Kysela [this message]
2024-08-09 13:51                   ` Jaroslav Kysela
2024-08-06 10:26 ` [RFC PATCH 2/6] ASoC: fsl_asrc: define functions for memory to memory usage Shengjiu Wang
2024-08-06 10:26 ` [RFC PATCH 3/6] ASoC: fsl_easrc: " Shengjiu Wang
2024-08-06 10:26 ` [RFC PATCH 4/6] ASoC: fsl_asrc_m2m: Add memory to memory function Shengjiu Wang
2024-08-06 10:26 ` [RFC PATCH 5/6] ASoC: fsl_asrc: register m2m platform device Shengjiu Wang
2024-08-06 10:26 ` [RFC PATCH 6/6] ASoC: fsl_easrc: " Shengjiu Wang

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=bf85656b-5b12-4101-adfa-1a8c6afb6084@perex.cz \
    --to=perex@perex.cz \
    --cc=Xiubo.Lee@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=festevam@gmail.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=nicoleotsuka@gmail.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=shengjiu.wang@gmail.com \
    --cc=shengjiu.wang@nxp.com \
    --cc=tiwai@suse.com \
    --cc=vkoul@kernel.org \
    /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

all inboxes | Powered by JetHome®