Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparation for E2E latency tuning #786

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ bool Thread::enable_realtime() {
errno_to_str(err).c_str());
return false;
}
roc_log(LogDebug, "thread: set realtime priority");

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ NetworkLoop::NetworkLoop(core::IPool& packet_pool,
task_sem_.data = this;
task_sem_initialized_ = true;

enable_realtime();
if (!(started_ = Thread::start())) {
init_status_ = status::StatusErrThread;
return;
Expand Down
9 changes: 4 additions & 5 deletions src/internal_modules/roc_pipeline/receiver_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ packet::IWriter& ReceiverEndpoint::inbound_writer() {
return *this;
}

status::StatusCode ReceiverEndpoint::pull_packets(core::nanoseconds_t current_time) {
status::StatusCode ReceiverEndpoint::pull_packets() {
roc_panic_if(init_status_ != status::StatusOK);

roc_panic_if(!parser_);
Expand All @@ -209,7 +209,7 @@ status::StatusCode ReceiverEndpoint::pull_packets(core::nanoseconds_t current_ti
// queue were added in a very short time or are being added currently. It's
// acceptable to consider such packets late and pull them next time.
while (packet::PacketPtr packet = inbound_queue_.try_pop_front_exclusive()) {
const status::StatusCode code = handle_packet_(packet, current_time);
const status::StatusCode code = handle_packet_(packet);
state_tracker_.unregister_packet();

if (code != status::StatusOK) {
Expand All @@ -220,14 +220,13 @@ status::StatusCode ReceiverEndpoint::pull_packets(core::nanoseconds_t current_ti
return status::StatusOK;
}

status::StatusCode ReceiverEndpoint::handle_packet_(const packet::PacketPtr& packet,
core::nanoseconds_t current_time) {
status::StatusCode ReceiverEndpoint::handle_packet_(const packet::PacketPtr& packet) {
if (!parser_->parse(*packet, packet->buffer())) {
roc_log(LogDebug, "receiver endpoint: dropping bad packet: can't parse");
return status::StatusOK;
}

const status::StatusCode code = session_group_.route_packet(packet, current_time);
const status::StatusCode code = session_group_.route_packet(packet);

if (code == status::StatusNoRoute) {
roc_log(LogDebug, "receiver endpoint: dropping bad packet: can't route");
Expand Down
5 changes: 2 additions & 3 deletions src/internal_modules/roc_pipeline/receiver_endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,12 @@ class ReceiverEndpoint : public core::RefCounted<ReceiverEndpoint, core::ArenaAl
//! Packets are written to inbound_writer() from network thread.
//! They don't appear in pipeline immediately. Instead, pipeline thread
//! should periodically call pull_packets() to make them available.
ROC_ATTR_NODISCARD status::StatusCode pull_packets(core::nanoseconds_t current_time);
ROC_ATTR_NODISCARD status::StatusCode pull_packets();

private:
virtual ROC_ATTR_NODISCARD status::StatusCode write(const packet::PacketPtr& packet);

status::StatusCode handle_packet_(const packet::PacketPtr& packet,
core::nanoseconds_t current_time);
status::StatusCode handle_packet_(const packet::PacketPtr& packet);

const address::Protocol proto_;

Expand Down
12 changes: 5 additions & 7 deletions src/internal_modules/roc_pipeline/receiver_session_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ReceiverSessionGroup::create_control_pipeline(ReceiverEndpoint* control_endpoint
// and later when we call generate_packets() or process_packets().
rtcp_communicator_.reset(new (rtcp_communicator_) rtcp::Communicator(
source_config_.common.rtcp, *this, *control_endpoint->outbound_writer(),
*control_endpoint->outbound_composer(), packet_factory_, arena_));
*control_endpoint->outbound_composer(), packet_factory_, arena_, dumper_));

const status::StatusCode code = rtcp_communicator_->init_status();
if (code != status::StatusOK) {
Expand Down Expand Up @@ -140,12 +140,11 @@ void ReceiverSessionGroup::reclock_sessions(core::nanoseconds_t playback_time) {
}
}

status::StatusCode ReceiverSessionGroup::route_packet(const packet::PacketPtr& packet,
core::nanoseconds_t current_time) {
status::StatusCode ReceiverSessionGroup::route_packet(const packet::PacketPtr& packet) {
roc_panic_if(init_status_ != status::StatusOK);

if (packet->has_flags(packet::Packet::FlagControl)) {
return route_control_packet_(packet, current_time);
return route_control_packet_(packet);
}

return route_transport_packet_(packet);
Expand Down Expand Up @@ -344,15 +343,14 @@ ReceiverSessionGroup::route_transport_packet_(const packet::PacketPtr& packet) {
}

status::StatusCode
ReceiverSessionGroup::route_control_packet_(const packet::PacketPtr& packet,
core::nanoseconds_t current_time) {
ReceiverSessionGroup::route_control_packet_(const packet::PacketPtr& packet) {
if (!rtcp_communicator_) {
roc_panic("session group: rtcp communicator is null");
}

// This will invoke IParticipant methods implemented by us,
// in particular notify_recv_stream() and maybe halt_recv_stream().
return rtcp_communicator_->process_packet(packet, current_time);
return rtcp_communicator_->process_packet(packet);
}

bool ReceiverSessionGroup::can_create_session_(const packet::PacketPtr& packet) {
Expand Down
6 changes: 2 additions & 4 deletions src/internal_modules/roc_pipeline/receiver_session_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ class ReceiverSessionGroup : public core::NonCopyable<>, private rtcp::IParticip
void reclock_sessions(core::nanoseconds_t playback_time);

//! Route packet to session.
ROC_ATTR_NODISCARD status::StatusCode route_packet(const packet::PacketPtr& packet,
core::nanoseconds_t current_time);
ROC_ATTR_NODISCARD status::StatusCode route_packet(const packet::PacketPtr& packet);

//! Get number of sessions in group.
size_t num_sessions() const;
Expand Down Expand Up @@ -130,8 +129,7 @@ class ReceiverSessionGroup : public core::NonCopyable<>, private rtcp::IParticip
virtual void halt_recv_stream(packet::stream_source_t send_source_id);

status::StatusCode route_transport_packet_(const packet::PacketPtr& packet);
status::StatusCode route_control_packet_(const packet::PacketPtr& packet,
core::nanoseconds_t current_time);
status::StatusCode route_control_packet_(const packet::PacketPtr& packet);

bool can_create_session_(const packet::PacketPtr& packet);

Expand Down
6 changes: 3 additions & 3 deletions src/internal_modules/roc_pipeline/receiver_slot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ status::StatusCode ReceiverSlot::refresh(core::nanoseconds_t current_time,
status::StatusCode code = status::NoStatus;

if (source_endpoint_) {
if ((code = source_endpoint_->pull_packets(current_time)) != status::StatusOK) {
if ((code = source_endpoint_->pull_packets()) != status::StatusOK) {
return code;
}
}

if (repair_endpoint_) {
if ((code = repair_endpoint_->pull_packets(current_time)) != status::StatusOK) {
if ((code = repair_endpoint_->pull_packets()) != status::StatusOK) {
return code;
}
}

if (control_endpoint_) {
if ((code = control_endpoint_->pull_packets(current_time)) != status::StatusOK) {
if ((code = control_endpoint_->pull_packets()) != status::StatusOK) {
return code;
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/internal_modules/roc_pipeline/sender_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ packet::IWriter* SenderEndpoint::inbound_writer() {
return this;
}

status::StatusCode SenderEndpoint::pull_packets(core::nanoseconds_t current_time) {
status::StatusCode SenderEndpoint::pull_packets() {
roc_panic_if(init_status_ != status::StatusOK);

if (!parser_) {
Expand All @@ -197,7 +197,7 @@ status::StatusCode SenderEndpoint::pull_packets(core::nanoseconds_t current_time
// queue were added in a very short time or are being added currently. It's
// acceptable to consider such packets late and pull them next time.
while (packet::PacketPtr packet = inbound_queue_.try_pop_front_exclusive()) {
const status::StatusCode code = handle_packet_(packet, current_time);
const status::StatusCode code = handle_packet_(packet);
state_tracker_.unregister_packet();

if (code != status::StatusOK) {
Expand All @@ -208,14 +208,13 @@ status::StatusCode SenderEndpoint::pull_packets(core::nanoseconds_t current_time
return status::StatusOK;
}

status::StatusCode SenderEndpoint::handle_packet_(const packet::PacketPtr& packet,
core::nanoseconds_t current_time) {
status::StatusCode SenderEndpoint::handle_packet_(const packet::PacketPtr& packet) {
if (!parser_->parse(*packet, packet->buffer())) {
roc_log(LogDebug, "sender endpoint: dropping bad packet: can't parse");
return status::StatusOK;
}

const status::StatusCode code = sender_session_.route_packet(packet, current_time);
const status::StatusCode code = sender_session_.route_packet(packet);

if (code == status::StatusNoRoute) {
roc_log(LogDebug, "sender endpoint: dropping bad packet: can't route");
Expand Down
5 changes: 2 additions & 3 deletions src/internal_modules/roc_pipeline/sender_endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ class SenderEndpoint : public core::NonCopyable<>, private packet::IWriter {
//! Packets are written to inbound_writer() from network thread.
//! They don't appear in pipeline immediately. Instead, pipeline thread
//! should periodically call pull_packets() to make them available.
ROC_ATTR_NODISCARD status::StatusCode pull_packets(core::nanoseconds_t current_time);
ROC_ATTR_NODISCARD status::StatusCode pull_packets();

private:
virtual ROC_ATTR_NODISCARD status::StatusCode write(const packet::PacketPtr& packet);

status::StatusCode handle_packet_(const packet::PacketPtr& packet,
core::nanoseconds_t current_time);
status::StatusCode handle_packet_(const packet::PacketPtr& packet);

const address::Protocol proto_;

Expand Down
13 changes: 5 additions & 8 deletions src/internal_modules/roc_pipeline/sender_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ SenderSession::create_control_pipeline(SenderEndpoint* control_endpoint) {

rtcp_communicator_.reset(new (rtcp_communicator_) rtcp::Communicator(
sink_config_.rtcp, *this, control_endpoint->outbound_writer(),
control_endpoint->outbound_composer(), packet_factory_, arena_));
control_endpoint->outbound_composer(), packet_factory_, arena_, dumper_));

const status::StatusCode code = rtcp_communicator_->init_status();
if (code != status::StatusOK) {
Expand Down Expand Up @@ -281,8 +281,7 @@ status::StatusCode SenderSession::refresh(core::nanoseconds_t current_time,
return status::StatusOK;
}

status::StatusCode SenderSession::route_packet(const packet::PacketPtr& packet,
core::nanoseconds_t current_time) {
status::StatusCode SenderSession::route_packet(const packet::PacketPtr& packet) {
roc_panic_if(init_status_ != status::StatusOK);

if (fail_status_ != status::NoStatus) {
Expand All @@ -294,7 +293,7 @@ status::StatusCode SenderSession::route_packet(const packet::PacketPtr& packet,
roc_panic("sender session: unexpected non-control packet");
}

return route_control_packet_(packet, current_time);
return route_control_packet_(packet);
}

status::StatusCode SenderSession::write(audio::Frame& frame) {
Expand Down Expand Up @@ -439,15 +438,13 @@ void SenderSession::start_feedback_monitor_() {
feedback_monitor_->start();
}

status::StatusCode
SenderSession::route_control_packet_(const packet::PacketPtr& packet,
core::nanoseconds_t current_time) {
status::StatusCode SenderSession::route_control_packet_(const packet::PacketPtr& packet) {
if (!rtcp_communicator_) {
roc_panic("sender session: rtcp communicator is null");
}

// This will invoke IParticipant methods implemented by us.
return rtcp_communicator_->process_packet(packet, current_time);
return rtcp_communicator_->process_packet(packet);
}

} // namespace pipeline
Expand Down
6 changes: 2 additions & 4 deletions src/internal_modules/roc_pipeline/sender_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ class SenderSession : public core::NonCopyable<>,
//! This way feedback packets from receiver reach sender pipeline.
//! Packets are stored inside internal pipeline queues, and then fetched
//! when frame are passed from frame_writer().
ROC_ATTR_NODISCARD status::StatusCode route_packet(const packet::PacketPtr& packet,
core::nanoseconds_t current_time);
ROC_ATTR_NODISCARD status::StatusCode route_packet(const packet::PacketPtr& packet);

//! Get slot metrics.
//! @remarks
Expand Down Expand Up @@ -133,8 +132,7 @@ class SenderSession : public core::NonCopyable<>,

void start_feedback_monitor_();

status::StatusCode route_control_packet_(const packet::PacketPtr& packet,
core::nanoseconds_t current_time);
status::StatusCode route_control_packet_(const packet::PacketPtr& packet);

core::IArena& arena_;

Expand Down
6 changes: 3 additions & 3 deletions src/internal_modules/roc_pipeline/sender_slot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,19 @@ status::StatusCode SenderSlot::refresh(core::nanoseconds_t current_time,
status::StatusCode code = status::NoStatus;

if (source_endpoint_) {
if ((code = source_endpoint_->pull_packets(current_time)) != status::StatusOK) {
if ((code = source_endpoint_->pull_packets()) != status::StatusOK) {
return code;
}
}

if (repair_endpoint_) {
if ((code = repair_endpoint_->pull_packets(current_time)) != status::StatusOK) {
if ((code = repair_endpoint_->pull_packets()) != status::StatusOK) {
return code;
}
}

if (control_endpoint_) {
if ((code = control_endpoint_->pull_packets(current_time)) != status::StatusOK) {
if ((code = control_endpoint_->pull_packets()) != status::StatusOK) {
return code;
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/internal_modules/roc_rtcp/communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "roc_core/log.h"
#include "roc_core/panic.h"
#include "roc_core/time.h"
#include "roc_dbgio/csv_dumper.h"
#include "roc_packet/ntp.h"
#include "roc_packet/units.h"
#include "roc_rtcp/headers.h"
Expand All @@ -30,12 +31,13 @@ Communicator::Communicator(const Config& config,
packet::IWriter& packet_writer,
packet::IComposer& packet_composer,
packet::PacketFactory& packet_factory,
core::IArena& arena)
core::IArena& arena,
dbgio::CsvDumper* dumper)
: packet_factory_(packet_factory)
, packet_writer_(packet_writer)
, packet_composer_(packet_composer)
, config_(config)
, reporter_(config, participant, arena)
, reporter_(config, participant, arena, dumper)
, next_deadline_(0)
, dest_addr_count_(0)
, dest_addr_index_(0)
Expand All @@ -50,7 +52,8 @@ Communicator::Communicator(const Config& config,
, processed_packet_count_(0)
, generated_packet_count_(0)
, log_limiter_(LogInterval)
, init_status_(status::NoStatus) {
, init_status_(status::NoStatus)
, dumper_(dumper) {
if ((init_status_ = reporter_.init_status()) != status::StatusOK) {
return;
}
Expand All @@ -69,14 +72,12 @@ size_t Communicator::total_streams() const {
return reporter_.total_streams();
}

status::StatusCode Communicator::process_packet(const packet::PacketPtr& packet,
core::nanoseconds_t current_time) {
status::StatusCode Communicator::process_packet(const packet::PacketPtr& packet) {
roc_panic_if(init_status_ != status::StatusOK);

roc_panic_if_msg(!packet, "rtcp communicator: null packet");
roc_panic_if_msg(!packet->udp(), "rtcp communicator: non-udp packet");
roc_panic_if_msg(!packet->rtcp(), "rtcp communicator: non-rtcp packet");
roc_panic_if_msg(current_time <= 0, "rtcp communicator: invalid timestamp");

roc_log(LogTrace, "rtcp communicator: processing incoming packet");

Expand All @@ -89,8 +90,8 @@ status::StatusCode Communicator::process_packet(const packet::PacketPtr& packet,
return status::StatusOK;
}

status::StatusCode status =
reporter_.begin_processing(packet->udp()->src_addr, current_time);
status::StatusCode status = reporter_.begin_processing(
packet->udp()->src_addr, packet->udp()->receive_timestamp);
roc_log(LogTrace, "rtcp communicator: begin_processing(): status=%s",
status::code_to_str(status));

Expand Down
9 changes: 6 additions & 3 deletions src/internal_modules/roc_rtcp/communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "roc_core/rate_limiter.h"
#include "roc_core/stddefs.h"
#include "roc_core/time.h"
#include "roc_dbgio/csv_dumper.h"
#include "roc_packet/icomposer.h"
#include "roc_packet/iwriter.h"
#include "roc_packet/packet.h"
Expand Down Expand Up @@ -61,7 +62,8 @@ class Communicator : public core::NonCopyable<> {
packet::IWriter& packet_writer,
packet::IComposer& packet_composer,
packet::PacketFactory& packet_factory,
core::IArena& arena);
core::IArena& arena,
dbgio::CsvDumper* dumper);

//! Check if the object was successfully constructed.
status::StatusCode init_status() const;
Expand All @@ -74,8 +76,7 @@ class Communicator : public core::NonCopyable<> {

//! Parse and process incoming packet.
//! Invokes IParticipant methods during processing.
ROC_ATTR_NODISCARD status::StatusCode
process_packet(const packet::PacketPtr& packet, core::nanoseconds_t current_time);
ROC_ATTR_NODISCARD status::StatusCode process_packet(const packet::PacketPtr& packet);

//! When we should generate packets next time.
//! Returns absolute time.
Expand Down Expand Up @@ -169,6 +170,8 @@ class Communicator : public core::NonCopyable<> {
core::RateLimiter log_limiter_;

status::StatusCode init_status_;

dbgio::CsvDumper* dumper_;
};

} // namespace rtcp
Expand Down
Loading
Loading