> 2. Modify qemu to change the device sample rate dynamically > > This seems like it should be possible. I'm working up a > hack to try it (basically, we regen the rate at voice_enable > time). This seems to fly in the face of 'normal' > practice, so there is probably something horrible wrong with it. > > But it's fun to play :-). Attached is a patch that suggests my idea. I've done some hacks, and it seems 'safe' to adjust the rate on the fly like this. I'd appreciate some friendly folks glancing it over before I try to flesh it out and get myself laughed off the qemu mailing list. Cheers, Jeremy
diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c index bc24557..49a4aac 100644 --- a/audio/spiceaudio.c +++ b/audio/spiceaudio.c @@ -106,20 +106,26 @@ static int rate_get_samples (struct audio_pcm_info *info, SpiceRateCtl *rate) /* playback */ -static int line_out_init (HWVoiceOut *hw, struct audsettings *as) +static void line_set_frequency(struct audio_pcm_info *info, int freq, int channels) { - SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw); struct audsettings settings; - settings.freq = SPICE_INTERFACE_PLAYBACK_FREQ; - settings.nchannels = SPICE_INTERFACE_PLAYBACK_CHAN; + settings.freq = freq; + settings.nchannels = channels; settings.fmt = AUD_FMT_S16; settings.endianness = AUDIO_HOST_ENDIANNESS; - audio_pcm_init_info (&hw->info, &settings); + audio_pcm_init_info (info, &settings); +} + +static int line_out_init (HWVoiceOut *hw, struct audsettings *as) +{ + SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw); hw->samples = LINE_OUT_SAMPLES; out->active = 0; + line_set_frequency(&hw->info, SPICE_INTERFACE_PLAYBACK_FREQ, SPICE_INTERFACE_PLAYBACK_CHAN); + out->sin.base.sif = &playback_sif.base; qemu_spice_add_interface (&out->sin.base); return 0; @@ -177,6 +183,14 @@ static int line_out_write (SWVoiceOut *sw, void *buf, int len) return audio_pcm_sw_write (sw, buf, len); } +static void check_for_spice_rate_change(SpiceVoiceOut *out, struct audio_pcm_info *info) +{ + int freq; + int chan; + if (spice_server_playback_get_rate(&out->sin, &freq, &chan)) + line_set_frequency(info, freq, chan); +} + static int line_out_ctl (HWVoiceOut *hw, int cmd, ...) { SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw); @@ -187,6 +201,11 @@ static int line_out_ctl (HWVoiceOut *hw, int cmd, ...) break; } out->active = 1; + +#if ((SPICE_INTERFACE_PLAYBACK_MAJOR >= 1) && (SPICE_INTERFACE_PLAYBACK_MINOR >= 3)) + check_for_spice_rate_change(out, &hw->info); +#endif + rate_start (&out->rate); spice_server_playback_start (&out->sin); break; @@ -230,14 +249,9 @@ static int line_out_ctl (HWVoiceOut *hw, int cmd, ...) static int line_in_init (HWVoiceIn *hw, struct audsettings *as) { SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw); - struct audsettings settings; - settings.freq = SPICE_INTERFACE_RECORD_FREQ; - settings.nchannels = SPICE_INTERFACE_RECORD_CHAN; - settings.fmt = AUD_FMT_S16; - settings.endianness = AUDIO_HOST_ENDIANNESS; + line_set_frequency(&hw->info, SPICE_INTERFACE_RECORD_FREQ, SPICE_INTERFACE_RECORD_CHAN); - audio_pcm_init_info (&hw->info, &settings); hw->samples = LINE_IN_SAMPLES; in->active = 0;
_______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel