module-rtp: Get the current stream time in a reusable manner

That way, redundant pw_stream_get_nsec() and clock_gettime()
calls can be avoided.
This commit is contained in:
Carlos Rafael Giani 2025-10-23 20:08:22 +02:00
parent 3e0f4daf60
commit 955c9ae837
7 changed files with 40 additions and 20 deletions

View file

@ -233,7 +233,8 @@ static void rtp_audio_process_playback(void *data)
pw_stream_queue_buffer(impl->stream, buf);
}
static int rtp_audio_receive(struct impl *impl, uint8_t *buffer, ssize_t len)
static int rtp_audio_receive(struct impl *impl, uint8_t *buffer, ssize_t len,
uint64_t current_time)
{
struct rtp_header *hdr;
ssize_t hlen, plen;
@ -273,7 +274,7 @@ static int rtp_audio_receive(struct impl *impl, uint8_t *buffer, ssize_t len)
timestamp = ntohl(hdr->timestamp) - impl->ts_offset;
impl->receiving = true;
impl->last_recv_timestamp = pw_stream_get_nsec(impl->stream);
impl->last_recv_timestamp = current_time;
plen = len - hlen;
samples = plen / stride;

View file

@ -318,7 +318,8 @@ static int rtp_midi_receive_midi(struct impl *impl, uint8_t *packet, uint32_t ti
return 0;
}
static int rtp_midi_receive(struct impl *impl, uint8_t *buffer, ssize_t len)
static int rtp_midi_receive(struct impl *impl, uint8_t *buffer, ssize_t len,
uint64_t current_time)
{
struct rtp_header *hdr;
ssize_t hlen;

View file

@ -99,7 +99,8 @@ static void rtp_opus_process_playback(void *data)
pw_stream_queue_buffer(impl->stream, buf);
}
static int rtp_opus_receive(struct impl *impl, uint8_t *buffer, ssize_t len)
static int rtp_opus_receive(struct impl *impl, uint8_t *buffer, ssize_t len,
uint64_t current_time)
{
struct rtp_header *hdr;
ssize_t hlen, plen;

View file

@ -151,7 +151,8 @@ struct impl {
* access below for the reason why. */
uint8_t timer_running;
int (*receive_rtp)(struct impl *impl, uint8_t *buffer, ssize_t len);
int (*receive_rtp)(struct impl *impl, uint8_t *buffer, ssize_t len,
uint64_t current_time);
/* Used for resetting the ring buffer before the stream starts, to prevent
* reading from uninitialized memory. This can otherwise happen in direct
* timestamp mode when the read index is set to an uninitialized location.
@ -1036,10 +1037,17 @@ int rtp_stream_update_properties(struct rtp_stream *s, const struct spa_dict *di
return pw_stream_update_properties(impl->stream, dict);
}
int rtp_stream_receive_packet(struct rtp_stream *s, uint8_t *buffer, size_t len)
int rtp_stream_receive_packet(struct rtp_stream *s, uint8_t *buffer, size_t len,
uint64_t current_time)
{
struct impl *impl = (struct impl*)s;
return impl->receive_rtp(impl, buffer, len);
return impl->receive_rtp(impl, buffer, len, current_time);
}
uint64_t rtp_stream_get_nsec(struct rtp_stream *s)
{
struct impl *impl = (struct impl*)s;
return pw_stream_get_nsec(impl->stream);
}
uint64_t rtp_stream_get_time(struct rtp_stream *s, uint32_t *rate)

View file

@ -62,7 +62,10 @@ void rtp_stream_destroy(struct rtp_stream *s);
int rtp_stream_update_properties(struct rtp_stream *s, const struct spa_dict *dict);
int rtp_stream_receive_packet(struct rtp_stream *s, uint8_t *buffer, size_t len);
int rtp_stream_receive_packet(struct rtp_stream *s, uint8_t *buffer, size_t len,
uint64_t current_time);
uint64_t rtp_stream_get_nsec(struct rtp_stream *s);
uint64_t rtp_stream_get_time(struct rtp_stream *s, uint32_t *rate);