From 1bc816994033cffd9ec0b4d961783f4e0a67e33d Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Sat, 13 Jul 2013 13:49:10 +1000 Subject: [PATCH] Accrue time adjustments for HLS recorder. 4f645a870b974b367b011973b5b826f5cc5f5e39 improved HLS recording greatly, however didn't cater in case the HLS ringbuffer took a long time (like when it's rebuffering), Adjust logic to accrue the time differences and adjust waiting time accordingly --- .../libmythtv/recorders/hlsstreamhandler.cpp | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/mythtv/libs/libmythtv/recorders/hlsstreamhandler.cpp b/mythtv/libs/libmythtv/recorders/hlsstreamhandler.cpp index e04c87ceda3..0885ef53d54 100644 --- a/mythtv/libs/libmythtv/recorders/hlsstreamhandler.cpp +++ b/mythtv/libs/libmythtv/recorders/hlsstreamhandler.cpp @@ -125,12 +125,12 @@ void HLSStreamHandler::run(void) m_hls->OpenFile(m_tuning.GetURL(0).toString()); } + uint64_t startup = MythDate::current().toMSecsSinceEpoch(); + uint64_t expected = 0; + while (m_hls->IsOpen() && _running_desired) { - QDateTime before = MythDate::current(); int size = m_hls->Read((void*)m_buffer, BUFFER_SIZE); - QDateTime after = MythDate::current(); - uint64_t duration = before.msecsTo(after); if (size < 0) { @@ -153,7 +153,6 @@ void HLSStreamHandler::run(void) remainder = sit.key()->ProcessData(m_buffer, size); } } - if (remainder != 0) { @@ -161,14 +160,13 @@ void HLSStreamHandler::run(void) QString("data_length = %1 remainder = %2") .arg(size).arg(remainder)); } - uint64_t waiting = m_hls->DurationForBytes(size); - if (waiting > duration) - { - waiting -= duration; - } - else + + expected += m_hls->DurationForBytes(size); + uint64_t actual = MythDate::current().toMSecsSinceEpoch() - startup; + uint64_t waiting = 0; + if (expected > actual) { - waiting = 0; + waiting = expected-actual; } // The HLS Stream Handler feeds data to the MPEGStreamData, however it feeds // data as fast as the MPEGStream can accept it, which quickly exhausts the HLS buffer. @@ -177,8 +175,9 @@ void HLSStreamHandler::run(void) // The frontend will usually timeout by then. // So we simulate a live mechanism by pausing before feeding new data // to the MPEGStreamData - LOG(VB_RECORD, LOG_DEBUG, LOC + QString("waiting %1ms").arg(waiting)); - usleep(waiting * 750); // wait 3/4th of this time + LOG(VB_RECORD, LOG_DEBUG, LOC + QString("waiting %1ms (actual:%2, expected:%3)") + .arg(waiting).arg(actual).arg(expected)); + usleep(waiting * 1000); } SetRunning(false, false, false);