From patchwork Thu Jan 14 13:45:30 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: 567461 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 83DED1402E2 for ; Fri, 15 Jan 2016 01:01:53 +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=ApbC85ct; dkim-atps=neutral Received: from localhost ([::1]:42661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJiTH-0000cO-Ez for incoming@patchwork.ozlabs.org; Thu, 14 Jan 2016 09:01:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJiEQ-0001OE-Po for qemu-devel@nongnu.org; Thu, 14 Jan 2016 08:46:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJiEJ-0003RT-He for qemu-devel@nongnu.org; Thu, 14 Jan 2016 08:46:30 -0500 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:35689) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJiEJ-0003RI-77 for qemu-devel@nongnu.org; Thu, 14 Jan 2016 08:46:23 -0500 Received: by mail-wm0-x244.google.com with SMTP id f206so43693505wmf.2 for ; Thu, 14 Jan 2016 05:46:23 -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=wnmHQa9L8YnYe0BY6ijo3EEV8mJboF1PhXeVt7VYSIw=; b=ApbC85ctJLcBHdF6Pp3LP1T9XaCpSaBuOjQ9QNE8gNFb8rlzqHcJ7mdEZ42kx1yIcm Qie+oO66jXW9BVDPs2cgDvhCfYMap97fOGpYov+VDyF6SHgQn6Fbub0/7BCAUoh0Emkb 29vH3t+IBOKi5LqYKymV5J6u+Q3JUrOIH/P7N3TVJiDfHqXOMzjB6SZGFpC5ZiVsUbYb 8odsQofO3asriq1vHQaAA5h5bX70Fdmh2za8L4cUcMgeNlPmCWn4+Zkhw5/zMxCPD3NW vW27j1lDYpS7WXstmPXY8GcjnV3PCcCGdqrrdICU0GhSDupIyyh0j9IH9udfENHjY7pc 2Uaw== 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=wnmHQa9L8YnYe0BY6ijo3EEV8mJboF1PhXeVt7VYSIw=; b=JR/7Ecf/P9xdJwASStxZqHYGsmgh591k1wPKjbADDL6kblzqNk89Hcgb/RU/kjNnx1 D/Vzt6v8thZfMRZgazM1spcE5EeH0af41TruVZCMWWTDVVI7R/JsCRIlcWzzGiQ3QR07 ympAxW7Nr3aB/KbwvFMCHHLMtf0gifcqk6i76vEqJr+P/wVIatC2mVbJ24hTCc9joyWz exZ5XH9jxO/fHSG2f2IcdXbXKgug8uuqUtcJufuSYefdCT2cEgHjf2JY9w6OjnOs2V+8 B/ts51NX2L5oDVJ5f7eiaccNhw56cuHyGlNtsWUPbbW52+LgsjR1ApUQENFXNDlnBr7D y66A== X-Gm-Message-State: ALoCoQma4MnAUmvCw3l23NQNAG8jsivd3uyCCjM0ZN9ftyPb+FgHC/LzHNQ+oEDAoIKviySi1uAQ7v/Y4P7W17KW7KBfl0BSPw== X-Received: by 10.194.20.67 with SMTP id l3mr3931472wje.86.1452779182718; Thu, 14 Jan 2016 05:46:22 -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.22 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 14 Jan 2016 05:46:22 -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:30 +0100 Message-Id: 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 17/51] audio: reduce glob_audio_state usage 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 Remove glob_audio_state from functions, where possible without breaking the API. This means that most static functions in audio.c now take an AudioState pointer instead of implicitly using glob_audio_state. Also included a pointer in SWVoice*, HWVoice* structs, so that functions dealing them can know the audio state without having to pass it around separately. This is required in order to support multiple simultaneous audio backends (added in a later commit). Signed-off-by: Kővágó, Zoltán --- audio/audio.c | 41 ++++++++++++++++++++--------------------- audio/audio_int.h | 4 ++++ audio/audio_template.h | 46 ++++++++++++++++++++++------------------------ 3 files changed, 46 insertions(+), 45 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index 115d41d..2aa2071 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -367,12 +367,10 @@ static void noop_conv (struct st_sample *dst, const void *src, int samples) (void) samples; } -static CaptureVoiceOut *audio_pcm_capture_find_specific ( - struct audsettings *as - ) +static CaptureVoiceOut *audio_pcm_capture_find_specific(AudioState *s, + struct audsettings *as) { CaptureVoiceOut *cap; - AudioState *s = &glob_audio_state; for (cap = s->cap_head.lh_first; cap; cap = cap->entries.le_next) { if (audio_pcm_info_eq (&cap->hw.info, as)) { @@ -449,7 +447,7 @@ static void audio_detach_capture (HWVoiceOut *hw) static int audio_attach_capture (HWVoiceOut *hw) { - AudioState *s = &glob_audio_state; + AudioState *s = hw->s; CaptureVoiceOut *cap; audio_detach_capture (hw); @@ -762,15 +760,15 @@ static void audio_pcm_print_info (const char *cap, struct audio_pcm_info *info) /* * Timer */ -static int audio_is_timer_needed (void) +static int audio_is_timer_needed(AudioState *s) { HWVoiceIn *hwi = NULL; HWVoiceOut *hwo = NULL; - while ((hwo = audio_pcm_hw_find_any_enabled_out (hwo))) { + while ((hwo = audio_pcm_hw_find_any_enabled_out(s, hwo))) { if (!hwo->poll_mode) return 1; } - while ((hwi = audio_pcm_hw_find_any_enabled_in (hwi))) { + while ((hwi = audio_pcm_hw_find_any_enabled_in(s, hwi))) { if (!hwi->poll_mode) return 1; } return 0; @@ -778,7 +776,7 @@ static int audio_is_timer_needed (void) static void audio_reset_timer (AudioState *s) { - if (audio_is_timer_needed ()) { + if (audio_is_timer_needed(s)) { timer_mod (s->ts, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + s->period_ticks); } @@ -847,7 +845,7 @@ void AUD_set_active_out (SWVoiceOut *sw, int on) hw = sw->hw; if (sw->active != on) { - AudioState *s = &glob_audio_state; + AudioState *s = sw->s; SWVoiceOut *temp_sw; SWVoiceCap *sc; @@ -894,7 +892,7 @@ void AUD_set_active_in (SWVoiceIn *sw, int on) hw = sw->hw; if (sw->active != on) { - AudioState *s = &glob_audio_state; + AudioState *s = sw->s; SWVoiceIn *temp_sw; if (on) { @@ -1017,7 +1015,7 @@ static void audio_run_out (AudioState *s) HWVoiceOut *hw = NULL; SWVoiceOut *sw; - while ((hw = audio_pcm_hw_find_any_enabled_out (hw))) { + while ((hw = audio_pcm_hw_find_any_enabled_out(s, hw))) { int played; int live, free, nb_live, cleanup_required, prev_rpos; @@ -1121,7 +1119,7 @@ static void audio_run_in (AudioState *s) { HWVoiceIn *hw = NULL; - while ((hw = audio_pcm_hw_find_any_enabled_in (hw))) { + while ((hw = audio_pcm_hw_find_any_enabled_in(s, hw))) { SWVoiceIn *sw; int captured, min; @@ -1224,8 +1222,8 @@ static int audio_driver_init(AudioState *s, struct audio_driver *drv, s->drv_opaque = drv->init(dev); if (s->drv_opaque) { - audio_init_nb_voices_out (drv); - audio_init_nb_voices_in (drv); + audio_init_nb_voices_out(s, drv); + audio_init_nb_voices_in(s, drv); s->drv = drv; return 0; } @@ -1244,11 +1242,11 @@ static void audio_vm_change_state_handler (void *opaque, int running, int op = running ? VOICE_ENABLE : VOICE_DISABLE; s->vm_running = running; - while ((hwo = audio_pcm_hw_find_any_enabled_out (hwo))) { + while ((hwo = audio_pcm_hw_find_any_enabled_out(s, hwo))) { hwo->pcm_ops->ctl_out(hwo, op); } - while ((hwi = audio_pcm_hw_find_any_enabled_in (hwi))) { + while ((hwi = audio_pcm_hw_find_any_enabled_in(s, hwi))) { hwi->pcm_ops->ctl_in(hwi, op); } audio_reset_timer (s); @@ -1260,7 +1258,7 @@ static void audio_atexit (void) HWVoiceOut *hwo = NULL; HWVoiceIn *hwi = NULL; - while ((hwo = audio_pcm_hw_find_any_out (hwo))) { + while ((hwo = audio_pcm_hw_find_any_out(s, hwo))) { SWVoiceCap *sc; if (hwo->enabled) { @@ -1278,7 +1276,7 @@ static void audio_atexit (void) } } - while ((hwi = audio_pcm_hw_find_any_in (hwi))) { + while ((hwi = audio_pcm_hw_find_any_in(s, hwi))) { if (hwi->enabled) { hwi->pcm_ops->ctl_in (hwi, VOICE_DISABLE); } @@ -1459,7 +1457,7 @@ CaptureVoiceOut *AUD_add_capture ( cb->ops = *ops; cb->opaque = cb_opaque; - cap = audio_pcm_capture_find_specific (as); + cap = audio_pcm_capture_find_specific(s, as); if (cap) { QLIST_INSERT_HEAD (&cap->cb_head, cb, entries); return cap; @@ -1476,6 +1474,7 @@ CaptureVoiceOut *AUD_add_capture ( } hw = &cap->hw; + hw->s = s; QLIST_INIT (&hw->sw_head); QLIST_INIT (&cap->cb_head); @@ -1509,7 +1508,7 @@ CaptureVoiceOut *AUD_add_capture ( QLIST_INSERT_HEAD (&cap->cb_head, cb, entries); hw = NULL; - while ((hw = audio_pcm_hw_find_any_out (hw))) { + while ((hw = audio_pcm_hw_find_any_out(s, hw))) { audio_attach_capture (hw); } return cap; diff --git a/audio/audio_int.h b/audio/audio_int.h index 59b2362..101081b 100644 --- a/audio/audio_int.h +++ b/audio/audio_int.h @@ -51,6 +51,7 @@ struct audio_pcm_info { typedef struct SWVoiceCap SWVoiceCap; typedef struct HWVoiceOut { + AudioState *s; int enabled; int poll_mode; int pending_disable; @@ -72,6 +73,7 @@ typedef struct HWVoiceOut { } HWVoiceOut; typedef struct HWVoiceIn { + AudioState *s; int enabled; int poll_mode; struct audio_pcm_info info; @@ -93,6 +95,7 @@ typedef struct HWVoiceIn { struct SWVoiceOut { QEMUSoundCard *card; + AudioState *s; struct audio_pcm_info info; t_sample *conv; int64_t ratio; @@ -110,6 +113,7 @@ struct SWVoiceOut { struct SWVoiceIn { QEMUSoundCard *card; + AudioState *s; int active; struct audio_pcm_info info; int64_t ratio; diff --git a/audio/audio_template.h b/audio/audio_template.h index 096b2b3..455e50d 100644 --- a/audio/audio_template.h +++ b/audio/audio_template.h @@ -36,9 +36,9 @@ #define HWBUF hw->conv_buf #endif -static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv) +static void glue(audio_init_nb_voices_, TYPE)(AudioState *s, + struct audio_driver *drv) { - AudioState *s = &glob_audio_state; int max_voices = glue (drv->max_voices_, TYPE); int voice_size = glue (drv->voice_size_, TYPE); @@ -183,8 +183,8 @@ static void glue (audio_pcm_hw_del_sw_, TYPE) (SW *sw) static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp) { - AudioState *s = &glob_audio_state; HW *hw = *hwp; + AudioState *s = hw->s; if (!hw->sw_head.lh_first) { #ifdef DAC @@ -199,15 +199,14 @@ static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp) } } -static HW *glue (audio_pcm_hw_find_any_, TYPE) (HW *hw) +static HW *glue(audio_pcm_hw_find_any_, TYPE)(AudioState *s, HW *hw) { - AudioState *s = &glob_audio_state; return hw ? hw->entries.le_next : glue (s->hw_head_, TYPE).lh_first; } -static HW *glue (audio_pcm_hw_find_any_enabled_, TYPE) (HW *hw) +static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioState *s, HW *hw) { - while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (hw))) { + while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) { if (hw->enabled) { return hw; } @@ -215,12 +214,10 @@ static HW *glue (audio_pcm_hw_find_any_enabled_, TYPE) (HW *hw) return NULL; } -static HW *glue (audio_pcm_hw_find_specific_, TYPE) ( - HW *hw, - struct audsettings *as - ) +static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioState *s, HW *hw, + struct audsettings *as) { - while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (hw))) { + while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) { if (audio_pcm_info_eq (&hw->info, as)) { return hw; } @@ -228,10 +225,10 @@ static HW *glue (audio_pcm_hw_find_specific_, TYPE) ( return NULL; } -static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as) +static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s, + struct audsettings *as) { HW *hw; - AudioState *s = &glob_audio_state; struct audio_driver *drv = s->drv; if (!glue (s->nb_hw_voices_, TYPE)) { @@ -255,6 +252,7 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as) return NULL; } + hw->s = s; hw->pcm_ops = drv->pcm_ops; hw->ctl_caps = drv->ctl_caps; @@ -299,33 +297,33 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as) return NULL; } -static HW *glue (audio_pcm_hw_add_, TYPE) (struct audsettings *as) +static HW *glue(audio_pcm_hw_add_, TYPE)(AudioState *s, struct audsettings *as) { HW *hw; - AudioState *s = &glob_audio_state; AudiodevPerDirectionOptions *pdo = s->dev->TYPE; if (pdo->fixed_settings) { - hw = glue (audio_pcm_hw_add_new_, TYPE) (as); + hw = glue(audio_pcm_hw_add_new_, TYPE)(s, as); if (hw) { return hw; } } - hw = glue (audio_pcm_hw_find_specific_, TYPE) (NULL, as); + hw = glue(audio_pcm_hw_find_specific_, TYPE)(s, NULL, as); if (hw) { return hw; } - hw = glue (audio_pcm_hw_add_new_, TYPE) (as); + hw = glue(audio_pcm_hw_add_new_, TYPE)(s, as); if (hw) { return hw; } - return glue (audio_pcm_hw_find_any_, TYPE) (NULL); + return glue(audio_pcm_hw_find_any_, TYPE)(s, NULL); } -static SW *glue (audio_pcm_create_voice_pair_, TYPE) ( +static SW *glue(audio_pcm_create_voice_pair_, TYPE)( + AudioState *s, const char *sw_name, struct audsettings *as ) @@ -333,7 +331,6 @@ static SW *glue (audio_pcm_create_voice_pair_, TYPE) ( SW *sw; HW *hw; struct audsettings hw_as; - AudioState *s = &glob_audio_state; AudiodevPerDirectionOptions *pdo = s->dev->TYPE; if (pdo->fixed_settings) { @@ -349,8 +346,9 @@ static SW *glue (audio_pcm_create_voice_pair_, TYPE) ( sw_name ? sw_name : "unknown", sizeof (*sw)); goto err1; } + sw->s = s; - hw = glue (audio_pcm_hw_add_, TYPE) (&hw_as); + hw = glue(audio_pcm_hw_add_, TYPE)(s, &hw_as); if (!hw) { goto err2; } @@ -447,7 +445,7 @@ SW *glue (AUD_open_, TYPE) ( } } else { - sw = glue (audio_pcm_create_voice_pair_, TYPE) (name, as); + sw = glue(audio_pcm_create_voice_pair_, TYPE)(s, name, as); if (!sw) { dolog ("Failed to create voice `%s'\n", name); return NULL;