mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-16 08:56:45 -05:00
add clock
Add a gstreamer pinos clock that reports the time at the server
This commit is contained in:
parent
0b380dd43e
commit
f86b50d202
11 changed files with 259 additions and 72 deletions
|
|
@ -107,7 +107,8 @@ struct _SpaClock {
|
|||
const SpaProps *props);
|
||||
|
||||
SpaResult (*get_time) (SpaClock *clock,
|
||||
int64_t *clock_time,
|
||||
int32_t *rate,
|
||||
int64_t *ticks,
|
||||
int64_t *monotonic_time);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -48,11 +48,12 @@ struct _SpaNodeCommand {
|
|||
/**
|
||||
* SpaNodeCommandClockUpdate:
|
||||
* @change_mask: marks which fields are updated
|
||||
* @timestamp: the new timestamp, when @change_mask = 1<<0
|
||||
* @monotonic_time: the new monotonic time associated with @timestamp, when
|
||||
* @change_mask = 1<<0
|
||||
* @rate: the number of @ticks per second
|
||||
* @ticks: the new ticks, when @change_mask = 1<<0
|
||||
* @monotonic_time: the new monotonic time in nanoseconds associated with
|
||||
* @ticks, when @change_mask = 1<<0
|
||||
* @offset: the difference between the time when this update was generated
|
||||
* and @monotonic_time
|
||||
* and @monotonic_time in nanoseconds
|
||||
* @scale: update to the speed stored as Q16.16, @change_mask = 1<<1
|
||||
* @state: the new clock state, when @change_mask = 1<<2
|
||||
*/
|
||||
|
|
@ -61,7 +62,8 @@ typedef struct {
|
|||
#define SPA_NODE_COMMAND_CLOCK_UPDATE_SCALE (1 << 1)
|
||||
#define SPA_NODE_COMMAND_CLOCK_UPDATE_STATE (1 << 2)
|
||||
uint32_t change_mask;
|
||||
int64_t timestamp;
|
||||
int32_t rate;
|
||||
int64_t ticks;
|
||||
int64_t monotonic_time;
|
||||
int64_t offset;
|
||||
int32_t scale;
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ typedef struct {
|
|||
SpaAllocParamBuffers param_buffers;
|
||||
SpaPortStatus status;
|
||||
|
||||
int64_t last_timestamp;
|
||||
int64_t last_ticks;
|
||||
int64_t last_monotonic;
|
||||
} SpaV4l2State;
|
||||
|
||||
|
|
@ -759,7 +759,8 @@ spa_v4l2_source_clock_set_props (SpaClock *clock,
|
|||
|
||||
static SpaResult
|
||||
spa_v4l2_source_clock_get_time (SpaClock *clock,
|
||||
int64_t *clock_time,
|
||||
int32_t *rate,
|
||||
int64_t *ticks,
|
||||
int64_t *monotonic_time)
|
||||
{
|
||||
SpaV4l2Source *this;
|
||||
|
|
@ -771,8 +772,10 @@ spa_v4l2_source_clock_get_time (SpaClock *clock,
|
|||
this = (SpaV4l2Source *) clock->handle;
|
||||
state = &this->state[0];
|
||||
|
||||
if (clock_time)
|
||||
*clock_time = state->last_timestamp;
|
||||
if (rate)
|
||||
*rate = 1000000;
|
||||
if (ticks)
|
||||
*ticks = state->last_ticks;
|
||||
if (monotonic_time)
|
||||
*monotonic_time = state->last_monotonic;
|
||||
|
||||
|
|
|
|||
|
|
@ -788,7 +788,8 @@ spa_v4l2_set_format (SpaV4l2Source *this, V4l2Format *f, bool try_only)
|
|||
state->info.flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS |
|
||||
SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
||||
state->info.maxbuffering = -1;
|
||||
state->info.latency = -1;
|
||||
state->info.latency = (streamparm.parm.capture.timeperframe.numerator * 1000000000LL) /
|
||||
streamparm.parm.capture.timeperframe.denominator;
|
||||
|
||||
state->info.n_params = 1;
|
||||
state->info.params = state->params;
|
||||
|
|
@ -834,12 +835,13 @@ mmap_read (SpaV4l2Source *this)
|
|||
if (buf.flags & V4L2_BUF_FLAG_ERROR)
|
||||
b->header.flags |= SPA_BUFFER_FLAG_CORRUPTED;
|
||||
|
||||
state->last_ticks = (int64_t)buf.timestamp.tv_sec * 1000000 + (uint64_t)buf.timestamp.tv_usec;
|
||||
|
||||
b->header.seq = buf.sequence;
|
||||
b->header.pts = (uint64_t)buf.timestamp.tv_sec * 1000000000lu + (uint64_t)buf.timestamp.tv_usec * 1000lu;
|
||||
state->last_timestamp = b->header.pts;
|
||||
b->header.pts = state->last_ticks * 1000;
|
||||
|
||||
if (buf.flags & V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC)
|
||||
state->last_monotonic = state->last_timestamp;
|
||||
state->last_monotonic = b->header.pts;
|
||||
else
|
||||
state->last_monotonic = SPA_TIME_INVALID;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue