From 892b57c55d7cf2653ee4ba463e462862d946eb92 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 19 Jul 2018 16:55:00 +0200 Subject: [PATCH] stream: add capture queued time calculation Take the size of a newly captured buffer as the difference between previous and current tick and use this to calculate the queued size. --- src/pipewire/stream.c | 15 +++++++++++---- src/pipewire/stream.h | 10 +++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index 907b96b29..88ace06b8 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -657,9 +657,12 @@ static int impl_node_process_input(struct spa_node *node) struct pw_stream *stream = &impl->this; struct spa_io_buffers *io = impl->io; struct buffer *b; + uint64_t size; - pw_log_trace("stream %p: process in %d %d %"PRIu64" %"PRIi64, stream, - io->status, io->buffer_id, impl->time.ticks, impl->time.delay); + size = impl->time.ticks - impl->dequeued.incount; + + pw_log_trace("stream %p: process in %d %d %"PRIu64" %"PRIi64" %"PRIu64, stream, + io->status, io->buffer_id, impl->time.ticks, impl->time.delay, size); if (io->status != SPA_STATUS_HAVE_BUFFER) goto done; @@ -667,6 +670,8 @@ static int impl_node_process_input(struct spa_node *node) if ((b = get_buffer(stream, io->buffer_id)) == NULL) goto done; + b->this.size = size; + /* push new buffer */ if (push_queue(impl, &impl->dequeued, b) == 0) call_process(impl); @@ -1138,9 +1143,11 @@ int pw_stream_get_time(struct pw_stream *stream, struct pw_time *time) } while (impl->seq1 != seq); if (impl->direction == SPA_DIRECTION_INPUT) - time->queued = time->queued - impl->dequeued.outcount; + time->queued = (int64_t)(time->queued - impl->dequeued.outcount); else - time->queued = impl->queued.incount - time->queued; + time->queued = (int64_t)(impl->queued.incount - time->queued); + + pw_log_trace("%ld %d/%d %ld", time->ticks, time->rate.num, time->rate.denom, time->queued); return 0; } diff --git a/src/pipewire/stream.h b/src/pipewire/stream.h index 73b935317..20461ab5b 100644 --- a/src/pipewire/stream.h +++ b/src/pipewire/stream.h @@ -164,9 +164,13 @@ enum pw_stream_state { }; struct pw_buffer { - struct spa_buffer *buffer; /* the spa buffer */ - void *user_data; /* user data attached to the buffer */ - uint64_t size; /* size to keep track of queued size */ + struct spa_buffer *buffer; /**< the spa buffer */ + void *user_data; /**< user data attached to the buffer */ + uint64_t size; /**< For input streams, this field is set by pw_stream + * with the duration of the buffer in ticks. + * For output streams, this field is set by the user. + * This field is added for all queued buffers and + * returned in the time info. */ }; /** Events for a stream */