Skip to content

Commit

Permalink
gh-14 rtcp::Reporter refinements
Browse files Browse the repository at this point in the history
- Unify types of report fields: use nanoseconds and unsized
  types where possible

- Query streams before processing reports, not only before
  generating reports.

- Fill ext_first_seqnum from reports.

- Adjust tests to the above changes.

- Cleanup headers helpers.

- Simplify RTT estimator metrics.
  • Loading branch information
gavv committed Jan 26, 2024
1 parent 6ecc6fb commit ffe0e87
Show file tree
Hide file tree
Showing 21 changed files with 1,071 additions and 572 deletions.
4 changes: 4 additions & 0 deletions src/internal_modules/roc_audio/packetizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ bool Packetizer::is_valid() const {
return valid_;
}

size_t Packetizer::sample_rate() const {
return sample_spec_.sample_rate();
}

PacketizerMetrics Packetizer::metrics() const {
return metrics_;
}
Expand Down
3 changes: 3 additions & 0 deletions src/internal_modules/roc_audio/packetizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class Packetizer : public IFrameWriter, public core::NonCopyable<> {
//! Check if object is successfully constructed.
bool is_valid() const;

//! Get sample rate.
size_t sample_rate() const;

//! Get metrics.
PacketizerMetrics metrics() const;

Expand Down
56 changes: 56 additions & 0 deletions src/internal_modules/roc_packet/units.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2015 Roc Streaming authors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include "roc_packet/units.h"
#include "roc_core/macro_helpers.h"
#include "roc_core/panic.h"

namespace roc {
namespace packet {

stream_timestamp_t ns_2_stream_timestamp(const core::nanoseconds_t ns,
const size_t sample_rate) {
roc_panic_if_msg(ns < 0, "units: ns should not be negative");
roc_panic_if_msg(sample_rate == 0, "units: sample_rate should not be zero");

float ts = roundf(float(ns) / core::Second * sample_rate);

ts = std::min(ts, (float)ROC_MAX_OF(stream_timestamp_t));
ts = std::max(ts, (float)ROC_MIN_OF(stream_timestamp_t));

return (stream_timestamp_t)ts;
}

core::nanoseconds_t stream_timestamp_2_ns(stream_timestamp_t ts,
const size_t sample_rate) {
roc_panic_if_msg(sample_rate == 0, "units: sample_rate should not be zero");

return (core::nanoseconds_t)roundf(float(ts) / sample_rate * core::Second);
}

stream_timestamp_diff_t ns_2_stream_timestamp_delta(const core::nanoseconds_t ns,
const size_t sample_rate) {
roc_panic_if_msg(sample_rate == 0, "units: sample_rate should not be zero");

float ts = roundf(float(ns) / core::Second * sample_rate);

ts = std::min(ts, (float)ROC_MAX_OF(stream_timestamp_diff_t));
ts = std::max(ts, (float)ROC_MIN_OF(stream_timestamp_diff_t));

return (stream_timestamp_diff_t)ts;
}

core::nanoseconds_t stream_timestamp_delta_2_ns(stream_timestamp_diff_t ts,
const size_t sample_rate) {
roc_panic_if_msg(sample_rate == 0, "units: sample_rate should not be zero");

return (core::nanoseconds_t)roundf(float(ts) / sample_rate * core::Second);
}

} // namespace packet
} // namespace roc
14 changes: 14 additions & 0 deletions src/internal_modules/roc_packet/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ inline bool stream_timestamp_le(const stream_timestamp_t a, const stream_timesta
return stream_timestamp_diff(a, b) <= 0;
}

//! Convert nanoseconds to stream timestamp.
stream_timestamp_t ns_2_stream_timestamp(core::nanoseconds_t ns, size_t sample_rate);

//! Convert stream timestamp.to nanoseconds.
core::nanoseconds_t stream_timestamp_2_ns(stream_timestamp_t ts, size_t sample_rate);

//! Convert nanoseconds to stream timestamp delta.
stream_timestamp_diff_t ns_2_stream_timestamp_delta(core::nanoseconds_t ns,
size_t sample_rate);

//! Convert stream timestamp.delta to nanoseconds.
core::nanoseconds_t stream_timestamp_delta_2_ns(stream_timestamp_diff_t ts,
size_t sample_rate);

//! Packet sequence number.
//! @remarks
//! Defines position of packet within stream.
Expand Down
7 changes: 4 additions & 3 deletions src/internal_modules/roc_pipeline/receiver_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ReceiverSession::ReceiverSession(

packet::IWriter* pwriter = source_queue_.get();

source_meter_.reset(new (source_meter_) rtp::LinkMeter());
source_meter_.reset(new (source_meter_) rtp::LinkMeter(encoding_map));
if (!source_meter_) {
return;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ ReceiverSession::ReceiverSession(
return;
}

repair_meter_.reset(new (repair_meter_) rtp::LinkMeter());
repair_meter_.reset(new (repair_meter_) rtp::LinkMeter(encoding_map));
if (!repair_meter_) {
return;
}
Expand Down Expand Up @@ -306,6 +306,7 @@ void ReceiverSession::generate_reports(const char* report_cname,
report.sender_source_id =
packet_router_->get_source_id(packet::Packet::FlagAudio);
report.report_timestamp = report_time;
report.sample_rate = link_metrics.sample_rate;
report.ext_first_seqnum = link_metrics.ext_first_seqnum;
report.ext_last_seqnum = link_metrics.ext_last_seqnum;
report.fract_loss = link_metrics.fract_loss;
Expand All @@ -328,12 +329,12 @@ void ReceiverSession::generate_reports(const char* report_cname,
report.sender_source_id =
packet_router_->get_source_id(packet::Packet::FlagRepair);
report.report_timestamp = report_time;
report.sample_rate = link_metrics.sample_rate;
report.ext_first_seqnum = link_metrics.ext_first_seqnum;
report.ext_last_seqnum = link_metrics.ext_last_seqnum;
report.fract_loss = link_metrics.fract_loss;
report.cum_loss = link_metrics.cum_loss;
report.jitter = link_metrics.jitter;
report.e2e_latency = 0;

reports++;
n_reports--;
Expand Down
1 change: 1 addition & 0 deletions src/internal_modules/roc_pipeline/sender_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ rtcp::SendReport SenderSession::query_send_stream(core::nanoseconds_t report_tim
report.sender_source_id = identity_->ssrc();
report.report_timestamp = report_time;
report.stream_timestamp = timestamp_extractor_->get_mapping(report_time);
report.sample_rate = packetizer_->sample_rate();
report.packet_count = (uint32_t)packet_metrics.packet_count;
report.byte_count = (uint32_t)packet_metrics.payload_count;

Expand Down
9 changes: 9 additions & 0 deletions src/internal_modules/roc_rtcp/communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ void Communicator::process_extended_report_(const XrTraverser& xr) {
reporter_.process_rrtr_block(xr.packet(), iter.get_rrtr());
} break;

case XrTraverser::Iterator::MEASUREMENT_INFO_BLOCK: {
// Measurement Info is extended receiver report.
reporter_.process_measurement_info_block(xr.packet(),
iter.get_measurement_info());
} break;

case XrTraverser::Iterator::DELAY_METRICS_BLOCK: {
// Delay Metrics is extended receiver report.
reporter_.process_delay_metrics_block(xr.packet(), iter.get_delay_metrics());
Expand Down Expand Up @@ -682,6 +688,7 @@ void Communicator::generate_standard_report_(Builder& bld) {
if (!next_recv_stream_(stream_index)) {
break;
}

header::ReceptionReportBlock blk;
reporter_.generate_reception_block(dest_addr_index_, stream_index, blk);

Expand All @@ -706,6 +713,7 @@ void Communicator::generate_standard_report_(Builder& bld) {
if (!next_recv_stream_(stream_index)) {
break;
}

header::ReceptionReportBlock blk;
reporter_.generate_reception_block(dest_addr_index_, stream_index, blk);

Expand Down Expand Up @@ -736,6 +744,7 @@ void Communicator::generate_extended_report_(Builder& bld) {
if (!next_send_stream_(stream_index)) {
break;
}

header::XrDlrrSubblock blk;
reporter_.generate_dlrr_subblock(dest_addr_index_, stream_index, blk);

Expand Down
Loading

0 comments on commit ffe0e87

Please sign in to comment.