Skip to content

Commit

Permalink
Refactor and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
baranovmv committed May 7, 2024
1 parent f372581 commit 2ee9ab4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 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
12 changes: 7 additions & 5 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,15 +33,17 @@ 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;

UDP();

//! 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 enqueue_ts;
};

} // namespace packet
Expand Down
1 change: 0 additions & 1 deletion src/internal_modules/roc_pipeline/receiver_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ audio::IFrameReader& ReceiverSession::frame_reader() {
status::StatusCode ReceiverSession::route_packet(const packet::PacketPtr& packet) {
roc_panic_if(!is_valid());

packet->udp()->enqueue_ts = core::timestamp(core::ClockUnix);
return packet_router_->write(packet);
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/roc_rtp/test_link_meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ packet::PacketPtr new_packet(packet::seqnum_t sn) {
packet->add_flags(packet::Packet::FlagRTP | packet::Packet::FlagUDP);
packet->rtp()->payload_type = PayloadType_L16_Stereo;
packet->rtp()->seqnum = sn;
packet->udp()->enqueue_ts = 666;
packet->udp()->queue_ts = 666;

return packet;
}
Expand Down

0 comments on commit 2ee9ab4

Please sign in to comment.