spa: add some latency helpers

Add more fields to the latency object.
Add methods to create, parse and process latency info.
This commit is contained in:
Wim Taymans 2021-05-24 18:01:19 +02:00
parent 0779862cda
commit b9b89b92b2
15 changed files with 245 additions and 145 deletions

View file

@ -459,12 +459,7 @@ impl_node_port_enum_params(void *object, int seq,
case SPA_PARAM_Latency:
switch (result.index) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamLatency, id,
SPA_PARAM_LATENCY_direction, SPA_POD_Id(direction),
SPA_PARAM_LATENCY_quantum, SPA_POD_Float(this->latency_quantum),
SPA_PARAM_LATENCY_min, SPA_POD_Int(this->latency),
SPA_PARAM_LATENCY_max, SPA_POD_Int(this->latency));
param = spa_latency_build(&b, id, &this->latency);
break;
default:
return 0;
@ -775,7 +770,9 @@ impl_init(const struct spa_handle_factory *factory,
spa_hook_list_init(&this->hooks);
this->stream = SND_PCM_STREAM_PLAYBACK;
this->latency_quantum = 1.0f;
this->latency = SPA_LATENCY_INFO(SPA_DIRECTION_INPUT);
this->latency.min_quantum = 1.0f;
this->latency.max_quantum = 1.0f;
this->info_all = SPA_NODE_CHANGE_MASK_FLAGS |
SPA_NODE_CHANGE_MASK_PROPS |

View file

@ -457,12 +457,7 @@ impl_node_port_enum_params(void *object, int seq,
case SPA_PARAM_Latency:
switch (result.index) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamLatency, id,
SPA_PARAM_LATENCY_direction, SPA_POD_Id(direction),
SPA_PARAM_LATENCY_quantum, SPA_POD_Float(this->latency_quantum),
SPA_PARAM_LATENCY_min, SPA_POD_Int(this->latency),
SPA_PARAM_LATENCY_max, SPA_POD_Int(this->latency));
param = spa_latency_build(&b, id, &this->latency);
break;
default:
return 0;
@ -794,8 +789,9 @@ impl_init(const struct spa_handle_factory *factory,
spa_hook_list_init(&this->hooks);
this->stream = SND_PCM_STREAM_CAPTURE;
this->latency_quantum = 1.0f;
this->latency = SPA_LATENCY_INFO(SPA_DIRECTION_OUTPUT);
this->latency.min_quantum = 1.0f;
this->latency.max_quantum = 1.0f;
this->info_all = SPA_NODE_CHANGE_MASK_FLAGS |
SPA_NODE_CHANGE_MASK_PROPS |

View file

@ -630,7 +630,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
state->headroom = SPA_MIN(state->headroom, state->buffer_frames);
state->start_delay = state->default_start_delay;
state->latency = state->headroom;
state->latency.min_rate = state->latency.max_rate = state->headroom;
state->period_frames = period_size;
periods = state->buffer_frames / state->period_frames;

View file

@ -45,6 +45,7 @@ extern "C" {
#include <spa/node/io.h>
#include <spa/debug/types.h>
#include <spa/param/param.h>
#include <spa/param/latency-utils.h>
#include <spa/param/audio/format-utils.h>
#include "dll.h"
@ -192,8 +193,7 @@ struct state {
struct spa_dll dll;
double max_error;
float latency_quantum;
uint32_t latency;
struct spa_latency_info latency;
};
int

View file

@ -36,6 +36,7 @@
#include <spa/utils/list.h>
#include <spa/monitor/device.h>
#include <spa/param/audio/format.h>
#include <spa/param/latency-utils.h>
#include <spa/pod/filter.h>
#define NAME "alsa-bridge"
@ -578,13 +579,13 @@ impl_node_port_enum_params(void *object, int seq,
case SPA_PARAM_Latency:
switch (result.index) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamLatency, id,
SPA_PARAM_LATENCY_direction, SPA_POD_Id(direction),
SPA_PARAM_LATENCY_quantum, SPA_POD_Float(1.0f),
SPA_PARAM_LATENCY_min, SPA_POD_Int(0),
SPA_PARAM_LATENCY_max, SPA_POD_Int(0));
{
struct spa_latency_info info = {
.direction = direction,
.min_quantum = 1.0f, .max_quantum = 1.0f };
param = spa_latency_build(&b, id, &info);
break;
}
default:
return 0;
}