From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSToA-0007qV-Qu for qemu-devel@nongnu.org; Thu, 20 Aug 2015 13:39:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZSTo9-0002NG-6G for qemu-devel@nongnu.org; Thu, 20 Aug 2015 13:39:22 -0400 Received: from mail-ob0-x235.google.com ([2607:f8b0:4003:c01::235]:33874) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSTo9-0002Mw-0n for qemu-devel@nongnu.org; Thu, 20 Aug 2015 13:39:21 -0400 Received: by obbfr1 with SMTP id fr1so38262630obb.1 for ; Thu, 20 Aug 2015 10:39:20 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <21301babb2fd02470314de3a7e6c63d9575a25af.1438884611.git.DirtY.iCE.hu@gmail.com> References: <21301babb2fd02470314de3a7e6c63d9575a25af.1438884611.git.DirtY.iCE.hu@gmail.com> Date: Thu, 20 Aug 2015 19:39:20 +0200 Message-ID: From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 11/25] audio: reduce glob_audio_state usage List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?S8WRdsOhZ8OzLCBab2x0w6Fu?= Cc: QEMU , Gerd Hoffmann Hi On Thu, Aug 6, 2015 at 8:28 PM, K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n wrote: > Signed-off-by: K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n Fill a bit the commit message, to say simply use AudioState instead. Also explain why you add AudioState *s in struct although it's not used in that commit, saying simply it's going to be used in later commit is enough imho (I guess it is). > --- > 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 08ac15e..05b24dc 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 audsettin= gs *as) > { > CaptureVoiceOut *cap; > - AudioState *s =3D &glob_audio_state; > > for (cap =3D s->cap_head.lh_first; cap; cap =3D 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 =3D &glob_audio_state; > + AudioState *s =3D 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 =3D NULL; > HWVoiceOut *hwo =3D NULL; > > - while ((hwo =3D audio_pcm_hw_find_any_enabled_out (hwo))) { > + while ((hwo =3D audio_pcm_hw_find_any_enabled_out(s, hwo))) { > if (!hwo->poll_mode) return 1; > } > - while ((hwi =3D audio_pcm_hw_find_any_enabled_in (hwi))) { > + while ((hwi =3D 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 =3D sw->hw; > if (sw->active !=3D on) { > - AudioState *s =3D &glob_audio_state; > + AudioState *s =3D sw->s; > SWVoiceOut *temp_sw; > SWVoiceCap *sc; > > @@ -894,7 +892,7 @@ void AUD_set_active_in (SWVoiceIn *sw, int on) > > hw =3D sw->hw; > if (sw->active !=3D on) { > - AudioState *s =3D &glob_audio_state; > + AudioState *s =3D sw->s; > SWVoiceIn *temp_sw; > > if (on) { > @@ -1017,7 +1015,7 @@ static void audio_run_out (AudioState *s) > HWVoiceOut *hw =3D NULL; > SWVoiceOut *sw; > > - while ((hw =3D audio_pcm_hw_find_any_enabled_out (hw))) { > + while ((hw =3D 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 =3D NULL; > > - while ((hw =3D audio_pcm_hw_find_any_enabled_in (hw))) { > + while ((hw =3D 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 =3D 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 =3D drv; > return 0; > } > @@ -1244,11 +1242,11 @@ static void audio_vm_change_state_handler (void *= opaque, int running, > int op =3D running ? VOICE_ENABLE : VOICE_DISABLE; > > s->vm_running =3D running; > - while ((hwo =3D audio_pcm_hw_find_any_enabled_out (hwo))) { > + while ((hwo =3D audio_pcm_hw_find_any_enabled_out(s, hwo))) { > hwo->pcm_ops->ctl_out (hwo, op); > } > > - while ((hwi =3D audio_pcm_hw_find_any_enabled_in (hwi))) { > + while ((hwi =3D 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 =3D NULL; > HWVoiceIn *hwi =3D NULL; > > - while ((hwo =3D audio_pcm_hw_find_any_out (hwo))) { > + while ((hwo =3D audio_pcm_hw_find_any_out(s, hwo))) { > SWVoiceCap *sc; > > if (hwo->enabled) { > @@ -1278,7 +1276,7 @@ static void audio_atexit (void) > } > } > > - while ((hwi =3D audio_pcm_hw_find_any_in (hwi))) { > + while ((hwi =3D 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 =3D *ops; > cb->opaque =3D cb_opaque; > > - cap =3D audio_pcm_capture_find_specific (as); > + cap =3D 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 =3D &cap->hw; > + hw->s =3D 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 =3D NULL; > - while ((hw =3D audio_pcm_hw_find_any_out (hw))) { > + while ((hw =3D 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 =3D &glob_audio_state; > int max_voices =3D glue (drv->max_voices_, TYPE); > int voice_size =3D 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 =3D &glob_audio_state; > HW *hw =3D *hwp; > + AudioState *s =3D 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 =3D &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 =3D glue (audio_pcm_hw_find_any_, TYPE) (hw))) { > + while ((hw =3D 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_, TY= PE) (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 *a= s) > { > - while ((hw =3D glue (audio_pcm_hw_find_any_, TYPE) (hw))) { > + while ((hw =3D 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 =3D &glob_audio_state; > struct audio_driver *drv =3D 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 =3D s; > hw->pcm_ops =3D drv->pcm_ops; > hw->ctl_caps =3D drv->ctl_caps; > > @@ -299,33 +297,33 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (stru= ct 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 audsettin= gs *as) > { > HW *hw; > - AudioState *s =3D &glob_audio_state; > AudiodevPerDirectionOptions *pdo =3D s->dev->TYPE; > > if (pdo->fixed_settings) { > - hw =3D glue (audio_pcm_hw_add_new_, TYPE) (as); > + hw =3D glue(audio_pcm_hw_add_new_, TYPE)(s, as); > if (hw) { > return hw; > } > } > > - hw =3D glue (audio_pcm_hw_find_specific_, TYPE) (NULL, as); > + hw =3D glue(audio_pcm_hw_find_specific_, TYPE)(s, NULL, as); > if (hw) { > return hw; > } > > - hw =3D glue (audio_pcm_hw_add_new_, TYPE) (as); > + hw =3D 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 =3D &glob_audio_state; > AudiodevPerDirectionOptions *pdo =3D 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 =3D s; > > - hw =3D glue (audio_pcm_hw_add_, TYPE) (&hw_as); > + hw =3D glue(audio_pcm_hw_add_, TYPE)(s, &hw_as); > if (!hw) { > goto err2; > } > @@ -447,7 +445,7 @@ SW *glue (AUD_open_, TYPE) ( > } > } > else { > - sw =3D glue (audio_pcm_create_voice_pair_, TYPE) (name, as); > + sw =3D glue(audio_pcm_create_voice_pair_, TYPE)(s, name, as); > if (!sw) { > dolog ("Failed to create voice `%s'\n", name); > return NULL; > -- > 2.4.5 > > --=20 Marc-Andr=C3=A9 Lureau