summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-09-05 17:09:44 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-09-05 17:10:48 +0200
commit716b3d84adaaa36c9dd8652ec43fc88e760da611 (patch)
tree0543ad7760e3b76e44ff623eaf07872ecdb9013c /src
parent1ed62f38f32b219f1eb7e9e06024f9fa86eb58bc (diff)
downloaddabmux-716b3d84adaaa36c9dd8652ec43fc88e760da611.tar.gz
dabmux-716b3d84adaaa36c9dd8652ec43fc88e760da611.tar.bz2
dabmux-716b3d84adaaa36c9dd8652ec43fc88e760da611.zip
Fix EDI with timestamping input
Diffstat (limited to 'src')
-rw-r--r--src/DabMultiplexer.cpp53
-rw-r--r--src/input/Edi.cpp18
-rw-r--r--src/input/Edi.h2
-rw-r--r--src/input/File.cpp2
-rw-r--r--src/input/File.h2
-rw-r--r--src/input/Prbs.cpp2
-rw-r--r--src/input/Prbs.h2
-rw-r--r--src/input/Udp.cpp2
-rw-r--r--src/input/Udp.h2
-rw-r--r--src/input/Zmq.cpp2
-rw-r--r--src/input/Zmq.h2
-rw-r--r--src/input/inputs.h4
12 files changed, 46 insertions, 47 deletions
diff --git a/src/DabMultiplexer.cpp b/src/DabMultiplexer.cpp
index 6b887bd..549850a 100644
--- a/src/DabMultiplexer.cpp
+++ b/src/DabMultiplexer.cpp
@@ -380,6 +380,17 @@ void DabMultiplexer::mux_frame(std::vector<std::shared_ptr<DabOutput> >& outputs
// The above Tag Items will be assembled into a TAG Packet
edi::TagPacket edi_tagpacket(edi_conf.tagpacket_alignment);
+ const bool tist_enabled = m_pt.get("general.tist", false);
+
+ int tai_utc_offset = 0;
+ if (tist_enabled and m_tai_clock_required) {
+ try {
+ tai_utc_offset = m_clock_tai.get_offset();
+ }
+ catch (const std::runtime_error& e) {
+ etiLog.level(error) << "Could not get UTC-TAI offset for EDI timestamp";
+ }
+ }
update_dab_time();
// Initialise the ETI frame
@@ -588,7 +599,8 @@ void DabMultiplexer::mux_frame(std::vector<std::shared_ptr<DabOutput> >& outputs
break;
case BufferManagement::Timestamped:
// no need to check enableTist because we always increment the timestamp
- result = subchannel->input->readFrame(&etiFrame[index], sizeSubchannel, edi_time + m_tist_offset, timestamp);
+ result = subchannel->input->readFrame(&etiFrame[index],
+ sizeSubchannel, edi_time + m_tist_offset, tai_utc_offset, timestamp);
break;
}
@@ -643,34 +655,25 @@ void DabMultiplexer::mux_frame(std::vector<std::shared_ptr<DabOutput> >& outputs
edi_tagDETI.tsta = 0xffffff;
}
- const bool tist_enabled = m_pt.get("general.tist", false);
-
if (tist_enabled and m_tai_clock_required) {
- try {
- const auto tai_utc_offset = m_clock_tai.get_offset();
- edi_tagDETI.set_edi_time(edi_time + m_tist_offset, tai_utc_offset);
- edi_tagDETI.atstf = true;
-
- for (auto output : outputs) {
- shared_ptr<OutputMetadata> md_utco =
- make_shared<OutputMetadataUTCO>(edi_tagDETI.utco);
- output->setMetadata(md_utco);
-
- shared_ptr<OutputMetadata> md_edi_time =
- make_shared<OutputMetadataEDITime>(edi_tagDETI.seconds);
- output->setMetadata(md_edi_time);
-
- shared_ptr<OutputMetadata> md_dlfc =
- make_shared<OutputMetadataDLFC>(currentFrame % 5000);
- output->setMetadata(md_dlfc);
- }
- }
- catch (const std::runtime_error& e) {
- etiLog.level(error) << "Could not get UTC-TAI offset for EDI timestamp";
+ edi_tagDETI.set_edi_time(edi_time + m_tist_offset, tai_utc_offset);
+ edi_tagDETI.atstf = true;
+
+ for (auto output : outputs) {
+ shared_ptr<OutputMetadata> md_utco =
+ make_shared<OutputMetadataUTCO>(edi_tagDETI.utco);
+ output->setMetadata(md_utco);
+
+ shared_ptr<OutputMetadata> md_edi_time =
+ make_shared<OutputMetadataEDITime>(edi_tagDETI.seconds);
+ output->setMetadata(md_edi_time);
+
+ shared_ptr<OutputMetadata> md_dlfc =
+ make_shared<OutputMetadataDLFC>(currentFrame % 5000);
+ output->setMetadata(md_dlfc);
}
}
-
/* Coding of the TIST, according to ETS 300 799 Annex C
Bit number b0(MSb)..b6 b7..b9 b10..b17 b18..b20 b21..b23(LSb)
diff --git a/src/input/Edi.cpp b/src/input/Edi.cpp
index 6e0e683..247c16f 100644
--- a/src/input/Edi.cpp
+++ b/src/input/Edi.cpp
@@ -155,7 +155,7 @@ size_t Edi::readFrame(uint8_t *buffer, size_t size)
}
}
-size_t Edi::readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t tsta)
+size_t Edi::readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utco, uint32_t tsta)
{
if (m_pending_sti_frame.frame.empty()) {
m_frames.try_pop(m_pending_sti_frame);
@@ -171,12 +171,10 @@ size_t Edi::readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t t
// difference between the input frame timestamp and the requested
// timestamp.
if (m_pending_sti_frame.timestamp.valid()) {
- double ts_frame = (double)m_pending_sti_frame.timestamp.seconds +
- (m_pending_sti_frame.timestamp.tsta / 16384000.0);
+ const auto ts_req = EdiDecoder::frame_timestamp_t::from_unix_epoch(seconds, utco, tsta);
+ const double offset = m_pending_sti_frame.timestamp.diff_ms(ts_req);
- double ts_req = (double)seconds + (tsta / 16384000.0);
-
- if (std::abs(ts_frame - ts_req) < 24e-3) {
+ if (offset < 24e-3) {
m_is_prebuffering = false;
etiLog.level(warn) << "EDI input " << m_name <<
" valid timestamp, pre-buffering complete";
@@ -226,12 +224,10 @@ size_t Edi::readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t t
return 0;
}
else {
- double ts_frame = (double)sti_frame.timestamp.seconds +
- (sti_frame.timestamp.tsta / 16384000.0);
-
- double ts_req = (double)seconds + (tsta / 16384000.0);
+ const auto ts_req = EdiDecoder::frame_timestamp_t::from_unix_epoch(seconds, utco, tsta);
+ const double offset = m_pending_sti_frame.timestamp.diff_ms(ts_req);
- if (std::abs(ts_frame - ts_req) > 24e-3) {
+ if (offset > 24e-3) {
m_is_prebuffering = true;
etiLog.level(warn) << "EDI input " << m_name <<
" timestamp out of bounds, re-enabling pre-buffering";
diff --git a/src/input/Edi.h b/src/input/Edi.h
index bf65ac9..8f270d0 100644
--- a/src/input/Edi.h
+++ b/src/input/Edi.h
@@ -54,7 +54,7 @@ class Edi : public InputBase {
virtual void open(const std::string& name);
virtual size_t readFrame(uint8_t *buffer, size_t size);
- virtual size_t readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t tsta);
+ virtual size_t readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utco, uint32_t tsta);
virtual int setBitrate(int bitrate);
virtual void close();
diff --git a/src/input/File.cpp b/src/input/File.cpp
index 9c36263..46bfb59 100644
--- a/src/input/File.cpp
+++ b/src/input/File.cpp
@@ -74,7 +74,7 @@ void FileBase::open(const std::string& name)
}
}
-size_t FileBase::readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t tsta)
+size_t FileBase::readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utco, uint32_t tsta)
{
// Will not be implemented, as there is no obvious way to carry timestamps
// in files.
diff --git a/src/input/File.h b/src/input/File.h
index 3e96ad4..39ce7fd 100644
--- a/src/input/File.h
+++ b/src/input/File.h
@@ -38,7 +38,7 @@ class FileBase : public InputBase {
public:
virtual void open(const std::string& name);
virtual size_t readFrame(uint8_t *buffer, size_t size) = 0;
- virtual size_t readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t tsta);
+ virtual size_t readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utco, uint32_t tsta);
virtual int setBitrate(int bitrate);
virtual void close();
diff --git a/src/input/Prbs.cpp b/src/input/Prbs.cpp
index 148e919..155e625 100644
--- a/src/input/Prbs.cpp
+++ b/src/input/Prbs.cpp
@@ -84,7 +84,7 @@ size_t Prbs::readFrame(uint8_t *buffer, size_t size)
return size;
}
-size_t Prbs::readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t tsta)
+size_t Prbs::readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utco, uint32_t tsta)
{
memset(buffer, 0, size);
return 0;
diff --git a/src/input/Prbs.h b/src/input/Prbs.h
index 600fd89..e2b94ec 100644
--- a/src/input/Prbs.h
+++ b/src/input/Prbs.h
@@ -39,7 +39,7 @@ class Prbs : public InputBase {
public:
virtual void open(const std::string& name);
virtual size_t readFrame(uint8_t *buffer, size_t size);
- virtual size_t readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t tsta);
+ virtual size_t readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utco, uint32_t tsta);
virtual int setBitrate(int bitrate);
virtual void close();
diff --git a/src/input/Udp.cpp b/src/input/Udp.cpp
index 5ddc366..a37ee21 100644
--- a/src/input/Udp.cpp
+++ b/src/input/Udp.cpp
@@ -105,7 +105,7 @@ size_t Udp::readFrame(uint8_t *buffer, size_t size)
}
}
-size_t Udp::readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t tsta)
+size_t Udp::readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utco, uint32_t tsta)
{
// Maybe there's a way to carry timestamps, but we don't need it.
memset(buffer, 0x0, size);
diff --git a/src/input/Udp.h b/src/input/Udp.h
index 81956f9..e5961c7 100644
--- a/src/input/Udp.h
+++ b/src/input/Udp.h
@@ -42,7 +42,7 @@ class Udp : public InputBase {
public:
virtual void open(const std::string& name);
virtual size_t readFrame(uint8_t *buffer, size_t size);
- virtual size_t readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t tsta);
+ virtual size_t readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utco, uint32_t tsta);
virtual int setBitrate(int bitrate);
virtual void close();
diff --git a/src/input/Zmq.cpp b/src/input/Zmq.cpp
index 352c95d..0a9d59d 100644
--- a/src/input/Zmq.cpp
+++ b/src/input/Zmq.cpp
@@ -331,7 +331,7 @@ size_t ZmqBase::readFrame(uint8_t* buffer, size_t size)
}
}
-size_t ZmqBase::readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t tsta)
+size_t ZmqBase::readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utco, uint32_t tsta)
{
// TODO add timestamps into the metadata and implement this
memset(buffer, 0, size);
diff --git a/src/input/Zmq.h b/src/input/Zmq.h
index 899d6f2..2e37b5f 100644
--- a/src/input/Zmq.h
+++ b/src/input/Zmq.h
@@ -183,7 +183,7 @@ class ZmqBase : public InputBase, public RemoteControllable {
virtual void open(const std::string& inputUri);
virtual size_t readFrame(uint8_t *buffer, size_t size);
- virtual size_t readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t tsta);
+ virtual size_t readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utco, uint32_t tsta);
virtual int setBitrate(int bitrate);
virtual void close();
diff --git a/src/input/inputs.h b/src/input/inputs.h
index b4bb00b..b99a88f 100644
--- a/src/input/inputs.h
+++ b/src/input/inputs.h
@@ -56,7 +56,7 @@ class InputBase {
/* read a frame from the input, taking into account timestamp. The timestamp of the data
* returned is not more recent than the timestamp specified in seconds and tsta.
*
- * seconds and tsta are in the format used by EDI.
+ * seconds is in UNIX epoch, utco is the TAI-UTC offset, tsta is in the format used by ETI.
*
* Returns number of data bytes written to the buffer. May clear the buffer
* if no data bytes available, in which case it will return 0.
@@ -66,7 +66,7 @@ class InputBase {
* Calling this function on inputs that do not support timestamps returns 0. This allows
* changing the buffer management at runtime without risking an crash due to an exception.
*/
- virtual size_t readFrame(uint8_t *buffer, size_t size, uint32_t seconds, uint32_t tsta) = 0;
+ virtual size_t readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utco, uint32_t tsta) = 0;
/* Returns the effectively used bitrate, or throws invalid_argument on invalid bitrate */
virtual int setBitrate(int bitrate) = 0;