Add sync and async support in *testsrc

Make minumum alsa latency configurable.
This commit is contained in:
Wim Taymans 2017-04-03 16:54:44 +02:00
parent 01c13adab5
commit 5c32690cc8
13 changed files with 186 additions and 153 deletions

View file

@ -32,17 +32,13 @@
typedef struct _SpaALSAState SpaALSASink;
static const char default_device[] = "default";
static const uint32_t default_period_size = 128;
static const uint32_t default_periods = 2;
static const bool default_period_event = 0;
static const uint32_t default_min_latency = 1024;
static void
reset_alsa_sink_props (SpaALSAProps *props)
{
strncpy (props->device, default_device, 64);
props->period_size = default_period_size;
props->periods = default_periods;
props->period_event = default_period_event;
props->min_latency = default_min_latency;
}
static void
@ -83,9 +79,7 @@ spa_alsa_sink_node_get_props (SpaNode *node,
PROP (&f[1], this->type.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device)),
PROP (&f[1], this->type.prop_device_name, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
PROP (&f[1], this->type.prop_card_name, -SPA_POD_TYPE_STRING, this->props.card_name, sizeof (this->props.card_name)),
PROP_MM (&f[1], this->type.prop_period_size, SPA_POD_TYPE_INT, this->props.period_size, 1, INT32_MAX),
PROP_MM (&f[1], this->type.prop_periods, SPA_POD_TYPE_INT, this->props.periods, 1, INT32_MAX),
PROP (&f[1], this->type.prop_period_event, SPA_POD_TYPE_BOOL, this->props.period_event));
PROP_MM (&f[1], this->type.prop_min_latency, SPA_POD_TYPE_INT, this->props.min_latency, 1, INT32_MAX));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
@ -109,9 +103,7 @@ spa_alsa_sink_node_set_props (SpaNode *node,
} else {
spa_props_query (props,
this->type.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
this->type.prop_period_size, SPA_POD_TYPE_INT, &this->props.period_size,
this->type.prop_periods, SPA_POD_TYPE_INT, &this->props.periods,
this->type.prop_period_event, SPA_POD_TYPE_BOOL, &this->props.period_event,
this->type.prop_min_latency, SPA_POD_TYPE_INT, &this->props.min_latency,
0);
}
return SPA_RESULT_OK;

View file

@ -39,17 +39,13 @@ update_state (SpaALSASource *this, SpaNodeState state)
}
static const char default_device[] = "hw:0";
static const uint32_t default_period_size = 32;
static const uint32_t default_periods = 2;
static const bool default_period_event = 0;
static const uint32_t default_min_latency = 1024;
static void
reset_alsa_props (SpaALSAProps *props)
{
strncpy (props->device, default_device, 64);
props->period_size = default_period_size;
props->periods = default_periods;
props->period_event = default_period_event;
props->min_latency = default_min_latency;
}
#define PROP(f,key,type,...) \
@ -84,9 +80,7 @@ spa_alsa_source_node_get_props (SpaNode *node,
PROP (&f[1], this->type.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device)),
PROP (&f[1], this->type.prop_device_name, -SPA_POD_TYPE_STRING, this->props.device_name, sizeof (this->props.device_name)),
PROP (&f[1], this->type.prop_card_name, -SPA_POD_TYPE_STRING, this->props.card_name, sizeof (this->props.card_name)),
PROP_MM (&f[1], this->type.prop_period_size, SPA_POD_TYPE_INT, this->props.period_size, 1, INT32_MAX),
PROP_MM (&f[1], this->type.prop_periods, SPA_POD_TYPE_INT, this->props.periods, 1, INT32_MAX),
PROP (&f[1], this->type.prop_period_event, SPA_POD_TYPE_BOOL, this->props.period_event));
PROP_MM (&f[1], this->type.prop_min_latency, SPA_POD_TYPE_INT, this->props.min_latency, 1, INT32_MAX));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
@ -110,9 +104,7 @@ spa_alsa_source_node_set_props (SpaNode *node,
} else {
spa_props_query (props,
this->type.prop_device, -SPA_POD_TYPE_STRING, this->props.device, sizeof (this->props.device),
this->type.prop_period_size, SPA_POD_TYPE_INT, &this->props.period_size,
this->type.prop_periods, SPA_POD_TYPE_INT, &this->props.periods,
this->type.prop_period_event, SPA_POD_TYPE_BOOL, &this->props.period_event,
this->type.prop_min_latency, SPA_POD_TYPE_INT, &this->props.min_latency,
0);
}

View file

@ -117,7 +117,6 @@ spa_alsa_set_format (SpaALSAState *state, SpaAudioInfo *fmt, SpaPortFormatFlags
SpaAudioInfoRaw *info = &fmt->info.raw;
snd_pcm_t *hndl;
unsigned int periods;
SpaALSAProps *props = &state->props;
if ((err = spa_alsa_open (state)) < 0)
return err;
@ -195,8 +194,6 @@ set_swparams (SpaALSAState *state)
snd_pcm_sw_params_t *params;
snd_pcm_uframes_t boundary;
SpaALSAProps *props = &state->props;
snd_pcm_sw_params_alloca (&params);
/* get the current params */
@ -618,7 +615,7 @@ spa_alsa_start (SpaALSAState *state, bool xrun_recover)
state->source.rmask = 0;
spa_loop_add_source (state->data_loop, &state->source);
state->threshold = 1024;
state->threshold = state->props.min_latency;
if (state->stream == SND_PCM_STREAM_PLAYBACK) {
state->alsa_started = false;

View file

@ -45,9 +45,7 @@ typedef struct {
char device[64];
char device_name[128];
char card_name[128];
uint32_t period_size;
uint32_t periods;
bool period_event;
uint32_t min_latency;
} SpaALSAProps;
#define MAX_BUFFERS 64
@ -68,9 +66,7 @@ typedef struct {
uint32_t prop_device;
uint32_t prop_device_name;
uint32_t prop_card_name;
uint32_t prop_period_size;
uint32_t prop_periods;
uint32_t prop_period_event;
uint32_t prop_min_latency;
SpaTypeMediaType media_type;
SpaTypeMediaSubtype media_subtype;
SpaTypeMediaSubtypeAudio media_subtype_audio;
@ -92,9 +88,7 @@ init_type (Type *type, SpaTypeMap *map)
type->prop_device = spa_type_map_get_id (map, SPA_TYPE_PROPS__device);
type->prop_device_name = spa_type_map_get_id (map, SPA_TYPE_PROPS__deviceName);
type->prop_card_name = spa_type_map_get_id (map, SPA_TYPE_PROPS__cardName);
type->prop_period_size = spa_type_map_get_id (map, SPA_TYPE_PROPS__periodSize);
type->prop_periods = spa_type_map_get_id (map, SPA_TYPE_PROPS__periods);
type->prop_period_event = spa_type_map_get_id (map, SPA_TYPE_PROPS__periodEvent);
type->prop_min_latency = spa_type_map_get_id (map, SPA_TYPE_PROPS__minLatency);
spa_type_media_type_map (map, &type->media_type);
spa_type_media_subtype_map (map, &type->media_subtype);