From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "David Hildenbrand" <david@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Kashyap Chamarthy" <kchamart@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Eric Auger" <eric.auger@redhat.com>,
"Christian Schoenebeck" <qemu_oss@crudebyte.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eric Blake" <eblake@redhat.com>,
"Volker Rümelin" <vr_qemu@t-online.de>
Subject: [PULL 05/26] audio: add more audio rate control functions
Date: Thu, 13 Oct 2022 08:52:03 +0200 [thread overview]
Message-ID: <20221013065224.1864145-6-kraxel@redhat.com> (raw)
In-Reply-To: <20221013065224.1864145-1-kraxel@redhat.com>
From: Volker Rümelin <vr_qemu@t-online.de>
The next patch needs two new rate control functions. The first
one returns the bytes needed at call time to maintain the
selected rate. The second one adjusts the bytes actually sent.
Split the audio_rate_get_bytes() function into these two
functions and reintroduce audio_rate_get_bytes().
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20220923183640.8314-5-vr_qemu@t-online.de>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
audio/audio_int.h | 2 ++
audio/audio.c | 35 ++++++++++++++++++++++++-----------
2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/audio/audio_int.h b/audio/audio_int.h
index 2a6914d2aa65..97e20e842927 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -263,6 +263,8 @@ typedef struct RateCtl {
} RateCtl;
void audio_rate_start(RateCtl *rate);
+size_t audio_rate_peek_bytes(RateCtl *rate, struct audio_pcm_info *info);
+void audio_rate_add_bytes(RateCtl *rate, size_t bytes_used);
size_t audio_rate_get_bytes(struct audio_pcm_info *info, RateCtl *rate,
size_t bytes_avail);
diff --git a/audio/audio.c b/audio/audio.c
index 567f953e66f9..61cdd73df5aa 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -2251,26 +2251,39 @@ void audio_rate_start(RateCtl *rate)
rate->start_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
}
-size_t audio_rate_get_bytes(struct audio_pcm_info *info, RateCtl *rate,
- size_t bytes_avail)
+size_t audio_rate_peek_bytes(RateCtl *rate, struct audio_pcm_info *info)
{
int64_t now;
int64_t ticks;
int64_t bytes;
- int64_t samples;
- size_t ret;
+ int64_t frames;
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
ticks = now - rate->start_ticks;
bytes = muldiv64(ticks, info->bytes_per_second, NANOSECONDS_PER_SECOND);
- samples = (bytes - rate->bytes_sent) / info->bytes_per_frame;
- if (samples < 0 || samples > 65536) {
- AUD_log(NULL, "Resetting rate control (%" PRId64 " samples)\n", samples);
+ frames = (bytes - rate->bytes_sent) / info->bytes_per_frame;
+ if (frames < 0 || frames > 65536) {
+ AUD_log(NULL, "Resetting rate control (%" PRId64 " frames)\n", frames);
audio_rate_start(rate);
- samples = 0;
+ frames = 0;
}
- ret = MIN(samples * info->bytes_per_frame, bytes_avail);
- rate->bytes_sent += ret;
- return ret;
+ return frames * info->bytes_per_frame;
+}
+
+void audio_rate_add_bytes(RateCtl *rate, size_t bytes_used)
+{
+ rate->bytes_sent += bytes_used;
+}
+
+size_t audio_rate_get_bytes(struct audio_pcm_info *info, RateCtl *rate,
+ size_t bytes_avail)
+{
+ size_t bytes;
+
+ bytes = audio_rate_peek_bytes(rate, info);
+ bytes = MIN(bytes, bytes_avail);
+ audio_rate_add_bytes(rate, bytes);
+
+ return bytes;
}
--
2.37.3
next prev parent reply other threads:[~2022-10-13 7:24 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-13 6:51 [PULL 00/26] Kraxel 20221013 patches Gerd Hoffmann
2022-10-13 6:51 ` [PULL 01/26] audio: refactor code in audio_run_out() Gerd Hoffmann
2022-10-13 6:52 ` [PULL 02/26] audio: fix GUS audio playback with out.mixing-engine=off Gerd Hoffmann
2022-10-13 6:52 ` [PULL 03/26] audio: run downstream playback queue unconditionally Gerd Hoffmann
2022-10-13 6:52 ` [PULL 04/26] alsaaudio: reduce playback latency Gerd Hoffmann
2022-10-13 6:52 ` Gerd Hoffmann [this message]
2022-10-13 6:52 ` [PULL 06/26] spiceaudio: add a pcm_ops buffer_get_free function Gerd Hoffmann
2022-10-13 6:52 ` [PULL 07/26] spiceaudio: update comment Gerd Hoffmann
2022-10-13 6:52 ` [PULL 08/26] audio: swap audio_rate_get_bytes() function parameters Gerd Hoffmann
2022-10-13 6:52 ` [PULL 09/26] audio: rename audio_sw_bytes_free() Gerd Hoffmann
2022-10-13 6:52 ` [PULL 10/26] audio: refactor audio_get_avail() Gerd Hoffmann
2022-10-13 6:52 ` [PULL 11/26] audio: fix sw->buf size for audio recording Gerd Hoffmann
2022-10-13 6:52 ` [PULL 12/26] audio: prevent an integer overflow in resampling code Gerd Hoffmann
2022-10-13 6:52 ` [PULL 13/26] ui/vnc-clipboard: fix integer underflow in vnc_client_cut_text_ext Gerd Hoffmann
2022-10-13 6:52 ` [PULL 14/26] ui/gtk-egl: egl context needs to be unbound in the end of gd_egl_switch Gerd Hoffmann
2022-10-13 6:52 ` [PULL 15/26] cirrus_vga: fix potential memory overflow Gerd Hoffmann
2022-10-13 6:52 ` [PULL 16/26] docs: add firmware feature flags Gerd Hoffmann
2022-10-13 6:52 ` [PULL 17/26] pci-ids: drop PCI_DEVICE_ID_VIRTIO_IOMMU Gerd Hoffmann
2022-10-13 6:52 ` [PULL 18/26] pci-ids: drop PCI_DEVICE_ID_VIRTIO_MEM Gerd Hoffmann
2022-10-13 6:52 ` [PULL 19/26] pci-ids: drop PCI_DEVICE_ID_VIRTIO_PMEM Gerd Hoffmann
2022-10-13 6:52 ` [PULL 20/26] pci-ids: drop list of modern virtio devices Gerd Hoffmann
2022-10-13 6:52 ` [PULL 21/26] pci-ids: document modern virtio-pci ids in pci.h too Gerd Hoffmann
2022-10-13 6:52 ` [PULL 22/26] ui/gtk: Fix the implicit mouse ungrabbing logic Gerd Hoffmann
2022-10-13 6:52 ` [PULL 23/26] qemu-edid: Restrict input parameter -d to avoid division by zero Gerd Hoffmann
2022-10-13 6:52 ` [PULL 24/26] gtk: Add show_menubar=on|off command line option Gerd Hoffmann
2022-10-13 6:52 ` [PULL 25/26] audio: fix in.voices test Gerd Hoffmann
2022-10-13 6:52 ` [PULL 26/26] audio: improve out.voices test Gerd Hoffmann
2022-10-13 20:29 ` [PULL 00/26] Kraxel 20221013 patches Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221013065224.1864145-6-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=david@redhat.com \
--cc=eblake@redhat.com \
--cc=eric.auger@redhat.com \
--cc=f4bug@amsat.org \
--cc=kchamart@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu_oss@crudebyte.com \
--cc=vr_qemu@t-online.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).