Skip to content

Commit

Permalink
packet counter: remoed unneeded packet store
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MartinPulec committed Aug 1, 2023
1 parent 2e03e67 commit f106180
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/audio/codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/rtp/audio_decoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 15 additions & 29 deletions src/utils/packet_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, map<int, int> >::const_iterator it = cumulative[i].begin();
it != cumulative[i].end();
for(map<int, map<int, int> >::const_iterator it = packets[i].begin();
it != packets[i].end();
++it) {
for(map<int, int>::const_iterator it2 = it->second.begin();
it2 != it->second.end();
Expand All @@ -84,8 +81,8 @@ struct packet_counter {
int ret = 0;

for(int i = 0; i < num_substreams; ++i) {
for(map<int, map<int, int> >::const_iterator it = cumulative[i].begin();
it != cumulative[i].end();
for(map<int, map<int, int> >::const_iterator it = packets[i].begin();
it != packets[i].end();
++it) {
if(!it->second.empty()) {
ret += (--it->second.end())->first + (--it->second.end())->second;
Expand All @@ -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;
Expand All @@ -129,8 +120,8 @@ struct packet_counter {

private:
int num_substreams;
vector<map<int, map<int, int>>> cumulative;
vector<map<int, int>> current_frame;
vector<map<int, map<int, int>>> packets; ///< channel, bufnum, off, len
int current_bufnum = 0;

friend int packet_counter_get_channels(struct packet_counter *state);
};
Expand Down Expand Up @@ -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)
{
state->clear_cumulative();
}

void packet_counter_clear_current_frame(struct packet_counter *state)
void packet_counter_clear(struct packet_counter *state)
{
state->clear_current_frame();
state->clear();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/utils/packet_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f106180

Please sign in to comment.