From patchwork Thu Feb 28 10:08:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 1049353 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4497b33gkzz9s5c for ; Thu, 28 Feb 2019 21:10:04 +1100 (AEDT) Received: from localhost ([127.0.0.1]:35431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzIdc-00031l-TB for incoming@patchwork.ozlabs.org; Thu, 28 Feb 2019 05:10:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52938) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzIcm-00031S-L5 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 05:09:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzIck-0000wa-Pr for qemu-devel@nongnu.org; Thu, 28 Feb 2019 05:09:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45052) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gzIck-0000u9-DR for qemu-devel@nongnu.org; Thu, 28 Feb 2019 05:09:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F2279D1F8 for ; Thu, 28 Feb 2019 10:09:03 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-248.ams2.redhat.com [10.36.117.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB4C360BE0; Thu, 28 Feb 2019 10:09:02 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id AEC5517510; Thu, 28 Feb 2019 11:08:58 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 28 Feb 2019 11:08:58 +0100 Message-Id: <20190228100858.28397-6-kraxel@redhat.com> In-Reply-To: <20190228100858.28397-1-kraxel@redhat.com> References: <20190228100858.28397-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 28 Feb 2019 10:09:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/5] audio/sdlaudio: Simplify the sdl_callback function 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: Thomas Huth , Gerd Hoffmann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Thomas Huth At the end of the while-loop, either "samples" or "sdl->live" is zero, so now that we've removed the semaphore code, the content of the while-loop is always only executed once. Thus we can remove the while-loop now to get rid of one indentation level here. Signed-off-by: Thomas Huth Message-id: 1549336101-17623-3-git-send-email-thuth@redhat.com Signed-off-by: Gerd Hoffmann --- audio/sdlaudio.c | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c index 53bfdbf72439..f7ee70b15347 100644 --- a/audio/sdlaudio.c +++ b/audio/sdlaudio.c @@ -189,37 +189,30 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len) SDLAudioState *s = &glob_sdl; HWVoiceOut *hw = &sdl->hw; int samples = len >> hw->info.shift; + int to_mix, decr; - if (s->exit) { + if (s->exit || !sdl->live) { return; } - while (samples) { - int to_mix, decr; - - /* dolog ("in callback samples=%d\n", samples); */ - - if (s->exit || !sdl->live) { - break; - } - - /* dolog ("in callback live=%d\n", live); */ - to_mix = audio_MIN (samples, sdl->live); - decr = to_mix; - while (to_mix) { - int chunk = audio_MIN (to_mix, hw->samples - hw->rpos); - struct st_sample *src = hw->mix_buf + hw->rpos; - - /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */ - hw->clip (buf, src, chunk); - hw->rpos = (hw->rpos + chunk) % hw->samples; - to_mix -= chunk; - buf += chunk << hw->info.shift; - } - samples -= decr; - sdl->live -= decr; - sdl->decr += decr; + /* dolog ("in callback samples=%d live=%d\n", samples, sdl->live); */ + + to_mix = audio_MIN(samples, sdl->live); + decr = to_mix; + while (to_mix) { + int chunk = audio_MIN(to_mix, hw->samples - hw->rpos); + struct st_sample *src = hw->mix_buf + hw->rpos; + + /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */ + hw->clip(buf, src, chunk); + hw->rpos = (hw->rpos + chunk) % hw->samples; + to_mix -= chunk; + buf += chunk << hw->info.shift; } + samples -= decr; + sdl->live -= decr; + sdl->decr += decr; + /* dolog ("done len=%d\n", len); */ /* SDL2 does not clear the remaining buffer for us, so do it on our own */