Skip to content

Commit

Permalink
Accrue time adjustments for HLS recorder.
Browse files Browse the repository at this point in the history
4f645a8 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
  • Loading branch information
jyavenard committed Jul 14, 2013
1 parent f6fbe1d commit 1bc8169
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions mythtv/libs/libmythtv/recorders/hlsstreamhandler.cpp
Expand Up @@ -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)
{
Expand All @@ -153,22 +153,20 @@ void HLSStreamHandler::run(void)
remainder = sit.key()->ProcessData(m_buffer, size);
}
}


if (remainder != 0)
{
LOG(VB_RECORD, LOG_INFO, LOC +
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.
Expand All @@ -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);
Expand Down

0 comments on commit 1bc8169

Please sign in to comment.