qapi audio: Elide redundant has_FOO in generated C
The has_FOO for pointer-valued FOO are redundant, except for arrays. They are also a nuisance to work with. Recent commit "qapi: Start to elide redundant has_FOO in generated C" provided the means to elide them step by step. This is the step for qapi/audio.json. Said commit explains the transformation in more detail. The invariant violations mentioned there do not occur here. Additionally, helper get_str() loses its @has_dst parameter. Cc: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20221104160712.3005652-8-armbru@redhat.com>
This commit is contained in:
parent
b94ba62fd4
commit
ceb19c8f68
@ -449,7 +449,7 @@ static int alsa_open(bool in, struct alsa_params_req *req,
|
|||||||
snd_pcm_hw_params_t *hw_params;
|
snd_pcm_hw_params_t *hw_params;
|
||||||
int err;
|
int err;
|
||||||
unsigned int freq, nchannels;
|
unsigned int freq, nchannels;
|
||||||
const char *pcm_name = apdo->has_dev ? apdo->dev : "default";
|
const char *pcm_name = apdo->dev ?: "default";
|
||||||
snd_pcm_uframes_t obt_buffer_size;
|
snd_pcm_uframes_t obt_buffer_size;
|
||||||
const char *typ = in ? "ADC" : "DAC";
|
const char *typ = in ? "ADC" : "DAC";
|
||||||
snd_pcm_format_t obtfmt;
|
snd_pcm_format_t obtfmt;
|
||||||
|
@ -2035,15 +2035,13 @@ void audio_create_pdos(Audiodev *dev)
|
|||||||
switch (dev->driver) {
|
switch (dev->driver) {
|
||||||
#define CASE(DRIVER, driver, pdo_name) \
|
#define CASE(DRIVER, driver, pdo_name) \
|
||||||
case AUDIODEV_DRIVER_##DRIVER: \
|
case AUDIODEV_DRIVER_##DRIVER: \
|
||||||
if (!dev->u.driver.has_in) { \
|
if (!dev->u.driver.in) { \
|
||||||
dev->u.driver.in = g_malloc0( \
|
dev->u.driver.in = g_malloc0( \
|
||||||
sizeof(Audiodev##pdo_name##PerDirectionOptions)); \
|
sizeof(Audiodev##pdo_name##PerDirectionOptions)); \
|
||||||
dev->u.driver.has_in = true; \
|
|
||||||
} \
|
} \
|
||||||
if (!dev->u.driver.has_out) { \
|
if (!dev->u.driver.out) { \
|
||||||
dev->u.driver.out = g_malloc0( \
|
dev->u.driver.out = g_malloc0( \
|
||||||
sizeof(Audiodev##pdo_name##PerDirectionOptions)); \
|
sizeof(Audiodev##pdo_name##PerDirectionOptions)); \
|
||||||
dev->u.driver.has_out = true; \
|
|
||||||
} \
|
} \
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -62,15 +62,12 @@ static void get_int(const char *env, uint32_t *dst, bool *has_dst)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_str(const char *env, char **dst, bool *has_dst)
|
static void get_str(const char *env, char **dst)
|
||||||
{
|
{
|
||||||
const char *val = getenv(env);
|
const char *val = getenv(env);
|
||||||
if (val) {
|
if (val) {
|
||||||
if (*has_dst) {
|
g_free(*dst);
|
||||||
g_free(*dst);
|
|
||||||
}
|
|
||||||
*dst = g_strdup(val);
|
*dst = g_strdup(val);
|
||||||
*has_dst = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +166,7 @@ static void handle_alsa_per_direction(
|
|||||||
get_bool(buf, &apdo->try_poll, &apdo->has_try_poll);
|
get_bool(buf, &apdo->try_poll, &apdo->has_try_poll);
|
||||||
|
|
||||||
strcpy(buf + len, "DEV");
|
strcpy(buf + len, "DEV");
|
||||||
get_str(buf, &apdo->dev, &apdo->has_dev);
|
get_str(buf, &apdo->dev);
|
||||||
|
|
||||||
strcpy(buf + len, "SIZE_IN_USEC");
|
strcpy(buf + len, "SIZE_IN_USEC");
|
||||||
get_bool(buf, &size_in_usecs, &dummy);
|
get_bool(buf, &size_in_usecs, &dummy);
|
||||||
@ -235,7 +232,7 @@ static void handle_oss_per_direction(
|
|||||||
const char *dev_env)
|
const char *dev_env)
|
||||||
{
|
{
|
||||||
get_bool(try_poll_env, &opdo->try_poll, &opdo->has_try_poll);
|
get_bool(try_poll_env, &opdo->try_poll, &opdo->has_try_poll);
|
||||||
get_str(dev_env, &opdo->dev, &opdo->has_dev);
|
get_str(dev_env, &opdo->dev);
|
||||||
|
|
||||||
get_bytes_to_usecs("QEMU_OSS_FRAGSIZE",
|
get_bytes_to_usecs("QEMU_OSS_FRAGSIZE",
|
||||||
&opdo->buffer_length, &opdo->has_buffer_length,
|
&opdo->buffer_length, &opdo->has_buffer_length,
|
||||||
@ -261,7 +258,7 @@ static void handle_oss(Audiodev *dev)
|
|||||||
static void handle_pa_per_direction(
|
static void handle_pa_per_direction(
|
||||||
AudiodevPaPerDirectionOptions *ppdo, const char *env)
|
AudiodevPaPerDirectionOptions *ppdo, const char *env)
|
||||||
{
|
{
|
||||||
get_str(env, &ppdo->name, &ppdo->has_name);
|
get_str(env, &ppdo->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_pa(Audiodev *dev)
|
static void handle_pa(Audiodev *dev)
|
||||||
@ -278,7 +275,7 @@ static void handle_pa(Audiodev *dev)
|
|||||||
&dev->u.pa.out->has_buffer_length,
|
&dev->u.pa.out->has_buffer_length,
|
||||||
qapi_AudiodevPaPerDirectionOptions_base(dev->u.pa.out));
|
qapi_AudiodevPaPerDirectionOptions_base(dev->u.pa.out));
|
||||||
|
|
||||||
get_str("QEMU_PA_SERVER", &dev->u.pa.server, &dev->u.pa.has_server);
|
get_str("QEMU_PA_SERVER", &dev->u.pa.server);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SDL */
|
/* SDL */
|
||||||
@ -299,7 +296,7 @@ static void handle_wav(Audiodev *dev)
|
|||||||
&dev->u.wav.out->has_format);
|
&dev->u.wav.out->has_format);
|
||||||
get_int("QEMU_WAV_DAC_FIXED_CHANNELS",
|
get_int("QEMU_WAV_DAC_FIXED_CHANNELS",
|
||||||
&dev->u.wav.out->channels, &dev->u.wav.out->has_channels);
|
&dev->u.wav.out->channels, &dev->u.wav.out->has_channels);
|
||||||
get_str("QEMU_WAV_PATH", &dev->u.wav.path, &dev->u.wav.has_path);
|
get_str("QEMU_WAV_PATH", &dev->u.wav.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* general */
|
/* general */
|
||||||
|
@ -252,7 +252,7 @@ static int oss_open(int in, struct oss_params *req, audsettings *as,
|
|||||||
audio_buf_info abinfo;
|
audio_buf_info abinfo;
|
||||||
int fmt, freq, nchannels;
|
int fmt, freq, nchannels;
|
||||||
int setfragment = 1;
|
int setfragment = 1;
|
||||||
const char *dspname = opdo->has_dev ? opdo->dev : "/dev/dsp";
|
const char *dspname = opdo->dev ?: "/dev/dsp";
|
||||||
const char *typ = in ? "ADC" : "DAC";
|
const char *typ = in ? "ADC" : "DAC";
|
||||||
#ifdef USE_DSP_POLICY
|
#ifdef USE_DSP_POLICY
|
||||||
int policy = oopts->has_dsp_policy ? oopts->dsp_policy : 5;
|
int policy = oopts->has_dsp_policy ? oopts->dsp_policy : 5;
|
||||||
@ -745,10 +745,8 @@ static void *oss_audio_init(Audiodev *dev)
|
|||||||
oss_init_per_direction(oopts->in);
|
oss_init_per_direction(oopts->in);
|
||||||
oss_init_per_direction(oopts->out);
|
oss_init_per_direction(oopts->out);
|
||||||
|
|
||||||
if (access(oopts->in->has_dev ? oopts->in->dev : "/dev/dsp",
|
if (access(oopts->in->dev ?: "/dev/dsp", R_OK | W_OK) < 0 ||
|
||||||
R_OK | W_OK) < 0 ||
|
access(oopts->out->dev ?: "/dev/dsp", R_OK | W_OK) < 0) {
|
||||||
access(oopts->out->has_dev ? oopts->out->dev : "/dev/dsp",
|
|
||||||
R_OK | W_OK) < 0) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return dev;
|
return dev;
|
||||||
|
@ -536,9 +536,9 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
|
|||||||
|
|
||||||
pa->stream = qpa_simple_new (
|
pa->stream = qpa_simple_new (
|
||||||
c,
|
c,
|
||||||
ppdo->has_stream_name ? ppdo->stream_name : g->dev->id,
|
ppdo->stream_name ?: g->dev->id,
|
||||||
PA_STREAM_PLAYBACK,
|
PA_STREAM_PLAYBACK,
|
||||||
ppdo->has_name ? ppdo->name : NULL,
|
ppdo->name,
|
||||||
&ss,
|
&ss,
|
||||||
&ba, /* buffering attributes */
|
&ba, /* buffering attributes */
|
||||||
&error
|
&error
|
||||||
@ -585,9 +585,9 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
|
|||||||
|
|
||||||
pa->stream = qpa_simple_new (
|
pa->stream = qpa_simple_new (
|
||||||
c,
|
c,
|
||||||
ppdo->has_stream_name ? ppdo->stream_name : g->dev->id,
|
ppdo->stream_name ?: g->dev->id,
|
||||||
PA_STREAM_RECORD,
|
PA_STREAM_RECORD,
|
||||||
ppdo->has_name ? ppdo->name : NULL,
|
ppdo->name,
|
||||||
&ss,
|
&ss,
|
||||||
&ba, /* buffering attributes */
|
&ba, /* buffering attributes */
|
||||||
&error
|
&error
|
||||||
@ -827,7 +827,7 @@ static void *qpa_audio_init(Audiodev *dev)
|
|||||||
|
|
||||||
assert(dev->driver == AUDIODEV_DRIVER_PA);
|
assert(dev->driver == AUDIODEV_DRIVER_PA);
|
||||||
|
|
||||||
if (!popts->has_server) {
|
if (!popts->server) {
|
||||||
char pidfile[64];
|
char pidfile[64];
|
||||||
char *runtime;
|
char *runtime;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -850,7 +850,7 @@ static void *qpa_audio_init(Audiodev *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g = g_new0(paaudio, 1);
|
g = g_new0(paaudio, 1);
|
||||||
server = popts->has_server ? popts->server : NULL;
|
server = popts->server;
|
||||||
|
|
||||||
g->dev = dev;
|
g->dev = dev;
|
||||||
|
|
||||||
|
@ -333,7 +333,7 @@ static int sndio_init(SndioVoice *self,
|
|||||||
unsigned int nch;
|
unsigned int nch;
|
||||||
int i, nfds;
|
int i, nfds;
|
||||||
|
|
||||||
dev_name = opts->has_dev ? opts->dev : SIO_DEVANY;
|
dev_name = opts->dev ?: SIO_DEVANY;
|
||||||
latency = opts->has_latency ? opts->latency : SNDIO_LATENCY_US;
|
latency = opts->has_latency ? opts->latency : SNDIO_LATENCY_US;
|
||||||
|
|
||||||
/* open the device in non-blocking mode */
|
/* open the device in non-blocking mode */
|
||||||
|
@ -78,7 +78,7 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as,
|
|||||||
Audiodev *dev = drv_opaque;
|
Audiodev *dev = drv_opaque;
|
||||||
AudiodevWavOptions *wopts = &dev->u.wav;
|
AudiodevWavOptions *wopts = &dev->u.wav;
|
||||||
struct audsettings wav_as = audiodev_to_audsettings(dev->u.wav.out);
|
struct audsettings wav_as = audiodev_to_audsettings(dev->u.wav.out);
|
||||||
const char *wav_path = wopts->has_path ? wopts->path : "qemu.wav";
|
const char *wav_path = wopts->path ?: "qemu.wav";
|
||||||
|
|
||||||
stereo = wav_as.nchannels == 2;
|
stereo = wav_as.nchannels == 2;
|
||||||
switch (wav_as.fmt) {
|
switch (wav_as.fmt) {
|
||||||
|
@ -759,7 +759,6 @@ class QAPISchemaObjectTypeMember(QAPISchemaMember):
|
|||||||
assert self.type
|
assert self.type
|
||||||
# Temporary hack to support dropping the has_FOO in reviewable chunks
|
# Temporary hack to support dropping the has_FOO in reviewable chunks
|
||||||
opt_out = [
|
opt_out = [
|
||||||
'qapi/audio.json',
|
|
||||||
'qapi/block-core.json',
|
'qapi/block-core.json',
|
||||||
'qapi/block-export.json',
|
'qapi/block-export.json',
|
||||||
'qapi/block.json',
|
'qapi/block.json',
|
||||||
|
Loading…
Reference in New Issue
Block a user