From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E35EC433ED for ; Mon, 19 Apr 2021 12:36:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8605461221 for ; Mon, 19 Apr 2021 12:36:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8605461221 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYT8L-0000eY-K6 for qemu-devel@archiver.kernel.org; Mon, 19 Apr 2021 08:36:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYT5i-0006h8-7s for qemu-devel@nongnu.org; Mon, 19 Apr 2021 08:33:26 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:45873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lYT5g-0003q6-0t for qemu-devel@nongnu.org; Mon, 19 Apr 2021 08:33:25 -0400 Received: by mail-pl1-x633.google.com with SMTP id p16so13650344plf.12 for ; Mon, 19 Apr 2021 05:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DEe6zdYgh7g283HFwY45ii6A2MPaobZVDaA+8dj7oNA=; b=cNbvxXt2mpRbTx7e3GjVg7o9VM/JGS35MAs2NNSOrJGbxseoSPtk7ckEz+YqRP4aWh rkGD2UbJHi7NQFgjKX92QtXChcQi7PaYKQDkW5zxyB57aIeAKRAclFR2VcvsFx9EnZYT RJn1FfY+jksBH/g9OFsRUZUA6F18GNmfyGtetcPJeqUGaxQXgWyDwCC7Hmk7ydUoIpG6 GmxMPxgh6ojT0Q0X5GPXQF6034971E6Hz25PuAi6Y2jvYZn5IOC6yQoDNsWACreFrlt2 wyVchL9Tb4gLtyhVzwqm5nhAAEllhN1EK4i6y3HXo/b5am5ml7j0wZ4eeju1EfvmU96G z5Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DEe6zdYgh7g283HFwY45ii6A2MPaobZVDaA+8dj7oNA=; b=q+3kJf72wXTHsfQSOc7bB4Y8jpZp4TZ1G/XszRgkD2CJ26+I9gdPFkg4dv1Dluy+cK WLvF8ky3FJsVPCXpBmdbmfLEnezg4oCf6b3eJZ4EDhgDG6RcTqbJCSXUNKKeOX/bxIQy HqTZkdYZHfmi49z5+SsINNvDyIsAfh9bt+es0E9wY55r0rmhur+xNBFRk+9qDpi47ztg CBLACxGLUGieImz2pI/vu4rKvaFGtg7xULmSYr/SV7TIcQ/YQVRgUUSVtIMF8vCnLDbh 0y9vfd206xx6YJg3a++slKW+PFWyCT6p3QzU/03APOWYzsyjYI6mkvfr5J6q0N3L63h5 1FUA== X-Gm-Message-State: AOAM532dCVIRoQrY4C+u0x4/Q+tTy5I+T4/yWbY01Bg1rBrbRpi0RAfh OEsMgFJmEdyk+rrFFFmWgDFdGLXUtxwbkv0kB28= X-Google-Smtp-Source: ABdhPJzyR1QNhb54MAvrwd8J9vdmmzibYms+3z8p+eg+wlyYTojBLBge6as6b7Fhg+xA6JPQNxnSQmB6+8h0aUsfxTQ= X-Received: by 2002:a17:90a:20b:: with SMTP id c11mr25137510pjc.183.1618835602511; Mon, 19 Apr 2021 05:33:22 -0700 (PDT) MIME-Version: 1.0 References: <87v9blmf1x.fsf@linaro.org> <20210128112541.qjpve3qbjy46ofkk@sirius.home.kraxel.org> <20210128163001.jjptft2t5fbdlvyn@sirius.home.kraxel.org> <20210215143934.sz6tdtoaaffkvla7@sirius.home.kraxel.org> <20210416113252.km4w72vnruv6s2oi@sirius.home.kraxel.org> In-Reply-To: From: Shreyansh Chouhan Date: Mon, 19 Apr 2021 18:03:11 +0530 Message-ID: Subject: Re: Fwd: VirtioSound device emulation implementation To: Gerd Hoffmann Content-Type: multipart/alternative; boundary="000000000000099abe05c0528942" Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=chouhan.shreyansh2702@gmail.com; helo=mail-pl1-x633.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?B?QWxleCBCZW5uw6ll?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --000000000000099abe05c0528942 Content-Type: text/plain; charset="UTF-8" On Mon, 19 Apr 2021 at 18:00, Shreyansh Chouhan < chouhan.shreyansh2702@gmail.com> wrote: > > On Fri, 16 Apr 2021 at 17:02, Gerd Hoffmann wrote: > >> Hi, >> >> > I learned that the callback passed in AUD_open_out, (lets call it the >> write >> > audio callback,) is supposed to mix and write the >> > buffers to HWVoiceOut. I have written that, the basic algorithm being: >> > >> > 1. Pop element from tx virtqueue. >> > 2. Get the xfer header from the elem->out_sg (iov_to_buf(elem->out_sg, >> 1, >> > 0, &hdr, sizeof(hdr))) >> > 3. Get the buffer from elem->out_sg (iov_to_buf(elem->out_sg, 1, >> > sizeof(hdr), &mixbuf, period_bytes)) >> > 4. AUD_write the buffer >> >> AUD_write returns the number of bytes actually accepted. >> >> In case the audio backend consumed the complete buffer you can go ahead >> as described. Otherwise stop here and resume (try AUD_write() the >> remaining data) when the callback is called again. >> > The callback that is supposed to write the buffers to HWVoiceOut has to > do it such that it only writes the buffers for the streams that it was > called by. The tx > virtqueue is going to have buffers for all the streams. How do I handle > this situation? > > Say, I have 3 output streams 0, 1 and 2, the callback was called on stream > 0, how do > I only play buffers corresponding to this stream? Is there a way by which > I could iterate over > the virtqeueue? > > If not then I should probably store the VirtQueueElements corresponding to > a specific stream > in the stream itself. I have to store the elements because I'd have to > write to the response and > mark these elements as used, (via virtqueue_push i think.) > > Also, is virtqueue a 'queue'? I remember reading in the specs that the > device can consume > the buffers in any order it prefers unless a feature bit is negotiated. So > does virtqueue_pop > always return the first element that entered the queue? (FIFO?) > > If it is FIFO, then I think the only way would be to iterate over the > virtqueue. However if `virtqueu_pop` > does return the last inserted element, I can use `handle_tx` > to get the last element inserted and then add it to the corresponding stream. Sorry for the incomplete mail. I don't know how I hit send. > > >> No problem. I'm likewise busy or on (easter) vacation at times and fail >> to send timely answers (sorry for that). >> > Also that's fine, I just got a bit worried :) I think once this `tx` part is done I'll have the pcm streams ready, and I can send in patches by tonight or tomorrow evening latest. > >> HTH & take care, >> Gerd >> >> --000000000000099abe05c0528942 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Mon, 19 Apr 2021 at 18:00, Shreyan= sh Chouhan <chouhan.s= hreyansh2702@gmail.com> wrote:

On Fri, 16 Apr 2021 at 17:02, Gerd Hoffman= n <kraxel@redhat.= com> wrote:
=C2=A0 Hi,

> I learned that the callback passed in AUD_open_out, (lets call it the = write
> audio callback,)=C2=A0 is supposed to mix and write the
> buffers to HWVoiceOut. I have written that, the basic algorithm being:=
>
> 1. Pop element from tx virtqueue.
> 2. Get the xfer header from the elem->out_sg (iov_to_buf(elem->o= ut_sg, 1,
> 0, &hdr, sizeof(hdr)))
> 3. Get the buffer from elem->out_sg (iov_to_buf(elem->out_sg, 1,=
> sizeof(hdr), &mixbuf, period_bytes))
> 4. AUD_write the buffer

AUD_write returns the number of bytes actually accepted.

In case the audio backend consumed the complete buffer you can go ahead
as described.=C2=A0 Otherwise stop here and resume (try AUD_write() the
remaining data) when the callback is called again.
The= callback that is supposed to write the buffers to HWVoiceOut has to
<= div>do it such that it only writes the buffers for the streams that it was = called by. The tx
virtqueue is going to have buffers for all the = streams. How do I handle this situation?

Say, I have 3 ou= tput streams 0, 1 and 2, the callback was called on stream 0, how do
<= div>I only play buffers corresponding to this stream? Is there a way by whi= ch I could iterate over
the virtqeueue?

=
If not then I should probably store the VirtQueueElements correspondin= g to a specific stream
in the stream itself. I have to store the = elements because I'd have to write to the response and
mark t= hese elements as used, (via virtqueue_push i think.)

Also, is virtqueue a 'queue'? I remember reading in the spe= cs that the device can consume
the buffers in any order it prefer= s unless a feature bit is negotiated. So does virtqueue_pop
alway= s return the first element that entered the queue? (FIFO?)
<= br>
If it is FIFO, then I think the only way would be to iterate = over the virtqueue. However if `virtqueu_pop`
does return the las= t inserted element, I can use `handle_tx`
to get the last element inserted and then add it to the corresponding= stream.

Sorry for the incomplete mail. I don'= t know how I hit send.


No problem.=C2=A0 I'm likewise busy or on (easter) vacation at times an= d fail
to send timely answers (sorry for that).
Also that's fine, I just got a bit worried :)
I think once this `tx` part is done I'll have the pcm strea= ms ready, and I can send in patches by tonight
or tomorrow evenin= g latest.

HTH & take care,
=C2=A0 Gerd

--000000000000099abe05c0528942--