diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-09-01 21:58:32 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-09-01 21:58:32 +0200 |
commit | 1c68dced7ee77ed9065135d54c069a673e16291e (patch) | |
tree | 2612b572d219d2c0a16b1d5962f89594b9486056 /src | |
parent | 2b99cb3f3d43c48d9292707725b6618b18944d42 (diff) | |
download | dabmux-1c68dced7ee77ed9065135d54c069a673e16291e.tar.gz dabmux-1c68dced7ee77ed9065135d54c069a673e16291e.tar.bz2 dabmux-1c68dced7ee77ed9065135d54c069a673e16291e.zip |
Add RC parameters for deferred start/stop of announcements
This is helpful to compensate for audio encoding delays.
Diffstat (limited to 'src')
-rw-r--r-- | src/MuxElements.cpp | 81 | ||||
-rw-r--r-- | src/MuxElements.h | 30 | ||||
-rw-r--r-- | src/fig/FIG0.cpp | 2 |
3 files changed, 107 insertions, 6 deletions
diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp index fd8d57a..773ec17 100644 --- a/src/MuxElements.cpp +++ b/src/MuxElements.cpp @@ -3,8 +3,10 @@ 2011, 2012 Her Majesty the Queen in Right of Canada (Communications Research Center Canada) - Copyright (C) 2014, 2015 + Copyright (C) 2016 Matthias P. Braendli, matthias.braendli@mpb.li + + http://www.opendigitalradio.org */ /* This file is part of ODR-DabMux. @@ -53,7 +55,15 @@ std::string AnnouncementCluster::tostring() const ss << ", flags 0x" << boost::format("%04x") % flags; ss << ", subchannel " << subchanneluid; if (m_active) { - ss << " *"; + ss << " active "; + } + + if (m_deferred_start_time) { + ss << " start pending"; + } + + if (m_deferred_stop_time) { + ss << " stop pending"; } ss << " )"; @@ -61,6 +71,33 @@ std::string AnnouncementCluster::tostring() const return ss.str(); } +bool AnnouncementCluster::is_active(void) +{ + if (m_deferred_start_time) + { + const auto now = std::chrono::steady_clock::now(); + + if (*m_deferred_start_time <= now) { + m_active = true; + + m_deferred_start_time = boost::none; + } + } + + if (m_deferred_stop_time) + { + const auto now = std::chrono::steady_clock::now(); + + if (*m_deferred_stop_time <= now) { + m_active = false; + + m_deferred_stop_time = boost::none; + } + } + + return m_active; +} + void AnnouncementCluster::set_parameter(const string& parameter, const string& value) { @@ -69,6 +106,26 @@ void AnnouncementCluster::set_parameter(const string& parameter, ss << value; ss >> m_active; } + else if (parameter == "start_in") { + stringstream ss; + ss << value; + + int start_in_ms; + ss >> start_in_ms; + + using namespace std::chrono; + m_deferred_start_time = steady_clock::now() + milliseconds(start_in_ms); + } + else if (parameter == "stop_in") { + stringstream ss; + ss << value; + + int stop_in_ms; + ss >> stop_in_ms; + + using namespace std::chrono; + m_deferred_stop_time = steady_clock::now() + milliseconds(stop_in_ms); + } else { stringstream ss; ss << "Parameter '" << parameter << @@ -79,10 +136,30 @@ void AnnouncementCluster::set_parameter(const string& parameter, const string AnnouncementCluster::get_parameter(const string& parameter) const { + using namespace std::chrono; + stringstream ss; if (parameter == "active") { ss << m_active; } + else if (parameter == "start_in") { + if (m_deferred_start_time) { + const auto diff = *m_deferred_start_time - steady_clock::now(); + ss << duration_cast<milliseconds>(diff).count(); + } + else { + ss << "Not set"; + } + } + else if (parameter == "stop_in") { + if (m_deferred_stop_time) { + const auto diff = *m_deferred_stop_time - steady_clock::now(); + ss << duration_cast<milliseconds>(diff).count(); + } + else { + ss << "Not set"; + } + } else { ss << "Parameter '" << parameter << "' is not exported by controllable " << get_rc_name(); diff --git a/src/MuxElements.h b/src/MuxElements.h index 289c35a..7056121 100644 --- a/src/MuxElements.h +++ b/src/MuxElements.h @@ -3,9 +3,11 @@ 2011, 2012 Her Majesty the Queen in Right of Canada (Communications Research Center Canada) - Copyright (C) 2014, 2015 + Copyright (C) 2016 Matthias P. Braendli, matthias.braendli@mpb.li + http://www.opendigitalradio.org + This file defines all data structures used in DabMux to represent and save ensemble data. */ @@ -34,6 +36,8 @@ #include <functional> #include <exception> #include <algorithm> +#include <chrono> +#include <boost/optional.hpp> #include <stdint.h> #include "dabOutput/dabOutput.h" #include "dabInput.h" @@ -85,7 +89,15 @@ class AnnouncementCluster : public RemoteControllable { RemoteControllable(name), m_active(false) { - RC_ADD_PARAMETER(active, "Signal this announcement"); + RC_ADD_PARAMETER(active, "Signal this announcement [0 or 1]"); + + /* This supports deferred start/stop to allow the user + * to compensate for audio encoding delay + */ + RC_ADD_PARAMETER(start_in, + "Start signalling this announcement after a delay [ms]"); + RC_ADD_PARAMETER(stop_in, + "Stop signalling this announcement after a delay [ms]"); } uint8_t cluster_id; @@ -94,11 +106,23 @@ class AnnouncementCluster : public RemoteControllable { std::string tostring(void) const; - bool is_active(void) const { return m_active; }; + /* Check if the activation/deactivation timeout occurred, + * and return of if the Announcement is active + */ + bool is_active(void); private: bool m_active; + boost::optional< + std::chrono::time_point< + std::chrono::steady_clock> > m_deferred_start_time; + + boost::optional< + std::chrono::time_point< + std::chrono::steady_clock> > m_deferred_stop_time; + + /* Remote control */ virtual void set_parameter(const std::string& parameter, const std::string& value); diff --git a/src/fig/FIG0.cpp b/src/fig/FIG0.cpp index 650baa4..8393c72 100644 --- a/src/fig/FIG0.cpp +++ b/src/fig/FIG0.cpp @@ -1196,7 +1196,7 @@ FillStatus FIG0_19::fill(uint8_t *buf, size_t max_size) const int length_0_19 = 4; fs.complete_fig_transmitted = true; - for (const auto& cluster : allclusters) { + for (auto& cluster : allclusters) { if (fig0 == NULL) { if (remaining < 2 + length_0_19) { |