summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-08-19 17:18:51 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-08-19 17:18:51 +0200
commit5ee85c4ac41337e383eb1a735bc05f1e5d46a98f (patch)
tree9a6b4e9ec0138e282a67ac5d537248af4b067ad5
parent247b175a6bf8107f0c92e6ca32e11af4b1a47b8a (diff)
downloaddabmux-5ee85c4ac41337e383eb1a735bc05f1e5d46a98f.tar.gz
dabmux-5ee85c4ac41337e383eb1a735bc05f1e5d46a98f.tar.bz2
dabmux-5ee85c4ac41337e383eb1a735bc05f1e5d46a98f.zip
Use EDI output from odr-mmbtools-common
-rw-r--r--Makefile.am52
-rw-r--r--lib/ClockTAI.cpp159
-rw-r--r--lib/ClockTAI.h10
-rw-r--r--lib/edioutput/AFPacket.cpp (renamed from src/dabOutput/edi/AFPacket.cpp)12
-rw-r--r--lib/edioutput/AFPacket.h (renamed from src/dabOutput/edi/AFPacket.h)12
-rw-r--r--lib/edioutput/Config.h (renamed from src/dabOutput/edi/Config.h)10
-rw-r--r--lib/edioutput/Interleaver.cpp (renamed from src/dabOutput/edi/Interleaver.cpp)0
-rw-r--r--lib/edioutput/Interleaver.h (renamed from src/dabOutput/edi/Interleaver.h)12
-rw-r--r--lib/edioutput/PFT.cpp (renamed from src/dabOutput/edi/PFT.cpp)12
-rw-r--r--lib/edioutput/PFT.h (renamed from src/dabOutput/edi/PFT.h)14
-rw-r--r--lib/edioutput/TagItems.cpp (renamed from src/dabOutput/edi/TagItems.cpp)183
-rw-r--r--lib/edioutput/TagItems.h (renamed from src/dabOutput/edi/TagItems.h)94
-rw-r--r--lib/edioutput/TagPacket.cpp (renamed from src/dabOutput/edi/TagPacket.cpp)13
-rw-r--r--lib/edioutput/TagPacket.h (renamed from src/dabOutput/edi/TagPacket.h)12
-rw-r--r--lib/edioutput/Transport.cpp (renamed from src/dabOutput/edi/Transport.cpp)11
-rw-r--r--lib/edioutput/Transport.h (renamed from src/dabOutput/edi/Transport.h)12
-rw-r--r--src/DabMultiplexer.cpp2
-rw-r--r--src/DabMultiplexer.h8
-rw-r--r--src/zmq2edi/EDISender.cpp2
-rw-r--r--src/zmq2edi/EDISender.h6
20 files changed, 463 insertions, 173 deletions
diff --git a/Makefile.am b/Makefile.am
index 216f7c0..e426f74 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -81,19 +81,6 @@ odr_dabmux_SOURCES =src/DabMux.cpp \
src/dabOutput/dabOutputZMQ.cpp \
src/dabOutput/metadata.h \
src/dabOutput/metadata.cpp \
- src/dabOutput/edi/AFPacket.cpp \
- src/dabOutput/edi/AFPacket.h \
- src/dabOutput/edi/Config.h \
- src/dabOutput/edi/Interleaver.cpp \
- src/dabOutput/edi/Interleaver.h \
- src/dabOutput/edi/PFT.cpp \
- src/dabOutput/edi/PFT.h \
- src/dabOutput/edi/TagItems.cpp \
- src/dabOutput/edi/TagItems.h \
- src/dabOutput/edi/TagPacket.cpp \
- src/dabOutput/edi/TagPacket.h \
- src/dabOutput/edi/Transport.cpp \
- src/dabOutput/edi/Transport.h \
src/ConfigParser.cpp \
src/ConfigParser.h \
src/Eti.h \
@@ -169,6 +156,19 @@ odr_dabmux_SOURCES =src/DabMux.cpp \
lib/edi/common.cpp \
lib/edi/common.h \
lib/edi/buffer_unpack.hpp \
+ lib/edioutput/AFPacket.cpp \
+ lib/edioutput/AFPacket.h \
+ lib/edioutput/Config.h \
+ lib/edioutput/Interleaver.cpp \
+ lib/edioutput/Interleaver.h \
+ lib/edioutput/PFT.cpp \
+ lib/edioutput/PFT.h \
+ lib/edioutput/TagItems.cpp \
+ lib/edioutput/TagItems.h \
+ lib/edioutput/TagPacket.cpp \
+ lib/edioutput/TagPacket.h \
+ lib/edioutput/Transport.cpp \
+ lib/edioutput/Transport.h \
lib/ReedSolomon.h \
lib/ReedSolomon.cpp \
lib/Socket.h \
@@ -199,19 +199,19 @@ odr_zmq2edi_SOURCES = src/zmq2edi/zmq2edi.cpp \
src/dabOutput/dabOutput.h \
src/dabOutput/metadata.h \
src/dabOutput/metadata.cpp \
- src/dabOutput/edi/AFPacket.cpp \
- src/dabOutput/edi/AFPacket.h \
- src/dabOutput/edi/Config.h \
- src/dabOutput/edi/Interleaver.cpp \
- src/dabOutput/edi/Interleaver.h \
- src/dabOutput/edi/PFT.cpp \
- src/dabOutput/edi/PFT.h \
- src/dabOutput/edi/TagItems.cpp \
- src/dabOutput/edi/TagItems.h \
- src/dabOutput/edi/TagPacket.cpp \
- src/dabOutput/edi/TagPacket.h \
- src/dabOutput/edi/Transport.cpp \
- src/dabOutput/edi/Transport.h \
+ lib/edioutput/AFPacket.cpp \
+ lib/edioutput/AFPacket.h \
+ lib/edioutput/Config.h \
+ lib/edioutput/Interleaver.cpp \
+ lib/edioutput/Interleaver.h \
+ lib/edioutput/PFT.cpp \
+ lib/edioutput/PFT.h \
+ lib/edioutput/TagItems.cpp \
+ lib/edioutput/TagItems.h \
+ lib/edioutput/TagPacket.cpp \
+ lib/edioutput/TagPacket.h \
+ lib/edioutput/Transport.cpp \
+ lib/edioutput/Transport.h \
lib/Log.h \
lib/Log.cpp \
lib/crc.h \
diff --git a/lib/ClockTAI.cpp b/lib/ClockTAI.cpp
index 42497f4..2656345 100644
--- a/lib/ClockTAI.cpp
+++ b/lib/ClockTAI.cpp
@@ -9,27 +9,27 @@
http://www.opendigitalradio.org
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
-*/
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
/* This file downloads the TAI-UTC bulletins from the from IETF and parses them
* so that correct time can be communicated in EDI timestamps.
*
* This file contains self-test code that can be executed by running
- * g++ -g -Wall -DTEST -DHAVE_CURL -std=c++11 -lcurl -pthread \
+ * g++ -g -Wall -DTAI_TEST -DHAVE_CURL -std=c++11 -lcurl -pthread \
* ClockTAI.cpp Log.cpp RemoteControl.cpp -lboost_system -o taitest && ./taitest
*/
@@ -40,9 +40,9 @@
#include "ClockTAI.h"
#include "Log.h"
-#include <time.h>
-#include <stdio.h>
-#include <errno.h>
+#include <ctime>
+#include <cstdio>
+#include <cerrno>
#if SUPPORT_SETTING_CLOCK_TAI
# include <sys/timex.h>
#endif
@@ -54,10 +54,13 @@
#include <iostream>
#include <algorithm>
#include <regex>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
using namespace std;
-#ifdef TEST
+#ifdef DOWNLOADED_IN_THE_PAST_TEST
static bool wait_longer = true;
#endif
@@ -76,7 +79,7 @@ static array<const char*, 2> default_tai_urls = {
// According to the Filesystem Hierarchy Standard, the data in
// /var/tmp "must not be deleted when the system is booted."
-static const char *tai_cache_location = "/var/tmp/odr-dabmux-leap-seconds.cache";
+static const char *tai_cache_location = "/var/tmp/odr-leap-seconds.cache";
// read TAI offset from a valid bulletin in IETF format
static int parse_ietf_bulletin(const std::string& bulletin)
@@ -127,7 +130,7 @@ static int parse_ietf_bulletin(const std::string& bulletin)
tai_utc_offset = offset;
tai_utc_offset_valid = true;
}
-#if TEST
+#if TAI_TEST
else {
cerr << "IETF Ignoring offset " << bulletin_offset <<
" at TS " << bulletin_ntp_timestamp <<
@@ -183,7 +186,7 @@ static bulletin_state parse_bulletin(const string& bulletin)
const int64_t expiry_unix =
std::atoll(expiry_data_str.c_str()) - ntp_unix_offset;
-#ifdef TEST
+#ifdef TAI_TEST
etiLog.level(info) << "Bulletin expires in " << expiry_unix - now;
#endif
ret.expiry = expiry_unix - now;
@@ -246,17 +249,46 @@ static string download_tai_utc_bulletin(const char* url)
static string load_bulletin_from_file(const char* cache_filename)
{
- // Clear the bulletin
- ifstream f(cache_filename);
- if (not f.good()) {
- return {};
+ int fd = open(cache_filename, O_RDWR); // lockf requires O_RDWR
+ if (fd == -1) {
+ etiLog.level(error) << "TAI-UTC bulletin open cache for reading: " <<
+ strerror(errno);
+ return "";
}
- stringstream ss;
- ss << f.rdbuf();
- f.close();
+ lseek(fd, 0, SEEK_SET);
+
+ vector<char> buf(1024);
+ vector<char> new_bulletin_data;
+
+ ssize_t ret = lockf(fd, F_LOCK, 0);
+ if (ret == 0) {
+ // exclusive lock acquired
+
+ do {
+ ret = read(fd, buf.data(), buf.size());
+
+ if (ret == -1) {
+ close(fd);
+ etiLog.level(error) << "TAI-UTC bulletin read cache: " <<
+ strerror(errno);
+ return "";
+ }
+
+ copy(buf.data(), buf.data() + ret, back_inserter(new_bulletin_data));
+ } while (ret > 0);
+
+ close(fd);
- return ss.str();
+ return string{new_bulletin_data.data(), new_bulletin_data.size()};
+ }
+ else {
+ etiLog.level(error) <<
+ "TAI-UTC bulletin acquire cache lock for reading: " <<
+ strerror(errno);
+ close(fd);
+ }
+ return "";
}
ClockTAI::ClockTAI(const std::vector<std::string>& bulletin_urls) :
@@ -289,7 +321,7 @@ int ClockTAI::get_valid_offset()
const auto state = parse_bulletin(m_bulletin);
if (state.usable()) {
-#if TEST
+#if TAI_TEST
etiLog.level(info) << "Bulletin already valid";
#endif
offset = state.offset;
@@ -297,20 +329,25 @@ int ClockTAI::get_valid_offset()
}
else {
const auto cache_bulletin = load_bulletin_from_file(tai_cache_location);
+#if TAI_TEST
+ etiLog.level(info) << "Loaded cache bulletin with " <<
+ std::count_if(cache_bulletin.cbegin(), cache_bulletin.cend(),
+ [](const char c){ return c == '\n'; }) << " lines";
+#endif
const auto cache_state = parse_bulletin(cache_bulletin);
if (cache_state.usable()) {
m_bulletin = cache_bulletin;
offset = cache_state.offset;
offset_valid = true;
-#if TEST
+#if TAI_TEST
etiLog.level(info) << "Bulletin from cache valid with offset=" << offset;
#endif
}
else {
for (const auto url : m_bulletin_urls) {
try {
-#if TEST
+#if TAI_TEST
etiLog.level(info) << "Load bulletin from " << url;
#endif
const auto new_bulletin = download_tai_utc_bulletin(url.c_str());
@@ -368,7 +405,7 @@ int ClockTAI::get_offset()
std::unique_lock<std::mutex> lock(m_data_mutex);
if (not m_offset_valid) {
-#ifdef TEST
+#ifdef DOWNLOADED_IN_THE_PAST_TEST
// Assume we've downloaded it in the past:
m_offset = 37; // Valid in early 2017
@@ -418,7 +455,7 @@ int ClockTAI::get_offset()
m_bulletin_download_time += hours(download_retry_interval_hours);
}
-#ifdef TEST
+#ifdef DOWNLOADED_IN_THE_PAST_TEST
wait_longer = false;
#endif
break;
@@ -426,14 +463,14 @@ int ClockTAI::get_offset()
case future_status::deferred:
case future_status::timeout:
// Not ready yet
-#ifdef TEST
+#ifdef TAI_TEST
etiLog.level(debug) << " async not ready yet";
#endif
break;
}
}
else {
-#ifdef TEST
+#ifdef TAI_TEST
etiLog.level(debug) << " Launch async";
#endif
m_offset_future = async(launch::async, &ClockTAI::get_valid_offset, this);
@@ -463,13 +500,45 @@ int ClockTAI::update_local_tai_clock(int offset)
void ClockTAI::update_cache(const char* cache_filename)
{
- ofstream f(cache_filename);
- if (not f.good()) {
- throw runtime_error("TAI-UTC bulletin open cache for writing");
+ int fd = open(cache_filename, O_RDWR | O_CREAT, 00664);
+ if (fd == -1) {
+ etiLog.level(error) <<
+ "TAI-UTC bulletin open cache for writing: " <<
+ strerror(errno);
+ return;
}
- f << m_bulletin;
- f.close();
+ lseek(fd, 0, SEEK_SET);
+
+ ssize_t ret = lockf(fd, F_LOCK, 0);
+ if (ret == 0) {
+ // exclusive lock acquired
+ const char *data = m_bulletin.data();
+ size_t remaining = m_bulletin.size();
+
+ while (remaining > 0) {
+ ret = write(fd, data, remaining);
+ if (ret == -1) {
+ close(fd);
+ etiLog.level(error) <<
+ "TAI-UTC bulletin write cache: " <<
+ strerror(errno);
+ return;
+ }
+
+ remaining -= ret;
+ data += ret;
+ }
+ etiLog.level(debug) << "TAI-UTC bulletin cache updated";
+ close(fd);
+ }
+ else {
+ close(fd);
+ etiLog.level(error) <<
+ "TAI-UTC bulletin acquire cache lock for writing: " <<
+ strerror(errno);
+ return;
+ }
}
@@ -536,27 +605,3 @@ void debug_tai_clk()
}
#endif
-#if TEST
-int main(int argc, char **argv)
-{
- using namespace std;
-
- ClockTAI tai({});
-
- while (wait_longer) {
- try {
- etiLog.level(info) <<
- "Offset is " << tai.get_offset();
- }
- catch (const exception &e) {
- etiLog.level(error) <<
- "Exception " << e.what();
- }
-
- this_thread::sleep_for(chrono::seconds(2));
- }
-
- return 0;
-}
-#endif
-
diff --git a/lib/ClockTAI.h b/lib/ClockTAI.h
index bb85815..50a6323 100644
--- a/lib/ClockTAI.h
+++ b/lib/ClockTAI.h
@@ -9,21 +9,21 @@
http://www.opendigitalradio.org
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
-*/
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
/* The EDI output needs TAI clock, according to ETSI TS 102 693 Annex F
* "EDI Timestamps". This module can set the local CLOCK_TAI clock by
diff --git a/src/dabOutput/edi/AFPacket.cpp b/lib/edioutput/AFPacket.cpp
index a58a980..b38c38b 100644
--- a/src/dabOutput/edi/AFPacket.cpp
+++ b/lib/edioutput/AFPacket.cpp
@@ -10,21 +10,21 @@
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#include "config.h"
#include "crc.h"
#include "AFPacket.h"
@@ -34,7 +34,7 @@
#include <string>
#include <iostream>
#include <cstdio>
-#include <stdint.h>
+#include <cstdint>
#include <arpa/inet.h>
namespace edi {
diff --git a/src/dabOutput/edi/AFPacket.h b/lib/edioutput/AFPacket.h
index b4ccef1..f2c4e35 100644
--- a/src/dabOutput/edi/AFPacket.h
+++ b/lib/edioutput/AFPacket.h
@@ -10,27 +10,27 @@
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#pragma once
#include "config.h"
#include <vector>
-#include <stdint.h>
+#include <cstdint>
#include "TagItems.h"
#include "TagPacket.h"
diff --git a/src/dabOutput/edi/Config.h b/lib/edioutput/Config.h
index 0c7dce8..ca76322 100644
--- a/src/dabOutput/edi/Config.h
+++ b/lib/edioutput/Config.h
@@ -9,21 +9,21 @@
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#pragma once
diff --git a/src/dabOutput/edi/Interleaver.cpp b/lib/edioutput/Interleaver.cpp
index f26a50e..f26a50e 100644
--- a/src/dabOutput/edi/Interleaver.cpp
+++ b/lib/edioutput/Interleaver.cpp
diff --git a/src/dabOutput/edi/Interleaver.h b/lib/edioutput/Interleaver.h
index f1cff30..3029d5d 100644
--- a/src/dabOutput/edi/Interleaver.h
+++ b/lib/edioutput/Interleaver.h
@@ -13,21 +13,21 @@
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#pragma once
@@ -35,7 +35,7 @@
#include <vector>
#include <deque>
#include <stdexcept>
-#include <stdint.h>
+#include <cstdint>
#include "Log.h"
#include "PFT.h"
diff --git a/src/dabOutput/edi/PFT.cpp b/lib/edioutput/PFT.cpp
index 63dfa34..371d36f 100644
--- a/src/dabOutput/edi/PFT.cpp
+++ b/lib/edioutput/PFT.cpp
@@ -14,28 +14,28 @@
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#include "config.h"
#include <vector>
#include <list>
#include <cstdio>
#include <cstring>
-#include <stdint.h>
+#include <cstdint>
#include <arpa/inet.h>
#include <stdexcept>
#include <sstream>
diff --git a/src/dabOutput/edi/PFT.h b/lib/edioutput/PFT.h
index 4076bf3..0ff4839 100644
--- a/src/dabOutput/edi/PFT.h
+++ b/lib/edioutput/PFT.h
@@ -14,21 +14,21 @@
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#pragma once
@@ -36,11 +36,11 @@
#include <vector>
#include <list>
#include <stdexcept>
-#include <stdint.h>
+#include <cstdint>
#include "AFPacket.h"
#include "Log.h"
#include "ReedSolomon.h"
-#include "dabOutput/edi/Config.h"
+#include "Config.h"
namespace edi {
diff --git a/src/dabOutput/edi/TagItems.cpp b/lib/edioutput/TagItems.cpp
index dfb4934..35a6852 100644
--- a/src/dabOutput/edi/TagItems.cpp
+++ b/lib/edioutput/TagItems.cpp
@@ -10,32 +10,40 @@
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#include "config.h"
#include "TagItems.h"
#include <vector>
#include <iostream>
#include <string>
-#include <stdint.h>
+#include <cstdint>
#include <stdexcept>
namespace edi {
+TagStarPTR::TagStarPTR(const std::string& protocol)
+ : m_protocol(protocol)
+{
+ if (m_protocol.size() != 4) {
+ throw std::runtime_error("TagStarPTR protocol invalid length");
+ }
+}
+
std::vector<uint8_t> TagStarPTR::Assemble()
{
//std::cerr << "TagItem *ptr" << std::endl;
@@ -47,8 +55,7 @@ std::vector<uint8_t> TagStarPTR::Assemble()
packet.push_back(0);
packet.push_back(0x40);
- std::string protocol("DETI");
- packet.insert(packet.end(), protocol.begin(), protocol.end());
+ packet.insert(packet.end(), m_protocol.begin(), m_protocol.end());
// Major
packet.push_back(0);
@@ -193,6 +200,166 @@ std::vector<uint8_t> TagESTn::Assemble()
return packet;
}
+std::vector<uint8_t> TagDSTI::Assemble()
+{
+ std::string pack_data("dsti");
+ std::vector<uint8_t> packet(pack_data.begin(), pack_data.end());
+ packet.reserve(256);
+
+ // Placeholder for length
+ packet.push_back(0);
+ packet.push_back(0);
+ packet.push_back(0);
+ packet.push_back(0);
+
+ uint8_t dfctl = dflc % 250;
+ uint8_t dfcth = dflc / 250;
+
+
+ uint16_t dstiHeader = dfctl | (dfcth << 8) | (rfadf << 13) | (atstf << 14) | (stihf << 15);
+ packet.push_back(dstiHeader >> 8);
+ packet.push_back(dstiHeader & 0xFF);
+
+ if (stihf) {
+ packet.push_back(stat);
+ packet.push_back((spid >> 8) & 0xFF);
+ packet.push_back(spid & 0xFF);
+ }
+
+ if (atstf) {
+ packet.push_back(utco);
+
+ packet.push_back((seconds >> 24) & 0xFF);
+ packet.push_back((seconds >> 16) & 0xFF);
+ packet.push_back((seconds >> 8) & 0xFF);
+ packet.push_back(seconds & 0xFF);
+
+ packet.push_back((tsta >> 16) & 0xFF);
+ packet.push_back((tsta >> 8) & 0xFF);
+ packet.push_back(tsta & 0xFF);
+ }
+
+ if (rfadf) {
+ for (size_t i = 0; i < rfad.size(); i++) {
+ packet.push_back(rfad[i]);
+ }
+ }
+ // calculate and update size
+ // remove TAG name and TAG length fields and convert to bits
+ uint32_t taglength = (packet.size() - 8) * 8;
+
+ // write length into packet
+ packet[4] = (taglength >> 24) & 0xFF;
+ packet[5] = (taglength >> 16) & 0xFF;
+ packet[6] = (taglength >> 8) & 0xFF;
+ packet[7] = taglength & 0xFF;
+
+ dflc = (dflc+1) % 5000;
+
+ /*
+ std::cerr << "TagItem dsti, packet.size " << packet.size() << std::endl;
+ std::cerr << " length " << taglength / 8 << std::endl;
+ */
+ return packet;
+}
+
+void TagDSTI::set_edi_time(const std::time_t t, int tai_utc_offset)
+{
+ utco = tai_utc_offset - 32;
+
+ const std::time_t posix_timestamp_1_jan_2000 = 946684800;
+
+ seconds = t - posix_timestamp_1_jan_2000 + utco;
+}
+
+#if 0
+/* Update the EDI time. t is in UTC, TAI offset is requested from adjtimex */
+void TagDSTI::set_edi_time(const std::time_t t)
+{
+ if (tai_offset_cache_updated_at == 0 or tai_offset_cache_updated_at + 3600 < t) {
+ struct timex timex_request;
+ timex_request.modes = 0;
+
+ int err = adjtimex(&timex_request);
+ if (err == -1) {
+ throw std::runtime_error("adjtimex failed");
+ }
+
+ if (timex_request.tai == 0) {
+ throw std::runtime_error("CLOCK_TAI is not properly set up");
+ }
+ tai_offset_cache = timex_request.tai;
+ tai_offset_cache_updated_at = t;
+
+ fprintf(stderr, "adjtimex: %d, tai %d\n", err, timex_request.tai);
+ }
+
+ utco = tai_offset_cache - 32;
+
+ const std::time_t posix_timestamp_1_jan_2000 = 946684800;
+
+ seconds = t - posix_timestamp_1_jan_2000 + utco;
+}
+#endif
+
+std::vector<uint8_t> TagSSm::Assemble()
+{
+ std::string pack_data("ss");
+ std::vector<uint8_t> packet(pack_data.begin(), pack_data.end());
+ packet.reserve(istd_length + 16);
+
+ packet.push_back((id >> 8) & 0xFF);
+ packet.push_back(id & 0xFF);
+
+ // Placeholder for length
+ packet.push_back(0);
+ packet.push_back(0);
+ packet.push_back(0);
+ packet.push_back(0);
+
+ if (rfa > 0x1F) {
+ throw std::runtime_error("TagSSm: invalid RFA value");
+ }
+
+ if (tid > 0x7) {
+ throw std::runtime_error("TagSSm: invalid tid value");
+ }
+
+ if (tidext > 0x7) {
+ throw std::runtime_error("TagSSm: invalid tidext value");
+ }
+
+ if (stid > 0x0FFF) {
+ throw std::runtime_error("TagSSm: invalid stid value");
+ }
+
+ uint32_t istc = (rfa << 19) | (tid << 16) | (tidext << 13) | ((crcstf ? 1 : 0) << 12) | stid;
+ packet.push_back((istc >> 16) & 0xFF);
+ packet.push_back((istc >> 8) & 0xFF);
+ packet.push_back(istc & 0xFF);
+
+ for (size_t i = 0; i < istd_length; i++) {
+ packet.push_back(istd_data[i]);
+ }
+
+ // calculate and update size
+ // remove TAG name and TAG length fields and convert to bits
+ uint32_t taglength = (packet.size() - 8) * 8;
+
+ // write length into packet
+ packet[4] = (taglength >> 24) & 0xFF;
+ packet[5] = (taglength >> 16) & 0xFF;
+ packet[6] = (taglength >> 8) & 0xFF;
+ packet[7] = taglength & 0xFF;
+
+ /*
+ std::cerr << "TagItem SSm, length " << packet.size() << std::endl;
+ std::cerr << " istd_length " << istd_length << std::endl;
+ */
+ return packet;
+}
+
+
std::vector<uint8_t> TagStarDMY::Assemble()
{
std::string pack_data("*dmy");
diff --git a/src/dabOutput/edi/TagItems.h b/lib/edioutput/TagItems.h
index b29a142..25daa14 100644
--- a/src/dabOutput/edi/TagItems.h
+++ b/lib/edioutput/TagItems.h
@@ -10,30 +10,30 @@
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#pragma once
#include "config.h"
-#include "Eti.h"
#include <vector>
+#include <array>
#include <chrono>
#include <string>
-#include <stdint.h>
+#include <cstdint>
namespace edi {
@@ -47,7 +47,11 @@ class TagItem
class TagStarPTR : public TagItem
{
public:
+ TagStarPTR(const std::string& protocol);
std::vector<uint8_t> Assemble();
+
+ private:
+ std::string m_protocol = "";
};
// ETSI TS 102 693, 5.1.3 DAB ETI(LI) Management (deti)
@@ -133,6 +137,82 @@ class TagESTn : public TagItem
uint8_t id;
};
+// ETSI TS 102 693, 5.1.2 DAB STI-D(LI) Management
+class TagDSTI : public TagItem
+{
+ public:
+ std::vector<uint8_t> Assemble();
+
+ // dsti Header
+ bool stihf = false;
+ bool atstf = false; // presence of atst data
+ bool rfadf = false;
+ uint16_t dflc = 0; // modulo 5000 frame counter
+
+ // STI Header (optional)
+ uint8_t stat = 0;
+ uint16_t spid = 0;
+
+ /* UTCO: Offset (in seconds) between UTC and the Seconds value. The
+ * value is expressed as an unsigned 8-bit quantity. As of February
+ * 2009, the value shall be 2 and shall change as a result of each
+ * modification of the number of leap seconds, as proscribed by
+ * International Earth Rotation and Reference Systems Service (IERS).
+ *
+ * According to Annex F
+ * EDI = TAI - 32s (constant)
+ * EDI = UTC + UTCO
+ * we derive
+ * UTCO = TAI-UTC - 32
+ * where the TAI-UTC offset is given by the USNO bulletin using
+ * the ClockTAI module.
+ */
+ uint8_t utco = 0;
+
+ /* Update the EDI time. t is in UTC */
+ void set_edi_time(const std::time_t t, int tai_utc_offset);
+
+ /* The number of SI seconds since 2000-01-01 T 00:00:00 UTC as an
+ * unsigned 32-bit quantity. Contrary to POSIX, this value also
+ * counts leap seconds.
+ */
+ uint32_t seconds = 0;
+
+ /* TSTA: Shall be the 24 least significant bits of the Time Stamp
+ * (TIST) field from the STI-D(LI) Frame. The full definition for the
+ * STI TIST can be found in annex B of EN 300 797 [4]. The most
+ * significant 8 bits of the TIST field of the incoming STI-D(LI)
+ * frame, if required, may be carried in the RFAD field.
+ */
+ uint32_t tsta = 0xFFFFFF;
+
+ std::array<uint8_t, 9> rfad;
+
+ private:
+ int tai_offset_cache = 0;
+ std::time_t tai_offset_cache_updated_at = 0;
+};
+
+// ETSI TS 102 693, 5.1.4 STI-D Payload Stream <m>
+class TagSSm : public TagItem
+{
+ public:
+ std::vector<uint8_t> Assemble();
+
+ // SSTCn
+ uint8_t rfa = 0;
+ uint8_t tid = 0; // See EN 300 797, 5.4.1.1. Value 0 means "MSC sub-channel"
+ uint8_t tidext = 0; // EN 300 797, 5.4.1.3, Value 0 means "MSC audio stream"
+ bool crcstf = false;
+ uint16_t stid = 0;
+
+ // Pointer to ISTDm data
+ const uint8_t *istd_data;
+ size_t istd_length; // bytes
+
+ uint16_t id = 0;
+};
+
// ETSI TS 102 821, 5.2.2.2 Dummy padding
class TagStarDMY : public TagItem
{
diff --git a/src/dabOutput/edi/TagPacket.cpp b/lib/edioutput/TagPacket.cpp
index b16dc33..b0bf9a1 100644
--- a/src/dabOutput/edi/TagPacket.cpp
+++ b/lib/edioutput/TagPacket.cpp
@@ -8,31 +8,30 @@
This defines a TAG Packet.
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#include "config.h"
-#include "Eti.h"
#include "TagPacket.h"
#include "TagItems.h"
#include <vector>
#include <iostream>
#include <string>
#include <list>
-#include <stdint.h>
+#include <cstdint>
#include <cassert>
namespace edi {
diff --git a/src/dabOutput/edi/TagPacket.h b/lib/edioutput/TagPacket.h
index a861cbb..1e40ce7 100644
--- a/src/dabOutput/edi/TagPacket.h
+++ b/lib/edioutput/TagPacket.h
@@ -8,21 +8,21 @@
This defines a TAG Packet.
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#pragma once
@@ -31,7 +31,7 @@
#include <vector>
#include <string>
#include <list>
-#include <stdint.h>
+#include <cstdint>
namespace edi {
diff --git a/src/dabOutput/edi/Transport.cpp b/lib/edioutput/Transport.cpp
index 187aabe..0d5c237 100644
--- a/src/dabOutput/edi/Transport.cpp
+++ b/lib/edioutput/Transport.cpp
@@ -9,22 +9,21 @@
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
-
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#include "Transport.h"
#include <iterator>
diff --git a/src/dabOutput/edi/Transport.h b/lib/edioutput/Transport.h
index 9633275..325acf8 100644
--- a/src/dabOutput/edi/Transport.h
+++ b/lib/edioutput/Transport.h
@@ -9,26 +9,26 @@
*/
/*
- This file is part of ODR-DabMux.
+ This file is part of the ODR-mmbTools.
- ODR-DabMux is free software: you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
- ODR-DabMux is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
- */
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#pragma once
#include "config.h"
-#include "dabOutput/edi/Config.h"
+#include "Config.h"
#include "AFPacket.h"
#include "PFT.h"
#include "Interleaver.h"
diff --git a/src/DabMultiplexer.cpp b/src/DabMultiplexer.cpp
index 489787f..0d68ac2 100644
--- a/src/DabMultiplexer.cpp
+++ b/src/DabMultiplexer.cpp
@@ -376,7 +376,7 @@ void DabMultiplexer::mux_frame(std::vector<std::shared_ptr<DabOutput> >& outputs
// For EDI, save ETI(LI) Management data into a TAG Item DETI
edi::TagDETI edi_tagDETI;
- edi::TagStarPTR edi_tagStarPtr;
+ edi::TagStarPTR edi_tagStarPtr("DETI");
map<DabSubchannel*, edi::TagESTn> edi_subchannelToTag;
// The above Tag Items will be assembled into a TAG Packet
diff --git a/src/DabMultiplexer.h b/src/DabMultiplexer.h
index d1075a6..56a8dde 100644
--- a/src/DabMultiplexer.h
+++ b/src/DabMultiplexer.h
@@ -30,10 +30,10 @@
#endif
#include "dabOutput/dabOutput.h"
-#include "dabOutput/edi/TagItems.h"
-#include "dabOutput/edi/TagPacket.h"
-#include "dabOutput/edi/AFPacket.h"
-#include "dabOutput/edi/Transport.h"
+#include "edioutput/TagItems.h"
+#include "edioutput/TagPacket.h"
+#include "edioutput/AFPacket.h"
+#include "edioutput/Transport.h"
#include "fig/FIGCarousel.h"
#include "crc.h"
#include "utils.h"
diff --git a/src/zmq2edi/EDISender.cpp b/src/zmq2edi/EDISender.cpp
index 2128abf..2188f8a 100644
--- a/src/zmq2edi/EDISender.cpp
+++ b/src/zmq2edi/EDISender.cpp
@@ -79,7 +79,7 @@ void EDISender::print_configuration()
void EDISender::send_eti_frame(uint8_t* p, metadata_t metadata)
{
edi::TagDETI edi_tagDETI;
- edi::TagStarPTR edi_tagStarPtr;
+ edi::TagStarPTR edi_tagStarPtr("DETI");
map<int, edi::TagESTn> edi_subchannelToTag;
// The above Tag Items will be assembled into a TAG Packet
edi::TagPacket edi_tagpacket(edi_conf.tagpacket_alignment);
diff --git a/src/zmq2edi/EDISender.h b/src/zmq2edi/EDISender.h
index bb9c8bc..3525b4b 100644
--- a/src/zmq2edi/EDISender.h
+++ b/src/zmq2edi/EDISender.h
@@ -34,9 +34,9 @@
#include <atomic>
#include "ThreadsafeQueue.h"
#include "dabOutput/dabOutput.h"
-#include "dabOutput/edi/TagItems.h"
-#include "dabOutput/edi/TagPacket.h"
-#include "dabOutput/edi/Transport.h"
+#include "edioutput/TagItems.h"
+#include "edioutput/TagPacket.h"
+#include "edioutput/Transport.h"
// This metadata gets transmitted in the zmq stream
struct metadata_t {