node: add a clock flag to mark rate/duration inaccurate

Some clocks (v4l2) don't process exactly process buffers at the given
rate/duration so mark this in the clock flags.

We need to use the nsec field in the clock to derive ticks in pw-stream
in that case to get a good clock.
This commit is contained in:
Wim Taymans 2024-11-26 17:02:02 +01:00
parent ef8d2ab125
commit 3f0fe0032f
2 changed files with 9 additions and 1 deletions

View file

@ -128,6 +128,9 @@ struct spa_io_clock {
#define SPA_IO_CLOCK_FLAG_FREEWHEEL (1u<<0) /* graph is freewheeling */ #define SPA_IO_CLOCK_FLAG_FREEWHEEL (1u<<0) /* graph is freewheeling */
#define SPA_IO_CLOCK_FLAG_XRUN_RECOVER (1u<<1) /* recovering from xrun */ #define SPA_IO_CLOCK_FLAG_XRUN_RECOVER (1u<<1) /* recovering from xrun */
#define SPA_IO_CLOCK_FLAG_LAZY (1u<<2) /* lazy scheduling */ #define SPA_IO_CLOCK_FLAG_LAZY (1u<<2) /* lazy scheduling */
#define SPA_IO_CLOCK_FLAG_NO_RATE (1u<<3) /* the rate of the clock is only approximately.
* it is recommended to use the nsec as a clock source.
* The rate_diff contains the measured inaccuracy. */
uint32_t flags; /**< Clock flags */ uint32_t flags; /**< Clock flags */
uint32_t id; /**< Unique clock id, set by host application */ uint32_t id; /**< Unique clock id, set by host application */
char name[64]; /**< Clock name prefixed with API, set by node when it receives char name[64]; /**< Clock name prefixed with API, set by node when it receives

View file

@ -638,7 +638,12 @@ static inline void copy_position(struct stream *impl, int64_t queued)
impl->base_pos = p->clock.position - impl->time.ticks; impl->base_pos = p->clock.position - impl->time.ticks;
impl->clock_id = p->clock.id; impl->clock_id = p->clock.id;
} }
if (SPA_FLAG_IS_SET(p->clock.flags, SPA_IO_CLOCK_FLAG_NO_RATE))
impl->time.ticks = p->clock.nsec * p->clock.rate.denom /
(SPA_NSEC_PER_SEC * p->clock.rate.num);
else
impl->time.ticks = p->clock.position - impl->base_pos; impl->time.ticks = p->clock.position - impl->base_pos;
impl->time.delay = 0; impl->time.delay = 0;
impl->time.queued = queued; impl->time.queued = queued;
impl->quantum = p->clock.duration; impl->quantum = p->clock.duration;