Skip to content

Commit

Permalink
roc-streaminggh-688 Issue 688: UDP packet has timestamp field
Browse files Browse the repository at this point in the history
  • Loading branch information
baranovmv authored and gavv committed May 8, 2024
1 parent 7135e84 commit d6a5801
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion docs/sphinx/internals/timestamps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ Timestamps
Types of timestamps
===================

:doc:`Packets and frames </internals/packets_frames>` have three major types of timestamps:
:doc:`Packets and frames </internals/packets_frames>` have four major types of timestamps:

* STS - stream timestamp
* CTS - capture timestamp
* RTS - receive timestamp
* QTS - queue timestamp

**Stream timestamp** (STS) describes position of the first sample in packet or frame using abstract stream clock.

Expand All @@ -37,6 +38,10 @@ The clock for RTS is the same as for CTS: local Unix-time UTC clock, counting na

This timestamp is used only on receiver and only for packets.

**Queue timestamp** (QTS) is the time when the packet was transferred to a local queue of a sink-thread. The main difference with RTS is thread-switch time.

This timestamp is used only on receiver and only for packets.

Use of timestamps
=================

Expand Down
4 changes: 4 additions & 0 deletions src/internal_modules/roc_packet/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ status::StatusCode Router::write(const PacketPtr& packet) {

if (Route* route = find_route_(packet->flags())) {
if (allow_route_(*route, *packet)) {
if (packet->udp()) {
packet->udp()->queue_ts = core::timestamp(core::ClockUnix);
}

return route->writer->write(packet);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace roc {
namespace packet {

UDP::UDP()
: receive_timestamp(0) {
: receive_timestamp(0)
, queue_ts(0) {
memset(&request, 0, sizeof(request));
}

Expand Down
7 changes: 7 additions & 0 deletions src/internal_modules/roc_packet/target_libuv/roc_packet/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ struct UDP {
//! Packet receive timestamp (RTS), nanoseconds since Unix epoch.
core::nanoseconds_t receive_timestamp;

//! Timestamp in ns since unix-epoch. It points to a moment when
//! the packet was transferred to a sink-thread, that "consumes"
//! this packet. The reason to have it separate is that this
//! allows us to account additional jitter introduced by
//! thread-switch time.
core::nanoseconds_t queue_ts;

//! Sender request state.
uv_udp_send_t request;

Expand Down
3 changes: 2 additions & 1 deletion src/tests/roc_rtp/test_link_meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ packet::PacketPtr new_packet(packet::seqnum_t sn) {
packet::PacketPtr packet = packet_factory.new_packet();
CHECK(packet);

packet->add_flags(packet::Packet::FlagRTP);
packet->add_flags(packet::Packet::FlagRTP | packet::Packet::FlagUDP);
packet->rtp()->payload_type = PayloadType_L16_Stereo;
packet->rtp()->seqnum = sn;
packet->udp()->queue_ts = 666;

return packet;
}
Expand Down

0 comments on commit d6a5801

Please sign in to comment.