Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
audio: Make audio optional and configurable
Browse files Browse the repository at this point in the history
CONFIG_AUDIO is now the top-level AUDIO configuration knob, and is
disabled through a new --disable-audio configure option.
By default it is enabled.

When disabled, all the hw/audio and audio/ code is replaced with a pair
of audio stub files.

Signed-off-by: Yang Zhong <yang.zhong@intel.com>
  • Loading branch information
yangzhon authored and rbradford committed Dec 13, 2018
1 parent d2eaca1 commit 46c16a9
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 59 deletions.
10 changes: 9 additions & 1 deletion audio/Makefile.objs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
common-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
ifeq ($(CONFIG_AUDIO), y)

common-obj-$(CONFIG_AUDIO) = audio.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
Expand Down Expand Up @@ -29,3 +31,9 @@ common-obj-$(CONFIG_AUDIO_SDL) += sdl.mo
sdl.mo-objs = sdlaudio.o
sdl.mo-cflags := $(SDL_CFLAGS)
sdl.mo-libs := $(SDL_LIBS)

else

common-obj-y = stub.o

endif
174 changes: 174 additions & 0 deletions audio/stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
* QEMU Audio subsystem stubs
*
* Copyright (c) 2018, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "qemu/osdep.h"
#include "audio.h"
#include "ui/qemu-spice.h"

void AUD_help (void)
{
}

void AUD_log (const char *cap, const char *fmt, ...)
{
}

void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw)
{
}

void AUD_register_card (const char *name, QEMUSoundCard *card)
{
}

void AUD_remove_card (QEMUSoundCard *card)
{
}

void AUD_set_active_out (SWVoiceOut *sw, int on)
{
}

int AUD_is_active_out (SWVoiceOut *sw)
{
return -1;
}

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)
{
}

CaptureVoiceOut *AUD_add_capture (
struct audsettings *as,
struct audio_capture_ops *ops,
void *opaque
)
{
return NULL;
}

void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque)
{
}

SWVoiceOut *AUD_open_out (
QEMUSoundCard *card,
SWVoiceOut *sw,
const char *name,
void *callback_opaque,
audio_callback_fn callback_fn,
struct audsettings *settings
)
{
return NULL;
}

int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size)
{
return -1;

}

int AUD_get_buffer_size_out (SWVoiceOut *sw)
{
return -1;
}

SWVoiceIn *AUD_open_in (
QEMUSoundCard *card,
SWVoiceIn *sw,
const char *name,
void *callback_opaque,
audio_callback_fn callback_fn,
struct audsettings *settings
)
{
return NULL;
}

void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw)
{
}

int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size)
{
return -1;
}

void AUD_set_active_in (SWVoiceIn *sw, int on)
{
}

int AUD_is_active_in (SWVoiceIn *sw)
{
return -1;
}

void AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts)
{
}

uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts)
{
return 0;
}

void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts)
{
}

uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts)
{
return 0;
}

void audio_cleanup(void)
{
}

void audio_sample_to_uint64(void *samples, int pos,
uint64_t *left, uint64_t *right)
{
}

void audio_sample_from_uint64(void *samples, int pos,
uint64_t left, uint64_t right)
{
}

int wav_start_capture (CaptureState *s, const char *path, int freq,
int bits, int nchannels)
{
return -1;
}

#ifdef CONFIG_SPICE
void qemu_spice_audio_init (void)
{
}
#endif
129 changes: 72 additions & 57 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ iasl="iasl"
interp_prefix="/usr/gnemul/qemu-%M"
static="no"
cross_prefix=""
audio="yes"
audio_drv_list=""
block_drv_rw_whitelist=""
block_drv_ro_whitelist=""
Expand Down Expand Up @@ -1055,6 +1056,10 @@ for opt do
;;
--enable-vnc) vnc="yes"
;;
--disable-audio) audio="no"
;;
--enable-audio) audio="yes"
;;
--oss-lib=*) oss_lib="$optarg"
;;
--audio-drv-list=*) audio_drv_list="$optarg"
Expand Down Expand Up @@ -1181,7 +1186,9 @@ for opt do
;;
--enable-cocoa)
cocoa="yes" ;
audio_drv_list="coreaudio $(echo $audio_drv_list | sed s,coreaudio,,g)"
if test "$audio" = "yes"; then
audio_drv_list="coreaudio $(echo $audio_drv_list | sed s,coreaudio,,g)"
fi
;;
--disable-system) softmmu="no"
;;
Expand Down Expand Up @@ -3295,53 +3302,58 @@ EOF
fi
}

audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/,/ /g')
for drv in $audio_drv_list; do
case $drv in
alsa)
audio_drv_probe $drv alsa/asoundlib.h -lasound \
"return snd_pcm_close((snd_pcm_t *)0);"
alsa_libs="-lasound"
;;

pa)
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)
if test "$sdl" = "no"; then
error_exit "sdl not found or disabled, can not use sdl audio driver"
fi
;;

coreaudio)
coreaudio_libs="-framework CoreAudio"
;;

dsound)
dsound_libs="-lole32 -ldxguid"
audio_win_int="yes"
;;

oss)
oss_libs="$oss_lib"
;;

wav)
# XXX: Probes for CoreAudio, DirectSound
;;

*)
echo "$audio_possible_drivers" | grep -q "\<$drv\>" || {
error_exit "Unknown driver '$drv' selected" \
"Possible drivers are: $audio_possible_drivers"
}
;;
esac
done
if test "$audio" = "yes"; then
audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/,/ /g')
for drv in $audio_drv_list; do
case $drv in
alsa)
audio_drv_probe $drv alsa/asoundlib.h -lasound \
"return snd_pcm_close((snd_pcm_t *)0);"
alsa_libs="-lasound"
;;

pa)
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)
if test "$sdl" = "no"; then
error_exit "sdl not found or disabled, can not use sdl audio driver"
fi
;;

coreaudio)
coreaudio_libs="-framework CoreAudio"
;;

dsound)
dsound_libs="-lole32 -ldxguid"
audio_win_int="yes"
;;

oss)
oss_libs="$oss_lib"
;;

wav)
# XXX: Probes for CoreAudio, DirectSound
;;

*)
echo "$audio_possible_drivers" | grep -q "\<$drv\>" || {
error_exit "Unknown driver '$drv' selected" \
"Possible drivers are: $audio_possible_drivers"
}
;;
esac
done
else
audio_drv_list=""
fi

##########################################
# BrlAPI probe
Expand Down Expand Up @@ -6267,16 +6279,19 @@ fi
if test "$cap_ng" = "yes" ; then
echo "CONFIG_LIBCAP=y" >> $config_host_mak
fi
echo "CONFIG_AUDIO_DRIVERS=$audio_drv_list" >> $config_host_mak
for drv in $audio_drv_list; do
def=CONFIG_AUDIO_$(echo $drv | LC_ALL=C tr '[a-z]' '[A-Z]')
case "$drv" in
alsa | oss | pa | sdl)
echo "$def=m" >> $config_host_mak ;;
*)
echo "$def=y" >> $config_host_mak ;;
esac
done
if test "$audio" = "yes"; then
echo "CONFIG_AUDIO=y" >> $config_host_mak
echo "CONFIG_AUDIO_DRIVERS=$audio_drv_list" >> $config_host_mak
for drv in $audio_drv_list; do
def=CONFIG_AUDIO_$(echo $drv | LC_ALL=C tr '[a-z]' '[A-Z]')
case "$drv" in
alsa | oss | pa | sdl)
echo "$def=m" >> $config_host_mak ;;
*)
echo "$def=y" >> $config_host_mak ;;
esac
done
fi
echo "ALSA_LIBS=$alsa_libs" >> $config_host_mak
echo "PULSE_LIBS=$pulse_libs" >> $config_host_mak
echo "COREAUDIO_LIBS=$coreaudio_libs" >> $config_host_mak
Expand Down
11 changes: 10 additions & 1 deletion hw/audio/Makefile.objs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Sound

ifeq ($(CONFIG_AUDIO), y)

common-obj-y += soundhw.o

common-obj-$(CONFIG_SB16) += sb16.o
common-obj-$(CONFIG_ES1370) += es1370.o
common-obj-$(CONFIG_AC97) += ac97.o
Expand All @@ -15,4 +20,8 @@ common-obj-$(CONFIG_CS4231) += cs4231.o
common-obj-$(CONFIG_MARVELL_88W8618) += marvell_88w8618.o
common-obj-$(CONFIG_MILKYMIST) += milkymist-ac97.o

common-obj-y += soundhw.o
else

common-obj-y += stub.o

endif
Loading

0 comments on commit 46c16a9

Please sign in to comment.