diff --git a/spa/include/spa/utils/defs.h b/spa/include/spa/utils/defs.h index 1ffb4ba6c..a6c39f2c9 100644 --- a/spa/include/spa/utils/defs.h +++ b/spa/include/spa/utils/defs.h @@ -129,8 +129,10 @@ struct spa_fraction { #define SPA_USEC_PER_MSEC (1000ll) #define SPA_MSEC_PER_SEC (1000ll) -#define SPA_TIMESPEC_TO_TIME(ts) ((ts)->tv_sec * SPA_NSEC_PER_SEC + (ts)->tv_nsec) -#define SPA_TIMEVAL_TO_TIME(tv) ((tv)->tv_sec * SPA_NSEC_PER_SEC + (tv)->tv_usec * 1000ll) +#define SPA_TIMESPEC_TO_NSEC(ts) ((ts)->tv_sec * SPA_NSEC_PER_SEC + (ts)->tv_nsec) +#define SPA_TIMESPEC_TO_USEC(ts) ((ts)->tv_sec * SPA_USEC_PER_SEC + (ts)->tv_nsec / SPA_NSEC_PER_USEC) +#define SPA_TIMEVAL_TO_NSEC(tv) ((tv)->tv_sec * SPA_NSEC_PER_SEC + (tv)->tv_usec * SPA_NSEC_PER_USEC) +#define SPA_TIMEVAL_TO_USEC(tv) ((tv)->tv_sec * SPA_USEC_PER_SEC + (tv)->tv_usec) #ifdef __GNUC__ #define SPA_PRINTF_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1))) diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c index 704c8fe40..b11464e2e 100644 --- a/spa/plugins/alsa/alsa-utils.c +++ b/spa/plugins/alsa/alsa-utils.c @@ -643,7 +643,7 @@ push_frames(struct state *state, if (b->h) { b->h->seq = state->sample_count; - b->h->pts = SPA_TIMESPEC_TO_TIME(&state->now); + b->h->pts = SPA_TIMESPEC_TO_NSEC(&state->now); b->h->dts_offset = 0; } @@ -716,7 +716,7 @@ static void alsa_on_playback_timeout_event(struct spa_source *source) state->filled = state->buffer_frames - avail; if (state->clock) { - state->clock->nsec = SPA_TIMESPEC_TO_TIME(&state->now); + state->clock->nsec = SPA_TIMESPEC_TO_NSEC(&state->now); state->clock->rate = SPA_FRACTION(1, state->rate); state->clock->position = state->sample_count; state->clock->delay = state->filled; @@ -789,10 +789,10 @@ static void alsa_on_capture_timeout_event(struct spa_source *source) avail = snd_pcm_status_get_avail(status); snd_pcm_status_get_htstamp(status, &state->now); - clock_gettime(CLOCK_MONOTONIC, &now); + clock_gettime(CLOCK_MONOTONIC, &state->now); if (state->clock) { - state->clock->nsec = SPA_TIMESPEC_TO_TIME(&state->now); + state->clock->nsec = SPA_TIMESPEC_TO_NSEC(&state->now); state->clock->rate = SPA_FRACTION(1, state->rate); state->clock->position = state->sample_count; state->clock->delay = avail; diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index faf275c6b..c65e130aa 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -1157,7 +1157,7 @@ static int mmap_read(struct impl *this) if (xioctl(port->fd, VIDIOC_DQBUF, &buf) < 0) return -errno; - pts = SPA_TIMEVAL_TO_TIME(&buf.timestamp); + pts = SPA_TIMEVAL_TO_NSEC(&buf.timestamp); if (this->clock) { this->clock->nsec = pts; diff --git a/spa/tests/test-perf.c b/spa/tests/test-perf.c index f9d6296ff..a6e272f82 100644 --- a/spa/tests/test-perf.c +++ b/spa/tests/test-perf.c @@ -465,7 +465,7 @@ static void run_graph(struct data *data) } clock_gettime(CLOCK_MONOTONIC, &now); - start = SPA_TIMESPEC_TO_TIME(&now); + start = SPA_TIMESPEC_TO_NSEC(&now); printf("running\n"); @@ -487,7 +487,7 @@ static void run_graph(struct data *data) } clock_gettime(CLOCK_MONOTONIC, &now); - stop = SPA_TIMESPEC_TO_TIME(&now); + stop = SPA_TIMESPEC_TO_NSEC(&now); printf("stopping, elapsed %" PRIi64 "\n", stop - start); diff --git a/spa/tests/test-props.c b/spa/tests/test-props.c index 3ffad3a01..0937e15c8 100644 --- a/spa/tests/test-props.c +++ b/spa/tests/test-props.c @@ -333,7 +333,7 @@ int main(int argc, char *argv[]) fmt = spa_pod_builder_pop(&b); } clock_gettime(CLOCK_MONOTONIC, &ts2); - fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_TIME(&ts2) - SPA_TIMESPEC_TO_TIME(&ts1)); + fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_NSEC(&ts2) - SPA_TIMESPEC_TO_NSEC(&ts1)); spa_debug_pod(0, NULL, &fmt->pod); fprintf(stderr, "build 2: "); @@ -356,7 +356,7 @@ int main(int argc, char *argv[]) &SPA_FRACTION(INT32_MAX,1)); } clock_gettime(CLOCK_MONOTONIC, &ts2); - fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_TIME(&ts2) - SPA_TIMESPEC_TO_TIME(&ts1)); + fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_NSEC(&ts2) - SPA_TIMESPEC_TO_NSEC(&ts1)); spa_debug_pod(0, NULL, &fmt->pod); spa_debug_format(0, NULL, &fmt->pod); @@ -385,7 +385,7 @@ int main(int argc, char *argv[]) "}", NULL); } clock_gettime(CLOCK_MONOTONIC, &ts2); - fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_TIME(&ts2) - SPA_TIMESPEC_TO_TIME(&ts1)); + fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_NSEC(&ts2) - SPA_TIMESPEC_TO_NSEC(&ts1)); spa_debug_pod(0, NULL, &fmt->pod); spa_debug_format(0, NULL, &fmt->pod); @@ -417,7 +417,7 @@ int main(int argc, char *argv[]) fmt = spa_pod_builder_pop(&b); } clock_gettime(CLOCK_MONOTONIC, &ts2); - fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_TIME(&ts2) - SPA_TIMESPEC_TO_TIME(&ts1)); + fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_NSEC(&ts2) - SPA_TIMESPEC_TO_NSEC(&ts1)); spa_debug_pod(0, NULL, &fmt->pod); spa_debug_format(0, NULL, &fmt->pod); @@ -445,7 +445,7 @@ int main(int argc, char *argv[]) 0); } clock_gettime(CLOCK_MONOTONIC, &ts2); - fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_TIME(&ts2) - SPA_TIMESPEC_TO_TIME(&ts1)); + fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_NSEC(&ts2) - SPA_TIMESPEC_TO_NSEC(&ts1)); spa_debug_pod(0, NULL, &fmt->pod); spa_debug_format(0, NULL, &fmt->pod); @@ -472,7 +472,7 @@ int main(int argc, char *argv[]) fmt = spa_pod_builder_pop(&b); } clock_gettime(CLOCK_MONOTONIC, &ts2); - fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_TIME(&ts2) - SPA_TIMESPEC_TO_TIME(&ts1)); + fprintf(stderr, "elapsed %lld\n", SPA_TIMESPEC_TO_NSEC(&ts2) - SPA_TIMESPEC_TO_NSEC(&ts1)); spa_debug_pod(0, NULL, &fmt->pod); spa_debug_format(0, NULL, &fmt->pod); diff --git a/src/examples/media-session.c b/src/examples/media-session.c index d960a1396..03222335a 100644 --- a/src/examples/media-session.c +++ b/src/examples/media-session.c @@ -538,7 +538,7 @@ handle_node(struct impl *impl, uint32_t id, uint32_t parent_id, if ((str = spa_dict_lookup(props, "node.plugged")) != NULL) sess->plugged = pw_properties_parse_uint64(str); else - sess->plugged = SPA_TIMESPEC_TO_TIME(&impl->now); + sess->plugged = SPA_TIMESPEC_TO_NSEC(&impl->now); spa_list_init(&sess->node_list); spa_list_append(&impl->session_list, &sess->l); diff --git a/src/gst/gstpipewireclock.c b/src/gst/gstpipewireclock.c index 6bac23425..b89fd28bd 100644 --- a/src/gst/gstpipewireclock.c +++ b/src/gst/gstpipewireclock.c @@ -62,7 +62,7 @@ gst_pipewire_clock_get_internal_time (GstClock * clock) result = gst_util_uint64_scale_int (t.ticks, GST_SECOND * t.rate.num, t.rate.denom); clock_gettime(CLOCK_MONOTONIC, &ts); - result += SPA_TIMESPEC_TO_TIME(&ts) - t.now; + result += SPA_TIMESPEC_TO_NSEC(&ts) - t.now; GST_DEBUG ("%"PRId64", %d/%d %"PRId64" %"PRId64, t.ticks, t.rate.num, t.rate.denom, t.now, result); diff --git a/src/pipewire/node.c b/src/pipewire/node.c index 5a63b846b..229a44342 100644 --- a/src/pipewire/node.c +++ b/src/pipewire/node.c @@ -810,7 +810,7 @@ static void node_process(void *data, int status) if (!node->rt.clock) { clock_gettime(CLOCK_MONOTONIC, &ts); - q->clock.nsec = SPA_TIMESPEC_TO_TIME(&ts); + q->clock.nsec = SPA_TIMESPEC_TO_NSEC(&ts); q->clock.position = impl->next_position; q->clock.delay = 0; }