diff options
Diffstat (limited to 'src/DabMultiplexer.cpp')
-rw-r--r-- | src/DabMultiplexer.cpp | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/src/DabMultiplexer.cpp b/src/DabMultiplexer.cpp index e84b58c..f56a4ff 100644 --- a/src/DabMultiplexer.cpp +++ b/src/DabMultiplexer.cpp @@ -92,8 +92,10 @@ DabMultiplexer::DabMultiplexer( m_clock_tai(split_pipe_separated_string(pt.get("general.tai_clock_bulletins", ""))), fig_carousel(ensemble) { - RC_ADD_PARAMETER(frames, - "Show number of frames generated [read-only]"); + gettimeofday(&mnsc_time, nullptr); + + RC_ADD_PARAMETER(frames, "Show number of frames generated [read-only]"); + RC_ADD_PARAMETER(tist_edioffset, "EDI Time offset in seconds"); rcs.enrol(&m_clock_tai); } @@ -169,7 +171,7 @@ void DabMultiplexer::prepare(bool require_tai_clock) throw MuxInitException(); } - auto last_subchannel = *(ensemble->subchannels.end() - 1); + const auto last_subchannel = *(ensemble->subchannels.end() - 1); if (last_subchannel->startAddress + last_subchannel->getSizeCu() > 864) { etiLog.log(error, "Total size in CU exceeds 864"); @@ -191,6 +193,7 @@ void DabMultiplexer::prepare(bool require_tai_clock) // Try to load offset once bool tist_enabled = m_pt.get("general.tist", false); + m_tist_edioffset = m_pt.get<int>("general.tist_edioffset", 0); m_tai_clock_required = (tist_enabled and edi_conf.enabled()) or require_tai_clock; @@ -198,7 +201,7 @@ void DabMultiplexer::prepare(bool require_tai_clock) try { m_clock_tai.get_offset(); } - catch (std::runtime_error& e) { + catch (const std::runtime_error& e) { etiLog.level(error) << "Could not initialise TAI clock properly. " "Do you have a working internet connection?"; @@ -400,9 +403,6 @@ void DabMultiplexer::mux_frame(std::vector<std::shared_ptr<DabOutput> >& outputs unsigned char etiFrame[6144]; unsigned short index = 0; - vec_sp_service::iterator service; - vec_sp_component::iterator component; - // FIC Length, DAB Mode I, II, IV -> FICL = 24, DAB Mode III -> FICL = 32 unsigned FICL = (ensemble->transmission_mode == TransmissionMode_e::TM_III ? 32 : 24); @@ -546,7 +546,8 @@ void DabMultiplexer::mux_frame(std::vector<std::shared_ptr<DabOutput> >& outputs eoh->MNSC = 0; - struct tm *time_tm = gmtime(&mnsc_time.tv_sec); + struct tm time_tm; + gmtime_r(&mnsc_time.tv_sec, &time_tm); switch (fc->FP & 0x3) { case 0: @@ -567,7 +568,7 @@ void DabMultiplexer::mux_frame(std::vector<std::shared_ptr<DabOutput> >& outputs case 1: { eti_MNSC_TIME_1 *mnsc = (eti_MNSC_TIME_1 *) &eoh->MNSC; - mnsc->setFromTime(time_tm); + mnsc->setFromTime(&time_tm); mnsc->accuracy = 1; mnsc->sync_to_frame = 1; } @@ -575,13 +576,13 @@ void DabMultiplexer::mux_frame(std::vector<std::shared_ptr<DabOutput> >& outputs case 2: { eti_MNSC_TIME_2 *mnsc = (eti_MNSC_TIME_2 *) &eoh->MNSC; - mnsc->setFromTime(time_tm); + mnsc->setFromTime(&time_tm); } break; case 3: { eti_MNSC_TIME_3 *mnsc = (eti_MNSC_TIME_3 *) &eoh->MNSC; - mnsc->setFromTime(time_tm); + mnsc->setFromTime(&time_tm); } break; } @@ -670,19 +671,18 @@ void DabMultiplexer::mux_frame(std::vector<std::shared_ptr<DabOutput> >& outputs edi_tagDETI.tsta = 0xffffff; } - edi_tagDETI.atstf = 1; - edi_tagDETI.utco = 0; - edi_tagDETI.seconds = 0; #if HAVE_OUTPUT_EDI - try { - bool tist_enabled = m_pt.get("general.tist", false); - - if (tist_enabled and m_tai_clock_required) { - edi_tagDETI.set_seconds(edi_time); + const bool tist_enabled = m_pt.get("general.tist", false); - // In case get_offset fails, we still want to update the EDI seconds + if (tist_enabled and m_tai_clock_required) { + try { const auto tai_utc_offset = m_clock_tai.get_offset(); - edi_tagDETI.set_tai_utc_offset(tai_utc_offset); + + edi_tagDETI.set_edi_time(edi_time + + std::chrono::seconds(m_tist_edioffset), + tai_utc_offset); + + edi_tagDETI.atstf = true; for (auto output : outputs) { shared_ptr<OutputMetadata> md_utco = @@ -698,9 +698,9 @@ void DabMultiplexer::mux_frame(std::vector<std::shared_ptr<DabOutput> >& outputs output->setMetadata(md_dlfc); } } - } - catch (std::runtime_error& e) { - etiLog.level(error) << "Could not get UTC-TAI offset for EDI timestamp"; + catch (const std::runtime_error& e) { + etiLog.level(error) << "Could not get UTC-TAI offset for EDI timestamp"; + } } #endif @@ -872,6 +872,9 @@ void DabMultiplexer::set_parameter(const std::string& parameter, " is read-only"; throw ParameterError(ss.str()); } + else if (parameter == "tist_edioffset") { + m_tist_edioffset = std::stoi(value); + } else { stringstream ss; ss << "Parameter '" << parameter << @@ -887,6 +890,9 @@ const std::string DabMultiplexer::get_parameter(const std::string& parameter) co if (parameter == "frames") { ss << currentFrame; } + else if (parameter == "tist_edioffset") { + ss << m_tist_edioffset; + } else { ss << "Parameter '" << parameter << "' is not exported by controllable " << get_rc_name(); |