From nobody Fri Nov 7 03:57:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1545599196422313.94025197527174; Sun, 23 Dec 2018 13:06:36 -0800 (PST) Received: from localhost ([127.0.0.1]:59744 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbAxH-0000dH-1N for importer@patchew.org; Sun, 23 Dec 2018 16:06:35 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbAkA-0008B0-8K for qemu-devel@nongnu.org; Sun, 23 Dec 2018 15:53:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbAk9-0003Ei-3M for qemu-devel@nongnu.org; Sun, 23 Dec 2018 15:53:02 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:54758) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gbAk8-000376-Sz for qemu-devel@nongnu.org; Sun, 23 Dec 2018 15:53:01 -0500 Received: by mail-wm1-x342.google.com with SMTP id a62so9861848wmh.4 for ; Sun, 23 Dec 2018 12:52:59 -0800 (PST) Received: from nullptr.home.dirty-ice.org (2a01-036c-0113-24a3-0000-0000-0000-0005.pool6.digikabel.hu. [2a01:36c:113:24a3::5]) by smtp.gmail.com with ESMTPSA id g198sm25456920wmd.23.2018.12.23.12.52.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Dec 2018 12:52:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ft3EHNJylWfz7qh/YSL81ihyTJc8DQwGj3ZZ2/uBCGQ=; b=eU1uiGAvj0igtY0s9qqPRHnigD87DafQ5y3i19ioZa4YNgNrzIJKecVgOo4eMs9Nwt w6/d1Mm9dXCffmA+xtBo54wAB8pTVZowrjAgoliy8NXL9ircFu4wphmLj46wb9aCsVXN /wQvab490VKUzGQ0YFRlBnHteMTRodzZq3OBQyzQ644aptfBpEu10x4i2sX0Jc0zCJ5H eQ/n/a4o7tlYTjRPJOG56dhT0NV/799zk6L1vKzLVxYXxGZ36QrKfa+so5tWDo+dqtLU ViM0lCEtq4w4ZOdKB07/XEdbFU2Mn6Ifd96fNDnCpOjNqGZt+4XqD2FiCe7GTt+lMzgx t8dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ft3EHNJylWfz7qh/YSL81ihyTJc8DQwGj3ZZ2/uBCGQ=; b=GQhJeI5ae2eChNGRGqzohAO3gg07C8GyjAQAM4L5+3yqKtBGgAdp2ZSEzW0t9SmM0E D/9S7prvYYg/Cl3p6uH3KXEXTTLiepTQh9p43iKqhYSy6ZIJc1GgJkYmA43W2REyOVrA F1ftfHB0LYFxNbz0G7CGvoAlxXxjLHQ74f2Oc+sPkxmoj/6pcaXcPvbHVafrXck2gtPH j4Orm3NAVuW7LS4SbSyDrm0Q2G6ANBuAyoWaxVxDfKwnf/TmXdMh6LQjQUGZTEnDs8qr V/C3WXuUJeRVbUGC3sySxitI4wbIZPSq/7B1V0+21pdhgsLFwDG0GxV40ITCwXLIcVUs T0Tw== X-Gm-Message-State: AA+aEWYy9v3GIASrFeGlw8F912GF7XNIZFNaVi+9ehywylWO1CzpATJk 2Fk+HTDvuJmtIPNCYkGOz1iOKiy1ekc= X-Google-Smtp-Source: ALg8bN7fcNZj+tRyzPXpFBpwWSmsXrb55YzgA+GzsMkHeVhsdTrRZSYIFLpijF+yLkVADwr6eTi30g== X-Received: by 2002:a1c:b456:: with SMTP id d83mr10563643wmf.115.1545598378631; Sun, 23 Dec 2018 12:52:58 -0800 (PST) From: "=?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?=" X-Google-Original-From: =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= To: qemu-devel@nongnu.org Date: Sun, 23 Dec 2018 21:52:11 +0100 Message-Id: <8b28b74150934d42fef0b2e4b9d19b60700a686e.1545598229.git.DirtY.iCE.hu@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 Subject: [Qemu-devel] [PATCH v2 35/52] sdlaudio: port to the new audio backend api X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) SDL2 is still a big mess, but it's probably not worse than the current version. Signed-off-by: K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n --- audio/sdlaudio.c | 136 +++++++++++++++++------------------------------ 1 file changed, 50 insertions(+), 86 deletions(-) diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c index 92da4804c6..685cbc83b8 100644 --- a/audio/sdlaudio.c +++ b/audio/sdlaudio.c @@ -42,11 +42,6 @@ =20 typedef struct SDLVoiceOut { HWVoiceOut hw; - int live; -#if USE_SEMAPHORE - int rpos; -#endif - int decr; } SDLVoiceOut; =20 static struct SDLAudioState { @@ -252,17 +247,13 @@ static void sdl_callback (void *opaque, Uint8 *buf, i= nt len) SDLVoiceOut *sdl =3D opaque; SDLAudioState *s =3D &glob_sdl; HWVoiceOut *hw =3D &sdl->hw; - int samples =3D len >> hw->info.shift; =20 if (s->exit) { return; } =20 - while (samples) { - int to_mix, decr; - - /* dolog ("in callback samples=3D%d\n", samples); */ #if USE_SEMAPHORE + while (len) { sdl_wait (s, "sdl_callback"); if (s->exit) { return; @@ -271,95 +262,66 @@ static void sdl_callback (void *opaque, Uint8 *buf, i= nt len) if (sdl_lock (s, "sdl_callback")) { return; } - - if (audio_bug(__func__, sdl->live < 0 || sdl->live > hw->samples))= { - dolog("sdl->live=3D%d hw->samples=3D%zu\n", sdl->live, hw->sam= ples); - return; - } - - if (!sdl->live) { - goto again; - } -#else - if (s->exit || !sdl->live) { - break; - } #endif =20 - /* dolog ("in callback live=3D%d\n", live); */ - to_mix =3D MIN (samples, sdl->live); - decr =3D to_mix; - while (to_mix) { - int chunk =3D MIN (to_mix, hw->samples - hw->rpos); - struct st_sample *src =3D hw->mix_buf + hw->rpos; + while (hw->pending_emul && len) { + size_t write_len; + ssize_t start =3D ((ssize_t) hw->pos_emul) - hw->pending_emul; + if (start < 0) { + start +=3D hw->size_emul; + } + assert(start >=3D 0 && start < hw->size_emul); =20 - /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk);= */ - hw->clip (buf, src, chunk); -#if USE_SEMAPHORE - sdl->rpos =3D (sdl->rpos + chunk) % hw->samples; -#else - hw->rpos =3D (hw->rpos + chunk) % hw->samples; -#endif - to_mix -=3D chunk; - buf +=3D chunk << hw->info.shift; + write_len =3D MIN(MIN(hw->pending_emul, len), + hw->size_emul - start); + + memcpy(buf, hw->buf_emul + start, write_len); + hw->pending_emul -=3D write_len; + len -=3D write_len; + buf +=3D write_len; } - samples -=3D decr; - sdl->live -=3D decr; - sdl->decr +=3D decr; =20 #if USE_SEMAPHORE - again: if (sdl_unlock (s, "sdl_callback")) { return; } -#endif } - /* dolog ("done len=3D%d\n", len); */ - -#if (SDL_MAJOR_VERSION >=3D 2) - /* SDL2 does not clear the remaining buffer for us, so do it on our ow= n */ - if (samples) { - memset(buf, 0, samples << hw->info.shift); - } -#endif -} - -static int sdl_run_out (HWVoiceOut *hw, int live) -{ - int decr; - SDLVoiceOut *sdl =3D (SDLVoiceOut *) hw; - SDLAudioState *s =3D &glob_sdl; - - if (sdl_lock (s, "sdl_run_out")) { - return 0; - } - - if (sdl->decr > live) { - ldebug ("sdl->decr %d live %d sdl->live %d\n", - sdl->decr, - live, - sdl->live); - } - - decr =3D MIN (sdl->decr, live); - sdl->decr -=3D decr; - -#if USE_SEMAPHORE - sdl->live =3D live - decr; - hw->rpos =3D sdl->rpos; #else - sdl->live =3D live; + /* clear remaining buffer that we couldn't fill with data */ + if (len) { + memset(buf, 0, len); + } #endif - - if (sdl->live > 0) { - sdl_unlock_and_post (s, "sdl_run_out"); - } - else { - sdl_unlock (s, "sdl_run_out"); - } - return decr; } =20 +#define SDL_WRAPPER_FUNC(name, ret_type, args_decl, args, fail, unlock) \ + static ret_type glue(sdl_, name)args_decl \ + { \ + SDLAudioState *s =3D &glob_sdl; \ + ret_type ret; \ + \ + if (sdl_lock(s, "sdl_" #name)) { \ + fail; \ + return 0; /* implicitly casts to NULL */ \ + } \ + \ + ret =3D glue(audio_generic_, name)args; \ + \ + unlock(s, "sdl_" #name); \ + return ret; \ + } + +SDL_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size), + (hw, size), *size =3D 0, sdl_unlock) +SDL_WRAPPER_FUNC(put_buffer_out_nowrite, size_t, + (HWVoiceOut *hw, void *buf, size_t size), (hw, buf, size), + /*nothing*/, sdl_unlock_and_post) +SDL_WRAPPER_FUNC(write, size_t, + (HWVoiceOut *hw, void *buf, size_t size), (hw, buf, size), + /* nothing */, sdl_unlock_and_post) + +#undef SDL_WRAPPER_FUNC + static void sdl_fini_out (HWVoiceOut *hw) { (void) hw; @@ -476,7 +438,9 @@ static void sdl_audio_fini (void *opaque) static struct audio_pcm_ops sdl_pcm_ops =3D { .init_out =3D sdl_init_out, .fini_out =3D sdl_fini_out, - .run_out =3D sdl_run_out, + .write =3D sdl_write, + .get_buffer_out =3D sdl_get_buffer_out, + .put_buffer_out =3D sdl_put_buffer_out_nowrite, .ctl_out =3D sdl_ctl_out, }; =20 --=20 2.20.1