UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
ssrc_container.hpp
Go to the documentation of this file.
1#ifndef SSRC_CONTAINER_HPP_1b2b8951b25f
2#define SSRC_CONTAINER_HPP_1b2b8951b25f
3
4#include <vector>
5
6template<typename T, typename Ts_type>
8public:
9 struct Holder{
11 uint32_t ssrc;
12 Ts_type timestamp;
13 };
14
15 void insert(uint32_t ssrc, const T& item, Ts_type timestamp);
16 const std::vector<Holder>& get() const { return items; }
17 void remove_timed_out(Ts_type timeout, Ts_type now);
18 void clear() { items.clear(); }
19
20private:
21 std::vector<Holder> items;
22};
23
24template<typename T, typename Ts_type>
25inline void SSRC_container<T, Ts_type>::insert(uint32_t ssrc, const T& item, Ts_type timestamp){
26 Holder *h = nullptr;
27 for(auto& i : items){
28 if(i.ssrc == ssrc){
29 h = &i;
30 }
31 }
32
33 if(!h){
34 Holder newItem = {};
35 newItem.ssrc = ssrc;
36 items.push_back(newItem);
37 h = &items.back();
38 }
39
40 h->item = item;
41 h->timestamp = timestamp;
42}
43
44template<typename T, typename Ts_type>
45inline void SSRC_container<T, Ts_type>::remove_timed_out(Ts_type timeout, Ts_type now){
46 auto endIt = std::remove_if(items.begin(), items.end(),
47 [now, timeout](const Holder& h){ return now - h.timestamp > timeout; });
48
49 items.erase(endIt, items.end());
50}
51
52#endif //SSRC_CONTAINER_HPP_1b2b8951b25f
void insert(uint32_t ssrc, const T &item, Ts_type timestamp)
const std::vector< Holder > & get() const
void remove_timed_out(Ts_type timeout, Ts_type now)
std::vector< Holder > items
Definition hd-rum.c:27