Skip to content

Commit

Permalink
Get rid off link meter reader part
Browse files Browse the repository at this point in the history
  • Loading branch information
baranovmv committed Apr 6, 2024
1 parent a5ed75e commit 5dd9dd1
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 76 deletions.
4 changes: 0 additions & 4 deletions src/internal_modules/roc_audio/freq_estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,5 @@ static const char* fe_profile_to_str(FreqEstimatorProfile profile) {
return "<invalid>";
}

// TODO:
// * overshoot -- почему аккумулятор должен быть равен площади ошибки?
// * stable точно норм определяется аккумулятором?

} // namespace audio
} // namespace roc
6 changes: 0 additions & 6 deletions src/internal_modules/roc_pipeline/receiver_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ ReceiverSession::ReceiverSession(
}
pkt_reader = delayed_reader_.get();

source_meter_->set_reader(*pkt_reader);
pkt_reader = source_meter_.get();

if (session_config.fec_decoder.scheme != packet::FEC_None) {
repair_queue_.reset(new (repair_queue_) packet::SortedQueue(0));
if (!repair_queue_) {
Expand Down Expand Up @@ -135,9 +132,6 @@ ReceiverSession::ReceiverSession(
return;
}
pkt_reader = fec_filter_.get();

repair_meter_->set_reader(*pkt_reader);
pkt_reader = repair_meter_.get();
}

timestamp_injector_.reset(new (timestamp_injector_) rtp::TimestampInjector(
Expand Down
51 changes: 2 additions & 49 deletions src/internal_modules/roc_rtp/link_meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@ LinkMeter::LinkMeter(core::IArena& arena,
: encoding_map_(encoding_map)
, encoding_(NULL)
, writer_(NULL)
, reader_(NULL)
, sample_spec_(sample_spec)
, first_packet_jitter_(true)
, first_packet_losses_(true)
, win_len_(latency_config.tuner_profile == audio::LatencyTunerProfile_Responsive ?
10000 : 30000)
, has_metrics_(false)
, first_seqnum_(0)
, last_seqnum_hi_(0)
, last_seqnum_lo_(0)
, processed_packets_(0)
, seqnum_prev_loss_(0)
, prev_packet_enq_ts_(-1)
, prev_stream_timestamp_(0)
, packet_jitter_stats_(arena, win_len_) {
Expand Down Expand Up @@ -90,33 +87,10 @@ status::StatusCode LinkMeter::write(const packet::PacketPtr& packet) {
return writer_->write(packet);
}

status::StatusCode LinkMeter::read(packet::PacketPtr& packet) {
if (!reader_) {
roc_panic("link meter: forgot to call set_reader()");
}

const status::StatusCode code = reader_->read(packet);
if (code != status::StatusOK) {
return code;
}

if (packet->rtp()) {
update_losses_(*packet);
} else {
roc_panic("link meter: non-rtp packet on reader input");
}

return status::StatusOK;
}

void LinkMeter::set_writer(packet::IWriter& writer) {
writer_ = &writer;
}

void LinkMeter::set_reader(packet::IReader& reader) {
reader_ = &reader;
}

void LinkMeter::update_jitter_(const packet::Packet& packet) {
static std::ofstream fout("/tmp/jitt.log", std::ios::out);

Expand Down Expand Up @@ -175,35 +149,14 @@ void LinkMeter::update_jitter_(const packet::Packet& packet) {

prev_packet_enq_ts_ = packet.udp()->enqueue_ts;
prev_stream_timestamp_ = packet.rtp()->stream_timestamp;
processed_packets_++;

metrics_.ext_first_seqnum = first_seqnum_;
metrics_.ext_last_seqnum = last_seqnum_hi_ + last_seqnum_lo_;
metrics_.total_packets = metrics_.ext_last_seqnum - first_seqnum_ + 1;

has_metrics_ = true;
}

void LinkMeter::update_losses_(const packet::Packet& packet) {
static std::ofstream fout("/tmp/loss.log", std::ios::out);

// Do not calculate losses on recovered packets.
if (packet.has_flags(packet::Packet::FlagRestored)) {
return;
}

processed_packets_++;

const packet::seqnum_t pkt_seqnum = packet.rtp()->seqnum;
if (packet::seqnum_diff(pkt_seqnum, last_seqnum_lo_) > 0) {
roc_panic("link meter: seqnum was not processed in writer part");
}
metrics_.lost_packets = (ssize_t)metrics_.total_packets - processed_packets_;

const ssize_t gap = packet::seqnum_diff(pkt_seqnum, seqnum_prev_loss_ + 1);

fout << pkt_seqnum << ", " << gap << std::endl;

seqnum_prev_loss_ = pkt_seqnum;
has_metrics_ = true;
}

core::nanoseconds_t rtp::LinkMeter::mean_jitter() const {
Expand Down
15 changes: 0 additions & 15 deletions src/internal_modules/roc_rtp/link_meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ namespace rtp {
//! writer/reader, and updates metrics.
class LinkMeter : public packet::ILinkMeter,
public packet::IWriter,
public packet::IReader,
public core::NonCopyable<> {
public:
//! Initialize.
Expand Down Expand Up @@ -78,40 +77,27 @@ class LinkMeter : public packet::ILinkMeter,
//! Invoked early in pipeline right after the packet is received.
virtual ROC_ATTR_NODISCARD status::StatusCode write(const packet::PacketPtr& packet);

//! Read packet and update metrics.
//! @remarks
//! Invoked late in pipeline right before the packet is decoded.
virtual ROC_ATTR_NODISCARD status::StatusCode read(packet::PacketPtr& packet);

//! Set nested packet writer.
//! @remarks
//! Should be called before first write() call.
void set_writer(packet::IWriter& writer);

//! Set nested packet reader.
//! @remarks
//! Should be called before first read() call.
void set_reader(packet::IReader& reader);

//! Get metrics.
core::nanoseconds_t mean_jitter() const;

size_t running_window_len() const;

private:
void update_jitter_(const packet::Packet& packet);
void update_losses_(const packet::Packet& packet);

const EncodingMap& encoding_map_;
const Encoding* encoding_;

packet::IWriter* writer_;
packet::IReader* reader_;

const audio::SampleSpec sample_spec_;

bool first_packet_jitter_;
bool first_packet_losses_;
const size_t win_len_;
bool has_metrics_;

Expand All @@ -122,7 +108,6 @@ class LinkMeter : public packet::ILinkMeter,
uint16_t last_seqnum_lo_;

ssize_t processed_packets_;
packet::seqnum_t seqnum_prev_loss_;
core::nanoseconds_t prev_packet_enq_ts_;
packet::stream_timestamp_t prev_stream_timestamp_;
core::MovStats<core::nanoseconds_t> packet_jitter_stats_;
Expand Down
3 changes: 1 addition & 2 deletions src/tests/roc_rtp/test_link_meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ TEST(link_meter, losses_test) {
latency_config.tuner_profile = audio::LatencyTunerProfile_Responsive;
LinkMeter meter(arena, encoding_map, sample_spec, latency_config);
meter.set_writer(queue);
meter.set_reader(queue);
const size_t num_packets = Duration * 2 * (1 << 16);
size_t total_losses = 0;
size_t fract_losses_cntr = 0;
Expand All @@ -352,7 +351,7 @@ TEST(link_meter, losses_test) {
}

packet::PacketPtr pr;
CHECK_EQUAL(status::StatusOK, meter.read(pr));
CHECK_EQUAL(status::StatusOK, queue.read(pr));
CHECK_EQUAL(pr->rtp()->seqnum, p->rtp()->seqnum);

if (i > 0) {
Expand Down

0 comments on commit 5dd9dd1

Please sign in to comment.