From patchwork Sun Jan 12 19:06:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1221856 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=EgwMFm9T; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47wmXb3Dlbz9s4Y for ; Mon, 13 Jan 2020 06:11:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B5D3D816DD; Sun, 12 Jan 2020 20:07:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="EgwMFm9T"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B914081808; Sun, 12 Jan 2020 20:07:35 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CE142817E7 for ; Sun, 12 Jan 2020 20:07:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x142.google.com with SMTP id x5so6056900ila.6 for ; Sun, 12 Jan 2020 11:07:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T8B+NhEYk2DQ3EdU8Q/uAExO3XSxkKH3vmp1DO3nms0=; b=EgwMFm9TNMc+6BSrGZ295YhUorHWJAlTrQbzRt4dzr3xUdRAbGdmG3ZT0lqLX5ATij Dy8jIydBZEwNZqBWQ8PRY4AnDHCHNdd8GPuqyAbzBQKzSX3d7gdBxomD9/fK1sm3acrJ pF2KypgwRvOQKFhO+WpahxjEHVp/tbN5Y20Xs= 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=T8B+NhEYk2DQ3EdU8Q/uAExO3XSxkKH3vmp1DO3nms0=; b=qyb9TjgxPiWNntngK5Zmc7refBVSn8zTWr1w74SgdtPnXzJololcn+44NoK7GrP/ov fNBf3QWWJDAye2KUmif+ADAfO30BnrwGzMwyZAEX7EaqRnGV/GN0oMgjZJ8O7sf2FQ/u +1DKbmHdpUBS2Y4PlUbpy9jApw5p724Ysz+LPXxwVxJQijpv0Fq7sM9Dc4SnmjjrdYYn xLbhgr5DiyNaa9erUsZZ1mMsKkX3iChIx/9iIDouT7LANsWLTC8wI/stwVIthRVsTDY3 DiADLhKzfwN8wuo4zcXbMT4fCywluvUwDJZjB63R7wdYl+VTmU6Bda/Q7zGRynHazXbb VBXg== X-Gm-Message-State: APjAAAVpujr7nEjNG3dpmibKNwXQ8HVUF1GazPExYWpJpez/Oi+J4g1O mSr/tcEMjkA3Imtrotl5/WB9mPxChMg= X-Google-Smtp-Source: APXvYqz58ZmzH+sHSNrd8Epb3CUwSORiSazy2rozreU3ZcdKIMtnHga2H1QMBZOjIevkwtltXhmQ2Q== X-Received: by 2002:a92:48c2:: with SMTP id j63mr11400628ilg.153.1578856051670; Sun, 12 Jan 2020 11:07:31 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id r22sm3039219ilb.25.2020.01.12.11.07.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2020 11:07:31 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 24/33] sandbox: sdl: Support waiting for audio to complete Date: Sun, 12 Jan 2020 12:06:15 -0700 Message-Id: <20200112120216.24.Ib94b6be5078e355d597706e70639153bcfb9f9fe@changeid> X-Mailer: git-send-email 2.25.0.rc1.283.g88dfdc4193-goog In-Reply-To: <20200112190624.79077-1-sjg@chromium.org> References: <20200112190624.79077-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean At present when audio stops, any in-progress output is cut off. Fix this by waiting for output to finish. Also use booleans for the boolean variables. Signed-off-by: Simon Glass --- arch/sandbox/cpu/sdl.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c index ee62da265b..dedf00ed35 100644 --- a/arch/sandbox/cpu/sdl.c +++ b/arch/sandbox/cpu/sdl.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -39,6 +40,7 @@ struct buf_info { * @buf: The two available audio buffers. SDL can be reading from one while we * are setting up the next * @running: true if audio is running + * @stopping: true if audio will stop once it runs out of data */ static struct sdl_info { SDL_Surface *screen; @@ -52,6 +54,7 @@ static struct sdl_info { int cur_buf; struct buf_info buf[2]; bool running; + bool stopping; } sdl; static void sandbox_sdl_poll_events(void) @@ -271,6 +274,7 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len) { struct buf_info *buf; int avail; + bool have_data = false; int i; for (i = 0; i < 2; i++) { @@ -282,6 +286,7 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len) } if (avail > len) avail = len; + have_data = true; SDL_MixAudio(stream, buf->data + buf->pos, avail, SDL_MIX_MAXVOLUME); @@ -294,6 +299,7 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len) else break; } + sdl.stopping = !have_data; } int sandbox_sdl_sound_init(int rate, int channels) @@ -347,7 +353,7 @@ int sandbox_sdl_sound_init(int rate, int channels) sdl.audio_active = true; sdl.sample_rate = wanted.freq; sdl.cur_buf = 0; - sdl.running = 0; + sdl.running = false; return 0; @@ -378,7 +384,8 @@ int sandbox_sdl_sound_play(const void *data, uint size) buf->pos = 0; if (!sdl.running) { SDL_PauseAudio(0); - sdl.running = 1; + sdl.running = true; + sdl.stopping = false; } return 0; @@ -387,8 +394,12 @@ int sandbox_sdl_sound_play(const void *data, uint size) int sandbox_sdl_sound_stop(void) { if (sdl.running) { + while (!sdl.stopping) + SDL_Delay(100); + SDL_PauseAudio(1); sdl.running = 0; + sdl.stopping = false; } return 0;