From 5dd9dd13d40feeb750280ab374f0514ac2d02897 Mon Sep 17 00:00:00 2001 From: Mikhail Baranov Date: Fri, 5 Apr 2024 12:33:01 +0200 Subject: [PATCH] Get rid off link meter reader part --- .../roc_audio/freq_estimator.cpp | 4 -- .../roc_pipeline/receiver_session.cpp | 6 --- src/internal_modules/roc_rtp/link_meter.cpp | 51 +------------------ src/internal_modules/roc_rtp/link_meter.h | 15 ------ src/tests/roc_rtp/test_link_meter.cpp | 3 +- 5 files changed, 3 insertions(+), 76 deletions(-) diff --git a/src/internal_modules/roc_audio/freq_estimator.cpp b/src/internal_modules/roc_audio/freq_estimator.cpp index f560f7529..797dac426 100644 --- a/src/internal_modules/roc_audio/freq_estimator.cpp +++ b/src/internal_modules/roc_audio/freq_estimator.cpp @@ -224,9 +224,5 @@ static const char* fe_profile_to_str(FreqEstimatorProfile profile) { return ""; } -// TODO: -// * overshoot -- почему аккумулятор должен быть равен площади ошибки? -// * stable точно норм определяется аккумулятором? - } // namespace audio } // namespace roc diff --git a/src/internal_modules/roc_pipeline/receiver_session.cpp b/src/internal_modules/roc_pipeline/receiver_session.cpp index 07ac6d5e7..29c856f3a 100644 --- a/src/internal_modules/roc_pipeline/receiver_session.cpp +++ b/src/internal_modules/roc_pipeline/receiver_session.cpp @@ -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_) { @@ -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( diff --git a/src/internal_modules/roc_rtp/link_meter.cpp b/src/internal_modules/roc_rtp/link_meter.cpp index 449201764..2f2ee8d4d 100644 --- a/src/internal_modules/roc_rtp/link_meter.cpp +++ b/src/internal_modules/roc_rtp/link_meter.cpp @@ -21,10 +21,8 @@ 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) @@ -32,7 +30,6 @@ LinkMeter::LinkMeter(core::IArena& arena, , 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_) { @@ -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); @@ -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 { diff --git a/src/internal_modules/roc_rtp/link_meter.h b/src/internal_modules/roc_rtp/link_meter.h index 64499731b..67de8b955 100644 --- a/src/internal_modules/roc_rtp/link_meter.h +++ b/src/internal_modules/roc_rtp/link_meter.h @@ -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. @@ -78,21 +77,11 @@ 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; @@ -100,18 +89,15 @@ class LinkMeter : public packet::ILinkMeter, 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_; @@ -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 packet_jitter_stats_; diff --git a/src/tests/roc_rtp/test_link_meter.cpp b/src/tests/roc_rtp/test_link_meter.cpp index d8867564e..7f5f08d57 100644 --- a/src/tests/roc_rtp/test_link_meter.cpp +++ b/src/tests/roc_rtp/test_link_meter.cpp @@ -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; @@ -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) {