31 changes: 16 additions & 15 deletions mythtv/libs/libmythbase/mythtimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ MythTimer::MythTimer(StartState state)
void MythTimer::start(void)
{
m_timer.start();
m_offset = 0;
m_offset = 0ms;
}

/** Returns milliseconds elapsed since last start() or restart()
Expand All @@ -59,15 +59,16 @@ void MythTimer::start(void)
* \note If addMSecs() has been called and the total offset applied
* is negative then this can return a negative number.
*/
int MythTimer::restart(void)
std::chrono::milliseconds MythTimer::restart(void)
{
if (m_timer.isValid())
{
int val = static_cast<int>(m_timer.restart() + m_offset);
m_offset = 0;
auto val = std::chrono::milliseconds(m_timer.restart()) + m_offset;
m_offset = 0ms;
return val;
}
return start(), 0;
start();
return 0ms;
}

/** Stops timer, next call to isRunning() will return false and
Expand All @@ -87,24 +88,24 @@ void MythTimer::stop(void)
* \note If addMSecs() has been called and the total offset applied
* is negative then this can return a negative number.
*/
int MythTimer::elapsed(void)
std::chrono::milliseconds MythTimer::elapsed(void)
{
if (!m_timer.isValid())
{
#ifdef DEBUG_TIMER_API_USAGE
assert(0 == "elapsed called without timer being started");
#endif
return 0;
return 0ms;
}

qint64 e = m_timer.elapsed();
if (!QElapsedTimer::isMonotonic() && (e > 86300000))
auto e = std::chrono::milliseconds(m_timer.elapsed());
if (!QElapsedTimer::isMonotonic() && (e > (24h - 100s)))
{
start();
e = 0;
e = 0ms;
}

return static_cast<int>(e + m_offset);
return e + m_offset;
}

/** Returns nanoseconds elapsed since last start() or restart()
Expand All @@ -115,17 +116,17 @@ int MythTimer::elapsed(void)
* \note If addMSecs() has been called and the total offset applied
* is negative then this can return a negative number.
*/
int64_t MythTimer::nsecsElapsed(void) const
std::chrono::nanoseconds MythTimer::nsecsElapsed(void) const
{
if (!m_timer.isValid())
{
#ifdef DEBUG_TIMER_API_USAGE
assert(0 == "elapsed called without timer being started");
#endif
return 0;
return 0ns;
}

return m_timer.nsecsElapsed() + 1000000LL * m_offset;
return std::chrono::nanoseconds(m_timer.nsecsElapsed()) + m_offset;
}

/** Returns true if start() or restart() has been called at least
Expand All @@ -142,7 +143,7 @@ bool MythTimer::isRunning(void) const
* again. The offset may be positive or negative. This
* may be called multiple times to accrete various offsets.
*/
void MythTimer::addMSecs(int ms)
void MythTimer::addMSecs(std::chrono::milliseconds ms)
{
m_offset += ms;
}
13 changes: 6 additions & 7 deletions mythtv/libs/libmythbase/mythtimer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef MYTHTIMER_H_
#define MYTHTIMER_H_

#include <cinttypes>
#include <QElapsedTimer>
#include "mythbaseexp.h"
#include "mythchrono.h"
Expand All @@ -22,18 +21,18 @@ class MBASE_PUBLIC MythTimer
explicit MythTimer(StartState state = kStartInactive);

void start(void);
int restart(void);
std::chrono::milliseconds restart(void);
void stop(void);

void addMSecs(int ms);
void addMSecs(std::chrono::milliseconds ms);

int elapsed(void);
int64_t nsecsElapsed(void) const;
std::chrono::milliseconds elapsed(void);
std::chrono::nanoseconds nsecsElapsed(void) const;
bool isRunning(void) const;

private:
QElapsedTimer m_timer;
int m_offset {0};
QElapsedTimer m_timer;
std::chrono::milliseconds m_offset {0ms};
};

#endif
5 changes: 3 additions & 2 deletions mythtv/libs/libmythbase/portchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@
* of linkLocalOnly, return true if it was link local and
* was changed, false in other cases.
*/
bool PortChecker::checkPort(QString &host, int port, int timeLimit, bool linkLocalOnly)
bool PortChecker::checkPort(QString &host, int port, int timeLimitMS, bool linkLocalOnly)
{
auto timeLimit = std::chrono::milliseconds(timeLimitMS);
LOG(VB_GENERAL, LOG_DEBUG, LOC + QString("host %1 port %2 timeLimit %3 linkLocalOnly %4")
.arg(host).arg(port).arg(timeLimit).arg(linkLocalOnly));
.arg(host).arg(port).arg(timeLimit.count()).arg(linkLocalOnly));
m_cancelCheck = false;
QHostAddress addr;
bool isIPAddress = addr.setAddress(host);
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythbase/portchecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QString>

#include "mythbaseexp.h"
#include "mythchrono.h"

/**
* Small class to handle TCP port checking and finding link-local context.
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythbase/remotefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "threadedfilewriter.h"
#include "storagegroup.h"

#define MAX_FILE_CHECK 500 // in ms
static constexpr std::chrono::milliseconds MAX_FILE_CHECK { 500ms };

static bool RemoteSendReceiveStringList(const QString &host, QStringList &strlist)
{
Expand Down Expand Up @@ -993,7 +993,7 @@ int RemoteFile::Read(void *data, int size)
MythTimer mtimer;
mtimer.start();

while (recv < sent && !error && mtimer.elapsed() < 10000)
while (recv < sent && !error && mtimer.elapsed() < 10s)
{
int ret = m_sock->Read(((char *)data) + recv, sent - recv, waitms);

Expand Down
28 changes: 14 additions & 14 deletions mythtv/libs/libmythbase/test/test_mythtimer/test_mythtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,75 +48,75 @@ class TestMythTimer: public QObject
MythTimer t;
t.start();
std::this_thread::sleep_for(520ms);
QVERIFY(t.elapsed() > 500);
QVERIFY(t.elapsed() > 500ms);
}

static void TimeElapsesAfterRestart(void)
{
MythTimer t;
t.restart();
std::this_thread::sleep_for(520ms);
QVERIFY(t.elapsed() > 500);
QVERIFY(t.elapsed() > 500ms);
}

static void TimeDoesNotElapseImmediatelyAfterConstructionByDefault(void)
{
MythTimer t;
std::this_thread::sleep_for(520ms);
QVERIFY(t.elapsed() == 0);
QVERIFY(t.elapsed() == 0ms);
}

static void TimeDoesNotElapsesImmediatelyAfterContructionIfIntended(void)
{
MythTimer t(MythTimer::kStartRunning);
std::this_thread::sleep_for(520ms);
QVERIFY(t.elapsed() > 500);
QVERIFY(t.elapsed() > 500ms);
}

static void TimeElapsesContinually(void)
{
MythTimer t;
t.start();
std::this_thread::sleep_for(520ms);
QVERIFY(t.elapsed() > 500);
QVERIFY(t.elapsed() > 500ms);
std::this_thread::sleep_for(500ms);
QVERIFY(t.elapsed() > 1000);
QVERIFY(t.elapsed() > 1s);
}

static void TimeResetsOnRestart(void)
{
MythTimer t;
t.start();
std::this_thread::sleep_for(520ms);
QVERIFY(t.restart() > 500);
QVERIFY(t.restart() > 500ms);
std::this_thread::sleep_for(520ms);
QVERIFY(t.elapsed() > 500 && t.elapsed() < 750);
QVERIFY(t.elapsed() > 500ms && t.elapsed() < 750ms);
}

static void AddMSecsWorks(void)
{
MythTimer t;
t.start();
t.addMSecs(-250);
t.addMSecs(-250ms);
std::this_thread::sleep_for(520ms);
QVERIFY(t.elapsed() > 250 && t.elapsed() < 500);
QVERIFY(t.elapsed() > 250ms && t.elapsed() < 500ms);
}

static void AddMSecsIsResetOnStart(void)
{
MythTimer t;
t.addMSecs(-250);
t.addMSecs(-250ms);
t.start();
std::this_thread::sleep_for(520ms);
QVERIFY(t.elapsed() > 500);
QVERIFY(t.elapsed() > 500ms);
}

static void AddMSecsIsResetOnRestart(void)
{
MythTimer t;
t.addMSecs(-250);
t.addMSecs(-250ms);
t.restart();
std::this_thread::sleep_for(520ms);
QVERIFY(t.elapsed() > 500);
QVERIFY(t.elapsed() > 500ms);
}
};
12 changes: 6 additions & 6 deletions mythtv/libs/libmythbase/threadedfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,10 @@ void ThreadedFileWriter::DiskLoop(void)
continue;
}

int mwte = minWriteTimer.elapsed();
if (!m_flush && (mwte < 250) && (m_totalBufferUse < kMinWriteSize))
auto mwte = minWriteTimer.elapsed();
if (!m_flush && (mwte < 250ms) && (m_totalBufferUse < kMinWriteSize))
{
m_bufferHasData.wait(locker.mutex(), 250 - mwte);
m_bufferHasData.wait(locker.mutex(), (250ms - mwte).count());
TrimEmptyBuffers();
continue;
}
Expand Down Expand Up @@ -532,7 +532,7 @@ void ThreadedFileWriter::DiskLoop(void)

//////////////////////////////////////////

if (lastRegisterTimer.elapsed() >= 10000)
if (lastRegisterTimer.elapsed() >= 10s)
{
gCoreContext->RegisterFileForWrite(m_filename, total_written);
m_registered = true;
Expand All @@ -542,12 +542,12 @@ void ThreadedFileWriter::DiskLoop(void)
buf->lastUsed = MythDate::current();
m_emptyBuffers.push_back(buf);

if (writeTimer.elapsed() > 1000)
if (writeTimer.elapsed() > 1s)
{
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("write(%1) cnt %2 total %3 -- took a long time, %4 ms")
.arg(sz).arg(m_writeBuffers.size())
.arg(m_totalBufferUse).arg(writeTimer.elapsed()));
.arg(m_totalBufferUse).arg(writeTimer.elapsed().count()));
}

if (!write_ok && ((EFBIG == errno) || (ENOSPC == errno)))
Expand Down
7 changes: 4 additions & 3 deletions mythtv/libs/libmythtv/DVD/mythdvdplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ void MythDVDPlayer::ChangeSpeed(void)
// it to what the unstretched value would have been
// had we been playing with the new timestretch value
// all along
int elapsed = static_cast<int>((m_stillFrameTimer.elapsed() * m_playSpeed / m_nextPlaySpeed));
auto elapsed = millisecondsFromFloat(m_stillFrameTimer.elapsed().count() *
m_playSpeed / m_nextPlaySpeed);
m_stillFrameTimer.restart();
m_stillFrameTimer.addMSecs(elapsed);
m_stillFrameTimerLock.unlock();
Expand Down Expand Up @@ -461,7 +462,7 @@ int64_t MythDVDPlayer::GetSecondsPlayed(bool /*HonorCutList*/, int Divisor)
if (m_stillFrameLength == 255)
played = -1;
else
played = static_cast<int64_t>(m_stillFrameTimer.elapsed() * m_playSpeed / Divisor);
played = static_cast<int64_t>(m_stillFrameTimer.elapsed().count() * m_playSpeed / Divisor);
}

return played;
Expand Down Expand Up @@ -699,7 +700,7 @@ void MythDVDPlayer::StillFrameCheck(void)
(m_stillFrameLength > 0) && (m_stillFrameLength < 0xff))
{
m_stillFrameTimerLock.lock();
int elapsedTime = static_cast<int>(m_stillFrameTimer.elapsed() * m_playSpeed / 1000.0F);
int elapsedTime = static_cast<int>(m_stillFrameTimer.elapsed().count() * m_playSpeed / 1000.0F);
m_stillFrameTimerLock.unlock();
if (elapsedTime >= m_stillFrameLength)
{
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/HLS/httplivestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ DTC::LiveStreamInfo *HTTPLiveStream::StartStream(void)

HTTPLiveStreamStatus status = GetDBStatus();
while ((status == kHLSStatusQueued) &&
((statusTimer.elapsed() / 1000) < 30))
(statusTimer.elapsed() < 30s))
{
delay = (int)(delay * 1.5);
usleep(delay);
Expand Down Expand Up @@ -940,7 +940,7 @@ DTC::LiveStreamInfo *HTTPLiveStream::StopStream(int id)
while ((status != kHLSStatusStopped) &&
(status != kHLSStatusCompleted) &&
(status != kHLSStatusErrored) &&
((statusTimer.elapsed() / 1000) < 30))
(statusTimer.elapsed() < 30s))
{
delay = (int)(delay * 1.5);
usleep(delay);
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ void AvFormatDecoder::SeekReset(long long newKey, uint skipFrames,
// skipping would take longer than giveUpPredictionMs, and if so,
// stop skipping right away.
bool exactSeeks = GetSeekSnap() == 0U;
const int maxSeekTimeMs = 200;
static constexpr std::chrono::milliseconds maxSeekTimeMs { 200ms };
int profileFrames = 0;
MythTimer begin(MythTimer::kStartRunning);
for (; (skipFrames > 0 && !m_atEof &&
Expand Down Expand Up @@ -791,7 +791,7 @@ void AvFormatDecoder::SeekReset(long long newKey, uint skipFrames,
{
const int giveUpPredictionMs = 400;
int remainingTimeMs =
skipFrames * (float)begin.elapsed() / profileFrames;
skipFrames * (float)begin.elapsed().count() / profileFrames;
if (remainingTimeMs > giveUpPredictionMs)
{
LOG(VB_PLAYBACK, LOG_DEBUG,
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/eitscanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void EITScanner::run(void)
// Tell the scheduler to run if we are in passive scan
// and there have been updated events since the last scheduler run
// but not in the last 60 seconds
if (!m_activeScan && eitCount && (t.elapsed() > 60 * 1000))
if (!m_activeScan && eitCount && (t.elapsed() > 60s))
{
LOG(VB_EIT, LOG_INFO,
LOC_ID + QString("Added %1 EIT events in passive scan").arg(eitCount));
Expand Down
11 changes: 6 additions & 5 deletions mythtv/libs/libmythtv/io/mythfilebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,11 @@ static QString LocalSubtitleFilename(QFileInfo &FileInfo)
return QString();
}

bool MythFileBuffer::OpenFile(const QString &Filename, uint Retry)
bool MythFileBuffer::OpenFile(const QString &Filename, uint _Retry)
{
auto Retry = std::chrono::milliseconds(_Retry);
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("OpenFile(%1, %2 ms)")
.arg(Filename).arg(Retry));
.arg(Filename).arg(Retry.count()));

m_rwLock.lockForWrite();

Expand Down Expand Up @@ -267,7 +268,7 @@ bool MythFileBuffer::OpenFile(const QString &Filename, uint Retry)
m_fd2 = -1;
}
}
} while (static_cast<uint>(openTimer.elapsed()) < Retry);
} while (openTimer.elapsed() < Retry);

switch (lasterror)
{
Expand Down Expand Up @@ -303,7 +304,7 @@ bool MythFileBuffer::OpenFile(const QString &Filename, uint Retry)
default: break;
}
LOG(VB_FILE, LOG_INFO, LOC + QString("OpenFile() made %1 attempts in %2 ms")
.arg(openAttempts).arg(openTimer.elapsed()));
.arg(openAttempts).arg(openTimer.elapsed().count()));
}
else
{
Expand Down Expand Up @@ -333,7 +334,7 @@ bool MythFileBuffer::OpenFile(const QString &Filename, uint Retry)
}
}

m_remotefile = new RemoteFile(m_filename, false, true, static_cast<int>(Retry), &auxFiles);
m_remotefile = new RemoteFile(m_filename, false, true, Retry.count(), &auxFiles);
if (!m_remotefile->isOpen())
{
LOG(VB_GENERAL, LOG_ERR, LOC + QString("RingBuffer::RingBuffer(): Failed to open remote file (%1)")
Expand Down
33 changes: 18 additions & 15 deletions mythtv/libs/libmythtv/io/mythmediabuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,9 @@ void MythMediaBuffer::WaitForPause(void)
while (m_readAheadRunning && !m_paused && m_requestPause)
{
m_generalWait.wait(&m_rwLock, 1000);
if (m_readAheadRunning && !m_paused && m_requestPause && t.elapsed() > 1000)
LOG(VB_GENERAL, LOG_WARNING, LOC + QString("Waited %1 ms for ringbuffer pause").arg(t.elapsed()));
if (m_readAheadRunning && !m_paused && m_requestPause && t.elapsed() > 1s)
LOG(VB_GENERAL, LOG_WARNING, LOC + QString("Waited %1 ms for ringbuffer pause")
.arg(t.elapsed().count()));
}
m_rwLock.unlock();
}
Expand Down Expand Up @@ -973,7 +974,7 @@ void MythMediaBuffer::run(void)

readResult = SafeRead(m_readAheadBuffer + rbwposcopy, static_cast<uint>(totfree));

int sr_elapsed = sr_timer.elapsed();
int sr_elapsed = sr_timer.elapsed().count();
uint64_t bps = !sr_elapsed ? 1000000001 :
static_cast<uint64_t>((readResult * 8000.0) / static_cast<double>(sr_elapsed));
LOG(VB_FILE, LOG_DEBUG, LOC +
Expand Down Expand Up @@ -1188,30 +1189,31 @@ bool MythMediaBuffer::WaitForReadsAllowed(void)
// Wait up to 30000 ms for reads allowed (or readsdesired if post seek/open)
bool &check = (m_recentSeek || m_readInternalMode) ? m_readsDesired : m_readsAllowed;
m_recentSeek = false;
int timeoutms = 30000;
std::chrono::milliseconds timeoutms = 30s;
int count = 0;
MythTimer timer;
timer.start();

while ((timer.elapsed() < timeoutms) && !check && !m_stopReads &&
!m_requestPause && !m_commsError && m_readAheadRunning)
{
m_generalWait.wait(&m_rwLock, static_cast<unsigned long>(clamp(timeoutms - timer.elapsed(), 10, 100)));
if (!check && timer.elapsed() > 1000 && (count % 100) == 0)
std::chrono::milliseconds delta = clamp(timeoutms - timer.elapsed(), 10ms, 100ms);
m_generalWait.wait(&m_rwLock, delta.count());
if (!check && timer.elapsed() > 1s && (count % 100) == 0)
LOG(VB_GENERAL, LOG_WARNING, LOC + "Taking too long to be allowed to read..");
count++;
}

if (timer.elapsed() >= timeoutms)
{
LOG(VB_GENERAL, LOG_ERR, LOC + QString("Took more than %1 seconds to be allowed to read, aborting.")
.arg(timeoutms / 1000));
.arg(std::chrono::duration_cast<std::chrono::seconds>(timeoutms).count()));
return false;
}
return check;
}

int MythMediaBuffer::WaitForAvail(int Count, int Timeout)
int MythMediaBuffer::WaitForAvail(int Count, std::chrono::milliseconds Timeout)
{
int available = ReadBufAvail();
if (available >= Count)
Expand All @@ -1232,7 +1234,8 @@ int MythMediaBuffer::WaitForAvail(int Count, int Timeout)
while ((available < Count) && !m_stopReads && !m_requestPause && !m_commsError && m_readAheadRunning)
{
m_wantToRead = Count;
m_generalWait.wait(&m_rwLock, static_cast<unsigned long>(clamp(Timeout - timer.elapsed(), 10, 250)));
std::chrono::milliseconds delta = clamp(Timeout - timer.elapsed(), 10ms, 250ms);
m_generalWait.wait(&m_rwLock, delta.count());
available = ReadBufAvail();
if (m_ateof)
break;
Expand All @@ -1259,7 +1262,7 @@ int MythMediaBuffer::ReadDirect(void *Buffer, int Count, bool Peek)
MythTimer timer;
timer.start();
int result = SafeRead(Buffer, static_cast<uint>(Count));
int elapsed = timer.elapsed();
int elapsed = timer.elapsed().count();
uint64_t bps = !elapsed ? 1000000001 : static_cast<uint64_t>((result * 8000.0) / static_cast<double>(elapsed));
UpdateStorageRate(bps);

Expand Down Expand Up @@ -1371,11 +1374,11 @@ int MythMediaBuffer::ReadPriv(void *Buffer, int Count, bool Peek)
MythTimer timer(MythTimer::kStartRunning);

// Wait up to 10000 ms for any data
int timeout_ms = 10000;
std::chrono::milliseconds timeout_ms = 10s;
while (!m_readInternalMode && !m_ateof && (timer.elapsed() < timeout_ms) && m_readAheadRunning &&
!m_stopReads && !m_requestPause && !m_commsError)
{
available = WaitForAvail(Count, std::min(timeout_ms - timer.elapsed(), 100));
available = WaitForAvail(Count, std::min(timeout_ms - timer.elapsed(), 100ms));
if (m_liveTVChain && m_setSwitchToNext && available < Count)
{
LOG(VB_GENERAL, LOG_INFO, LOC + "Checking to see if there's a new livetv program to switch to..");
Expand All @@ -1385,10 +1388,10 @@ int MythMediaBuffer::ReadPriv(void *Buffer, int Count, bool Peek)
if (available > 0)
break;
}
if (timer.elapsed() > 6000)
if (timer.elapsed() > 6s)
{
LOG(VB_GENERAL, LOG_WARNING, LOC + desc + QString(" -- waited %1 ms for avail(%2) > count(%3)")
.arg(timer.elapsed()).arg(available).arg(Count));
.arg(timer.elapsed().count()).arg(available).arg(Count));
}

if (m_readInternalMode)
Expand All @@ -1410,7 +1413,7 @@ int MythMediaBuffer::ReadPriv(void *Buffer, int Count, bool Peek)
// If we're not at the end of file but have no data
// at this point time out and shutdown read ahead.
LOG(VB_GENERAL, LOG_ERR, LOC + desc + QString(" -- timed out waiting for data (%1 ms)")
.arg(timer.elapsed()));
.arg(timer.elapsed().count()));

m_rwLock.unlock();
m_stopReads = true; // this needs to be outside the lock
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/io/mythmediabuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class MTV_PUBLIC MythMediaBuffer : protected MThread
int ReadPriv (void *Buffer, int Count, bool Peek);
int ReadDirect (void *Buffer, int Count, bool Peek);
bool WaitForReadsAllowed (void);
int WaitForAvail (int Count, int Timeout);
int WaitForAvail (int Count, std::chrono::milliseconds Timeout);
int ReadBufFree (void) const;
int ReadBufAvail (void) const;
void ResetReadAhead (long long NewInternal);
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/mpeg/mpegstreamdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ void MPEGStreamData::ProcessPAT(const ProgramAssociationTable *pat)
"ProcessPAT: PAT is missing program, setting timeout");
}
else if (m_invalidPatSeen && !foundProgram &&
(m_invalidPatTimer.elapsed() > 400) && !m_invalidPatWarning)
(m_invalidPatTimer.elapsed() > 400ms) && !m_invalidPatWarning)
{
m_invalidPatWarning = true; // only emit one warning...
// After 400ms emit error if we haven't found correct PAT.
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/mythccextractorplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static QString progress_string(
static const std::string kSpinChars { R"(/-\|)" };
static uint s_spinCnt = 0;

double elapsed = flagTime.elapsed() * 0.001;
double elapsed = flagTime.elapsed().count() * 0.001;
double flagFPS = (elapsed > 0.0) ? (m_myFramesPlayed / elapsed) : 0;

double percentage = m_myFramesPlayed * 100.0 / totalFrames;
Expand Down Expand Up @@ -162,7 +162,7 @@ bool MythCCExtractorPlayer::run(void)

while (!m_killDecoder && !IsErrored())
{
if (inuse_timer.elapsed() > 2534)
if (inuse_timer.elapsed() > 2534ms)
{
inuse_timer.restart();
m_playerCtx->LockPlayingInfo(__FILE__, __LINE__);
Expand All @@ -171,7 +171,7 @@ bool MythCCExtractorPlayer::run(void)
m_playerCtx->UnlockPlayingInfo(__FILE__, __LINE__);
}

if (m_showProgress && (ui_timer.elapsed() > 98 * 4))
if (m_showProgress && (ui_timer.elapsed() > 98ms * 4))
{
ui_timer.restart();
QString str = progress_string(
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/mythcommflagplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool MythCommFlagPlayer::RebuildSeekTable(bool ShowPercentage, StatusCallback Ca

ClearAfterSeek();

int save_timeout = 1001;
std::chrono::milliseconds save_timeout { 1s + 1ms };
MythTimer flagTime;
MythTimer ui_timer;
MythTimer inuse_timer;
Expand All @@ -110,7 +110,7 @@ bool MythCommFlagPlayer::RebuildSeekTable(bool ShowPercentage, StatusCallback Ca
bool usingIframes = false;
while (GetEof() == kEofStateNone)
{
if (inuse_timer.elapsed() > 2534)
if (inuse_timer.elapsed() > 2534ms)
{
inuse_timer.restart();
m_playerCtx->LockPlayingInfo(__FILE__, __LINE__);
Expand Down Expand Up @@ -138,13 +138,13 @@ bool MythCommFlagPlayer::RebuildSeekTable(bool ShowPercentage, StatusCallback Ca
save_timer.restart();
}

if (ui_timer.elapsed() > 98)
if (ui_timer.elapsed() > 98ms)
{
ui_timer.restart();

if (m_totalFrames)
{
float elapsed = flagTime.elapsed() * 0.001F;
float elapsed = flagTime.elapsed().count() * 0.001F;
auto flagFPS = (elapsed > 0.0F) ? static_cast<int>(myFramesPlayed / elapsed) : 0;
auto percentage = static_cast<int>(myFramesPlayed * 100 / m_totalFrames);
if (Callback)
Expand Down
14 changes: 8 additions & 6 deletions mythtv/libs/libmythtv/mythplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,21 @@ void MythPlayer::SetPlaying(bool is_playing)
m_playingWaitCond.wakeAll();
}

bool MythPlayer::IsPlaying(uint wait_in_msec, bool wait_for) const
bool MythPlayer::IsPlaying(uint _wait_in_msec, bool wait_for) const
{
auto wait_in_msec = std::chrono::milliseconds(_wait_in_msec);
QMutexLocker locker(&m_playingLock);

if (!wait_in_msec)
if (wait_in_msec != 0ms)
return m_playing;

MythTimer t;
t.start();

while ((wait_for != m_playing) && ((uint)t.elapsed() < wait_in_msec))
while ((wait_for != m_playing) && (t.elapsed() < wait_in_msec))
{
m_playingWaitCond.wait(
&m_playingLock, std::max(0,(int)wait_in_msec - t.elapsed()));
&m_playingLock, std::max(0ms,wait_in_msec - t.elapsed()).count());
}

return m_playing;
Expand Down Expand Up @@ -455,7 +456,8 @@ int MythPlayer::OpenFile(int Retries)
// Test the incoming buffer and create a suitable decoder
MythTimer bigTimer;
bigTimer.start();
int timeout = std::max((Retries + 1) * 500, 30000);
std::chrono::milliseconds timeout =
std::max(500ms * (Retries + 1), 30000ms);
while (testreadsize <= kDecoderProbeBufferSize)
{
testbuf.resize(testreadsize);
Expand All @@ -464,7 +466,7 @@ int MythPlayer::OpenFile(int Retries)
while (m_playerCtx->m_buffer->Peek(testbuf) != testreadsize)
{
// NB need to allow for streams encountering network congestion
if (peekTimer.elapsed() > 30000 || bigTimer.elapsed() > timeout
if (peekTimer.elapsed() > 30s || bigTimer.elapsed() > timeout
|| m_playerCtx->m_buffer->GetStopReads())
{
LOG(VB_GENERAL, LOG_ERR, LOC +
Expand Down
5 changes: 1 addition & 4 deletions mythtv/libs/libmythtv/playercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@

#define LOC QString("playCtx: ")

const uint PlayerContext::kSMExitTimeout = 2000;
const uint PlayerContext::kMaxChannelHistory = 30;

PlayerContext::PlayerContext(QString inUseID) :
m_recUsage(std::move(inUseID))
{
m_lastSignalMsgTime.start();
m_lastSignalMsgTime.addMSecs(-2 * (int)kSMExitTimeout);
m_lastSignalMsgTime.addMSecs(-2 * kSMExitTimeout);
}

PlayerContext::~PlayerContext()
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/playercontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class MTV_PUBLIC PlayerContext
MythDeque<TVState> m_nextState;

/// Timeout after last Signal Monitor message for ignoring OSD when exiting.
static const uint kSMExitTimeout;
static const uint kMaxChannelHistory;
static constexpr std::chrono::milliseconds kSMExitTimeout { 2s };
static constexpr uint kMaxChannelHistory { 30 };
};

#endif // PLAYER_CONTEXT_H
26 changes: 13 additions & 13 deletions mythtv/libs/libmythtv/recorders/DeviceReadBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,14 @@ bool DeviceReadBuffer::Poll(void) const
polls[1].revents = 0;
poll_cnt = (m_wakePipe[0] >= 0) ? poll_cnt : 1;

int timeout = m_maxPollWait;
std::chrono::milliseconds timeout = m_maxPollWait;
if (1 == poll_cnt)
timeout = 10;
timeout = 10ms;
else if (m_pollTimeoutIsError)
// subtract a bit to allow processing time.
timeout = std::max((int)m_maxPollWait - timer.elapsed() - 15, 10);
timeout = std::max(m_maxPollWait - timer.elapsed() - 15ms, 10ms);

int ret = poll(polls.data(), poll_cnt, timeout);
int ret = poll(polls.data(), poll_cnt, timeout.count());

if (polls[0].revents & POLLHUP)
{
Expand Down Expand Up @@ -490,7 +490,7 @@ bool DeviceReadBuffer::Poll(void) const
else // ret == 0
{
if (m_pollTimeoutIsError &&
(timer.elapsed() >= (int)m_maxPollWait))
(timer.elapsed() >= m_maxPollWait))
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Poll giving up 1");
QMutexLocker locker(&m_lock);
Expand All @@ -508,22 +508,22 @@ bool DeviceReadBuffer::Poll(void) const
::read(m_wakePipe[0], dummy.data(), cnt);
}

if (m_pollTimeoutIsError && (timer.elapsed() >= (int)m_maxPollWait))
if (m_pollTimeoutIsError && (timer.elapsed() >= m_maxPollWait))
{
LOG(VB_GENERAL, LOG_ERR, LOC + QString("Poll giving up after %1ms")
.arg(m_maxPollWait));
.arg(m_maxPollWait.count()));
QMutexLocker locker(&m_lock);
m_error = true;
return true;
}
}

int e = timer.elapsed();
if (e > (int)m_maxPollWait)
std::chrono::milliseconds e = timer.elapsed();
if (e > m_maxPollWait)
{
LOG(VB_GENERAL, LOG_WARNING, LOC +
QString("Poll took an unusually long time %1 ms")
.arg(timer.elapsed()));
.arg(timer.elapsed().count()));
}

return retval;
Expand Down Expand Up @@ -613,7 +613,7 @@ bool DeviceReadBuffer::CheckForErrors(
*/
uint DeviceReadBuffer::Read(unsigned char *buf, const uint count)
{
uint avail = WaitForUsed(std::min(count, (uint)m_readThreshold), 20);
uint avail = WaitForUsed(std::min(count, (uint)m_readThreshold), 20ms);
size_t cnt = std::min(count, avail);

if (!cnt)
Expand Down Expand Up @@ -679,7 +679,7 @@ uint DeviceReadBuffer::WaitForUnused(uint needed) const
* \param max_wait Number of milliseconds to wait for the needed data
* \return bytes available for reading
*/
uint DeviceReadBuffer::WaitForUsed(uint needed, uint max_wait) const
uint DeviceReadBuffer::WaitForUsed(uint needed, std::chrono::milliseconds max_wait) const
{
MythTimer timer;
timer.start();
Expand All @@ -688,7 +688,7 @@ uint DeviceReadBuffer::WaitForUsed(uint needed, uint max_wait) const
size_t avail = m_used;
while ((needed > avail) && isRunning() &&
!m_requestPause && !m_error && !m_eof &&
(timer.elapsed() < (int)max_wait))
(timer.elapsed() < max_wait))
{
m_dataWait.wait(locker.mutex(), 10);
avail = m_used;
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/recorders/DeviceReadBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class DeviceReadBuffer : protected MThread
bool Poll(void) const;
void WakePoll(void) const;
uint WaitForUnused(uint needed) const;
uint WaitForUsed (uint needed, uint max_wait /*ms*/) const;
uint WaitForUsed (uint needed, std::chrono::milliseconds max_wait) const;

bool IsPauseRequested(void) const;
bool IsOpen(void) const { return m_streamFd >= 0; }
Expand All @@ -99,7 +99,7 @@ class DeviceReadBuffer : protected MThread
bool m_paused {false};
bool m_usingPoll {true};
bool m_pollTimeoutIsError {true};
uint m_maxPollWait {2500 /*ms*/};
std::chrono::milliseconds m_maxPollWait {2500ms};

size_t m_size {0};
size_t m_used {0};
Expand Down
20 changes: 11 additions & 9 deletions mythtv/libs/libmythtv/recorders/ExternalStreamHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ void ExternalStreamHandler::run(void)

if (m_xon)
{
if (status_timer.elapsed() >= 2000)
if (status_timer.elapsed() >= 2s)
{
// Since we may never need to send the XOFF
// command, occationally check to see if the
Expand Down Expand Up @@ -710,7 +710,7 @@ void ExternalStreamHandler::run(void)
nodata_timer.start();
else
{
if (nodata_timer.elapsed() >= 50000)
if (nodata_timer.elapsed() >= 50s)
{
LOG(VB_GENERAL, LOG_WARNING, LOC +
"No data for 50 seconds, Restarting stream.");
Expand All @@ -728,7 +728,7 @@ void ExternalStreamHandler::run(void)
std::this_thread::sleep_for(50ms);

// HLS type streams may only produce data every ~10 seconds
if (nodata_timer.elapsed() < 12000 && buffer.size() < TS_PACKET_SIZE)
if (nodata_timer.elapsed() < 12s && buffer.size() < TS_PACKET_SIZE)
continue;
}
else
Expand Down Expand Up @@ -1240,9 +1240,10 @@ bool ExternalStreamHandler::ProcessCommand(const QString & cmd,
}

bool ExternalStreamHandler::ProcessVer1(const QString & cmd,
QString & result, int timeout,
QString & result, int _timeout,
uint retry_cnt)
{
auto timeout = std::chrono::milliseconds(_timeout);
LOG(VB_RECORD, LOG_DEBUG, LOC + QString("ProcessVer1('%1')")
.arg(cmd));

Expand Down Expand Up @@ -1276,7 +1277,7 @@ bool ExternalStreamHandler::ProcessVer1(const QString & cmd,
MythTimer timer(MythTimer::kStartRunning);
while (timer.elapsed() < timeout)
{
result = m_io->GetStatus(timeout);
result = m_io->GetStatus(timeout.count());
if (m_io->Error())
{
LOG(VB_GENERAL, LOG_ERR, LOC +
Expand Down Expand Up @@ -1323,7 +1324,7 @@ bool ExternalStreamHandler::ProcessVer1(const QString & cmd,
LOG(VB_RECORD, level,
LOC + QString("ProcessCommand('%1') = '%2' took %3ms %4")
.arg(cmd).arg(result)
.arg(timer.elapsed())
.arg(timer.elapsed().count())
.arg(okay ? "" : "<-- NOTE"));

return okay;
Expand All @@ -1345,9 +1346,10 @@ bool ExternalStreamHandler::ProcessVer1(const QString & cmd,
}

bool ExternalStreamHandler::ProcessVer2(const QString & command,
QString & result, int timeout,
QString & result, int _timeout,
uint retry_cnt)
{
auto timeout = std::chrono::milliseconds(_timeout);
QString status;
QString raw;

Expand Down Expand Up @@ -1384,7 +1386,7 @@ bool ExternalStreamHandler::ProcessVer2(const QString & command,
MythTimer timer(MythTimer::kStartRunning);
while (timer.elapsed() < timeout)
{
result = m_io->GetStatus(timeout);
result = m_io->GetStatus(timeout.count());
if (m_io->Error())
{
LOG(VB_GENERAL, LOG_ERR, LOC +
Expand Down Expand Up @@ -1468,7 +1470,7 @@ bool ExternalStreamHandler::ProcessVer2(const QString & command,

LOG(VB_RECORD, level,
LOC + QString("ProcessV2('%1') = '%2' took %3ms %4")
.arg(cmd).arg(result).arg(timer.elapsed())
.arg(cmd).arg(result).arg(timer.elapsed().count())
.arg(okay ? "" : "<-- NOTE"));

return okay;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/analogsignalmonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AnalogSignalMonitor : public SignalMonitor
QString m_driver;
uint32_t m_version {0};
uint m_width {0};
int m_stableTime {2000};
std::chrono::milliseconds m_stableTime {2s};
uint m_lockCnt {0};
MythTimer m_timer;
int m_logIdx {40};
Expand Down
10 changes: 5 additions & 5 deletions mythtv/libs/libmythtv/recorders/darwinfirewiredevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ namespace AVS
#define LOC QString("DFireDev(%1): ").arg(guid_to_string(m_guid))

#define kAnyAvailableIsochChannel 0xFFFFFFFF
#define kNoDataTimeout 300 /* msec */
#define kResetTimeout 1500 /* msec */
static constexpr std::chrono::milliseconds kNoDataTimeout { 300ms };
static constexpr std::chrono::milliseconds kResetTimeout { 1500ms };

static IOReturn dfd_tspacket_handler_thunk(
UInt32 tsPacketCount, UInt32 **ppBuf, void *callback_data);
Expand Down Expand Up @@ -356,7 +356,7 @@ bool DarwinFirewireDevice::OpenAVStream(void)
}

m_priv->m_avstream->registerNoDataNotificationCallback(
dfd_no_data_notification, this, kNoDataTimeout);
dfd_no_data_notification, this, kNoDataTimeout.count());

return true;
}
Expand Down Expand Up @@ -549,15 +549,15 @@ void DarwinFirewireDevice::ProcessNoDataMessage(void)
{
if (m_priv->m_no_data_timer_set)
{
int short_interval = kNoDataTimeout + (kNoDataTimeout>>1);
std::chrono::milliseconds short_interval = kNoDataTimeout + (kNoDataTimeout/2);
bool recent = m_priv->m_no_data_timer.elapsed() <= short_interval;
m_priv->m_no_data_cnt = (recent) ? m_priv->m_no_data_cnt + 1 : 1;
}
m_priv->m_no_data_timer_set = true;
m_priv->m_no_data_timer.start();

LOG(VB_GENERAL, LOG_WARNING, LOC + QString("No Input in %1 msecs")
.arg(m_priv->m_no_data_cnt * kNoDataTimeout));
.arg(m_priv->m_no_data_cnt * kNoDataTimeout.count()));

if (m_priv->m_no_data_cnt > (kResetTimeout / kNoDataTimeout))
{
Expand Down
12 changes: 6 additions & 6 deletions mythtv/libs/libmythtv/recorders/dtvrecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,14 @@ void DTVRecorder::BufferedWrite(const TSPacket &tspacket, bool insert)
if (val > thresh)
{
QMutexLocker locker(&m_statisticsLock);
uint elapsed = m_timeOfLatestDataTimer.restart();
std::chrono::milliseconds elapsed = m_timeOfLatestDataTimer.restart();
int interval = thresh;
if (elapsed > kTimeOfLatestDataIntervalTarget + 250)
if (elapsed > kTimeOfLatestDataIntervalTarget + 250ms)
{
interval = m_timeOfLatestDataPacketInterval
.fetchAndStoreRelaxed(thresh * 4 / 5);
}
else if (elapsed + 250 < kTimeOfLatestDataIntervalTarget)
else if (elapsed + 250ms < kTimeOfLatestDataIntervalTarget)
{
interval = m_timeOfLatestDataPacketInterval
.fetchAndStoreRelaxed(thresh * 9 / 8);
Expand All @@ -294,7 +294,7 @@ void DTVRecorder::BufferedWrite(const TSPacket &tspacket, bool insert)

LOG(VB_RECORD, LOG_DEBUG, LOC +
QString("Updating timeOfLatestData elapsed(%1) interval(%2)")
.arg(elapsed).arg(interval));
.arg(elapsed.count()).arg(interval));
}

// Do we have to buffer the packet for exact keyframe detection?
Expand Down Expand Up @@ -1508,12 +1508,12 @@ bool DTVRecorder::ProcessTSPacket(const TSPacket &tspacket)
if (m_framesSeenCount++ == 0)
m_recordMptsTimer.start();

if (m_recordMptsTimer.elapsed() > 500) // 0.5 seconds
if (m_recordMptsTimer.elapsed() > 0.5s)
{
UpdateFramesWritten();
m_lastKeyframeSeen = m_framesSeenCount;
HandleKeyframe(m_payloadBuffer.size());
m_recordMptsTimer.addMSecs(-500);
m_recordMptsTimer.addMSecs(-500ms);
}
}
else if (m_streamId[pid] == 0)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/dvbstreamhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void DVBStreamHandler::CycleFiltersByPriority(void)

// we have to cycle within our priority level

if (m_cycleTimer.elapsed() < 1000)
if (m_cycleTimer.elapsed() < 1s)
break; // we don't want to cycle too often

if (!m_pidInfo[*open]->IsOpen())
Expand Down
7 changes: 2 additions & 5 deletions mythtv/libs/libmythtv/recorders/firewiresignalmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ void FirewireTableMonitorThread::run(void)
RunEpilog();
}

const uint FirewireSignalMonitor::kPowerTimeout = 3000; /* ms */
const uint FirewireSignalMonitor::kBufferTimeout = 5000; /* ms */

QHash<void*,uint> FirewireSignalMonitor::s_patKeys;
QMutex FirewireSignalMonitor::s_patKeysLock;

Expand Down Expand Up @@ -96,7 +93,7 @@ void FirewireSignalMonitor::HandlePAT(const ProgramAssociationTable *pat)

bool crc_bogus = !fwchan->GetFirewireDevice()->IsSTBBufferCleared();
if (crc_bogus && m_stbNeedsToWaitForPat &&
(m_stbWaitForPatTimer.elapsed() < (int)kBufferTimeout))
(m_stbWaitForPatTimer.elapsed() < kBufferTimeout))
{
LOG(VB_CHANNEL, LOG_INFO, LOC + "HandlePAT() ignoring PAT");
uint tsid = pat->TransportStreamID();
Expand Down Expand Up @@ -206,7 +203,7 @@ void FirewireSignalMonitor::UpdateValues(void)
}

if (m_stbNeedsToWaitForPower &&
(m_stbWaitForPowerTimer.elapsed() < (int)kPowerTimeout))
(m_stbWaitForPowerTimer.elapsed() < kPowerTimeout))
{
return;
}
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/recorders/firewiresignalmonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class FirewireSignalMonitor : public DTVSignalMonitor, public TSDataListener
void AddData(const unsigned char *data, uint len) override; // TSDataListener

public:
static const uint kPowerTimeout;
static const uint kBufferTimeout;
static constexpr std::chrono::milliseconds kPowerTimeout { 3s };
static constexpr std::chrono::milliseconds kBufferTimeout { 5s };

protected:
volatile bool m_dtvMonitorRunning {false};
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/linuxfirewiredevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ void LinuxFirewireDevice::run(void)
LFDPriv::s_lock.lock();
bool reset_timer_on = m_priv->m_resetTimerOn;
bool handle_reset = reset_timer_on &&
(m_priv->m_resetTimer.elapsed() > 100);
(m_priv->m_resetTimer.elapsed() > 100ms);
if (handle_reset)
m_priv->m_resetTimerOn = false;
LFDPriv::s_lock.unlock();
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/recorders/mpegrecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,20 +987,20 @@ void MpegRecorder::run(void)
{
if (dummyBPS && bytesRead)
{
elapsed = (elapsedTimer.elapsed() / 1000.0) + 1;
elapsed = (elapsedTimer.elapsed().count() / 1000.0) + 1;
while ((bytesRead / elapsed) > dummyBPS)
{
std::this_thread::sleep_for(50ms);
elapsed = (elapsedTimer.elapsed() / 1000.0) + 1;
elapsed = (elapsedTimer.elapsed().count() / 1000.0) + 1;
}
}
else if (GetFramesWritten())
{
elapsed = (elapsedTimer.elapsed() / 1000.0) + 1;
elapsed = (elapsedTimer.elapsed().count() / 1000.0) + 1;
while ((GetFramesWritten() / elapsed) > 30)
{
std::this_thread::sleep_for(50ms);
elapsed = (elapsedTimer.elapsed() / 1000.0) + 1;
elapsed = (elapsedTimer.elapsed().count() / 1000.0) + 1;
}
}
}
Expand Down
21 changes: 10 additions & 11 deletions mythtv/libs/libmythtv/recorders/recorderbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
#define LOC QString("RecBase[%1](%2): ") \
.arg(TVREC_CARDNUM).arg(m_videodevice)

const uint RecorderBase::kTimeOfLatestDataIntervalTarget = 5000;

RecorderBase::RecorderBase(TVRec *rec)
: m_tvrec(rec)
{
Expand Down Expand Up @@ -296,18 +294,19 @@ bool RecorderBase::IsPaused(bool holding_lock) const
* \param timeout number of milliseconds to wait defaults to 1000.
* \return true iff pause happened within timeout period.
*/
bool RecorderBase::WaitForPause(int timeout)
bool RecorderBase::WaitForPause(int _timeout)
{
auto timeout = std::chrono::milliseconds(_timeout);
MythTimer t;
t.start();

QMutexLocker locker(&m_pauseLock);
while (!IsPaused(true) && m_requestPause)
{
int wait = timeout - t.elapsed();
if (wait <= 0)
std::chrono::milliseconds wait = timeout - t.elapsed();
if (wait <= 0ms)
return false;
m_pauseWait.wait(&m_pauseLock, wait);
m_pauseWait.wait(&m_pauseLock, wait.count());
}
return true;
}
Expand Down Expand Up @@ -594,13 +593,13 @@ void RecorderBase::SavePositionMap(bool force, bool finished)

bool has_delta = !m_positionMapDelta.empty();
// set pm_elapsed to a fake large value if the timer hasn't yet started
uint pm_elapsed = (m_positionMapTimer.isRunning()) ?
m_positionMapTimer.elapsed() : ~0;
std::chrono::milliseconds pm_elapsed = (m_positionMapTimer.isRunning()) ?
m_positionMapTimer.elapsed() : std::chrono::milliseconds::max();
// save on every 1.5 seconds if in the first few frames of a recording
needToSave |= (m_positionMap.size() < 30) &&
has_delta && (pm_elapsed >= 1500);
has_delta && (pm_elapsed >= 1.5s);
// save every 10 seconds later on
needToSave |= has_delta && (pm_elapsed >= 10000);
needToSave |= has_delta && (pm_elapsed >= 10s);
// Assume that m_durationMapDelta is the same size as
// m_positionMapDelta and implicitly use the same logic about when
// to same m_durationMapDelta.
Expand Down Expand Up @@ -645,7 +644,7 @@ void RecorderBase::SavePositionMap(bool force, bool finished)
// and if there is a problem with the input we may never see one
// again, resulting in a wedged recording.
if (!finished && m_ringBufferCheckTimer.isRunning() &&
m_ringBufferCheckTimer.elapsed() > 3000)
m_ringBufferCheckTimer.elapsed() > 3s)
{
if (CheckForRingBufferSwitch())
LOG(VB_RECORD, LOG_WARNING, LOC +
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/recorderbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class MTV_PUBLIC RecorderBase : public QRunnable
MythTimer m_timeOfLatestDataTimer;
RecordingGaps m_recordingGaps;
/// timeOfLatest update interval target in milliseconds.
static const uint kTimeOfLatestDataIntervalTarget;
static constexpr std::chrono::milliseconds kTimeOfLatestDataIntervalTarget { 5s };
};

#endif
Expand Down
18 changes: 10 additions & 8 deletions mythtv/libs/libmythtv/recorders/satiputils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,31 @@

#define LOC QString("SatIP: ")

#define SEARCH_TIME_MS 3000
static constexpr std::chrono::milliseconds SEARCH_TIME_MS { 3s };
#define SATIP_URI "urn:ses-com:device:SatIPServer:1"

QStringList SatIP::probeDevices(void)
{
const int milliSeconds = SEARCH_TIME_MS;
const std::chrono::milliseconds milliSeconds = SEARCH_TIME_MS;
int seconds = std::chrono::duration_cast<std::chrono::seconds>(milliSeconds).count();

LOG(VB_GENERAL, LOG_INFO, LOC + QString("Using UPNP to search for Sat>IP servers (%1 secs)")
.arg(milliSeconds / 1000));
.arg(seconds));

SSDP::Instance()->PerformSearch(SATIP_URI, milliSeconds / 1000);
SSDP::Instance()->PerformSearch(SATIP_URI, seconds);

MythTimer totalTime; totalTime.start();
MythTimer searchTime; searchTime.start();

while (totalTime.elapsed() < milliSeconds)
{
std::this_thread::sleep_for(25ms);
int ttl = milliSeconds - totalTime.elapsed();
if (searchTime.elapsed() > 249 && ttl > 1000)
std::chrono::milliseconds ttl = milliSeconds - totalTime.elapsed();
if (searchTime.elapsed() > 249ms && ttl > 1s)
{
LOG(VB_GENERAL, LOG_DEBUG, LOC + QString("UPNP search %1 ms").arg(ttl));
SSDP::Instance()->PerformSearch(SATIP_URI, ttl / 1000);
int ttl_s = std::chrono::duration_cast<std::chrono::seconds>(ttl).count();
LOG(VB_GENERAL, LOG_DEBUG, LOC + QString("UPNP search %1 ms").arg(ttl_s));
SSDP::Instance()->PerformSearch(SATIP_URI, ttl_s);
searchTime.start();
}
}
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/streamhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ bool StreamHandler::UpdateFiltersFromStreamData(void)
ok &= AddPIDFilter(pid);

// Cycle filters if it's been a while
if (m_cycleTimer.isRunning() && (m_cycleTimer.elapsed() > 1000))
if (m_cycleTimer.isRunning() && (m_cycleTimer.elapsed() > 1s))
CycleFiltersByPriority();

return ok;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/v4l2encsignalmonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class V4L2encSignalMonitor: public DTVSignalMonitor

private:
int m_strength {0};
int m_stableTime {1500};
std::chrono::milliseconds m_stableTime {1500ms};
int m_width {0};
int m_height {0};
uint m_lockCnt {0};
Expand Down
17 changes: 9 additions & 8 deletions mythtv/libs/libmythtv/recorders/vboxutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
#define QUERY_CHANNELS "http://{URL}/cgi-bin/HttpControl/HttpControlApp?OPTION=1&Method=GetXmltvChannelsList"\
"&FromChIndex=FirstChannel&ToChIndex=LastChannel&FilterBy=All"

#define SEARCH_TIME 3000
static constexpr std::chrono::milliseconds SEARCH_TIME { 3s };
#define VBOX_URI "urn:schemas-upnp-org:device:MediaServer:1"
#define VBOX_UDN "uuid:b7531642-0123-3210"

// static method
QStringList VBox::probeDevices(void)
{
const int milliSeconds = SEARCH_TIME;
const std::chrono::milliseconds milliSeconds { SEARCH_TIME };
int seconds = std::chrono::duration_cast<std::chrono::seconds>(milliSeconds).count();

// see if we have already found one or more vboxes
QStringList result = VBox::doUPNPSearch();
Expand All @@ -37,9 +38,9 @@ QStringList VBox::probeDevices(void)

// non found so start a new search
LOG(VB_GENERAL, LOG_INFO, LOC + QString("Using UPNP to search for Vboxes (%1 secs)")
.arg(milliSeconds / 1000));
.arg(seconds));

SSDP::Instance()->PerformSearch(VBOX_URI, milliSeconds / 1000);
SSDP::Instance()->PerformSearch(VBOX_URI, seconds);

// Search for a total of 'milliSeconds' ms, sending new search packet
// about every 250 ms until less than one second remains.
Expand All @@ -48,12 +49,12 @@ QStringList VBox::probeDevices(void)
while (totalTime.elapsed() < milliSeconds)
{
std::this_thread::sleep_for(25ms);
int ttl = milliSeconds - totalTime.elapsed();
if ((searchTime.elapsed() > 249) && (ttl > 1000))
auto ttl = std::chrono::duration_cast<std::chrono::seconds>(milliSeconds - totalTime.elapsed());
if ((searchTime.elapsed() > 249ms) && (ttl > 1s))
{
LOG(VB_GENERAL, LOG_DEBUG, LOC + QString("UPNP Search %1 secs")
.arg(ttl / 1000));
SSDP::Instance()->PerformSearch(VBOX_URI, ttl / 1000);
.arg(ttl.count()));
SSDP::Instance()->PerformSearch(VBOX_URI, ttl.count());
searchTime.start();
}
}
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/remoteencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#define LOC QString("RemoteEncoder(%1): ").arg(m_recordernum)

#define MAX_SIZE_CHECK 500 // in ms
static constexpr std::chrono::milliseconds MAX_SIZE_CHECK { 500ms };

RemoteEncoder::~RemoteEncoder()
{
Expand Down
46 changes: 26 additions & 20 deletions mythtv/libs/libmythtv/tv_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
#include <cstdlib>
#include <thread>

using namespace std::chrono_literals;

#if ! HAVE_ROUND
#define round(x) ((int) ((x) + 0.5))
#endif
Expand All @@ -96,14 +98,14 @@ const uint TV::kInputKeysMax = 6;
const uint TV::kNextSource = 1;
const uint TV::kPreviousSource = 2;

const uint TV::kInputModeTimeout = 5000;
const uint TV::kLCDTimeout = 1000;
const uint TV::kBrowseTimeout = 30000;
const uint TV::kKeyRepeatTimeout = 300;
const uint TV::kPrevChanTimeout = 750;
const uint TV::kSleepTimerDialogTimeout = 45000;
const uint TV::kIdleTimerDialogTimeout = 45000;
const uint TV::kVideoExitDialogTimeout = 120000;
const std::chrono::milliseconds TV::kInputModeTimeout = 5s;
const std::chrono::milliseconds TV::kLCDTimeout = 1s;
const std::chrono::milliseconds TV::kBrowseTimeout = 30s;
const std::chrono::milliseconds TV::kKeyRepeatTimeout = 300ms;
const std::chrono::milliseconds TV::kPrevChanTimeout = 750ms;
const std::chrono::milliseconds TV::kSleepTimerDialogTimeout = 45s;
const std::chrono::milliseconds TV::kIdleTimerDialogTimeout = 45s;
const std::chrono::milliseconds TV::kVideoExitDialogTimeout = 2min;

const uint TV::kEndOfPlaybackCheckFrequency = 250;
const uint TV::kEndOfRecPromptCheckFrequency = 250;
Expand Down Expand Up @@ -267,8 +269,10 @@ bool TV::CreatePlayer(TVState State, bool Muted)
* \param MaxWait How long to wait for MythPlayer to start playing.
* \return true when successful, false otherwise.
*/
bool TV::StartPlaying(int MaxWait)
bool TV::StartPlaying(int _MaxWait)
{
auto MaxWait = std::chrono::milliseconds(_MaxWait);

if (!m_player)
return false;

Expand All @@ -279,9 +283,9 @@ bool TV::StartPlaying(int MaxWait)
// later following the error
return false;
}
MaxWait = (MaxWait <= 0) ? 20000 : MaxWait;
MaxWait = (MaxWait <= 0ms) ? 20s : MaxWait;
#ifdef USING_VALGRIND
maxWait = (1<<30);
MaxWait = std::chrono::milliseconds::max();
#endif // USING_VALGRIND
MythTimer t;
t.start();
Expand All @@ -293,7 +297,7 @@ bool TV::StartPlaying(int MaxWait)
{
LOG(VB_PLAYBACK, LOG_INFO, LOC +
QString("StartPlaying(): took %1 ms to start player.")
.arg(t.elapsed()));
.arg(t.elapsed().count()));
return true;
}
LOG(VB_GENERAL, LOG_ERR, LOC + "StartPlaying() Failed to start player");
Expand Down Expand Up @@ -2344,10 +2348,11 @@ void TV::HandleStateChange()
* not provided, this defaults to 40 seconds.
* \return true when successful, false otherwise.
*/
bool TV::StartRecorder(int MaxWait)
bool TV::StartRecorder(int _MaxWait)
{
RemoteEncoder *rec = m_playerContext.m_recorder;
MaxWait = (MaxWait <= 0) ? 40000 : MaxWait;
auto MaxWait = std::chrono::milliseconds(_MaxWait);
MaxWait = (MaxWait <= 0ms) ? 40s : MaxWait;
MythTimer t;
t.start();
bool recording = false;
Expand Down Expand Up @@ -2376,7 +2381,8 @@ bool TV::StartRecorder(int MaxWait)
return false;
}

LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Took %1 ms to start recorder.").arg(t.elapsed()));
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Took %1 ms to start recorder.")
.arg(t.elapsed().count()));
return true;
}

Expand Down Expand Up @@ -3923,7 +3929,7 @@ bool TV::ActiveHandleAction(const QStringList &Actions,
else if (IsActionable({ "ESCAPE", "BACK" }, Actions))
{
if (StateIsLiveTV(m_playerContext.GetState()) &&
(m_playerContext.m_lastSignalMsgTime.elapsed() < static_cast<int>(PlayerContext::kSMExitTimeout)))
(m_playerContext.m_lastSignalMsgTime.elapsed() < PlayerContext::kSMExitTimeout))
{
ClearOSD();
}
Expand Down Expand Up @@ -5051,7 +5057,7 @@ void TV::DoSeek(float Time, const QString &Msg, bool TimeIsOffset, bool HonorCut
if (m_player->GetLimitKeyRepeat())
limitkeys = true;

if (!limitkeys || (m_keyRepeatTimer.elapsed() > static_cast<int>(kKeyRepeatTimeout)))
if (!limitkeys || (m_keyRepeatTimer.elapsed() > kKeyRepeatTimeout))
{
m_keyRepeatTimer.start();
NormalSpeed();
Expand Down Expand Up @@ -6411,7 +6417,7 @@ void TV::UpdateOSDSignal(const QStringList &List)

InfoMap infoMap = m_playerContext.m_lastSignalUIInfo;
if ((!m_playerContext.m_lastSignalUIInfoTime.isRunning() ||
(m_playerContext.m_lastSignalUIInfoTime.elapsed() > 5000)) ||
(m_playerContext.m_lastSignalUIInfoTime.elapsed() > 5s)) ||
infoMap["callsign"].isEmpty())
{
m_playerContext.m_lastSignalUIInfo.clear();
Expand Down Expand Up @@ -7080,7 +7086,7 @@ void TV::ShowOSDSleep()
"Do you wish to continue watching?")
.arg(static_cast<double>(m_sleepTimerTimeout * (1.0F / 60000.0F)));

emit ChangeOSDDialog( { OSD_DLG_SLEEP, message, kSleepTimerDialogTimeout,
emit ChangeOSDDialog( { OSD_DLG_SLEEP, message, (int)kSleepTimerDialogTimeout.count(),
{ { tr("Yes"), "DIALOG_SLEEP_YES_0" },
{ tr("No"), "DIALOG_SLEEP_NO_0" } }});

Expand Down Expand Up @@ -7135,7 +7141,7 @@ void TV::ShowOSDIdle()
"will exit in %d seconds. Are you still watching?")
.arg(static_cast<double>(m_dbIdleTimeout * (1.0F / 60000.0F)));

emit ChangeOSDDialog( { OSD_DLG_IDLE, message, kIdleTimerDialogTimeout,
emit ChangeOSDDialog( { OSD_DLG_IDLE, message, (int)kIdleTimerDialogTimeout.count(),
{ { tr("Yes"), "DIALOG_IDLE_YES_0" },
{ tr("No"), "DIALOG_IDLE_NO_0" }}});

Expand Down
18 changes: 10 additions & 8 deletions mythtv/libs/libmythtv/tv_play.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ class MTV_PUBLIC TV : public TVPlaybackState, public MythTVMenuItemDisplayer, pu

// Timers and timer events
int StartTimer(int Interval, int Line);
int StartTimer(std::chrono::milliseconds Interval, int Line)
{ return StartTimer(Interval.count(), Line); }
void KillTimer(int Id);

void SetSpeedChangeTimer(int When, int Line);
Expand Down Expand Up @@ -743,21 +745,21 @@ class MTV_PUBLIC TV : public TVPlaybackState, public MythTVMenuItemDisplayer, pu
static const uint kPreviousSource;

///< Timeout for entry modes in msec
static const uint kInputModeTimeout;
static const std::chrono::milliseconds kInputModeTimeout;
/// Timeout for updating LCD info in msec
static const uint kLCDTimeout;
static const std::chrono::milliseconds kLCDTimeout;
/// Timeout for browse mode exit in msec
static const uint kBrowseTimeout;
static const std::chrono::milliseconds kBrowseTimeout;
/// Seek key repeat timeout in msec
static const uint kKeyRepeatTimeout;
static const std::chrono::milliseconds kKeyRepeatTimeout;
/// How long to wait before applying all previous channel keypresses in msec
static const uint kPrevChanTimeout;
static const std::chrono::milliseconds kPrevChanTimeout;
/// How long to display sleep timer dialog in msec
static const uint kSleepTimerDialogTimeout;
static const std::chrono::milliseconds kSleepTimerDialogTimeout;
/// How long to display idle timer dialog in seconds
static const uint kIdleTimerDialogTimeout;
static const std::chrono::milliseconds kIdleTimerDialogTimeout;
/// How long to display idle timer dialog in msec
static const uint kVideoExitDialogTimeout;
static const std::chrono::milliseconds kVideoExitDialogTimeout;

static const uint kEndOfPlaybackCheckFrequency;
static const uint kEmbedCheckFrequency;
Expand Down
11 changes: 6 additions & 5 deletions mythtv/libs/libmythtv/tv_rec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1520,13 +1520,14 @@ void TVRec::run(void)
* You MUST HAVE the stateChange-lock locked when you call this method!
*/

bool TVRec::WaitForEventThreadSleep(bool wake, ulong time)
bool TVRec::WaitForEventThreadSleep(bool wake, ulong _time)
{
auto time = std::chrono::milliseconds(_time);
bool ok = false;
MythTimer t;
t.start();

while (!ok && ((unsigned long) t.elapsed()) < time)
while (!ok && (t.elapsed() < time))
{
MythTimer t2;
t2.start();
Expand All @@ -1550,9 +1551,9 @@ bool TVRec::WaitForEventThreadSleep(bool wake, ulong time)
// verify that we were triggered.
ok = (m_tuningRequests.empty() && !m_changeState);

int te = t2.elapsed();
if (!ok && te < 10)
std::this_thread::sleep_for(std::chrono::microseconds(10-te));
std::chrono::milliseconds te = t2.elapsed();
if (!ok && te < 10ms)
std::this_thread::sleep_for(std::chrono::microseconds(10ms - te));
}
return ok;
}
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/tvbrowsehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void TVBrowseHelper::BrowseDispInfo(const BrowseInfo& Browseinfo)
return;

m_parent->KillTimer(m_browseTimerId);
m_browseTimerId = m_parent->StartTimer(static_cast<int>(TV::kBrowseTimeout), __LINE__);
m_browseTimerId = m_parent->StartTimer(TV::kBrowseTimeout, __LINE__);

QMutexLocker locker(&m_browseLock);
if (BROWSE_SAME == Browseinfo.m_dir)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythuitextedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void MythUITextEdit::Pulse(void)

if (m_hasFocus)
{
if (m_lastKeyPress.elapsed() < 500)
if (m_lastKeyPress.elapsed() < 500ms)
{
m_cursorImage->SetVisible(true);
m_blinkInterval = 0;
Expand Down
12 changes: 6 additions & 6 deletions mythtv/libs/libmythupnp/bufferedsocketdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ qulonglong BufferedSocketDevice::BytesAvailable(void)
/////////////////////////////////////////////////////////////////////////////

qulonglong BufferedSocketDevice::WaitForMore(
int msecs, bool *pTimeout /* = nullptr*/ )
std::chrono::milliseconds msecs, bool *pTimeout /* = nullptr*/ )
{
bool bTimeout = false;

Expand Down Expand Up @@ -417,9 +417,9 @@ qulonglong BufferedSocketDevice::WaitForMore(
// -=>TODO: Override the timeout to 1 second... Closes connection sooner
// to help recover from lost requests. (hack until better fix found)

msecs = 1000;
msecs = 1s;

nBytes = m_pSocket->waitForMore( msecs, &bTimeout );
nBytes = m_pSocket->waitForMore( msecs.count(), &bTimeout );

if (pTimeout != nullptr)
*pTimeout = bTimeout;
Expand Down Expand Up @@ -623,7 +623,7 @@ QString BufferedSocketDevice::ReadLine()
//
/////////////////////////////////////////////////////////////////////////////

QString BufferedSocketDevice::ReadLine( int msecs )
QString BufferedSocketDevice::ReadLine( std::chrono::milliseconds msecs )
{
MythTimer timer;
QString sLine;
Expand All @@ -636,7 +636,7 @@ QString BufferedSocketDevice::ReadLine( int msecs )
// or timeout.
// ----------------------------------------------------------------------

if ( msecs > 0)
if ( msecs > 0ms)
{
bool bTimeout = false;

Expand All @@ -650,7 +650,7 @@ QString BufferedSocketDevice::ReadLine( int msecs )

WaitForMore( msecs, &bTimeout );

if ( timer.elapsed() >= msecs )
if ( timer.elapsed() >= msecs )
{
bTimeout = true;
LOG(VB_HTTP, LOG_INFO, "Exceeded Total Elapsed Wait Time." );
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythupnp/bufferedsocketdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BufferedSocketDevice
bool AtEnd ();

qulonglong BytesAvailable ();
qulonglong WaitForMore ( int msecs,
qulonglong WaitForMore ( std::chrono::milliseconds msecs,
bool *timeout = nullptr );

qulonglong BytesToWrite () const;
Expand All @@ -99,7 +99,7 @@ class BufferedSocketDevice

bool CanReadLine ();
QString ReadLine ();
QString ReadLine ( int msecs );
QString ReadLine ( std::chrono::milliseconds msecs );
qlonglong ReadLine ( char *data,
qulonglong maxlen );

Expand Down
12 changes: 7 additions & 5 deletions mythtv/libs/libmythupnp/httprequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2383,8 +2383,9 @@ void HTTPRequest::AddCORSHeaders( const QString &sOrigin )
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

QString BufferedSocketDeviceRequest::ReadLine( int msecs )
QString BufferedSocketDeviceRequest::ReadLine( int _msecs )
{
auto msecs = std::chrono::milliseconds(_msecs);
QString sLine;

if (m_pSocket && m_pSocket->isValid() &&
Expand All @@ -2395,7 +2396,7 @@ QString BufferedSocketDeviceRequest::ReadLine( int msecs )
timer.start();
while (!m_pSocket->canReadLine() && !timeout)
{
timeout = !(m_pSocket->waitForReadyRead( msecs ));
timeout = !(m_pSocket->waitForReadyRead( msecs.count() ));

if ( timer.elapsed() >= msecs )
{
Expand All @@ -2416,20 +2417,21 @@ QString BufferedSocketDeviceRequest::ReadLine( int msecs )
/////////////////////////////////////////////////////////////////////////////

qint64 BufferedSocketDeviceRequest::ReadBlock(char *pData, qint64 nMaxLen,
int msecs)
int _msecs)
{
auto msecs = std::chrono::milliseconds(_msecs);
if (m_pSocket && m_pSocket->isValid() &&
m_pSocket->state() == QAbstractSocket::ConnectedState)
{
if (msecs == 0)
if (msecs == 0ms)
return( m_pSocket->read( pData, nMaxLen ));

bool bTimeout = false;
MythTimer timer;
timer.start();
while ( (m_pSocket->bytesAvailable() < (int)nMaxLen) && !bTimeout ) // This can end up waiting far longer than msecs
{
bTimeout = !(m_pSocket->waitForReadyRead( msecs ));
bTimeout = !(m_pSocket->waitForReadyRead( msecs.count() ));

if ( timer.elapsed() >= msecs )
{
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythupnp/upnpsubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ QObject::customEvent to receive event notifications for subscribed services.
// default requested time for subscription (actual is dictated by server)
#define SUBSCRIPTION_TIME 1800
// maximum time to wait for responses to subscription requests (UPnP spec. 30s)
#define MAX_WAIT 30000
static constexpr std::chrono::milliseconds MAX_WAIT { 30s };

#define LOC QString("UPnPSub: ")

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythupnp/upnptaskevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void UPnpEventTask::Execute( TaskQueue * /*pQueue*/ )
// Read first line to determine success/Fail
// --------------------------------------------------------------

QString sResponseLine = sock.ReadLine( 3000 );
QString sResponseLine = sock.ReadLine( 3s );

if ( sResponseLine.length() > 0)
{
Expand Down
12 changes: 5 additions & 7 deletions mythtv/programs/mythbackend/mainserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,16 @@ class FreeSpaceUpdater : public QRunnable
m_parent.m_masterFreeSpaceList = list;
}
QMutexLocker locker(&m_lock);
int left = kRequeryTimeout - t.elapsed();
std::chrono::milliseconds left = kRequeryTimeout - t.elapsed();
if (m_lastRequest.elapsed() + left > kExitTimeout)
m_dorun = false;
if (!m_dorun)
{
m_running = false;
break;
}
if (left > 50)
m_wait.wait(locker.mutex(), left);
if (left > 50ms)
m_wait.wait(locker.mutex(), left.count());
}
}

Expand All @@ -229,11 +229,9 @@ class FreeSpaceUpdater : public QRunnable
bool m_running;
MythTimer m_lastRequest;
QWaitCondition m_wait;
const static int kRequeryTimeout;
const static int kExitTimeout;
static constexpr std::chrono::milliseconds kRequeryTimeout { 15s };
static constexpr std::chrono::milliseconds kExitTimeout { 61s };
};
const int FreeSpaceUpdater::kRequeryTimeout = 15000;
const int FreeSpaceUpdater::kExitTimeout = 61000;

MainServer::MainServer(bool master, int port,
QMap<int, EncoderLink *> *_tvList,
Expand Down