From 5b1dea7f85749d14bf85114accd01677caae7530 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 15 Nov 2019 12:31:54 +0100 Subject: Initialise TIST with consistent system time at startup The change introduced in fd33dd4 (v2.4.0) had the consequence of generating different timestamp offsets depending on when exactly the mux was started. The intended goal to avoid having the NULL symbol output at a fixed offset to avoid receiver synchronisation is however not so important, because most commercial receivers will cut transmission for several seconds before resuming, and the majority of the receivers will then start resynchronising. However, the different timestamp offsets upsets some modulator input modules, which so not necessarily have enough buffering capacity. This change reverts back to the previous behaviour, where the timestamp is set to current system time, rounded to 24ms. --- src/DabMultiplexer.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/DabMultiplexer.cpp b/src/DabMultiplexer.cpp index 9bd3c3f..2bd8d74 100644 --- a/src/DabMultiplexer.cpp +++ b/src/DabMultiplexer.cpp @@ -134,24 +134,23 @@ void DabMultiplexer::prepare(bool require_tai_clock) throw MuxInitException(); } - /* TODO: - * In a SFN, when reconfiguring the ensemble, the multiplexer - * has to be restarted (odr-dabmux doesn't support reconfiguration). - * Ideally, we must be able to restart transmission s.t. the receiver - * synchronisation is preserved. + /* Ensure edi_time and TIST represent current time. Keep + * a granularity of 24ms, which corresponds to the + * duration of an ETI frame, to get nicer timestamps. */ using Sec = chrono::seconds; - const auto now = chrono::time_point_cast(chrono::system_clock::now()); - - edi_time = chrono::system_clock::to_time_t(now); - - // We define that when the time is multiple of six seconds, the timestamp - // (PPS offset) is 0. This ensures consistency of TIST even across a - // mux restart + const auto now = chrono::system_clock::now(); + edi_time = chrono::system_clock::to_time_t(chrono::time_point_cast(now)); + auto offset = now - chrono::time_point_cast(now); + if (offset >= chrono::seconds(1)) { + throw std::logic_error("Invalid startup offset calculation for TIST! " + + to_string(chrono::duration_cast(offset).count()) + + " ms"); + } timestamp = 0; - edi_time -= (edi_time % 6); - while (edi_time < chrono::system_clock::to_time_t(now)) { + while (offset >= chrono::milliseconds(24)) { increment_timestamp(); + offset -= chrono::milliseconds(24); } // Try to load offset once -- cgit v1.2.3