Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2146915rdb; Tue, 20 Feb 2024 20:31:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVtOAXOP9zyoUtCfKyo7q1BGHQIfPt+ehKDnUd+/lOH9PnCmmRiLu5gVrEJDp/TiH9YPk8Z6EepUAR0gPG1+yeOKjgI+m0+foix+PFZMA== X-Google-Smtp-Source: AGHT+IHfdq3gsk5R7rBNZn/QlUYjGV0Bv2kD/FE8stpgjhJ7gJpKrSEQ6nqOtrkHZfL/WbS+FUOi X-Received: by 2002:aa7:df14:0:b0:564:6b09:9305 with SMTP id c20-20020aa7df14000000b005646b099305mr5215178edy.6.1708489867254; Tue, 20 Feb 2024 20:31:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708489867; cv=pass; d=google.com; s=arc-20160816; b=DtQKI2ouJnGiQ4DjviRk6ewoxXD28b6Kh/kLo0wIShWo8oH25tV4kKJ6uZ6hD+dvXM jIiyyeQw7qs7fwkJllsSDeFZbobXtdMPBM8KnNZBumyAU+83bPshAI7dpxbQIK+eHDnh IaTD+jNNkpcX7SjMW2zZKnVImixbxy5km8yA5DvW4MXr6c9khb0mD6WZlxgrdY2/3iBg OKtQCd5vPeBRmf/cRkFiKBhS8Sm7IyFJga70KYIHdj/+qkKMFFZnoI7Wpp2/Y30aSrdA Dk3z83rCyWi1wK33nZAY1MvfuIQE8/FeB7jUvJTdowKc6D2HMtth2JI8XGYzqek7BSA7 4QtQ== 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=aTLF+9/86+3ZrNqwWCAt6rY4IvAqp7zzJB3AKM6ztK4=; fh=QS4SbMkFQ7BUhj22l41eAOU9FODTxex4metKvDOEkiQ=; b=XrIuJBsGVM/tdhXlATbNVLfFa6uiiYIglyPM+melbfVzTRa+auHwru0evKpHkY3zt8 MjD2MnkT8XOQfSsioLXj1couVh2IrAog4S7k7CbaCQZtOBWtlDpmsH8lfNtgW8nfxZYN qfW2SOaVutQUBuQAXcWGUUKmdzlrri7uBGzTSLgP744tUWTgqTkfi0fNKi4vfgnjLahI dktz0S/wRGa6Scaq+a8pZqL5+7JKkeCrkL+43ojEfY9iL5MXMcwVIb8h2dYU3gadPaUf QM/s3XG17csFfP7ATdcE1/vuEXEjADdLoojLoaM3GhuT7J0V59eUHKGhx04RtM7Xyrbf DG4Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Eclbx+rb; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-74048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74048-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z6-20020a05640235c600b00564902eac01si2183392edc.250.2024.02.20.20.31.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 20:31:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74048-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=@chromium.org header.s=google header.b=Eclbx+rb; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-74048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74048-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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 E13BE1F2541E for ; Wed, 21 Feb 2024 04:31:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CEEA239AC5; Wed, 21 Feb 2024 04:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Eclbx+rb" Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 AD34D2943A for ; Wed, 21 Feb 2024 04:30:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708489851; cv=none; b=BB7xzsdpZHHieCB0vaYeUXWNV6c6z8MANHU7mjzst3j6o4yYtGnuqs0lqayafut3lPWs+AYZmtZtXMjiqYjkClOYpFBxqNKYx6rOZXo2q7FjkU8UHzbmA+tBId4R0u9dBdlNir23D6LMfdHNkDf3SJaYWMK7Qfa+Driy5seSWxY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708489851; c=relaxed/simple; bh=bWzhYtox2bpUREEb2FwOBY7Yv6HvM9YvDi85zi8WYRE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Vjbf2rf6FX37d+HD22LjjpYBIxLs3rpnoleXCt0yuXwfL2qZnKVTRVvndtIMVkp5hj1tuNnWUqr9McXsaOqGVYYtt2pQ5KgJREcLSy+/Vi6N4L5r4HlP2K/rPVUrtJE0FizLjlClKzN8UgKjczre3aorraLFBbrF6r8850wkPtU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Eclbx+rb; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-563fe793e1cso6275240a12.3 for ; Tue, 20 Feb 2024 20:30:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1708489848; x=1709094648; 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=aTLF+9/86+3ZrNqwWCAt6rY4IvAqp7zzJB3AKM6ztK4=; b=Eclbx+rbCvRSej7MS7bLfHBisTI5B79t0eu+/SBLXv4CiX7pe2Bh7awXb1Pd/BWqLY YhlSOqlkxIUuv5DrgRt/ralvzw3uskKhjNxZNfbG9eBM8MBlP/pYijZqyXy9k/ELQ/YW s61mGqQlvgjjMVAt0uOF7cyOJ4gTAe9EWVFGo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708489848; x=1709094648; 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=aTLF+9/86+3ZrNqwWCAt6rY4IvAqp7zzJB3AKM6ztK4=; b=VpPf6Sba9yGReNeuEVOhgY8v9yg1mPs/1Mct6IYeQLMNFK4+aukW6cd8GEyDK8PpTI IY/rIBurO8GtNNCI+mLCbF5BQpkLLk7KbJqO5ZaQWhD+O5AAPdPzMetNIKLO0f5BnS4A aE38Ahi2kuDA0NthT6aGb7fqkXLtagECysE+t8vGknGNKJ3OhT9acENe8bA5Bz+mAuie eNXoWLCUzHUKgR+Sn9j/ZMInqxZogkdcBN4lwSDkgKsrY/oxQ+wrxD0cZmwEiiv6SOKu iiWl3V7eDADvtuRjwJEGK+zaczk4Gn0kWG2+yjjZW7uYpA9BtiGZp8LwlrIlYoY6dl82 0uGw== X-Forwarded-Encrypted: i=1; AJvYcCW8WaIZQSo6kQNt17LrGJLUHZG8HN7y/EsPZQMEiJUyeumIsWaHluYDxitP3Uf1PFBmVXdV2b/Qh+CJoev5cVFoVOIaTuG9ptThCqkK X-Gm-Message-State: AOJu0YylN4Nxv5zqSDjTrqKBPLoYMngRO6FWjnQZkYrebf1J2DHH2mO1 7/jt8Ulasidk+H5KaI6zvXmJUMtulRMibIGdM8Mrvf1mEPfBYlqer04nhslY8qOXFw1/z/usU53 7ig== X-Received: by 2002:a05:6402:3788:b0:563:ccd1:26c0 with SMTP id et8-20020a056402378800b00563ccd126c0mr11749433edb.8.1708489847911; Tue, 20 Feb 2024 20:30:47 -0800 (PST) Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com. [209.85.221.46]) by smtp.gmail.com with ESMTPSA id c40-20020a509fab000000b005607f899175sm4508847edf.70.2024.02.20.20.30.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Feb 2024 20:30:47 -0800 (PST) Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-33d153254b7so3058196f8f.0 for ; Tue, 20 Feb 2024 20:30:47 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCX4yJrzdx3Pz9TBEHAi2oJmvjK+fp1SIpPNKq2GWzf9PHC8C1q9/VIsPz8SqT60FUmahejwBPc0p+Jgi3FzmXViQivzTyuOiFIlgxUk X-Received: by 2002:adf:ef8f:0:b0:33d:2775:1e63 with SMTP id d15-20020adfef8f000000b0033d27751e63mr9141684wro.41.1708489847044; Tue, 20 Feb 2024 20:30:47 -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-8-git-send-email-shengjiu.wang@nxp.com> <20240217104212.32f07e3a@coco.lan> In-Reply-To: <20240217104212.32f07e3a@coco.lan> From: Tomasz Figa Date: Wed, 21 Feb 2024 13:30:29 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v12 07/15] media: v4l2: Add audio capture and output support To: Mauro Carvalho Chehab Cc: Shengjiu Wang , hverkuil@xs4all.nl, sakari.ailus@iki.fi, m.szyprowski@samsung.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, shengjiu.wang@gmail.com, 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 Sat, Feb 17, 2024 at 6:42=E2=80=AFPM 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-mem= 2mem.rst > > > > diff --git a/Documentation/userspace-api/media/v4l/buffer.rst b/Documen= tation/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 =3D 0, > SNDRV_PCM_STREAM_CAPTURE, > SNDRV_PCM_STREAM_LAST =3D 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? > > + - Buffer for audio output, see :ref:`audio`. > > > > > > .. _buffer-flags: > > diff --git a/Documentation/userspace-api/media/v4l/dev-audio-mem2mem.rs= t 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 m= emory. > > +Such memory-to-memory devices set the ``V4L2_CAP_AUDIO_M2M`` capabilit= y. > > +Examples of memory-to-memory devices are audio codecs, audio preproces= sing, > > +audio postprocessing. > > + > > +A memory-to-memory audio node supports both output (sending audio fram= es from > > +memory to the hardware) and capture (receiving the processed audio fra= mes > > +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 t= o > > +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 acces= s. > > + > > +Audio memory-to-memory devices are accessed through character device > > +special files named ``/dev/v4l-audio`` > > + > > +Querying Capabilities > > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > + > > +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_QU= ERYCAP` > > +ioctl. > > + > > +Data Format Negotiation > > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > + > > +The audio device uses the :ref:`format` ioctls to select the capture f= ormat. > > +The audio buffer content format is bound to that selected format. In a= ddition > > +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-au= dio` > > 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 matc= h > 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. > 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