summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYaniv Kamay <ykamay@redhat.com>2009-10-08 17:12:42 +0200
committerYaniv Kamay <ykamay@redhat.com>2009-10-14 01:06:16 +0200
commiteffd4dd3c9a0b52ef4cb15c8008f6627bb2b4b57 (patch)
tree951d3074affd6f646b6ce9f541f76245d42c5848
parentdf82cf0d2f2d0bff6552a623007d43515293ebba (diff)
protect against out of order audio verbs in vd_interface_audio
-rw-r--r--qemu/audio/vd_interface_audio.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/qemu/audio/vd_interface_audio.c b/qemu/audio/vd_interface_audio.c
index 1de84489..402397b3 100644
--- a/qemu/audio/vd_interface_audio.c
+++ b/qemu/audio/vd_interface_audio.c
@@ -137,12 +137,14 @@ static void end_wave(void)
typedef struct InterfaceVoiceOut {
HWVoiceOut base;
uint64_t prev_ticks;
+ int active;
} InterfaceVoiceOut;
typedef struct InterfaceVoiceIn {
- HWVoiceOut base;
+ HWVoiceIn base;
uint64_t prev_ticks;
uint32_t samples[LINE_IN_SAMPLES];
+ int active;
} InterfaceVoiceIn;
static struct audio_option options[] = {
@@ -161,7 +163,7 @@ typedef struct Interface_audio {
uint32_t silence[LINE_IN_SAMPLES];
InterfaceVoiceOut *voic_out;
- HWVoiceIn *voic_in;
+ InterfaceVoiceIn *voic_in;
} Interface_audio;
static Interface_audio driver = {
@@ -187,7 +189,7 @@ static VDObjectRef interface_play_plug(PlaybackInterface *playback, PlaybackPlug
}
ASSERT(plug && playback == driver.play_interface && enabled);
driver.play_plug = plug;
- *enabled = driver.voic_out ? driver.voic_out->base.enabled : 0;
+ *enabled = driver.voic_out ? driver.voic_out->active : 0;
return (VDObjectRef)plug;
}
@@ -233,7 +235,7 @@ static VDObjectRef interface_record_plug(RecordInterface *recorder, RecordPlug*
ASSERT(!driver.record_plug && plug && recorder == driver.record_interface
&& enabled);
driver.record_plug = plug;
- *enabled = driver.voic_in ? driver.voic_in->enabled : 0;
+ *enabled = driver.voic_in ? driver.voic_in->active : 0;
return (VDObjectRef)plug;
}
@@ -343,6 +345,7 @@ static int line_out_init(HWVoiceOut *hw, struct audsettings *as)
audio_pcm_init_info(&hw->info, &settings);
hw->samples = LINE_OUT_SAMPLES;
driver.voic_out = voice_out;
+ voice_out->active = 0;
return 0;
}
@@ -423,12 +426,20 @@ static int line_out_ctl(HWVoiceOut *hw, int cmd, ...)
switch (cmd) {
case VOICE_ENABLE:
+ if (voice_out->active) {
+ break;
+ }
+ voice_out->active = 1;
voice_out->prev_ticks = get_monotonic_time();
if (driver.play_plug) {
driver.play_plug->start(driver.play_plug);
}
break;
case VOICE_DISABLE:
+ if (!voice_out->active) {
+ break;
+ }
+ voice_out->active = 0;
if (driver.play_plug) {
if (driver.play_frame) {
uint32_t *frame = driver.play_frame;
@@ -449,6 +460,7 @@ static int line_out_ctl(HWVoiceOut *hw, int cmd, ...)
static int line_in_init(HWVoiceIn *hw, struct audsettings *as)
{
+ InterfaceVoiceIn *voice_in = (InterfaceVoiceIn *)hw;
struct audsettings settings;
dprintf("");
@@ -466,7 +478,8 @@ static int line_in_init(HWVoiceIn *hw, struct audsettings *as)
audio_pcm_init_info(&hw->info, &settings);
hw->samples = LINE_IN_SAMPLES;
- driver.voic_in = hw;
+ driver.voic_in = voice_in;
+ voice_in->active = 0;
return 0;
}
@@ -545,6 +558,10 @@ static int line_in_ctl(HWVoiceIn *hw, int cmd, ...)
switch (cmd) {
case VOICE_ENABLE:
+ if (voice_in->active) {
+ break;
+ }
+ voice_in->active = 1;
#ifdef WAVE_CAPTURE
start_wave();
#endif
@@ -554,6 +571,10 @@ static int line_in_ctl(HWVoiceIn *hw, int cmd, ...)
}
break;
case VOICE_DISABLE:
+ if (!voice_in->active) {
+ break;
+ }
+ voice_in->active = 0;
#ifdef WAVE_CAPTURE
end_wave();
#endif