Audio 5.1 patches
v3 cover Audio 5.1 patches
Hi,
Here's an updated version of my audio 5.1 patches. Bigger changes from the previous version:
* Removed QemuOpts, use qobject_input_visitor. This also means I removed my two OptsVisitor patches as they are no longer needed. I haven't done the input and output option merging, I think they're better this way as we can share a few functions between the input and output, but it has its drawbacks too with its extra nesting, so it's still up for debate.
* Trivial qapi fixes
* MIN/MAX: Eric Blake's patches[1] should fix the osdep.h problems eventually, so I left that out of my patch series.
Additionally, [email protected] reported some problems with the coreaudio backend, but since I don't have a Mac I can't really test/debug it. Any help is greatly appreciated!
Regards,
Zoltan
[1]: https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg00727.html
Kővágó, Zoltán (50):
qapi: qapi for audio backends
audio: use qapi AudioFormat instead of audfmt_e
audio: -audiodev command line option: documentation
audio: -audiodev command line option basic implementation
alsaaudio: port to -audiodev config
coreaudio: port to -audiodev config
dsoundaudio: port to -audiodev config
noaudio: port to -audiodev config
ossaudio: port to -audiodev config
paaudio: port to -audiodev config
sdlaudio: port to -audiodev config
spiceaudio: port to -audiodev config
wavaudio: port to -audiodev config
audio: -audiodev command line option: cleanup
audio: reduce glob_audio_state usage
audio: basic support for multi backend audio
audio: add audiodev properties to frontends
audio: audiodev= parameters no longer optional when -audiodev present
paaudio: do not move stream when sink/source name is specified
paaudio: properly disconnect streams in fini_*
audio: remove audio_MIN, audio_MAX
audio: do not run each backend in audio_run
paaudio: fix playback glitches
audio: remove read and write pcm_ops
audio: use size_t where makes sense
audio: api for mixeng code free backends
alsaaudio: port to the new audio backend api
coreaudio: port to the new audio backend api
dsoundaudio: port to the new audio backend api
noaudio: port to the new audio backend api
ossaudio: port to the new audio backend api
paaudio: port to the new audio backend api
sdlaudio: port to the new audio backend api
spiceaudio: port to the new audio backend api
wavaudio: port to the new audio backend api
audio: remove remains of the old backend api
audio: unify input and output mixeng buffer management
audio: remove hw->samples, buffer_size_in/out pcm_ops
audio: common rate control code for timer based outputs
audio: split ctl_* functions into enable_* and volume_*
audio: add mixeng option (documentation)
audio: make mixeng optional
paaudio: get/put_buffer functions
audio: support more than two channels in volume setting
audio: replace shift in audio_pcm_info with bytes_per_frame
audio: basic support for multichannel audio
paaudio: channel-map option
usb-audio: do not count on avail bytes actually available
usb-audio: support more than two channels of audio
usbaudio: change playback counters to 64 bit
configure | 5 - Makefile.objs | 6 +- qapi/audio.json | 241 +++++ qapi/qapi-schema.json | 1 + audio/audio.h | 76 +- audio/audio_int.h | 141 +-- audio/audio_pt_int.h | 22 - audio/audio_template.h | 112 ++- audio/dsound_template.h | 63 +- audio/mixeng.h | 9 +- audio/rate_template.h | 2 +- include/hw/qdev-properties.h | 3 + include/sysemu/replay.h | 4 +- ui/vnc.h | 2 + audio/alsaaudio.c | 771 +++++---------- audio/audio.c | 1571 +++++++++++++++--------------- audio/audio_legacy.c | 548 +++++++++++ audio/audio_pt_int.c | 174 ---- audio/audio_win_int.c | 18 +- audio/coreaudio.c | 198 ++-- audio/dsoundaudio.c | 449 +++------ audio/noaudio.c | 98 +- audio/ossaudio.c | 608 +++++------- audio/paaudio.c | 894 +++++++---------- audio/sdlaudio.c | 218 ++--- audio/spiceaudio.c | 286 ++---- audio/wavaudio.c | 158 +-- audio/wavcapture.c | 8 +- hw/arm/omap2.c | 2 +- hw/audio/ac97.c | 13 +- hw/audio/adlib.c | 7 +- hw/audio/cs4231a.c | 11 +- hw/audio/es1370.c | 17 +- hw/audio/gus.c | 9 +- hw/audio/hda-codec.c | 35 +- hw/audio/lm4549.c | 6 +- hw/audio/milkymist-ac97.c | 16 +- hw/audio/pcspk.c | 5 +- hw/audio/pl041.c | 1 + hw/audio/sb16.c | 17 +- hw/audio/wm8750.c | 16 +- hw/core/qdev-properties-system.c | 57 ++ hw/display/xlnx_dp.c | 2 +- hw/input/tsc210x.c | 2 +- hw/usb/dev-audio.c | 464 +++++++-- monitor.c | 12 +- replay/replay-audio.c | 16 +- replay/replay.c | 2 +- ui/vnc.c | 41 +- vl.c | 7 +- audio/Makefile.objs | 3 +- hmp-commands.hx | 11 +- qemu-options.hx | 242 ++++- 53 files changed, 3985 insertions(+), 3715 deletions(-) create mode 100644 qapi/audio.json delete mode 100644 audio/audio_pt_int.h create mode 100644 audio/audio_legacy.c delete mode 100644 audio/audio_pt_int.c
Signature · 1 line
2.20.1
PATCH v3 6/50 coreaudio: port to -audiodev config
--- audio/audio_legacy.c | 24 ++++++++++++++++++++++ audio/coreaudio.c | 47 ++++++++++---------------------------------- 2 files changed, 34 insertions(+), 37 deletions(-)
audio/audio_legacy.c +24 -0
@@ -109,6 +109,17 @@ static uint32_t frames_to_usecs(uint32_t frames,return (frames *1000000 + freq /2 ) / freq; } + +static void get_frames_to_usecs (const char *env,uint32_t *dst,bool *has_dst, +AudiodevPerDirectionOptions *pdo) +{ +const char *val =getenv (env); +if (val) { + *dst =frames_to_usecs (toui32 (val), pdo); + *has_dst = true; + } +} +/* backend specific functions */ /* ALSA */ static void handle_alsa_per_direction(
@@ -166,6 +177,15 @@ static void handle_alsa(Audiodev *dev) &aopt->threshold, &aopt->has_threshold); } +/* coreaudio */ +static void handle_coreaudio (Audiodev *dev) +{ +get_frames_to_usecs ("QEMU_COREAUDIO_BUFFER_SIZE" , &dev->out->buffer_len, + &dev->out->has_buffer_len, dev->out); +get_int ("QEMU_COREAUDIO_BUFFER_COUNT" , + &dev->out->buffer_count, &dev->out->has_buffer_count); +} +/* general */ static void handle_per_direction (AudiodevPerDirectionOptions *pdo,const char *prefix)
@@ -213,6 +233,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)handle_alsa (e->dev);break ; +case AUDIODEV_DRIVER_COREAUDIO : +handle_coreaudio (e->dev); +break ; +default :break ; }
audio/coreaudio.c +10 -37
98 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 1/50 qapi: qapi for audio backends
In reply to Kővágó, ZoltánThis patch adds structures into qapi to replace the existing configuration structures used by audio backends currently. This qapi will be the base of the -audiodev command line parameter (that replaces the old environment variables based config).
This is not a 1:1 translation of the old options, I've tried to make them much more consistent (e.g. almost every backend had an option to specify buffer size, but the name was different for every backend, and some backends required usecs, while some other required frames, samples or bytes). Also tried to reduce the number of abbreviations used by the config keys.
Some of the more important changes:
* use in and out instead of ADC and DAC, as the former is more user friendly imho
* moved buffer settings into the global setting area (so it's the same for all backends that support it. Backends that can't change buffer size will simply ignore them). Also using usecs, as it's probably more user friendly than samples or bytes.
* try-poll is now an alsa backend specific option (as all other backends currently ignore it)
---
Notes:
Changes from v2:
* update copyright, version numbers
* remove #optional
* per-direction options are now optional (needed for qobject_object_visitor_new_str)
* removed unnecessary AudiodevNoOptions
* changed integers to unsigned
Makefile.objs | 6 +- qapi/audio.json | 233 ++++++++++++++++++++++++++++++++++++++++++ qapi/qapi-schema.json | 1 + 3 files changed, 237 insertions(+), 3 deletions(-) create mode 100644 qapi/audio.json
Makefile.objs +3 -3
@@ -1,6 +1,6 @@ -QAPI_MODULES = block-core block char common crypto introspect job migration -QAPI_MODULES += misc net rdma rocker run-state sockets tpm trace transaction -QAPI_MODULES += ui +QAPI_MODULES = audio block-core block char common crypto introspect job +QAPI_MODULES += migration misc net rdma rocker run-state sockets tpm trace +QAPI_MODULES += transaction ui ####################################################################### # Common libraries for tools and emulators
qapi/audio.json new file +233 -0
233 lines not on this page · raw message
qapi/qapi-schema.json +1 -0
@@ -95,3 +95,4 @@ { 'include': 'trace.json' } { 'include': 'introspect.json' } { 'include': 'misc.json' } +{ 'include': 'audio.json' }
Signature · 1 line
2.20.1
PATCH v3 3/50 audio: -audiodev command line option: documentation
In reply to Kővágó, ZoltánThis patch adds documentation of an -audiodev command line option, that deprecates the old QEMU_* environment variables for audio backend configuration. It's syntax is similar to existing options (-netdev, -device, etc):
-audiodev driver_name,property=value,...
Although now it's possible to specify multiple -audiodev options on command line, multiple audio backends are not supported yet.
--- qemu-options.hx | 222 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 219 insertions(+), 3 deletions(-)
qemu-options.hx +219 -3
@@ -416,14 +416,230 @@ The default is @code{en-us}. ETEXI +HXCOMM Deprecated by -audiodev DEF("audio-help", 0, QEMU_OPTION_audio_help, - "-audio-help print list of audio drivers and their options\n", + "-audio-help show -audiodev equivalent of the currently specified audio settings\n", QEMU_ARCH_ALL) STEXI @item -audio-help @findex -audio-help -Will show the audio subsystem help: list of drivers, tunable -parameters. +Will show the -audiodev equivalent of the currently specified +(deprecated) environment variables. +ETEXI + +DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev, + "-audiodev [driver=]driver,id=id[,prop[=value][,...]]\n" + " specifies the audio backend to use\n" + " id= identifier of the backend\n" + " timer-period= timer period in microseconds\n" + " in|out.fixed-settings= use fixed settings for host audio\n" + " in|out.frequency= frequency to use with fixed settings\n" + " in|out.channels= number of channels to use with fixed settings\n" + " in|out.format= sample format to use with fixed settings\n" + " valid values: s8, s16, s32, u8, u16, u32\n" + " in|out.voices= number of voices to use\n" + " in|out.buffer-len= size of buffer in microseconds\n" + " in|out.buffer-count= number of buffers\n" + "-audiodev none,id=id,[,prop[=value][,...]]\n" + " dummy driver that discards all output\n" +#ifdef CONFIG_ALSA + "-audiodev alsa,id=id[,prop[=value][,...]]\n" + " alsa-in|alsa-out.dev= name of the audio device to use\n" + " alsa-in|alsa-out.try-poll= attempt to use poll mode\n" + " threshold= threshold (in microseconds) when playback starts\n" +#endif +#ifdef CONFIG_COREAUDIO + "-audiodev coreaudio,id=id[,prop[=value][,...]]\n" +#endif +#ifdef CONFIG_DSOUND + "-audiodev dsound,id=id[,prop[=value][,...]]\n" + " latency= add extra latency to playback in microseconds\n" +#endif +#ifdef CONFIG_OSS + "-audiodev oss,id=id[,prop[=value][,...]]\n" + " oss-in|oss-out.dev= path of the audio device to use\n" + " oss-in|oss-out.try-poll= attempt to use poll mode\n" + " try-mmap= try using memory mapped access\n" + " exclusive= open device in exclusive mode\n" + " dsp-policy= set timing policy (0..10), -1 to use fragment mode\n" +#endif +#ifdef CONFIG_PA + "-audiodev pa,id=id[,prop[=value][,...]]\n" + " server= PulseAudio server address\n" + " sink|source.name= sink/source device name\n" +#endif +#ifdef CONFIG_SDL + "-audiodev sdl,id=id[,prop[=value][,...]]\n" +#endif +#ifdef CONFIG_SPICE + "-audiodev spice,id=id[,prop[=value][,...]]\n" +#endif + "-audiodev wav,id=id[,prop[=value][,...]]\n" + " path= path of wav file to record\n", + QEMU_ARCH_ALL) +STEXI +@item -audiodev [driver=]@var{driver},id=@var{id}[,@var{prop}[=@var{value}][,...]] +@findex -audiodev +Adds a new audio backend @var{driver} identified by @var{id}. There are +global and driver specific properties. Some values can be set +differently for input and output, they're marked with @code{in|out.}. +You can set the input's property with @code{in.@var{prop}} and the +output's property with @code{out.@var{prop}}. For example: +@example +-audiodev alsa,id=example,in.frequency=44110,out.frequency=8000 +-audiodev alsa,id=example,out.channels=1 # leaves in.channels unspecified +@end example + +Valid global options are: + +@table @option +@item id=@var{identifier} +Identifies the audio backend. + +@item timer-period=@var{period} +Sets the timer @var{period} used by the audio subsystem in microseconds. +Default is 10000 (10 ms). + +@item in|out.fixed-settings=on|off +Use fixed settings for host audio. When off, it will change based on +how the guest opens the sound card. In this case you must not specify +@var{frequency}, @var{channels} or @var{format}. Default is on. + +@item in|out.frequency=@var{frequency} +Specify the @var{frequency} to use when using @var{fixed-settings}. +Default is 44100Hz. + +@item in|out.channels=@var{channels} +Specify the number of @var{channels} to use when using +@var{fixed-settings}. Default is 2 (stereo). + +@item in|out.format=@var{format} +Specify the sample @var{format} to use when using @var{fixed-settings}. +Valid values are: @code{s8}, @code{s16}, @code{s32}, @code{u8}, +@code{u16}, @code{u32}. Default is @code{s16}. + +@item in|out.voices=@var{voices} +Specify the number of @var{voices} to use. Default is 1. + +@item in|out.buffer=@var{usecs} +Sets the size of the buffer in microseconds. + +@item in|out.buffer-count=@var{count} +Sets the @var{count} of the buffers. + +@end table + +@item -audiodev none,id=@var{id}[,@var{prop}[=@var{value}][,...]] +Creates a dummy backend that discards all outputs. This backend has no +backend specific properties. + +@item -audiodev alsa,id=@var{id}[,@var{prop}[=@var{value}][,...]] +Creates backend using the ALSA. This backend is only available on +Linux. + +ALSA specific options are: + +@table @option +@item alsa-in|alsa-out.dev=@var{device} +Specify the ALSA @var{device} to use for input and/or output. Default +is @code{default}. + +@item alsa-in|alsa-out.try-poll=on|off +Attempt to use poll mode with the device. Default is on. + +@item threshold=@var{threshold} +Threshold (in microseconds) when playback starts. Default is 0. + +@end table + +@item -audiodev coreaudio,id=@var{id}[,@var{prop}[=@var{value}][,...]] +Creates a backend using Apple's Core Audio. This backend is only +available on Mac OS and only supports playback. This backend has no +backend specific properties. + +@item -audiodev dsound,id=@var{id}[,@var{prop}[=@var{value}][,...]] +Creates a backend using Microsoft's DirectSound. This backend is only +available on Windows and only supports playback. + +Backend specific options are: + +@table @option + +@item latency=@var{usecs} +Add extra @var{usecs} microseconds latency to playback. Default is +10000 (10 ms). + +@end table + +@item -audiodev oss,id=@var{id}[,@var{prop}[=@var{value}][,...]] +Creates a backend using OSS. This backend is available on most +Unix-like systems. + +OSS specific options are: + +@table @option + +@item oss-in|oss-out.dev=@var{device} +Specify the file name of the OSS @var{device} to use. Default is +@code{/dev/dsp}. + +@item oss-in|oss-out.try-poll=on|of +Attempt to use poll mode with the device. Default is on. + +@item try-mmap=on|off +Try using memory mapped device access. Default is off. + +@item exclusive=on|off +Open the device in exclusive mode (vmix won't work in this case). +Default is off. + +@item dsp-policy=@var{policy} +Sets the timing policy (between 0 and 10, where smaller number means +smaller latency but higher CPU usage). Use -1 to use buffer sizes +specified by @code{buffer} and @code{buffer-count}. This option is +ignored if you do not have OSS 4. Default is 5. + +@end table + +@item -audiodev pa,id=@var{id}[,@var{prop}[=@var{value}][,...]] +Creates a backend using PulseAudio. This backend is available on most +systems. + +PulseAudio specific options are: + +@table @option + +@item server=@var{server} +Sets the PulseAudio @var{server} to connect to. + +@item sink|source.name=@var{sink} +Use the specified sink/source for playback/recording. + +@end table + +@item -audiodev sdl,id=@var{id}[,@var{prop}[=@var{value}][,...]] +Creates a backend using SDL. This backend is available on most systems, +but you should use your platform's native backend if possible. This +backend has no backend specific properties. + +@item -audiodev spice,id=@var{id}[,@var{prop}[=@var{value}][,...]] +Creates a backend that sends audio through SPICE. This backend requires +@code{-spice} and automatically selected in that case, so usually you +can ignore this option. This backend has no backend specific +properties. + +@item -audiodev wav,id=@var{id}[,@var{prop}[=@var{value}][,...]] +Creates a backend that writes audio to a WAV file. + +Backend specific options are: + +@table @option + +@item path=@var{path} +Write recorded audio into the specified file. Default is +@code{qemu.wav}. + +@end table ETEXI DEF("soundhw", HAS_ARG, QEMU_OPTION_soundhw,
Signature · 1 line
2.20.1
PATCH v3 8/50 noaudio: port to -audiodev config
In reply to Kővágó, Zoltán--- audio/noaudio.c | 1 - 1 file changed, 1 deletion(-)
audio/noaudio.c +0 -1
@@ -163,7 +163,6 @@ static struct audio_pcm_ops no_pcm_ops = {static struct audio_driver no_audio_driver = { .name ="none" , .descr ="Timer based audio emulation" , - .options =NULL , .init = no_audio_init, .fini = no_audio_fini, .pcm_ops = &no_pcm_ops,
Signature · 1 line
2.20.1
PATCH v3 9/50 ossaudio: port to -audiodev config
In reply to Kővágó, Zoltán--- audio/audio_legacy.c | 33 +++++++++ audio/ossaudio.c | 167 +++++++++++++++---------------------------- 2 files changed, 90 insertions(+), 110 deletions(-)
audio/audio_legacy.c +33 -0
@@ -221,6 +221,35 @@ static void handle_dsound(Audiodev *dev) &dev->in->has_buffer_len, dev->in); } +/* OSS */ +static void handle_oss_per_direction ( +AudiodevPerDirectionOptions *pdo,AudiodevOssPerDirectionOptions **opdo, +bool *has_opdo,const char *try_poll_env,const char *dev_env) +{ + *opdo =g_malloc0 (sizeof (AudiodevOssPerDirectionOptions)); + *has_opdo = true; + +get_bool (try_poll_env, &(*opdo)->try_poll, &(*opdo)->has_try_poll); +get_str (dev_env, &(*opdo)->dev, &(*opdo)->has_dev); + +get_bytes_to_usecs ("QEMU_OSS_FRAGSIZE" , + &pdo->buffer_len, &pdo->has_buffer_len, pdo); +get_int ("QEMU_OSS_NFRAGS" , &pdo->buffer_count, &pdo->has_buffer_count); +} + +static void handle_oss (Audiodev *dev) +{ +AudiodevOssOptions *oopt = &dev->u.oss; +handle_oss_per_direction (dev->in, &oopt->oss_in, &oopt->has_oss_in, +"QEMU_AUDIO_ADC_TRY_POLL" ,"QEMU_OSS_ADC_DEV" ); +handle_oss_per_direction (dev->out, &oopt->oss_out, &oopt->has_oss_out, +"QEMU_AUDIO_DAC_TRY_POLL" ,"QEMU_OSS_DAC_DEV" ); + +get_bool ("QEMU_OSS_MMAP" , &oopt->try_mmap, &oopt->has_try_mmap); +get_bool ("QEMU_OSS_EXCLUSIVE" , &oopt->exclusive, &oopt->has_exclusive); +get_int ("QEMU_OSS_POLICY" , &oopt->dsp_policy, &oopt->has_dsp_policy); +} +/* general */ static void handle_per_direction (AudiodevPerDirectionOptions *pdo,const char *prefix)
@@ -276,6 +305,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)handle_dsound (e->dev);break ; +case AUDIODEV_DRIVER_OSS : +handle_oss (e->dev); +break ; +default :break ; }
audio/ossaudio.c +57 -110
310 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 13/50 wavaudio: port to -audiodev config
In reply to Kővágó, Zoltán--- audio/audio_legacy.c | 15 ++++++++++++ audio/wavaudio.c | 58 +++++++------------------------------------- 2 files changed, 24 insertions(+), 49 deletions(-)
audio/audio_legacy.c +15 -0
@@ -293,6 +293,17 @@ static void handle_sdl(Audiodev *dev) &dev->out->has_buffer_len, dev->out); } +/* wav */ +static void handle_wav (Audiodev *dev) +{ +get_int ("QEMU_WAV_FREQUENCY" , + &dev->out->frequency, &dev->out->has_frequency); +get_fmt ("QEMU_WAV_FORMAT" , &dev->out->format, &dev->out->has_format); +get_int ("QEMU_WAV_DAC_FIXED_CHANNELS" , + &dev->out->channels, &dev->out->has_channels); +get_str ("QEMU_WAV_PATH" , &dev->u.wav.path, &dev->u.wav.has_path); +} +/* general */ static void handle_per_direction (AudiodevPerDirectionOptions *pdo,const char *prefix)
@@ -360,6 +371,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)handle_sdl (e->dev);break ; +case AUDIODEV_DRIVER_WAV : +handle_wav (e->dev); +break ; +default :break ; }
audio/wavaudio.c +9 -49
105 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 15/50 audio: reduce glob_audio_state usage
In reply to Kővágó, ZoltánRemove 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).
--- audio/audio_int.h | 7 +++++ audio/audio_template.h | 46 ++++++++++++++++---------------- audio/audio.c | 59 +++++++++++++++++++----------------------- 3 files changed, 56 insertions(+), 56 deletions(-)
audio/audio_int.h +7 -0
@@ -52,6 +52,7 @@ struct audio_pcm_info {typedef struct SWVoiceCap SWVoiceCap ; typedef struct HWVoiceOut { + AudioState *s; int enabled; int poll_mode; int pending_disable;
@@ -73,6 +74,7 @@ typedef struct HWVoiceOut { } HWVoiceOut; typedef struct HWVoiceIn { + AudioState *s; int enabled; int poll_mode; struct audio_pcm_info info;
@@ -94,6 +96,7 @@ typedef struct HWVoiceIn {struct SWVoiceOut {QEMUSoundCard *card; +AudioState *s;struct audio_pcm_info info;t_sample *conv;int64_t ratio;
@@ -111,6 +114,7 @@ struct SWVoiceOut {struct SWVoiceIn {QEMUSoundCard *card; +AudioState *s;int active;struct audio_pcm_info info;int64_t ratio;
@@ -188,6 +192,9 @@ struct AudioState {int nb_hw_voices_in;int vm_running;int64_t period_ticks; + +bool timer_running; +uint64_t timer_last; };extern const struct mixeng_volume nominal_volume;
audio/audio_template.h +22 -24
137 lines not on this page · raw message
audio/audio.c +27 -32
175 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 19/50 paaudio: do not move stream when sink/source name is specified
In reply to Kővágó, ZoltánUnless we disable stream moving, pulseaudio can easily move the stream on connect, effectively ignoring the source/sink specified by the user.
--- audio/paaudio.c | 5 +++++ 1 file changed, 5 insertions(+)
audio/paaudio.c +5 -0
@@ -516,6 +516,11 @@ static pa_stream *qpa_simple_new (#endif |PA_STREAM_AUTO_TIMING_UPDATE; +if (dev) { +/* don't move the stream if the user specified a sink/source */ + flags |=PA_STREAM_DONT_MOVE ; + } +if (dir ==PA_STREAM_PLAYBACK ) { r =pa_stream_connect_playback (stream, dev, attr, flags,NULL ,NULL ); }else {
Signature · 1 line
2.20.1
PATCH v3 7/50 dsoundaudio: port to -audiodev config
In reply to Kővágó, Zoltán--- audio/dsound_template.h | 6 ++--- audio/audio_legacy.c | 39 +++++++++++++++++++++++++++ audio/dsoundaudio.c | 59 ++++++++++++----------------------------- 3 files changed, 59 insertions(+), 45 deletions(-)
audio/dsound_template.h +3 -3
@@ -167,17 +167,18 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,dsound *s = drv_opaque;WAVEFORMATEX wfx;struct audsettings obt_as; -DSoundConf *conf = &s->conf;#ifdef DSBTYPE_IN const char *typ ="ADC" ;DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;DSCBUFFERDESC bd;DSCBCAPS bc; +AudiodevPerDirectionOptions *pdo = s->dev->in;#else const char *typ ="DAC" ;DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;DSBUFFERDESC bd;DSBCAPS bc; +AudiodevPerDirectionOptions *pdo = s->dev->out;#endif if (!s->FIELD2) {
@@ -193,8 +194,8 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,memset (&bd,0 ,sizeof (bd)); bd.dwSize =sizeof (bd); bd.lpwfxFormat = &wfx; + bd.dwBufferBytes =audio_buffer_bytes (pdo, as,92880 );#ifdef DSBTYPE_IN - bd.dwBufferBytes = conf->bufsize_in; hr = IDirectSoundCapture_CreateCaptureBuffer ( s->dsound_capture, &bd,
@@ -203,7 +204,6 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as, );#else bd.dwFlags =DSBCAPS_STICKYFOCUS |DSBCAPS_GETCURRENTPOSITION2 ; - bd.dwBufferBytes = conf->bufsize_out; hr = IDirectSound_CreateSoundBuffer ( s->dsound, &bd,
audio/audio_legacy.c +39 -0
@@ -120,6 +120,30 @@ static void get_frames_to_usecs(const char *env, uint32_t *dst, bool *has_dst, } } +static uint32_t samples_to_usecs (uint32_t samples, +AudiodevPerDirectionOptions *pdo) +{ +uint32_t channels = pdo->has_channels ? pdo->channels :2 ; +return frames_to_usecs (samples / channels, pdo); +} + +static uint32_t bytes_to_usecs (uint32_t bytes,AudiodevPerDirectionOptions *pdo) +{ +AudioFormat fmt = pdo->has_format ? pdo->format :AUDIO_FORMAT_S16 ; +uint32_t bytes_per_sample =audioformat_bytes_per_sample (fmt); +return samples_to_usecs (bytes / bytes_per_sample, pdo); +} + +static void get_bytes_to_usecs (const char *env,uint32_t *dst,bool *has_dst, +AudiodevPerDirectionOptions *pdo) +{ +const char *val =getenv (env); +if (val) { + *dst =bytes_to_usecs (toui32 (val), pdo); + *has_dst = true; + } +} +/* backend specific functions */ /* ALSA */ static void handle_alsa_per_direction(
@@ -186,6 +210,17 @@ static void handle_coreaudio(Audiodev *dev) &dev->out->buffer_count, &dev->out->has_buffer_count); } +/* dsound */ +static void handle_dsound (Audiodev *dev) +{ +get_millis_to_usecs ("QEMU_DSOUND_LATENCY_MILLIS" , + &dev->u.dsound.latency, &dev->u.dsound.has_latency); +get_bytes_to_usecs ("QEMU_DSOUND_BUFSIZE_OUT" , &dev->out->buffer_len, + &dev->out->has_buffer_len, dev->out); +get_bytes_to_usecs ("QEMU_DSOUND_BUFSIZE_IN" , &dev->in->buffer_len, + &dev->in->has_buffer_len, dev->in); +} +/* general */ static void handle_per_direction (AudiodevPerDirectionOptions *pdo,const char *prefix)
@@ -237,6 +272,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)handle_coreaudio (e->dev);break ; +case AUDIODEV_DRIVER_DSOUND : +handle_dsound (e->dev); +break ; +default :break ; }
audio/dsoundaudio.c +17 -42
125 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 10/50 paaudio: port to -audiodev config
In reply to Kővágó, Zoltán--- audio/audio_legacy.c | 39 +++++++++++++++++++ audio/paaudio.c | 90 ++++++++++++++++++++------------------------ 2 files changed, 79 insertions(+), 50 deletions(-)
audio/audio_legacy.c +39 -0
@@ -127,6 +127,16 @@ static uint32_t samples_to_usecs(uint32_t samples,return frames_to_usecs (samples / channels, pdo); } +static void get_samples_to_usecs (const char *env,uint32_t *dst,bool *has_dst, +AudiodevPerDirectionOptions *pdo) +{ +const char *val =getenv (env); +if (val) { + *dst =samples_to_usecs (toui32 (val), pdo); + *has_dst = true; + } +} +static uint32_t bytes_to_usecs (uint32_t bytes,AudiodevPerDirectionOptions *pdo) {AudioFormat fmt = pdo->has_format ? pdo->format :AUDIO_FORMAT_S16 ;
@@ -250,6 +260,31 @@ static void handle_oss(Audiodev *dev)get_int ("QEMU_OSS_POLICY" , &oopt->dsp_policy, &oopt->has_dsp_policy); } +/* pulseaudio */ +static void handle_pa_per_direction ( +AudiodevPaPerDirectionOptions **ppdo,bool *has_ppdo,const char *env) +{ + *ppdo =g_malloc0 (sizeof (AudiodevPaPerDirectionOptions)); + *has_ppdo = true; + +get_str (env, &(*ppdo)->name, &(*ppdo)->has_name); +} + +static void handle_pa (Audiodev *dev) +{ +handle_pa_per_direction (&dev->u.pa.sink, &dev->u.pa.has_sink, +"QEMU_PA_SINK" ); +handle_pa_per_direction (&dev->u.pa.source, &dev->u.pa.has_source, +"QEMU_PA_SOURCE" ); + +get_samples_to_usecs ("QEMU_PA_SAMPLES" , &dev->in->buffer_len, + &dev->in->has_buffer_len, dev->in); +get_samples_to_usecs ("QEMU_PA_SAMPLES" , &dev->out->buffer_len, + &dev->out->has_buffer_len, dev->out); + +get_str ("QEMU_PA_SERVER" , &dev->u.pa.server, &dev->u.pa.has_server); +} +/* general */ static void handle_per_direction (AudiodevPerDirectionOptions *pdo,const char *prefix)
@@ -309,6 +344,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)handle_oss (e->dev);break ; +case AUDIODEV_DRIVER_PA : +handle_pa (e->dev); +break ; +default :break ; }
audio/paaudio.c +40 -50
195 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 11/50 sdlaudio: port to -audiodev config
In reply to Kővágó, Zoltán--- audio/audio_legacy.c | 12 ++++++++++++ audio/sdlaudio.c | 22 ++++------------------ 2 files changed, 16 insertions(+), 18 deletions(-)
audio/audio_legacy.c +12 -0
@@ -285,6 +285,14 @@ static void handle_pa(Audiodev *dev)get_str ("QEMU_PA_SERVER" , &dev->u.pa.server, &dev->u.pa.has_server); } +/* SDL */ +static void handle_sdl (Audiodev *dev) +{ +/* SDL is output only */ +get_samples_to_usecs ("QEMU_SDL_SAMPLES" , &dev->out->buffer_len, + &dev->out->has_buffer_len, dev->out); +} +/* general */ static void handle_per_direction (AudiodevPerDirectionOptions *pdo,const char *prefix)
@@ -348,6 +356,10 @@ static AudiodevListEntry *legacy_opt(const char *drvname)handle_pa (e->dev);break ; +case AUDIODEV_DRIVER_SDL : +handle_sdl (e->dev); +break ; +default :break ; }
audio/sdlaudio.c +4 -18
@@ -49,12 +49,6 @@ typedef struct SDLVoiceOut {int decr; } SDLVoiceOut; -static struct { -int nb_samples; -} conf = { - .nb_samples =1024 -}; - static struct SDLAudioState { int exit; #if USE_SEMAPHORE
@@ -63,6 +57,7 @@ static struct SDLAudioState {#endif int initialized;bool driver_created; +Audiodev *dev; } glob_sdl;typedef struct SDLAudioState SDLAudioState ;
@@ -392,7 +387,7 @@ static int sdl_init_out(HWVoiceOut *hw, struct audsettings *as, req.freq = as->freq; req.format =aud_to_sdlfmt (as->fmt); req.channels = as->nchannels; - req.samples = conf.nb_samples; + req.samples =audio_buffer_samples (s->dev->out, as,11610 ); req.callback = sdl_callback; req.userdata = sdl;
@@ -467,6 +462,7 @@ static void *sdl_audio_init(Audiodev *dev)#endif s->driver_created = true; + s->dev = dev;return s; }
@@ -480,18 +476,9 @@ static void sdl_audio_fini (void *opaque)#endif SDL_QuitSubSystem (SDL_INIT_AUDIO ); s->driver_created = false; + s->dev =NULL ; } -static struct audio_option sdl_options[] = { - { - .name ="SAMPLES" , - .tag =AUD_OPT_INT , - .valp = &conf.nb_samples, - .descr ="Size of SDL buffer in samples" - }, - {/* End of list */ } -}; -static struct audio_pcm_ops sdl_pcm_ops = { .init_out = sdl_init_out, .fini_out = sdl_fini_out,
@@ -503,7 +490,6 @@ static struct audio_pcm_ops sdl_pcm_ops = {static struct audio_driver sdl_audio_driver = { .name ="sdl" , .descr ="SDL http://www.libsdl.org" , - .options = sdl_options, .init = sdl_audio_init, .fini = sdl_audio_fini, .pcm_ops = &sdl_pcm_ops,
Signature · 1 line
2.20.1
PATCH v3 12/50 spiceaudio: port to -audiodev config
In reply to Kővágó, Zoltán--- audio/spiceaudio.c | 5 ----- 1 file changed, 5 deletions(-)
audio/spiceaudio.c +0 -5
@@ -373,10 +373,6 @@ static int line_in_ctl (HWVoiceIn *hw, int cmd, ...)return 0 ; } -static struct audio_option audio_options[] = { - {/* end of list */ }, -}; -static struct audio_pcm_ops audio_callbacks = { .init_out = line_out_init, .fini_out = line_out_fini,
@@ -394,7 +390,6 @@ static struct audio_pcm_ops audio_callbacks = {static struct audio_driver spice_audio_driver = { .name ="spice" , .descr ="spice audio driver" , - .options = audio_options, .init = spice_audio_init, .fini = spice_audio_fini, .pcm_ops = &audio_callbacks,
Signature · 1 line
2.20.1
PATCH v3 14/50 audio: -audiodev command line option: cleanup
In reply to Kővágó, ZoltánRemove no longer needed code.
--- audio/audio_int.h | 17 ---- audio/audio.c | 201 +--------------------------------------------- 2 files changed, 4 insertions(+), 214 deletions(-)
audio/audio_int.h +0 -17
@@ -33,22 +33,6 @@struct audio_pcm_ops ; -typedef enum { -AUD_OPT_INT , -AUD_OPT_FMT , -AUD_OPT_STR , -AUD_OPT_BOOL -}audio_option_tag_e ; - -struct audio_option { -const char *name; -audio_option_tag_e tag; -void *valp; -const char *descr; -int *overriddenp; -int overridden; -}; -struct audio_callback {void *opaque;audio_callback_fn fn;
@@ -145,7 +129,6 @@ typedef struct audio_driver audio_driver;struct audio_driver {const char *name;const char *descr; -struct audio_option *options;void *(*init) (Audiodev *);void (*fini) (void *);struct audio_pcm_ops *pcm_ops;
audio/audio.c +4 -197
240 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 20/50 paaudio: properly disconnect streams in fini_*
In reply to Kővágó, ZoltánCurrently this needs a workaround due to bug #74624 in pulseaudio.
--- audio/paaudio.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
audio/paaudio.c +23 -2
@@ -680,6 +680,27 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)return -1 ; } +static void qpa_simple_disconnect (PAConnection *c,pa_stream *stream) +{ +int err; + +pa_threaded_mainloop_lock (c->mainloop); +/* +* wait until actually connects. workaround pa bug #74624 +* https://bugs.freedesktop.org/show_bug.cgi?id=74624 +*/ +while (pa_stream_get_state (stream) ==PA_STREAM_CREATING ) { +pa_threaded_mainloop_wait (c->mainloop); + } + + err =pa_stream_disconnect (stream); +if (err !=0 ) { +dolog ("Failed to dissconnect! err=%d\n" , err); + } +pa_stream_unref (stream); +pa_threaded_mainloop_unlock (c->mainloop); +} +static void qpa_fini_out (HWVoiceOut *hw) {void *ret;
@@ -691,7 +712,7 @@ static void qpa_fini_out (HWVoiceOut *hw)audio_pt_join (&pa->pt, &ret, __func__);if (pa->stream) { -pa_stream_unref (pa->stream); +qpa_simple_disconnect (pa->g->conn, pa->stream); pa->stream =NULL ; }
@@ -711,7 +732,7 @@ static void qpa_fini_in (HWVoiceIn *hw)audio_pt_join (&pa->pt, &ret, __func__);if (pa->stream) { -pa_stream_unref (pa->stream); +qpa_simple_disconnect (pa->g->conn, pa->stream); pa->stream =NULL ; }
Signature · 1 line
2.20.1
PATCH v3 22/50 audio: do not run each backend in audio_run
In reply to Kővágó, Zoltánaudio_run is called manually by alsa and oss backends when polling. In this case only the requesting backend should be run, not all of them.
--- audio/audio_int.h | 2 +- audio/alsaaudio.c | 7 +++++-- audio/audio.c | 14 +++++--------- audio/ossaudio.c | 12 ++++++------ 4 files changed, 17 insertions(+), 18 deletions(-)
audio/audio_int.h +1 -1
@@ -220,7 +220,7 @@ int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,int audio_bug (const char *funcname,int cond);void *audio_calloc (const char *funcname,int nmemb,size_t size); -void audio_run (const char *msg); +void audio_run (AudioState *s,const char *msg);#define VOICE_ENABLE 1#define VOICE_DISABLE 2
audio/alsaaudio.c +5 -2
@@ -38,6 +38,7 @@ struct pollhlp {struct pollfd *pfds;int count;int mask; +AudioState *s; }; typedef struct ALSAVoiceOut {
@@ -198,11 +199,11 @@ static void alsa_poll_handler (void *opaque)break ;case SND_PCM_STATE_PREPARED : -audio_run ("alsa run (prepared)" ); +audio_run (hlp->s,"alsa run (prepared)" );break ;case SND_PCM_STATE_RUNNING : -audio_run ("alsa run (running)" ); +audio_run (hlp->s,"alsa run (running)" );break ;default :
@@ -756,6 +757,7 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,return -1 ; } + alsa->pollhlp.s = hw->s; alsa->handle = handle; alsa->dev = dev;return 0 ;
@@ -857,6 +859,7 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)return -1 ; } + alsa->pollhlp.s = hw->s; alsa->handle = handle; alsa->dev = dev;return 0 ;
audio/audio.c +5 -9
@@ -838,7 +838,7 @@ static void audio_timer (void *opaque) } s->timer_last = now; -audio_run ("timer" ); +audio_run (s,"timer" );audio_reset_timer (s); }
@@ -1240,15 +1240,11 @@ static void audio_run_capture (AudioState *s) } } -void audio_run (const char *msg) +void audio_run (AudioState *s,const char *msg) { -AudioState *s; - - QTAILQ_FOREACH(s, &audio_states, list) { -audio_run_out (s); -audio_run_in (s); -audio_run_capture (s); - } +audio_run_out (s); +audio_run_in (s); +audio_run_capture (s);#ifdef DEBUG_POLL {
audio/ossaudio.c +6 -6
@@ -109,28 +109,28 @@ static void oss_anal_close (int *fdp)static void oss_helper_poll_out (void *opaque) { - (void ) opaque; -audio_run ("oss_poll_out" ); +AudioState *s = opaque; +audio_run (s,"oss_poll_out" ); }static void oss_helper_poll_in (void *opaque) { - (void ) opaque; -audio_run ("oss_poll_in" ); +AudioState *s = opaque; +audio_run (s,"oss_poll_in" ); }static void oss_poll_out (HWVoiceOut *hw) {OSSVoiceOut *oss = (OSSVoiceOut *) hw; -qemu_set_fd_handler (oss->fd,NULL , oss_helper_poll_out,NULL ); +qemu_set_fd_handler (oss->fd,NULL , oss_helper_poll_out, hw->s); }static void oss_poll_in (HWVoiceIn *hw) {OSSVoiceIn *oss = (OSSVoiceIn *) hw; -qemu_set_fd_handler (oss->fd, oss_helper_poll_in,NULL ,NULL ); +qemu_set_fd_handler (oss->fd, oss_helper_poll_in,NULL , hw->s); }static int oss_write (SWVoiceOut *sw,void *buf,int len)
Signature · 1 line
2.20.1
PATCH v3 16/50 audio: basic support for multi backend audio
In reply to Kővágó, ZoltánAudio functions no longer access glob_audio_state, instead they get an AudioState as a parameter. This is required in order to support multiple backends.
glob_audio_state is also gone, and replaced with a tailq so we can store more than one states.
--- audio/audio.h | 12 +++-- audio/audio_int.h | 2 + audio/audio_template.h | 2 +- ui/vnc.h | 2 + audio/audio.c | 102 +++++++++++++++++++++++++++++++---------- audio/wavcapture.c | 6 +-- monitor.c | 12 ++++- ui/vnc.c | 15 +++++- hmp-commands.hx | 11 +++-- qemu-options.hx | 5 ++ 10 files changed, 131 insertions(+), 38 deletions(-)
audio/audio.h +9 -3
@@ -78,8 +78,10 @@ typedef struct SWVoiceOut SWVoiceOut;typedef struct CaptureVoiceOut CaptureVoiceOut ;typedef struct SWVoiceIn SWVoiceIn ; +typedef struct AudioState AudioState ;typedef struct QEMUSoundCard {char *name; +AudioState *state;QLIST_ENTRY (QEMUSoundCard) entries; }QEMUSoundCard ;
@@ -92,7 +94,8 @@ void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);void AUD_register_card (const char *name,QEMUSoundCard *card);void AUD_remove_card (QEMUSoundCard *card); -CaptureVoiceOut *AUD_add_capture ( +CaptureVoiceOut *AUD_add_capture ( +AudioState *s,struct audsettings *as,struct audio_capture_ops *ops, void *opaque
@@ -160,8 +163,8 @@ static inline void *advance (void *p, int incr)#define audio_MAX (a, b) ((a)<(b)?(b):(a))#endif -int wav_start_capture (CaptureState *s,const char *path,int freq, -int bits,int nchannels); +int wav_start_capture (AudioState *state,CaptureState *s,const char *path, +int freq,int bits,int nchannels);bool audio_is_cleaning_up (void );void audio_cleanup (void );
@@ -175,4 +178,7 @@ void audio_parse_option(const char *opt);void audio_init_audiodevs (void );void audio_legacy_help (void ); +AudioState *audio_state_by_name (const char *name); +const char *audio_get_id (QEMUSoundCard *card); +#endif /* QEMU_AUDIO_H */
audio/audio_int.h +2 -0
@@ -195,6 +195,8 @@ struct AudioState {bool timer_running;uint64_t timer_last; + +QTAILQ_ENTRY (AudioState) list; };extern const struct mixeng_volume nominal_volume;
audio/audio_template.h +1 -1
@@ -399,7 +399,7 @@ SW *glue (AUD_open_, TYPE) (struct audsettings *as ) { -AudioState *s = &glob_audio_state; +AudioState *s = card->state;AudiodevPerDirectionOptions *pdo = s->dev->TYPE;if (audio_bug (__func__, !card || !name || !callback_fn || !as)) {
ui/vnc.h +2 -0
@@ -181,6 +181,8 @@ struct VncDisplay#ifdef CONFIG_VNC_SASL VncDisplaySASL sasl;#endif + +AudioState *audio_state; }; typedef struct VncTight {
audio/audio.c +78 -24
191 lines not on this page · raw message
audio/wavcapture.c +3 -3
@@ -107,8 +107,8 @@ static struct capture_ops wav_capture_ops = { .info = wav_capture_info }; -int wav_start_capture (CaptureState *s,const char *path,int freq, -int bits,int nchannels) +int wav_start_capture (AudioState *state,CaptureState *s,const char *path, +int freq,int bits,int nchannels) {Monitor *mon = cur_mon;WAVState *wav;
@@ -175,7 +175,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq, goto error_free; } - cap =AUD_add_capture (&as, &ops, wav); + cap =AUD_add_capture (state, &as, &ops, wav);if (!cap) {monitor_printf (mon,"Failed to add audio capture\n" ); goto error_free;
monitor.c +11 -1
@@ -2038,7 +2038,17 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)int bits =qdict_get_try_int (qdict,"bits" ,-1 );int has_channels =qdict_haskey (qdict,"nchannels" );int nchannels =qdict_get_try_int (qdict,"nchannels" ,-1 ); +const char *audiodev =qdict_get_try_str (qdict,"audiodev" );CaptureState *s; +AudioState *as =NULL ; + +if (audiodev) { + as =audio_state_by_name (audiodev); +if (!as) { +monitor_printf (mon,"Invalid audiodev specified\n" ); +return ; + } + } s =g_malloc0 (sizeof (*s));
@@ -2046,7 +2056,7 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict) bits = has_bits ? bits :16 ; nchannels = has_channels ? nchannels :2 ; -if (wav_start_capture (s, path, freq, bits, nchannels)) { +if (wav_start_capture (as, s, path, freq, bits, nchannels)) {monitor_printf (mon,"Failed to add wave capture\n" );g_free (s);return ;
ui/vnc.c +14 -1
@@ -1195,7 +1195,7 @@ static void audio_add(VncState *vs) ops.destroy = audio_capture_destroy; ops.capture = audio_capture; - vs->audio_cap =AUD_add_capture (&vs->as, &ops, vs); + vs->audio_cap =AUD_add_capture (vs->vd->audio_state, &vs->as, &ops, vs);if (!vs->audio_cap) {error_report ("Failed to add audio capture" ); }
@@ -3390,6 +3390,9 @@ static QemuOptsList qemu_vnc_opts = { },{ .name = "non-adaptive", .type = QEMU_OPT_BOOL, + },{ + .name = "audiodev", + .type = QEMU_OPT_STRING, }, {/* end of list */ } },
@@ -3825,6 +3828,7 @@ void vnc_display_open(const char *id, Error **errp)int acl =0 ;int lock_key_sync =1 ;int key_delay_ms; +const char *audiodev;if (!vd) {error_setg (errp,"VNC display not active" );
@@ -3978,6 +3982,15 @@ void vnc_display_open(const char *id, Error **errp) vd->ledstate =0 ; vd->key_delay_ms = key_delay_ms; + audiodev =qemu_opt_get (opts,"audiodev" ); +if (audiodev) { + vd->audio_state =audio_state_by_name (audiodev); +if (!vd->audio_state) { +error_setg (errp,"Audiodev '%s' not found" , audiodev); + goto fail; + } + } + device_id =qemu_opt_get (opts,"display" );if (device_id) {int head =qemu_opt_get_number (opts,"head" ,0 );
hmp-commands.hx +6 -5
@@ -796,16 +796,17 @@ ETEXI { .name = "wavcapture", - .args_type = "path:F,freq:i?,bits:i?,nchannels:i?", - .params = "path [frequency [bits [channels]]]", + .args_type = "path:F,freq:i?,bits:i?,nchannels:i?,audiodev:s?", + .params = "path [frequency [bits [channels [audiodev]]]]", .help = "capture audio to a wave file (default frequency=44100 bits=16 channels=2)", .cmd = hmp_wavcapture, }, STEXI -@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels}]]] +@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels} [@var{audiodev}]]]] @findex wavcapture -Capture audio into @var{filename}. Using sample rate @var{frequency} -bits per sample @var{bits} and number of channels @var{channels}. +Capture audio into @var{filename} from @var{audiodev}. Using sample rate +@var{frequency} bits per sample @var{bits} and number of channels +@var{channels}. Defaults: @itemize @minus
qemu-options.hx +5 -0
@@ -1911,6 +1911,11 @@ can help the device and guest to keep up and not lose events in case events are arriving in bulk. Possible causes for the latter are flaky network connections, or scripts for automated testing. +@item audiodev=@var{audiodev} + +Use the specified @var{audiodev} when the VNC client requests audio +transmission. + @end table ETEXI
Signature · 1 line
2.20.1
PATCH v3 17/50 audio: add audiodev properties to frontends
In reply to Kővágó, ZoltánFinally add audiodev= options to audio frontends so users can specify which backend to use when multiple backends exist. Not specifying an audiodev= option currently causes the first audiodev to be used, this is fixed in the next commit.
Example usage: -audiodev pa,id=foo -device AC97,audiodev=foo
--- audio/audio.h | 3 ++ include/hw/qdev-properties.h | 3 ++ hw/audio/ac97.c | 1 + hw/audio/adlib.c | 1 + hw/audio/cs4231a.c | 1 + hw/audio/es1370.c | 7 +++- hw/audio/gus.c | 1 + hw/audio/hda-codec.c | 1 + hw/audio/milkymist-ac97.c | 6 ++++ hw/audio/pcspk.c | 1 + hw/audio/pl041.c | 1 + hw/audio/sb16.c | 1 + hw/audio/wm8750.c | 6 ++++ hw/core/qdev-properties-system.c | 57 ++++++++++++++++++++++++++++++++ hw/usb/dev-audio.c | 1 + 15 files changed, 90 insertions(+), 1 deletion(-)
audio/audio.h +3 -0
@@ -181,4 +181,7 @@ void audio_legacy_help(void);AudioState *audio_state_by_name (const char *name);const char *audio_get_id (QEMUSoundCard *card); +#define DEFINE_AUDIO_PROPERTIES (_s, _f) \ + DEFINE_PROP_AUDIODEV("audiodev", _s, _f) +#endif /* QEMU_AUDIO_H */
include/hw/qdev-properties.h +3 -0
@@ -34,6 +34,7 @@ extern const PropertyInfo qdev_prop_blocksize;extern const PropertyInfo qdev_prop_pci_host_devaddr;extern const PropertyInfo qdev_prop_uuid;extern const PropertyInfo qdev_prop_arraylen; +extern const PropertyInfo qdev_prop_audiodev;extern const PropertyInfo qdev_prop_link;extern const PropertyInfo qdev_prop_off_auto_pcibar;extern const PropertyInfo qdev_prop_pcie_link_speed;
@@ -233,6 +234,8 @@ extern const PropertyInfo qdev_prop_pcie_link_width; + type_check(QemuUUID, typeof_field(_state, _field)), \ .set_default = true, \ } +#define DEFINE_PROP_AUDIODEV (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)#define DEFINE_PROP_END_OF_LIST () \ {}
hw/audio/ac97.c +1 -0
@@ -1408,6 +1408,7 @@ static int ac97_init (PCIBus *bus) }static Property ac97_properties[] = { +DEFINE_AUDIO_PROPERTIES (AC97LinkState, card),DEFINE_PROP_UINT32 ("use_broken_id" , AC97LinkState, use_broken_id,0 ),DEFINE_PROP_END_OF_LIST (), };
hw/audio/adlib.c +1 -0
@@ -298,6 +298,7 @@ static void adlib_realizefn (DeviceState *dev, Error **errp) }static Property adlib_properties[] = { +DEFINE_AUDIO_PROPERTIES (AdlibState, card),DEFINE_PROP_UINT32 ("iobase" , AdlibState, port,0x220 ),DEFINE_PROP_UINT32 ("freq" , AdlibState, freq,44100 ),DEFINE_PROP_END_OF_LIST (),
hw/audio/cs4231a.c +1 -0
@@ -687,6 +687,7 @@ static int cs4231a_init (ISABus *bus) }static Property cs4231a_properties[] = { +DEFINE_AUDIO_PROPERTIES (CSState, card),DEFINE_PROP_UINT32 ("iobase" , CSState, port,0x534 ),DEFINE_PROP_UINT32 ("irq" , CSState, irq,9 ),DEFINE_PROP_UINT32 ("dma" , CSState, dma,3 ),
hw/audio/es1370.c +6 -1
@@ -886,6 +886,11 @@ static int es1370_init (PCIBus *bus)return 0 ; } +static Property es1370_properties[] = { +DEFINE_AUDIO_PROPERTIES (ES1370State, card), +DEFINE_PROP_END_OF_LIST (), +}; +static void es1370_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -902,6 +907,7 @@ static void es1370_class_init (ObjectClass *klass, void *data) dc->desc ="ENSONIQ AudioPCI ES1370" ; dc->vmsd = &vmstate_es1370; dc->reset = es1370_on_reset; + dc->props = es1370_properties; }static const TypeInfo es1370_info = {
@@ -922,4 +928,3 @@ static void es1370_register_types (void) }type_init (es1370_register_types) -
hw/audio/gus.c +1 -0
@@ -295,6 +295,7 @@ static int GUS_init (ISABus *bus) }static Property gus_properties[] = { +DEFINE_AUDIO_PROPERTIES (GUSState, card),DEFINE_PROP_UINT32 ("freq" , GUSState, freq,44100 ),DEFINE_PROP_UINT32 ("iobase" , GUSState, port,0x240 ),DEFINE_PROP_UINT32 ("irq" , GUSState, emu.gusirq,7 ),
hw/audio/hda-codec.c +1 -0
@@ -839,6 +839,7 @@ static const VMStateDescription vmstate_hda_audio = { };static Property hda_audio_properties[] = { +DEFINE_AUDIO_PROPERTIES (HDAAudioState, card),DEFINE_PROP_UINT32 ("debug" , HDAAudioState, debug,0 ),DEFINE_PROP_BOOL ("mixer" , HDAAudioState, mixer, true),DEFINE_PROP_BOOL ("use-timer" , HDAAudioState, use_timer, true),
hw/audio/milkymist-ac97.c +6 -0
@@ -328,6 +328,11 @@ static const VMStateDescription vmstate_milkymist_ac97 = { } }; +static Property milkymist_ac97_properties[] = { +DEFINE_AUDIO_PROPERTIES (MilkymistAC97State, card), +DEFINE_PROP_END_OF_LIST (), +}; +static void milkymist_ac97_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -335,6 +340,7 @@ static void milkymist_ac97_class_init(ObjectClass *klass, void *data) dc->realize = milkymist_ac97_realize; dc->reset = milkymist_ac97_reset; dc->vmsd = &vmstate_milkymist_ac97; + dc->props = milkymist_ac97_properties; }static const TypeInfo milkymist_ac97_info = {
hw/audio/pcspk.c +1 -0
@@ -208,6 +208,7 @@ static const VMStateDescription vmstate_spk = { };static Property pcspk_properties[] = { +DEFINE_AUDIO_PROPERTIES (PCSpkState, card),DEFINE_PROP_UINT32 ("iobase" , PCSpkState, iobase,-1 ),DEFINE_PROP_BOOL ("migrate" , PCSpkState, migrate, true),DEFINE_PROP_END_OF_LIST (),
hw/audio/pl041.c +1 -0
@@ -621,6 +621,7 @@ static const VMStateDescription vmstate_pl041 = { };static Property pl041_device_properties[] = { +DEFINE_AUDIO_PROPERTIES (PL041State, codec.card),/* Non-compact FIFO depth property */ DEFINE_PROP_UINT32 ("nc_fifo_depth" , PL041State, fifo_depth,DEFAULT_FIFO_DEPTH ),
hw/audio/sb16.c +1 -0
@@ -1419,6 +1419,7 @@ static int SB16_init (ISABus *bus) }static Property sb16_properties[] = { +DEFINE_AUDIO_PROPERTIES (SB16State, card),DEFINE_PROP_UINT32 ("version" , SB16State, ver,0x0405 ),/* 4.5 */ DEFINE_PROP_UINT32 ("iobase" , SB16State, port,0x220 ),DEFINE_PROP_UINT32 ("irq" , SB16State, irq,5 ),
hw/audio/wm8750.c +6 -0
@@ -700,6 +700,11 @@ void wm8750_set_bclk_in(void *opaque, int new_hz)wm8750_clk_update (s,1 ); } +static Property wm8750_properties[] = { +DEFINE_AUDIO_PROPERTIES (WM8750State, card), +DEFINE_PROP_END_OF_LIST (), +}; +static void wm8750_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -710,6 +715,7 @@ static void wm8750_class_init(ObjectClass *klass, void *data) sc->recv = wm8750_rx; sc->send = wm8750_tx; dc->vmsd = &vmstate_wm8750; + dc->props = wm8750_properties; }static const TypeInfo wm8750_info = {
hw/core/qdev-properties-system.c +57 -0
69 lines not on this page · raw message
hw/usb/dev-audio.c +1 -0
@@ -666,6 +666,7 @@ static const VMStateDescription vmstate_usb_audio = { };static Property usb_audio_properties[] = { +DEFINE_AUDIO_PROPERTIES (USBAudioState, card),DEFINE_PROP_UINT32 ("debug" , USBAudioState, debug,0 ),DEFINE_PROP_UINT32 ("buffer" , USBAudioState, buffer,32 *USBAUDIO_PACKET_SIZE ),
Signature · 1 line
2.20.1
PATCH v3 18/50 audio: audiodev= parameters no longer optional when -audiodev present
In reply to Kővágó, ZoltánThis means you should probably stop using -soundhw (as it doesn't allow you to specify any options) and add the device manually with -device. The exception is pcspk, it's currently not possible to manually add it. To use it with audiodev, use something like this:
-audiodev id=foo,... -global isa-pcspk.audiodev=foo -soundhw pcspk
--- audio/audio.c | 24 ++-- audio/paaudio.c | 304 ++++++++++++++++++++++++++++-------------------- 2 files changed, 190 insertions(+), 138 deletions(-)
audio/audio.c +15 -9
@@ -99,6 +99,8 @@ const struct mixeng_volume nominal_volume = {#endif }; +static bool legacy_config = true; +#ifdef AUDIO_IS_FLAWLESS_AND_NO_CHECKS_ARE_REQURIED #error No its not#else
@@ -1393,7 +1395,7 @@ static AudiodevListEntry *audiodev_find(* if dev == NULL => legacy implicit initialization, return the already created * state or create a new one */ -static AudioState *audio_init (Audiodev *dev) +static AudioState *audio_init (Audiodev *dev,const char *name) {static bool atexit_registered;size_t i;
@@ -1407,12 +1409,13 @@ static AudioState *audio_init(Audiodev *dev)if (dev) {/* -audiodev option */ + legacy_config = false; drvname =AudiodevDriver_str (dev->driver); }else if (!QTAILQ_EMPTY (&audio_states)) { -/* -* todo: check for -audiodev once we have normal audiodev selection -* support -*/ +if (!legacy_config) { +dolog ("You must specify an audiodev= for the device %s\n" , name); +exit (1 ); + }return QTAILQ_FIRST (&audio_states); }else {/* legacy implicit initialization */
@@ -1518,7 +1521,7 @@ void audio_free_audiodev_list(AudiodevListHead *head)void AUD_register_card (const char *name,QEMUSoundCard *card) {if (!card->state) { - card->state =audio_init (NULL ); + card->state =audio_init (NULL , name); } card->name =g_strdup (name);
@@ -1544,8 +1547,11 @@ CaptureVoiceOut *AUD_add_capture(struct capture_callback *cb;if (!s) { -/* todo: remove when we have normal audiodev selection support */ - s =audio_init (NULL ); +if (!legacy_config) { +dolog ("You must specify audiodev when trying to capture\n" ); + goto err0; + } + s =audio_init (NULL ,NULL ); }if (audio_validate_settings (as)) {
@@ -1778,7 +1784,7 @@ void audio_init_audiodevs(void)AudiodevListEntry *e; QSIMPLEQ_FOREACH(e, &audiodevs, next) { -audio_init (e->dev); +audio_init (e->dev,NULL ); } }
audio/paaudio.c +175 -129
551 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 23/50 paaudio: fix playback glitches
In reply to Kővágó, ZoltánPulseaudio normally assumes that when the server wants it, the client can generate the audio samples and send it right away. Unfortunately this is not the case with QEMU -- it's up to the emulated system when does it generate the samples. Buffering the samples and sending them from a background thread is just a workaround, that doesn't work too well. Instead enable pa's compatibility support and let pa worry about the details.
--- audio/paaudio.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
audio/paaudio.c +2 -4
@@ -511,10 +511,8 @@ static pa_stream *qpa_simple_new ( flags =PA_STREAM_INTERPOLATE_TIMING -#ifdef PA_STREAM_ADJUST_LATENCY - |PA_STREAM_ADJUST_LATENCY -#endif - |PA_STREAM_AUTO_TIMING_UPDATE ; + |PA_STREAM_AUTO_TIMING_UPDATE + |PA_STREAM_EARLY_REQUESTS ;if (dev) {/* don't move the stream if the user specified a sink/source */
Signature · 1 line
2.20.1
PATCH v3 5/50 alsaaudio: port to -audiodev config
In reply to Kővágó, Zoltán--- audio/alsaaudio.c | 330 ++++++++++++++----------------------------- audio/audio_legacy.c | 94 +++++++++++- 2 files changed, 198 insertions(+), 226 deletions(-)
audio/alsaaudio.c +105 -225
@@ -33,28 +33,9 @@#define AUDIO_CAP "alsa"#include "audio_int.h" -typedef struct ALSAConf { -int size_in_usec_in; -int size_in_usec_out; -const char *pcm_name_in; -const char *pcm_name_out; -unsigned int buffer_size_in; -unsigned int period_size_in; -unsigned int buffer_size_out; -unsigned int period_size_out; -unsigned int threshold; - -int buffer_size_in_overridden; -int period_size_in_overridden; - -int buffer_size_out_overridden; -int period_size_out_overridden; -}ALSAConf ; -struct pollhlp {snd_pcm_t *handle;struct pollfd *pfds; -ALSAConf *conf;int count;int mask; };
@@ -66,6 +47,7 @@ typedef struct ALSAVoiceOut {void *pcm_buf;snd_pcm_t *handle;struct pollhlp pollhlp; +Audiodev *dev; } ALSAVoiceOut; typedef struct ALSAVoiceIn {
@@ -73,16 +55,13 @@ typedef struct ALSAVoiceIn {snd_pcm_t *handle;void *pcm_buf;struct pollhlp pollhlp; +Audiodev *dev; } ALSAVoiceIn;struct alsa_params_req {int freq;snd_pcm_format_t fmt;int nchannels; -int size_in_usec; -int override_mask; -unsigned int buffer_size; -unsigned int period_size; };struct alsa_params_obt {
@@ -408,7 +387,8 @@ static int alsa_to_audfmt (snd_pcm_format_t alsafmt, AudioFormat *fmt,static void alsa_dump_info (struct alsa_params_req *req,struct alsa_params_obt *obt, -snd_pcm_format_t obtfmt) +snd_pcm_format_t obtfmt, +AudiodevPerDirectionOptions *pdo) {dolog ("parameter | requested value | obtained value\n" );dolog ("format | %10d | %10d\n" , req->fmt, obtfmt);
@@ -416,8 +396,9 @@ static void alsa_dump_info (struct alsa_params_req *req, req->nchannels, obt->nchannels);dolog ("frequency | %10d | %10d\n" , req->freq, obt->freq);dolog ("============================================\n" ); -dolog ("requested: buffer size %d period size %d\n" , - req->buffer_size, req->period_size); +dolog ("requested: buffer len %" PRId32" buffer count %" PRId32"\n" , + pdo->has_buffer_len ? pdo->buffer_len :0 , + pdo->has_buffer_count ? pdo->buffer_count :0 );dolog ("obtained: samples %ld\n" , obt->samples); }
@@ -451,23 +432,25 @@ static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold) } } -static int alsa_open (int in,struct alsa_params_req *req, -struct alsa_params_obt *obt,snd_pcm_t **handlep, -ALSAConf *conf) +static int alsa_open (bool in,struct alsa_params_req *req, +struct alsa_params_obt *obt,snd_pcm_t **handlep, +Audiodev *dev) { +AudiodevPerDirectionOptions *pdo = in ? dev->in : dev->out; +AudiodevAlsaOptions *aopts = &dev->u.alsa; +AudiodevAlsaPerDirectionOptions *apdo = + in ? aopts->alsa_in : aopts->alsa_out;snd_pcm_t *handle;snd_pcm_hw_params_t *hw_params;int err; -int size_in_usec;unsigned int freq, nchannels; -const char *pcm_name = in ? conf->pcm_name_in : conf->pcm_name_out; +const char *pcm_name = apdo->has_dev ? apdo->dev :"default" ;snd_pcm_uframes_t obt_buffer_size;const char *typ = in ?"ADC" :"DAC" ;snd_pcm_format_t obtfmt; freq = req->freq; nchannels = req->nchannels; - size_in_usec = req->size_in_usec;snd_pcm_hw_params_alloca (&hw_params);
@@ -527,79 +510,49 @@ static int alsa_open (int in, struct alsa_params_req *req, goto err; } -if (req->buffer_size) { -unsigned long obt; +if (pdo->buffer_count) { +if (pdo->buffer_len) { +int64_t req = pdo->buffer_len * pdo->buffer_count; -if (size_in_usec) {int dir =0 ; -unsigned int btime = req->buffer_size; +unsigned int btime = req; - err =snd_pcm_hw_params_set_buffer_time_near ( - handle, - hw_params, - &btime, - &dir - ); - obt = btime; - } -else { -snd_pcm_uframes_t bsize = req->buffer_size; + err =snd_pcm_hw_params_set_buffer_time_near ( + handle, hw_params, &btime, &dir); - err =snd_pcm_hw_params_set_buffer_size_near ( - handle, - hw_params, - &bsize - ); - obt = bsize; - } -if (err <0 ) { -alsa_logerr2 (err, typ,"Failed to set buffer %s to %d\n" , - size_in_usec ?"time" :"size" , req->buffer_size); - goto err; - } +if (err <0 ) { +alsa_logerr2 (err, typ, +"Failed to set buffer time to %" PRId64"\n" , + req); + goto err; + } -if ((req->override_mask &2 ) && (obt - req->buffer_size)) -dolog ("Requested buffer %s %u was rejected, using %lu\n" , - size_in_usec ?"time" :"size" , req->buffer_size, obt); +if (pdo->has_buffer_count && btime != req) { +dolog ("Requested buffer time %" PRId64 +" was rejected, using %u\n" , req, btime); + } + }else { +dolog ("Can't set buffer-count without buffer-len!\n" ); + } } -if (req->period_size) { -unsigned long obt; +if (pdo->buffer_len) { +int dir =0 ; +unsigned int ptime = pdo->buffer_len; -if (size_in_usec) { -int dir =0 ; -unsigned int ptime = req->period_size; - - err =snd_pcm_hw_params_set_period_time_near ( - handle, - hw_params, - &ptime, - &dir - ); - obt = ptime; - } -else { -int dir =0 ; -snd_pcm_uframes_t psize = req->period_size; - - err =snd_pcm_hw_params_set_period_size_near ( - handle, - hw_params, - &psize, - &dir - ); - obt = psize; - } + err =snd_pcm_hw_params_set_period_time_near (handle, hw_params, &ptime, + &dir);if (err <0 ) { -alsa_logerr2 (err, typ,"Failed to set period %s to %d\n" , - size_in_usec ?"time" :"size" , req->period_size); +alsa_logerr2 (err, typ,"Failed to set period time to %" PRId32"\n" , + pdo->buffer_len); goto err; } -if (((req->override_mask &1 ) && (obt - req->period_size))) -dolog ("Requested period %s %u was rejected, using %lu\n" , - size_in_usec ?"time" :"size" , req->period_size, obt); +if (pdo->has_buffer_len && ptime != pdo->buffer_len) { +dolog ("Requested period time %" PRId32" was rejected, using %d\n" , + pdo->buffer_len, ptime); + } } err =snd_pcm_hw_params (handle, hw_params);
@@ -631,33 +584,10 @@ static int alsa_open (int in, struct alsa_params_req *req, goto err; } -if (!in && conf->threshold) { -snd_pcm_uframes_t threshold; -int bytes_per_sec; - - bytes_per_sec = freq << (nchannels ==2 ); - -switch (obt->fmt) { -case AUDIO_FORMAT_S8 : -case AUDIO_FORMAT_U8 : -break ; - -case AUDIO_FORMAT_S16 : -case AUDIO_FORMAT_U16 : - bytes_per_sec <<=1 ; -break ; - -case AUDIO_FORMAT_S32 : -case AUDIO_FORMAT_U32 : - bytes_per_sec <<=2 ; -break ; - -default : -abort (); - } - - threshold = (conf->threshold * bytes_per_sec) /1000 ; -alsa_set_threshold (handle, threshold); +if (!in && aopts->has_threshold && aopts->threshold) { +struct audsettings as = { .freq = freq }; +alsa_set_threshold (handle, +audio_buffer_frames (pdo, &as, aopts->threshold)); } obt->nchannels = nchannels;
@@ -670,11 +600,11 @@ static int alsa_open (int in, struct alsa_params_req *req, obt->nchannels != req->nchannels || obt->freq != req->freq) {dolog ("Audio parameters for %s\n" , typ); -alsa_dump_info (req, obt, obtfmt); +alsa_dump_info (req, obt, obtfmt, pdo); }#ifdef DEBUG -alsa_dump_info (req, obt, obtfmt); +alsa_dump_info (req, obt, obtfmt, pdo);#endif return 0 ;
@@ -800,19 +730,13 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,struct alsa_params_obt obt;snd_pcm_t *handle;struct audsettings obt_as; -ALSAConf *conf = drv_opaque; +Audiodev *dev = drv_opaque; req.fmt =aud_to_alsafmt (as->fmt, as->endianness); req.freq = as->freq; req.nchannels = as->nchannels; - req.period_size = conf->period_size_out; - req.buffer_size = conf->buffer_size_out; - req.size_in_usec = conf->size_in_usec_out; - req.override_mask = - (conf->period_size_out_overridden ?1 :0 ) | - (conf->buffer_size_out_overridden ?2 :0 ); -if (alsa_open (0 , &req, &obt, &handle, conf)) { +if (alsa_open (0 , &req, &obt, &handle, dev)) {return -1 ; }
@@ -833,7 +757,7 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as, } alsa->handle = handle; - alsa->pollhlp.conf = conf; + alsa->dev = dev;return 0 ; }
@@ -873,16 +797,12 @@ static int alsa_voice_ctl (snd_pcm_t *handle, const char *typ, int ctl)static int alsa_ctl_out (HWVoiceOut *hw,int cmd, ...) {ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw; +AudiodevAlsaPerDirectionOptions *apdo = alsa->dev->u.alsa.alsa_out;switch (cmd) {case VOICE_ENABLE : { -va_list ap; -int poll_mode; - -va_start (ap, cmd); - poll_mode =va_arg (ap, int); -va_end (ap); +bool poll_mode = apdo->try_poll;ldebug ("enabling voice\n" );if (poll_mode &&alsa_poll_out (hw)) {
@@ -911,19 +831,13 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)struct alsa_params_obt obt;snd_pcm_t *handle;struct audsettings obt_as; -ALSAConf *conf = drv_opaque; +Audiodev *dev = drv_opaque; req.fmt =aud_to_alsafmt (as->fmt, as->endianness); req.freq = as->freq; req.nchannels = as->nchannels; - req.period_size = conf->period_size_in; - req.buffer_size = conf->buffer_size_in; - req.size_in_usec = conf->size_in_usec_in; - req.override_mask = - (conf->period_size_in_overridden ?1 :0 ) | - (conf->buffer_size_in_overridden ?2 :0 ); -if (alsa_open (1 , &req, &obt, &handle, conf)) { +if (alsa_open (1 , &req, &obt, &handle, dev)) {return -1 ; }
@@ -944,7 +858,7 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) } alsa->handle = handle; - alsa->pollhlp.conf = conf; + alsa->dev = dev;return 0 ; }
@@ -1086,16 +1000,12 @@ static int alsa_read (SWVoiceIn *sw, void *buf, int size)static int alsa_ctl_in (HWVoiceIn *hw,int cmd, ...) {ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw; +AudiodevAlsaPerDirectionOptions *apdo = alsa->dev->u.alsa.alsa_in;switch (cmd) {case VOICE_ENABLE : { -va_list ap; -int poll_mode; - -va_start (ap, cmd); - poll_mode =va_arg (ap, int); -va_end (ap); +bool poll_mode = apdo->try_poll;ldebug ("enabling voice\n" );if (poll_mode &&alsa_poll_in (hw)) {
@@ -1118,88 +1028,59 @@ static int alsa_ctl_in (HWVoiceIn *hw, int cmd, ...)return -1 ; } -static ALSAConf glob_conf = { - .buffer_size_out =4096 , - .period_size_out =1024 , - .pcm_name_out ="default" , - .pcm_name_in ="default" , -}; +static void alsa_init_per_direction (AudiodevAlsaPerDirectionOptions **apdo, +bool *has_apdo) +{ +if (!*has_apdo) { + *apdo =g_malloc0 (sizeof (AudiodevAlsaPerDirectionOptions)); + *has_apdo = true; + } + +if (!(*apdo)->has_try_poll) { + (*apdo)->try_poll = true; + (*apdo)->has_try_poll = true; + } +}static void *alsa_audio_init (Audiodev *dev) { -ALSAConf *conf =g_malloc (sizeof (ALSAConf)); - *conf = glob_conf; -return conf; +AudiodevAlsaOptions *aopts; +assert (dev->driver ==AUDIODEV_DRIVER_ALSA ); + + aopts = &dev->u.alsa; +alsa_init_per_direction (&aopts->alsa_in, &aopts->has_alsa_in); +alsa_init_per_direction (&aopts->alsa_out, &aopts->has_alsa_out); + +/* +* need to define them, as otherwise alsa produces no sound +* doesn't set has_* so alsa_open can identify it wasn't set by the user +*/ +if (!dev->out->has_buffer_count) { + dev->out->buffer_count =4 ; + } +if (!dev->out->has_buffer_len) { +/* 1024 frames assuming 44100Hz */ + dev->out->buffer_len =1024 *1000000 /44100 ; + } + +/* +* OptsVisitor sets unspecified optional fields to zero, but do not depend +* on it... +*/ +if (!dev->in->has_buffer_count) { + dev->in->buffer_count =0 ; + } +if (!dev->in->has_buffer_len) { + dev->in->buffer_len =0 ; + } + +return dev; }static void alsa_audio_fini (void *opaque) { -g_free (opaque); } -static struct audio_option alsa_options[] = { - { - .name ="DAC_SIZE_IN_USEC" , - .tag =AUD_OPT_BOOL , - .valp = &glob_conf.size_in_usec_out, - .descr ="DAC period/buffer size in microseconds (otherwise in frames)" - }, - { - .name ="DAC_PERIOD_SIZE" , - .tag =AUD_OPT_INT , - .valp = &glob_conf.period_size_out, - .descr ="DAC period size (0 to go with system default)" , - .overriddenp = &glob_conf.period_size_out_overridden - }, - { - .name ="DAC_BUFFER_SIZE" , - .tag =AUD_OPT_INT , - .valp = &glob_conf.buffer_size_out, - .descr ="DAC buffer size (0 to go with system default)" , - .overriddenp = &glob_conf.buffer_size_out_overridden - }, - { - .name ="ADC_SIZE_IN_USEC" , - .tag =AUD_OPT_BOOL , - .valp = &glob_conf.size_in_usec_in, - .descr = -"ADC period/buffer size in microseconds (otherwise in frames)" - }, - { - .name ="ADC_PERIOD_SIZE" , - .tag =AUD_OPT_INT , - .valp = &glob_conf.period_size_in, - .descr ="ADC period size (0 to go with system default)" , - .overriddenp = &glob_conf.period_size_in_overridden - }, - { - .name ="ADC_BUFFER_SIZE" , - .tag =AUD_OPT_INT , - .valp = &glob_conf.buffer_size_in, - .descr ="ADC buffer size (0 to go with system default)" , - .overriddenp = &glob_conf.buffer_size_in_overridden - }, - { - .name ="THRESHOLD" , - .tag =AUD_OPT_INT , - .valp = &glob_conf.threshold, - .descr ="(undocumented)" - }, - { - .name ="DAC_DEV" , - .tag =AUD_OPT_STR , - .valp = &glob_conf.pcm_name_out, - .descr ="DAC device name (for instance dmix)" - }, - { - .name ="ADC_DEV" , - .tag =AUD_OPT_STR , - .valp = &glob_conf.pcm_name_in, - .descr ="ADC device name" - }, - {/* End of list */ } -}; -static struct audio_pcm_ops alsa_pcm_ops = { .init_out = alsa_init_out, .fini_out = alsa_fini_out,
@@ -1217,7 +1098,6 @@ static struct audio_pcm_ops alsa_pcm_ops = {static struct audio_driver alsa_audio_driver = { .name ="alsa" , .descr ="ALSA http://www.alsa-project.org" , - .options = alsa_options, .init = alsa_audio_init, .fini = alsa_audio_fini, .pcm_ops = &alsa_pcm_ops,
audio/audio_legacy.c +93 -1
113 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 21/50 audio: remove audio_MIN, audio_MAX
In reply to Kővágó, ZoltánThere's already a MIN and MAX macro in include/qemu/osdep.h, use them instead.
--- audio/audio.h | 17 ----------------- audio/alsaaudio.c | 6 +++--- audio/audio.c | 20 ++++++++++---------- audio/coreaudio.c | 2 +- audio/dsoundaudio.c | 2 +- audio/noaudio.c | 10 +++++----- audio/ossaudio.c | 6 +++--- audio/paaudio.c | 12 ++++++------ audio/sdlaudio.c | 6 +++--- audio/spiceaudio.c | 10 +++++----- audio/wavaudio.c | 4 ++-- hw/audio/ac97.c | 10 +++++----- hw/audio/adlib.c | 4 ++-- hw/audio/cs4231a.c | 4 ++-- hw/audio/es1370.c | 6 +++--- hw/audio/gus.c | 6 +++--- hw/audio/hda-codec.c | 16 ++++++++-------- hw/audio/milkymist-ac97.c | 8 ++++---- hw/audio/pcspk.c | 2 +- hw/audio/sb16.c | 2 +- hw/audio/wm8750.c | 4 ++-- 21 files changed, 70 insertions(+), 87 deletions(-)
audio/audio.h +0 -17
@@ -146,23 +146,6 @@ static inline void *advance (void *p, int incr)return (d + incr); } -#ifdef __GNUC__ -#define audio_MIN (a, b) ( __extension__ ({ \ - __typeof (a) ta = a; \ - __typeof (b) tb = b; \ - ((ta)>(tb)?(tb):(ta)); \ -})) - -#define audio_MAX (a, b) ( __extension__ ({ \ - __typeof (a) ta = a; \ - __typeof (b) tb = b; \ - ((ta)<(tb)?(tb):(ta)); \ -})) -#else -#define audio_MIN (a, b) ((a)>(b)?(b):(a)) -#define audio_MAX (a, b) ((a)<(b)?(b):(a)) -#endif -int wav_start_capture (AudioState *state,CaptureState *s,const char *path,int freq,int bits,int nchannels);
audio/alsaaudio.c +3 -3
@@ -641,7 +641,7 @@ static void alsa_write_pending (ALSAVoiceOut *alsa)while (alsa->pending) {int left_till_end_samples = hw->samples - alsa->wpos; -int len =audio_MIN (alsa->pending, left_till_end_samples); +int len =MIN (alsa->pending, left_till_end_samples);char *src =advance (alsa->pcm_buf, alsa->wpos << hw->info.shift);while (len) {
@@ -704,7 +704,7 @@ static int alsa_run_out (HWVoiceOut *hw, int live)return 0 ; } - decr =audio_MIN (live, avail); + decr =MIN (live, avail); decr =audio_pcm_hw_clip_out (hw, alsa->pcm_buf, decr, alsa->pending); alsa->pending += decr;alsa_write_pending (alsa);
@@ -922,7 +922,7 @@ static int alsa_run_in (HWVoiceIn *hw) } } - decr =audio_MIN (dead, avail); + decr =MIN (dead, avail);if (!decr) {return 0 ; }
audio/audio.c +10 -10
@@ -536,7 +536,7 @@ static int audio_pcm_hw_find_min_in (HWVoiceIn *hw)for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {if (sw->active) { - m =audio_MIN (m, sw->total_hw_samples_acquired); + m =MIN (m, sw->total_hw_samples_acquired); } }return m;
@@ -556,14 +556,14 @@ int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf, int live, int pending) { int left = hw->samples - pending; -int len =audio_MIN (left, live); +int len =MIN (left, live);int clipped =0 ;while (len) {struct st_sample *src = hw->mix_buf + hw->rpos;uint8_t *dst =advance (pcm_buf, hw->rpos << hw->info.shift);int samples_till_end_of_buf = hw->samples - hw->rpos; -int samples_to_clip =audio_MIN (len, samples_till_end_of_buf); +int samples_to_clip =MIN (len, samples_till_end_of_buf); hw->clip (dst, src, samples_to_clip);
@@ -617,7 +617,7 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size) } swlim = (live * sw->ratio) >>32 ; - swlim =audio_MIN (swlim, samples); + swlim =MIN (swlim, samples);while (swlim) { src = hw->conv_buf + rpos;
@@ -665,7 +665,7 @@ static int audio_pcm_hw_find_min_out (HWVoiceOut *hw, int *nb_livep)for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {if (sw->active || !sw->empty) { - m =audio_MIN (m, sw->total_hw_samples_mixed); + m =MIN (m, sw->total_hw_samples_mixed); nb_live +=1 ; } }
@@ -728,7 +728,7 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size) dead = hwsamples - live; swlim = ((int64_t ) dead <<32 ) / sw->ratio; - swlim =audio_MIN (swlim, samples); + swlim =MIN (swlim, samples);if (swlim) { sw->conv (sw->buf, buf, swlim);
@@ -740,7 +740,7 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size)while (swlim) { dead = hwsamples - live; left = hwsamples - wpos; - blck =audio_MIN (dead, left); + blck =MIN (dead, left);if (!blck) {break ; }
@@ -1032,7 +1032,7 @@ static void audio_capture_mix_and_clear (HWVoiceOut *hw, int rpos, int samples) n = samples;while (n) {int till_end_of_hw = hw->samples - rpos2; -int to_write =audio_MIN (till_end_of_hw, n); +int to_write =MIN (till_end_of_hw, n);int bytes = to_write << hw->info.shift;int written;
@@ -1050,7 +1050,7 @@ static void audio_capture_mix_and_clear (HWVoiceOut *hw, int rpos, int samples) } } - n =audio_MIN (samples, hw->samples - rpos); + n =MIN (samples, hw->samples - rpos);mixeng_clear (hw->mix_buf + rpos, n);mixeng_clear (hw->mix_buf, samples - n); }
@@ -1206,7 +1206,7 @@ static void audio_run_capture (AudioState *s) rpos = hw->rpos;while (live) {int left = hw->samples - rpos; -int to_capture =audio_MIN (live, left); +int to_capture =MIN (live, left);struct st_sample *src;struct capture_callback *cb;
audio/coreaudio.c +1 -1
@@ -413,7 +413,7 @@ static int coreaudio_run_out (HWVoiceOut *hw, int live) core->live); } - decr =audio_MIN (core->decr, live); + decr =MIN (core->decr, live); core->decr -= decr; core->live = live - decr;
audio/dsoundaudio.c +1 -1
@@ -707,7 +707,7 @@ static int dsound_run_in (HWVoiceIn *hw)if (!len) {return 0 ; } - len =audio_MIN (len, dead); + len =MIN (len, dead); err = dsound_lock_in ( dscb,
audio/noaudio.c +5 -5
@@ -51,11 +51,11 @@ static int no_run_out (HWVoiceOut *hw, int live) now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); ticks = now - no->old_ticks; bytes =muldiv64 (ticks, hw->info.bytes_per_second,NANOSECONDS_PER_SECOND ); - bytes =audio_MIN (bytes,INT_MAX ); + bytes =MIN (bytes,INT_MAX ); samples = bytes >> hw->info.shift; no->old_ticks = now; - decr =audio_MIN (live, samples); + decr =MIN (live, samples); hw->rpos = (hw->rpos + decr) % hw->samples;return decr; }
@@ -110,9 +110,9 @@ static int no_run_in (HWVoiceIn *hw)muldiv64 (ticks, hw->info.bytes_per_second,NANOSECONDS_PER_SECOND ); no->old_ticks = now; - bytes =audio_MIN (bytes,INT_MAX ); + bytes =MIN (bytes,INT_MAX ); samples = bytes >> hw->info.shift; - samples =audio_MIN (samples, dead); + samples =MIN (samples, dead); }return samples; }
@@ -123,7 +123,7 @@ static int no_read (SWVoiceIn *sw, void *buf, int size)* useless resampling/mixing */ int samples = size >> sw->info.shift;int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired; -int to_clear =audio_MIN (samples, total); +int to_clear =MIN (samples, total); sw->total_hw_samples_acquired += total;audio_pcm_info_clear_buf (&sw->info, buf, to_clear);return to_clear << sw->info.shift;
audio/ossaudio.c +3 -3
@@ -387,7 +387,7 @@ static void oss_write_pending (OSSVoiceOut *oss)int samples_written;ssize_t bytes_written;int samples_till_end = hw->samples - oss->wpos; -int samples_to_write =audio_MIN (oss->pending, samples_till_end); +int samples_to_write =MIN (oss->pending, samples_till_end);int bytes_to_write = samples_to_write << hw->info.shift;void *pcm =advance (oss->pcm_buf, oss->wpos << hw->info.shift);
@@ -436,7 +436,7 @@ static int oss_run_out (HWVoiceOut *hw, int live) pos = hw->rpos << hw->info.shift; bytes =audio_ring_dist (cntinfo.ptr, pos, bufsize); - decr =audio_MIN (bytes >> hw->info.shift, live); + decr =MIN (bytes >> hw->info.shift, live); }else { err =ioctl (oss->fd,SNDCTL_DSP_GETOSPACE , &abinfo);
@@ -455,7 +455,7 @@ static int oss_run_out (HWVoiceOut *hw, int live)return 0 ; } - decr =audio_MIN (abinfo.bytes >> hw->info.shift, live); + decr =MIN (abinfo.bytes >> hw->info.shift, live);if (!decr) {return 0 ; }
audio/paaudio.c +6 -6
@@ -234,7 +234,7 @@ static void *qpa_thread_out (void *arg) } } - decr = to_mix =audio_MIN (pa->live, pa->samples >>5 ); + decr = to_mix =MIN (pa->live, pa->samples >>5 ); rpos = pa->rpos;if (audio_pt_unlock (&pa->pt, __func__)) {
@@ -243,7 +243,7 @@ static void *qpa_thread_out (void *arg)while (to_mix) {int error; -int chunk =audio_MIN (to_mix, hw->samples - rpos); +int chunk =MIN (to_mix, hw->samples - rpos);struct st_sample *src = hw->mix_buf + rpos; hw->clip (pa->pcm_buf, src, chunk);
@@ -281,7 +281,7 @@ static int qpa_run_out (HWVoiceOut *hw, int live)return 0 ; } - decr =audio_MIN (live, pa->decr); + decr =MIN (live, pa->decr); pa->decr -= decr; pa->live = live - decr; hw->rpos = pa->rpos;
@@ -326,7 +326,7 @@ static void *qpa_thread_in (void *arg) } } - incr = to_grab =audio_MIN (pa->dead, pa->samples >>5 ); + incr = to_grab =MIN (pa->dead, pa->samples >>5 ); wpos = pa->wpos;if (audio_pt_unlock (&pa->pt, __func__)) {
@@ -335,7 +335,7 @@ static void *qpa_thread_in (void *arg)while (to_grab) {int error; -int chunk =audio_MIN (to_grab, hw->samples - wpos); +int chunk =MIN (to_grab, hw->samples - wpos);void *buf =advance (pa->pcm_buf, wpos); if (qpa_simple_read (pa, buf,
@@ -374,7 +374,7 @@ static int qpa_run_in (HWVoiceIn *hw) live =audio_pcm_hw_get_live_in (hw); dead = hw->samples - live; - incr =audio_MIN (dead, pa->incr); + incr =MIN (dead, pa->incr); pa->incr -= incr; pa->dead = dead - incr; hw->wpos = pa->wpos;
audio/sdlaudio.c +3 -3
@@ -288,10 +288,10 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)#endif /* dolog ("in callback live=%d\n", live); */ - to_mix =audio_MIN (samples, sdl->live); + to_mix =MIN (samples, sdl->live); decr = to_mix;while (to_mix) { -int chunk =audio_MIN (to_mix, hw->samples - hw->rpos); +int chunk =MIN (to_mix, hw->samples - hw->rpos);struct st_sample *src = hw->mix_buf + hw->rpos;/* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
@@ -347,7 +347,7 @@ static int sdl_run_out (HWVoiceOut *hw, int live) sdl->live); } - decr =audio_MIN (sdl->decr, live); + decr =MIN (sdl->decr, live); sdl->decr -= decr;#if USE_SEMAPHORE
audio/spiceaudio.c +5 -5
@@ -163,20 +163,20 @@ static int line_out_run (HWVoiceOut *hw, int live) } decr =rate_get_samples (&hw->info, &out->rate); - decr =audio_MIN (live, decr); + decr =MIN (live, decr); samples = decr; rpos = hw->rpos;while (samples) {int left_till_end_samples = hw->samples - rpos; -int len =audio_MIN (samples, left_till_end_samples); +int len =MIN (samples, left_till_end_samples);if (!out->frame) {spice_server_playback_get_buffer (&out->sin, &out->frame, &out->fsize); out->fpos = out->frame; }if (out->frame) { - len =audio_MIN (len, out->fsize); + len =MIN (len, out->fsize); hw->clip (out->fpos, hw->mix_buf + rpos, len); out->fsize -= len; out->fpos += len;
@@ -294,7 +294,7 @@ static int line_in_run (HWVoiceIn *hw) } delta_samp =rate_get_samples (&hw->info, &in->rate); - num_samples =audio_MIN (num_samples, delta_samp); + num_samples =MIN (num_samples, delta_samp); ready =spice_server_record_get_samples (&in->sin, in->samples, num_samples); samples = in->samples;
@@ -304,7 +304,7 @@ static int line_in_run (HWVoiceIn *hw) ready =LINE_IN_SAMPLES ; } - num_samples =audio_MIN (ready, num_samples); + num_samples =MIN (ready, num_samples);if (hw->wpos + num_samples > hw->samples) { len[0 ] = hw->samples - hw->wpos;
audio/wavaudio.c +2 -2
@@ -57,12 +57,12 @@ static int wav_run_out (HWVoiceOut *hw, int live) } wav->old_ticks = now; - decr =audio_MIN (live, samples); + decr =MIN (live, samples); samples = decr; rpos = hw->rpos;while (samples) {int left_till_end_samples = hw->samples - rpos; -int convert_samples =audio_MIN (samples, left_till_end_samples); +int convert_samples =MIN (samples, left_till_end_samples); src = hw->mix_buf + rpos; dst =advance (wav->pcm_buf, rpos << hw->info.shift);
hw/audio/ac97.c +5 -5
@@ -963,7 +963,7 @@ static int write_audio (AC97LinkState *s, AC97BusMasterRegs *r,uint32_t temp = r->picb <<1 ;uint32_t written =0 ;int to_copy =0 ; - temp =audio_MIN (temp, max); + temp =MIN (temp, max);if (!temp) { *stop =1 ;
@@ -972,7 +972,7 @@ static int write_audio (AC97LinkState *s, AC97BusMasterRegs *r,while (temp) {int copied; - to_copy =audio_MIN (temp,sizeof (tmpbuf)); + to_copy =MIN (temp,sizeof (tmpbuf));pci_dma_read (&s->dev, addr, tmpbuf, to_copy); copied =AUD_write (s->voice_po, tmpbuf, to_copy); dolog ("write_audio max=%x to_copy=%x copied=%x\n",
@@ -1018,7 +1018,7 @@ static void write_bup (AC97LinkState *s, int elapsed) }while (elapsed) { -int temp =audio_MIN (elapsed,sizeof (s->silence)); +int temp =MIN (elapsed,sizeof (s->silence));while (temp) {int copied =AUD_write (s->voice_po, s->silence, temp);if (!copied)
@@ -1039,7 +1039,7 @@ static int read_audio (AC97LinkState *s, AC97BusMasterRegs *r,int to_copy =0 ;SWVoiceIn *voice = (r - s->bm_regs) ==MC_INDEX ? s->voice_mc : s->voice_pi; - temp =audio_MIN (temp, max); + temp =MIN (temp, max);if (!temp) { *stop =1 ;
@@ -1048,7 +1048,7 @@ static int read_audio (AC97LinkState *s, AC97BusMasterRegs *r,while (temp) {int acquired; - to_copy =audio_MIN (temp,sizeof (tmpbuf)); + to_copy =MIN (temp,sizeof (tmpbuf)); acquired =AUD_read (voice, tmpbuf, to_copy);if (!acquired) { *stop =1 ;
hw/audio/adlib.c +2 -2
@@ -194,7 +194,7 @@ static void adlib_callback (void *opaque, int free)return ; } - to_play =audio_MIN (s->left, samples); + to_play =MIN (s->left, samples);while (to_play) { written =write_audio (s, to_play);
@@ -209,7 +209,7 @@ static void adlib_callback (void *opaque, int free) } } - samples =audio_MIN (samples, s->samples - s->pos); + samples =MIN (samples, s->samples - s->pos);if (!samples) {return ; }
hw/audio/cs4231a.c +2 -2
@@ -533,7 +533,7 @@ static int cs_write_audio (CSState *s, int nchan, int dma_pos,int copied;size_t to_copy; - to_copy =audio_MIN (temp, left); + to_copy =MIN (temp, left);if (to_copy >sizeof (tmpbuf)) { to_copy =sizeof (tmpbuf); }
@@ -576,7 +576,7 @@ static int cs_dma_read (void *opaque, int nchan, int dma_pos, int dma_len) till = (s->dregs[Playback_Lower_Base_Count] | (s->dregs[Playback_Upper_Base_Count] <<8 )) << s->shift; till -= s->transferred; - copy =audio_MIN (till, copy); + copy =MIN (till, copy); }if ((copy <=0 ) || (dma_len <=0 )) {
hw/audio/es1370.c +3 -3
@@ -644,7 +644,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,int size = d->frame_cnt &0xffff ;int left = ((size - cnt +1 ) <<2 ) + d->leftover;int transferred =0 ; -int temp =audio_MIN (max,audio_MIN (left, csc_bytes)); +int temp =MIN (max,MIN (left, csc_bytes));int index = d - &s->chan[0 ]; addr += (cnt <<2 ) + d->leftover;
@@ -653,7 +653,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,while (temp) {int acquired, to_copy; - to_copy =audio_MIN ((size_t ) temp,sizeof (tmpbuf)); + to_copy =MIN ((size_t ) temp,sizeof (tmpbuf)); acquired =AUD_read (s->adc_voice, tmpbuf, to_copy);if (!acquired)break ;
@@ -671,7 +671,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,while (temp) {int copied, to_copy; - to_copy =audio_MIN ((size_t ) temp,sizeof (tmpbuf)); + to_copy =MIN ((size_t ) temp,sizeof (tmpbuf));pci_dma_read (&s->dev, addr, tmpbuf, to_copy); copied =AUD_write (voice, tmpbuf, to_copy);if (!copied)
hw/audio/gus.c +3 -3
@@ -115,7 +115,7 @@ static void GUS_callback (void *opaque, int free)GUSState *s = opaque; samples = free >> s->shift; - to_play =audio_MIN (samples, s->left); + to_play =MIN (samples, s->left);while (to_play) {int written =write_audio (s, to_play);
@@ -130,7 +130,7 @@ static void GUS_callback (void *opaque, int free) net += written; } - samples =audio_MIN (samples, s->samples); + samples =MIN (samples, s->samples);if (samples) {gus_mixvoices (&s->emu, s->freq, samples, s->mixbuf);
@@ -190,7 +190,7 @@ static int GUS_read_DMA (void *opaque, int nchan, int dma_pos, int dma_len)ldebug ("read DMA %#x %d\n" , dma_pos, dma_len); mode = k->has_autoinitialization (s->isa_dma, s->emu.gusdma);while (left) { -int to_copy =audio_MIN ((size_t ) left,sizeof (tmpbuf)); +int to_copy =MIN ((size_t ) left,sizeof (tmpbuf));int copied;ldebug ("left=%d to_copy=%d pos=%d\n" , left, to_copy, pos);
hw/audio/hda-codec.c +8 -8
@@ -233,10 +233,10 @@ static void hda_audio_input_timer(void *opaque) goto out_timer; } -int64_t to_transfer =audio_MIN (wpos - rpos, wanted_rpos - rpos); +int64_t to_transfer =MIN (wpos - rpos, wanted_rpos - rpos);while (to_transfer) {uint32_t start = (rpos &B_MASK ); -uint32_t chunk =audio_MIN (B_SIZE - start, to_transfer); +uint32_t chunk =MIN (B_SIZE - start, to_transfer);int rc =hda_codec_xfer ( &st->state->hda, st->stream, false, st->buf + start, chunk);if (!rc) {
@@ -261,13 +261,13 @@ static void hda_audio_input_cb(void *opaque, int avail)int64_t wpos = st->wpos;int64_t rpos = st->rpos; -int64_t to_transfer =audio_MIN (B_SIZE - (wpos - rpos), avail); +int64_t to_transfer =MIN (B_SIZE - (wpos - rpos), avail);hda_timer_sync_adjust (st, -((wpos - rpos) + to_transfer - (B_SIZE >>1 )));while (to_transfer) {uint32_t start = (uint32_t ) (wpos &B_MASK ); -uint32_t chunk = (uint32_t )audio_MIN (B_SIZE - start, to_transfer); +uint32_t chunk = (uint32_t )MIN (B_SIZE - start, to_transfer);uint32_t read =AUD_read (st->voice.in, st->buf + start, chunk); wpos += read; to_transfer -= read;
@@ -297,10 +297,10 @@ static void hda_audio_output_timer(void *opaque) goto out_timer; } -int64_t to_transfer =audio_MIN (B_SIZE - (wpos - rpos), wanted_wpos - wpos); +int64_t to_transfer =MIN (B_SIZE - (wpos - rpos), wanted_wpos - wpos);while (to_transfer) {uint32_t start = (wpos &B_MASK ); -uint32_t chunk =audio_MIN (B_SIZE - start, to_transfer); +uint32_t chunk =MIN (B_SIZE - start, to_transfer);int rc =hda_codec_xfer ( &st->state->hda, st->stream, true, st->buf + start, chunk);if (!rc) {
@@ -325,7 +325,7 @@ static void hda_audio_output_cb(void *opaque, int avail)int64_t wpos = st->wpos;int64_t rpos = st->rpos; -int64_t to_transfer =audio_MIN (wpos - rpos, avail); +int64_t to_transfer =MIN (wpos - rpos, avail);if (wpos - rpos ==B_SIZE ) {/* drop buffer, reset timer adjust */
@@ -340,7 +340,7 @@ static void hda_audio_output_cb(void *opaque, int avail)while (to_transfer) {uint32_t start = (uint32_t ) (rpos &B_MASK ); -uint32_t chunk = (uint32_t )audio_MIN (B_SIZE - start, to_transfer); +uint32_t chunk = (uint32_t )MIN (B_SIZE - start, to_transfer);uint32_t written =AUD_write (st->voice.out, st->buf + start, chunk); rpos += written; to_transfer -= written;
hw/audio/milkymist-ac97.c +4 -4
@@ -183,7 +183,7 @@ static void ac97_in_cb(void *opaque, int avail_b)MilkymistAC97State *s = opaque;uint8_t buf[4096 ];uint32_t remaining = s->regs[R_U_REMAINING ]; -int temp =audio_MIN (remaining, avail_b); +int temp =MIN (remaining, avail_b);uint32_t addr = s->regs[R_U_ADDR ];int transferred =0 ;
@@ -197,7 +197,7 @@ static void ac97_in_cb(void *opaque, int avail_b)while (temp) {int acquired, to_copy; - to_copy =audio_MIN (temp,sizeof (buf)); + to_copy =MIN (temp,sizeof (buf)); acquired =AUD_read (s->voice_in, buf, to_copy);if (!acquired) {break ;
@@ -226,7 +226,7 @@ static void ac97_out_cb(void *opaque, int free_b)MilkymistAC97State *s = opaque;uint8_t buf[4096 ];uint32_t remaining = s->regs[R_D_REMAINING ]; -int temp =audio_MIN (remaining, free_b); +int temp =MIN (remaining, free_b);uint32_t addr = s->regs[R_D_ADDR ];int transferred =0 ;
@@ -240,7 +240,7 @@ static void ac97_out_cb(void *opaque, int free_b)while (temp) {int copied, to_copy; - to_copy =audio_MIN (temp,sizeof (buf)); + to_copy =MIN (temp,sizeof (buf));cpu_physical_memory_read (addr, buf, to_copy); copied =AUD_write (s->voice_out, buf, to_copy);if (!copied) {
hw/audio/pcspk.c +1 -1
@@ -102,7 +102,7 @@ static void pcspk_callback(void *opaque, int free) }while (free >0 ) { - n =audio_MIN (s->samples - s->play_pos, (unsigned int )free); + n =MIN (s->samples - s->play_pos, (unsigned int )free); n =AUD_write (s->voice, &s->sample_buf[s->play_pos], n);if (!n)break ;
hw/audio/sb16.c +1 -1
@@ -1166,7 +1166,7 @@ static int write_audio (SB16State *s, int nchan, int dma_pos,int copied;size_t to_copy; - to_copy =audio_MIN (temp, left); + to_copy =MIN (temp, left);if (to_copy >sizeof (tmpbuf)) { to_copy =sizeof (tmpbuf); }
hw/audio/wm8750.c +2 -2
@@ -68,7 +68,7 @@ static inline void wm8750_in_load(WM8750State *s) {if (s->idx_in + s->req_in <=sizeof (s->data_in))return ; - s->idx_in =audio_MAX (0 , (int )sizeof (s->data_in) - s->req_in); + s->idx_in =MAX (0 , (int )sizeof (s->data_in) - s->req_in);AUD_read (*s->in[0 ], s->data_in + s->idx_in,sizeof (s->data_in) - s->idx_in); }
@@ -99,7 +99,7 @@ static void wm8750_audio_out_cb(void *opaque, int free_b)wm8750_out_flush (s); }else s->req_out = free_b - s->idx_out; - + s->data_req (s->opaque, s->req_out >>2 , s->req_in >>2 ); }
Signature · 1 line
2.20.1
PATCH v3 2/50 audio: use qapi AudioFormat instead of audfmt_e
In reply to Kővágó, ZoltánI had to include an enum for audio sampling formats into qapi, but that meant duplicating the audfmt_e enum. This patch replaces audfmt_e and associated values with the qapi generated AudioFormat enum.
This patch is mostly a search-and-replace, except for switches where the qapi generated AUDIO_FORMAT_MAX caused problems.
--- audio/audio.h | 12 +---- audio/alsaaudio.c | 53 +++++++++++---------- audio/audio.c | 97 +++++++++++++++++++++------------------ audio/audio_win_int.c | 18 ++++---- audio/ossaudio.c | 30 ++++++------ audio/paaudio.c | 28 +++++------ audio/sdlaudio.c | 26 +++++------ audio/spiceaudio.c | 4 +- audio/wavaudio.c | 17 ++++--- audio/wavcapture.c | 2 +- hw/arm/omap2.c | 2 +- hw/audio/ac97.c | 2 +- hw/audio/adlib.c | 2 +- hw/audio/cs4231a.c | 6 +-- hw/audio/es1370.c | 4 +- hw/audio/gus.c | 2 +- hw/audio/hda-codec.c | 18 ++++---- hw/audio/lm4549.c | 6 +-- hw/audio/milkymist-ac97.c | 2 +- hw/audio/pcspk.c | 2 +- hw/audio/sb16.c | 14 +++--- hw/audio/wm8750.c | 6 +-- hw/display/xlnx_dp.c | 2 +- hw/input/tsc210x.c | 2 +- hw/usb/dev-audio.c | 2 +- ui/vnc.c | 26 +++++------ 26 files changed, 196 insertions(+), 189 deletions(-)
audio/audio.h +2 -10
@@ -26,18 +26,10 @@#define QEMU_AUDIO_H #include "qemu/queue.h" +#include "qapi/qapi-types-audio.h" typedef void (*audio_callback_fn ) (void *opaque,int avail); -typedef enum { -AUD_FMT_U8 , -AUD_FMT_S8 , -AUD_FMT_U16 , -AUD_FMT_S16 , -AUD_FMT_U32 , -AUD_FMT_S32 -}audfmt_e ; -#ifdef HOST_WORDS_BIGENDIAN #define AUDIO_HOST_ENDIANNESS 1#else
@@ -47,7 +39,7 @@ typedef enum {struct audsettings {int freq;int nchannels; -audfmt_e fmt; +AudioFormat fmt;int endianness; };
audio/alsaaudio.c +28 -25
149 lines not on this page · raw message
audio/audio.c +53 -44
230 lines not on this page · raw message
audio/audio_win_int.c +9 -9
@@ -24,20 +24,20 @@ int waveformat_from_audio_settings (WAVEFORMATEX *wfx, wfx->cbSize =0 ;switch (as->fmt) { -case AUD_FMT_S8 : -case AUD_FMT_U8 : +case AUDIO_FORMAT_S8 : +case AUDIO_FORMAT_U8 : wfx->wBitsPerSample =8 ;break ; -case AUD_FMT_S16 : -case AUD_FMT_U16 : +case AUDIO_FORMAT_S16 : +case AUDIO_FORMAT_U16 : wfx->wBitsPerSample =16 ; wfx->nAvgBytesPerSec <<=1 ; wfx->nBlockAlign <<=1 ;break ; -case AUD_FMT_S32 : -case AUD_FMT_U32 : +case AUDIO_FORMAT_S32 : +case AUDIO_FORMAT_U32 : wfx->wBitsPerSample =32 ; wfx->nAvgBytesPerSec <<=2 ; wfx->nBlockAlign <<=2 ;
@@ -85,15 +85,15 @@ int waveformat_to_audio_settings (WAVEFORMATEX *wfx,switch (wfx->wBitsPerSample) {case 8 : - as->fmt =AUD_FMT_U8 ; + as->fmt =AUDIO_FORMAT_U8 ;break ;case 16 : - as->fmt =AUD_FMT_S16 ; + as->fmt =AUDIO_FORMAT_S16 ;break ;case 32 : - as->fmt =AUD_FMT_S32 ; + as->fmt =AUDIO_FORMAT_S32 ;break ;default :
audio/ossaudio.c +15 -15
@@ -70,7 +70,7 @@ typedef struct OSSVoiceIn {struct oss_params {int freq; -audfmt_e fmt; +AudioFormat fmt;int nchannels;int nfrags;int fragsize;
@@ -148,16 +148,16 @@ static int oss_write (SWVoiceOut *sw, void *buf, int len)return audio_pcm_sw_write (sw, buf, len); } -static int aud_to_ossfmt (audfmt_e fmt,int endianness) +static int aud_to_ossfmt (AudioFormat fmt,int endianness) {switch (fmt) { -case AUD_FMT_S8 : +case AUDIO_FORMAT_S8 :return AFMT_S8 ; -case AUD_FMT_U8 : +case AUDIO_FORMAT_U8 :return AFMT_U8 ; -case AUD_FMT_S16 : +case AUDIO_FORMAT_S16 :if (endianness) {return AFMT_S16_BE ; }
@@ -165,7 +165,7 @@ static int aud_to_ossfmt (audfmt_e fmt, int endianness)return AFMT_S16_LE ; } -case AUD_FMT_U16 : +case AUDIO_FORMAT_U16 :if (endianness) {return AFMT_U16_BE ; }
@@ -182,37 +182,37 @@ static int aud_to_ossfmt (audfmt_e fmt, int endianness) } } -static int oss_to_audfmt (int ossfmt,audfmt_e *fmt,int *endianness) +static int oss_to_audfmt (int ossfmt,AudioFormat *fmt,int *endianness) {switch (ossfmt) {case AFMT_S8 : *endianness =0 ; - *fmt =AUD_FMT_S8 ; + *fmt =AUDIO_FORMAT_S8 ;break ;case AFMT_U8 : *endianness =0 ; - *fmt =AUD_FMT_U8 ; + *fmt =AUDIO_FORMAT_U8 ;break ;case AFMT_S16_LE : *endianness =0 ; - *fmt =AUD_FMT_S16 ; + *fmt =AUDIO_FORMAT_S16 ;break ;case AFMT_U16_LE : *endianness =0 ; - *fmt =AUD_FMT_U16 ; + *fmt =AUDIO_FORMAT_U16 ;break ;case AFMT_S16_BE : *endianness =1 ; - *fmt =AUD_FMT_S16 ; + *fmt =AUDIO_FORMAT_S16 ;break ;case AFMT_U16_BE : *endianness =1 ; - *fmt =AUD_FMT_U16 ; + *fmt =AUDIO_FORMAT_U16 ;break ;default :
@@ -500,7 +500,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,int endianness;int err;int fd; -audfmt_e effective_fmt; +AudioFormat effective_fmt;struct audsettings obt_as;OSSConf *conf = drv_opaque;
@@ -667,7 +667,7 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)int endianness;int err;int fd; -audfmt_e effective_fmt; +AudioFormat effective_fmt;struct audsettings obt_as;OSSConf *conf = drv_opaque;
audio/paaudio.c +14 -14
@@ -385,21 +385,21 @@ static int qpa_read (SWVoiceIn *sw, void *buf, int len)return audio_pcm_sw_read (sw, buf, len); } -static pa_sample_format_t audfmt_to_pa (audfmt_e afmt,int endianness) +static pa_sample_format_t audfmt_to_pa (AudioFormat afmt,int endianness) {int format;switch (afmt) { -case AUD_FMT_S8 : -case AUD_FMT_U8 : +case AUDIO_FORMAT_S8 : +case AUDIO_FORMAT_U8 : format =PA_SAMPLE_U8 ;break ; -case AUD_FMT_S16 : -case AUD_FMT_U16 : +case AUDIO_FORMAT_S16 : +case AUDIO_FORMAT_U16 : format = endianness ?PA_SAMPLE_S16BE :PA_SAMPLE_S16LE ;break ; -case AUD_FMT_S32 : -case AUD_FMT_U32 : +case AUDIO_FORMAT_S32 : +case AUDIO_FORMAT_U32 : format = endianness ?PA_SAMPLE_S32BE :PA_SAMPLE_S32LE ;break ;default :
@@ -410,26 +410,26 @@ static pa_sample_format_t audfmt_to_pa (audfmt_e afmt, int endianness)return format; } -static audfmt_e pa_to_audfmt (pa_sample_format_t fmt,int *endianness) +static AudioFormat pa_to_audfmt (pa_sample_format_t fmt,int *endianness) {switch (fmt) {case PA_SAMPLE_U8 : -return AUD_FMT_U8 ; +return AUDIO_FORMAT_U8 ;case PA_SAMPLE_S16BE : *endianness =1 ; -return AUD_FMT_S16 ; +return AUDIO_FORMAT_S16 ;case PA_SAMPLE_S16LE : *endianness =0 ; -return AUD_FMT_S16 ; +return AUDIO_FORMAT_S16 ;case PA_SAMPLE_S32BE : *endianness =1 ; -return AUD_FMT_S32 ; +return AUDIO_FORMAT_S32 ;case PA_SAMPLE_S32LE : *endianness =0 ; -return AUD_FMT_S32 ; +return AUDIO_FORMAT_S32 ;default :dolog ("Internal logic error: Bad pa_sample_format %d\n" , fmt); -return AUD_FMT_U8 ; +return AUDIO_FORMAT_U8 ; } }
audio/sdlaudio.c +13 -13
@@ -137,19 +137,19 @@ static int sdl_unlock_and_post (SDLAudioState *s, const char *forfn)return sdl_post (s, forfn); } -static int aud_to_sdlfmt (audfmt_e fmt) +static int aud_to_sdlfmt (AudioFormat fmt) {switch (fmt) { -case AUD_FMT_S8 : +case AUDIO_FORMAT_S8 :return AUDIO_S8 ; -case AUD_FMT_U8 : +case AUDIO_FORMAT_U8 :return AUDIO_U8 ; -case AUD_FMT_S16 : +case AUDIO_FORMAT_S16 :return AUDIO_S16LSB ; -case AUD_FMT_U16 : +case AUDIO_FORMAT_U16 :return AUDIO_U16LSB ;default :
@@ -161,37 +161,37 @@ static int aud_to_sdlfmt (audfmt_e fmt) } } -static int sdl_to_audfmt (int sdlfmt,audfmt_e *fmt,int *endianness) +static int sdl_to_audfmt (int sdlfmt,AudioFormat *fmt,int *endianness) {switch (sdlfmt) {case AUDIO_S8 : *endianness =0 ; - *fmt =AUD_FMT_S8 ; + *fmt =AUDIO_FORMAT_S8 ;break ;case AUDIO_U8 : *endianness =0 ; - *fmt =AUD_FMT_U8 ; + *fmt =AUDIO_FORMAT_U8 ;break ;case AUDIO_S16LSB : *endianness =0 ; - *fmt =AUD_FMT_S16 ; + *fmt =AUDIO_FORMAT_S16 ;break ;case AUDIO_U16LSB : *endianness =0 ; - *fmt =AUD_FMT_U16 ; + *fmt =AUDIO_FORMAT_U16 ;break ;case AUDIO_S16MSB : *endianness =1 ; - *fmt =AUD_FMT_S16 ; + *fmt =AUDIO_FORMAT_S16 ;break ;case AUDIO_U16MSB : *endianness =1 ; - *fmt =AUD_FMT_U16 ; + *fmt =AUDIO_FORMAT_U16 ;break ;default :
@@ -386,7 +386,7 @@ static int sdl_init_out(HWVoiceOut *hw, struct audsettings *as,SDL_AudioSpec req, obt;int endianness;int err; -audfmt_e effective_fmt; +AudioFormat effective_fmt;struct audsettings obt_as; req.freq = as->freq;
audio/spiceaudio.c +2 -2
@@ -130,7 +130,7 @@ static int line_out_init(HWVoiceOut *hw, struct audsettings *as, settings.freq =SPICE_INTERFACE_PLAYBACK_FREQ ;#endif settings.nchannels =SPICE_INTERFACE_PLAYBACK_CHAN ; - settings.fmt =AUD_FMT_S16 ; + settings.fmt =AUDIO_FORMAT_S16 ; settings.endianness =AUDIO_HOST_ENDIANNESS ;audio_pcm_init_info (&hw->info, &settings);
@@ -258,7 +258,7 @@ static int line_in_init(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) settings.freq =SPICE_INTERFACE_RECORD_FREQ ;#endif settings.nchannels =SPICE_INTERFACE_RECORD_CHAN ; - settings.fmt =AUD_FMT_S16 ; + settings.fmt =AUDIO_FORMAT_S16 ; settings.endianness =AUDIO_HOST_ENDIANNESS ;audio_pcm_init_info (&hw->info, &settings);
audio/wavaudio.c +10 -7
@@ -117,20 +117,23 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as, stereo = wav_as.nchannels ==2 ;switch (wav_as.fmt) { -case AUD_FMT_S8 : -case AUD_FMT_U8 : +case AUDIO_FORMAT_S8 : +case AUDIO_FORMAT_U8 : bits16 =0 ;break ; -case AUD_FMT_S16 : -case AUD_FMT_U16 : +case AUDIO_FORMAT_S16 : +case AUDIO_FORMAT_U16 : bits16 =1 ;break ; -case AUD_FMT_S32 : -case AUD_FMT_U32 : +case AUDIO_FORMAT_S32 : +case AUDIO_FORMAT_U32 :dolog ("WAVE files can not handle 32bit formats\n" );return -1 ; + +default : +abort (); } hdr[34 ] = bits16 ?0x10 :0x08 ;
@@ -225,7 +228,7 @@ static int wav_ctl_out (HWVoiceOut *hw, int cmd, ...)static WAVConf glob_conf = { .settings.freq =44100 , .settings.nchannels =2 , - .settings.fmt =AUD_FMT_S16 , + .settings.fmt =AUDIO_FORMAT_S16 , .wav_path ="qemu.wav" };
audio/wavcapture.c +1 -1
@@ -139,7 +139,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq, as.freq = freq; as.nchannels =1 << stereo; - as.fmt = bits16 ?AUD_FMT_S16 :AUD_FMT_U8 ; + as.fmt = bits16 ?AUDIO_FORMAT_S16 :AUDIO_FORMAT_U8 ; as.endianness =0 ; ops.notify = wav_notify;
hw/arm/omap2.c +1 -1
@@ -273,7 +273,7 @@ static void omap_eac_format_update(struct omap_eac_s *s)* does I2S specify it? */ /* All register writes are 16 bits so we we store 16-bit samples * in the buffers regardless of AGCFR[B8_16] value. */ - fmt.fmt =AUD_FMT_U16 ; + fmt.fmt =AUDIO_FORMAT_U16 ; s->codec.in_voice =AUD_open_in (&s->codec.card, s->codec.in_voice,"eac.codec.in" , s, omap_eac_in_cb, &fmt);
hw/audio/ac97.c +1 -1
@@ -365,7 +365,7 @@ static void open_voice (AC97LinkState *s, int index, int freq) as.freq = freq; as.nchannels =2 ; - as.fmt =AUD_FMT_S16 ; + as.fmt =AUDIO_FORMAT_S16 ; as.endianness =0 ;if (freq >0 ) {
hw/audio/adlib.c +1 -1
@@ -269,7 +269,7 @@ static void adlib_realizefn (DeviceState *dev, Error **errp) as.freq = s->freq; as.nchannels =SHIFT ; - as.fmt =AUD_FMT_S16 ; + as.fmt =AUDIO_FORMAT_S16 ; as.endianness =AUDIO_HOST_ENDIANNESS ;AUD_register_card ("adlib" , &s->card);
hw/audio/cs4231a.c +3 -3
@@ -288,7 +288,7 @@ static void cs_reset_voices (CSState *s, uint32_t val)switch ((val >>5 ) & ((s->dregs[MODE_And_ID] &MODE2 ) ?7 :3 )) {case 0 : - as.fmt =AUD_FMT_U8 ; + as.fmt =AUDIO_FORMAT_U8 ; s->shift = as.nchannels ==2 ;break ;
@@ -298,7 +298,7 @@ static void cs_reset_voices (CSState *s, uint32_t val)case 3 : s->tab = ALawDecompressTable; x_law: - as.fmt =AUD_FMT_S16 ; + as.fmt =AUDIO_FORMAT_S16 ; as.endianness =AUDIO_HOST_ENDIANNESS ; s->shift = as.nchannels ==2 ;break ;
@@ -307,7 +307,7 @@ static void cs_reset_voices (CSState *s, uint32_t val) as.endianness =1 ;/* fall through */ case 2 : - as.fmt =AUD_FMT_S16 ; + as.fmt =AUDIO_FORMAT_S16 ; s->shift = as.nchannels;break ;
hw/audio/es1370.c +2 -2
@@ -414,14 +414,14 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl) i, new_freq,1 << (new_fmt &1 ), - (new_fmt &2 ) ?AUD_FMT_S16 :AUD_FMT_U8 , + (new_fmt &2 ) ?AUDIO_FORMAT_S16 :AUDIO_FORMAT_U8 , d->shift);if (new_freq) {struct audsettings as; as.freq = new_freq; as.nchannels =1 << (new_fmt &1 ); - as.fmt = (new_fmt &2 ) ?AUD_FMT_S16 :AUD_FMT_U8 ; + as.fmt = (new_fmt &2 ) ?AUDIO_FORMAT_S16 :AUDIO_FORMAT_U8 ; as.endianness =0 ;if (i ==ADC_CHANNEL ) {
hw/audio/gus.c +1 -1
@@ -251,7 +251,7 @@ static void gus_realizefn (DeviceState *dev, Error **errp) as.freq = s->freq; as.nchannels =2 ; - as.fmt =AUD_FMT_S16 ; + as.fmt =AUDIO_FORMAT_S16 ; as.endianness =GUS_ENDIANNESS ; s->voice = AUD_open_out (
hw/audio/hda-codec.c +9 -9
@@ -99,9 +99,9 @@ static void hda_codec_parse_fmt(uint32_t format, struct audsettings *as) }switch (format &AC_FMT_BITS_MASK ) { -case AC_FMT_BITS_8 : as->fmt =AUD_FMT_S8 ;break ; -case AC_FMT_BITS_16 : as->fmt =AUD_FMT_S16 ;break ; -case AC_FMT_BITS_32 : as->fmt =AUD_FMT_S32 ;break ; +case AC_FMT_BITS_8 : as->fmt =AUDIO_FORMAT_S8 ;break ; +case AC_FMT_BITS_16 : as->fmt =AUDIO_FORMAT_S16 ;break ; +case AC_FMT_BITS_32 : as->fmt =AUDIO_FORMAT_S32 ;break ; } as->nchannels = ((format &AC_FMT_CHAN_MASK ) >>AC_FMT_CHAN_SHIFT ) +1 ;
@@ -134,12 +134,12 @@ static void hda_codec_parse_fmt(uint32_t format, struct audsettings *as)/* -------------------------------------------------------------------------- */ static const char *fmt2name[] = { - [AUD_FMT_U8 ] ="PCM-U8" , - [AUD_FMT_S8 ] ="PCM-S8" , - [AUD_FMT_U16 ] ="PCM-U16" , - [AUD_FMT_S16 ] ="PCM-S16" , - [AUD_FMT_U32 ] ="PCM-U32" , - [AUD_FMT_S32 ] ="PCM-S32" , + [AUDIO_FORMAT_U8 ] ="PCM-U8" , + [AUDIO_FORMAT_S8 ] ="PCM-S8" , + [AUDIO_FORMAT_U16 ] ="PCM-U16" , + [AUDIO_FORMAT_S16 ] ="PCM-S16" , + [AUDIO_FORMAT_U32 ] ="PCM-U32" , + [AUDIO_FORMAT_S32 ] ="PCM-S32" , };typedef struct HDAAudioState HDAAudioState ;
hw/audio/lm4549.c +3 -3
@@ -185,7 +185,7 @@ void lm4549_write(lm4549_state *s,struct audsettings as; as.freq = value; as.nchannels =2 ; - as.fmt =AUD_FMT_S16 ; + as.fmt =AUDIO_FORMAT_S16 ; as.endianness =0 ; s->voice = AUD_open_out(
@@ -255,7 +255,7 @@ static int lm4549_post_load(void *opaque, int version_id)struct audsettings as; as.freq = freq; as.nchannels =2 ; - as.fmt =AUD_FMT_S16 ; + as.fmt =AUDIO_FORMAT_S16 ; as.endianness =0 ; s->voice = AUD_open_out(
@@ -292,7 +292,7 @@ void lm4549_init(lm4549_state *s, lm4549_callback data_req_cb, void* opaque)/* Open a default voice */ as.freq =48000 ; as.nchannels =2 ; - as.fmt =AUD_FMT_S16 ; + as.fmt =AUDIO_FORMAT_S16 ; as.endianness =0 ; s->voice = AUD_open_out(
hw/audio/milkymist-ac97.c +1 -1
@@ -308,7 +308,7 @@ static void milkymist_ac97_realize(DeviceState *dev, Error **errp) as.freq =48000 ; as.nchannels =2 ; - as.fmt =AUD_FMT_S16 ; + as.fmt =AUDIO_FORMAT_S16 ; as.endianness =1 ; s->voice_in = AUD_open_in(&s->card, s->voice_in,
hw/audio/pcspk.c +1 -1
@@ -114,7 +114,7 @@ static void pcspk_callback(void *opaque, int free)static int pcspk_audio_init (ISABus *bus) {PCSpkState *s = pcspk_state; -struct audsettings as = {PCSPK_SAMPLE_RATE ,1 ,AUD_FMT_U8 ,0 }; +struct audsettings as = {PCSPK_SAMPLE_RATE ,1 ,AUDIO_FORMAT_U8 ,0 };AUD_register_card (s_spk, &s->card);
hw/audio/sb16.c +7 -7
@@ -66,7 +66,7 @@ typedef struct SB16State {int fmt_stereo;int fmt_signed;int fmt_bits; -audfmt_e fmt; +AudioFormat fmt;int dma_auto;int block_size;int fifo;
@@ -224,7 +224,7 @@ static void continue_dma8 (SB16State *s)static void dma_cmd8 (SB16State *s,int mask,int dma_len) { - s->fmt =AUD_FMT_U8 ; + s->fmt =AUDIO_FORMAT_U8 ; s->use_hdma =0 ; s->fmt_bits =8 ; s->fmt_signed =0 ;
@@ -319,18 +319,18 @@ static void dma_cmd (SB16State *s, uint8_t cmd, uint8_t d0, int dma_len)if (16 == s->fmt_bits) {if (s->fmt_signed) { - s->fmt =AUD_FMT_S16 ; + s->fmt =AUDIO_FORMAT_S16 ; }else { - s->fmt =AUD_FMT_U16 ; + s->fmt =AUDIO_FORMAT_U16 ; } }else {if (s->fmt_signed) { - s->fmt =AUD_FMT_S8 ; + s->fmt =AUDIO_FORMAT_S8 ; }else { - s->fmt =AUD_FMT_U8 ; + s->fmt =AUDIO_FORMAT_U8 ; } }
@@ -852,7 +852,7 @@ static void legacy_reset (SB16State *s) as.freq = s->freq; as.nchannels =1 ; - as.fmt =AUD_FMT_U8 ; + as.fmt =AUDIO_FORMAT_U8 ; as.endianness =0 ; s->voice = AUD_open_out (
hw/audio/wm8750.c +3 -3
@@ -201,7 +201,7 @@ static void wm8750_set_format(WM8750State *s) in_fmt.endianness =0 ; in_fmt.nchannels =2 ; in_fmt.freq = s->adc_hz; - in_fmt.fmt =AUD_FMT_S16 ; + in_fmt.fmt =AUDIO_FORMAT_S16 ; s->adc_voice[0 ] =AUD_open_in (&s->card, s->adc_voice[0 ],CODEC ".input1" , s, wm8750_audio_in_cb, &in_fmt);
@@ -214,7 +214,7 @@ static void wm8750_set_format(WM8750State *s) out_fmt.endianness =0 ; out_fmt.nchannels =2 ; out_fmt.freq = s->dac_hz; - out_fmt.fmt =AUD_FMT_S16 ; + out_fmt.fmt =AUDIO_FORMAT_S16 ; s->dac_voice[0 ] =AUD_open_out (&s->card, s->dac_voice[0 ],CODEC ".speaker" , s, wm8750_audio_out_cb, &out_fmt);
@@ -681,7 +681,7 @@ uint32_t wm8750_adc_dat(void *opaque)if (s->idx_in >=sizeof (s->data_in)) {wm8750_in_load (s);if (s->idx_in >=sizeof (s->data_in)) { -return 0x80008000 ;/* silence in AUD_FMT_S16 sample format */ +return 0x80008000 ;/* silence in AUDIO_FORMAT_S16 sample format */ } }
hw/display/xlnx_dp.c +1 -1
@@ -1260,7 +1260,7 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp) as.freq =44100 ; as.nchannels =2 ; - as.fmt =AUD_FMT_S16 ; + as.fmt =AUDIO_FORMAT_S16 ; as.endianness =0 ;AUD_register_card ("xlnx_dp.audio" , &s->aud_card);
hw/input/tsc210x.c +1 -1
@@ -318,7 +318,7 @@ static void tsc2102_audio_output_update(TSC210xState *s) fmt.endianness =0 ; fmt.nchannels =2 ; fmt.freq = s->codec.tx_rate; - fmt.fmt =AUD_FMT_S16 ; + fmt.fmt =AUDIO_FORMAT_S16 ; s->dac_voice[0 ] =AUD_open_out (&s->card, s->dac_voice[0 ],"tsc2102.sink" , s, (void *) tsc210x_audio_out_cb, &fmt);
hw/usb/dev-audio.c +1 -1
@@ -650,7 +650,7 @@ static void usb_audio_realize(USBDevice *dev, Error **errp) s->out.vol[1 ] =240 ;/* 0 dB */ s->out.as.freq =USBAUDIO_SAMPLE_RATE ; s->out.as.nchannels =2 ; - s->out.as.fmt =AUD_FMT_S16 ; + s->out.as.fmt =AUDIO_FORMAT_S16 ; s->out.as.endianness =0 ;streambuf_init (&s->out.buf, s->buffer);
ui/vnc.c +13 -13
@@ -994,16 +994,16 @@ static void vnc_update_throttle_offset(VncState *vs)int bps;switch (vs->as.fmt) {default : -case AUD_FMT_U8 : -case AUD_FMT_S8 : +case AUDIO_FORMAT_U8 : +case AUDIO_FORMAT_S8 : bps =1 ;break ; -case AUD_FMT_U16 : -case AUD_FMT_S16 : +case AUDIO_FORMAT_U16 : +case AUDIO_FORMAT_S16 : bps =2 ;break ; -case AUD_FMT_U32 : -case AUD_FMT_S32 : +case AUDIO_FORMAT_U32 : +case AUDIO_FORMAT_S32 : bps =4 ;break ; }
@@ -2409,12 +2409,12 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len)if (len ==4 )return 10 ;switch (read_u8 (data,4 )) { -case 0 : vs->as.fmt =AUD_FMT_U8 ;break ; -case 1 : vs->as.fmt =AUD_FMT_S8 ;break ; -case 2 : vs->as.fmt =AUD_FMT_U16 ;break ; -case 3 : vs->as.fmt =AUD_FMT_S16 ;break ; -case 4 : vs->as.fmt =AUD_FMT_U32 ;break ; -case 5 : vs->as.fmt =AUD_FMT_S32 ;break ; +case 0 : vs->as.fmt =AUDIO_FORMAT_U8 ;break ; +case 1 : vs->as.fmt =AUDIO_FORMAT_S8 ;break ; +case 2 : vs->as.fmt =AUDIO_FORMAT_U16 ;break ; +case 3 : vs->as.fmt =AUDIO_FORMAT_S16 ;break ; +case 4 : vs->as.fmt =AUDIO_FORMAT_U32 ;break ; +case 5 : vs->as.fmt =AUDIO_FORMAT_S32 ;break ;default :VNC_DEBUG ("Invalid audio format %d\n" ,read_u8 (data,4 ));vnc_client_error (vs);
@@ -3145,7 +3145,7 @@ static void vnc_connect(VncDisplay *vd, QIOChannelSocket *sioc, vs->as.freq =44100 ; vs->as.nchannels =2 ; - vs->as.fmt =AUD_FMT_S16 ; + vs->as.fmt =AUDIO_FORMAT_S16 ; vs->as.endianness =0 ;qemu_mutex_init (&vs->output_mutex);
Signature · 1 line
2.20.1
PATCH v3 30/50 noaudio: port to the new audio backend api
In reply to Kővágó, Zoltán--- audio/noaudio.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-)
audio/noaudio.c +15 -24
@@ -40,10 +40,9 @@ typedef struct NoVoiceIn {int64_t old_ticks; } NoVoiceIn; -static size_t no_run_out (HWVoiceOut *hw,size_t live) +static size_t no_write (HWVoiceOut *hw,void *buf,size_t len) {NoVoiceOut *no = (NoVoiceOut *) hw; -size_t decr, samples;int64_t now;int64_t ticks;int64_t bytes;
@@ -51,13 +50,9 @@ static size_t no_run_out(HWVoiceOut *hw, size_t live) now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); ticks = now - no->old_ticks; bytes =muldiv64 (ticks, hw->info.bytes_per_second,NANOSECONDS_PER_SECOND ); - bytes =MIN (bytes,SIZE_MAX ); - samples = bytes >> hw->info.shift; no->old_ticks = now; - decr =MIN (live, samples); - hw->rpos = (hw->rpos + decr) % hw->samples; -return decr; +return MIN (len, bytes); }static int no_init_out (HWVoiceOut *hw,struct audsettings *as,void *drv_opaque)
@@ -91,25 +86,21 @@ static void no_fini_in (HWVoiceIn *hw) (void ) hw; } -static size_t no_run_in (HWVoiceIn *hw) +static size_t no_read (HWVoiceIn *hw,void *buf,size_t size) { +size_t to_clear;NoVoiceIn *no = (NoVoiceIn *) hw; -size_t live =audio_pcm_hw_get_live_in (hw); -size_t dead = hw->samples - live; -size_t samples =0 ; -if (dead) { -int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); -int64_t ticks = now - no->old_ticks; -int64_t bytes = -muldiv64 (ticks, hw->info.bytes_per_second,NANOSECONDS_PER_SECOND ); +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +int64_t ticks = now - no->old_ticks; +int64_t bytes = +muldiv64 (ticks, hw->info.bytes_per_second,NANOSECONDS_PER_SECOND ); - no->old_ticks = now; - bytes =MIN (bytes,SIZE_MAX ); - samples = bytes >> hw->info.shift; - samples =MIN (samples, dead); - } -return samples; + no->old_ticks = now; + to_clear =MIN (bytes, size); + +audio_pcm_info_clear_buf (&hw->info, buf, to_clear >> hw->info.shift); +return to_clear; }static int no_ctl_in (HWVoiceIn *hw,int cmd, ...)
@@ -132,12 +123,12 @@ static void no_audio_fini (void *opaque)static struct audio_pcm_ops no_pcm_ops = { .init_out = no_init_out, .fini_out = no_fini_out, - .run_out = no_run_out, + .write = no_write, .ctl_out = no_ctl_out, .init_in = no_init_in, .fini_in = no_fini_in, - .run_in = no_run_in, + .read = no_read, .ctl_in = no_ctl_in };
Signature · 1 line
2.20.1
PATCH v3 4/50 audio: -audiodev command line option basic implementation
In reply to Kővágó, ZoltánAudio drivers now get an Audiodev * as config paramters, instead of the global audio_option structs. There is some code in audio/audio_legacy.c that converts the old environment variables to audiodev options (this way backends do not have to worry about legacy options). It also contains a replacement of -audio-help, which prints out the equivalent -audiodev based config of the currently specified environment variables.
Note that backends are not updated and still rely on environment variables.
Also note that (due to moving try-poll from global to backend specific option) currently ALSA and OSS will always try poll mode, regardless of environment variables or -audiodev options.
---
Notes:
Changes from v2:
* MAJOR: use qobject_input_visitor instead of QemuOpts
* almost completely rewrote legacy options handling
* added missing license comment to audio_legacy.c0
audio/audio.h | 18 +- audio/audio_int.h | 16 +- audio/audio_template.h | 13 +- audio/alsaaudio.c | 2 +- audio/audio.c | 600 ++++++++++++++++------------------------- audio/audio_legacy.c | 294 ++++++++++++++++++++ audio/coreaudio.c | 2 +- audio/dsoundaudio.c | 2 +- audio/noaudio.c | 2 +- audio/ossaudio.c | 2 +- audio/paaudio.c | 2 +- audio/sdlaudio.c | 2 +- audio/spiceaudio.c | 2 +- audio/wavaudio.c | 2 +- vl.c | 7 +- audio/Makefile.objs | 2 +- 16 files changed, 588 insertions(+), 380 deletions(-) create mode 100644 audio/audio_legacy.c
audio/audio.h +15 -3
@@ -36,12 +36,21 @@ typedef void (*audio_callback_fn) (void *opaque, int avail);#define AUDIO_HOST_ENDIANNESS 0#endif -struct audsettings { +typedef struct audsettings {int freq;int nchannels;AudioFormat fmt;int endianness; -}; +}audsettings ; + +audsettings audiodev_to_audsettings (AudiodevPerDirectionOptions *pdo); +int audioformat_bytes_per_sample (AudioFormat fmt); +int audio_buffer_frames (AudiodevPerDirectionOptions *pdo, +audsettings *as,int def_usecs); +int audio_buffer_samples (AudiodevPerDirectionOptions *pdo, +audsettings *as,int def_usecs); +int audio_buffer_bytes (AudiodevPerDirectionOptions *pdo, +audsettings *as,int def_usecs); typedef enum { AUD_CNOTIFY_ENABLE,
@@ -81,7 +90,6 @@ typedef struct QEMUAudioTimeStamp { void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3); -void AUD_help (void );void AUD_register_card (const char *name,QEMUSoundCard *card);void AUD_remove_card (QEMUSoundCard *card); CaptureVoiceOut *AUD_add_capture (
@@ -163,4 +171,8 @@ void audio_sample_to_uint64(void *samples, int pos,void audio_sample_from_uint64 (void *samples,int pos,uint64_t left,uint64_t right); +void audio_parse_option (const char *opt); +void audio_init_audiodevs (void ); +void audio_legacy_help (void ); +#endif /* QEMU_AUDIO_H */
audio/audio_int.h +15 -1
@@ -146,7 +146,7 @@ struct audio_driver {const char *name;const char *descr;struct audio_option *options; -void *(*init) (void ); +void *(*init) (Audiodev *);void (*fini) (void *);struct audio_pcm_ops *pcm_ops;int can_be_default;
@@ -193,6 +193,7 @@ struct SWVoiceCap {struct AudioState {struct audio_driver *drv; +Audiodev *dev;void *drv_opaque;QEMUTimer *ts;
@@ -203,10 +204,13 @@ struct AudioState {int nb_hw_voices_out;int nb_hw_voices_in;int vm_running; +int64_t period_ticks; };extern const struct mixeng_volume nominal_volume; +extern const char *audio_prio_list[]; +void audio_driver_register (audio_driver *drv);audio_driver *audio_driver_lookup (const char *name);
@@ -248,4 +252,14 @@ static inline int audio_ring_dist (int dst, int src, int len)#define AUDIO_STRINGIFY_ (n) #n#define AUDIO_STRINGIFY (n) AUDIO_STRINGIFY_(n) +typedef struct AudiodevListEntry { +Audiodev *dev; +QSIMPLEQ_ENTRY (AudiodevListEntry) next; +}AudiodevListEntry ; + +typedef QSIMPLEQ_HEAD(, AudiodevListEntry) AudiodevListHead; +AudiodevListHead audio_handle_legacy_opts (void ); + +void audio_free_audiodev_list (AudiodevListHead *head); +#endif /* QEMU_AUDIO_INT_H */
audio/audio_template.h +9 -4
@@ -302,8 +302,10 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as)static HW *glue (audio_pcm_hw_add_ ,TYPE ) (struct audsettings *as) {HW *hw; +AudioState *s = &glob_audio_state; +AudiodevPerDirectionOptions *pdo = s->dev->TYPE; -if (glue (conf.fixed_,TYPE ).enabled &&glue (conf.fixed_,TYPE ).greedy) { +if (pdo->fixed_settings) { hw =glue (audio_pcm_hw_add_new_,TYPE ) (as);if (hw) {return hw;
@@ -331,9 +333,11 @@ 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 (glue (conf.fixed_,TYPE ).enabled) { - hw_as =glue (conf.fixed_,TYPE ).settings; +if (pdo->fixed_settings) { + hw_as =audiodev_to_audsettings (pdo); }else { hw_as = *as;
@@ -398,6 +402,7 @@ SW *glue (AUD_open_, TYPE) ( ) {AudioState *s = &glob_audio_state; +AudiodevPerDirectionOptions *pdo = s->dev->TYPE;if (audio_bug (__func__, !card || !name || !callback_fn || !as)) { dolog ("card=%p name=%p callback_fn=%p as=%p\n",
@@ -422,7 +427,7 @@ SW *glue (AUD_open_, TYPE) (return sw; } -if (!glue (conf.fixed_,TYPE ).enabled && sw) { +if (!pdo->fixed_settings && sw) {glue (AUD_close_,TYPE ) (card, sw); sw =NULL ; }
audio/alsaaudio.c +1 -1
@@ -1125,7 +1125,7 @@ static ALSAConf glob_conf = { .pcm_name_in = "default", }; -static void *alsa_audio_init (void ) +static void *alsa_audio_init (Audiodev *dev) {ALSAConf *conf =g_malloc (sizeof (ALSAConf)); *conf = glob_conf;
audio/audio.c +239 -361
770 lines not on this page · raw message
audio/audio_legacy.c new file +294 -0
294 lines not on this page · raw message
audio/coreaudio.c +1 -1
@@ -685,7 +685,7 @@ static CoreaudioConf glob_conf = { .nbuffers = 4, }; -static void *coreaudio_audio_init (void ) +static void *coreaudio_audio_init (Audiodev *dev) {CoreaudioConf *conf =g_malloc (sizeof (CoreaudioConf)); *conf = glob_conf;
audio/dsoundaudio.c +1 -1
@@ -783,7 +783,7 @@ static void dsound_audio_fini (void *opaque)g_free (s); } -static void *dsound_audio_init (void ) +static void *dsound_audio_init (Audiodev *dev) {int err;HRESULT hr;
audio/noaudio.c +1 -1
@@ -136,7 +136,7 @@ static int no_ctl_in (HWVoiceIn *hw, int cmd, ...)return 0 ; } -static void *no_audio_init (void ) +static void *no_audio_init (Audiodev *dev) {return &no_audio_init; }
audio/ossaudio.c +1 -1
@@ -842,7 +842,7 @@ static OSSConf glob_conf = { .policy = 5 }; -static void *oss_audio_init (void ) +static void *oss_audio_init (Audiodev *dev) {OSSConf *conf =g_malloc (sizeof (OSSConf)); *conf = glob_conf;
audio/paaudio.c +1 -1
@@ -812,7 +812,7 @@ static PAConf glob_conf = { .samples = 4096, }; -static void *qpa_audio_init (void ) +static void *qpa_audio_init (Audiodev *dev) {paaudio *g =g_malloc (sizeof (paaudio)); g->conf = glob_conf;
audio/sdlaudio.c +1 -1
@@ -436,7 +436,7 @@ static int sdl_ctl_out (HWVoiceOut *hw, int cmd, ...)return 0 ; } -static void *sdl_audio_init (void ) +static void *sdl_audio_init (Audiodev *dev) {SDLAudioState *s = &glob_sdl;if (s->driver_created) {
audio/spiceaudio.c +1 -1
@@ -77,7 +77,7 @@ static const SpiceRecordInterface record_sif = { .base.minor_version = SPICE_INTERFACE_RECORD_MINOR, }; -static void *spice_audio_init (void ) +static void *spice_audio_init (Audiodev *dev) {if (!using_spice) {return NULL ;
audio/wavaudio.c +1 -1
@@ -232,7 +232,7 @@ static WAVConf glob_conf = { .wav_path = "qemu.wav" }; -static void *wav_audio_init (void ) +static void *wav_audio_init (Audiodev *dev) {WAVConf *conf =g_malloc (sizeof (WAVConf)); *conf = glob_conf;
vl.c +6 -1
@@ -3302,9 +3302,12 @@ int main(int argc, char **argv, char **envp)add_device_config (DEV_BT , optarg);break ;case QEMU_OPTION_audio_help: -AUD_help (); +audio_legacy_help ();exit (0 );break ; +case QEMU_OPTION_audiodev: +audio_parse_option (optarg); +break ;case QEMU_OPTION_soundhw:select_soundhw (optarg);break ;
@@ -4533,6 +4536,8 @@ int main(int argc, char **argv, char **envp)/* do monitor/qmp handling at preconfig state if requested */ main_loop (); +audio_init_audiodevs (); +/* from here on runstate is RUN_STATE_PRELAUNCH */ machine_run_board_init (current_machine);
audio/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-y = audio.o noaudio.o wavaudio.o mixeng.o +common-obj-y = audio.o audio_legacy.o noaudio.o wavaudio.o mixeng.o common-obj-$(CONFIG_SPICE) += spiceaudio.o common-obj-$(CONFIG_AUDIO_COREAUDIO) += coreaudio.o common-obj-$(CONFIG_AUDIO_DSOUND) += dsoundaudio.o
Signature · 1 line
2.20.1
PATCH v3 28/50 coreaudio: port to the new audio backend api
In reply to Kővágó, Zoltán--- audio/coreaudio.c | 130 ++++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 61 deletions(-)
audio/coreaudio.c +69 -61
@@ -43,9 +43,6 @@ typedef struct coreaudioVoiceOut {UInt32 audioDevicePropertyBufferFrameSize;AudioStreamBasicDescription outputStreamBasicDescription;AudioDeviceIOProcID ioprocid; -size_t live; -size_t decr; -size_t rpos; } coreaudioVoiceOut;#if MAC_OS_X_VERSION_MAX_ALLOWED >=MAC_OS_X_VERSION_10_6
@@ -397,31 +394,29 @@ static int coreaudio_unlock (coreaudioVoiceOut *core, const char *fn_name)return 0 ; } -static size_t coreaudio_run_out (HWVoiceOut *hw,size_t live) -{ -size_t decr; -coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; - -if (coreaudio_lock (core,"coreaudio_run_out" )) { -return 0 ; +#define COREAUDIO_WRAPPER_FUNC (name, ret_type, args_decl, args) \ + static ret_type glue(coreaudio_, name)args_decl \ + { \ + coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; \ + ret_type ret; \ + \ + if (coreaudio_lock(core, "coreaudio_" #name)) { \ + return 0; \ + } \ + \ + ret = glue(audio_generic_, name)args; \ + \ + coreaudio_unlock(core, "coreaudio_" #name); \ + return ret; \ } - -if (core->decr > live) { -ldebug ("core->decr %d live %d core->live %d\n" , - core->decr, - live, - core->live); - } - - decr =MIN (core->decr, live); - core->decr -= decr; - - core->live = live - decr; - hw->rpos = core->rpos; - -coreaudio_unlock (core,"coreaudio_run_out" ); -return decr; -} +COREAUDIO_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size), + (hw, size)) +COREAUDIO_WRAPPER_FUNC (put_buffer_out_nowrite, size_t, + (HWVoiceOut *hw, void *buf, size_t size), + (hw, buf, size)) +COREAUDIO_WRAPPER_FUNC(write, size_t, (HWVoiceOut *hw, void *buf, size_t size), + (hw, buf, size)) +#undef COREAUDIO_WRAPPER_FUNC/* callback to feed audiooutput buffer */ static OSStatus audioDeviceIOProc(
@@ -433,19 +428,11 @@ static OSStatus audioDeviceIOProc(const AudioTimeStamp * inOutputTime, void* hwptr) { - UInt32 frame, frameCount; -float *out = outOutputData->mBuffers[0 ].mData; + UInt32 frameCount, pending_frames; +void *out = outOutputData->mBuffers[0 ].mData;HWVoiceOut *hw = hwptr;coreaudioVoiceOut *core = (coreaudioVoiceOut *) hwptr; -int rpos, live; -struct st_sample *src; -#ifndef FLOAT_MIXENG -#ifdef RECIPROCAL -const float scale =1.f /UINT_MAX ; -#else -const float scale =UINT_MAX ; -#endif -#endif +size_t len;if (coreaudio_lock (core,"audioDeviceIOProc" )) { inInputTime =0 ;
@@ -453,42 +440,51 @@ static OSStatus audioDeviceIOProc( } frameCount = core->audioDevicePropertyBufferFrameSize; - live = core->live; + pending_frames = hw->pending_emul >> hw->info.shift;/* if there are not enough samples, set signal and return */ -if (live < frameCount) { +if (pending_frames < frameCount) { inInputTime =0 ;coreaudio_unlock (core,"audioDeviceIOProc(empty)" );return 0 ; } - rpos = core->rpos; - src = hw->mix_buf + rpos; + len = frameCount << hw->info.shift; +while (len) { +size_t write_len; +ssize_t start = ((ssize_t ) hw->pos_emul) - hw->pending_emul; +if (start <0 ) { + start += hw->size_emul; + } +assert (start >=0 && start < hw->size_emul); -/* fill buffer */ -for (frame =0 ; frame < frameCount; frame++) { -#ifdef FLOAT_MIXENG - *out++ = src[frame].l;/* left channel */ - *out++ = src[frame].r;/* right channel */ -#else -#ifdef RECIPROCAL - *out++ = src[frame].l * scale;/* left channel */ - *out++ = src[frame].r * scale;/* right channel */ -#else - *out++ = src[frame].l / scale;/* left channel */ - *out++ = src[frame].r / scale;/* right channel */ -#endif -#endif + write_len =MIN (MIN (hw->pending_emul, len), + hw->size_emul - start); + +memcpy (out, hw->buf_emul + start, write_len); + hw->pending_emul -= write_len; + len -= write_len; + out += write_len; } - rpos = (rpos + frameCount) % hw->samples; - core->decr += frameCount; - core->rpos = rpos; -coreaudio_unlock (core,"audioDeviceIOProc" );return 0 ; } +static UInt32 coreaudio_get_flags (struct audio_pcm_info *info, +struct audsettings *as) +{ +UInt32 flags = info->sign ? kAudioFormatFlagIsSignedInteger :0 ; +if (as->endianness) {/* 0 = little, 1 = big */ + flags |= kAudioFormatFlagIsBigEndian; + } + +if (flags ==0 ) {/* must not be 0 */ + flags = kAudioFormatFlagsAreAllClear; + } +return flags; +} +static int coreaudio_init_out (HWVoiceOut *hw,struct audsettings *as,void *drv_opaque) {
@@ -576,6 +572,16 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,/* set Samplerate */ core->outputStreamBasicDescription.mSampleRate = (Float64 ) as->freq; + core->outputStreamBasicDescription.mFormatID = kAudioFormatLinearPCM; + core->outputStreamBasicDescription.mFormatFlags = +coreaudio_get_flags (&hw->info, as); + core->outputStreamBasicDescription.mBytesPerPacket = + core->outputStreamBasicDescription.mBytesPerFrame = + hw->info.nchannels * hw->info.bits /8 ; + core->outputStreamBasicDescription.mFramesPerPacket =1 ; + core->outputStreamBasicDescription.mChannelsPerFrame = hw->info.nchannels; + core->outputStreamBasicDescription.mBitsPerChannel = hw->info.bits; + status =coreaudio_set_streamformat (core->outputDeviceID, &core->outputStreamBasicDescription);if (status != kAudioHardwareNoError) {
@@ -686,7 +692,9 @@ static void coreaudio_audio_fini (void *opaque)static struct audio_pcm_ops coreaudio_pcm_ops = { .init_out = coreaudio_init_out, .fini_out = coreaudio_fini_out, - .run_out = coreaudio_run_out, + .write = coreaudio_write, + .get_buffer_out = coreaudio_get_buffer_out, + .put_buffer_out = coreaudio_put_buffer_out_nowrite, .ctl_out = coreaudio_ctl_out };
Signature · 1 line
2.20.1
PATCH v3 32/50 paaudio: port to the new audio backend api
In reply to Kővágó, Zoltán--- configure | 5 - audio/audio_pt_int.h | 22 --- audio/audio_pt_int.c | 174 -------------------- audio/paaudio.c | 372 ++++++------------------------------------- audio/Makefile.objs | 1 - 5 files changed, 45 insertions(+), 529 deletions(-) delete mode 100644 audio/audio_pt_int.h delete mode 100644 audio/audio_pt_int.c
configure +0 -5
@@ -286,7 +286,6 @@ block_drv_ro_whitelist="" host_cc="cc" libs_softmmu="" libs_tools="" -audio_pt_int="" audio_win_int="" libs_qga="" debug_info="yes"
@@ -3329,7 +3328,6 @@ for drv in $audio_drv_list; do audio_drv_probe $drv pulse/pulseaudio.h "-lpulse" \ "pa_context_set_source_output_volume(NULL, 0, NULL, NULL, NULL); return 0;" pulse_libs="-lpulse" - audio_pt_int="yes" ;; sdl)
@@ -6310,9 +6308,6 @@ echo "PULSE_LIBS=$pulse_libs" >> $config_host_mak echo "COREAUDIO_LIBS=$coreaudio_libs" >> $config_host_mak echo "DSOUND_LIBS=$dsound_libs" >> $config_host_mak echo "OSS_LIBS=$oss_libs" >> $config_host_mak -if test "$audio_pt_int" = "yes" ; then - echo "CONFIG_AUDIO_PT_INT=y" >> $config_host_mak -fi if test "$audio_win_int" = "yes" ; then echo "CONFIG_AUDIO_WIN_INT=y" >> $config_host_mak fi
audio/audio_pt_int.h deleted +0 -22
@@ -1,22 +0,0 @@ -#ifndef QEMU_AUDIO_PT_INT_H -#define QEMU_AUDIO_PT_INT_H - -#include <pthread.h> - -struct audio_pt { -const char *drv; -pthread_t thread; -pthread_cond_t cond; -pthread_mutex_t mutex; -}; - -int audio_pt_init (struct audio_pt *,void *(*) (void *),void *, -const char *,const char *); -int audio_pt_fini (struct audio_pt *,const char *); -int audio_pt_lock (struct audio_pt *,const char *); -int audio_pt_unlock (struct audio_pt *,const char *); -int audio_pt_wait (struct audio_pt *,const char *); -int audio_pt_unlock_and_signal (struct audio_pt *,const char *); -int audio_pt_join (struct audio_pt *,void **,const char *); - -#endif /* QEMU_AUDIO_PT_INT_H */
audio/audio_pt_int.c deleted +0 -174
174 lines not on this page · raw message
audio/paaudio.c +45 -327
509 lines not on this page · raw message
audio/Makefile.objs +0 -1
@@ -2,7 +2,6 @@ common-obj-y = audio.o audio_legacy.o noaudio.o wavaudio.o mixeng.o common-obj-$(CONFIG_SPICE) += spiceaudio.o common-obj-$(CONFIG_AUDIO_COREAUDIO) += coreaudio.o common-obj-$(CONFIG_AUDIO_DSOUND) += dsoundaudio.o -common-obj-$(CONFIG_AUDIO_PT_INT) += audio_pt_int.o common-obj-$(CONFIG_AUDIO_WIN_INT) += audio_win_int.o common-obj-y += wavcapture.o
Signature · 1 line
2.20.1
PATCH v3 36/50 audio: remove remains of the old backend api
In reply to Kővágó, Zoltán--- audio/audio_int.h | 7 ------- audio/audio.c | 42 ++++++------------------------------------ 2 files changed, 6 insertions(+), 43 deletions(-)
audio/audio_int.h +0 -7
@@ -152,7 +152,6 @@ struct audio_driver {struct audio_pcm_ops {int (*init_out)(HWVoiceOut *hw,audsettings *as,void *drv_opaque);void (*fini_out)(HWVoiceOut *hw); -size_t (*run_out)(HWVoiceOut *hw,size_t live);size_t (*write) (HWVoiceOut *hw,void *buf,size_t size);/* * get a buffer that after later can be passed to put_buffer_out; optional
@@ -170,7 +169,6 @@ struct audio_pcm_ops {int (*init_in) (HWVoiceIn *hw,audsettings *as,void *drv_opaque);void (*fini_in) (HWVoiceIn *hw); -size_t (*run_in)(HWVoiceIn *hw);size_t (*read) (HWVoiceIn *hw,void *buf,size_t size);void *(*get_buffer_in)(HWVoiceIn *hw,size_t *size);void (*put_buffer_in)(HWVoiceIn *hw,void *buf,size_t size);
@@ -236,11 +234,6 @@ audio_driver *audio_driver_lookup(const char *name);void audio_pcm_init_info (struct audio_pcm_info *info,struct audsettings *as);void audio_pcm_info_clear_buf (struct audio_pcm_info *info,void *buf,int len); -size_t audio_pcm_hw_get_live_in (HWVoiceIn *hw); - -size_t audio_pcm_hw_clip_out (HWVoiceOut *hw,void *pcm_buf, -size_t live,size_t pending); -int audio_bug (const char *funcname,int cond);void *audio_calloc (const char *funcname,int nmemb,size_t size);
audio/audio.c +6 -36
72 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 34/50 spiceaudio: port to the new audio backend api
In reply to Kővágó, Zoltán--- audio/spiceaudio.c | 112 +++++++++++++++------------------------------ 1 file changed, 38 insertions(+), 74 deletions(-)
audio/spiceaudio.c +38 -74
@@ -51,7 +51,7 @@ typedef struct SpiceVoiceOut {SpiceRateCtl rate;int active;uint32_t *frame; -uint32_t *fpos; +uint32_t fpos;uint32_t fsize; } SpiceVoiceOut;
@@ -60,7 +60,6 @@ typedef struct SpiceVoiceIn {SpiceRecordInstance sin;SpiceRateCtl rate;int active; -uint32_t samples[LINE_IN_SAMPLES ]; } SpiceVoiceIn;static const SpicePlaybackInterface playback_sif = {
@@ -152,44 +151,36 @@ static void line_out_fini (HWVoiceOut *hw)spice_server_remove_interface (&out->sin.base); } -static size_t line_out_run (HWVoiceOut *hw,size_t live) +static void *line_out_get_buffer (HWVoiceOut *hw,size_t *size) { -SpiceVoiceOut *out =container_of (hw, SpiceVoiceOut, hw); -size_t rpos, decr; -size_t samples; +SpiceVoiceOut *out =container_of (hw, SpiceVoiceOut, hw); +size_t decr; -if (!live) { -return 0 ; +if (!out->frame) { +spice_server_playback_get_buffer (&out->sin, &out->frame, &out->fsize); + out->fpos =0 ; } - decr =rate_get_samples (&hw->info, &out->rate); - decr =MIN (live, decr); + decr =rate_get_samples (&hw->info, &out->rate); + decr =MIN (out->fsize - out->fpos, decr); - samples = decr; - rpos = hw->rpos; -while (samples) { -int left_till_end_samples = hw->samples - rpos; -int len =MIN (samples, left_till_end_samples); + *size = decr << hw->info.shift; +return out->frame + out->fpos; +} -if (!out->frame) { -spice_server_playback_get_buffer (&out->sin, &out->frame, &out->fsize); - out->fpos = out->frame; - } -if (out->frame) { - len =MIN (len, out->fsize); - hw->clip (out->fpos, hw->mix_buf + rpos, len); - out->fsize -= len; - out->fpos += len; -if (out->fsize ==0 ) { -spice_server_playback_put_samples (&out->sin, out->frame); - out->frame = out->fpos =NULL ; - } - } - rpos = (rpos + len) % hw->samples; - samples -= len; +static size_t line_out_put_buffer (HWVoiceOut *hw,void *buf,size_t size) +{ +SpiceVoiceOut *out =container_of (hw, SpiceVoiceOut, hw); + + out->fpos += size >>2 ; +assert (buf == out->frame + out->fpos && out->fpos <= out->fsize); + +if (out->fpos == out->fsize) {/* buffer full */ +spice_server_playback_put_samples (&out->sin, out->frame); + out->frame =NULL ; } - hw->rpos = rpos; -return decr; + +return size; }static int line_out_ctl (HWVoiceOut *hw,int cmd, ...)
@@ -211,9 +202,9 @@ static int line_out_ctl (HWVoiceOut *hw, int cmd, ...) } out->active =0 ;if (out->frame) { -memset (out->fpos,0 , out->fsize <<2 ); +memset (out->frame + out->fpos,0 , (out->fsize - out->fpos) <<2 );spice_server_playback_put_samples (&out->sin, out->frame); - out->frame = out->fpos =NULL ; + out->frame =NULL ; }spice_server_playback_stop (&out->sin);break ;
@@ -275,49 +266,20 @@ static void line_in_fini (HWVoiceIn *hw)spice_server_remove_interface (&in->sin.base); } -static size_t line_in_run (HWVoiceIn *hw) +static size_t line_in_read (HWVoiceIn *hw,void *buf,size_t len) {SpiceVoiceIn *in =container_of (hw, SpiceVoiceIn, hw); -size_t num_samples; -int ready; -size_t len[2 ]; -uint64_t delta_samp; -const uint32_t *samples; +uint64_t delta_samp =rate_get_samples (&hw->info, &in->rate); +uint64_t to_read =MIN (len >>2 , delta_samp); +size_t ready =spice_server_record_get_samples (&in->sin, buf, to_read); -if (!(num_samples = hw->samples -audio_pcm_hw_get_live_in (hw))) { -return 0 ; - } - - delta_samp =rate_get_samples (&hw->info, &in->rate); - num_samples =MIN (num_samples, delta_samp); - - ready =spice_server_record_get_samples (&in->sin, in->samples, num_samples); - samples = in->samples; +/* XXX: do we need this? */ if (ready ==0 ) { -static const uint32_t silence[LINE_IN_SAMPLES ]; - samples = silence; - ready =LINE_IN_SAMPLES ; +memset (buf,0 , to_read <<2 ); + ready = to_read; } - num_samples =MIN (ready, num_samples); - -if (hw->wpos + num_samples > hw->samples) { - len[0 ] = hw->samples - hw->wpos; - len[1 ] = num_samples - len[0 ]; - }else { - len[0 ] = num_samples; - len[1 ] =0 ; - } - - hw->conv (hw->conv_buf + hw->wpos, samples, len[0 ]); - -if (len[1 ]) { - hw->conv (hw->conv_buf, samples + len[0 ], len[1 ]); - } - - hw->wpos = (hw->wpos + num_samples) % hw->samples; - -return num_samples; +return ready <<2 ; }static int line_in_ctl (HWVoiceIn *hw,int cmd, ...)
@@ -366,12 +328,14 @@ static int line_in_ctl (HWVoiceIn *hw, int cmd, ...)static struct audio_pcm_ops audio_callbacks = { .init_out = line_out_init, .fini_out = line_out_fini, - .run_out = line_out_run, + .write = audio_generic_write, + .get_buffer_out = line_out_get_buffer, + .put_buffer_out = line_out_put_buffer, .ctl_out = line_out_ctl, .init_in = line_in_init, .fini_in = line_in_fini, - .run_in = line_in_run, + .read = line_in_read, .ctl_in = line_in_ctl, };
Signature · 1 line
2.20.1
PATCH v3 43/50 paaudio: get/put_buffer functions
In reply to Kővágó, ZoltánThis lets us avoid some buffer copying when using mixeng.
--- audio/paaudio.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+)
audio/paaudio.c +83 -0
@@ -97,6 +97,59 @@ static inline int PA_STREAM_IS_GOOD(pa_stream_state_t x) } \ }while (0 ) +static void *qpa_get_buffer_in(HWVoiceIn *hw, size_t *size) +{ +PAVoiceIn *p = (PAVoiceIn *) hw; +PAConnection *c = p->g->conn; +int r; + +pa_threaded_mainloop_lock (c->mainloop); + +CHECK_DEAD_GOTO (c, p->stream, unlock_and_fail, +"pa_threaded_mainloop_lock failed\n" ); + +if (!p->read_length) { + r =pa_stream_peek (p->stream, &p->read_data, &p->read_length); +CHECK_SUCCESS_GOTO (c, r ==0 , unlock_and_fail, +"pa_stream_peek failed\n" ); + } + + *size =MIN (p->read_length, *size); + +pa_threaded_mainloop_unlock (c->mainloop); +return (void *) p->read_data; + +unlock_and_fail: +pa_threaded_mainloop_unlock (c->mainloop); + *size =0 ; +return NULL ; +} + +static void qpa_put_buffer_in (HWVoiceIn *hw,void *buf,size_t size) +{ +PAVoiceIn *p = (PAVoiceIn *) hw; +PAConnection *c = p->g->conn; +int r; + +pa_threaded_mainloop_lock (c->mainloop); + +CHECK_DEAD_GOTO (c, p->stream, unlock, +"pa_threaded_mainloop_lock failed\n" ); + +assert (buf == p->read_data && size <= p->read_length); + + p->read_data += size; + p->read_length -= size; + +if (size && !p->read_length) { + r =pa_stream_drop (p->stream); +CHECK_SUCCESS_GOTO (c, r ==0 , unlock,"pa_stream_drop failed\n" ); + } + +unlock: +pa_threaded_mainloop_unlock (c->mainloop); +} +static size_t qpa_read (HWVoiceIn *hw,void *data,size_t length) {PAVoiceIn *p = (PAVoiceIn *) hw;
@@ -135,6 +188,32 @@ unlock_and_fail:return 0 ; } +static void *qpa_get_buffer_out (HWVoiceOut *hw,size_t *size) +{ +PAVoiceOut *p = (PAVoiceOut *) hw; +PAConnection *c = p->g->conn; +void *ret; +int r; + +pa_threaded_mainloop_lock (c->mainloop); + +CHECK_DEAD_GOTO (c, p->stream, unlock_and_fail, +"pa_threaded_mainloop_lock failed\n" ); + + *size =-1 ; + r =pa_stream_begin_write (p->stream, &ret, size); +CHECK_SUCCESS_GOTO (c, r >=0 , unlock_and_fail, +"pa_stream_begin_write failed\n" ); + +pa_threaded_mainloop_unlock (c->mainloop); +return ret; + +unlock_and_fail: +pa_threaded_mainloop_unlock (c->mainloop); + *size =0 ; +return NULL ; +} +static size_t qpa_write (HWVoiceOut *hw,void *data,size_t length) {PAVoiceOut *p = (PAVoiceOut *) hw;
@@ -683,12 +762,16 @@ static struct audio_pcm_ops qpa_pcm_ops = { .fini_out = qpa_fini_out, .write = qpa_write, .buffer_size_out = qpa_buffer_size_out, + .get_buffer_out = qpa_get_buffer_out, + .put_buffer_out = qpa_write, /* pa handles it */ .volume_out = qpa_volume_out, .init_in = qpa_init_in, .fini_in = qpa_fini_in, .read = qpa_read, .buffer_size_in = qpa_buffer_size_in, + .get_buffer_in = qpa_get_buffer_in, + .put_buffer_in = qpa_put_buffer_in, .volume_in = qpa_volume_in };
Signature · 1 line
2.20.1
PATCH v3 33/50 sdlaudio: port to the new audio backend api
In reply to Kővágó, ZoltánSDL2 is still a big mess, but it's probably not worse than the current version.
--- audio/sdlaudio.c | 136 +++++++++++++++++------------------------------ 1 file changed, 50 insertions(+), 86 deletions(-)
audio/sdlaudio.c +50 -86
@@ -42,11 +42,6 @@typedef struct SDLVoiceOut {HWVoiceOut hw; -size_t live; -#if USE_SEMAPHORE -size_t rpos; -#endif -size_t decr; }SDLVoiceOut ; static struct SDLAudioState {
@@ -252,17 +247,13 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)SDLVoiceOut *sdl = opaque;SDLAudioState *s = &glob_sdl;HWVoiceOut *hw = &sdl->hw; -size_t samples = len >> hw->info.shift;if (s->exit) {return ; } -while (samples) { -size_t to_mix, decr; - -/* dolog ("in callback samples=%d\n", samples); */ #if USE_SEMAPHORE +while (len) {sdl_wait (s,"sdl_callback" );if (s->exit) {return ;
@@ -271,95 +262,66 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)if (sdl_lock (s,"sdl_callback" )) {return ; } - -if (audio_bug (__func__, sdl->live <0 || sdl->live > hw->samples)) { -dolog ("sdl->live=%d hw->samples=%zu\n" , sdl->live, hw->samples); -return ; - } - -if (!sdl->live) { - goto again; - } -#else -if (s->exit || !sdl->live) { -break ; - }#endif -/* dolog ("in callback live=%d\n", live); */ - to_mix =MIN (samples, sdl->live); - decr = to_mix; -while (to_mix) { -size_t chunk =MIN (to_mix, hw->samples - hw->rpos); -struct st_sample *src = hw->mix_buf + hw->rpos; +while (hw->pending_emul && len) { +size_t write_len; +ssize_t start = ((ssize_t ) hw->pos_emul) - hw->pending_emul; +if (start <0 ) { + start += hw->size_emul; + } +assert (start >=0 && start < hw->size_emul); -/* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */ - hw->clip (buf, src, chunk); -#if USE_SEMAPHORE - sdl->rpos = (sdl->rpos + chunk) % hw->samples; -#else - hw->rpos = (hw->rpos + chunk) % hw->samples; -#endif - to_mix -= chunk; - buf += chunk << hw->info.shift; + write_len =MIN (MIN (hw->pending_emul, len), + hw->size_emul - start); + +memcpy (buf, hw->buf_emul + start, write_len); + hw->pending_emul -= write_len; + len -= write_len; + buf += write_len; } - samples -= decr; - sdl->live -= decr; - sdl->decr += decr;#if USE_SEMAPHORE - again:if (sdl_unlock (s,"sdl_callback" )) {return ; } -#endif } -/* dolog ("done len=%d\n", len); */ - -#if (SDL_MAJOR_VERSION >=2 ) -/* SDL2 does not clear the remaining buffer for us, so do it on our own */ -if (samples) { -memset (buf,0 , samples << hw->info.shift); - } -#endif -} - -static size_t sdl_run_out (HWVoiceOut *hw,size_t live) -{ -size_t decr; -SDLVoiceOut *sdl = (SDLVoiceOut *) hw; -SDLAudioState *s = &glob_sdl; - -if (sdl_lock (s,"sdl_run_out" )) { -return 0 ; - } - -if (sdl->decr > live) { -ldebug ("sdl->decr %d live %d sdl->live %d\n" , - sdl->decr, - live, - sdl->live); - } - - decr =MIN (sdl->decr, live); - sdl->decr -= decr; - -#if USE_SEMAPHORE - sdl->live = live - decr; - hw->rpos = sdl->rpos;#else - sdl->live = live; +/* clear remaining buffer that we couldn't fill with data */ +if (len) { +memset (buf,0 , len); + }#endif - -if (sdl->live >0 ) { -sdl_unlock_and_post (s,"sdl_run_out" ); - } -else { -sdl_unlock (s,"sdl_run_out" ); - } -return decr; } +#define SDL_WRAPPER_FUNC (name, ret_type, args_decl, args, fail, unlock) \ + static ret_type glue(sdl_, name)args_decl \ + { \ + SDLAudioState *s = &glob_sdl; \ + ret_type ret; \ + \ + if (sdl_lock(s, "sdl_" #name)) { \ + fail; \ + return 0;/* implicitly casts to NULL */ \ + } \ + \ + ret = glue(audio_generic_, name)args; \ + \ + unlock(s, "sdl_" #name); \ +return ret; \ + } + +SDL_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size), + (hw, size), *size = 0, sdl_unlock) +SDL_WRAPPER_FUNC (put_buffer_out_nowrite, size_t, + (HWVoiceOut *hw, void *buf, size_t size), (hw, buf, size), + /*nothing*/, sdl_unlock_and_post) +SDL_WRAPPER_FUNC (write, size_t, + (HWVoiceOut *hw, void *buf, size_t size), (hw, buf, size), + /* nothing */, sdl_unlock_and_post) + +#undef SDL_WRAPPER_FUNC +static void sdl_fini_out (HWVoiceOut *hw) { (void ) hw;
@@ -476,7 +438,9 @@ static void sdl_audio_fini (void *opaque)static struct audio_pcm_ops sdl_pcm_ops = { .init_out = sdl_init_out, .fini_out = sdl_fini_out, - .run_out = sdl_run_out, + .write = sdl_write, + .get_buffer_out = sdl_get_buffer_out, + .put_buffer_out = sdl_put_buffer_out_nowrite, .ctl_out = sdl_ctl_out, };
Signature · 1 line
2.20.1
PATCH v3 35/50 wavaudio: port to the new audio backend api
In reply to Kővágó, Zoltán--- audio/wavaudio.c | 54 ++++++++---------------------------------------- 1 file changed, 9 insertions(+), 45 deletions(-)
audio/wavaudio.c +9 -45
@@ -34,52 +34,28 @@ typedef struct WAVVoiceOut {HWVoiceOut hw;FILE *f;int64_t old_ticks; -void *pcm_buf;int total_samples; } WAVVoiceOut; -static size_t wav_run_out (HWVoiceOut *hw,size_t live) +static size_t wav_write_out (HWVoiceOut *hw,void *buf,size_t len) {WAVVoiceOut *wav = (WAVVoiceOut *) hw; -size_t rpos, decr, samples; -uint8_t *dst; -struct st_sample *src;int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );int64_t ticks = now - wav->old_ticks;int64_t bytes =muldiv64 (ticks, hw->info.bytes_per_second,NANOSECONDS_PER_SECOND ); -if (bytes >INT_MAX ) { - samples =INT_MAX >> hw->info.shift; - } -else { - samples = bytes >> hw->info.shift; - } - + bytes =MIN (bytes, len); + bytes = bytes >> hw->info.shift << hw->info.shift; wav->old_ticks = now; - decr =MIN (live, samples); - samples = decr; - rpos = hw->rpos; -while (samples) { -int left_till_end_samples = hw->samples - rpos; -int convert_samples =MIN (samples, left_till_end_samples); - src = hw->mix_buf + rpos; - dst =advance (wav->pcm_buf, rpos << hw->info.shift); - - hw->clip (dst, src, convert_samples); -if (fwrite (dst, convert_samples << hw->info.shift,1 , wav->f) !=1 ) { -dolog ("wav_run_out: fwrite of %d bytes failed\nReaons: %s\n" , - convert_samples << hw->info.shift,strerror (errno)); - } - - rpos = (rpos + convert_samples) % hw->samples; - samples -= convert_samples; - wav->total_samples += convert_samples; +if (bytes &&fwrite (buf, bytes,1 , wav->f) !=1 ) { +dolog ("wav_write_out: fwrite of %zu bytes failed\nReaons: %s\n" , + bytes,strerror (errno)); } - hw->rpos = rpos; -return decr; + wav->total_samples += bytes >> hw->info.shift; +return bytes; }/* VICE code: Store number as little endian. */
@@ -135,13 +111,6 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as,audio_pcm_init_info (&hw->info, &wav_as); hw->samples =1024 ; - wav->pcm_buf =audio_calloc (__func__, hw->samples,1 << hw->info.shift); -if (!wav->pcm_buf) { -dolog ("Could not allocate buffer (%zu bytes)\n" , - hw->samples << hw->info.shift); -return -1 ; - } -le_store (hdr +22 , hw->info.nchannels,2 );le_store (hdr +24 , hw->info.freq,4 );le_store (hdr +28 , hw->info.freq << (bits16 + stereo),4 );
@@ -151,8 +120,6 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as,if (!wav->f) {dolog ("Failed to open wave file `%s'\nReason: %s\n" , wav_path,strerror (errno)); -g_free (wav->pcm_buf); - wav->pcm_buf =NULL ;return -1 ; }
@@ -206,9 +173,6 @@ static void wav_fini_out (HWVoiceOut *hw) wav->f, strerror (errno)); } wav->f =NULL ; - -g_free (wav->pcm_buf); - wav->pcm_buf =NULL ; }static int wav_ctl_out (HWVoiceOut *hw,int cmd, ...)
@@ -232,7 +196,7 @@ static void wav_audio_fini (void *opaque)static struct audio_pcm_ops wav_pcm_ops = { .init_out = wav_init_out, .fini_out = wav_fini_out, - .run_out = wav_run_out, + .write = wav_write_out, .ctl_out = wav_ctl_out, };
Signature · 1 line
2.20.1
PATCH v3 24/50 audio: remove read and write pcm_ops
In reply to Kővágó, ZoltánThey just called audio_pcm_sw_read/write anyway, so it makes no sense to have them too. (The noaudio's read is the only exception, but it should work with the generic code too.)
--- audio/audio_int.h | 5 ----- audio/alsaaudio.c | 12 ------------ audio/audio.c | 8 ++++---- audio/coreaudio.c | 6 ------ audio/dsoundaudio.c | 12 ------------ audio/noaudio.c | 19 ------------------- audio/ossaudio.c | 12 ------------ audio/paaudio.c | 12 ------------ audio/sdlaudio.c | 6 ------ audio/spiceaudio.c | 12 ------------ audio/wavaudio.c | 6 ------ 11 files changed, 4 insertions(+), 106 deletions(-)
audio/audio_int.h +0 -5
@@ -149,13 +149,11 @@ struct audio_pcm_ops {int (*init_out)(HWVoiceOut *hw,struct audsettings *as,void *drv_opaque);void (*fini_out)(HWVoiceOut *hw);int (*run_out) (HWVoiceOut *hw,int live); -int (*write) (SWVoiceOut *sw,void *buf,int size);int (*ctl_out) (HWVoiceOut *hw,int cmd, ...);int (*init_in) (HWVoiceIn *hw,struct audsettings *as,void *drv_opaque);void (*fini_in) (HWVoiceIn *hw);int (*run_in) (HWVoiceIn *hw); -int (*read) (SWVoiceIn *sw,void *buf,int size);int (*ctl_in) (HWVoiceIn *hw,int cmd, ...); };
@@ -209,11 +207,8 @@ audio_driver *audio_driver_lookup(const char *name);void audio_pcm_init_info (struct audio_pcm_info *info,struct audsettings *as);void audio_pcm_info_clear_buf (struct audio_pcm_info *info,void *buf,int len); -int audio_pcm_sw_write (SWVoiceOut *sw,void *buf,int len);int audio_pcm_hw_get_live_in (HWVoiceIn *hw); -int audio_pcm_sw_read (SWVoiceIn *sw,void *buf,int len); -int audio_pcm_hw_clip_out (HWVoiceOut *hw,void *pcm_buf,int live,int pending);
audio/alsaaudio.c +0 -12
@@ -269,11 +269,6 @@ static int alsa_poll_in (HWVoiceIn *hw)return alsa_poll_helper (alsa->handle, &alsa->pollhlp,POLLIN ); } -static int alsa_write (SWVoiceOut *sw,void *buf,int len) -{ -return audio_pcm_sw_write (sw, buf, len); -} -static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt,int endianness) {switch (fmt) {
@@ -995,11 +990,6 @@ static int alsa_run_in (HWVoiceIn *hw)return read_samples; } -static int alsa_read (SWVoiceIn *sw,void *buf,int size) -{ -return audio_pcm_sw_read (sw, buf, size); -} -static int alsa_ctl_in (HWVoiceIn *hw,int cmd, ...) {ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
@@ -1088,13 +1078,11 @@ static struct audio_pcm_ops alsa_pcm_ops = { .init_out = alsa_init_out, .fini_out = alsa_fini_out, .run_out = alsa_run_out, - .write = alsa_write, .ctl_out = alsa_ctl_out, .init_in = alsa_init_in, .fini_in = alsa_fini_in, .run_in = alsa_run_in, - .read = alsa_read, .ctl_in = alsa_ctl_in, };
audio/audio.c +4 -4
@@ -597,7 +597,7 @@ static int audio_pcm_sw_get_rpos_in (SWVoiceIn *sw) } } -int audio_pcm_sw_read (SWVoiceIn *sw,void *buf,int size) +static int audio_pcm_sw_read (SWVoiceIn *sw,void *buf,int size) {HWVoiceIn *hw = sw->hw;int samples, live, ret =0 , swlim, isamp, osamp, rpos, total =0 ;
@@ -699,7 +699,7 @@ static int audio_pcm_hw_get_live_out (HWVoiceOut *hw, int *nb_live)/* * Soft voice (playback) */ -int audio_pcm_sw_write (SWVoiceOut *sw,void *buf,int size) +static int audio_pcm_sw_write (SWVoiceOut *sw,void *buf,int size) {int hwsamples, samples, isamp, osamp, wpos, live, dead, left, swlim, blck;int ret =0 , pos =0 , total =0 ;
@@ -857,7 +857,7 @@ int AUD_write (SWVoiceOut *sw, void *buf, int size)return 0 ; } -return sw->hw->pcm_ops->write (sw, buf, size); +return audio_pcm_sw_write (sw, buf, size); }int AUD_read (SWVoiceIn *sw,void *buf,int size)
@@ -872,7 +872,7 @@ int AUD_read (SWVoiceIn *sw, void *buf, int size)return 0 ; } -return sw->hw->pcm_ops->read (sw, buf, size); +return audio_pcm_sw_read (sw, buf, size); }int AUD_get_buffer_size_out (SWVoiceOut *sw)
audio/coreaudio.c +0 -6
@@ -489,11 +489,6 @@ static OSStatus audioDeviceIOProc(return 0 ; } -static int coreaudio_write (SWVoiceOut *sw,void *buf,int len) -{ -return audio_pcm_sw_write (sw, buf, len); -} -static int coreaudio_init_out (HWVoiceOut *hw,struct audsettings *as,void *drv_opaque) {
@@ -692,7 +687,6 @@ static struct audio_pcm_ops coreaudio_pcm_ops = { .init_out = coreaudio_init_out, .fini_out = coreaudio_fini_out, .run_out = coreaudio_run_out, - .write = coreaudio_write, .ctl_out = coreaudio_ctl_out };
audio/dsoundaudio.c +0 -12
@@ -454,11 +454,6 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...)return 0 ; } -static int dsound_write (SWVoiceOut *sw,void *buf,int len) -{ -return audio_pcm_sw_write (sw, buf, len); -} -static int dsound_run_out (HWVoiceOut *hw,int live) {int err;
@@ -645,11 +640,6 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...)return 0 ; } -static int dsound_read (SWVoiceIn *sw,void *buf,int len) -{ -return audio_pcm_sw_read (sw, buf, len); -} -static int dsound_run_in (HWVoiceIn *hw) {int err;
@@ -856,13 +846,11 @@ static struct audio_pcm_ops dsound_pcm_ops = { .init_out = dsound_init_out, .fini_out = dsound_fini_out, .run_out = dsound_run_out, - .write = dsound_write, .ctl_out = dsound_ctl_out, .init_in = dsound_init_in, .fini_in = dsound_fini_in, .run_in = dsound_run_in, - .read = dsound_read, .ctl_in = dsound_ctl_in };
audio/noaudio.c +0 -19
@@ -60,11 +60,6 @@ static int no_run_out (HWVoiceOut *hw, int live)return decr; } -static int no_write (SWVoiceOut *sw,void *buf,int len) -{ -return audio_pcm_sw_write (sw, buf, len); -} -static int no_init_out (HWVoiceOut *hw,struct audsettings *as,void *drv_opaque) {audio_pcm_init_info (&hw->info, as);
@@ -117,18 +112,6 @@ static int no_run_in (HWVoiceIn *hw)return samples; } -static int no_read (SWVoiceIn *sw,void *buf,int size) -{ -/* use custom code here instead of audio_pcm_sw_read() to avoid -* useless resampling/mixing */ -int samples = size >> sw->info.shift; -int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired; -int to_clear =MIN (samples, total); - sw->total_hw_samples_acquired += total; -audio_pcm_info_clear_buf (&sw->info, buf, to_clear); -return to_clear << sw->info.shift; -} -static int no_ctl_in (HWVoiceIn *hw,int cmd, ...) { (void ) hw;
@@ -150,13 +133,11 @@ static struct audio_pcm_ops no_pcm_ops = { .init_out = no_init_out, .fini_out = no_fini_out, .run_out = no_run_out, - .write = no_write, .ctl_out = no_ctl_out, .init_in = no_init_in, .fini_in = no_fini_in, .run_in = no_run_in, - .read = no_read, .ctl_in = no_ctl_in };
audio/ossaudio.c +0 -12
@@ -133,11 +133,6 @@ static void oss_poll_in (HWVoiceIn *hw)qemu_set_fd_handler (oss->fd, oss_helper_poll_in,NULL , hw->s); } -static int oss_write (SWVoiceOut *sw,void *buf,int len) -{ -return audio_pcm_sw_write (sw, buf, len); -} -static int aud_to_ossfmt (AudioFormat fmt,int endianness) {switch (fmt) {
@@ -787,11 +782,6 @@ static int oss_run_in (HWVoiceIn *hw)return read_samples; } -static int oss_read (SWVoiceIn *sw,void *buf,int size) -{ -return audio_pcm_sw_read (sw, buf, size); -} -static int oss_ctl_in (HWVoiceIn *hw,int cmd, ...) {OSSVoiceIn *oss = (OSSVoiceIn *) hw;
@@ -860,13 +850,11 @@ static struct audio_pcm_ops oss_pcm_ops = { .init_out = oss_init_out, .fini_out = oss_fini_out, .run_out = oss_run_out, - .write = oss_write, .ctl_out = oss_ctl_out, .init_in = oss_init_in, .fini_in = oss_fini_in, .run_in = oss_run_in, - .read = oss_read, .ctl_in = oss_ctl_in };
audio/paaudio.c +0 -12
@@ -294,11 +294,6 @@ static int qpa_run_out (HWVoiceOut *hw, int live)return decr; } -static int qpa_write (SWVoiceOut *sw,void *buf,int len) -{ -return audio_pcm_sw_write (sw, buf, len); -} -/* capture */ static void *qpa_thread_in (void *arg) {
@@ -387,11 +382,6 @@ static int qpa_run_in (HWVoiceIn *hw)return incr; } -static int qpa_read (SWVoiceIn *sw,void *buf,int len) -{ -return audio_pcm_sw_read (sw, buf, len); -} -static pa_sample_format_t audfmt_to_pa (AudioFormat afmt,int endianness) {int format;
@@ -988,13 +978,11 @@ static struct audio_pcm_ops qpa_pcm_ops = { .init_out = qpa_init_out, .fini_out = qpa_fini_out, .run_out = qpa_run_out, - .write = qpa_write, .ctl_out = qpa_ctl_out, .init_in = qpa_init_in, .fini_in = qpa_fini_in, .run_in = qpa_run_in, - .read = qpa_read, .ctl_in = qpa_ctl_in };
audio/sdlaudio.c +0 -6
@@ -325,11 +325,6 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)#endif } -static int sdl_write_out (SWVoiceOut *sw,void *buf,int len) -{ -return audio_pcm_sw_write (sw, buf, len); -} -static int sdl_run_out (HWVoiceOut *hw,int live) {int decr;
@@ -483,7 +478,6 @@ static struct audio_pcm_ops sdl_pcm_ops = { .init_out = sdl_init_out, .fini_out = sdl_fini_out, .run_out = sdl_run_out, - .write = sdl_write_out, .ctl_out = sdl_ctl_out, };
audio/spiceaudio.c +0 -12
@@ -192,11 +192,6 @@ static int line_out_run (HWVoiceOut *hw, int live)return decr; } -static int line_out_write (SWVoiceOut *sw,void *buf,int len) -{ -return audio_pcm_sw_write (sw, buf, len); -} -static int line_out_ctl (HWVoiceOut *hw,int cmd, ...) {SpiceVoiceOut *out =container_of (hw, SpiceVoiceOut, hw);
@@ -325,11 +320,6 @@ static int line_in_run (HWVoiceIn *hw)return num_samples; } -static int line_in_read (SWVoiceIn *sw,void *buf,int size) -{ -return audio_pcm_sw_read (sw, buf, size); -} -static int line_in_ctl (HWVoiceIn *hw,int cmd, ...) {SpiceVoiceIn *in =container_of (hw, SpiceVoiceIn, hw);
@@ -377,13 +367,11 @@ static struct audio_pcm_ops audio_callbacks = { .init_out = line_out_init, .fini_out = line_out_fini, .run_out = line_out_run, - .write = line_out_write, .ctl_out = line_out_ctl, .init_in = line_in_init, .fini_in = line_in_fini, .run_in = line_in_run, - .read = line_in_read, .ctl_in = line_in_ctl, };
audio/wavaudio.c +0 -6
@@ -82,11 +82,6 @@ static int wav_run_out (HWVoiceOut *hw, int live)return decr; } -static int wav_write_out (SWVoiceOut *sw,void *buf,int len) -{ -return audio_pcm_sw_write (sw, buf, len); -} -/* VICE code: Store number as little endian. */ static void le_store (uint8_t *buf,uint32_t val,int len) {
@@ -238,7 +233,6 @@ static struct audio_pcm_ops wav_pcm_ops = { .init_out = wav_init_out, .fini_out = wav_fini_out, .run_out = wav_run_out, - .write = wav_write_out, .ctl_out = wav_ctl_out, };
Signature · 1 line
2.20.1
PATCH v3 26/50 audio: api for mixeng code free backends
In reply to Kővágó, Zoltán--- audio/audio_int.h | 41 ++++++-- audio/audio_template.h | 1 + audio/audio.c | 211 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 245 insertions(+), 8 deletions(-)
audio/audio_int.h +35 -6
@@ -64,6 +64,8 @@ typedef struct HWVoiceOut {uint64_t ts_helper;struct st_sample *mix_buf; +void *buf_emul; +size_t pos_emul, pending_emul, size_emul;size_t samples; QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
@@ -86,6 +88,8 @@ typedef struct HWVoiceIn {uint64_t ts_helper;struct st_sample *conv_buf; +void *buf_emul; +size_t pos_emul, pending_emul, size_emul;size_t samples; QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
@@ -146,17 +150,42 @@ struct audio_driver { };struct audio_pcm_ops { -int (*init_out)(HWVoiceOut *hw,struct audsettings *as,void *drv_opaque); -void (*fini_out)(HWVoiceOut *hw); +int (*init_out)(HWVoiceOut *hw,audsettings *as,void *drv_opaque); +void (*fini_out)(HWVoiceOut *hw);size_t (*run_out)(HWVoiceOut *hw,size_t live); -int (*ctl_out) (HWVoiceOut *hw,int cmd, ...); +size_t (*write) (HWVoiceOut *hw,void *buf,size_t size); +/* +* get a buffer that after later can be passed to put_buffer_out; optional +* returns the buffer, and writes it's size to size (in bytes) +* this is unrelated to the above buffer_size_out function +*/ +void *(*get_buffer_out)(HWVoiceOut *hw,size_t *size); +/* +* put back the buffer returned by get_buffer_out; optional +* buf must be equal the pointer returned by get_buffer_out, +* size may be smaller +*/ +size_t (*put_buffer_out)(HWVoiceOut *hw,void *buf,size_t size); +int (*ctl_out) (HWVoiceOut *hw,int cmd, ...); -int (*init_in) (HWVoiceIn *hw,struct audsettings *as,void *drv_opaque); -void (*fini_in) (HWVoiceIn *hw); +int (*init_in) (HWVoiceIn *hw,audsettings *as,void *drv_opaque); +void (*fini_in) (HWVoiceIn *hw);size_t (*run_in)(HWVoiceIn *hw); -int (*ctl_in) (HWVoiceIn *hw,int cmd, ...); +size_t (*read) (HWVoiceIn *hw,void *buf,size_t size); +void *(*get_buffer_in)(HWVoiceIn *hw,size_t *size); +void (*put_buffer_in)(HWVoiceIn *hw,void *buf,size_t size); +int (*ctl_in) (HWVoiceIn *hw,int cmd, ...); }; +void *audio_generic_get_buffer_in (HWVoiceIn *hw,size_t *size); +void audio_generic_put_buffer_in (HWVoiceIn *hw,void *buf,size_t size); +void *audio_generic_get_buffer_out (HWVoiceOut *hw,size_t *size); +size_t audio_generic_put_buffer_out (HWVoiceOut *hw,void *buf,size_t size); +size_t audio_generic_put_buffer_out_nowrite (HWVoiceOut *hw,void *buf, +size_t size); +size_t audio_generic_write (HWVoiceOut *hw,void *buf,size_t size); +size_t audio_generic_read (HWVoiceIn *hw,void *buf,size_t size); +struct capture_callback {struct audio_capture_ops ops;void *opaque;
audio/audio_template.h +1 -0
@@ -71,6 +71,7 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioState *s,static void glue (audio_pcm_hw_free_resources_ ,TYPE ) (HW *hw) { +g_free (hw->buf_emul);g_free (HWBUF );HWBUF =NULL ; }
audio/audio.c +209 -2
253 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 41/50 audio: add mixeng option (documentation)
In reply to Kővágó, ZoltánThis will allow us to disable mixeng when we use a decent backend.
Disabling mixeng have a few advantages:
* we no longer convert the audio output from one format to another, when the underlying audio system would just convert it to a third format. We no longer convert, only the underlying system, when needed.
* the underlying system probably has better resampling and sample format converting methods anyway...
* we may support formats that the mixeng currently does not support (S24 or float samples, more than two channels)
* when using an audio server (like pulseaudio) different sound card outputs will show up as separate streams, even if we use only one backend
Disadvantages:
* audio capturing no longer works (wavcapture, and vnc audio extension)
* some backends only support a single playback stream or very picky about the audio format. In this case we can't disable mixeng.
However mixeng is not removed, only made optional, so this shouldn't be a big concern.
---
Notes:
Changes from v2:
* removed #optional
qapi/audio.json | 5 +++++ qemu-options.hx | 6 ++++++ 2 files changed, 11 insertions(+)
qapi/audio.json +5 -0
@@ -172,6 +172,10 @@ # # General audio backend options that are used for both playback and recording. # +# @mixeng: use QEMU's mixing engine to mix all streams inside QEMU. When set to +# off, fixed-settings must be also off. Not every backend compatible +# with the off setting (default on) +# # @fixed-settings: use fixed settings for host input/output. When off, # frequency, channels and format must not be specified # (default on)
@@ -192,6 +196,7 @@ ## { 'struct': 'AudiodevPerDirectionOptions', 'data': { + '*mixeng': 'bool', '*fixed-settings': 'bool', '*frequency': 'uint32', '*channels': 'uint32',
qemu-options.hx +6 -0
@@ -432,6 +432,7 @@ DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev, " specifies the audio backend to use\n" " id= identifier of the backend\n" " timer-period= timer period in microseconds\n" + " in|out.mixeng= use mixeng to mix streams inside QEMU\n" " in|out.fixed-settings= use fixed settings for host audio\n" " in|out.frequency= frequency to use with fixed settings\n" " in|out.channels= number of channels to use with fixed settings\n"
@@ -500,6 +501,11 @@ Identifies the audio backend. Sets the timer @var{period} used by the audio subsystem in microseconds. Default is 10000 (10 ms). +@item in|out.mixeng=on|off +Use QEMU's mixing engine to mix all streams inside QEMU. When off, +@var{fixed-settings} must be off too. Not every backend is fully +compatible with the off setting. Default is on. + @item in|out.fixed-settings=on|off Use fixed settings for host audio. When off, it will change based on how the guest opens the sound card. In this case you must not specify
Signature · 1 line
2.20.1
PATCH v3 42/50 audio: make mixeng optional
In reply to Kővágó, ZoltánImplementation of the previously added mixeng option.
--- audio/audio_template.h | 46 ++++++++++++++++----------- audio/audio.c | 70 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 92 insertions(+), 24 deletions(-)
audio/audio_template.h +28 -18
@@ -78,26 +78,32 @@ static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)static void glue (audio_pcm_hw_alloc_resources_ ,TYPE )(HW *hw) { -size_t samples; -if (!hw->pcm_ops) { -/* -* We should only end up here when using wavcapture hmp command (and not -* the wavcapture audio backend). -* It needs a lot of samples, otherwise you'll end up with "Could not -* mix X bytes into a capture buffer" warnings and a garbled capture. -*/ - samples =4096 *4 ; - }else if (hw->pcm_ops->glue (buffer_size_,TYPE )) { - samples = hw->pcm_ops->glue (buffer_size_,TYPE )(hw); +if (hw->s->dev->TYPE->mixeng) { +size_t samples; +if (!hw->pcm_ops) { +/* +* We should only end up here when using wavcapture hmp command (and +* not the wavcapture audio backend). +* It needs a lot of samples, otherwise you'll end up with "Could +* not mix X bytes into a capture buffer" warnings and a garbled +* capture. +*/ + samples =4096 *4 ; + }else if (hw->pcm_ops->glue (buffer_size_,TYPE )) { + samples = hw->pcm_ops->glue (buffer_size_,TYPE )(hw); + }else { + samples =1024 ;/* todo better default */ + } + +if (audio_bug (__func__, samples ==0 )) { +dolog ("Attempted to allocate empty buffer\n" ); + } + +HWBUF =g_malloc0 (sizeof (STSampleBuffer) +sizeof (st_sample) * samples); +HWBUF ->size = samples; }else { - samples =1024 ;/* todo better default */ +HWBUF =NULL ; } -if (audio_bug (__func__, samples ==0 )) { -dolog ("Attempted to allocate empty buffer\n" ); - } - -HWBUF =g_malloc0 (sizeof (STSampleBuffer) +sizeof (st_sample) * samples); -HWBUF ->size = samples; }static void glue (audio_pcm_sw_free_resources_ ,TYPE ) (SW *sw)
@@ -116,6 +122,10 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw) {int samples; +if (!sw->s->dev->TYPE->mixeng) { +return 0 ; + } + samples = ((int64_t ) sw->HWBUF->size <<32 ) / sw->ratio; sw->buf =audio_calloc (__func__, samples,sizeof (struct st_sample ));
audio/audio.c +64 -6
136 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 44/50 audio: support more than two channels in volume setting
In reply to Kővágó, Zoltán--- audio/audio.h | 10 ++++++++++ audio/audio_int.h | 4 ++-- audio/audio.c | 28 ++++++++++++++++++++-------- audio/paaudio.c | 20 ++++++++++++-------- audio/spiceaudio.c | 14 ++++++++------ 5 files changed, 52 insertions(+), 24 deletions(-)
audio/audio.h +10 -0
@@ -123,6 +123,16 @@ uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);void AUD_set_volume_out (SWVoiceOut *sw,int mute,uint8_t lvol,uint8_t rvol);void AUD_set_volume_in (SWVoiceIn *sw,int mute,uint8_t lvol,uint8_t rvol); +#define AUDIO_MAX_CHANNELS 16 +typedef struct Volume { +bool mute; +int channels; +uint8_t vol[AUDIO_MAX_CHANNELS ]; +}Volume ; + +void audio_set_volume_out (SWVoiceOut *sw,Volume *vol); +void audio_set_volume_in (SWVoiceIn *sw,Volume *vol); + SWVoiceIn *AUD_open_in ( QEMUSoundCard *card, SWVoiceIn *sw,
audio/audio_int.h +2 -2
@@ -165,7 +165,7 @@ struct audio_pcm_ops {*/ size_t (*put_buffer_out)(HWVoiceOut *hw,void *buf,size_t size);void (*enable_out)(HWVoiceOut *hw,bool enable); -void (*volume_out)(HWVoiceOut *hw,struct mixeng_volume *vol); +void (*volume_out)(HWVoiceOut *hw,Volume *vol);int (*init_in) (HWVoiceIn *hw,audsettings *as,void *drv_opaque);void (*fini_in) (HWVoiceIn *hw);
@@ -174,7 +174,7 @@ struct audio_pcm_ops {void *(*get_buffer_in)(HWVoiceIn *hw,size_t *size);void (*put_buffer_in)(HWVoiceIn *hw,void *buf,size_t size);void (*enable_in)(HWVoiceIn *hw,bool enable); -void (*volume_in)(HWVoiceIn *hw,struct mixeng_volume *vol); +void (*volume_in)(HWVoiceIn *hw,Volume *vol); };void *audio_generic_get_buffer_in (HWVoiceIn *hw,size_t *size);
audio/audio.c +20 -8
@@ -1901,31 +1901,43 @@ void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque) }void AUD_set_volume_out (SWVoiceOut *sw,int mute,uint8_t lvol,uint8_t rvol) +{ +Volume vol = { .mute = mute, .channels =2 , .vol = { lvol, rvol } }; +audio_set_volume_out (sw, &vol); +} + +void audio_set_volume_out (SWVoiceOut *sw,Volume *vol) {if (sw) {HWVoiceOut *hw = sw->hw; - sw->vol.mute = mute; - sw->vol.l = nominal_volume.l * lvol /255 ; - sw->vol.r = nominal_volume.r * rvol /255 ; + sw->vol.mute = vol->mute; + sw->vol.l = nominal_volume.l * vol->vol[0 ] /255 ; + sw->vol.r = nominal_volume.l * vol->vol[vol->channels >1 ?1 :0 ] /255 ;if (hw->pcm_ops->volume_out) { - hw->pcm_ops->volume_out (hw, &sw->vol); + hw->pcm_ops->volume_out (hw, vol); } } }void AUD_set_volume_in (SWVoiceIn *sw,int mute,uint8_t lvol,uint8_t rvol) +{ +Volume vol = { .mute = mute, .channels =2 , .vol = { lvol, rvol } }; +audio_set_volume_in (sw, &vol); +} + +void audio_set_volume_in (SWVoiceIn *sw,Volume *vol) {if (sw) {HWVoiceIn *hw = sw->hw; - sw->vol.mute = mute; - sw->vol.l = nominal_volume.l * lvol /255 ; - sw->vol.r = nominal_volume.r * rvol /255 ; + sw->vol.mute = vol->mute; + sw->vol.l = nominal_volume.l * vol->vol[0 ] /255 ; + sw->vol.r = nominal_volume.r * vol->vol[vol->channels >1 ?1 :0 ] /255 ;if (hw->pcm_ops->volume_in) { - hw->pcm_ops->volume_in (hw, &sw->vol); + hw->pcm_ops->volume_in (hw, vol); } } }
audio/paaudio.c +12 -8
@@ -537,20 +537,22 @@ static void qpa_fini_in (HWVoiceIn *hw) } } -static void qpa_volume_out (HWVoiceOut *hw,struct mixeng_volume *vol) +static void qpa_volume_out (HWVoiceOut *hw,Volume *vol) {PAVoiceOut *pa = (PAVoiceOut *) hw;pa_operation *op;pa_cvolume v;PAConnection *c = pa->g->conn; +int i;#ifdef PA_CHECK_VERSION /* macro is present in 0.9.16+ */ pa_cvolume_init (&v);/* function is present in 0.9.13+ */ #endif - v.channels =2 ; - v.values[0 ] = ((PA_VOLUME_NORM -PA_VOLUME_MUTED ) * vol->l) /UINT32_MAX ; - v.values[1 ] = ((PA_VOLUME_NORM -PA_VOLUME_MUTED ) * vol->r) /UINT32_MAX ; + v.channels = vol->channels; +for (i =0 ; i < vol->channels; ++i) { + v.values[i] = ((PA_VOLUME_NORM -PA_VOLUME_MUTED ) * vol->vol[i]) /255 ; + }pa_threaded_mainloop_lock (c->mainloop);
@@ -577,20 +579,22 @@ static void qpa_volume_out(HWVoiceOut *hw, struct mixeng_volume *vol)pa_threaded_mainloop_unlock (c->mainloop); } -static void qpa_volume_in (HWVoiceIn *hw,struct mixeng_volume *vol) +static void qpa_volume_in (HWVoiceIn *hw,Volume *vol) {PAVoiceIn *pa = (PAVoiceIn *) hw;pa_operation *op;pa_cvolume v;PAConnection *c = pa->g->conn; +int i;#ifdef PA_CHECK_VERSION pa_cvolume_init (&v);#endif - v.channels =2 ; - v.values[0 ] = ((PA_VOLUME_NORM -PA_VOLUME_MUTED ) * vol->l) /UINT32_MAX ; - v.values[1 ] = ((PA_VOLUME_NORM -PA_VOLUME_MUTED ) * vol->r) /UINT32_MAX ; + v.channels = vol->channels; +for (i =0 ; i < vol->channels; ++i) { + v.values[i] = ((PA_VOLUME_NORM -PA_VOLUME_MUTED ) * vol->vol[i]) /255 ; + }pa_threaded_mainloop_lock (c->mainloop);
audio/spiceaudio.c +8 -6
@@ -179,13 +179,14 @@ static void line_out_enable(HWVoiceOut *hw, bool enable) }#if ((SPICE_INTERFACE_PLAYBACK_MAJOR >=1 ) && (SPICE_INTERFACE_PLAYBACK_MINOR >=2 )) -static void line_out_volume (HWVoiceOut *hw,struct mixeng_volume *vol) +static void line_out_volume (HWVoiceOut *hw,Volume *vol) {SpiceVoiceOut *out =container_of (hw, SpiceVoiceOut, hw);uint16_t svol[2 ]; - svol[0 ] = vol->l / ((1ULL <<16 ) +1 ); - svol[1 ] = vol->r / ((1ULL <<16 ) +1 ); +assert (vol->channels ==2 ); + svol[0 ] = vol->vol[0 ] *257 ; + svol[1 ] = vol->vol[1 ] *257 ;spice_server_playback_set_volume (&out->sin,2 , svol);spice_server_playback_set_mute (&out->sin, vol->mute); }
@@ -266,13 +267,14 @@ static void line_in_enable(HWVoiceIn *hw, bool enable) }#if ((SPICE_INTERFACE_RECORD_MAJOR >=2 ) && (SPICE_INTERFACE_RECORD_MINOR >=2 )) -static void line_in_volume (HWVoiceIn *hw,struct mixeng_volume *vol) +static void line_in_volume (HWVoiceIn *hw,Volume *vol) {SpiceVoiceIn *in =container_of (hw, SpiceVoiceIn, hw);uint16_t svol[2 ]; - svol[0 ] = vol->l / ((1ULL <<16 ) +1 ); - svol[1 ] = vol->r / ((1ULL <<16 ) +1 ); +assert (vol->channels ==2 ); + svol[0 ] = vol->vol[0 ] *257 ; + svol[1 ] = vol->vol[1 ] *257 ;spice_server_record_set_volume (&in->sin,2 , svol);spice_server_record_set_mute (&in->sin, vol->mute); }
Signature · 1 line
2.20.1
PATCH v3 46/50 audio: basic support for multichannel audio
In reply to Kővágó, ZoltánWhich currently only means removing some checks. Old code won't require more than two channels, but new code will need it.
--- audio/alsaaudio.c | 7 ------- audio/audio.c | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-)
audio/alsaaudio.c +0 -7
@@ -497,13 +497,6 @@ static int alsa_open(bool in, struct alsa_params_req *req, goto err; } -if (nchannels !=1 && nchannels !=2 ) { -alsa_logerr2 (err, typ, -"Can not handle obtained number of channels %d\n" , - nchannels); - goto err; - } -if (pdo->buffer_count) {if (pdo->buffer_len) {int64_t req = pdo->buffer_len * pdo->buffer_count;
audio/audio.c +1 -1
@@ -240,7 +240,7 @@ static int audio_validate_settings (struct audsettings *as) {int invalid; - invalid = as->nchannels !=1 && as->nchannels !=2 ; + invalid = as->nchannels <1 ; invalid |= as->endianness !=0 && as->endianness !=1 ;switch (as->fmt) {
Signature · 1 line
2.20.1
PATCH v3 48/50 usb-audio: do not count on avail bytes actually available
In reply to Kővágó, ZoltánThis assumption is no longer true when mixeng is turned off.
--- hw/usb/dev-audio.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
hw/usb/dev-audio.c +18 -12
@@ -318,30 +318,31 @@ static int streambuf_put(struct streambuf *buf, USBPacket *p) {uint32_t free = buf->size - (buf->prod - buf->cons); -if (!free) { +if (free <USBAUDIO_PACKET_SIZE ) {return 0 ; }if (p->iov.size !=USBAUDIO_PACKET_SIZE ) {return 0 ; } -assert (free >=USBAUDIO_PACKET_SIZE ); +usb_packet_copy (p, buf->data + (buf->prod % buf->size),USBAUDIO_PACKET_SIZE ); buf->prod +=USBAUDIO_PACKET_SIZE ;return USBAUDIO_PACKET_SIZE ; } -static uint8_t *streambuf_get (struct streambuf *buf) +static uint8_t *streambuf_get (struct streambuf *buf,size_t *len) {uint32_t used = buf->prod - buf->cons;uint8_t *data;if (!used) { + *len =0 ;return NULL ; } -assert (used >=USBAUDIO_PACKET_SIZE ); data = buf->data + (buf->cons % buf->size); - buf->cons +=USBAUDIO_PACKET_SIZE ; + *len =MIN (buf->prod - buf->cons, + buf->size - (buf->cons % buf->size));return data; }
@@ -373,16 +374,21 @@ static void output_callback(void *opaque, int avail)USBAudioState *s = opaque;uint8_t *data; -for (;;) { -if (avail <USBAUDIO_PACKET_SIZE ) { -return ; - } - data =streambuf_get (&s->out.buf); +while (avail) { +size_t written, len; + + data =streambuf_get (&s->out.buf, &len);if (!data) {return ; } -AUD_write (s->out.voice, data,USBAUDIO_PACKET_SIZE ); - avail -=USBAUDIO_PACKET_SIZE ; + + written =AUD_write (s->out.voice, data, len); + avail -= written; + s->out.buf.cons += written; + +if (written < len) { +return ; + } } }
Signature · 1 line
2.20.1
PATCH v3 27/50 alsaaudio: port to the new audio backend api
In reply to Kővágó, Zoltán--- audio/alsaaudio.c | 306 ++++++++++++---------------------------------- 1 file changed, 81 insertions(+), 225 deletions(-)
audio/alsaaudio.c +81 -225
@@ -43,9 +43,6 @@ struct pollhlp { typedef struct ALSAVoiceOut { HWVoiceOut hw; - int wpos; - int pending; - void *pcm_buf; snd_pcm_t *handle; struct pollhlp pollhlp; Audiodev *dev;
@@ -54,7 +51,6 @@ typedef struct ALSAVoiceOut {typedef struct ALSAVoiceIn {HWVoiceIn hw;snd_pcm_t *handle; -void *pcm_buf;struct pollhlp pollhlp;Audiodev *dev; }ALSAVoiceIn ;
@@ -609,102 +605,62 @@ static int alsa_open(bool in, struct alsa_params_req *req,return -1 ; } -static snd_pcm_sframes_t alsa_get_avail (snd_pcm_t *handle) -{ -snd_pcm_sframes_t avail; - - avail =snd_pcm_avail_update (handle); -if (avail <0 ) { -if (avail == -EPIPE ) { -if (!alsa_recover (handle)) { - avail =snd_pcm_avail_update (handle); - } - } - -if (avail <0 ) { -alsa_logerr (avail, -"Could not obtain number of available frames\n" ); -return -1 ; - } - } - -return avail; -} - -static void alsa_write_pending (ALSAVoiceOut *alsa) -{ -HWVoiceOut *hw = &alsa->hw; - -while (alsa->pending) { -int left_till_end_samples = hw->samples - alsa->wpos; -int len =MIN (alsa->pending, left_till_end_samples); -char *src =advance (alsa->pcm_buf, alsa->wpos << hw->info.shift); - -while (len) { -snd_pcm_sframes_t written; - - written =snd_pcm_writei (alsa->handle, src, len); - -if (written <=0 ) { -switch (written) { -case 0 : -trace_alsa_wrote_zero (len); -return ; - -case -EPIPE : -if (alsa_recover (alsa->handle)) { -alsa_logerr (written,"Failed to write %d frames\n" , - len); -return ; - } -trace_alsa_xrun_out (); -continue ; - -case -ESTRPIPE : -/* stream is suspended and waiting for an -application recovery */ -if (alsa_resume (alsa->handle)) { -alsa_logerr (written,"Failed to write %d frames\n" , - len); -return ; - } -trace_alsa_resume_out (); -continue ; - -case -EAGAIN : -return ; - -default : -alsa_logerr (written,"Failed to write %d frames from %p\n" , - len, src); -return ; - } - } - - alsa->wpos = (alsa->wpos + written) % hw->samples; - alsa->pending -= written; - len -= written; - } - } -} - -static size_t alsa_run_out (HWVoiceOut *hw,size_t live) +static size_t alsa_write (HWVoiceOut *hw,void *buf,size_t len) {ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw; -size_t decr; -snd_pcm_sframes_t avail; +size_t pos =0 ; +size_t len_frames = len >> hw->info.shift; - avail =alsa_get_avail (alsa->handle); -if (avail <0 ) { -dolog ("Could not get number of available playback frames\n" ); -return 0 ; +while (len_frames) { +char *src =advance (buf, pos); +snd_pcm_sframes_t written; + + written =snd_pcm_writei (alsa->handle, src, len_frames); + +if (written <=0 ) { +switch (written) { +case 0 : +trace_alsa_wrote_zero (len_frames); +return pos; + +case -EPIPE : +if (alsa_recover (alsa->handle)) { +alsa_logerr (written,"Failed to write %zu frames\n" , + len_frames); +return pos; + } +trace_alsa_xrun_out (); +continue ; + +case -ESTRPIPE : +/* stream is suspended and waiting for an +application recovery */ +if (alsa_resume (alsa->handle)) { +alsa_logerr (written,"Failed to write %zu frames\n" , + len_frames); +return pos; + } +trace_alsa_resume_out (); +continue ; + +case -EAGAIN : +return pos; + +default : +alsa_logerr (written,"Failed to write %zu frames from %p\n" , + len, src); +return pos; + } + } + + pos += written << hw->info.shift; +if (written < len_frames) { +break ; + } + len_frames -= written; } - decr =MIN (live, avail); - decr =audio_pcm_hw_clip_out (hw, alsa->pcm_buf, decr, alsa->pending); - alsa->pending += decr; -alsa_write_pending (alsa); -return decr; +return pos; }static void alsa_fini_out (HWVoiceOut *hw)
@@ -713,9 +669,6 @@ static void alsa_fini_out (HWVoiceOut *hw)ldebug ("alsa_fini\n" );alsa_anal_close (&alsa->handle, &alsa->pollhlp); - -g_free (alsa->pcm_buf); - alsa->pcm_buf =NULL ; } static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,
@@ -744,14 +697,6 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,audio_pcm_init_info (&hw->info, &obt_as); hw->samples = obt.samples; - alsa->pcm_buf =audio_calloc (__func__, obt.samples,1 << hw->info.shift); -if (!alsa->pcm_buf) { -dolog ("Could not allocate DAC buffer (%zu samples, each %d bytes)\n" , - hw->samples,1 << hw->info.shift); -alsa_anal_close1 (&handle); -return -1 ; - } - alsa->pollhlp.s = hw->s; alsa->handle = handle; alsa->dev = dev;
@@ -846,14 +791,6 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)audio_pcm_init_info (&hw->info, &obt_as); hw->samples = obt.samples; - alsa->pcm_buf =audio_calloc (__func__, hw->samples,1 << hw->info.shift); -if (!alsa->pcm_buf) { -dolog ("Could not allocate ADC buffer (%zu samples, each %d bytes)\n" , - hw->samples,1 << hw->info.shift); -alsa_anal_close1 (&handle); -return -1 ; - } - alsa->pollhlp.s = hw->s; alsa->handle = handle; alsa->dev = dev;
@@ -865,129 +802,48 @@ static void alsa_fini_in (HWVoiceIn *hw)ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;alsa_anal_close (&alsa->handle, &alsa->pollhlp); - -g_free (alsa->pcm_buf); - alsa->pcm_buf =NULL ; } -static size_t alsa_run_in (HWVoiceIn *hw) +static size_t alsa_read (HWVoiceIn *hw,void *buf,size_t len) {ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw; -int hwshift = hw->info.shift; -int i; -size_t live =audio_pcm_hw_get_live_in (hw); -size_t dead = hw->samples - live; -size_t decr; -struct { -size_t add; -size_t len; - } bufs[2 ] = { - { .add = hw->wpos, .len =0 }, - { .add =0 , .len =0 } - }; -snd_pcm_sframes_t avail; -snd_pcm_uframes_t read_samples =0 ; +size_t pos =0 ; -if (!dead) { -return 0 ; - } - - avail =alsa_get_avail (alsa->handle); -if (avail <0 ) { -dolog ("Could not get number of captured frames\n" ); -return 0 ; - } - -if (!avail) { -snd_pcm_state_t state; - - state =snd_pcm_state (alsa->handle); -switch (state) { -case SND_PCM_STATE_PREPARED : - avail = hw->samples; -break ; -case SND_PCM_STATE_SUSPENDED : -/* stream is suspended and waiting for an application recovery */ -if (alsa_resume (alsa->handle)) { -dolog ("Failed to resume suspended input stream\n" ); -return 0 ; - } -trace_alsa_resume_in (); -break ; -default : -trace_alsa_no_frames (state); -return 0 ; - } - } - - decr =MIN (dead, avail); -if (!decr) { -return 0 ; - } - -if (hw->wpos + decr > hw->samples) { - bufs[0 ].len = (hw->samples - hw->wpos); - bufs[1 ].len = (decr - (hw->samples - hw->wpos)); - } -else { - bufs[0 ].len = decr; - } - -for (i =0 ; i <2 ; ++i) { -void *src; -struct st_sample *dst; +while (len) { +void *dst =advance (buf, pos);snd_pcm_sframes_t nread; -snd_pcm_uframes_t len; - len = bufs[i].len; + nread =snd_pcm_readi (alsa->handle, dst, len >> hw->info.shift); - src =advance (alsa->pcm_buf, bufs[i].add << hwshift); - dst = hw->conv_buf + bufs[i].add; +if (nread <=0 ) { +switch (nread) { +case 0 : +trace_alsa_read_zero (len); +return pos;; -while (len) { - nread =snd_pcm_readi (alsa->handle, src, len); - -if (nread <=0 ) { -switch (nread) { -case 0 : -trace_alsa_read_zero (len); - goto exit; - -case -EPIPE : -if (alsa_recover (alsa->handle)) { -alsa_logerr (nread,"Failed to read %ld frames\n" , len); - goto exit; - } -trace_alsa_xrun_in (); -continue ; - -case -EAGAIN : - goto exit; - -default : -alsa_logerr ( - nread, -"Failed to read %ld frames from %p\n" , - len, - src - ); - goto exit; +case -EPIPE : +if (alsa_recover (alsa->handle)) { +alsa_logerr (nread,"Failed to read %zu frames\n" , len); +return pos; } +trace_alsa_xrun_in (); +continue ; + +case -EAGAIN : +return pos; + +default : +alsa_logerr (nread,"Failed to read %zu frames to %p\n" , + len, dst); +return pos;; } - - hw->conv (dst, src, nread); - - src =advance (src, nread << hwshift); - dst += nread; - - read_samples += nread; - len -= nread; } + + pos += nread << hw->info.shift; + len -= nread << hw->info.shift; } - exit: - hw->wpos = (hw->wpos + read_samples) % hw->samples; -return read_samples; +return pos; }static int alsa_ctl_in (HWVoiceIn *hw,int cmd, ...)
@@ -1077,12 +933,12 @@ static void alsa_audio_fini (void *opaque)static struct audio_pcm_ops alsa_pcm_ops = { .init_out = alsa_init_out, .fini_out = alsa_fini_out, - .run_out = alsa_run_out, + .write = alsa_write, .ctl_out = alsa_ctl_out, .init_in = alsa_init_in, .fini_in = alsa_fini_in, - .run_in = alsa_run_in, + .read = alsa_read, .ctl_in = alsa_ctl_in, };
Signature · 1 line
2.20.1
PATCH v3 47/50 paaudio: channel-map option
In reply to Kővágó, ZoltánAdd an option to change the channel map used by pulseaudio. If not specified, falls back to an OSS compatible channel map.
--- qapi/audio.json | 5 ++++- audio/paaudio.c | 18 ++++++++++++++---- qemu-options.hx | 9 +++++++++ 3 files changed, 27 insertions(+), 5 deletions(-)
qapi/audio.json +4 -1
@@ -107,11 +107,14 @@ # # @name: name of the sink/source to use # +# @channel-map: channel map to use (default: OSS compatible map) +# # Since: 4.0 ## { 'struct': 'AudiodevPaPerDirectionOptions', 'data': { - '*name': 'str' } } + '*name': 'str', + '*channel-map': 'str' } } ## # @AudiodevPaOptions:
audio/paaudio.c +14 -4
@@ -337,17 +337,27 @@ static pa_stream *qpa_simple_new (pa_stream_direction_t dir, const char *dev, const pa_sample_spec *ss, - const pa_channel_map *map, + const char *map, const pa_buffer_attr *attr, int *rerror) { int r;pa_stream *stream;pa_stream_flags_t flags; +pa_channel_map pa_map;pa_threaded_mainloop_lock (c->mainloop); - stream =pa_stream_new (c->context, name, ss, map); +if (map && !pa_channel_map_parse (&pa_map, map)) { +dolog ("Invalid channel map specified: '%s'\n" , map); + map =NULL ; + } +if (!map) { +pa_channel_map_init_extend (&pa_map, ss->channels, +PA_CHANNEL_MAP_OSS ); + } + + stream =pa_stream_new (c->context, name, ss, &pa_map);if (!stream) { goto fail; }
@@ -424,7 +434,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,PA_STREAM_PLAYBACK , ppdo->has_name ? ppdo->name :NULL , &ss, -NULL ,/* channel map */ + ppdo->has_channel_map ? ppdo->channel_map :NULL , &ba,/* buffering attributes */ &error );
@@ -472,7 +482,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)PA_STREAM_RECORD , ppdo->has_name ? ppdo->name :NULL , &ss, -NULL ,/* channel map */ + ppdo->has_channel_map ? ppdo->channel_map :NULL ,NULL ,/* buffering attributes */ &error );
qemu-options.hx +9 -0
@@ -468,6 +468,7 @@ DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev, "-audiodev pa,id=id[,prop[=value][,...]]\n" " server= PulseAudio server address\n" " sink|source.name= sink/source device name\n" + " sink|source.channel-map= channel map to use\n" #endif #ifdef CONFIG_SDL "-audiodev sdl,id=id[,prop[=value][,...]]\n"
@@ -621,6 +622,14 @@ Sets the PulseAudio @var{server} to connect to. @item sink|source.name=@var{sink} Use the specified sink/source for playback/recording. +@item sink|source.channel-map=@var{map} +Use the specified channel map. The default is an OSS compatible +channel map. Do not forget to escape commas inside the map: + +@example +-audiodev pa,id=example,sink.channel-map=front-left,,front-right +@end example + @end table @item -audiodev sdl,id=@var{id}[,@var{prop}[=@var{value}][,...]]
Signature · 1 line
2.20.1
PATCH v3 50/50 usbaudio: change playback counters to 64 bit
In reply to Kővágó, ZoltánWith stereo playback, they need about 375 minutes of continuous audio playback to overflow, which is usually not a problem (as stopping and later resuming playback resets the counters). But with 7.1 audio, they only need about 95 minutes to overflow.
After the overflow, the buf->prod % USBAUDIO_PACKET_SIZE(channels) assertion no longer holds true, which will result in overflowing the buffer. With 64 bit variables, it would take about 762000 years to overflow.
--- hw/usb/dev-audio.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
hw/usb/dev-audio.c +8 -6
@@ -577,9 +577,9 @@ static const USBDesc desc_audio_multi = {struct streambuf {uint8_t *data; -uint32_t size; -uint32_t prod; -uint32_t cons; +size_t size; +uint64_t prod; +uint64_t cons; }; static void streambuf_init(struct streambuf *buf, uint32_t size,
@@ -600,7 +600,7 @@ static void streambuf_fini(struct streambuf *buf)static int streambuf_put (struct streambuf *buf,USBPacket *p,uint32_t channels) { -uint32_t free = buf->size - (buf->prod - buf->cons); +int64_t free = buf->size - (buf->prod - buf->cons);if (free <USBAUDIO_PACKET_SIZE (channels)) {return 0 ;
@@ -609,6 +609,8 @@ static int streambuf_put(struct streambuf *buf, USBPacket *p, uint32_t channels)return 0 ; } +/* can happen if prod overflows */ +assert (buf->prod %USBAUDIO_PACKET_SIZE (channels) ==0 );usb_packet_copy (p, buf->data + (buf->prod % buf->size),USBAUDIO_PACKET_SIZE (channels)); buf->prod +=USBAUDIO_PACKET_SIZE (channels);
@@ -617,10 +619,10 @@ static int streambuf_put(struct streambuf *buf, USBPacket *p, uint32_t channels)static uint8_t *streambuf_get (struct streambuf *buf,size_t *len) { -uint32_t used = buf->prod - buf->cons; +int64_t used = buf->prod - buf->cons;uint8_t *data; -if (!used) { +if (used <=0 ) { *len =0 ;return NULL ; }
Signature · 1 line
2.20.1
PATCH v3 29/50 dsoundaudio: port to the new audio backend api
In reply to Kővágó, Zoltán--- audio/dsound_template.h | 45 +++--- audio/dsoundaudio.c | 329 ++++++++++------------------------------ 2 files changed, 102 insertions(+), 272 deletions(-)
audio/dsound_template.h +23 -22
@@ -29,6 +29,8 @@#define BUFPTR LPDIRECTSOUNDCAPTUREBUFFER#define FIELD dsound_capture_buffer#define FIELD2 dsound_capture +#define HWVOICE HWVoiceIn +#define DSOUNDVOICE DSoundVoiceIn#else #define NAME "playback buffer"#define NAME2 "DirectSound"
@@ -37,6 +39,8 @@#define BUFPTR LPDIRECTSOUNDBUFFER#define FIELD dsound_buffer#define FIELD2 dsound +#define HWVOICE HWVoiceOut +#define DSOUNDVOICE DSoundVoiceOut#endif static int glue (dsound_unlock_, TYPE) (
@@ -72,8 +76,6 @@ static int glue (dsound_lock_, TYPE) ( ) {HRESULT hr; -LPVOID p1 =NULL , p2 =NULL ; -DWORD blen1 =0 , blen2 =0 ;DWORD flag;#ifdef DSBTYPE_IN
@@ -81,7 +83,7 @@ static int glue (dsound_lock_, TYPE) (#else flag = entire ?DSBLOCK_ENTIREBUFFER :0 ;#endif - hr =glue (IFACE , _Lock)(buf, pos, len, &p1, &blen1, &p2, &blen2, flag); + hr =glue (IFACE , _Lock)(buf, pos, len, p1p, blen1p, p2p, blen2p, flag);if (FAILED (hr)) {#ifndef DSBTYPE_IN
@@ -96,34 +98,34 @@ static int glue (dsound_lock_, TYPE) ( goto fail; } -if ((p1 && (blen1 & info->align)) || (p2 && (blen2 & info->align))) { +if ((p1p && *p1p && (*blen1p & info->align)) || + (p2p && *p2p && (*blen2p & info->align))) {dolog ("DirectSound returned misaligned buffer %ld %ld\n" , - blen1, blen2); -glue (dsound_unlock_,TYPE ) (buf, p1, p2, blen1, blen2); + *blen1p, *blen2p); +glue (dsound_unlock_,TYPE ) (buf, *p1p, p2p ? *p2p :NULL , *blen1p, + blen2p ? *blen2p :0 ); goto fail; } -if (!p1 && blen1) { -dolog ("warning: !p1 && blen1=%ld\n" , blen1); - blen1 =0 ; +if (p1p && !*p1p && *blen1p) { +dolog ("warning: !p1 && blen1=%ld\n" , *blen1p); + *blen1p =0 ; } -if (!p2 && blen2) { -dolog ("warning: !p2 && blen2=%ld\n" , blen2); - blen2 =0 ; +if (p2p && !*p2p && *blen2p) { +dolog ("warning: !p2 && blen2=%ld\n" , *blen2p); + *blen2p =0 ; } - *p1p = p1; - *p2p = p2; - *blen1p = blen1; - *blen2p = blen2;return 0 ; fail: *p1p =NULL -1 ; - *p2p =NULL -1 ; *blen1p =-1 ; - *blen2p =-1 ; +if (p2p) { + *p2p =NULL -1 ; + *blen2p =-1 ; + }return -1 ; }
@@ -242,7 +244,6 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as, goto fail0; } - ds->first_time =1 ; obt_as.endianness =0 ;audio_pcm_init_info (&hw->info, &obt_as);
@@ -252,15 +253,13 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as, bc.dwBufferBytes, hw->info.align +1 ); } + hw->size_emul = bc.dwBufferBytes; hw->samples = bc.dwBufferBytes >> hw->info.shift; ds->s = s;#ifdef DEBUG_DSOUND dolog ("caps %ld, desc %ld\n" , bc.dwBufferBytes, bd.dwBufferBytes); - -dolog ("bufsize %d, freq %d, chan %d, fmt %d\n" , - hw->bufsize, settings.freq, settings.nchannels, settings.fmt);#endif return 0 ;
@@ -276,3 +275,5 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,#undef BUFPTR#undef FIELD#undef FIELD2 +#undef HWVOICE +#undef DSOUNDVOICE
audio/dsoundaudio.c +79 -250
396 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 31/50 ossaudio: port to the new audio backend api
In reply to Kővágó, Zoltán--- audio/ossaudio.c | 288 +++++++++++++++++------------------------------ 1 file changed, 104 insertions(+), 184 deletions(-)
audio/ossaudio.c +104 -184
@@ -39,19 +39,15 @@typedef struct OSSVoiceOut {HWVoiceOut hw; -void *pcm_buf;int fd; -int wpos;int nfrags;int fragsize;int mmapped; -int pending;Audiodev *dev; }OSSVoiceOut ; typedef struct OSSVoiceIn { HWVoiceIn hw; - void *pcm_buf; int fd; int nfrags; int fragsize;
@@ -370,98 +366,87 @@ static int oss_open(int in, struct oss_params *req, audsettings *as,return -1 ; } -static void oss_write_pending (OSSVoiceOut *oss) +static size_t oss_get_available_bytes (OSSVoiceOut *oss) { -HWVoiceOut *hw = &oss->hw; +int err; +struct count_info cntinfo; +assert (oss->mmapped); + err =ioctl (oss->fd,SNDCTL_DSP_GETOPTR , &cntinfo); +if (err <0 ) { +oss_logerr (errno,"SNDCTL_DSP_GETOPTR failed\n" ); +return 0 ; + } + +return audio_ring_dist (cntinfo.ptr, oss->hw.pos_emul, oss->hw.size_emul); +} + +static void *oss_get_buffer_out (HWVoiceOut *hw,size_t *size) +{ +OSSVoiceOut *oss = (OSSVoiceOut *) hw; +if (oss->mmapped) { + *size =MIN (oss_get_available_bytes (oss), hw->size_emul - hw->pos_emul); +return hw->buf_emul + hw->pos_emul; + }else { +return audio_generic_get_buffer_out (hw, size); + } +} + +static size_t oss_put_buffer_out (HWVoiceOut *hw,void *buf,size_t size) +{ +OSSVoiceOut *oss = (OSSVoiceOut *) hw;if (oss->mmapped) { -return ; +assert (buf == hw->buf_emul + hw->pos_emul && size < hw->size_emul); + + hw->pos_emul = (hw->pos_emul + size) % hw->size_emul; +return size; + }else { +return audio_generic_put_buffer_out (hw, buf, size); + } +} + +static size_t oss_write (HWVoiceOut *hw,void *buf,size_t len) +{ +OSSVoiceOut *oss = (OSSVoiceOut *) hw; +size_t pos; + +if (oss->mmapped) { +size_t total_len; + len =MIN (len,oss_get_available_bytes (oss)); + + total_len = len; +while (len) { +size_t to_copy =MIN (len, hw->size_emul - hw->pos_emul); +memcpy (hw->buf_emul + hw->pos_emul, buf, to_copy); + + hw->pos_emul = (hw->pos_emul + to_copy) % hw->pos_emul; + buf += to_copy; + len -= to_copy; + } +return total_len; } -while (oss->pending) { -int samples_written; + pos =0 ; +while (len) {ssize_t bytes_written; -int samples_till_end = hw->samples - oss->wpos; -int samples_to_write =MIN (oss->pending, samples_till_end); -int bytes_to_write = samples_to_write << hw->info.shift; -void *pcm =advance (oss->pcm_buf, oss->wpos << hw->info.shift); +void *pcm =advance (buf, pos); - bytes_written =write (oss->fd, pcm, bytes_to_write); + bytes_written =write (oss->fd, pcm, len);if (bytes_written <0 ) {if (errno !=EAGAIN ) { -oss_logerr (errno,"failed to write %d bytes\n" , - bytes_to_write); +oss_logerr (errno,"failed to write %zu bytes\n" , + len); } -break ; - } - -if (bytes_written & hw->info.align) { -dolog ("misaligned write asked for %d, but got %zd\n" , - bytes_to_write, bytes_written); -return ; +return pos; } - samples_written = bytes_written >> hw->info.shift; - oss->pending -= samples_written; - oss->wpos = (oss->wpos + samples_written) % hw->samples; -if (bytes_written - bytes_to_write) { + pos += bytes_written; +if (bytes_written < len) {break ; } + len -= bytes_written; } -} - -static size_t oss_run_out (HWVoiceOut *hw,size_t live) -{ -OSSVoiceOut *oss = (OSSVoiceOut *) hw; -int err; -size_t decr; -struct audio_buf_info abinfo; -struct count_info cntinfo; -size_t bufsize; - - bufsize = hw->samples << hw->info.shift; - -if (oss->mmapped) { -int bytes, pos; - - err =ioctl (oss->fd,SNDCTL_DSP_GETOPTR , &cntinfo); -if (err <0 ) { -oss_logerr (errno,"SNDCTL_DSP_GETOPTR failed\n" ); -return 0 ; - } - - pos = hw->rpos << hw->info.shift; - bytes =audio_ring_dist (cntinfo.ptr, pos, bufsize); - decr =MIN (bytes >> hw->info.shift, live); - } -else { - err =ioctl (oss->fd,SNDCTL_DSP_GETOSPACE , &abinfo); -if (err <0 ) { -oss_logerr (errno,"SNDCTL_DSP_GETOPTR failed\n" ); -return 0 ; - } - -if (abinfo.bytes > bufsize) { -trace_oss_invalid_available_size (abinfo.bytes, bufsize); - abinfo.bytes = bufsize; - } - -if (abinfo.bytes <0 ) { -trace_oss_invalid_available_size (abinfo.bytes, bufsize); -return 0 ; - } - - decr =MIN (abinfo.bytes >> hw->info.shift, live); -if (!decr) { -return 0 ; - } - } - - decr =audio_pcm_hw_clip_out (hw, oss->pcm_buf, decr, oss->pending); - oss->pending += decr; -oss_write_pending (oss); - -return decr; +return pos; }static void oss_fini_out (HWVoiceOut *hw)
@@ -472,18 +457,13 @@ static void oss_fini_out (HWVoiceOut *hw)ldebug ("oss_fini\n" );oss_anal_close (&oss->fd); -if (oss->pcm_buf) { -if (oss->mmapped) { - err =munmap (oss->pcm_buf, hw->samples << hw->info.shift); -if (err) { -oss_logerr (errno,"Failed to unmap buffer %p, size %zu\n" , - oss->pcm_buf, hw->samples << hw->info.shift); - } +if (oss->mmapped && hw->buf_emul) { + err =munmap (hw->buf_emul, hw->size_emul); +if (err) { +oss_logerr (errno,"Failed to unmap buffer %p, size %zu\n" , + hw->buf_emul, hw->size_emul); } -else { -g_free (oss->pcm_buf); - } - oss->pcm_buf =NULL ; + hw->buf_emul =NULL ; } }
@@ -534,19 +514,20 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as, oss->mmapped =0 ;if (oopts->has_try_mmap && oopts->try_mmap) { - oss->pcm_buf =mmap ( + hw->size_emul = hw->samples << hw->info.shift; + hw->buf_emul =mmap (NULL , - hw->samples << hw->info.shift, + hw->size_emul,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 ); -if (oss->pcm_buf ==MAP_FAILED ) { +if (hw->buf_emul ==MAP_FAILED ) {oss_logerr (errno,"Failed to map %zu bytes of DAC\n" , - hw->samples << hw->info.shift); - } -else { + hw->size_emul); + hw->buf_emul =NULL ; + }else {int err;int trig =0 ;if (ioctl (fd,SNDCTL_DSP_SETTRIGGER , &trig) <0 ) {
@@ -566,30 +547,16 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as, }if (!oss->mmapped) { - err =munmap (oss->pcm_buf, hw->samples << hw->info.shift); + err =munmap (hw->buf_emul, hw->size_emul);if (err) {oss_logerr (errno,"Failed to unmap buffer %p size %zu\n" , - oss->pcm_buf, hw->samples << hw->info.shift); + hw->buf_emul, hw->size_emul); } + hw->buf_emul =NULL ; } } } -if (!oss->mmapped) { - oss->pcm_buf =audio_calloc (__func__, - hw->samples, -1 << hw->info.shift); -if (!oss->pcm_buf) { -dolog ( -"Could not allocate DAC buffer (%zu samples, each %d bytes)\n" , - hw->samples, -1 << hw->info.shift - ); -oss_anal_close (&fd); -return -1 ; - } - } - oss->fd = fd; oss->dev = dev;return 0 ;
@@ -617,7 +584,7 @@ static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...)return 0 ; } -audio_pcm_info_clear_buf (&hw->info, oss->pcm_buf, hw->samples); +audio_pcm_info_clear_buf (&hw->info, hw->buf_emul, hw->samples); trig =PCM_ENABLE_OUTPUT ;if (ioctl (oss->fd,SNDCTL_DSP_SETTRIGGER , &trig) <0 ) { oss_logerr (
@@ -691,13 +658,6 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) } hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; - oss->pcm_buf =audio_calloc (__func__, hw->samples,1 << hw->info.shift); -if (!oss->pcm_buf) { -dolog ("Could not allocate ADC buffer (%zu samples, each %d bytes)\n" , - hw->samples,1 << hw->info.shift); -oss_anal_close (&fd); -return -1 ; - } oss->fd = fd; oss->dev = dev;
@@ -709,78 +669,36 @@ static void oss_fini_in (HWVoiceIn *hw)OSSVoiceIn *oss = (OSSVoiceIn *) hw;oss_anal_close (&oss->fd); - -g_free (oss->pcm_buf); - oss->pcm_buf =NULL ; } -static size_t oss_run_in (HWVoiceIn *hw) +static size_t oss_read (HWVoiceIn *hw,void *buf,size_t len) {OSSVoiceIn *oss = (OSSVoiceIn *) hw; -int hwshift = hw->info.shift; -int i; -size_t live =audio_pcm_hw_get_live_in (hw); -size_t dead = hw->samples - live; -size_t read_samples =0 ; -struct { -size_t add; -size_t len; - } bufs[2 ] = { - { .add = hw->wpos, .len =0 }, - { .add =0 , .len =0 } - }; +size_t pos =0 ; -if (!dead) { -return 0 ; - } - -if (hw->wpos + dead > hw->samples) { - bufs[0 ].len = (hw->samples - hw->wpos) << hwshift; - bufs[1 ].len = (dead - (hw->samples - hw->wpos)) << hwshift; - } -else { - bufs[0 ].len = dead << hwshift; - } - -for (i =0 ; i <2 ; ++i) { +while (len) {ssize_t nread; -if (bufs[i].len) { -void *p =advance (oss->pcm_buf, bufs[i].add << hwshift); - nread =read (oss->fd, p, bufs[i].len); +void *dst =advance (buf, pos); + nread =read (oss->fd, dst, len); -if (nread >0 ) { -if (nread & hw->info.align) { -dolog ("warning: Misaligned read %zd (requested %zu), " -"alignment %d\n" , nread, bufs[i].add << hwshift, - hw->info.align +1 ); - } - read_samples += nread >> hwshift; - hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwshift); - } - -if (bufs[i].len - nread) { -if (nread ==-1 ) { -switch (errno) { -case EINTR : -case EAGAIN : -break ; -default : -oss_logerr ( - errno, -"Failed to read %zu bytes of audio (to %p)\n" , - bufs[i].len, p - ); -break ; - } - } +if (nread ==-1 ) { +switch (errno) { +case EINTR : +case EAGAIN : +break ; +default : +oss_logerr (errno,"Failed to read %zu bytes of audio (to %p)\n" , + len, dst);break ; } } + + pos += nread; + len -= nread; } - hw->wpos = (hw->wpos + read_samples) % hw->samples; -return read_samples; +return pos; }static int oss_ctl_in (HWVoiceIn *hw,int cmd, ...)
@@ -850,12 +768,14 @@ static void oss_audio_fini (void *opaque)static struct audio_pcm_ops oss_pcm_ops = { .init_out = oss_init_out, .fini_out = oss_fini_out, - .run_out = oss_run_out, + .write = oss_write, + .get_buffer_out = oss_get_buffer_out, + .put_buffer_out = oss_put_buffer_out, .ctl_out = oss_ctl_out, .init_in = oss_init_in, .fini_in = oss_fini_in, - .run_in = oss_run_in, + .read = oss_read, .ctl_in = oss_ctl_in };
Signature · 1 line
2.20.1
PATCH v3 37/50 audio: unify input and output mixeng buffer management
In reply to Kővágó, ZoltánUsage notes: hw->samples became hw->{mix,conv}_buf->size, except before initialization (audio_pcm_hw_alloc_resources_*), hw->samples gives the initial size of the STSampleBuffer. The next commit tries to fix this inconsistency.
--- audio/audio_int.h | 12 ++-- audio/audio_template.h | 19 +++--- audio/audio.c | 130 ++++++++++++++++++++--------------------- audio/ossaudio.c | 2 +- 4 files changed, 80 insertions(+), 83 deletions(-)
audio/audio_int.h +7 -5
@@ -51,6 +51,11 @@ struct audio_pcm_info {typedef struct SWVoiceCap SWVoiceCap ; +typedef struct STSampleBuffer { +size_t pos, size; +st_sample samples[]; +}STSampleBuffer ; + typedef struct HWVoiceOut { AudioState *s; int enabled;
@@ -59,11 +64,9 @@ typedef struct HWVoiceOut {struct audio_pcm_info info;f_sample *clip; - -size_t rpos;uint64_t ts_helper; -struct st_sample *mix_buf; +STSampleBuffer *mix_buf;void *buf_emul;size_t pos_emul, pending_emul, size_emul;
@@ -83,11 +86,10 @@ typedef struct HWVoiceIn {t_sample *conv; -size_t wpos;size_t total_samples_captured;uint64_t ts_helper; -struct st_sample *conv_buf; +STSampleBuffer *conv_buf;void *buf_emul;size_t pos_emul, pending_emul, size_emul;
audio/audio_template.h +8 -11
@@ -76,16 +76,15 @@ static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)HWBUF =NULL ; } -static bool glue (audio_pcm_hw_alloc_resources_ ,TYPE )(HW *hw) +static void glue (audio_pcm_hw_alloc_resources_ ,TYPE )(HW *hw) { -HWBUF =audio_calloc (__func__, hw->samples,sizeof (struct st_sample )); -if (!HWBUF ) { -dolog ("Could not allocate " NAME " buffer (%zu samples)\n" , - hw->samples); -return false; +size_t samples = hw->samples; +if (audio_bug (__func__, samples ==0 )) { +dolog ("Attempted to allocate empty buffer\n" ); } -return true; +HWBUF =g_malloc0 (sizeof (STSampleBuffer) +sizeof (st_sample) * samples); +HWBUF ->size = samples; }static void glue (audio_pcm_sw_free_resources_ ,TYPE ) (SW *sw)
@@ -104,7 +103,7 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw) {int samples; - samples = ((int64_t ) sw->hw->samples <<32 ) / sw->ratio; + samples = ((int64_t ) sw->HWBUF->size <<32 ) / sw->ratio; sw->buf =audio_calloc (__func__, samples,sizeof (struct st_sample ));if (!sw->buf) {
@@ -280,9 +279,7 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s, [hw->info.swap_endianness] [audio_bits_to_index (hw->info.bits)]; -if (!glue (audio_pcm_hw_alloc_resources_,TYPE )(hw)) { - goto err1; - } +glue (audio_pcm_hw_alloc_resources_,TYPE )(hw);QLIST_INSERT_HEAD (&s->glue (hw_head_,TYPE ), hw, entries);glue (s->nb_hw_voices_,TYPE ) -=1 ;
audio/audio.c +64 -66
340 lines not on this page · raw message
audio/ossaudio.c +1 -1
@@ -584,7 +584,7 @@ static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...)return 0 ; } -audio_pcm_info_clear_buf (&hw->info, hw->buf_emul, hw->samples); +audio_pcm_info_clear_buf (&hw->info, hw->buf_emul, hw->mix_buf->size); trig =PCM_ENABLE_OUTPUT ;if (ioctl (oss->fd,SNDCTL_DSP_SETTRIGGER , &trig) <0 ) { oss_logerr (
Signature · 1 line
2.20.1
PATCH v3 39/50 audio: common rate control code for timer based outputs
In reply to Kővágó, ZoltánThis commit removes the ad-hoc rate-limiting code from noaudio and wavaudio, and replaces them with a (slightly modified) code from spiceaudio. This way multiple write calls (for example when the circular buffer wraps around) do not cause problems.
--- audio/audio_int.h | 9 +++++++++ audio/audio.c | 30 ++++++++++++++++++++++++++++ audio/noaudio.c | 49 +++++++++++++++++++++------------------------- audio/spiceaudio.c | 49 +++++++--------------------------------------- audio/wavaudio.c | 21 ++++++++++---------- 5 files changed, 78 insertions(+), 80 deletions(-)
audio/audio_int.h +9 -0
@@ -242,6 +242,15 @@ void *audio_calloc (const char *funcname, int nmemb, size_t size);void audio_run (AudioState *s,const char *msg); +typedef struct RateCtl { +int64_t start_ticks; +int64_t bytes_sent; +}RateCtl ; + +void audio_rate_start (RateCtl *rate); +size_t audio_rate_get_bytes (struct audio_pcm_info *info,RateCtl *rate, +size_t bytes_avail); +#define VOICE_ENABLE 1#define VOICE_DISABLE 2#define VOICE_VOLUME 3
audio/audio.c +30 -0
@@ -2032,3 +2032,33 @@ const char *audio_get_id(QEMUSoundCard *card)return "" ; } } + +void audio_rate_start (RateCtl *rate) +{ +memset (rate,0 ,sizeof (RateCtl)); + rate->start_ticks =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +} + +size_t audio_rate_get_bytes (struct audio_pcm_info *info,RateCtl *rate, +size_t bytes_avail) +{ +int64_t now; +int64_t ticks; +int64_t bytes; +int64_t samples; +size_t ret; + + now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); + ticks = now - rate->start_ticks; + bytes =muldiv64 (ticks, info->bytes_per_second,NANOSECONDS_PER_SECOND ); + samples = (bytes - rate->bytes_sent) >> info->shift; +if (samples <0 || samples >65536 ) { +AUD_log (NULL ,"Resetting rate control (%" PRId64" samples)" , samples); +audio_rate_start (rate); + samples =0 ; + } + + ret =MIN (samples << info->shift, bytes_avail); + rate->bytes_sent += ret; +return ret; +}
audio/noaudio.c +22 -27
93 lines not on this page · raw message
audio/spiceaudio.c +7 -42
100 lines not on this page · raw message
audio/wavaudio.c +10 -11
@@ -33,21 +33,15 @@typedef struct WAVVoiceOut {HWVoiceOut hw;FILE *f; -int64_t old_ticks; +RateCtl rate;int total_samples; }WAVVoiceOut ;static size_t wav_write_out (HWVoiceOut *hw,void *buf,size_t len) {WAVVoiceOut *wav = (WAVVoiceOut *) hw; -int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); -int64_t ticks = now - wav->old_ticks; -int64_t bytes = -muldiv64 (ticks, hw->info.bytes_per_second,NANOSECONDS_PER_SECOND ); - - bytes =MIN (bytes, len); - bytes = bytes >> hw->info.shift << hw->info.shift; - wav->old_ticks = now; +int64_t bytes =audio_rate_get_bytes (&hw->info, &wav->rate, len); +assert (bytes >> hw->info.shift << hw->info.shift == bytes);if (bytes &&fwrite (buf, bytes,1 , wav->f) !=1 ) { dolog("wav_write_out: fwrite of %zu bytes failed\nReaons: %s\n",
@@ -127,6 +121,8 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as, strerror(errno));return -1 ; } + +audio_rate_start (&wav->rate);return 0 ; }
@@ -176,8 +172,11 @@ static void wav_fini_out (HWVoiceOut *hw)static int wav_ctl_out (HWVoiceOut *hw,int cmd, ...) { - (void ) hw; - (void ) cmd; +WAVVoiceOut *wav = (WAVVoiceOut *) hw; + +if (cmd ==VOICE_ENABLE ) { +audio_rate_start (&wav->rate); + }return 0 ; }
Signature · 1 line
2.20.1
PATCH v3 45/50 audio: replace shift in audio_pcm_info with bytes_per_frame
In reply to Kővágó, ZoltánThe bit shifting trick worked because the number of bytes per frame was always a power-of-two (since QEMU only supports mono, stereo and 8, 16 and 32 bit samples). But if we want to add support for surround sound, this no longer holds true.
--- audio/audio_int.h | 3 +- audio/dsound_template.h | 10 +++--- audio/alsaaudio.c | 10 +++--- audio/audio.c | 76 ++++++++++++++++++++--------------------- audio/coreaudio.c | 4 +-- audio/dsoundaudio.c | 4 +-- audio/noaudio.c | 2 +- audio/ossaudio.c | 14 ++++---- audio/spiceaudio.c | 5 +-- audio/wavaudio.c | 6 ++-- 10 files changed, 67 insertions(+), 67 deletions(-)
audio/audio_int.h +1 -2
@@ -43,8 +43,7 @@ struct audio_pcm_info {int sign;int freq;int nchannels; -int align; -int shift; +int bytes_per_frame;int bytes_per_second;int swap_endianness; };
audio/dsound_template.h +5 -5
@@ -98,8 +98,8 @@ static int glue (dsound_lock_, TYPE) ( goto fail; } -if ((p1p && *p1p && (*blen1p & info->align)) || - (p2p && *p2p && (*blen2p & info->align))) { +if ((p1p && *p1p && (*blen1p % info->bytes_per_frame)) || + (p2p && *p2p && (*blen2p % info->bytes_per_frame))) {dolog ("DirectSound returned misaligned buffer %ld %ld\n" , *blen1p, *blen2p); glue (dsound_unlock_, TYPE) (buf, *p1p, p2p ? *p2p : NULL, *blen1p,
@@ -247,14 +247,14 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as, obt_as.endianness =0 ;audio_pcm_init_info (&hw->info, &obt_as); -if (bc.dwBufferBytes & hw->info.align) { +if (bc.dwBufferBytes % hw->info.bytes_per_frame) {dolog ("GetCaps returned misaligned buffer size %ld, alignment %d\n" , - bc.dwBufferBytes, hw->info.align +1 + bc.dwBufferBytes, hw->info.bytes_per_frame ); } hw->size_emul = bc.dwBufferBytes; - ds->samples = bc.dwBufferBytes >> hw->info.shift; + ds->samples = bc.dwBufferBytes / hw->info.bytes_per_frame; ds->s = s;#ifdef DEBUG_DSOUND
audio/alsaaudio.c +5 -5
@@ -611,7 +611,7 @@ static size_t alsa_write(HWVoiceOut *hw, void *buf, size_t len) {ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;size_t pos =0 ; -size_t len_frames = len >> hw->info.shift; +size_t len_frames = len / hw->info.bytes_per_frame;while (len_frames) {char *src =advance (buf, pos);
@@ -655,7 +655,7 @@ static size_t alsa_write(HWVoiceOut *hw, void *buf, size_t len) } } - pos += written << hw->info.shift; + pos += written * hw->info.bytes_per_frame;if (written < len_frames) {break ; }
@@ -821,7 +821,7 @@ static size_t alsa_read(HWVoiceIn *hw, void *buf, size_t len)void *dst =advance (buf, pos);snd_pcm_sframes_t nread; - nread =snd_pcm_readi (alsa->handle, dst, len >> hw->info.shift); + nread =snd_pcm_readi (alsa->handle, dst, len / hw->info.bytes_per_frame);if (nread <=0 ) {switch (nread) {
@@ -847,8 +847,8 @@ static size_t alsa_read(HWVoiceIn *hw, void *buf, size_t len) } } - pos += nread << hw->info.shift; - len -= nread << hw->info.shift; + pos += nread * hw->info.bytes_per_frame; + len -= nread * hw->info.bytes_per_frame; }return pos;
audio/audio.c +38 -38
267 lines not on this page · raw message
audio/coreaudio.c +2 -2
@@ -441,7 +441,7 @@ static OSStatus audioDeviceIOProc( } frameCount = core->audioDevicePropertyBufferFrameSize; - pending_frames = hw->pending_emul >> hw->info.shift; + pending_frames = hw->pending_emul / hw->info.bytes_per_frame;/* if there are not enough samples, set signal and return */ if (pending_frames < frameCount) {
@@ -450,7 +450,7 @@ static OSStatus audioDeviceIOProc(return 0 ; } - len = frameCount << hw->info.shift; + len = frameCount * hw->info.bytes_per_frame;while (len) {size_t write_len;ssize_t start = ((ssize_t ) hw->pos_emul) - hw->pending_emul;
audio/dsoundaudio.c +2 -2
@@ -322,8 +322,8 @@ static void dsound_clear_sample (HWVoiceOut *hw, LPDIRECTSOUNDBUFFER dsb,return ; } - len1 = blen1 >> hw->info.shift; - len2 = blen2 >> hw->info.shift; + len1 = blen1 / hw->info.bytes_per_frame; + len2 = blen2 / hw->info.bytes_per_frame;#ifdef DEBUG_DSOUND dolog ("clear %p,%ld,%ld %p,%ld,%ld\n",
audio/noaudio.c +1 -1
@@ -88,7 +88,7 @@ static size_t no_read(HWVoiceIn *hw, void *buf, size_t size)NoVoiceIn *no = (NoVoiceIn *) hw;int64_t bytes =audio_rate_get_bytes (&hw->info, &no->rate, size); -audio_pcm_info_clear_buf (&hw->info, buf, bytes >> hw->info.shift); +audio_pcm_info_clear_buf (&hw->info, buf, bytes / hw->info.bytes_per_frame);return bytes; }
audio/ossaudio.c +7 -7
@@ -507,16 +507,16 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as, oss->nfrags = obt.nfrags; oss->fragsize = obt.fragsize; -if (obt.nfrags * obt.fragsize & hw->info.align) { +if (obt.nfrags * obt.fragsize % hw->info.bytes_per_frame) {dolog ("warning: Misaligned DAC buffer, size %d, alignment %d\n" , - obt.nfrags * obt.fragsize, hw->info.align +1 ); + obt.nfrags * obt.fragsize, hw->info.bytes_per_frame); } - oss->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; + oss->samples = (obt.nfrags * obt.fragsize) / hw->info.bytes_per_frame; oss->mmapped =0 ;if (oopts->has_try_mmap && oopts->try_mmap) { - hw->size_emul = oss->samples << hw->info.shift; + hw->size_emul = oss->samples * hw->info.bytes_per_frame; hw->buf_emul = mmap ( NULL, hw->size_emul,
@@ -651,12 +651,12 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) oss->nfrags = obt.nfrags; oss->fragsize = obt.fragsize; -if (obt.nfrags * obt.fragsize & hw->info.align) { +if (obt.nfrags * obt.fragsize % hw->info.bytes_per_frame) {dolog ("warning: Misaligned ADC buffer, size %d, alignment %d\n" , - obt.nfrags * obt.fragsize, hw->info.align +1 ); + obt.nfrags * obt.fragsize, hw->info.bytes_per_frame); } - oss->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; + oss->samples = (obt.nfrags * obt.fragsize) / hw->info.bytes_per_frame; oss->fd = fd; oss->dev = dev;
audio/spiceaudio.c +3 -2
@@ -133,8 +133,9 @@ static void *line_out_get_buffer(HWVoiceOut *hw, size_t *size) out->fpos =0 ; } - *size =audio_rate_get_bytes (&hw->info, &out->rate, - (out->fsize - out->fpos) << hw->info.shift); + *size =audio_rate_get_bytes ( + &hw->info, &out->rate, + (out->fsize - out->fpos) * hw->info.bytes_per_frame);return out->frame + out->fpos; }
audio/wavaudio.c +3 -3
@@ -41,14 +41,14 @@ static size_t wav_write_out(HWVoiceOut *hw, void *buf, size_t len) {WAVVoiceOut *wav = (WAVVoiceOut *) hw;int64_t bytes =audio_rate_get_bytes (&hw->info, &wav->rate, len); -assert (bytes >> hw->info.shift << hw->info.shift == bytes); +assert (bytes % hw->info.bytes_per_frame ==0 );if (bytes &&fwrite (buf, bytes,1 , wav->f) !=1 ) {dolog ("wav_write_out: fwrite of %zu bytes failed\nReaons: %s\n" , bytes,strerror (errno)); } - wav->total_samples += bytes >> hw->info.shift; + wav->total_samples += bytes / hw->info.bytes_per_frame;return bytes; }
@@ -131,7 +131,7 @@ static void wav_fini_out (HWVoiceOut *hw)WAVVoiceOut *wav = (WAVVoiceOut *) hw;uint8_t rlen[4 ];uint8_t dlen[4 ]; -uint32_t datalen = wav->total_samples << hw->info.shift; +uint32_t datalen = wav->total_samples * hw->info.bytes_per_frame;uint32_t rifflen = datalen +36 ;if (!wav->f) {
Signature · 1 line
2.20.1
PATCH v3 38/50 audio: remove hw->samples, buffer_size_in/out pcm_ops
In reply to Kővágó, ZoltánThis patch removes the samples member from HWVoiceIn and HWVoiceOut. Backends can specify buffer size via the newly added buffer_size_in and buffer_size_out functions in audio_pcm_ops. They are optional, if not defined qemu will fall back to some built-in constant.
---
Notes:
Not sure if this is necessary. At first it seemed like a good idea to have a function so that backends can compute the size on demand when needed and things like that, but currently it's just a burden. The only good feature is that it allows a backend to not define a function and let the audio subsystem choose a default value, but the same could be achieved by specifying that hw->samples = 0 means use a default value.
So if you guys agree, I'll remove this patch. Maybe add an -audiodev parameter to change it, overriding whatever the backends supplies.
audio/audio_int.h | 5 +++-- audio/audio_template.h | 24 +++++++++++++++--------- audio/dsound_template.h | 8 +++++++- audio/alsaaudio.c | 20 ++++++++++++++++++-- audio/audio.c | 2 -- audio/coreaudio.c | 10 +++++++++- audio/dsoundaudio.c | 4 ++++ audio/noaudio.c | 2 -- audio/ossaudio.c | 22 +++++++++++++++++++--- audio/paaudio.c | 21 +++++++++++++++++---- audio/sdlaudio.c | 10 +++++++++- audio/spiceaudio.c | 14 ++++++++++++-- audio/wavaudio.c | 1 - 13 files changed, 113 insertions(+), 30 deletions(-)
audio/audio_int.h +3 -2
@@ -70,7 +70,6 @@ typedef struct HWVoiceOut {void *buf_emul;size_t pos_emul, pending_emul, size_emul; -size_t samples; QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head; QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;int ctl_caps;
@@ -93,7 +92,6 @@ typedef struct HWVoiceIn {void *buf_emul;size_t pos_emul, pending_emul, size_emul; -size_t samples; QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;int ctl_caps;struct audio_pcm_ops *pcm_ops;
@@ -155,6 +153,8 @@ struct audio_pcm_ops {int (*init_out)(HWVoiceOut *hw,audsettings *as,void *drv_opaque);void (*fini_out)(HWVoiceOut *hw);size_t (*write) (HWVoiceOut *hw,void *buf,size_t size); +/* get the optimal buffer size in samples; optional */ +size_t (*buffer_size_out)(HWVoiceOut *hw);/* * get a buffer that after later can be passed to put_buffer_out; optional * returns the buffer, and writes it's size to size (in bytes)
@@ -172,6 +172,7 @@ struct audio_pcm_ops {int (*init_in) (HWVoiceIn *hw,audsettings *as,void *drv_opaque);void (*fini_in) (HWVoiceIn *hw);size_t (*read) (HWVoiceIn *hw,void *buf,size_t size); +size_t (*buffer_size_in)(HWVoiceIn *hw);void *(*get_buffer_in)(HWVoiceIn *hw,size_t *size);void (*put_buffer_in)(HWVoiceIn *hw,void *buf,size_t size);int (*ctl_in) (HWVoiceIn *hw,int cmd, ...);
audio/audio_template.h +15 -9
@@ -78,7 +78,20 @@ static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)static void glue (audio_pcm_hw_alloc_resources_ ,TYPE )(HW *hw) { -size_t samples = hw->samples; +size_t samples; +if (!hw->pcm_ops) { +/* +* We should only end up here when using wavcapture hmp command (and not +* the wavcapture audio backend). +* It needs a lot of samples, otherwise you'll end up with "Could not +* mix X bytes into a capture buffer" warnings and a garbled capture. +*/ + samples =4096 *4 ; + }else if (hw->pcm_ops->glue (buffer_size_,TYPE )) { + samples = hw->pcm_ops->glue (buffer_size_,TYPE )(hw); + }else { + samples =1024 ;/* todo better default */ + }if (audio_bug (__func__, samples ==0 )) {dolog ("Attempted to allocate empty buffer\n" ); }
@@ -264,11 +277,6 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s, goto err0; } -if (audio_bug (__func__, hw->samples <=0 )) { -dolog ("hw->samples=%zd\n" , hw->samples); - goto err1; - } -#ifdef DAC hw->clip = mixeng_clip #else
@@ -288,9 +296,7 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,#endif return hw; - err1: -glue (hw->pcm_ops->fini_,TYPE ) (hw); - err0: +err0:g_free (hw);return NULL ; }
audio/dsound_template.h +7 -1
@@ -254,7 +254,7 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as, ); } hw->size_emul = bc.dwBufferBytes; - hw->samples = bc.dwBufferBytes >> hw->info.shift; + ds->samples = bc.dwBufferBytes >> hw->info.shift; ds->s = s;#ifdef DEBUG_DSOUND
@@ -268,6 +268,12 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,return -1 ; } +static size_t glue (dsound_buffer_size_ ,TYPE )(HWVOICE *hw) +{ +DSOUNDVOICE *ds = (DSOUNDVOICE *) hw; +return ds->samples; +} +#undef NAME#undef NAME2#undef TYPE
audio/alsaaudio.c +18 -2
@@ -44,6 +44,7 @@ struct pollhlp {typedef struct ALSAVoiceOut {HWVoiceOut hw;snd_pcm_t *handle; +size_t samples;struct pollhlp pollhlp;Audiodev *dev; }ALSAVoiceOut ;
@@ -51,6 +52,7 @@ typedef struct ALSAVoiceOut {typedef struct ALSAVoiceIn {HWVoiceIn hw;snd_pcm_t *handle; +size_t samples;struct pollhlp pollhlp;Audiodev *dev; }ALSAVoiceIn ;
@@ -695,7 +697,7 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as, obt_as.endianness = obt.endianness;audio_pcm_init_info (&hw->info, &obt_as); - hw->samples = obt.samples; + alsa->samples = obt.samples; alsa->pollhlp.s = hw->s; alsa->handle = handle;
@@ -703,6 +705,12 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,return 0 ; } +static size_t alsa_buffer_size_out (HWVoiceOut *hw) +{ +ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw; +return alsa->samples; +} +#define VOICE_CTL_PAUSE 0#define VOICE_CTL_PREPARE 1#define VOICE_CTL_START 2
@@ -789,7 +797,7 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) obt_as.endianness = obt.endianness;audio_pcm_init_info (&hw->info, &obt_as); - hw->samples = obt.samples; + alsa->samples = obt.samples; alsa->pollhlp.s = hw->s; alsa->handle = handle;
@@ -797,6 +805,12 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)return 0 ; } +static size_t alsa_buffer_size_in (HWVoiceIn *hw) +{ +ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw; +return alsa->samples; +} +static void alsa_fini_in (HWVoiceIn *hw) {ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
@@ -933,11 +947,13 @@ static void alsa_audio_fini (void *opaque)static struct audio_pcm_ops alsa_pcm_ops = { .init_out = alsa_init_out, .fini_out = alsa_fini_out, + .buffer_size_out = alsa_buffer_size_out, .write = alsa_write, .ctl_out = alsa_ctl_out, .init_in = alsa_init_in, .fini_in = alsa_fini_in, + .buffer_size_in = alsa_buffer_size_in, .read = alsa_read, .ctl_in = alsa_ctl_in, };
audio/audio.c +0 -2
@@ -1763,8 +1763,6 @@ CaptureVoiceOut *AUD_add_capture(QLIST_INIT (&hw->sw_head);QLIST_INIT (&cap->cb_head); -/* XXX find a more elegant way */ - hw->samples =4096 *4 ;audio_pcm_hw_alloc_resources_out (hw);audio_pcm_init_info (&hw->info, as);
audio/coreaudio.c +9 -1
@@ -43,6 +43,7 @@ typedef struct coreaudioVoiceOut {UInt32 audioDevicePropertyBufferFrameSize;AudioStreamBasicDescription outputStreamBasicDescription;AudioDeviceIOProcID ioprocid; +size_t samples; } coreaudioVoiceOut;#if MAC_OS_X_VERSION_MAX_ALLOWED >=MAC_OS_X_VERSION_10_6
@@ -557,7 +558,7 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, "Could not get device buffer frame size\n");return -1 ; } - hw->samples = (pdo->has_buffer_count ? pdo->buffer_count :4 ) * + core->samples = (pdo->has_buffer_count ? pdo->buffer_count :4 ) * core->audioDevicePropertyBufferFrameSize;/* get StreamFormat */
@@ -617,6 +618,12 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,return 0 ; } +static size_t coreaudio_buffer_size_out (HWVoiceOut *hw) +{ +coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; +return core->samples; +} +static void coreaudio_fini_out (HWVoiceOut *hw) {OSStatus status;
@@ -693,6 +700,7 @@ static struct audio_pcm_ops coreaudio_pcm_ops = { .init_out = coreaudio_init_out, .fini_out = coreaudio_fini_out, .write = coreaudio_write, + .buffer_size_out = coreaudio_buffer_size_out, .get_buffer_out = coreaudio_get_buffer_out, .put_buffer_out = coreaudio_put_buffer_out_nowrite, .ctl_out = coreaudio_ctl_out
audio/dsoundaudio.c +4 -0
@@ -54,12 +54,14 @@ typedef struct {HWVoiceOut hw;LPDIRECTSOUNDBUFFER dsound_buffer;dsound *s; +size_t samples; } DSoundVoiceOut;typedef struct {HWVoiceIn hw;LPDIRECTSOUNDCAPTUREBUFFER dsound_capture_buffer;dsound *s; +size_t samples; }DSoundVoiceIn ;static void dsound_log_hresult (HRESULT hr)
@@ -672,6 +674,7 @@ static struct audio_pcm_ops dsound_pcm_ops = { .init_out = dsound_init_out, .fini_out = dsound_fini_out, .write = audio_generic_write, + .buffer_size_out = dsound_buffer_size_out, .get_buffer_out = dsound_get_buffer_out, .put_buffer_out = dsound_put_buffer_out, .ctl_out = dsound_ctl_out,
@@ -679,6 +682,7 @@ static struct audio_pcm_ops dsound_pcm_ops = { .init_in = dsound_init_in, .fini_in = dsound_fini_in, .read = audio_generic_read, + .buffer_size_in = dsound_buffer_size_in, .get_buffer_in = dsound_get_buffer_in, .put_buffer_in = dsound_put_buffer_in, .ctl_in = dsound_ctl_in
audio/noaudio.c +0 -2
@@ -58,7 +58,6 @@ static size_t no_write(HWVoiceOut *hw, void *buf, size_t len)static int no_init_out (HWVoiceOut *hw,struct audsettings *as,void *drv_opaque) {audio_pcm_init_info (&hw->info, as); - hw->samples =1024 ;return 0 ; }
@@ -77,7 +76,6 @@ static int no_ctl_out (HWVoiceOut *hw, int cmd, ...)static int no_init_in (HWVoiceIn *hw,struct audsettings *as,void *drv_opaque) {audio_pcm_init_info (&hw->info, as); - hw->samples =1024 ;return 0 ; }
audio/ossaudio.c +19 -3
@@ -43,6 +43,7 @@ typedef struct OSSVoiceOut {int nfrags;int fragsize;int mmapped; +size_t samples;Audiodev *dev; } OSSVoiceOut;
@@ -51,6 +52,7 @@ typedef struct OSSVoiceIn {int fd;int nfrags;int fragsize; +size_t samples;Audiodev *dev; } OSSVoiceIn;
@@ -510,11 +512,11 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as, obt.nfrags * obt.fragsize, hw->info.align + 1); } - hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; + oss->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; oss->mmapped =0 ;if (oopts->has_try_mmap && oopts->try_mmap) { - hw->size_emul = hw->samples << hw->info.shift; + hw->size_emul = oss->samples << hw->info.shift; hw->buf_emul = mmap ( NULL, hw->size_emul,
@@ -562,6 +564,12 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,return 0 ; } +static size_t oss_buffer_size_out (HWVoiceOut *hw) +{ +OSSVoiceOut *oss = (OSSVoiceOut *) hw; +return oss->samples; +} +static int oss_ctl_out (HWVoiceOut *hw,int cmd, ...) {int trig;
@@ -657,13 +665,19 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) obt.nfrags * obt.fragsize, hw->info.align + 1); } - hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; + oss->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift; oss->fd = fd; oss->dev = dev;return 0 ; } +static size_t oss_buffer_size_in (HWVoiceIn *hw) +{ +OSSVoiceIn *oss = (OSSVoiceIn *) hw; +return oss->samples; +} +static void oss_fini_in (HWVoiceIn *hw) {OSSVoiceIn *oss = (OSSVoiceIn *) hw;
@@ -769,6 +783,7 @@ static struct audio_pcm_ops oss_pcm_ops = { .init_out = oss_init_out, .fini_out = oss_fini_out, .write = oss_write, + .buffer_size_out = oss_buffer_size_out, .get_buffer_out = oss_get_buffer_out, .put_buffer_out = oss_put_buffer_out, .ctl_out = oss_ctl_out,
@@ -776,6 +791,7 @@ static struct audio_pcm_ops oss_pcm_ops = { .init_in = oss_init_in, .fini_in = oss_fini_in, .read = oss_read, + .buffer_size_in = oss_buffer_size_in, .ctl_in = oss_ctl_in };
audio/paaudio.c +17 -4
@@ -355,8 +355,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as, }audio_pcm_init_info (&hw->info, &obt_as); - hw->samples = pa->samples =audio_buffer_samples (g->dev->out, &obt_as, -46440 ); + pa->samples =audio_buffer_samples (g->dev->out, &obt_as,46440 );return 0 ;
@@ -364,6 +363,13 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,return -1 ; } +static size_t qpa_buffer_size_out (HWVoiceOut *hw) +{ +PAVoiceOut *pa = (PAVoiceOut *) hw; +return pa->samples; +} + +static int qpa_init_in (HWVoiceIn *hw,struct audsettings *as,void *drv_opaque) {int error;
@@ -397,8 +403,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) }audio_pcm_init_info (&hw->info, &obt_as); - hw->samples = pa->samples =audio_buffer_samples (g->dev->in, &obt_as, -46440 ); + pa->samples =audio_buffer_samples (g->dev->in, &obt_as,46440 );return 0 ;
@@ -406,6 +411,12 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)return -1 ; } +static size_t qpa_buffer_size_in (HWVoiceIn *hw) +{ +PAVoiceIn *pa = (PAVoiceIn *) hw; +return pa->samples; +} +static void qpa_simple_disconnect (PAConnection *c,pa_stream *stream) {int err;
@@ -696,11 +707,13 @@ static struct audio_pcm_ops qpa_pcm_ops = { .init_out = qpa_init_out, .fini_out = qpa_fini_out, .write = qpa_write, + .buffer_size_out = qpa_buffer_size_out, .ctl_out = qpa_ctl_out, .init_in = qpa_init_in, .fini_in = qpa_fini_in, .read = qpa_read, + .buffer_size_in = qpa_buffer_size_in, .ctl_in = qpa_ctl_in };
audio/sdlaudio.c +9 -1
@@ -42,6 +42,7 @@typedef struct SDLVoiceOut {HWVoiceOut hw; +size_t samples; }SDLVoiceOut ; static struct SDLAudioState {
@@ -363,7 +364,7 @@ static int sdl_init_out(HWVoiceOut *hw, struct audsettings *as, obt_as.endianness = endianness;audio_pcm_init_info (&hw->info, &obt_as); - hw->samples = obt.samples; + sdl->samples = obt.samples; s->initialized =1 ; s->exit =0 ;
@@ -371,6 +372,12 @@ static int sdl_init_out(HWVoiceOut *hw, struct audsettings *as,return 0 ; } +static size_t sdl_buffer_size_out (HWVoiceOut *hw) +{ +SDLVoiceOut *sdl = (SDLVoiceOut *) hw; +return sdl->samples; +} +static int sdl_ctl_out (HWVoiceOut *hw,int cmd, ...) { (void ) hw;
@@ -439,6 +446,7 @@ static struct audio_pcm_ops sdl_pcm_ops = { .init_out = sdl_init_out, .fini_out = sdl_fini_out, .write = sdl_write, + .buffer_size_out = sdl_buffer_size_out, .get_buffer_out = sdl_get_buffer_out, .put_buffer_out = sdl_put_buffer_out_nowrite, .ctl_out = sdl_ctl_out,
audio/spiceaudio.c +12 -2
@@ -133,7 +133,6 @@ static int line_out_init(HWVoiceOut *hw, struct audsettings *as, settings.endianness =AUDIO_HOST_ENDIANNESS ;audio_pcm_init_info (&hw->info, &settings); - hw->samples =LINE_OUT_SAMPLES ; out->active =0 ; out->sin.base.sif = &playback_sif.base;
@@ -144,6 +143,11 @@ static int line_out_init(HWVoiceOut *hw, struct audsettings *as,return 0 ; } +static size_t line_out_buffer_size (HWVoiceOut *hw) +{ +return LINE_OUT_SAMPLES ; +} +static void line_out_fini (HWVoiceOut *hw) {SpiceVoiceOut *out =container_of (hw, SpiceVoiceOut, hw);
@@ -248,7 +252,6 @@ static int line_in_init(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) settings.endianness =AUDIO_HOST_ENDIANNESS ;audio_pcm_init_info (&hw->info, &settings); - hw->samples =LINE_IN_SAMPLES ; in->active =0 ; in->sin.base.sif = &record_sif.base;
@@ -259,6 +262,11 @@ static int line_in_init(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)return 0 ; } +static size_t line_in_buffer_size (HWVoiceIn *hw) +{ +return LINE_IN_SAMPLES ; +} +static void line_in_fini (HWVoiceIn *hw) {SpiceVoiceIn *in =container_of (hw, SpiceVoiceIn, hw);
@@ -329,6 +337,7 @@ static struct audio_pcm_ops audio_callbacks = { .init_out = line_out_init, .fini_out = line_out_fini, .write = audio_generic_write, + .buffer_size_out = line_out_buffer_size, .get_buffer_out = line_out_get_buffer, .put_buffer_out = line_out_put_buffer, .ctl_out = line_out_ctl,
@@ -336,6 +345,7 @@ static struct audio_pcm_ops audio_callbacks = { .init_in = line_in_init, .fini_in = line_in_fini, .read = line_in_read, + .buffer_size_in = line_in_buffer_size, .ctl_in = line_in_ctl, };
audio/wavaudio.c +0 -1
@@ -110,7 +110,6 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as, wav_as.endianness =0 ;audio_pcm_init_info (&hw->info, &wav_as); - hw->samples =1024 ;le_store (hdr +22 , hw->info.nchannels,2 );le_store (hdr +24 , hw->info.freq,4 );le_store (hdr +28 , hw->info.freq << (bits16 + stereo),4 );
Signature · 1 line
2.20.1
PATCH v3 40/50 audio: split ctl_* functions into enable_* and volume_*
In reply to Kővágó, ZoltánThis way we no longer need vararg functions, improving compile time error detection. Also now it's possible to check actually what commands are supported, without needing to manually update ctl_caps.
--- audio/audio_int.h | 15 ++--- audio/audio_template.h | 1 - audio/alsaaudio.c | 56 +++++++----------- audio/audio.c | 45 +++++++++------ audio/coreaudio.c | 13 ++--- audio/dsoundaudio.c | 50 +++++++--------- audio/noaudio.c | 14 ++--- audio/ossaudio.c | 78 ++++++++++--------------- audio/paaudio.c | 126 ++++++++++++++++------------------------- audio/sdlaudio.c | 17 +----- audio/spiceaudio.c | 101 ++++++++++++++------------------- audio/wavaudio.c | 7 +-- 12 files changed, 213 insertions(+), 310 deletions(-)
audio/audio_int.h +4 -11
@@ -72,7 +72,6 @@ typedef struct HWVoiceOut { QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head; QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head; -int ctl_caps;struct audio_pcm_ops *pcm_ops;QLIST_ENTRY (HWVoiceOut) entries; } HWVoiceOut;
@@ -93,7 +92,6 @@ typedef struct HWVoiceIn {size_t pos_emul, pending_emul, size_emul; QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head; -int ctl_caps;struct audio_pcm_ops *pcm_ops;QLIST_ENTRY (HWVoiceIn) entries; } HWVoiceIn;
@@ -145,7 +143,6 @@ struct audio_driver {int max_voices_in;int voice_size_out;int voice_size_in; -int ctl_caps;QLIST_ENTRY (audio_driver) next; };
@@ -167,7 +164,8 @@ struct audio_pcm_ops {* size may be smaller */ size_t (*put_buffer_out)(HWVoiceOut *hw,void *buf,size_t size); -int (*ctl_out) (HWVoiceOut *hw,int cmd, ...); +void (*enable_out)(HWVoiceOut *hw,bool enable); +void (*volume_out)(HWVoiceOut *hw,struct mixeng_volume *vol);int (*init_in) (HWVoiceIn *hw,audsettings *as,void *drv_opaque);void (*fini_in) (HWVoiceIn *hw);
@@ -175,7 +173,8 @@ struct audio_pcm_ops {size_t (*buffer_size_in)(HWVoiceIn *hw);void *(*get_buffer_in)(HWVoiceIn *hw,size_t *size);void (*put_buffer_in)(HWVoiceIn *hw,void *buf,size_t size); -int (*ctl_in) (HWVoiceIn *hw,int cmd, ...); +void (*enable_in)(HWVoiceIn *hw,bool enable); +void (*volume_in)(HWVoiceIn *hw,struct mixeng_volume *vol); };void *audio_generic_get_buffer_in (HWVoiceIn *hw,size_t *size);
@@ -251,12 +250,6 @@ void audio_rate_start(RateCtl *rate);size_t audio_rate_get_bytes (struct audio_pcm_info *info,RateCtl *rate,size_t bytes_avail); -#define VOICE_ENABLE 1 -#define VOICE_DISABLE 2 -#define VOICE_VOLUME 3 - -#define VOICE_VOLUME_CAP (1 << VOICE_VOLUME) -static inline size_t audio_ring_dist (size_t dst,size_t src,size_t len) {return (dst >= src) ? (dst - src) : (len - src + dst);
audio/audio_template.h +0 -1
@@ -267,7 +267,6 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s, hw->s = s; hw->pcm_ops = drv->pcm_ops; - hw->ctl_caps = drv->ctl_caps;QLIST_INIT (&hw->sw_head);#ifdef DAC
audio/alsaaudio.c +22 -34
104 lines not on this page · raw message
audio/audio.c +28 -17
117 lines not on this page · raw message
audio/coreaudio.c +4 -9
@@ -655,13 +655,12 @@ static void coreaudio_fini_out (HWVoiceOut *hw) } } -static int coreaudio_ctl_out (HWVoiceOut *hw,int cmd, ...) +static void coreaudio_enable_out (HWVoiceOut *hw,bool enable) {OSStatus status;coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; -switch (cmd) { -case VOICE_ENABLE : +if (enable) {/* start playback */ if (!isPlaying (core->outputDeviceID)) { status =AudioDeviceStart (core->outputDeviceID, core->ioprocid);
@@ -669,9 +668,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)coreaudio_logerr (status,"Could not resume playback\n" ); } } -break ; - -case VOICE_DISABLE : + }else {/* stop playback */ if (!audio_is_cleaning_up ()) {if (isPlaying (core->outputDeviceID)) {
@@ -682,9 +679,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...) } } } -break ; } -return 0 ; }static void *coreaudio_audio_init (Audiodev *dev)
@@ -703,7 +698,7 @@ static struct audio_pcm_ops coreaudio_pcm_ops = { .buffer_size_out = coreaudio_buffer_size_out, .get_buffer_out = coreaudio_get_buffer_out, .put_buffer_out = coreaudio_put_buffer_out_nowrite, - .ctl_out = coreaudio_ctl_out + .enable_out = coreaudio_enable_out };static struct audio_driver coreaudio_audio_driver = {
audio/dsoundaudio.c +20 -30
140 lines not on this page · raw message
audio/noaudio.c +6 -8
@@ -60,14 +60,13 @@ static void no_fini_out (HWVoiceOut *hw) (void ) hw; } -static int no_ctl_out (HWVoiceOut *hw,int cmd, ...) +static void no_enable_out (HWVoiceOut *hw,bool enable) {NoVoiceOut *no = (NoVoiceOut *) hw; -if (cmd ==VOICE_ENABLE ) { +if (enable) {audio_rate_start (&no->rate); } -return 0 ; }static int no_init_in (HWVoiceIn *hw,struct audsettings *as,void *drv_opaque)
@@ -93,14 +92,13 @@ static size_t no_read(HWVoiceIn *hw, void *buf, size_t size)return bytes; } -static int no_ctl_in (HWVoiceIn *hw,int cmd, ...) +static void no_enable_in (HWVoiceIn *hw,bool enable) {NoVoiceIn *no = (NoVoiceIn *) hw; -if (cmd ==VOICE_ENABLE ) { +if (enable) {audio_rate_start (&no->rate); } -return 0 ; }static void *no_audio_init (Audiodev *dev)
@@ -117,12 +115,12 @@ static struct audio_pcm_ops no_pcm_ops = { .init_out = no_init_out, .fini_out = no_fini_out, .write = no_write, - .ctl_out = no_ctl_out, + .enable_out = no_enable_out, .init_in = no_init_in, .fini_in = no_fini_in, .read = no_read, - .ctl_in = no_ctl_in + .enable_in = no_enable_in };static struct audio_driver no_audio_driver = {
audio/ossaudio.c +31 -47
135 lines not on this page · raw message
audio/paaudio.c +50 -76
171 lines not on this page · raw message
audio/sdlaudio.c +3 -14
@@ -378,20 +378,9 @@ static size_t sdl_buffer_size_out(HWVoiceOut *hw)return sdl->samples; } -static int sdl_ctl_out (HWVoiceOut *hw,int cmd, ...) +static void sdl_enable_out (HWVoiceOut *hw,bool enable) { - (void ) hw; - -switch (cmd) { -case VOICE_ENABLE : -SDL_PauseAudio (0 ); -break ; - -case VOICE_DISABLE : -SDL_PauseAudio (1 ); -break ; - } -return 0 ; +SDL_PauseAudio (!enable); }static void *sdl_audio_init (Audiodev *dev)
@@ -449,7 +438,7 @@ static struct audio_pcm_ops sdl_pcm_ops = { .buffer_size_out = sdl_buffer_size_out, .get_buffer_out = sdl_get_buffer_out, .put_buffer_out = sdl_put_buffer_out_nowrite, - .ctl_out = sdl_ctl_out, + .enable_out = sdl_enable_out, };static struct audio_driver sdl_audio_driver = {
audio/spiceaudio.c +42 -59
163 lines not on this page · raw message
audio/wavaudio.c +3 -4
@@ -170,14 +170,13 @@ static void wav_fini_out (HWVoiceOut *hw) wav->f =NULL ; } -static int wav_ctl_out (HWVoiceOut *hw,int cmd, ...) +static void wav_enable_out (HWVoiceOut *hw,bool enable) {WAVVoiceOut *wav = (WAVVoiceOut *) hw; -if (cmd ==VOICE_ENABLE ) { +if (enable) {audio_rate_start (&wav->rate); } -return 0 ; }static void *wav_audio_init (Audiodev *dev)
@@ -195,7 +194,7 @@ static struct audio_pcm_ops wav_pcm_ops = { .init_out = wav_init_out, .fini_out = wav_fini_out, .write = wav_write_out, - .ctl_out = wav_ctl_out, + .enable_out = wav_enable_out, };static struct audio_driver wav_audio_driver = {
Signature · 1 line
2.20.1
PATCH v3 25/50 audio: use size_t where makes sense
In reply to Kővágó, Zoltán---
Notes:
Changes from v2:
* Update REPLAY_VERSION
* Fix run_in/run_out prototypes in audio_pcm_ops
audio/audio.h | 4 +- audio/audio_int.h | 26 +++---- audio/audio_template.h | 14 ++-- audio/mixeng.h | 9 ++- audio/rate_template.h | 2 +- include/sysemu/replay.h | 4 +- audio/alsaaudio.c | 26 +++---- audio/audio.c | 162 ++++++++++++++++++++-------------------- audio/coreaudio.c | 10 +-- audio/dsoundaudio.c | 11 +-- audio/noaudio.c | 16 ++-- audio/ossaudio.c | 45 +++++------ audio/paaudio.c | 44 +++++------ audio/sdlaudio.c | 19 +++-- audio/spiceaudio.c | 12 +-- audio/wavaudio.c | 8 +- replay/replay-audio.c | 16 ++-- replay/replay.c | 2 +- 18 files changed, 214 insertions(+), 216 deletions(-)
audio/audio.h +2 -2
@@ -112,7 +112,7 @@ SWVoiceOut *AUD_open_out ( );void AUD_close_out (QEMUSoundCard *card,SWVoiceOut *sw); -int AUD_write (SWVoiceOut *sw,void *pcm_buf,int size); +size_t AUD_write (SWVoiceOut *sw,void *pcm_buf,size_t size);int AUD_get_buffer_size_out (SWVoiceOut *sw);void AUD_set_active_out (SWVoiceOut *sw,int on);int AUD_is_active_out (SWVoiceOut *sw);
@@ -133,7 +133,7 @@ SWVoiceIn *AUD_open_in ( );void AUD_close_in (QEMUSoundCard *card,SWVoiceIn *sw); -int AUD_read (SWVoiceIn *sw,void *pcm_buf,int size); +size_t AUD_read (SWVoiceIn *sw,void *pcm_buf,size_t size);void AUD_set_active_in (SWVoiceIn *sw,int on);int AUD_is_active_in (SWVoiceIn *sw);
audio/audio_int.h +13 -13
@@ -60,12 +60,12 @@ typedef struct HWVoiceOut {f_sample *clip; -int rpos; +size_t rpos;uint64_t ts_helper;struct st_sample *mix_buf; -int samples; +size_t samples; QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head; QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;int ctl_caps;
@@ -81,13 +81,13 @@ typedef struct HWVoiceIn {t_sample *conv; -int wpos; -int total_samples_captured; +size_t wpos; +size_t total_samples_captured;uint64_t ts_helper;struct st_sample *conv_buf; -int samples; +size_t samples; QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;int ctl_caps;struct audio_pcm_ops *pcm_ops;
@@ -102,7 +102,7 @@ struct SWVoiceOut {int64_t ratio;struct st_sample *buf;void *rate; -int total_hw_samples_mixed; +size_t total_hw_samples_mixed;int active;int empty;HWVoiceOut *hw;
@@ -119,7 +119,7 @@ struct SWVoiceIn {struct audio_pcm_info info;int64_t ratio;void *rate; -int total_hw_samples_acquired; +size_t total_hw_samples_acquired;struct st_sample *buf;f_sample *clip;HWVoiceIn *hw;
@@ -148,12 +148,12 @@ struct audio_driver {struct audio_pcm_ops {int (*init_out)(HWVoiceOut *hw,struct audsettings *as,void *drv_opaque);void (*fini_out)(HWVoiceOut *hw); -int (*run_out) (HWVoiceOut *hw,int live); +size_t (*run_out)(HWVoiceOut *hw,size_t live);int (*ctl_out) (HWVoiceOut *hw,int cmd, ...);int (*init_in) (HWVoiceIn *hw,struct audsettings *as,void *drv_opaque);void (*fini_in) (HWVoiceIn *hw); -int (*run_in) (HWVoiceIn *hw); +size_t (*run_in)(HWVoiceIn *hw);int (*ctl_in) (HWVoiceIn *hw,int cmd, ...); };
@@ -207,10 +207,10 @@ audio_driver *audio_driver_lookup(const char *name);void audio_pcm_init_info (struct audio_pcm_info *info,struct audsettings *as);void audio_pcm_info_clear_buf (struct audio_pcm_info *info,void *buf,int len); -int audio_pcm_hw_get_live_in (HWVoiceIn *hw); +size_t audio_pcm_hw_get_live_in (HWVoiceIn *hw); -int audio_pcm_hw_clip_out (HWVoiceOut *hw,void *pcm_buf, -int live,int pending); +size_t audio_pcm_hw_clip_out (HWVoiceOut *hw,void *pcm_buf, +size_t live,size_t pending);int audio_bug (const char *funcname,int cond);void *audio_calloc (const char *funcname,int nmemb,size_t size);
@@ -223,7 +223,7 @@ void audio_run(AudioState *s, const char *msg);#define VOICE_VOLUME_CAP (1 << VOICE_VOLUME) -static inline int audio_ring_dist (int dst,int src,int len) +static inline size_t audio_ring_dist (size_t dst,size_t src,size_t len) {return (dst >= src) ? (dst - src) : (len - src + dst); }
audio/audio_template.h +7 -7
@@ -75,16 +75,16 @@ static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)HWBUF =NULL ; } -static int glue (audio_pcm_hw_alloc_resources_ ,TYPE ) (HW *hw) +static bool glue (audio_pcm_hw_alloc_resources_ ,TYPE )(HW *hw) {HWBUF =audio_calloc (__func__, hw->samples,sizeof (struct st_sample ));if (!HWBUF ) { -dolog ("Could not allocate " NAME " buffer (%d samples)\n" , - hw->samples); -return -1 ; +dolog ("Could not allocate " NAME " buffer (%zu samples)\n" , + hw->samples); +return false; } -return 0 ; +return true; }static void glue (audio_pcm_sw_free_resources_ ,TYPE ) (SW *sw)
@@ -265,7 +265,7 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s, }if (audio_bug (__func__, hw->samples <=0 )) { -dolog ("hw->samples=%d\n" , hw->samples); +dolog ("hw->samples=%zd\n" , hw->samples); goto err1; }
@@ -279,7 +279,7 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s, [hw->info.swap_endianness] [audio_bits_to_index (hw->info.bits)]; -if (glue (audio_pcm_hw_alloc_resources_,TYPE ) (hw)) { +if (!glue (audio_pcm_hw_alloc_resources_,TYPE )(hw)) { goto err1; }
audio/mixeng.h +5 -4
@@ -33,6 +33,7 @@ struct st_sample { mixeng_real l; mixeng_real r; };struct mixeng_volume {int mute;int64_t r;int64_t l; };struct st_sample {int64_t l;int64_t r; };#endif +typedef struct st_sample st_sample ;typedef void (t_sample ) (struct st_sample *dst,const void *src,int samples);typedef void (f_sample ) (void *dst,const struct st_sample *src,int samples);
@@ -41,10 +42,10 @@ extern t_sample *mixeng_conv[2][2][2][3];extern f_sample *mixeng_clip[2 ][2 ][2 ][3 ];void *st_rate_start (int inrate,int outrate); -void st_rate_flow (void *opaque,struct st_sample *ibuf,struct st_sample *obuf, -int *isamp,int *osamp); -void st_rate_flow_mix (void *opaque,struct st_sample *ibuf,struct st_sample *obuf, -int *isamp,int *osamp); +void st_rate_flow (void *opaque,st_sample *ibuf,st_sample *obuf, +size_t *isamp,size_t *osamp); +void st_rate_flow_mix (void *opaque,st_sample *ibuf,st_sample *obuf, +size_t *isamp,size_t *osamp);void st_rate_stop (void *opaque);void mixeng_clear (struct st_sample *buf,int len);void mixeng_volume (struct st_sample *buf,int len,struct mixeng_volume *vol);
audio/rate_template.h +1 -1
@@ -28,7 +28,7 @@* Return number of samples processed. */ void NAME (void *opaque,struct st_sample *ibuf,struct st_sample *obuf, -int *isamp,int *osamp) +size_t *isamp,size_t *osamp) {struct rate *rate = opaque;struct st_sample *istart, *iend;
include/sysemu/replay.h +2 -2
@@ -179,9 +179,9 @@ void replay_net_packet_event(ReplayNetState *rns, unsigned flags,/* Audio */ /*! Saves/restores number of played samples of audio out operation. */ -void replay_audio_out (int *played); +void replay_audio_out (size_t *played);/*! Saves/restores recorded samples of audio in operation. */ -void replay_audio_in (int *recorded,void *samples,int *wpos,int size); +void replay_audio_in (size_t *recorded,void *samples,size_t *wpos,size_t size);/* VM state operations */
audio/alsaaudio.c +13 -13
@@ -688,10 +688,10 @@ static void alsa_write_pending (ALSAVoiceOut *alsa) } } -static int alsa_run_out (HWVoiceOut *hw,int live) +static size_t alsa_run_out (HWVoiceOut *hw,size_t live) {ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw; -int decr; +size_t decr;snd_pcm_sframes_t avail; avail =alsa_get_avail (alsa->handle);
@@ -746,8 +746,8 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as, alsa->pcm_buf =audio_calloc (__func__, obt.samples,1 << hw->info.shift);if (!alsa->pcm_buf) { -dolog ("Could not allocate DAC buffer (%d samples, each %d bytes)\n" , - hw->samples,1 << hw->info.shift); +dolog ("Could not allocate DAC buffer (%zu samples, each %d bytes)\n" , + hw->samples,1 << hw->info.shift);alsa_anal_close1 (&handle);return -1 ; }
@@ -848,8 +848,8 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) alsa->pcm_buf =audio_calloc (__func__, hw->samples,1 << hw->info.shift);if (!alsa->pcm_buf) { -dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n" , - hw->samples,1 << hw->info.shift); +dolog ("Could not allocate ADC buffer (%zu samples, each %d bytes)\n" , + hw->samples,1 << hw->info.shift);alsa_anal_close1 (&handle);return -1 ; }
@@ -870,17 +870,17 @@ static void alsa_fini_in (HWVoiceIn *hw) alsa->pcm_buf =NULL ; } -static int alsa_run_in (HWVoiceIn *hw) +static size_t alsa_run_in (HWVoiceIn *hw) {ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;int hwshift = hw->info.shift;int i; -int live =audio_pcm_hw_get_live_in (hw); -int dead = hw->samples - live; -int decr; +size_t live =audio_pcm_hw_get_live_in (hw); +size_t dead = hw->samples - live; +size_t decr;struct { -int add; -int len; +size_t add; +size_t len; } bufs[2 ] = { { .add = hw->wpos, .len =0 }, { .add =0 , .len =0 }
@@ -920,7 +920,7 @@ static int alsa_run_in (HWVoiceIn *hw) } } - decr =MIN (dead, avail); + decr =MIN (dead, avail);if (!decr) {return 0 ; }
audio/audio.c +79 -83
394 lines not on this page · raw message
audio/coreaudio.c +5 -5
@@ -43,9 +43,9 @@ typedef struct coreaudioVoiceOut {UInt32 audioDevicePropertyBufferFrameSize;AudioStreamBasicDescription outputStreamBasicDescription;AudioDeviceIOProcID ioprocid; -int live; -int decr; -int rpos; +size_t live; +size_t decr; +size_t rpos; } coreaudioVoiceOut;#if MAC_OS_X_VERSION_MAX_ALLOWED >=MAC_OS_X_VERSION_10_6
@@ -397,9 +397,9 @@ static int coreaudio_unlock (coreaudioVoiceOut *core, const char *fn_name)return 0 ; } -static int coreaudio_run_out (HWVoiceOut *hw,int live) +static size_t coreaudio_run_out (HWVoiceOut *hw,size_t live) { -int decr; +size_t decr;coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;if (coreaudio_lock (core,"coreaudio_run_out" )) {
audio/dsoundaudio.c +6 -5
@@ -454,19 +454,20 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...)return 0 ; } -static int dsound_run_out (HWVoiceOut *hw,int live) +static size_t dsound_run_out (HWVoiceOut *hw,size_t live) {int err;HRESULT hr;DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;LPDIRECTSOUNDBUFFER dsb = ds->dsound_buffer; -int len, hwshift; +size_t len; +int hwshift;DWORD blen1, blen2;DWORD len1, len2;DWORD decr;DWORD wpos, ppos, old_pos;LPVOID p1, p2; -int bufsize; +size_t bufsize;dsound *s = ds->s;AudiodevDsoundOptions *dso = &s->dev->u.dsound;
@@ -640,13 +641,13 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...)return 0 ; } -static int dsound_run_in (HWVoiceIn *hw) +static size_t dsound_run_in (HWVoiceIn *hw) {int err;HRESULT hr;DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;LPDIRECTSOUNDCAPTUREBUFFER dscb = ds->dsound_capture_buffer; -int live, len, dead; +size_t live, len, dead;DWORD blen1, blen2;DWORD len1, len2;DWORD decr;
audio/noaudio.c +8 -8
@@ -40,10 +40,10 @@ typedef struct NoVoiceIn {int64_t old_ticks; } NoVoiceIn; -static int no_run_out (HWVoiceOut *hw,int live) +static size_t no_run_out (HWVoiceOut *hw,size_t live) {NoVoiceOut *no = (NoVoiceOut *) hw; -int decr, samples; +size_t decr, samples;int64_t now;int64_t ticks;int64_t bytes;
@@ -51,7 +51,7 @@ static int no_run_out (HWVoiceOut *hw, int live) now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); ticks = now - no->old_ticks; bytes =muldiv64 (ticks, hw->info.bytes_per_second,NANOSECONDS_PER_SECOND ); - bytes =MIN (bytes,INT_MAX ); + bytes =MIN (bytes,SIZE_MAX ); samples = bytes >> hw->info.shift; no->old_ticks = now;
@@ -91,12 +91,12 @@ static void no_fini_in (HWVoiceIn *hw) (void ) hw; } -static int no_run_in (HWVoiceIn *hw) +static size_t no_run_in (HWVoiceIn *hw) {NoVoiceIn *no = (NoVoiceIn *) hw; -int live =audio_pcm_hw_get_live_in (hw); -int dead = hw->samples - live; -int samples =0 ; +size_t live =audio_pcm_hw_get_live_in (hw); +size_t dead = hw->samples - live; +size_t samples =0 ;if (dead) {int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );
@@ -105,7 +105,7 @@ static int no_run_in (HWVoiceIn *hw)muldiv64 (ticks, hw->info.bytes_per_second,NANOSECONDS_PER_SECOND ); no->old_ticks = now; - bytes =MIN (bytes,INT_MAX ); + bytes =MIN (bytes,SIZE_MAX ); samples = bytes >> hw->info.shift; samples =MIN (samples, dead); }
audio/ossaudio.c +23 -22
110 lines not on this page · raw message
audio/paaudio.c +22 -22
114 lines not on this page · raw message
audio/sdlaudio.c +9 -10
@@ -42,11 +42,11 @@typedef struct SDLVoiceOut {HWVoiceOut hw; -int live; +size_t live;#if USE_SEMAPHORE -int rpos; +size_t rpos;#endif -int decr; +size_t decr; }SDLVoiceOut ; static struct SDLAudioState {
@@ -252,14 +252,14 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)SDLVoiceOut *sdl = opaque;SDLAudioState *s = &glob_sdl;HWVoiceOut *hw = &sdl->hw; -int samples = len >> hw->info.shift; +size_t samples = len >> hw->info.shift;if (s->exit) {return ; }while (samples) { -int to_mix, decr; +size_t to_mix, decr;/* dolog ("in callback samples=%d\n", samples); */ #if USE_SEMAPHORE
@@ -273,8 +273,7 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len) }if (audio_bug (__func__, sdl->live <0 || sdl->live > hw->samples)) { -dolog ("sdl->live=%d hw->samples=%d\n" , - sdl->live, hw->samples); +dolog ("sdl->live=%d hw->samples=%zu\n" , sdl->live, hw->samples);return ; }
@@ -291,7 +290,7 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len) to_mix =MIN (samples, sdl->live); decr = to_mix;while (to_mix) { -int chunk =MIN (to_mix, hw->samples - hw->rpos); +size_t chunk =MIN (to_mix, hw->samples - hw->rpos);struct st_sample *src = hw->mix_buf + hw->rpos;/* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
@@ -325,9 +324,9 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)#endif } -static int sdl_run_out (HWVoiceOut *hw,int live) +static size_t sdl_run_out (HWVoiceOut *hw,size_t live) { -int decr; +size_t decr;SDLVoiceOut *sdl = (SDLVoiceOut *) hw;SDLAudioState *s = &glob_sdl;
audio/spiceaudio.c +6 -6
@@ -152,11 +152,11 @@ static void line_out_fini (HWVoiceOut *hw)spice_server_remove_interface (&out->sin.base); } -static int line_out_run (HWVoiceOut *hw,int live) +static size_t line_out_run (HWVoiceOut *hw,size_t live) {SpiceVoiceOut *out =container_of (hw, SpiceVoiceOut, hw); -int rpos, decr; -int samples; +size_t rpos, decr; +size_t samples;if (!live) {return 0 ;
@@ -275,12 +275,12 @@ static void line_in_fini (HWVoiceIn *hw)spice_server_remove_interface (&in->sin.base); } -static int line_in_run (HWVoiceIn *hw) +static size_t line_in_run (HWVoiceIn *hw) {SpiceVoiceIn *in =container_of (hw, SpiceVoiceIn, hw); -int num_samples; +size_t num_samples;int ready; -int len[2 ]; +size_t len[2 ];uint64_t delta_samp;const uint32_t *samples;
audio/wavaudio.c +4 -4
@@ -38,10 +38,10 @@ typedef struct WAVVoiceOut {int total_samples; } WAVVoiceOut; -static int wav_run_out (HWVoiceOut *hw,int live) +static size_t wav_run_out (HWVoiceOut *hw,size_t live) {WAVVoiceOut *wav = (WAVVoiceOut *) hw; -int rpos, decr, samples; +size_t rpos, decr, samples;uint8_t *dst;struct st_sample *src;int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );
@@ -137,8 +137,8 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as, hw->samples =1024 ; wav->pcm_buf =audio_calloc (__func__, hw->samples,1 << hw->info.shift);if (!wav->pcm_buf) { -dolog ("Could not allocate buffer (%d bytes)\n" , - hw->samples << hw->info.shift); +dolog ("Could not allocate buffer (%zu bytes)\n" , + hw->samples << hw->info.shift);return -1 ; }
replay/replay-audio.c +8 -8
@@ -16,18 +16,18 @@#include "sysemu/sysemu.h" #include "audio/audio.h" -void replay_audio_out (int *played) +void replay_audio_out (size_t *played) {if (replay_mode ==REPLAY_MODE_RECORD ) {g_assert (replay_mutex_locked ());replay_save_instructions ();replay_put_event (EVENT_AUDIO_OUT ); -replay_put_dword (*played); +replay_put_qword (*played); }else if (replay_mode ==REPLAY_MODE_PLAY ) {g_assert (replay_mutex_locked ());replay_account_executed_instructions ();if (replay_next_event_is (EVENT_AUDIO_OUT )) { - *played =replay_get_dword (); + *played =replay_get_qword ();replay_finish_event (); }else {error_report ("Missing audio out event in the replay log" );
@@ -36,7 +36,7 @@ void replay_audio_out(int *played) } } -void replay_audio_in (int *recorded,void *samples,int *wpos,int size) +void replay_audio_in (size_t *recorded,void *samples,size_t *wpos,size_t size) {int pos;uint64_t left, right;
@@ -44,8 +44,8 @@ void replay_audio_in(int *recorded, void *samples, int *wpos, int size)g_assert (replay_mutex_locked ());replay_save_instructions ();replay_put_event (EVENT_AUDIO_IN ); -replay_put_dword (*recorded); -replay_put_dword (*wpos); +replay_put_qword (*recorded); +replay_put_qword (*wpos);for (pos = (*wpos - *recorded + size) % size ; pos != *wpos ; pos = (pos +1 ) % size) {audio_sample_to_uint64 (samples, pos, &left, &right);
@@ -56,8 +56,8 @@ void replay_audio_in(int *recorded, void *samples, int *wpos, int size)g_assert (replay_mutex_locked ());replay_account_executed_instructions ();if (replay_next_event_is (EVENT_AUDIO_IN )) { - *recorded =replay_get_dword (); - *wpos =replay_get_dword (); + *recorded =replay_get_qword (); + *wpos =replay_get_qword ();for (pos = (*wpos - *recorded + size) % size ; pos != *wpos ; pos = (pos +1 ) % size) { left =replay_get_qword ();
replay/replay.c +1 -1
@@ -22,7 +22,7 @@/* Current version of the replay mechanism. Increase it when file format changes. */ -#define REPLAY_VERSION 0xe02007 +#define REPLAY_VERSION 0xe02008/* Size of replay log header */ #define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t))
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v3 20/50] paaudio: properly disconnect streams in fini_*
In reply to Kővágó, ZoltánHi
Quoted 15 lines · Zoltán
Currently this needs a workaround due to bug #74624 in pulseaudio.
Reviewed-by Marc-André Lureau <[email protected]>Signed-off-by Kővágó, Zoltán <[email protected]>--- audio/paaudio.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)audio/paaudio.c +0
-0@@ -680,6 +680,27 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)return -1 ;
audio/paaudio.c static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) · line 690
Quoted 10 lines
audio/paaudio.c +8
-0} +static void qpa_simple_disconnect (PAConnection *c,pa_stream *stream) +{ +int err; + +pa_threaded_mainloop_lock (c->mainloop); +/* +* wait until actually connects. workaround pa bug #74624 +* https://bugs.freedesktop.org/show_bug.cgi?id=74624
Now that they moved to gitlab, you could update the link & # in commit message
https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/247
Quoted 37 lines
audio/paaudio.c +15
-3+*/ +while (pa_stream_get_state (stream) ==PA_STREAM_CREATING ) { +pa_threaded_mainloop_wait (c->mainloop); + } + + err =pa_stream_disconnect (stream); +if (err !=0 ) { +dolog ("Failed to dissconnect! err=%d\n" , err); + } +pa_stream_unref (stream); +pa_threaded_mainloop_unlock (c->mainloop); +} +static void qpa_fini_out (HWVoiceOut *hw) {void *ret;@@ -691,7 +712,7 @@ static void qpa_fini_out (HWVoiceOut *hw)audio_pt_join (&pa->pt, &ret, __func__);if (pa->stream) { -pa_stream_unref (pa->stream); +qpa_simple_disconnect (pa->g->conn, pa->stream); pa->stream =NULL ; }@@ -711,7 +732,7 @@ static void qpa_fini_in (HWVoiceIn *hw)audio_pt_join (&pa->pt, &ret, __func__);if (pa->stream) { -pa_stream_unref (pa->stream); +qpa_simple_disconnect (pa->g->conn, pa->stream); pa->stream =NULL ; } --2.20.1
Re: [Qemu-devel] [PATCH v3 01/50] qapi: qapi for audio backends
In reply to Kővágó, ZoltánHi,
Quoted 25 lines
qapi/audio.json new file +25
-0+## +# @AudiodevAlsaPerDirectionOptions: +# +# Options of the alsa backend that are used for both playback and recording. +# +# @dev: the name of the alsa device to use (default 'default') +# +# @try-poll: attempt to use poll mode, falling back to non polling access on +# failure (default on) +# +# Since: 4.0 +## +{ 'struct': 'AudiodevAlsaPerDirectionOptions', + 'data': { + '*dev': 'str', + '*try-poll': 'bool' } } + +## +# @AudiodevAlsaOptions: +# +# Options of the alsa audio backend. +# +# @alsa-in: options of the capture stream +# +# @alsa-out: options of the playback stream
qapi/audio.json line 42
Quoted 10 lines
qapi/audio.json new file +10
-0+# +# @threshold: set the threshold (in microseconds) when playback starts +# +# Since: 4.0 +## +{ 'struct': 'AudiodevAlsaOptions', + 'data': { + '*alsa-in': 'AudiodevAlsaPerDirectionOptions', + '*alsa-out': 'AudiodevAlsaPerDirectionOptions', + '*threshold': 'uint32' } }
Hmm, do we need try-poll as per-direction option? If not we could simplify AudiodevAlsaOptions this way ...
{ 'struct': 'AudiodevAlsaOptions',
'data': {
'*dev-in': 'str',
'*dev-out': 'str',
'*threshold': 'uint32'
'*try-poll': 'bool' } }... eliminating some nesting.
Quoted 6 lines
qapi/audio.json new file +6
-0+## +# @AudiodevOssPerDirectionOptions: +# +# Options of the oss backend that are used for both playback and recording. +# +# @dev: file name of the oss device (default '/dev/dsp')
qapi/audio.json line 72
Quoted 10 lines
qapi/audio.json new file +10
-0+# +# @try-poll: attempt to use poll mode, falling back to non polling access on +# failure (default on) +# +# Since: 4.0 +## +{ 'struct': 'AudiodevOssPerDirectionOptions', + 'data': { + '*dev': 'str', + '*try-poll': 'bool' } }
Same here.
Quoted 8 lines
qapi/audio.json new file +8
-0+## +# @AudiodevPaOptions: +# +# Options of the pa (PulseAudio) audio backend. +# +# @server: PulseAudio server address (default: let PulseAudio choose) +# +# @sink: name of the sink to use
qapi/audio.json line 133
Quoted 10 lines
qapi/audio.json new file +10
-0+# +# @source: name of the source to use +# +# Since: 4.0 +## +{ 'struct': 'AudiodevPaOptions', + 'data': { + '*server': 'str', + '*sink': 'AudiodevPaPerDirectionOptions', + '*source': 'AudiodevPaPerDirectionOptions' } }
AudiodevPaPerDirectionOptions has only the name field, so we can drop the struct and just use '*sink' : 'str' ...
cheers,
Gerd
Re: [Qemu-devel] [PATCH v3 15/50] audio: reduce glob_audio_state usage
In reply to Kővágó, ZoltánQuoted 9 lines · Zoltán
Remove
glob_audio_statefrom functions, where possible without breaking the API. This means that most static functions inaudio.cnow take an AudioState pointer instead of implicitly usingglob_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).
I think it makes sense to split the series into smaller pieces, here would be a good place for the split (i.e. patches 1-14 which introduce -audiodev will be the first batch, this patch starts the next batch).
Quoted 403 lines
Signed-off-by Kővágó, Zoltán <[email protected]>--- audio/audio_int.h | 7 +++++ audio/audio_template.h | 46 ++++++++++++++++---------------- audio/audio.c | 59 +++++++++++++++++++----------------------- 3 files changed, 56 insertions(+), 56 deletions(-)audio/audio_int.h +7
-0@@ -52,6 +52,7 @@ struct audio_pcm_info {typedef struct SWVoiceCap SWVoiceCap ; typedef struct HWVoiceOut { + AudioState *s; int enabled; int poll_mode; int pending_disable;@@ -73,6 +74,7 @@ typedef struct HWVoiceOut { } HWVoiceOut; typedef struct HWVoiceIn { + AudioState *s; int enabled; int poll_mode; struct audio_pcm_info info;@@ -94,6 +96,7 @@ typedef struct HWVoiceIn {struct SWVoiceOut {QEMUSoundCard *card; +AudioState *s;struct audio_pcm_info info;t_sample *conv;int64_t ratio;@@ -111,6 +114,7 @@ struct SWVoiceOut {struct SWVoiceIn {QEMUSoundCard *card; +AudioState *s;int active;struct audio_pcm_info info;int64_t ratio;@@ -188,6 +192,9 @@ struct AudioState {int nb_hw_voices_in;int vm_running;int64_t period_ticks; + +bool timer_running; +uint64_t timer_last; };extern const struct mixeng_volume nominal_volume;audio/audio_template.h +22
-24@@ -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 ;audio/audio.c +27
-32@@ -397,12 +397,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)) {@@ -479,7 +477,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);@@ -792,19 +790,15 @@ static void audio_pcm_print_info (const char *cap, struct audio_pcm_info *info)/* * Timer */ - -static bool audio_timer_running; -static uint64_t audio_timer_last; - -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 ;@@ -812,18 +806,18 @@ 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_anticipate_ns (s->ts,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + s->period_ticks); -if (!audio_timer_running) { - audio_timer_running = true; - audio_timer_last =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +if (!s->timer_running) { + s->timer_running = true; + s->timer_last =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );trace_audio_timer_start (s->period_ticks /SCALE_MS ); } }else {timer_del (s->ts); -if (audio_timer_running) { - audio_timer_running = false; +if (s->timer_running) { + s->timer_running = false;trace_audio_timer_stop (); } }@@ -835,11 +829,11 @@ static void audio_timer (void *opaque)AudioState *s = opaque; now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); - diff = now - audio_timer_last; + diff = now - s->timer_last;if (diff > s->period_ticks *3 /2 ) {trace_audio_timer_delayed (diff /SCALE_MS ); } - audio_timer_last = now; + s->timer_last = now;audio_run ("timer" );audio_reset_timer (s);@@ -893,7 +887,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;@@ -940,7 +934,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) {@@ -1063,7 +1057,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;@@ -1168,7 +1162,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 =0 , min;@@ -1274,8 +1268,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 ; }@@ -1294,11 +1288,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);@@ -1318,7 +1312,7 @@ void audio_cleanup(void)HWVoiceIn *hwi, *hwin; is_cleaning_up = true; - QLIST_FOREACH_SAFE(hwo, &glob_audio_state.hw_head_out, entries, hwon) { + QLIST_FOREACH_SAFE(hwo, &s->hw_head_out, entries, hwon) {SWVoiceCap *sc;if (hwo->enabled) {@@ -1337,7 +1331,7 @@ void audio_cleanup(void)QLIST_REMOVE (hwo, entries); } - QLIST_FOREACH_SAFE(hwi, &glob_audio_state.hw_head_in, entries, hwin) { + QLIST_FOREACH_SAFE(hwi, &s->hw_head_in, entries, hwin) {if (hwi->enabled) { hwi->pcm_ops->ctl_in (hwi,VOICE_DISABLE ); }@@ -1537,7 +1531,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;@@ -1554,6 +1548,7 @@ CaptureVoiceOut *AUD_add_capture ( } hw = &cap->hw; + hw->s = s;QLIST_INIT (&hw->sw_head);QLIST_INIT (&cap->cb_head);@@ -1586,7 +1581,7 @@ CaptureVoiceOut *AUD_add_capture (QLIST_INSERT_HEAD (&s->cap_head, cap, entries);QLIST_INSERT_HEAD (&cap->cb_head, cb, entries); - QLIST_FOREACH(hw, &glob_audio_state.hw_head_out, entries) { + QLIST_FOREACH(hw, &s->hw_head_out, entries) {audio_attach_capture (hw); }return cap;Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v3 18/50] audio: audiodev= parameters no longer optional when -audiodev present
In reply to Kővágó, ZoltánQuoted 6 lines · Zoltán
This means you should probably stop using -soundhw (as it doesn't allow you to specify any options) and add the device manually with -device. The exception is pcspk, it's currently not possible to manually add it. To use it with audiodev, use something like this:
-audiodev id=foo,... -global isa-pcspk.audiodev=foo -soundhw pcspk
Fixing that doesn't look hard ...
cheers,
Gerd
Quoted 1 line
From
da41ae92d8da846ca363757e201993d35b74a669Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <[email protected]>
Date: Thu, 17 Jan 2019 10:39:17 +0100
Subject: [PATCH] audio: fix pc speaker init
--- hw/audio/pcspk.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)
hw/audio/pcspk.c +15 -20
@@ -57,7 +57,6 @@ typedef struct { } PCSpkState;static const char *s_spk ="pcspk" ; -static PCSpkState *pcspk_state;static inline void generate_samples (PCSpkState *s) {
@@ -111,22 +110,6 @@ static void pcspk_callback(void *opaque, int free) } } -static int pcspk_audio_init (ISABus *bus) -{ -PCSpkState *s = pcspk_state; -struct audsettings as = {PCSPK_SAMPLE_RATE ,1 ,AUD_FMT_U8 ,0 }; - -AUD_register_card (s_spk, &s->card); - - s->voice =AUD_open_out (&s->card, s->voice, s_spk, s, pcspk_callback, &as); -if (!s->voice) { -AUD_log (s_spk,"Could not open voice\n" ); -return -1 ; - } - -return 0 ; -} -static uint64_t pcspk_io_read (void *opaque,hwaddr addr,unsigned size) {
@@ -179,12 +162,20 @@ static void pcspk_initfn(Object *obj)static void pcspk_realizefn (DeviceState *dev,Error **errp) { +struct audsettings as = {PCSPK_SAMPLE_RATE ,1 ,AUD_FMT_U8 ,0 };ISADevice *isadev =ISA_DEVICE (dev);PCSpkState *s =PC_SPEAKER (dev);isa_register_ioport (isadev, &s->ioport, s->iobase); - pcspk_state = s; +AUD_register_card (s_spk, &s->card); + + s->voice =AUD_open_out (&s->card, s->voice, s_spk, s, pcspk_callback, &as); +if (!s->voice) { +error_setg (errp,"Initializing audio voice failed" ); +AUD_remove_card (&s->card); +return ; + } }static bool migrate_needed (void *opaque)
@@ -221,8 +212,6 @@ static void pcspk_class_initfn(ObjectClass *klass, void *data)set_bit (DEVICE_CATEGORY_SOUND , dc->categories); dc->vmsd = &vmstate_spk; dc->props = pcspk_properties; -/* Reason: realize sets global pcspk_state */ - dc->user_creatable = false; }static const TypeInfo pcspk_info = {
@@ -233,6 +222,12 @@ static const TypeInfo pcspk_info = { .class_init = pcspk_class_initfn, }; +static int pcspk_audio_init (ISABus *bus) +{ +isa_create_simple (bus,TYPE_PC_SPEAKER ); +return 0 ; +} +static void pcspk_register (void ) {type_register_static (&pcspk_info);
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH v3 18/50] audio: audiodev= parameters no longer optional when -audiodev present
In reply to Kővágó, ZoltánQuoted 11 lines · Zoltán
This means you should probably stop using -soundhw (as it doesn't allow you to specify any options) and add the device manually with -device. The exception is pcspk, it's currently not possible to manually add it. To use it with audiodev, use something like this:
-audiodev id=foo,... -global isa-pcspk.audiodev=foo -soundhw pcspk
Signed-off-by Kővágó, Zoltán <[email protected]>--- audio/audio.c | 24 ++-- audio/paaudio.c | 304 ++++++++++++++++++++++++++++--------------------
Hmm, the big paaudio chunk looks suspicious ...
cheers,
Gerd
Re: [Qemu-devel] [PATCH v3 26/50] audio: api for mixeng code free backends
In reply to Kővágó, ZoltánQuoted 1 line · Zoltán
Signed-off-by Kővágó, Zoltán <[email protected]>
The mixeng patches could go to a separate series too.
cheers,
Gerd
Re: [Qemu-devel] [PATCH v3 47/50] paaudio: channel-map option
In reply to Kővágó, ZoltánQuoted 17 lines · Zoltán
Add an option to change the channel map used by pulseaudio. If not specified, falls back to an OSS compatible channel map.
Signed-off-by Kővágó, Zoltán <[email protected]>--- qapi/audio.json | 5 ++++- audio/paaudio.c | 18 ++++++++++++++---- qemu-options.hx | 9 +++++++++ 3 files changed, 27 insertions(+), 5 deletions(-)qapi/audio.json +0
-0@@ -107,11 +107,14 @@ # # @name: name of the sink/source to use
qapi/audio.json line 117
Quoted 10 lines
qapi/audio.json +4
-1# +# @channel-map: channel map to use (default: OSS compatible map) +# # Since: 4.0 ## { 'struct': 'AudiodevPaPerDirectionOptions', 'data': { - '*name': 'str' } } + '*name': 'str', + '*channel-map': 'str' } }
Ah, I see. Thats why patch #1 creates a AudiodevPaPerDirectionOptions struct with just one field ...
cheers,
Gerd
Re: [Qemu-devel] [PATCH v3 47/50] paaudio: channel-map option
Quoted 23 lines · Gerd Hoffmann
Quoted 22 lines · Zoltán
Add an option to change the channel map used by pulseaudio. If not specified, falls back to an OSS compatible channel map.
Signed-off-by Kővágó, Zoltán <[email protected]>--- qapi/audio.json | 5 ++++- audio/paaudio.c | 18 ++++++++++++++---- qemu-options.hx | 9 +++++++++ 3 files changed, 27 insertions(+), 5 deletions(-)qapi/audio.json +2
-0@@ -107,11 +107,14 @@ # # @name: name of the sink/source to use # +# @channel-map: channel map to use (default: OSS compatible map) +# # Since: 4.0 ##
Quoted 8 lines
qapi/audio.json line 117
Quoted 5 lines
qapi/audio.json +2
-1{ 'struct': 'AudiodevPaPerDirectionOptions', 'data': { - '*name': 'str' } } + '*name': 'str', + '*channel-map': 'str' } }Ah, I see. Thats why patch #1 creates a AudiodevPaPerDirectionOptions struct with just one field ...
Yes, I was bitten by it too during a refactor, probably I should write a few words about it in the commit message.
However, this is the exact reason I'd recommend nested structs instead of randomly flattening it when we can. This way, if we later have to add an extra option, we don't end up in a problematic situation, since we can't easily change things like 'dev-in' to a structure without breaking backward compatibility.
Regards,
Zoltan
Re: [Qemu-devel] [PATCH v3 15/50] audio: reduce glob_audio_state usage
In reply to Gerd HoffmannQuoted 8 lines · Gerd Hoffmann
Quoted 7 lines · Zoltán
Remove
glob_audio_statefrom functions, where possible without breaking the API. This means that most static functions inaudio.cnow take an AudioState pointer instead of implicitly usingglob_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.
Quoted 6 lines
Quoted 2 lines
This is required in order to support multiple simultaneous audio backends (added in a later commit).
I think it makes sense to split the series into smaller pieces, here would be a good place for the split (i.e. patches 1-14 which introduce -audiodev will be the first batch, this patch starts the next batch).
Alright, I think this series is pretty useless without at least the multiple simultaneous backends part, but if it's easier to review in smaller chunks, let's do it.
Quoted 404 lines
Quoted 404 lines
Signed-off-by Kővágó, Zoltán <[email protected]>--- audio/audio_int.h | 7 +++++ audio/audio_template.h | 46 ++++++++++++++++---------------- audio/audio.c | 59 +++++++++++++++++++----------------------- 3 files changed, 56 insertions(+), 56 deletions(-)audio/audio_int.h +7
-0@@ -52,6 +52,7 @@ struct audio_pcm_info {typedef struct SWVoiceCap SWVoiceCap ; typedef struct HWVoiceOut { + AudioState *s; int enabled; int poll_mode; int pending_disable;@@ -73,6 +74,7 @@ typedef struct HWVoiceOut { } HWVoiceOut; typedef struct HWVoiceIn { + AudioState *s; int enabled; int poll_mode; struct audio_pcm_info info;@@ -94,6 +96,7 @@ typedef struct HWVoiceIn {struct SWVoiceOut {QEMUSoundCard *card; +AudioState *s;struct audio_pcm_info info;t_sample *conv;int64_t ratio;@@ -111,6 +114,7 @@ struct SWVoiceOut {struct SWVoiceIn {QEMUSoundCard *card; +AudioState *s;int active;struct audio_pcm_info info;int64_t ratio;@@ -188,6 +192,9 @@ struct AudioState {int nb_hw_voices_in;int vm_running;int64_t period_ticks; + +bool timer_running; +uint64_t timer_last; };extern const struct mixeng_volume nominal_volume;audio/audio_template.h +22
-24@@ -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 ;audio/audio.c +27
-32@@ -397,12 +397,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)) {@@ -479,7 +477,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);@@ -792,19 +790,15 @@ static void audio_pcm_print_info (const char *cap, struct audio_pcm_info *info)/* * Timer */ - -static bool audio_timer_running; -static uint64_t audio_timer_last; - -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 ;@@ -812,18 +806,18 @@ 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_anticipate_ns (s->ts,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + s->period_ticks); -if (!audio_timer_running) { - audio_timer_running = true; - audio_timer_last =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +if (!s->timer_running) { + s->timer_running = true; + s->timer_last =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );trace_audio_timer_start (s->period_ticks /SCALE_MS ); } }else {timer_del (s->ts); -if (audio_timer_running) { - audio_timer_running = false; +if (s->timer_running) { + s->timer_running = false;trace_audio_timer_stop (); } }@@ -835,11 +829,11 @@ static void audio_timer (void *opaque)AudioState *s = opaque; now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); - diff = now - audio_timer_last; + diff = now - s->timer_last;if (diff > s->period_ticks *3 /2 ) {trace_audio_timer_delayed (diff /SCALE_MS ); } - audio_timer_last = now; + s->timer_last = now;audio_run ("timer" );audio_reset_timer (s);@@ -893,7 +887,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;@@ -940,7 +934,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) {@@ -1063,7 +1057,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;@@ -1168,7 +1162,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 =0 , min;@@ -1274,8 +1268,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 ; }@@ -1294,11 +1288,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);@@ -1318,7 +1312,7 @@ void audio_cleanup(void)HWVoiceIn *hwi, *hwin; is_cleaning_up = true; - QLIST_FOREACH_SAFE(hwo, &glob_audio_state.hw_head_out, entries, hwon) { + QLIST_FOREACH_SAFE(hwo, &s->hw_head_out, entries, hwon) {SWVoiceCap *sc;if (hwo->enabled) {@@ -1337,7 +1331,7 @@ void audio_cleanup(void)QLIST_REMOVE (hwo, entries); } - QLIST_FOREACH_SAFE(hwi, &glob_audio_state.hw_head_in, entries, hwin) { + QLIST_FOREACH_SAFE(hwi, &s->hw_head_in, entries, hwin) {if (hwi->enabled) { hwi->pcm_ops->ctl_in (hwi,VOICE_DISABLE ); }@@ -1537,7 +1531,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;@@ -1554,6 +1548,7 @@ CaptureVoiceOut *AUD_add_capture ( } hw = &cap->hw; + hw->s = s;QLIST_INIT (&hw->sw_head);QLIST_INIT (&cap->cb_head);@@ -1586,7 +1581,7 @@ CaptureVoiceOut *AUD_add_capture (QLIST_INSERT_HEAD (&s->cap_head, cap, entries);QLIST_INSERT_HEAD (&cap->cb_head, cb, entries); - QLIST_FOREACH(hw, &glob_audio_state.hw_head_out, entries) { + QLIST_FOREACH(hw, &s->hw_head_out, entries) {audio_attach_capture (hw); }return cap;Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v3 47/50] paaudio: channel-map option
In reply to Zoltán KővágóQuoted 11 lines · Zoltán Kővágó
Quoted 8 lines
qapi/audio.json line 117
Quoted 5 lines
{ 'struct': 'AudiodevPaPerDirectionOptions',
'data': {qapi/audio.json +2
-1- '*name': 'str' } } + '*name': 'str', + '*channel-map': 'str' } }Ah, I see. Thats why patch #1 creates a AudiodevPaPerDirectionOptions struct with just one field ...
Yes, I was bitten by it too during a refactor, probably I should write a few words about it in the commit message.
Yes, a good commit message tries to anticipate the questions the reviewer will ask. The "what" is easy to see (read the patch), but the "why" is the one that determines whether the patch is worth including.
Quoted 6 lines
However, this is the exact reason I'd recommend nested structs instead of randomly flattening it when we can. This way, if we later have to add an extra option, we don't end up in a problematic situation, since we can't easily change things like 'dev-in' to a structure without breaking backward compatibility.
We can support QAPI Alternates, accepting either a string or a struct for a given member name like 'dev-in'. Admittedly, it's a bit harder to write C code interfacing with a QAPI alternate type, but at least it is possible and allows for back-compatibility. Then again, getting the struct right in the first place is even nicer than having to make back-compat tweaks.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v3 15/50] audio: reduce glob_audio_state usage
In reply to Zoltán KővágóQuoted 12 lines · Zoltán Kővágó
Quoted 11 lines · Gerd Hoffmann
Quoted 9 lines · Zoltán
Remove
glob_audio_statefrom functions, where possible without breaking the API. This means that most static functions inaudio.cnow take an AudioState pointer instead of implicitly usingglob_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).
Quoted 7 lines
Quoted 3 lines
I think it makes sense to split the series into smaller pieces, here would be a good place for the split (i.e. patches 1-14 which introduce -audiodev will be the first batch, this patch starts the next batch).
Alright, I think this series is pretty useless without at least the multiple simultaneous backends part, but if it's easier to review in smaller chunks, let's do it.
Also start merging stuff even though later in the series there are still open issues to be tackled (coreaudio breaking for example).
So, I think with the first part the only open issue is whenever we go with the nested types (i.e. patch #1 as-is) or not. Given that the one-element-structs added in that patch will get additional fields I think the nesting makes sense.
cheers,
Gerd
Re: [Qemu-devel] [PATCH v3 15/50] audio: reduce glob_audio_state usage
Hi,
Quoted 4 lines
So, I think with the first part the only open issue is whenever we go with the nested types (i.e. patch #1 as-is) or not. Given that the one-element-structs added in that patch will get additional fields I think the nesting makes sense.
Spoke too soon: scripts/checkpatch.pl flags a bunch of codestyle issues.
cheers,
Gerd
Re: [Qemu-devel] [PATCH v3 15/50] audio: reduce glob_audio_state usage
Quoted 9 lines · Gerd Hoffmann
Hi,
Quoted 4 lines
So, I think with the first part the only open issue is whenever we go with the nested types (i.e. patch #1 as-is) or not. Given that the one-element-structs added in that patch will get additional fields I think the nesting makes sense.
Spoke too soon:
scripts/checkpatch.plflags a bunch of codestyle issues.
Most of them are about the code style of the old audio subsystem, I fixed some of them but not everything. IIRC last time it wasn't a problem, but it was in 2015. Should I go over them again and fix all of them?
Regards,
Zoltan
Re: [Qemu-devel] [PATCH v3 15/50] audio: reduce glob_audio_state usage
Quoted 8 lines · Zoltán Kővágó
Quoted 7 lines · Gerd Hoffmann
Hi,
Quoted 4 lines
So, I think with the first part the only open issue is whenever we go with the nested types (i.e. patch #1 as-is) or not. Given that the one-element-structs added in that patch will get additional fields I think the nesting makes sense.
Quoted 6 lines
Quoted 1 line
Spoke too soon:
scripts/checkpatch.plflags a bunch of codestyle issues.Most of them are about the code style of the old audio subsystem, I fixed some of them but not everything. IIRC last time it wasn't a problem, but it was in 2015. Should I go over them again and fix all of them?
The first ones I saw where not a old audio codestyle (which is whitespace-after-function-name mostly) issues but newly introduced ones. A few rules have been added since 2015.
Fixing the existing issues due to old audio code style (when changing/moving code) is fine, but not required. Newly added code should follow usual qemu code style.
cheers,
Gerd