summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-10-02 12:37:44 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-10-02 12:37:44 +0200
commit9bcd309e3812263a11ee13d7999e85c4e6a48ebd (patch)
treea8983d634629748b4f0ab7dbb9500b6f797d59fe
parent1b851434726b3521add4dc226ee041b1e44bb7b3 (diff)
downloaddabmux-9bcd309e3812263a11ee13d7999e85c4e6a48ebd.tar.gz
dabmux-9bcd309e3812263a11ee13d7999e85c4e6a48ebd.tar.bz2
dabmux-9bcd309e3812263a11ee13d7999e85c4e6a48ebd.zip
Refactor handling of FIG state out of 0/19
We are going to need this for other FIGs too
-rw-r--r--src/fig/FIG0.cpp104
-rw-r--r--src/fig/FIG0.h47
2 files changed, 69 insertions, 82 deletions
diff --git a/src/fig/FIG0.cpp b/src/fig/FIG0.cpp
index 4233b5b..03fb00c 100644
--- a/src/fig/FIG0.cpp
+++ b/src/fig/FIG0.cpp
@@ -1258,24 +1258,27 @@ FillStatus FIG0_19::fill(uint8_t *buf, size_t max_size)
{
using namespace std;
- update_state();
+ auto ensemble = m_rti->ensemble;
+
+ // We are called every 24ms, and must timeout after 2s
+ const int timeout = 2000/24;
+
+ m_transition.update_state(timeout, ensemble->clusters);
FillStatus fs;
ssize_t remaining = max_size;
- auto ensemble = m_rti->ensemble;
-
FIGtype0* fig0 = NULL;
// Combine all clusters into one list
set<AnnouncementCluster*> allclusters;
- for (const auto& cluster : m_new_announcements) {
+ for (const auto& cluster : m_transition.new_entries) {
allclusters.insert(cluster.first.get());
}
- for (const auto& cluster : m_repeated_announcements) {
+ for (const auto& cluster : m_transition.repeated_entries) {
allclusters.insert(cluster.get());
}
- for (const auto& cluster : m_disabled_announcements) {
+ for (const auto& cluster : m_transition.disabled_entries) {
allclusters.insert(cluster.first.get());
}
@@ -1341,86 +1344,59 @@ FillStatus FIG0_19::fill(uint8_t *buf, size_t max_size)
return fs;
}
-void FIG0_19::update_state()
+template<class T>
+void TransitionHandler<T>::update_state(int timeout, std::vector<std::shared_ptr<T> > all_entries)
{
- auto ensemble = m_rti->ensemble;
-
- // We are called every 24ms, and must timeout after 2s
- const int timeout = 2000/24;
-
-//#define DEBUG_FIG0_19
-#ifdef DEBUG_FIG0_19
- etiLog.level(info) << " FIG0/19 new";
- for (const auto& cluster : m_new_announcements) {
- etiLog.level(info) << " " << cluster.first->tostring()
- << ": " << cluster.second;
- }
- etiLog.level(info) << " FIG0/19 repeated";
- for (const auto& cluster : m_repeated_announcements) {
- etiLog.level(info) << " " << cluster->tostring();
- }
- etiLog.level(info) << " FIG0/19 disabled";
- for (const auto& cluster : m_disabled_announcements) {
- etiLog.level(info) << " " << cluster.first->tostring()
- << ": " << cluster.second;
- }
-
- etiLog.level(info) << " FIG0/19 in ensemble";
-#endif
-
- for (const auto& cluster : ensemble->clusters) {
-#ifdef DEBUG_FIG0_19
- etiLog.level(info) << " " << cluster->tostring();
-#endif
- if (cluster->is_active()) {
- if (m_repeated_announcements.count(cluster) > 0) {
- // We are currently announcing this cluster
+ for (const auto& entry : all_entries) {
+ if (entry->is_active()) {
+ if (repeated_entries.count(entry) > 0) {
+ // We are currently announcing this entry
continue;
}
- if (m_new_announcements.count(cluster) > 0) {
- // We are currently announcing this cluster at a
+ if (new_entries.count(entry) > 0) {
+ // We are currently announcing this entry at a
// fast rate. Handle timeout:
- m_new_announcements[cluster] -= 1;
- if (m_new_announcements[cluster] <= 0) {
- m_repeated_announcements.insert(cluster);
- m_new_announcements.erase(cluster);
+ new_entries[entry] -= 1;
+ if (new_entries[entry] <= 0) {
+ repeated_entries.insert(entry);
+ new_entries.erase(entry);
}
continue;
}
// unlikely
- if (m_disabled_announcements.count(cluster) > 0) {
- m_new_announcements[cluster] = timeout;
- m_disabled_announcements.erase(cluster);
+ if (disabled_entries.count(entry) > 0) {
+ new_entries[entry] = timeout;
+ disabled_entries.erase(entry);
continue;
}
- // It's a new announcement!
- m_new_announcements[cluster] = timeout;
+ // It's a new entry!
+ new_entries[entry] = timeout;
}
else { // Not active
- if (m_disabled_announcements.count(cluster) > 0) {
- m_disabled_announcements[cluster] -= 1;
- if (m_disabled_announcements[cluster] <= 0) {
- m_disabled_announcements.erase(cluster);
+ if (disabled_entries.count(entry) > 0) {
+ disabled_entries[entry] -= 1;
+ if (disabled_entries[entry] <= 0) {
+ disabled_entries.erase(entry);
}
continue;
}
- if (m_repeated_announcements.count(cluster) > 0) {
- // We are currently announcing this cluster
- m_disabled_announcements[cluster] = timeout;
- m_repeated_announcements.erase(cluster);
+ if (repeated_entries.count(entry) > 0) {
+ // We are currently announcing this entry
+ disabled_entries[entry] = timeout;
+ repeated_entries.erase(entry);
continue;
}
// unlikely
- if (m_new_announcements.count(cluster) > 0) {
- // We are currently announcing this cluster at a
+ if (new_entries.count(entry) > 0) {
+ // We are currently announcing this entry at a
// fast rate. We must stop announcing it
- m_disabled_announcements[cluster] = timeout;
- m_new_announcements.erase(cluster);
+ disabled_entries[entry] = timeout;
+ new_entries.erase(entry);
continue;
}
}
@@ -1429,8 +1405,8 @@ void FIG0_19::update_state()
FIG_rate FIG0_19::repetition_rate(void)
{
- if ( m_new_announcements.size() > 0 or
- m_disabled_announcements.size() ) {
+ if ( m_transition.new_entries.size() > 0 or
+ m_transition.disabled_entries.size() ) {
return FIG_rate::A_B;
}
else {
diff --git a/src/fig/FIG0.h b/src/fig/FIG0.h
index 95a8a85..84bde41 100644
--- a/src/fig/FIG0.h
+++ b/src/fig/FIG0.h
@@ -34,6 +34,34 @@
namespace FIC {
+// Some FIGs need to adapt their rate or their contents depending
+// on if some data entries are stable or currently undergoing a
+// change. The TransitionHandler keeps track of which entries
+// are in what state.
+template<class T>
+class TransitionHandler {
+ public:
+ // update_state must be called once per ETI frame, and will
+ // move entries from new to repeated to disabled depending
+ // on their is_active() return value.
+ void update_state(int timeout, std::vector<std::shared_ptr<T> > all_entries);
+
+ // The FIG that needs the information about what state an entry is in
+ // can read from the following data structures. It shall not modify them.
+
+ /* Map to frame count */
+ std::map<
+ std::shared_ptr<T>,int> new_entries;
+
+ std::set<
+ std::shared_ptr<T> > repeated_entries;
+
+ /* Map to frame count */
+ std::map<
+ std::shared_ptr<T>,int> disabled_entries;
+};
+
+
// FIG type 0/0, Multiplex Configuration Info (MCI),
// Ensemble information
class FIG0_0 : public IFIG
@@ -260,24 +288,7 @@ class FIG0_19 : public IFIG
private:
FIGRuntimeInformation *m_rti;
- void update_state(void);
-
- /* When a new announcement gets active, it is moved into the list
- * of new announcements, and gets transmitted at a faster rate for
- * two seconds.
- * Same for recently disabled announcements.
- */
-
- /* Map of cluster to frame count */
- std::map<
- std::shared_ptr<AnnouncementCluster>,int> m_new_announcements;
-
- std::set<
- std::shared_ptr<AnnouncementCluster> > m_repeated_announcements;
-
- /* Map of cluster to frame count */
- std::map<
- std::shared_ptr<AnnouncementCluster>,int> m_disabled_announcements;
+ TransitionHandler<AnnouncementCluster> m_transition;
};
#ifdef _WIN32