From patchwork Thu Jan 14 13:45:47 2016 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: 567456 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 0A24514032F for ; Fri, 15 Jan 2016 00:59:28 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=IBQekjjF; dkim-atps=neutral Received: from localhost ([::1]:42639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJiQv-00063s-KP for incoming@patchwork.ozlabs.org; Thu, 14 Jan 2016 08:59:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJiEY-0001bq-7y for qemu-devel@nongnu.org; Thu, 14 Jan 2016 08:46:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJiEX-0003Wy-7d for qemu-devel@nongnu.org; Thu, 14 Jan 2016 08:46:38 -0500 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36630) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJiEW-0003Wm-Vw for qemu-devel@nongnu.org; Thu, 14 Jan 2016 08:46:37 -0500 Received: by mail-wm0-x244.google.com with SMTP id l65so43662512wmf.3 for ; Thu, 14 Jan 2016 05:46:36 -0800 (PST) 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=3jUV8DS9bAhDFCKxj+mMraHVDAbMvLR+eUES5d02f90=; b=IBQekjjFAgT2NNJK2g/sZwuNMG1B6OTINc5enum8yQwkx8ONepPJZ0LvOgZLOFMxBf anb0kOrfPRGXOcAib7W9MNZzS74g8oTPSznRa56oz8v0gf5o8rx7Ir2KBzqa/x2uHAL/ RadYz38/k90HjXRTlfCFUmel6NIU9RkVOBLEKFHmv66lyZ3rvg5LymisbFL4IFNuhgp6 1kGHOwH/H9m6g+oGudTn7h0KynBTFbuaMDrHCdNWnYl7cx27YUR3fGRZZ3Sa6U6sSqZc YOSGK2izvCZItfJVpvcnfzv5MuBG2QEhhMv6fvpMQ6zCBkdQsl6tTx1pRsgIikkeyj95 h8lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=3jUV8DS9bAhDFCKxj+mMraHVDAbMvLR+eUES5d02f90=; b=H4otojolYwTY+rGGE7+5pmk4hbqJejlxjTDstqLroA2mVmjltnuw30JUDmN4Kwu211 HeZwIKoUCNn6H9xDGFHZIbxE5QzYNg4E7FelWxwEbxg22kTdLuA6p7Aoc08mcNF7Fy/j cKKAR/BYQaKgDtzpG96Uj8Cr2rqV8yq3HiEm2V0l0AErVA4TPgs4LdcmD6HM+KYYVVea SDXUSn1SlGjH0FgKywIEzr+I8Gh//GLOgdsg+zRgCMQVYnYSKu+i8Nnu7vmgh0wbTaJ8 Yjj/3Ca7MpLoD8AGPT+t2+vDsqlvBv8oH3mlAzdTqICRzAIYW84E5eRSLByOYAhq2jI9 Cxag== X-Gm-Message-State: ALoCoQlFNC6IYZ4MiEP5UzrqZEPZ6/HxDlrDsW8qqazAU3LesQgbOGrp4/X/2Yj5I9Iff2Cp9R8wKLFNDHtXWuEQ3i8IuPJO0A== X-Received: by 10.28.153.3 with SMTP id b3mr5248735wme.7.1452779196471; Thu, 14 Jan 2016 05:46:36 -0800 (PST) Received: from nullptr.home.dirty-ice.org (188-143-126-18.pool.digikabel.hu. [188.143.126.18]) by smtp.gmail.com with ESMTPSA id 79sm7398061wmo.7.2016.01.14.05.46.35 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 14 Jan 2016 05:46:36 -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: Thu, 14 Jan 2016 14:45:47 +0100 Message-Id: <1a86a5c942d91a03d3389cdd1539191d4e341b3b.1452776884.git.DirtY.iCE.hu@gmail.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 34/51] 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, };