Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp111383rdb; Wed, 21 Feb 2024 19:51:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWNS3oheqDGWqXLL/WOHiOYsMPZ8AdColowxsrmR9F565HW1xh1Vp3rCS6l6BGzMefddQF8QyA+0sEqwXCe396tK0BIp9yU4HUN24pzWw== X-Google-Smtp-Source: AGHT+IEoolUlrxEh9AUZN0Fs6JLxgjPgr/BJP1p0YlNlxkARAlG2qLmnZdeDyY2xTVAJ2OLf56gu X-Received: by 2002:aa7:c599:0:b0:565:ccf:7876 with SMTP id g25-20020aa7c599000000b005650ccf7876mr1879641edq.2.1708573867208; Wed, 21 Feb 2024 19:51:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708573867; cv=pass; d=google.com; s=arc-20160816; b=nN55U1b3FjKRBYO6coyXJkYGtFPIO3TejnQx66fT9ZgACoe+pwdWSsDcu23wIBTcOe 0veqtCtBGcDqEOPqwK1pw8RKC8uPPWMDx4IgSEM7XsEi9jVW58y5f0bftzr0tan3bXmZ XD0PifC70alBcpwD1oE7S9m3PTw7Gxpvhh6Tqy0zC7vT0WEC/HH8g9ROegtaesv3OImC Op8tQXTZ9SUU3IHUIIYIse2KufLHFWNP9SHW6yuvL58Ev+MkDvfwZ3o8cygo4YElQVl1 H3yrkXe1xgvKnwIbXP0Dl/AWVBEdrVZNJrP0pHAu2/yQcfX5nRlaMKzj+ix94PF2V8aA ejUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=y/Q0YGTOKcdouf/IIlA2xOaiZYdgb6GG89hveRTd/5g=; fh=Y33DPTHsBnEHHQJlIaqQOPJ/KNAugLPEt9m9T7xW9gY=; b=0cJoBQrunNnTt+x3ZNQ56Q9nSX1JbA7yv8NIMuy1p+e6Ts9AJ8/UyE2r0pBVlyaSOa PA5dMjWa1jU7QlTjZR3UiIi7OjV+HWwTGthFPqfdjrtYc9J1xwnJI4jGPPsR7BoGQtJH lGZRj2IvTU2tYzWywCfacQAPnHnsnE/M/W+Qsoib93Sb397bESWl7aS2EtQhhnSNNXeM DZBz0LbVJXrkYlEhNkZ0UNxIza5+CjJQv933uJdkLNp5hY5+QCBIReqiz12FuG0kJqmN Ia/EJPd0sHTxnnRJQVeiar0z/TrFw/kc5ju1IEFmf8+KpNhLD09PHvOF2xg+NqLgn9bh cYDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=f8K79ujf; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-75875-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75875-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w19-20020a05640234d300b005645eea2000si3672700edc.60.2024.02.21.19.51.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 19:51:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75875-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=f8K79ujf; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-75875-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75875-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BBE2B1F21F5F for ; Thu, 22 Feb 2024 03:51:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5BCBB17743; Thu, 22 Feb 2024 03:50:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f8K79ujf" Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9373E111B2; Thu, 22 Feb 2024 03:50:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708573857; cv=none; b=I4NXzV+WKt3bAuko4G7SjMa0ATEBp1cYyHTYY/MlwV8u/TGR4No5CFfr55IuIHo2OyQMj8KwJYoAsZkqBUchEImUdMNvyNbAEUuBm9ZILv3jPO9durOWJ+e0kn3L0+/Sb7YyfdUs2lPCw05u2QYIKff6cwcReQmOPsORWHr2XxA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708573857; c=relaxed/simple; bh=J3j8PZZdp5i0Gd+0rx6IZWHUtQPKYoQur7jAPifN9go=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=aMkaX5RaDbTnAhfaLgSlBHyX7edoreggJtFyQZhogs/W9jgWGrEkhYvh/3lY5j82MKEvbg+TUklDIpXCKieyHAvIky9uo/vZIz+Q9hbaj19WtdIOrHzH6Pv7nSuomBiGNDykFK2uN/spa1eXI9Gr4sak3sNdfHPBgaghiAEdTKA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=f8K79ujf; arc=none smtp.client-ip=209.85.166.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-io1-f54.google.com with SMTP id ca18e2360f4ac-7c72294e3d1so284571339f.1; Wed, 21 Feb 2024 19:50:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708573855; x=1709178655; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=y/Q0YGTOKcdouf/IIlA2xOaiZYdgb6GG89hveRTd/5g=; b=f8K79ujf/hbdxRtSaN4HrY35pZYF8BBwW7zY4yzNK6HfT+rlN2O6BE024uL1u/c96Z iwEJvuwtUjyQ8cLbUHVf31+3rTf1K54H2LnZN4iAuI41GG2GZ+U11D4fkCWApCFM+acB +3ysARRj6I+1b6t1Eye8dKTjLAZHRAMsIOUe1QrDVfLJ+VfwTWbDswVDdkMeWHiig3qw abpqw+RQlYt5eKeGUGXYI9P0TUcVa78L4bR3nDizeBbJE9kzyu7oV4O3WCmybstKLQNR 1S/gWbrsthiQEswDnOnQzlDtwmZjKM1gZ+EM1GKjIqPxIok+vj1gIxv4S0wNdg27dFhR GFBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708573855; x=1709178655; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y/Q0YGTOKcdouf/IIlA2xOaiZYdgb6GG89hveRTd/5g=; b=Aj2CeEIoKi3HGXnevSxBW7dsQZizdoGY62iDn+lmumGhlqY5SI2CRqsksg5T3d4vi2 YJ6yO43g8TRzsad4innFPrcJcL9KYgmXaoh5t6LPB3TOVUvgHfgJjLAsC5/utg8uDxzq LGt9y7+BMrP4hPpUN9y17V5+dTl6OPDherwUhhI/bPLnPMXfXnEc7We6wlMF0V+p+GUm ZJw+AQyUuGrC91/FkXOqzS5mzYRYnEKdwTkbBJ7veTCaA4dWrTa2J56hSighmMDYQZjd vNssLtl0IPzR3dIXnOsedmctko5H2D+d/35BWJjisReZo2MCy8wtmaXbluyxhnKGpH6t EFrw== X-Forwarded-Encrypted: i=1; AJvYcCWc8zKhPL+AFvd4QprZe83YBK8/hEtB/qT2TRHAlwLVZWvNQpb4F/r1JbnDFYJsSZu0pUjxhu5KU63ORVmslPui12tI5wGnwAOlz0/LwjggGLvxrry5e0yq2ctN/vHYbeV7Bl2WA6TLUac= X-Gm-Message-State: AOJu0YwuWaYqyMnDxO1c1RAExOVftfJo3FZR2FfLUrWuQdXwLdsrJuZG zP5zoNyrtUdZx2/glvslqdxVtAGDi3S6XgYXguwYDKKL54iEXa7uJWDpoDV90SkqEkH7YF59biu UdztA0y6YW6EYwVL7+586x+tyuTw= X-Received: by 2002:a05:6e02:1d95:b0:365:1305:fac5 with SMTP id h21-20020a056e021d9500b003651305fac5mr19489792ila.0.1708573854696; Wed, 21 Feb 2024 19:50:54 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <1705581128-4604-1-git-send-email-shengjiu.wang@nxp.com> <1705581128-4604-9-git-send-email-shengjiu.wang@nxp.com> <20240217101926.3f1d2452@coco.lan> <20240219135618.5c557e66@coco.lan> In-Reply-To: From: Shengjiu Wang Date: Thu, 22 Feb 2024 11:50:43 +0800 Message-ID: Subject: Re: [PATCH v12 08/15] media: uapi: Define audio sample format fourcc type To: Hans Verkuil Cc: Mauro Carvalho Chehab , Shengjiu Wang , sakari.ailus@iki.fi, tfiga@chromium.org, m.szyprowski@samsung.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Xiubo.Lee@gmail.com, festevam@gmail.com, nicoleotsuka@gmail.com, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linuxppc-dev@lists.ozlabs.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Feb 21, 2024 at 7:10=E2=80=AFPM Hans Verkuil w= rote: > > On 19/02/2024 13:56, Mauro Carvalho Chehab wrote: > > Em Mon, 19 Feb 2024 12:05:02 +0800 > > Shengjiu Wang escreveu: > > > >> Hi Mauro > >> > >> On Sat, Feb 17, 2024 at 5:19=E2=80=AFPM Mauro Carvalho Chehab > >> wrote: > >>> > >>> Em Thu, 18 Jan 2024 20:32:01 +0800 > >>> Shengjiu Wang escreveu: > >>> > >>>> The audio sample format definition is from alsa, > >>>> the header file is include/uapi/sound/asound.h, but > >>>> don't include this header file directly, because in > >>>> user space, there is another copy in alsa-lib. > >>>> There will be conflict in userspace for include > >>>> videodev2.h & asound.h and asoundlib.h > >>>> > >>>> Here still use the fourcc format. > >>>> > >>>> Signed-off-by: Shengjiu Wang > >>>> --- > >>>> .../userspace-api/media/v4l/pixfmt-audio.rst | 87 ++++++++++++++++= +++ > >>>> .../userspace-api/media/v4l/pixfmt.rst | 1 + > >>>> drivers/media/v4l2-core/v4l2-ioctl.c | 13 +++ > >>>> include/uapi/linux/videodev2.h | 23 +++++ > >>>> 4 files changed, 124 insertions(+) > >>>> create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-aud= io.rst > >>>> > >>>> diff --git a/Documentation/userspace-api/media/v4l/pixfmt-audio.rst = b/Documentation/userspace-api/media/v4l/pixfmt-audio.rst > >>>> new file mode 100644 > >>>> index 000000000000..04b4a7fbd8f4 > >>>> --- /dev/null > >>>> +++ b/Documentation/userspace-api/media/v4l/pixfmt-audio.rst > >>>> @@ -0,0 +1,87 @@ > >>>> +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later > >>>> + > >>>> +.. _pixfmt-audio: > >>>> + > >>>> +************* > >>>> +Audio Formats > >>>> +************* > >>>> + > >>>> +These formats are used for :ref:`audiomem2mem` interface only. > >>>> + > >>>> +.. tabularcolumns:: |p{5.8cm}|p{1.2cm}|p{10.3cm}| > >>>> + > >>>> +.. cssclass:: longtable > >>>> + > >>>> +.. flat-table:: Audio Format > >>>> + :header-rows: 1 > >>>> + :stub-columns: 0 > >>>> + :widths: 3 1 4 > >>>> + > >>>> + * - Identifier > >>>> + - Code > >>>> + - Details > >>>> + * .. _V4L2-AUDIO-FMT-S8: > >>>> + > >>>> + - ``V4L2_AUDIO_FMT_S8`` > >>>> + - 'S8' > >>>> + - Corresponds to SNDRV_PCM_FORMAT_S8 in ALSA > >>>> + * .. _V4L2-AUDIO-FMT-S16-LE: > >>> > >>> Hmm... why can't we just use SNDRV_*_FORMAT_*? Those are already part= of > >>> an uAPI header. No need to add any abstraction here and/or redefine > >>> what is there already at include/uapi/sound/asound.h. > >>> > >> Actually I try to avoid including the include/uapi/sound/asound.h. > >> Because in user space, there is another copy in alsa-lib (asoundlib.h)= . > >> There will be conflict in userspace when including videodev2.h and > >> asoundlib.h. > > > > Well, alsasoundlib.h seems to be using the same definitions: > > https://github.com/michaelwu/alsa-lib/blob/master/include/pcm.h > > > > So, I can't see what would be the actual issue, as both userspace libra= ry > > and ALSA internal headers use the same magic numbers. > > > > You can still do things like: > > > > #ifdef __KERNEL__ > > # include > > #else > > # include > > #endif > > > > To avoid such kind of conflicts, if you need to have it included on > > some header file. Yet, I can't see why you would need that. > > > > IMO, at uAPI headers, you just need to declare the uAPI audiofmt field > > to be either __u32 or __u64, pointing it to where this value comes from > > (on both userspace and Kernelspace. E. g.: > > > > /** > > * struct v4l2_audio_format - audio data format definition > > * @audioformat: > > * an integer number matching the fields inside > > * enum snd_pcm_format_t (e. g. `SNDRV_PCM_FORMAT_*`), as defined > > * in include/uapi/sound/asound.h and > > * https://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m.ht= ml#gaa14b7f26877a812acbb39811364177f8. > > * @channels: channel numbers > > * @buffersize: maximum size in bytes required for data > > */ > > struct v4l2_audio_format { > > __u32 audioformat; > > __u32 channels; > > __u32 buffersize; > > } __attribute__ ((packed)); > > > > Then, at documentation you just need to point to where the > > possible values for SNDRV_PCM_FORMAT_ are defined. No need to > > document them one by one. > > > > With such definition, you'll only need to include sound/asound.h > > within the kAPI scope. > > > >> > >> And in the V4l framework, the fourcc type is commonly used in other > >> cases (video, radio, touch, meta....), to avoid changing common code > >> a lot, so I think using fourcc definition for audio may be simpler. > > > > Those are real video streams (or a video-related streams, in the case > > of metadata) where fourcc is widely used. There, it makes sense. > > However, ALSA format definitions are already being used for a long time= . > > There's no sense on trying to reinvent it - or having an abstract layer > > to convert from/to fourcc <=3D=3D> enum snd_pcm_format_t. Just use what= is > > there already. > > The problem is that within V4L2 we use fourcc consistently to describe a > format, including in VIDIOC_ENUM_FMT. And the expectation is that the fou= rcc > can be printed to a human readable string (there is even a printk format = for > that these days). > > But the pcm values are all small integers (and can even be 0!), and > printing the fourcc will give garbage. It doesn't work well at all > with the V4L2 API. But by having a straightforward conversion between the > pcm identifier and a fourcc it was really easy to deal with this. > > There might even be applications today that call VIDIOC_ENUM_FMT to see > what is supported and fail if it is not a proper fourcc is returned. > > It will certainly report nonsense in v4l_print_fmtdesc() (v4l2-ioctl.c). > > One of the early versions of this patch series did precisely what you req= uest, > but it just doesn't work well within the V4L2 uAPI. > Thanks all. So can I reach the conclusion below? 1. Keep using the fourcc definition for v4l2_audio_format.audioformat. 2. Keep the name V4L2_BUF_TYPE_AUDIO_CAPTURE and V4L2_BUF_TYPE_AUDIO_OUTPUT. 3. Fix Documentation/userspace-api/media/v4l/dev-audio-mem2mem.rst to change 'pixelformat' to 'audioformat'. 4. Update Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst to add more description for clock drift. Best Regards Shengjiu Wang > Regards, > > Hans > > > > > Thanks, > > Mauro >