-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4722eaa
commit fc92570
Showing
1 changed file
with
17 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* @author Martin Pulec <[email protected]> | ||
*/ | ||
/* | ||
* Copyright (c) 2012 CESNET, z. s. p. o. | ||
* Copyright (c) 2012-2023 CESNET, z. s. p. o. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -42,43 +42,26 @@ | |
#endif // defined HAVE_CONFIG_H | ||
|
||
#include "utils/packet_counter.h" | ||
#include <cassert> | ||
#include <map> | ||
#include <vector> | ||
|
||
using std::map; | ||
using std::vector; | ||
|
||
struct packet_counter { | ||
packet_counter(int num_substreams) { | ||
this->num_substreams = num_substreams; | ||
|
||
substream_data.reserve(num_substreams); | ||
for(int i = 0; i < num_substreams; ++i) { | ||
substream_data.push_back(map<int, map<int, int> > ()); | ||
} | ||
} | ||
|
||
~packet_counter() { | ||
} | ||
explicit packet_counter(int ns) : substream_data(ns) {} | ||
|
||
void register_packet(int substream_id, int bufnum, int offset, int len) { | ||
assert(substream_id < num_substreams); | ||
|
||
substream_data[substream_id][bufnum][offset] = len; | ||
substream_data.at(substream_id)[bufnum][offset] = len; | ||
} | ||
|
||
int get_total_bytes() { | ||
int ret = 0; | ||
|
||
for(int i = 0; i < num_substreams; ++i) { | ||
for(map<int, map<int, int> >::const_iterator it = substream_data[i].begin(); | ||
it != substream_data[i].end(); | ||
++it) { | ||
for(map<int, int>::const_iterator it2 = it->second.begin(); | ||
it2 != it->second.end(); | ||
++it2) { | ||
ret += it2->second; | ||
for (auto &&chan : substream_data) { | ||
for (auto &&buffer : chan) { | ||
for (auto &&packet : buffer.second) { | ||
ret += packet.second; | ||
} | ||
} | ||
} | ||
|
@@ -89,12 +72,11 @@ struct packet_counter { | |
int get_all_bytes() { | ||
int ret = 0; | ||
|
||
for(int i = 0; i < num_substreams; ++i) { | ||
for(map<int, map<int, int> >::const_iterator it = substream_data[i].begin(); | ||
it != substream_data[i].end(); | ||
++it) { | ||
if(!it->second.empty()) { | ||
ret += (--it->second.end())->first + (--it->second.end())->second; | ||
for (auto &&chan : substream_data) { | ||
for (auto &buf : chan) { | ||
if (!buf.second.empty()) { | ||
ret += (--buf.second.end())->first + | ||
(--buf.second.end())->second; | ||
} | ||
} | ||
} | ||
|
@@ -103,27 +85,20 @@ struct packet_counter { | |
} | ||
|
||
void clear() { | ||
for(int i = 0; i < num_substreams; ++i) { | ||
substream_data[i].clear(); | ||
for (auto &&chan : substream_data) { | ||
chan.clear(); | ||
} | ||
} | ||
|
||
vector<map<int, map<int, int> > > substream_data; | ||
int num_substreams; | ||
}; | ||
|
||
struct packet_counter *packet_counter_init(int num_substreams) { | ||
struct packet_counter *state; | ||
|
||
state = new packet_counter(num_substreams); | ||
|
||
return state; | ||
return new packet_counter(num_substreams); | ||
} | ||
|
||
void packet_counter_destroy(struct packet_counter *state) { | ||
if(state) { | ||
delete state; | ||
} | ||
delete state; | ||
} | ||
|
||
void packet_counter_register_packet(struct packet_counter *state, unsigned int substream_id, unsigned int bufnum, | ||
|
@@ -144,7 +119,7 @@ int packet_counter_get_all_bytes(struct packet_counter *state) | |
|
||
int packet_counter_get_channels(struct packet_counter *state) | ||
{ | ||
return state->num_substreams; | ||
return (int) state->substream_data.size(); | ||
} | ||
|
||
void packet_counter_clear(struct packet_counter *state) | ||
|