module-netjack2: set latency param

This commit is contained in:
Wim Taymans 2023-06-05 10:20:10 +02:00
parent 7de7a620f3
commit 407ee3940c
3 changed files with 34 additions and 9 deletions

View file

@ -606,9 +606,7 @@ static int make_stream(struct stream *s, const char *name)
const struct spa_pod *params[4]; const struct spa_pod *params[4];
uint8_t buffer[1024]; uint8_t buffer[1024];
struct spa_pod_builder b; struct spa_pod_builder b;
struct spa_latency_info latency;
spa_zero(latency);
n_params = 0; n_params = 0;
spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_builder_init(&b, buffer, sizeof(buffer));

View file

@ -367,11 +367,16 @@ static void param_latency_changed(struct stream *s, const struct spa_pod *param,
static void make_stream_ports(struct stream *s) static void make_stream_ports(struct stream *s)
{ {
struct impl *impl = s->impl;
uint32_t i; uint32_t i;
struct pw_properties *props; struct pw_properties *props;
const char *str, *prefix; const char *str, *prefix;
char name[256]; char name[256];
bool is_midi; bool is_midi;
uint8_t buffer[512];
struct spa_pod_builder b;
struct spa_latency_info latency;
const struct spa_pod *params[1];
if (s->direction == PW_DIRECTION_INPUT) { if (s->direction == PW_DIRECTION_INPUT) {
/* sink */ /* sink */
@ -383,6 +388,7 @@ static void make_stream_ports(struct stream *s)
for (i = 0; i < s->n_ports; i++) { for (i = 0; i < s->n_ports; i++) {
struct port *port = s->ports[i]; struct port *port = s->ports[i];
if (port != NULL) { if (port != NULL) {
s->ports[i] = NULL; s->ports[i] = NULL;
pw_filter_remove_port(port); pw_filter_remove_port(port);
@ -414,13 +420,22 @@ static void make_stream_ports(struct stream *s)
is_midi = true; is_midi = true;
} }
latency = SPA_LATENCY_INFO(s->direction,
.min_quantum = impl->latency,
.max_quantum = impl->latency);
spa_pod_builder_init(&b, buffer, sizeof(buffer));
params[0] = spa_latency_build(&b, SPA_PARAM_Latency, &latency);
port = pw_filter_add_port(s->filter, port = pw_filter_add_port(s->filter,
s->direction, s->direction,
PW_FILTER_PORT_FLAG_MAP_BUFFERS, PW_FILTER_PORT_FLAG_MAP_BUFFERS,
sizeof(struct port), sizeof(struct port),
props, NULL, 0); props, params, 1);
if (port == NULL) {
pw_log_error("Can't create port: %m");
return;
}
port->latency[s->direction] = latency;
port->is_midi = is_midi; port->is_midi = is_midi;
s->ports[i] = port; s->ports[i] = port;
@ -525,9 +540,7 @@ static int make_stream(struct stream *s, const char *name)
const struct spa_pod *params[4]; const struct spa_pod *params[4];
uint8_t buffer[1024]; uint8_t buffer[1024];
struct spa_pod_builder b; struct spa_pod_builder b;
struct spa_latency_info latency;
spa_zero(latency);
n_params = 0; n_params = 0;
spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_builder_init(&b, buffer, sizeof(buffer));

View file

@ -418,11 +418,16 @@ static void param_latency_changed(struct stream *s, const struct spa_pod *param,
static void make_stream_ports(struct stream *s) static void make_stream_ports(struct stream *s)
{ {
struct follower *follower = s->follower;
uint32_t i; uint32_t i;
struct pw_properties *props; struct pw_properties *props;
const char *str, *prefix; const char *str, *prefix;
char name[256]; char name[256];
bool is_midi; bool is_midi;
uint8_t buffer[512];
struct spa_pod_builder b;
struct spa_latency_info latency;
const struct spa_pod *params[1];
if (s->direction == PW_DIRECTION_INPUT) { if (s->direction == PW_DIRECTION_INPUT) {
/* sink */ /* sink */
@ -465,13 +470,24 @@ static void make_stream_ports(struct stream *s)
is_midi = true; is_midi = true;
} }
spa_zero(latency);
latency = SPA_LATENCY_INFO(s->direction,
.min_quantum = follower->peer.params.network_latency,
.max_quantum = follower->peer.params.network_latency);
spa_pod_builder_init(&b, buffer, sizeof(buffer));
params[0] = spa_latency_build(&b, SPA_PARAM_Latency, &latency);
port = pw_filter_add_port(s->filter, port = pw_filter_add_port(s->filter,
s->direction, s->direction,
PW_FILTER_PORT_FLAG_MAP_BUFFERS, PW_FILTER_PORT_FLAG_MAP_BUFFERS,
sizeof(struct port), sizeof(struct port),
props, NULL, 0); props, params, 1);
if (port == NULL) {
pw_log_error("Can't create port: %m");
return;
}
port->latency[s->direction] = latency;
port->is_midi = is_midi; port->is_midi = is_midi;
s->ports[i] = port; s->ports[i] = port;
@ -576,10 +592,8 @@ static int make_stream(struct stream *s, const char *name)
const struct spa_pod *params[4]; const struct spa_pod *params[4];
uint8_t buffer[1024]; uint8_t buffer[1024];
struct spa_pod_builder b; struct spa_pod_builder b;
struct spa_latency_info latency;
uint32_t flags; uint32_t flags;
spa_zero(latency);
n_params = 0; n_params = 0;
spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_builder_init(&b, buffer, sizeof(buffer));