From patchwork Fri Aug 21 15:37:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= X-Patchwork-Id: 509567 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5EFA1140773 for ; Sat, 22 Aug 2015 02:03:07 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=oD/C3a/T; dkim-atps=neutral Received: from localhost ([::1]:42344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSomX-0005uJ-71 for incoming@patchwork.ozlabs.org; Fri, 21 Aug 2015 12:03:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSoOV-0002ub-0d for qemu-devel@nongnu.org; Fri, 21 Aug 2015 11:38:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZSoOT-0002DZ-Ou for qemu-devel@nongnu.org; Fri, 21 Aug 2015 11:38:14 -0400 Received: from mail-wi0-x22c.google.com ([2a00:1450:400c:c05::22c]:33829) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSoOT-0002DM-Ez for qemu-devel@nongnu.org; Fri, 21 Aug 2015 11:38:13 -0400 Received: by wicne3 with SMTP id ne3so23102024wic.1 for ; Fri, 21 Aug 2015 08:38:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=weurOWbpisF6zKTZVuI8gyw1G3TVuEFnmY+pB9y10QA=; b=oD/C3a/T5PT35s3bNloqVd8AyMwZ1tBQ4YpgvCLILCw3l4Ql7S5jHTescdat4fMZa+ woeN/fHxodyCnUlm1tmAbm6V+QJG4ElmvlO3ZsVq6j7ETXR38r9blTz8dz2Gdc+0oCbx FHCgcC8xRbKVWboLY/jneTd/p6+vcoIUYdaYQ80nkdcZCR+3udj0mCeJs32yaZcBX/Vp AezfR00GRv40ESUl2YGSLVZZgUwC3kRAqFQ7G/d+OGy7Hampt99NhUUwsGguvtJ7gfif Z2ttAJzmxaV/kNYFncIOpTnlPseKVvVJ0LcJZyu74KgjZlI3mT6l9zCH3mSDPiY0ggtV W5/w== X-Received: by 10.180.11.194 with SMTP id s2mr6584551wib.33.1440171492920; Fri, 21 Aug 2015 08:38:12 -0700 (PDT) Received: from nullptr.home.dirty-ice.org (178-164-172-216.pool.digikabel.hu. [178.164.172.216]) by smtp.gmail.com with ESMTPSA id v8sm10479895wjr.15.2015.08.21.08.38.12 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 21 Aug 2015 08:38:12 -0700 (PDT) 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: Fri, 21 Aug 2015 17:37:38 +0200 Message-Id: <86c8e5761707fdfaa42e8166bb0257c7fe4416ea.1440171025.git.DirtY.iCE.hu@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22c Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH v2 42/49] sdlaudio: port to the new audio backend api X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Kővágó, Zoltán --- audio/sdlaudio.c | 102 ++++++++++++++++++++++--------------------------------- 1 file changed, 41 insertions(+), 61 deletions(-) diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c index 26538c8..183ecdd 100644 --- a/audio/sdlaudio.c +++ b/audio/sdlaudio.c @@ -39,9 +39,6 @@ typedef struct SDLVoiceOut { HWVoiceOut hw; - int live; - int rpos; - int decr; } SDLVoiceOut; static struct SDLAudioState { @@ -230,16 +227,12 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len) SDLVoiceOut *sdl = opaque; SDLAudioState *s = &glob_sdl; HWVoiceOut *hw = &sdl->hw; - int samples = len >> hw->info.shift; if (s->exit) { return; } - while (samples) { - int to_mix, decr; - - /* dolog ("in callback samples=%d\n", samples); */ + while (len) { sdl_wait (s, "sdl_callback"); if (s->exit) { return; @@ -249,34 +242,23 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len) return; } - if (audio_bug (AUDIO_FUNC, sdl->live < 0 || sdl->live > hw->samples)) { - dolog("sdl->live=%d hw->samples=%zu\n", - sdl->live, hw->samples); - return; - } - - if (!sdl->live) { - goto again; - } + while (hw->pending_emul && len) { + size_t write_len; + ssize_t start = ((ssize_t) hw->pos_emul) - hw->pending_emul; + if (start < 0) { + start += hw->size_emul; + } + assert(start >= 0 && start < hw->size_emul); - /* dolog ("in callback live=%d\n", live); */ - to_mix = MIN (samples, sdl->live); - decr = to_mix; - while (to_mix) { - int chunk = MIN (to_mix, hw->samples - hw->rpos); - struct st_sample *src = hw->mix_buf + hw->rpos; + write_len = MIN(MIN(hw->pending_emul, len), + hw->size_emul - start); - /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */ - hw->clip (buf, src, chunk); - sdl->rpos = (sdl->rpos + chunk) % hw->samples; - to_mix -= chunk; - buf += chunk << hw->info.shift; + memcpy(buf, hw->buf_emul + start, write_len); + hw->pending_emul -= write_len; + len -= write_len; + buf += write_len; } - samples -= decr; - sdl->live -= decr; - sdl->decr += decr; - again: if (sdl_unlock (s, "sdl_callback")) { return; } @@ -284,37 +266,33 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len) /* dolog ("done len=%d\n", len); */ } -static int sdl_run_out (HWVoiceOut *hw, int live) -{ - int decr; - SDLVoiceOut *sdl = (SDLVoiceOut *) hw; - SDLAudioState *s = &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); +#define SDL_WRAPPER_FUNC(name, ret_type, args_decl, args, fail, unlock) \ + static ret_type glue(sdl_, name)args_decl \ + { \ + SDLAudioState *s = &glob_sdl; \ + ret_type ret; \ + \ + if (sdl_lock(s, "sdl_" #name)) { \ + fail; \ + return 0; /* implicitly casts to NULL */ \ + } \ + \ + ret = glue(audio_generic_, name)args; \ + \ + unlock(s, "sdl_" #name); \ + return ret; \ } - decr = MIN (sdl->decr, live); - sdl->decr -= decr; +SDL_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size), + (hw, size), *size = 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) - sdl->live = live - decr; - hw->rpos = sdl->rpos; - - if (sdl->live > 0) { - sdl_unlock_and_post (s, "sdl_run_out"); - } - else { - sdl_unlock (s, "sdl_run_out"); - } - return decr; -} +#undef SDL_WRAPPER_FUNC static void sdl_fini_out (HWVoiceOut *hw) { @@ -428,7 +406,9 @@ static void sdl_audio_fini (void *opaque) static struct audio_pcm_ops sdl_pcm_ops = { .init_out = sdl_init_out, .fini_out = sdl_fini_out, - .run_out = sdl_run_out, + .write = sdl_write, + .get_buffer_out = sdl_get_buffer_out, + .put_buffer_out = sdl_put_buffer_out_nowrite, .ctl_out = sdl_ctl_out, };