From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1.perex.cz (mail1.perex.cz [77.48.224.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1858E1B3745; Wed, 14 Aug 2024 14:48:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.48.224.245 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723646938; cv=none; b=TBMshdB64Te9qFLYqT+vbdiX2qBWln8a5PL4imZSEKgXpdOPciQqPVadKkpLUiLLiFynCUAI1/TB208Vq8YeRyTu4wvnrdBQDIKHgxXYPe2JDLmENBQQi2XERov9XUwMadezzejZJC174t2fl/cUwFHjz/Vx+2vjKlpFz7LMB/w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723646938; c=relaxed/simple; bh=bgB+AGxkL7pa/5RfEGmbSBFKn4UxH4cStFGcwBOixEs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KmDEYNezLDJk3xkswJCwiwPE0DbyCXV7iEj783iig8eoa3jwe5QSZNPMVJMI9uGs/bgpj5tBbN/CKJfUIeIEpSHVDkIWkmtEcKu6OQPo9+HWVd5i4TQpKrdE3v+/IPtVd/JQvBbueO5i1X7+0eNDFNKIL+1Cxpz86/7i1hNB6r8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=perex.cz; spf=pass smtp.mailfrom=perex.cz; dkim=pass (1024-bit key) header.d=perex.cz header.i=@perex.cz header.b=ZqtZ6mkn; arc=none smtp.client-ip=77.48.224.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=perex.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=perex.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=perex.cz header.i=@perex.cz header.b="ZqtZ6mkn" Received: from mail1.perex.cz (localhost [127.0.0.1]) by smtp1.perex.cz (Perex's E-mail Delivery System) with ESMTP id 17094362A8; Wed, 14 Aug 2024 16:48:45 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.perex.cz 17094362A8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=perex.cz; s=default; t=1723646925; bh=uf2xW8WtF5oep5EfMnSWo30bmq7rA/yv7ksjq5ZNF78=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ZqtZ6mknsdTb+GhlqSLU1pKMbzM12+PpwW0OnK88bXL0kBV8lLkCxyZVV1ptFHw+1 0/MVjwkOrTVIOThvtkEjJIdRJ6u6E9vAg8TT8yWDP7y+Qdpzu5/BZiwUtgabcD9sc0 746KEDhSb8cWb8XGOlSeUG9EZsRiMBla3zPQQbH4= Received: from [192.168.100.98] (unknown [192.168.100.98]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: perex) by mail1.perex.cz (Perex's E-mail Delivery System) with ESMTPSA; Wed, 14 Aug 2024 16:48:31 +0200 (CEST) Message-ID: Date: Wed, 14 Aug 2024 16:48:30 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 1/6] ALSA: compress: add Sample Rate Converter codec support To: Pierre-Louis Bossart , Shengjiu Wang Cc: Shengjiu Wang , 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 References: <1722940003-20126-1-git-send-email-shengjiu.wang@nxp.com> <116041ee-7139-4b77-89be-3a68f699c01b@perex.cz> <930bb152-860a-4ec5-9ef0-1c96f554f365@linux.intel.com> <542d47c5-7ce3-4c17-8c0a-3a2b2a9e6c6a@linux.intel.com> <2be4303e-58e1-4ad7-92cf-f06fa6fa0f08@perex.cz> <7dc039db-ecce-4650-8eb7-96d0cfde09a2@linux.intel.com> <3cdb2041-59d4-4d43-ac4d-39d7f9640cef@linux.intel.com> <55a82ba3-1c33-4d1b-9f5f-8af33d76222f@linux.intel.com> From: Jaroslav Kysela Content-Language: en-US Autocrypt: addr=perex@perex.cz; keydata= xsFNBFvNeCsBEACUu2ZgwoGXmVFGukNPWjA68/7eMWI7AvNHpekSGv3z42Iy4DGZabs2Jtvk ZeWulJmMOh9ktP9rVWYKL9H54gH5LSdxjYYTQpSCPzM37nisJaksC8XCwD4yTDR+VFCtB5z/ E7U0qujGhU5jDTne3dZpVv1QnYHlVHk4noKxLjvEQIdJWzsF6e2EMp4SLG/OXhdC9ZeNt5IU HQpcKgyIOUdq+44B4VCzAMniaNLKNAZkTQ6Hc0sz0jXdq+8ZpaoPEgLlt7IlztT/MUcH3ABD LwcFvCsuPLLmiczk6/38iIjqMtrN7/gP8nvZuvCValLyzlArtbHFH8v7qO8o/5KXX62acCZ4 aHXaUHk7ahr15VbOsaqUIFfNxpthxYFuWDu9u0lhvEef5tDWb/FX+TOa8iSLjNoe69vMCj1F srZ9x2gjbqS2NgGfpQPwwoBxG0YRf6ierZK3I6A15N0RY5/KSFCQvJOX0aW8TztisbmJvX54 GNGzWurrztj690XLp/clewmfIUS3CYFqKLErT4761BpiK5XWUB4oxYVwc+L8btk1GOCOBVsp 4xAVD2m7M+9YKitNiYM4RtFiXwqfLk1uUTEvsaFkC1vu3C9aVDn3KQrZ9M8MBh/f2c8VcKbN njxs6x6tOdF5IhUc2E+janDLPZIfWDjYJ6syHadicPiATruKvwARAQABzSBKYXJvc2xhdiBL eXNlbGEgPHBlcmV4Q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DOygmpQAVYSOJvKAJ07AhQGaWAAi5msM6BcTU4YGcpW7FHr6+xaFDlRHzf1lkvavX WoxP1IA1DFuBMeYMzfyi4qDWjXc+C51ZaQd39EulYMh+JVaWRoY= In-Reply-To: <55a82ba3-1c33-4d1b-9f5f-8af33d76222f@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 >> 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 Linux Sound Maintainer; ALSA Project; Red Hat, Inc.