v4l2: set latency on port

Use the duration of one frame as the latency.

See #3910
This commit is contained in:
Wim Taymans 2024-03-22 11:15:10 +01:00
parent 58d626fec8
commit 842ac9e110
2 changed files with 15 additions and 9 deletions

View File

@ -82,7 +82,6 @@ struct port {
bool have_format;
struct spa_video_info current_format;
struct spa_fraction rate;
struct spa_v4l2_device dev;
@ -696,11 +695,19 @@ static int port_set_format(struct impl *this, struct port *port,
done:
this->info.change_mask |= SPA_NODE_CHANGE_MASK_PARAMS;
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
port->params[PORT_Latency].flags ^= SPA_PARAM_INFO_SERIAL;
if (port->have_format) {
uint64_t latency;
latency = port->info.rate.num * SPA_NSEC_PER_SEC / port->info.rate.denom;
this->latency[SPA_DIRECTION_OUTPUT] =
SPA_LATENCY_INFO(SPA_DIRECTION_OUTPUT,
.min_ns = latency,
.max_ns = latency);
port->params[PORT_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
port->params[PORT_Buffers] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
this->params[NODE_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READ);
} else {
this->latency[SPA_DIRECTION_OUTPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_OUTPUT);
port->params[PORT_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
port->params[PORT_Buffers] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
this->params[NODE_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, 0);

View File

@ -1012,10 +1012,6 @@ static int spa_v4l2_set_format(struct impl *this, struct spa_video_info *format,
dev->have_format = true;
size->width = fmt.fmt.pix.width;
size->height = fmt.fmt.pix.height;
port->rate.denom = framerate->num = streamparm.parm.capture.timeperframe.denominator;
port->rate.num = framerate->denom = streamparm.parm.capture.timeperframe.numerator;
probe_expbuf(this);
port->fmt = fmt;
port->info.change_mask |= SPA_PORT_CHANGE_MASK_FLAGS | SPA_PORT_CHANGE_MASK_RATE;
@ -1023,7 +1019,10 @@ static int spa_v4l2_set_format(struct impl *this, struct spa_video_info *format,
SPA_PORT_FLAG_LIVE |
SPA_PORT_FLAG_PHYSICAL |
SPA_PORT_FLAG_TERMINAL;
port->info.rate = SPA_FRACTION(port->rate.num, port->rate.denom);
port->info.rate.num = streamparm.parm.capture.timeperframe.numerator;
port->info.rate.denom = streamparm.parm.capture.timeperframe.denominator;
probe_expbuf(this);
return match ? 0 : 1;
}
@ -1376,16 +1375,16 @@ static int mmap_read(struct impl *this)
if (this->clock) {
/* FIXME, we should follow the driver clock and target_ values.
* for now we ignore and use our own. */
this->clock->target_rate = port->rate;
this->clock->target_rate = port->info.rate;
this->clock->target_duration = 1;
this->clock->nsec = pts;
this->clock->rate = port->rate;
this->clock->rate = port->info.rate;
this->clock->position = buf.sequence;
this->clock->duration = 1;
this->clock->delay = 0;
this->clock->rate_diff = 1.0;
this->clock->next_nsec = pts + 1000000000LL / port->rate.denom;
this->clock->next_nsec = pts + port->info.rate.num * SPA_NSEC_PER_SEC / port->info.rate.denom;
}
b = &port->buffers[buf.index];