Improve TIMESPEC_TO_TIME

Add explicit TO_NSEC and TO_USEC versions to make it clearer and to
allow for some optimizations.
This commit is contained in:
Wim Taymans 2018-11-07 09:56:24 +01:00
parent bf6843743a
commit 088ee9f09e
8 changed files with 20 additions and 18 deletions

View file

@ -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)))

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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;
}