Skip to content

Commit

Permalink
Remove any pretense that there can be more than one AudioState
Browse files Browse the repository at this point in the history
  • Loading branch information
malc committed May 13, 2009
1 parent b36aa85 commit 1a7dafc
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 103 deletions.
71 changes: 33 additions & 38 deletions audio/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,11 @@ static void noop_conv (struct st_sample *dst, const void *src,
}

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)) {
Expand Down Expand Up @@ -786,8 +786,9 @@ static void audio_detach_capture (HWVoiceOut *hw)
}
}

static int audio_attach_capture (AudioState *s, HWVoiceOut *hw)
static int audio_attach_capture (HWVoiceOut *hw)
{
AudioState *s = &glob_audio_state;
CaptureVoiceOut *cap;

audio_detach_capture (hw);
Expand Down Expand Up @@ -1295,7 +1296,7 @@ static void audio_run_out (AudioState *s)
HWVoiceOut *hw = NULL;
SWVoiceOut *sw;

while ((hw = audio_pcm_hw_find_any_enabled_out (s, hw))) {
while ((hw = audio_pcm_hw_find_any_enabled_out (hw))) {
int played;
int live, free, nb_live, cleanup_required, prev_rpos;

Expand Down Expand Up @@ -1390,7 +1391,7 @@ static void audio_run_out (AudioState *s)
#ifdef DEBUG_PLIVE
dolog ("Finishing with old voice\n");
#endif
audio_close_out (s, sw);
audio_close_out (sw);
}
sw = sw1;
}
Expand All @@ -1402,7 +1403,7 @@ static void audio_run_in (AudioState *s)
{
HWVoiceIn *hw = NULL;

while ((hw = audio_pcm_hw_find_any_enabled_in (s, hw))) {
while ((hw = audio_pcm_hw_find_any_enabled_in (hw))) {
SWVoiceIn *sw;
int captured, min;

Expand Down Expand Up @@ -1610,8 +1611,8 @@ static int audio_driver_init (AudioState *s, struct audio_driver *drv)
s->drv_opaque = drv->init ();

if (s->drv_opaque) {
audio_init_nb_voices_out (s, drv);
audio_init_nb_voices_in (s, drv);
audio_init_nb_voices_out (drv);
audio_init_nb_voices_in (drv);
s->drv = drv;
return 0;
}
Expand All @@ -1630,11 +1631,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 (s, hwo))) {
while ((hwo = audio_pcm_hw_find_any_enabled_out (hwo))) {
hwo->pcm_ops->ctl_out (hwo, op);
}

while ((hwi = audio_pcm_hw_find_any_enabled_in (s, hwi))) {
while ((hwi = audio_pcm_hw_find_any_enabled_in (hwi))) {
hwi->pcm_ops->ctl_in (hwi, op);
}
}
Expand All @@ -1645,7 +1646,7 @@ static void audio_atexit (void)
HWVoiceOut *hwo = NULL;
HWVoiceIn *hwi = NULL;

while ((hwo = audio_pcm_hw_find_any_enabled_out (s, hwo))) {
while ((hwo = audio_pcm_hw_find_any_enabled_out (hwo))) {
SWVoiceCap *sc;

hwo->pcm_ops->ctl_out (hwo, VOICE_DISABLE);
Expand All @@ -1661,7 +1662,7 @@ static void audio_atexit (void)
}
}

while ((hwi = audio_pcm_hw_find_any_enabled_in (s, hwi))) {
while ((hwi = audio_pcm_hw_find_any_enabled_in (hwi))) {
hwi->pcm_ops->ctl_in (hwi, VOICE_DISABLE);
hwi->pcm_ops->fini_in (hwi);
}
Expand Down Expand Up @@ -1689,30 +1690,15 @@ static int audio_load (QEMUFile *f, void *opaque, int version_id)
return 0;
}

void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card)
{
card->audio = s;
card->name = qemu_strdup (name);
memset (&card->entries, 0, sizeof (card->entries));
LIST_INSERT_HEAD (&s->card_head, card, entries);
}

void AUD_remove_card (QEMUSoundCard *card)
{
LIST_REMOVE (card, entries);
card->audio = NULL;
qemu_free (card->name);
}

AudioState *AUD_init (void)
static void audio_init (void)
{
size_t i;
int done = 0;
const char *drvname;
AudioState *s = &glob_audio_state;

if (s->drv) {
return s;
return;
}

LIST_INIT (&s->hw_head_out);
Expand Down Expand Up @@ -1804,24 +1790,33 @@ AudioState *AUD_init (void)
LIST_INIT (&s->card_head);
register_savevm ("audio", 0, 1, audio_save, audio_load, s);
qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks);
return s;
}

void AUD_register_card (const char *name, QEMUSoundCard *card)
{
audio_init ();
card->name = qemu_strdup (name);
memset (&card->entries, 0, sizeof (card->entries));
LIST_INSERT_HEAD (&glob_audio_state.card_head, card, entries);
}

void AUD_remove_card (QEMUSoundCard *card)
{
LIST_REMOVE (card, entries);
qemu_free (card->name);
}


CaptureVoiceOut *AUD_add_capture (
AudioState *s,
struct audsettings *as,
struct audio_capture_ops *ops,
void *cb_opaque
)
{
AudioState *s = &glob_audio_state;
CaptureVoiceOut *cap;
struct capture_callback *cb;

if (!s) {
/* XXX suppress */
s = &glob_audio_state;
}

if (audio_validate_settings (as)) {
dolog ("Invalid settings were passed when trying to add capture\n");
audio_print_settings (as);
Expand All @@ -1837,7 +1832,7 @@ CaptureVoiceOut *AUD_add_capture (
cb->ops = *ops;
cb->opaque = cb_opaque;

cap = audio_pcm_capture_find_specific (s, as);
cap = audio_pcm_capture_find_specific (as);
if (cap) {
LIST_INSERT_HEAD (&cap->cb_head, cb, entries);
return cap;
Expand Down Expand Up @@ -1887,8 +1882,8 @@ CaptureVoiceOut *AUD_add_capture (
LIST_INSERT_HEAD (&cap->cb_head, cb, entries);

hw = NULL;
while ((hw = audio_pcm_hw_find_any_out (s, hw))) {
audio_attach_capture (s, hw);
while ((hw = audio_pcm_hw_find_any_out (hw))) {
audio_attach_capture (hw);
}
return cap;

Expand Down
5 changes: 1 addition & 4 deletions audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ typedef struct CaptureVoiceOut CaptureVoiceOut;
typedef struct SWVoiceIn SWVoiceIn;

typedef struct QEMUSoundCard {
AudioState *audio;
char *name;
LIST_ENTRY (QEMUSoundCard) entries;
} QEMUSoundCard;
Expand All @@ -94,12 +93,10 @@ void AUD_log (const char *cap, const char *fmt, ...)
#endif
;

AudioState *AUD_init (void);
void AUD_help (void);
void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card);
void AUD_register_card (const char *name, QEMUSoundCard *card);
void AUD_remove_card (QEMUSoundCard *card);
CaptureVoiceOut *AUD_add_capture (
AudioState *s,
struct audsettings *as,
struct audio_capture_ops *ops,
void *opaque
Expand Down
2 changes: 2 additions & 0 deletions audio/audio_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ typedef struct HWVoiceIn {
} HWVoiceIn;

struct SWVoiceOut {
QEMUSoundCard *card;
struct audio_pcm_info info;
t_sample *conv;
int64_t ratio;
Expand All @@ -120,6 +121,7 @@ struct SWVoiceOut {
};

struct SWVoiceIn {
QEMUSoundCard *card;
int active;
struct audio_pcm_info info;
int64_t ratio;
Expand Down
Loading

0 comments on commit 1a7dafc

Please sign in to comment.