From f106180bbf8e23f7d3f5dad847c889b9104a160e Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 1 Aug 2023 11:14:35 +0200 Subject: [PATCH] packet counter: remoed unneeded packet store Not needed to store separately "current" buffer packets since it is already stored in cumulative, it is just needed to store the current buffer number. --- src/audio/codec.cpp | 1 - src/rtp/audio_decoders.cpp | 2 +- src/utils/packet_counter.cpp | 44 ++++++++++++------------------------ src/utils/packet_counter.h | 3 +-- 4 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/audio/codec.cpp b/src/audio/codec.cpp index 45985c728..cd0597123 100644 --- a/src/audio/codec.cpp +++ b/src/audio/codec.cpp @@ -325,7 +325,6 @@ audio_codec_decompress(struct audio_codec_state *s, audio_frame2 *frame, nonzero_channels += 1; } } - packet_counter_clear_current_frame(counter); if (nonzero_channels != frame->get_channel_count()) { log_msg(LOG_LEVEL_WARNING, diff --git a/src/rtp/audio_decoders.cpp b/src/rtp/audio_decoders.cpp index 7524dcd56..fa087fee2 100644 --- a/src/rtp/audio_decoders.cpp +++ b/src/rtp/audio_decoders.cpp @@ -886,7 +886,7 @@ int decode_audio_frame(struct coded_data *cdata, void *pbuf_data, struct pbuf_st task_run_async_detached(adec_compute_and_print_stats, d); decoder->t0 = t; - packet_counter_clear_cumulative(decoder->packet_counter); + packet_counter_clear(decoder->packet_counter); } DEBUG_TIMER_START(audio_decode_compute_autoscale); diff --git a/src/utils/packet_counter.cpp b/src/utils/packet_counter.cpp index ac2734b92..15f08e10c 100644 --- a/src/utils/packet_counter.cpp +++ b/src/utils/packet_counter.cpp @@ -50,24 +50,21 @@ using std::map; using std::vector; struct packet_counter { - explicit packet_counter(int ns) - : num_substreams(ns), cumulative(ns), current_frame(ns) - { - } + explicit packet_counter(int ns) : num_substreams(ns), packets(ns) {} void register_packet(int substream_id, int bufnum, int offset, int len) { assert(substream_id < num_substreams); - cumulative[substream_id][bufnum][offset] = len; - current_frame[substream_id][offset] = len; + packets[substream_id][bufnum][offset] = len; + current_bufnum = bufnum; } int get_total_bytes() { int ret = 0; for(int i = 0; i < num_substreams; ++i) { - for(map >::const_iterator it = cumulative[i].begin(); - it != cumulative[i].end(); + for(map >::const_iterator it = packets[i].begin(); + it != packets[i].end(); ++it) { for(map::const_iterator it2 = it->second.begin(); it2 != it->second.end(); @@ -84,8 +81,8 @@ struct packet_counter { int ret = 0; for(int i = 0; i < num_substreams; ++i) { - for(map >::const_iterator it = cumulative[i].begin(); - it != cumulative[i].end(); + for(map >::const_iterator it = packets[i].begin(); + it != packets[i].end(); ++it) { if(!it->second.empty()) { ret += (--it->second.end())->first + (--it->second.end())->second; @@ -96,28 +93,22 @@ struct packet_counter { return ret; } - void clear_cumulative() { + void clear() { for(int i = 0; i < num_substreams; ++i) { - cumulative[i].clear(); - } - } - - void clear_current_frame() { - for (auto && chan : current_frame) { - chan.clear(); + packets[i].clear(); } } void iterator_init(int channel, packet_iterator *it) { it->counter = this; it->channel = channel; - auto &&chan = current_frame.at(channel); + auto &&chan = packets.at(channel).at(current_bufnum); auto &&first_pkt = chan.begin(); it->offset = first_pkt->first; it->len = first_pkt->second; } bool next_packet(packet_iterator *it) { - auto &&chan = current_frame.at(it->channel); + auto &&chan = packets.at(it->channel).at(current_bufnum); auto &&cur_pkt = chan.find(it->offset); if (++cur_pkt == chan.end()) { return false; @@ -129,8 +120,8 @@ struct packet_counter { private: int num_substreams; - vector>> cumulative; - vector> current_frame; + vector>> packets; ///< channel, bufnum, off, len + int current_bufnum = 0; friend int packet_counter_get_channels(struct packet_counter *state); }; @@ -170,14 +161,9 @@ int packet_counter_get_channels(struct packet_counter *state) return state->num_substreams; } -void packet_counter_clear_cumulative(struct packet_counter *state) +void packet_counter_clear(struct packet_counter *state) { - state->clear_cumulative(); -} - -void packet_counter_clear_current_frame(struct packet_counter *state) -{ - state->clear_current_frame(); + state->clear(); } /** diff --git a/src/utils/packet_counter.h b/src/utils/packet_counter.h index 8c6f025c1..7c5325480 100644 --- a/src/utils/packet_counter.h +++ b/src/utils/packet_counter.h @@ -55,8 +55,7 @@ void packet_counter_register_packet(struct packet_counter *state, unsigned int s int packet_counter_get_total_bytes(struct packet_counter *state); int packet_counter_get_all_bytes(struct packet_counter *state); int packet_counter_get_channels(struct packet_counter *state); -void packet_counter_clear_cumulative(struct packet_counter *state); -void packet_counter_clear_current_frame(struct packet_counter *state); +void packet_counter_clear(struct packet_counter *state); struct packet_iterator { struct packet_counter *counter;