Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2294138rdb; Wed, 21 Feb 2024 03:16:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXji2GlzImraLrJppn94ZqVl6A13XEhQJUFNEeSEJqsz1I77WSlIfnkwOpmf/dsXwHSA8zPx0nMgEDFFXfUHZ0mo7HNE3DqfthepgtGQA== X-Google-Smtp-Source: AGHT+IFUfzC/8FPsAPg//f1ClCBS/B1Gz/Z8gz6zrwrATC7s1FVOnhyFNUGnDI3zta09t6pbPVVa X-Received: by 2002:a5d:929a:0:b0:7c7:4d7e:de87 with SMTP id s26-20020a5d929a000000b007c74d7ede87mr9294995iom.1.1708514211698; Wed, 21 Feb 2024 03:16:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708514211; cv=pass; d=google.com; s=arc-20160816; b=wK7oG3FYnvZYJ0KsI3OPyf39UK6+bs1B18HoOldy098dfr722J3q9L5T240mpo6E1C iLO2rC95m9F8I4GVmzr2b+f3pMzRnT9HgkB9CKZFTuAuIBDR1Yf7WfFsCcjmlHPuSKRu e+PP027ewU7cLgl3Yk7+Bl2ZN3MzidltdxRSQx/ugaywMe9pEHzWlXufqKV4vWFk15by Q8a5SOou9dclzgrmkjZWz+DtlRFlQeHfcyBIfQ47+SxdUuujVWmxhsTVwSm6KYxIa3C0 13dtvsPyjuok550E2FDGLfMIE+vnIZoNCQF4oLNhQsqXlng4p6TBcqZW2LnfibQX7eQD N0Vw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id; bh=np8ziHWN6Bne94dRoxvudZ6zSOBwVDmXGFxO7rpdo+U=; fh=M6ihe/QKqqW1qwOdXP3bNFybSx8XW80tcY+7R3FcW8c=; b=sVvbMZbKMizWkuIsUz3K0Im2pM1HcsgrDGHT2adaGmHCQrogwf83vfFV5ms6lcF0Kh rvRvYm6wCz3+bskXZ1uxT1e9j9uCNy4QXsi2y2McJQqEm7/SGbDgtIDN+SIPz9PjnRwo 4JEe65GjehY1qKqdVHHB2XME9+wYYMrjChIIUW+sDX4wFrDZKS4vbLePt60VVzbAgvJJ 7bsMZ2xXcjObpSIyu+fxcUFfcK4FtBDCWaiGAgLndTmWgRE5v9zZ0DkXmlNlFCP15hPA 5HA9tWVe0L5Xl39HyRgvtRco2PpSa30w6VqUgGF9hca24MoaMTSkz/zaCKB3zIUn6mUx 2Fjw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-74602-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74602-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p23-20020a639517000000b005dd565ce281si7860884pgd.881.2024.02.21.03.16.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 03:16:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74602-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-74602-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74602-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 59E35283E3F for ; Wed, 21 Feb 2024 11:16:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 63A7E3FE2A; Wed, 21 Feb 2024 11:16:42 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 826193EA8B; Wed, 21 Feb 2024 11:16:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708514201; cv=none; b=PFX7TD7QU9TOBFHWkqhv2d/rADxWO0fw76VNJbogWdQNGsjOPvtuzq2nMOF/dL/UHHwA+OwPiNM+2qRaknvWiVxzRpLW4BG/RDaJJxZ/DekKYEgn+xODB6KX1xdsC9dIP8Ad2O9rGp8JfmGBiskYmxf0urc3JExAptmV12DuV9U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708514201; c=relaxed/simple; bh=vpuxBZ8oEPP7CdvYYfEmiV0krzpKl60sOqo2vv8XlEU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=b/P5SymOJyOlb7ATrHNIIkF4OC19Ki3Kg9OdYYrBVIVvo46c8lU+6Ncwp/XtYMkM3Db4OCwng8g3aB0sqysPLhh9BxBD8O8PLwgkzDwlMf34jWH4g0yr2CH0QM8r7BA2sqOVerrTXuJMW7r7KvutMmuwOr1n7Z9QMPAvStEjQhE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A5E5C433F1; Wed, 21 Feb 2024 11:16:38 +0000 (UTC) Message-ID: <4205d9ae-43ae-407e-9eaf-e272c52799e6@xs4all.nl> Date: Wed, 21 Feb 2024 12:16:36 +0100 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: [PATCH v12 07/15] media: v4l2: Add audio capture and output support Content-Language: en-US, nl To: Shengjiu Wang , Tomasz Figa Cc: Mauro Carvalho Chehab , Shengjiu Wang , sakari.ailus@iki.fi, 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 References: <1705581128-4604-1-git-send-email-shengjiu.wang@nxp.com> <1705581128-4604-8-git-send-email-shengjiu.wang@nxp.com> <20240217104212.32f07e3a@coco.lan> From: Hans Verkuil Autocrypt: addr=hverkuil@xs4all.nl; keydata= xsFNBFQ84W0BEAC7EF1iL4s3tY8cRTVkJT/297h0Hz0ypA+ByVM4CdU9sN6ua/YoFlr9k0K4 BFUlg7JzJoUuRbKxkYb8mmqOe722j7N3HO8+ofnio5cAP5W0WwDpM0kM84BeHU0aPSTsWiGR yw55SOK2JBSq7hueotWLfJLobMWhQii0Zd83hGT9SIt9uHaHjgwmtTH7MSTIiaY6N14nw2Ud C6Uykc1va0Wqqc2ov5ihgk/2k2SKa02ookQI3e79laOrbZl5BOXNKR9LguuOZdX4XYR3Zi6/ BsJ7pVCK9xkiVf8svlEl94IHb+sa1KrlgGv3fn5xgzDw8Z222TfFceDL/2EzUyTdWc4GaPMC E/c1B4UOle6ZHg02+I8tZicjzj5+yffv1lB5A1btG+AmoZrgf0X2O1B96fqgHx8w9PIpVERN YsmkfxvhfP3MO3oHh8UY1OLKdlKamMneCLk2up1Z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pIpC5inPxIgR1+ZFvQrAV36SvLFfuMhyCAxV6WBlQc85ArOiQZB Wm7L0repwr7zEJFEkdy8C81WRhMdPvHkAIh3RoY1SGcdB7rB3wCzfYkAuCBqaF7Zgfw8xkad KEiQTexRbM1sc/I8ACpla3N26SfQwrfg6V7TIoweP0RwDrcf5PVvwSWsRQp2LxFCkwnCXOra gYmkrmv0duG1FStpY+IIQn1TOkuXrciTVfZY1cZD0aVxwlxXBnUNZZNslldvXFtndxR0SFat sflovhDxKyhFwXOP0Rv8H378/+14TaykknRBIKEc0+lcr+EMOSUR5eg4aURb8Gc3Uc7fgQ6q UssTXzHPyj1hAyDpfu8DzAwlh4kKFTodxSsKAjI45SLjadSc94/5Gy8645Y1KgBzBPTH7Q== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 21/02/2024 11:11, Shengjiu Wang wrote: > On Wed, Feb 21, 2024 at 12:30 PM Tomasz Figa wrote: >> >> On Sat, Feb 17, 2024 at 6:42 PM Mauro Carvalho Chehab >> wrote: >>> >>> Em Thu, 18 Jan 2024 20:32:00 +0800 >>> Shengjiu Wang escreveu: >>> >>>> Audio signal processing has the requirement for memory to >>>> memory similar as Video. >>>> >>>> This patch is to add this support in v4l2 framework, defined >>>> new buffer type V4L2_BUF_TYPE_AUDIO_CAPTURE and >>>> V4L2_BUF_TYPE_AUDIO_OUTPUT, defined new format v4l2_audio_format >>>> for audio case usage. >>>> >>>> The created audio device is named "/dev/v4l-audioX". >>>> >>>> Signed-off-by: Shengjiu Wang >>>> --- >>>> .../userspace-api/media/v4l/buffer.rst | 6 ++ >>>> .../media/v4l/dev-audio-mem2mem.rst | 71 +++++++++++++++++++ >>>> .../userspace-api/media/v4l/devices.rst | 1 + >>>> .../media/v4l/vidioc-enum-fmt.rst | 2 + >>>> .../userspace-api/media/v4l/vidioc-g-fmt.rst | 4 ++ >>>> .../media/videodev2.h.rst.exceptions | 2 + >>>> .../media/common/videobuf2/videobuf2-v4l2.c | 4 ++ >>>> drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 9 +++ >>>> drivers/media/v4l2-core/v4l2-dev.c | 17 +++++ >>>> drivers/media/v4l2-core/v4l2-ioctl.c | 53 ++++++++++++++ >>>> include/media/v4l2-dev.h | 2 + >>>> include/media/v4l2-ioctl.h | 34 +++++++++ >>>> include/uapi/linux/videodev2.h | 17 +++++ >>>> 13 files changed, 222 insertions(+) >>>> create mode 100644 Documentation/userspace-api/media/v4l/dev-audio-mem2mem.rst >>>> >>>> diff --git a/Documentation/userspace-api/media/v4l/buffer.rst b/Documentation/userspace-api/media/v4l/buffer.rst >>>> index 52bbee81c080..a3754ca6f0d6 100644 >>>> --- a/Documentation/userspace-api/media/v4l/buffer.rst >>>> +++ b/Documentation/userspace-api/media/v4l/buffer.rst >>>> @@ -438,6 +438,12 @@ enum v4l2_buf_type >>>> * - ``V4L2_BUF_TYPE_META_OUTPUT`` >>>> - 14 >>> >>>> - Buffer for metadata output, see :ref:`metadata`. >>>> + * - ``V4L2_BUF_TYPE_AUDIO_CAPTURE`` >>>> + - 15 >>>> + - Buffer for audio capture, see :ref:`audio`. >>>> + * - ``V4L2_BUF_TYPE_AUDIO_OUTPUT`` >>>> + - 16 >>> >>> Hmm... alsa APi define input/output as: >>> enum { >>> SNDRV_PCM_STREAM_PLAYBACK = 0, >>> SNDRV_PCM_STREAM_CAPTURE, >>> SNDRV_PCM_STREAM_LAST = SNDRV_PCM_STREAM_CAPTURE, >>> }; >>> >>> >>> I would use a namespace as close as possible to the >>> ALSA API. Also, we're not talking about V4L2, but, instead >>> audio. so, not sure if I like the prefix to start with >>> V4L2_. Maybe ALSA_? >>> >>> So, a better namespace would be: >>> >>> ${prefix}_BUF_TYPE_PCM_STREAM_PLAYBACK >>> and >>> ${prefix}_BUF_TYPE_PCM_STREAM_CAPTURE >>> >> >> The API is still V4L2, and all the other non-video buf types also use >> the V4L2_ prefix, so perhaps that's good here as well? >> >> Whether AUDIO or PCM_STREAM makes more sense goes outside of my >> expertise. Subjectively, a PCM stream sounds more specific than an >> audio stream. Do those buf types also support non-PCM audio streams? > > Currently I use it for PCM, but I think it can also be used for non-PCM. > So use the below name? > V4L2_BUF_TYPE_AUDIO_CAPTURE > V4L2_BUF_TYPE_AUDIO_PLAYBACK I really prefer keeping the names as they are in this patch. CAPTURE/OUTPUT is consistent with V4L2 nomenclature, and since this is a M2M device 'PLAYBACK' isn't really a good name either. It's not an audio playback device, it's a rate converter. Regards, Hans > >> >>>> + - Buffer for audio output, see :ref:`audio`. >>>> >>>> >>>> .. _buffer-flags: >>>> diff --git a/Documentation/userspace-api/media/v4l/dev-audio-mem2mem.rst b/Documentation/userspace-api/media/v4l/dev-audio-mem2mem.rst >>>> new file mode 100644 >>>> index 000000000000..68faecfe3a02 >>>> --- /dev/null >>>> +++ b/Documentation/userspace-api/media/v4l/dev-audio-mem2mem.rst >>>> @@ -0,0 +1,71 @@ >>>> +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later >>>> + >>>> +.. _audiomem2mem: >>>> + >>>> +******************************** >>>> +Audio Memory-To-Memory Interface >>>> +******************************** >>>> + >>>> +An audio memory-to-memory device can compress, decompress, transform, or >>>> +otherwise convert audio data from one format into another format, in memory. >>>> +Such memory-to-memory devices set the ``V4L2_CAP_AUDIO_M2M`` capability. >>>> +Examples of memory-to-memory devices are audio codecs, audio preprocessing, >>>> +audio postprocessing. >>>> + >>>> +A memory-to-memory audio node supports both output (sending audio frames from >>>> +memory to the hardware) and capture (receiving the processed audio frames >>>> +from the hardware into memory) stream I/O. An application will have to >>>> +setup the stream I/O for both sides and finally call >>>> +:ref:`VIDIOC_STREAMON ` for both capture and output to >>>> +start the hardware. >>>> + >>>> +Memory-to-memory devices function as a shared resource: you can >>>> +open the audio node multiple times, each application setting up their >>>> +own properties that are local to the file handle, and each can use >>>> +it independently from the others. The driver will arbitrate access to >>>> +the hardware and reprogram it whenever another file handler gets access. >>>> + >>>> +Audio memory-to-memory devices are accessed through character device >>>> +special files named ``/dev/v4l-audio`` >>>> + >>>> +Querying Capabilities >>>> +===================== >>>> + >>>> +Device nodes supporting the audio memory-to-memory interface set the >>>> +``V4L2_CAP_AUDIO_M2M`` flag in the ``device_caps`` field of the >>>> +:c:type:`v4l2_capability` structure returned by the :c:func:`VIDIOC_QUERYCAP` >>>> +ioctl. >>>> + >>>> +Data Format Negotiation >>>> +======================= >>>> + >>>> +The audio device uses the :ref:`format` ioctls to select the capture format. >>>> +The audio buffer content format is bound to that selected format. In addition >>>> +to the basic :ref:`format` ioctls, the :c:func:`VIDIOC_ENUM_FMT` ioctl must be >>>> +supported as well. >>>> + >>>> +To use the :ref:`format` ioctls applications set the ``type`` field of the >>>> +:c:type:`v4l2_format` structure to ``V4L2_BUF_TYPE_AUDIO_CAPTURE`` or to >>>> +``V4L2_BUF_TYPE_AUDIO_OUTPUT``. Both drivers and applications must set the >>>> +remainder of the :c:type:`v4l2_format` structure to 0. >>>> + >>>> +.. c:type:: v4l2_audio_format >>>> + >>>> +.. tabularcolumns:: |p{1.4cm}|p{2.4cm}|p{13.5cm}| >>>> + >>>> +.. flat-table:: struct v4l2_audio_format >>>> + :header-rows: 0 >>>> + :stub-columns: 0 >>>> + :widths: 1 1 2 >>>> + >>>> + * - __u32 >>>> + - ``pixelformat`` >>>> + - The sample format, set by the application. see :ref:`pixfmt-audio` >>> >>> pixelformat doesn't make any sense for audio: there are no pixels on a >>> PCM stream. Please use call it, instead: `snd_pcm_format`, making it match >>> the values for snd_pcm_format_t. >>> >> >> +1 >> >> FWIW v4l2_meta_format uses the name "dataformat". >> >> Actually, I just realized that the C code actually uses the name >> "audioformat". Tbh., after reading the kerneldoc comment, my >> subjective preference would be on "sample_format", since that's >> exactly what it is. >> > Ok, I will change it to sampleformat. > > Best Regards > Shengjiu Wang > >>> Yet, I would keep defining it as u32 (or u64?) instead of using a >>> typedef int field there (snd_pcm_format_t), as the size of integer >>> is different on 32 and 64 bit kernels. >> >> +1 >> >> Best regards, >> Tomasz