18 changes: 9 additions & 9 deletions mythtv/libs/libmythtv/DVD/mythdvdbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ class MTV_PUBLIC MythDVDBuffer : public MythOpticalBuffer
int GetCurrentAngle (void) const;
int GetNumAngles (void) const;
long long GetTotalReadPosition (void) const;
uint GetChapterLength (void) const;
void GetChapterTimes (QList<long long> &Times);
uint64_t GetChapterTimes (int Title);
std::chrono::seconds GetChapterLength (void) const;
void GetChapterTimes (QList<std::chrono::seconds> &Times);
std::chrono::seconds GetChapterTimes (int Title);
void GetDescForPos (QString &Description) const;
void GetPartAndTitle (int &Part, int &Title) const;
uint GetTotalTimeOfTitle (void) const;
std::chrono::seconds GetTotalTimeOfTitle (void) const;
float GetAspectOverride (void) const;
uint GetCellStart (void) const;
bool PGCLengthChanged (void);
Expand Down Expand Up @@ -111,8 +111,8 @@ class MTV_PUBLIC MythDVDBuffer : public MythOpticalBuffer
void GoToPreviousProgram (void);
bool GoBack (void);
void AudioStreamsChanged (bool Change);
int64_t GetCurrentTime (void) const;
uint TitleTimeLeft (void) const;
std::chrono::seconds GetCurrentTime (void) const;
std::chrono::seconds TitleTimeLeft (void) const;
void SetTrack (uint Type, int TrackNo);
int GetTrack (uint Type) const;
uint16_t GetNumAudioChannels (int Index);
Expand Down Expand Up @@ -170,8 +170,8 @@ class MTV_PUBLIC MythDVDBuffer : public MythOpticalBuffer
int m_currentTitleAngleCount { 0 };
int64_t m_endPts { 0 };
int64_t m_timeDiff { 0 };
int m_still { 0 };
int m_lastStill { 0 };
std::chrono::seconds m_still { 0s };
std::chrono::seconds m_lastStill { 0s };
bool m_audioStreamsChanged { false };
bool m_dvdWaiting { false };
long long m_titleLength { 0 };
Expand All @@ -193,7 +193,7 @@ class MTV_PUBLIC MythDVDBuffer : public MythOpticalBuffer
int64_t m_seektime { 0 };
int64_t m_currentTime { 0 };
static const QMap<int, int> kSeekSpeedMap;
QMap<int, QList<uint64_t> > m_chapterMap;
QMap<int, QList<std::chrono::seconds> > m_chapterMap;
MythDVDPlayer *m_parent { nullptr };
float m_forcedAspect { -1.0F };
QMutex m_contextLock { QMutex::Recursive };
Expand Down
14 changes: 7 additions & 7 deletions mythtv/libs/libmythtv/DVD/mythdvddecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void MythDVDDecoder::UpdateFramesPlayed(void)
if (!m_ringBuffer->IsDVD())
return;

auto currentpos = static_cast<long long>(m_ringBuffer->DVD()->GetCurrentTime() * m_fps);
auto currentpos = static_cast<long long>(m_ringBuffer->DVD()->GetCurrentTime().count() * m_fps);
m_framesPlayed = m_framesRead = currentpos ;
m_parent->SetFramesPlayed(static_cast<uint64_t>(currentpos + 1));
}
Expand Down Expand Up @@ -615,17 +615,17 @@ long long MythDVDDecoder::DVDFindPosition(long long DesiredFrame)

if (ffrewSkip == 1 || ffrewSkip == 0)
{
int diffTime = static_cast<int>(ceil((DesiredFrame - m_framesPlayed) / m_fps));
long long desiredTimePos = m_ringBuffer->DVD()->GetCurrentTime() +
std::chrono::seconds diffTime = std::chrono::seconds(static_cast<int>(ceil((DesiredFrame - m_framesPlayed) / m_fps)));
std::chrono::seconds desiredTimePos = m_ringBuffer->DVD()->GetCurrentTime() +
diffTime;
if (diffTime <= 0)
if (diffTime <= 0s)
desiredTimePos--;
else
desiredTimePos++;

if (desiredTimePos < 0)
desiredTimePos = 0;
return (desiredTimePos * 90000LL);
if (desiredTimePos < 0s)
desiredTimePos = 0s;
return (desiredTimePos.count() * 90000LL);
}
return current_speed;
}
Expand Down
49 changes: 24 additions & 25 deletions mythtv/libs/libmythtv/DVD/mythdvdplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ bool MythDVDPlayer::DecoderGetFrameREW(void)
{
MythPlayerUI::DecoderGetFrameREW();
return (m_playerCtx->m_buffer->IsDVD() &&
(m_playerCtx->m_buffer->DVD()->GetCurrentTime() < 2));
(m_playerCtx->m_buffer->DVD()->GetCurrentTime() < 2s));
}

void MythDVDPlayer::PreProcessNormalFrame(void)
Expand Down Expand Up @@ -415,7 +415,7 @@ uint64_t MythDVDPlayer::GetBookmark(void)

void MythDVDPlayer::ChangeSpeed(void)
{
if (m_stillFrameLength > 0)
if (m_stillFrameLength > 0s)
{
m_stillFrameTimerLock.lock();
// Get the timestretched elapsed time and transform
Expand Down Expand Up @@ -445,41 +445,40 @@ void MythDVDPlayer::ChangeSpeed(void)
long long MythDVDPlayer::CalcMaxFFTime(long long FastFwd, bool Setjump) const
{
if ((m_totalFrames > 0) && m_playerCtx->m_buffer->IsDVD() &&
m_playerCtx->m_buffer->DVD()->TitleTimeLeft() < 5)
m_playerCtx->m_buffer->DVD()->TitleTimeLeft() < 5s)
return 0;
return MythPlayerUI::CalcMaxFFTime(FastFwd, Setjump);
}

int64_t MythDVDPlayer::GetSecondsPlayed(bool /*HonorCutList*/, int Divisor)
std::chrono::milliseconds MythDVDPlayer::GetMillisecondsPlayed(bool /*HonorCutList*/)
{
if (!m_playerCtx->m_buffer->IsDVD())
return 0;
return 0ms;

int64_t played = m_playerCtx->m_buffer->DVD()->GetCurrentTime();
std::chrono::milliseconds played = m_playerCtx->m_buffer->DVD()->GetCurrentTime();

if (m_stillFrameLength > 0)
if (m_stillFrameLength > 0s)
{
if (m_stillFrameLength == 255)
played = -1;
else
played = static_cast<int64_t>(m_stillFrameTimer.elapsed().count() * m_playSpeed / Divisor);
if (m_stillFrameLength == 255s)
return -1ms;
played = millisecondsFromFloat(m_stillFrameTimer.elapsed().count() * m_playSpeed);
}

return played;
}

int64_t MythDVDPlayer::GetTotalSeconds(bool /*HonorCutList*/, int Divisor) const
std::chrono::milliseconds MythDVDPlayer::GetTotalMilliseconds(bool /*HonorCutList*/) const
{
int64_t total = m_totalLength;
std::chrono::milliseconds total = m_totalLength;

if (m_stillFrameLength > 0)
if (m_stillFrameLength > 0s)
{
if (m_stillFrameLength == 255)
return -1;
total = m_stillFrameLength;
if (m_stillFrameLength == 255s)
return -1ms;
total = duration_cast<std::chrono::milliseconds>(m_stillFrameLength);
}

return total * 1000 / Divisor;
return total;
}

void MythDVDPlayer::SetTrack(uint Type, uint TrackNo)
Expand Down Expand Up @@ -507,7 +506,7 @@ int MythDVDPlayer::GetCurrentChapter(void)
return m_playerCtx->m_buffer->DVD()->GetPart();
}

void MythDVDPlayer::GetChapterTimes(QList<long long> &Times)
void MythDVDPlayer::GetChapterTimes(QList<std::chrono::seconds> &Times)
{
if (!m_playerCtx->m_buffer->IsDVD())
return;
Expand Down Expand Up @@ -643,7 +642,7 @@ void MythDVDPlayer::GoToDVDProgram(bool Direction)

bool MythDVDPlayer::IsInStillFrame() const
{
return (m_stillFrameLength > 0);
return (m_stillFrameLength > 0s);
}

int MythDVDPlayer::GetNumAngles(void) const
Expand Down Expand Up @@ -682,7 +681,7 @@ bool MythDVDPlayer::SwitchAngle(int Angle)
return m_playerCtx->m_buffer->DVD()->SwitchAngle(Angle);
}

void MythDVDPlayer::SetStillFrameTimeout(int Length)
void MythDVDPlayer::SetStillFrameTimeout(std::chrono::seconds Length)
{
if (Length != m_stillFrameLength)
{
Expand All @@ -697,18 +696,18 @@ void MythDVDPlayer::StillFrameCheck(void)
{
if (m_playerCtx->m_buffer->IsDVD() &&
m_playerCtx->m_buffer->DVD()->IsInStillFrame() &&
(m_stillFrameLength > 0) && (m_stillFrameLength < 0xff))
(m_stillFrameLength > 0s) && (m_stillFrameLength < 255s))
{
m_stillFrameTimerLock.lock();
int elapsedTime = static_cast<int>(m_stillFrameTimer.elapsed().count() * m_playSpeed / 1000.0F);
auto elapsedTime = secondsFromFloat(m_stillFrameTimer.elapsed().count() * m_playSpeed / 1000.0F);
m_stillFrameTimerLock.unlock();
if (elapsedTime >= m_stillFrameLength)
{
LOG(VB_PLAYBACK, LOG_INFO, LOC +
QString("Stillframe timeout after %1 seconds (timestretch %2)")
.arg(m_stillFrameLength).arg(static_cast<double>(m_playSpeed)));
.arg(m_stillFrameLength.count()).arg(static_cast<double>(m_playSpeed)));
m_playerCtx->m_buffer->DVD()->SkipStillFrame();
m_stillFrameLength = 0;
m_stillFrameLength = 0s;
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions mythtv/libs/libmythtv/DVD/mythdvdplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class MythDVDPlayer : public MythPlayerUI
bool HasReachedEof(void) const override;
bool PrepareAudioSample(int64_t &Timecode) override;
uint64_t GetBookmark(void) override;
int64_t GetSecondsPlayed(bool HonorCutList, int Divisor = 1000) override;
int64_t GetTotalSeconds(bool HonorCutList, int Divisor = 1000) const override;
std::chrono::milliseconds GetMillisecondsPlayed(bool HonorCutList) override;
std::chrono::milliseconds GetTotalMilliseconds(bool HonorCutList) const override;
bool GoToMenu(const QString& Menu) override;
void GoToDVDProgram(bool Direction) override;
bool IsInStillFrame() const override;
Expand All @@ -29,9 +29,9 @@ class MythDVDPlayer : public MythPlayerUI
bool SwitchAngle(int Angle) override;
int GetNumChapters(void) override;
int GetCurrentChapter(void) override;
void GetChapterTimes(QList<long long> &Times) override;
void GetChapterTimes(QList<std::chrono::seconds> &Times) override;

void SetStillFrameTimeout(int Length);
void SetStillFrameTimeout(std::chrono::seconds Length);
void StillFrameCheck(void);

protected:
Expand Down Expand Up @@ -77,7 +77,7 @@ class MythDVDPlayer : public MythPlayerUI

// still frame timing
MythTimer m_stillFrameTimer { };
int m_stillFrameLength { 0 };
std::chrono::seconds m_stillFrameLength { 0s };
QMutex m_stillFrameTimerLock { QMutex::Recursive };
};

Expand Down
73 changes: 36 additions & 37 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@
#include <QTextCodec>
#include <QFileInfo>

#ifdef USING_MEDIACODEC
extern "C" {
#include "libavcodec/jni.h"
}
#include <QtAndroidExtras>
#endif

extern "C" {
#include "libavutil/avutil.h"
#include "libavutil/error.h"
#include "libavutil/log.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavformat/avio.h"
#include "libavformat/internal.h"
#include "libswscale/swscale.h"
#include "libavformat/isom.h"
#include "ivtv_myth.h"
#include "libavutil/imgutils.h"
#include "libavutil/display.h"
}

// MythTV headers
#include "mythtvexp.h"
#include "mythconfig.h"
Expand Down Expand Up @@ -41,28 +63,6 @@

#include "audiooutput.h"

#ifdef USING_MEDIACODEC
extern "C" {
#include "libavcodec/jni.h"
}
#include <QtAndroidExtras>
#endif

extern "C" {
#include "libavutil/avutil.h"
#include "libavutil/error.h"
#include "libavutil/log.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavformat/avio.h"
#include "libavformat/internal.h"
#include "libswscale/swscale.h"
#include "libavformat/isom.h"
#include "ivtv_myth.h"
#include "libavutil/imgutils.h"
#include "libavutil/display.h"
}

#ifdef _MSC_VER
// MSVC isn't C99 compliant...
# ifdef AV_TIME_BASE_Q
Expand Down Expand Up @@ -331,10 +331,10 @@ AvFormatDecoder::AvFormatDecoder(MythPlayer *parent,
cc608_build_parity_table(m_cc608ParityTable);

AvFormatDecoder::SetIdrOnlyKeyframes(true);
m_audioReadAhead = gCoreContext->GetNumSetting("AudioReadAhead", 100);
m_audioReadAhead = gCoreContext->GetDurSetting<std::chrono::milliseconds>("AudioReadAhead", 100ms);

LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("PlayerFlags: 0x%1, AudioReadAhead: %2 msec")
.arg(m_playerFlags, 0, 16).arg(m_audioReadAhead));
.arg(m_playerFlags, 0, 16).arg(m_audioReadAhead.count()));
}

AvFormatDecoder::~AvFormatDecoder()
Expand Down Expand Up @@ -475,7 +475,7 @@ int AvFormatDecoder::GetNumChapters()
return 0;
}

void AvFormatDecoder::GetChapterTimes(QList<long long> &times)
void AvFormatDecoder::GetChapterTimes(QList<std::chrono::seconds> &times)
{
int total = GetNumChapters();
if (!total)
Expand All @@ -488,7 +488,7 @@ void AvFormatDecoder::GetChapterTimes(QList<long long> &times)
int64_t start = m_ic->chapters[i]->start;
long double total_secs = (long double)start * (long double)num /
(long double)den;
times.push_back((long long)total_secs);
times.push_back(std::chrono::seconds((long long)total_secs));
}
}

Expand Down Expand Up @@ -1152,26 +1152,25 @@ int AvFormatDecoder::OpenFile(MythMediaBuffer *Buffer, bool novideo,

// If watching pre-recorded television or video use the marked duration
// from the db if it exists, else ffmpeg duration
int64_t dur = 0;
std::chrono::seconds dur = 0s;

if (m_playbackInfo)
{
dur = m_playbackInfo->QueryTotalDuration();
dur /= 1000;
dur = duration_cast<std::chrono::seconds>(m_playbackInfo->QueryTotalDuration());
}

if (dur == 0)
if (dur == 0s)
{
if ((m_ic->duration == AV_NOPTS_VALUE) &&
(!m_livetv && !m_ringBuffer->IsDisc()))
av_estimate_timings(m_ic, 0);

dur = m_ic->duration / (int64_t)AV_TIME_BASE;
dur = duration_cast<std::chrono::seconds>(av_duration(m_ic->duration));
}

if (dur > 0 && !m_livetv && !m_watchingRecording)
if (dur > 0s && !m_livetv && !m_watchingRecording)
{
m_parent->SetDuration((int)dur);
m_parent->SetDuration(dur);
}

// If we don't have a position map, set up ffmpeg for seeking
Expand All @@ -1180,16 +1179,16 @@ int AvFormatDecoder::OpenFile(MythMediaBuffer *Buffer, bool novideo,
LOG(VB_PLAYBACK, LOG_INFO, LOC +
"Recording has no position -- using libavformat seeking.");

if (dur > 0)
if (dur > 0s)
{
m_parent->SetFileLength((int)(dur), (int)(dur * m_fps));
m_parent->SetFileLength(dur, (int)(dur.count() * m_fps));
}
else
{
// the pvr-250 seems to over report the bitrate by * 2
float bytespersec = (float)m_bitrate / 8 / 2;
float secs = m_ringBuffer->GetRealFileSize() * 1.0F / bytespersec;
m_parent->SetFileLength((int)(secs),
m_parent->SetFileLength(secondsFromFloat(secs),
(int)(secs * static_cast<float>(m_fps)));
}

Expand Down Expand Up @@ -4863,7 +4862,7 @@ bool AvFormatDecoder::GetFrame(DecodeType decodetype, bool &Retry)
// buffer audio to prevent audio buffer
// underruns in case you are setting negative values
// in Adjust Audio Sync.
m_lastAPts < m_lastVPts + m_audioReadAhead &&
m_lastAPts < m_lastVPts + m_audioReadAhead.count() &&
!m_ringBuffer->IsInStillFrame())
{
storevideoframes = true;
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class AvFormatDecoder : public DecoderBase
int FindStreamInfo(void);

int GetNumChapters() override; // DecoderBase
void GetChapterTimes(QList<long long> &times) override; // DecoderBase
void GetChapterTimes(QList<std::chrono::seconds> &times) override; // DecoderBase
int GetCurrentChapter(long long framesPlayed) override; // DecoderBase
long long GetChapter(int chapter) override; // DecoderBase
bool DoRewind(long long desiredFrame, bool discardFrames = true) override; // DecoderBase
Expand Down Expand Up @@ -365,7 +365,7 @@ class AvFormatDecoder : public DecoderBase
bool m_resetHardwareDecoders { false };

// Value in milliseconds, from setting AudioReadAhead
int m_audioReadAhead {100};
std::chrono::milliseconds m_audioReadAhead {100ms};

QMutex m_avCodecLock { QMutex::Recursive };
};
Expand Down
24 changes: 12 additions & 12 deletions mythtv/libs/libmythtv/decoders/decoderbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ bool DecoderBase::PosMapFromDb(void)
if (m_fps < 26 && m_fps > 24)
m_keyframeDist = 12;
auto totframes =
(long long)(m_ringBuffer->DVD()->GetTotalTimeOfTitle() * m_fps);
(long long)(m_ringBuffer->DVD()->GetTotalTimeOfTitle().count() * m_fps);
posMap[totframes] = m_ringBuffer->DVD()->GetTotalReadPosition();
}
else if (m_ringBuffer && m_ringBuffer->IsBD())
Expand All @@ -118,7 +118,7 @@ bool DecoderBase::PosMapFromDb(void)
if (m_fps < 26 && m_fps > 24)
m_keyframeDist = 12;
auto totframes =
(long long)(m_ringBuffer->BD()->GetTotalTimeOfTitle() * m_fps);
(long long)(m_ringBuffer->BD()->GetTotalTimeOfTitle().count() * m_fps);
posMap[totframes] = m_ringBuffer->BD()->GetTotalReadPosition();
#if 0
LOG(VB_PLAYBACK, LOG_DEBUG, LOC +
Expand Down Expand Up @@ -376,7 +376,7 @@ bool DecoderBase::SyncPositionMap(void)
if (ret_val && m_keyframeDist > 0)
{
long long totframes = 0;
int length = 0;
std::chrono::seconds length = 0s;

if (m_ringBuffer && m_ringBuffer->IsDVD())
{
Expand All @@ -395,7 +395,7 @@ bool DecoderBase::SyncPositionMap(void)
QMutexLocker locker(&m_positionMapLock);
totframes = m_positionMap.back().index * m_keyframeDist;
if (m_fps != 0.0)
length = (int)((totframes * 1.0) / m_fps);
length = secondsFromFloat((totframes * 1.0) / m_fps);
}

m_parent->SetFileLength(length, totframes);
Expand All @@ -405,7 +405,7 @@ bool DecoderBase::SyncPositionMap(void)
LOG(VB_PLAYBACK, LOG_INFO, LOC +
QString("SyncPositionMap, new totframes: %1, new length: %2, "
"posMap size: %3")
.arg(totframes).arg(length).arg(new_posmap_size));
.arg(totframes).arg(length.count()).arg(new_posmap_size));
}
m_recordingHasPositionMap |= (0 != new_posmap_size);
{
Expand Down Expand Up @@ -722,7 +722,7 @@ bool DecoderBase::DoFastForward(long long desiredFrame, bool discardFrames)

if (m_ringBuffer->IsDVD() &&
!m_ringBuffer->IsInDiscMenuOrStillFrame() &&
m_ringBuffer->DVD()->TitleTimeLeft() < 5)
m_ringBuffer->DVD()->TitleTimeLeft() < 5s)
{
return false;
}
Expand Down Expand Up @@ -1243,7 +1243,7 @@ void DecoderBase::SaveTotalDuration(void)
if (!m_playbackInfo || av_q2d(m_totalDuration) == 0)
return;

m_playbackInfo->SaveTotalDuration(1000000 * av_q2d(m_totalDuration));
m_playbackInfo->SaveTotalDuration(millisecondsFromFloat(1000 * av_q2d(m_totalDuration)));
}

void DecoderBase::SaveTotalFrames(void)
Expand Down Expand Up @@ -1308,7 +1308,7 @@ uint64_t DecoderBase::TranslatePosition(const frm_pos_map_t &map,

// Convert from an absolute frame number (not cutlist adjusted) to its
// cutlist-adjusted position in milliseconds.
uint64_t DecoderBase::TranslatePositionFrameToMs(long long position,
std::chrono::milliseconds DecoderBase::TranslatePositionFrameToMs(long long position,
float fallback_framerate,
const frm_dir_map_t &cutlist)
{
Expand All @@ -1330,20 +1330,20 @@ uint64_t DecoderBase::TranslatePositionFrameToMs(long long position,
SyncPositionMap();
}
}
return TranslatePositionAbsToRel(cutlist, position, m_frameToDurMap,
1000 / fallback_framerate);
return std::chrono::milliseconds(TranslatePositionAbsToRel(cutlist, position, m_frameToDurMap,
1000 / fallback_framerate));
}

// Convert from a cutlist-adjusted position in milliseconds to its
// absolute frame number (not cutlist-adjusted).
uint64_t DecoderBase::TranslatePositionMsToFrame(uint64_t dur_ms,
uint64_t DecoderBase::TranslatePositionMsToFrame(std::chrono::milliseconds dur_ms,
float fallback_framerate,
const frm_dir_map_t &cutlist)
{
QMutexLocker locker(&m_positionMapLock);
// Convert relative position in milliseconds (cutlist-adjusted) to
// its absolute position in milliseconds (not cutlist-adjusted).
uint64_t ms = TranslatePositionRelToAbs(cutlist, dur_ms, m_frameToDurMap,
uint64_t ms = TranslatePositionRelToAbs(cutlist, dur_ms.count(), m_frameToDurMap,
1000 / fallback_framerate);
// Convert absolute position in milliseconds to its absolute frame
// number.
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/decoders/decoderbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class DecoderBase

virtual int GetNumChapters(void) { return 0; }
virtual int GetCurrentChapter(long long /*framesPlayed*/) { return 0; }
virtual void GetChapterTimes(QList<long long> &/*times*/) { }
virtual void GetChapterTimes(QList<std::chrono::seconds> &/*times*/) { }
virtual long long GetChapter(int /*chapter*/) { return m_framesPlayed; }
virtual bool DoRewind(long long desiredFrame, bool discardFrames = true);
virtual bool DoFastForward(long long desiredFrame, bool discardFrames = true);
Expand All @@ -172,10 +172,10 @@ class DecoderBase
static uint64_t TranslatePosition(const frm_pos_map_t &map,
long long key,
float fallback_ratio);
uint64_t TranslatePositionFrameToMs(long long position,
std::chrono::milliseconds TranslatePositionFrameToMs(long long position,
float fallback_framerate,
const frm_dir_map_t &cutlist);
uint64_t TranslatePositionMsToFrame(uint64_t dur_ms,
uint64_t TranslatePositionMsToFrame(std::chrono::milliseconds dur_ms,
float fallback_framerate,
const frm_dir_map_t &cutlist);

Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/deletemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ QString DeleteMap::CreateTimeString(uint64_t frame, bool use_cutlist,
double frame_rate, bool full_resolution)
const
{
auto ms = std::chrono::milliseconds(TranslatePositionFrameToMs(frame, frame_rate, use_cutlist));
std::chrono::milliseconds ms = TranslatePositionFrameToMs(frame, frame_rate, use_cutlist);
QString fmt = (ms >= 1h) ? "H:mm:ss" : "mm:ss";
if (full_resolution)
fmt += ".zzz";
Expand Down Expand Up @@ -892,7 +892,7 @@ bool DeleteMap::IsSaved(void) const
return currentMap == savedMap;
}

uint64_t DeleteMap::TranslatePositionFrameToMs(uint64_t position,
std::chrono::milliseconds DeleteMap::TranslatePositionFrameToMs(uint64_t position,
float fallback_framerate,
bool use_cutlist) const
{
Expand All @@ -901,7 +901,7 @@ uint64_t DeleteMap::TranslatePositionFrameToMs(uint64_t position,
use_cutlist ? m_deleteMap :
frm_dir_map_t());
}
uint64_t DeleteMap::TranslatePositionMsToFrame(uint64_t dur_ms,
uint64_t DeleteMap::TranslatePositionMsToFrame(std::chrono::milliseconds dur_ms,
float fallback_framerate,
bool use_cutlist) const
{
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/deletemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ class MTV_PUBLIC DeleteMap

// Provide translations between frame numbers and millisecond
// durations, optionally taking the custlist into account.
uint64_t TranslatePositionFrameToMs(uint64_t position,
std::chrono::milliseconds TranslatePositionFrameToMs(uint64_t position,
float fallback_framerate,
bool use_cutlist) const;
uint64_t TranslatePositionMsToFrame(uint64_t dur_ms,
uint64_t TranslatePositionMsToFrame(std::chrono::milliseconds dur_ms,
float fallback_framerate,
bool use_cutlist) const;
uint64_t TranslatePositionAbsToRel(uint64_t position) const;
Expand Down
37 changes: 18 additions & 19 deletions mythtv/libs/libmythtv/livetvchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,33 +355,33 @@ int LiveTVChain::ProgramIsAt(const ProgramInfo &pginfo) const
}

/** \fn LiveTVChain::GetLengthAtCurPos(void)
* \returns length in seocnds of recording at current position
* \returns length in seconds of recording at current position
*/
int LiveTVChain::GetLengthAtCurPos(void)
std::chrono::seconds LiveTVChain::GetLengthAtCurPos(void)
{
return GetLengthAtPos(m_curPos);
}

/** \fn LiveTVChain::GetLengthAtCurPos(void)
/**
* \returns length in seocnds of recording at m_curPos
*/
int LiveTVChain::GetLengthAtPos(int pos)
std::chrono::seconds LiveTVChain::GetLengthAtPos(int pos)
{
QMutexLocker lock(&m_lock);

LiveTVChainEntry entry = m_chain[pos];
if (pos == (m_chain.count() - 1))
{
// We're on live program, it hasn't ended. Use current time as end time
return entry.starttime.secsTo(MythDate::current());
return MythDate::secsInPast(entry.starttime);
}

// use begin time from the following program, as it's certain to be right
// the end time is set as per the EPG, but should playback be interrupted
// such as a channel change, the end value wouldn't have reflected the actual
// duration of the program
LiveTVChainEntry nextentry = m_chain[pos+1];
return entry.starttime.secsTo(nextentry.starttime);
return std::chrono::seconds(entry.starttime.secsTo(nextentry.starttime));
}

int LiveTVChain::TotalSize(void) const
Expand Down Expand Up @@ -412,7 +412,7 @@ void LiveTVChain::ClearSwitch(void)
QMutexLocker lock(&m_lock);

m_switchId = -1;
m_jumpPos = INT_MAX;
m_jumpPos = std::chrono::seconds::max();
}

/**
Expand Down Expand Up @@ -599,25 +599,24 @@ void LiveTVChain::SwitchToNext(bool up)
SwitchTo(m_curPos - 1);
}

void LiveTVChain::JumpTo(int num, int pos)
void LiveTVChain::JumpTo(int num, std::chrono::seconds pos)
{
m_jumpPos = pos;
SwitchTo(num);
}

/**
* JumpToNext(bool up, int pos)
* jump to the next (up == true) or previous (up == false) liveTV program
* If pos > 0: indicate the absolute position where to start the next program
* If pos < 0: indicate offset position; in which case the right liveTV program
* will be found accordingly.
* Offset is in reference to the beginning of the current recordings when going down
* and in reference to the end of the current recording when going up
*/
void LiveTVChain::JumpToNext(bool up, int pos)
void LiveTVChain::JumpToNext(bool up, std::chrono::seconds pos)
{
LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("JumpToNext: %1 -> %2").arg(up).arg(pos));
if (pos >= 0)
LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("JumpToNext: %1 -> %2").arg(up).arg(pos.count()));
if (pos >= 0s)
{
m_jumpPos = pos;
SwitchToNext(up);
Expand All @@ -642,15 +641,15 @@ void LiveTVChain::JumpToNext(bool up, int pos)
if (switchto == current)
{
// we've reached the end
pos = up ? GetLengthAtPos(switchto) : 0;
pos = up ? GetLengthAtPos(switchto) : 0s;
break;
}

int duration = GetLengthAtPos(switchto);
std::chrono::seconds duration = GetLengthAtPos(switchto);

pos += duration;

if (pos >= 0)
if (pos >= 0s)
{
if (up)
{
Expand All @@ -667,13 +666,13 @@ void LiveTVChain::JumpToNext(bool up, int pos)
}
}

/** \fn LiveTVChain::GetJumpPos(void)
/**
* \brief Returns the jump position in seconds and clears it.
*/
int LiveTVChain::GetJumpPos(void)
std::chrono::seconds LiveTVChain::GetJumpPos(void)
{
int ret = m_jumpPos;
m_jumpPos = 0;
std::chrono::seconds ret = m_jumpPos;
m_jumpPos = 0s;
return ret;
}

Expand Down
16 changes: 8 additions & 8 deletions mythtv/libs/libmythtv/livetvchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ class MTV_PUBLIC LiveTVChain : public ReferenceCounter
int GetCurPos(void) const { return m_curPos; }
int ProgramIsAt(uint chanid, const QDateTime &starttime) const;
int ProgramIsAt(const ProgramInfo &pginfo) const;
int GetLengthAtCurPos(void);
int GetLengthAtPos(int pos);
std::chrono::seconds GetLengthAtCurPos(void);
std::chrono::seconds GetLengthAtPos(int pos);
int TotalSize(void) const;
bool HasNext(void) const;
bool HasPrev(void) const { return (m_curPos > 0); }
ProgramInfo *GetProgramAt(int at) const;
/// Returns true iff a switch is required but no jump is required
/// m_jumppos sets to INT_MAX means not set
bool NeedsToSwitch(void) const
{ return (m_switchId >= 0 && m_jumpPos == INT_MAX); }
{ return (m_switchId >= 0 && m_jumpPos == std::chrono::seconds::max()); }
/// Returns true iff a switch and jump are required
bool NeedsToJump(void) const
{ return (m_switchId >= 0 && m_jumpPos != INT_MAX); }
{ return (m_switchId >= 0 && m_jumpPos != std::chrono::seconds::max()); }
QString GetChannelName(int pos = -1) const;
QString GetInputName(int pos = -1) const;
QString GetInputType(int pos = -1) const;
Expand All @@ -79,9 +79,9 @@ class MTV_PUBLIC LiveTVChain : public ReferenceCounter
ProgramInfo *GetSwitchProgram(bool &discont, bool &newtype, int &newid);

// sets/gets program to jump to
void JumpTo(int num, int pos);
void JumpToNext(bool up, int pos);
int GetJumpPos(void);
void JumpTo(int num, std::chrono::seconds pos);
void JumpToNext(bool up, std::chrono::seconds pos);
std::chrono::seconds GetJumpPos(void);

// socket stuff
void SetHostSocket(MythSocket *sock);
Expand Down Expand Up @@ -118,7 +118,7 @@ class MTV_PUBLIC LiveTVChain : public ReferenceCounter
int m_switchId {-1};
LiveTVChainEntry m_switchEntry;

int m_jumpPos {INT_MAX};
std::chrono::seconds m_jumpPos {std::chrono::seconds::max()};

mutable QMutex m_sockLock;
QList<MythSocket*> m_inUseSocks;
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/mheg/mhi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,20 +1145,20 @@ void MHIContext::StopVideo()
// Get current stream position, -1 if unknown
long MHIContext::GetStreamPos()
{
return m_parent->GetPlayer() ? m_parent->GetPlayer()->GetStreamPos() : -1;
return m_parent->GetPlayer() ? m_parent->GetPlayer()->GetStreamPos().count() : -1;
}

// Get current stream size, -1 if unknown
long MHIContext::GetStreamMaxPos()
{
return m_parent->GetPlayer() ? m_parent->GetPlayer()->GetStreamMaxPos() : -1;
return m_parent->GetPlayer() ? m_parent->GetPlayer()->GetStreamMaxPos().count() : -1;
}

// Set current stream position
long MHIContext::SetStreamPos(long pos)
{
if (m_parent->GetPlayer())
emit m_parent->GetPlayer()->SetInteractiveStreamPos(pos);
emit m_parent->GetPlayer()->SetInteractiveStreamPos(std::chrono::seconds(pos));
// Note: return value is never used
return 0;
}
Expand Down
48 changes: 28 additions & 20 deletions mythtv/libs/libmythtv/mythplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,13 @@ void MythPlayer::SetFrameRate(double fps)
SetFrameInterval(kScan_Progressive, 1.0 / (m_videoFrameRate * static_cast<double>(temp_speed)));
}

void MythPlayer::SetFileLength(int total, int frames)
void MythPlayer::SetFileLength(std::chrono::seconds total, int frames)
{
m_totalLength = total;
m_totalFrames = frames;
}

void MythPlayer::SetDuration(int duration)
void MythPlayer::SetDuration(std::chrono::seconds duration)
{
m_totalDuration = duration;
}
Expand Down Expand Up @@ -839,7 +839,8 @@ bool MythPlayer::FastForward(float seconds)

if (dest > length)
{
int64_t pos = TranslatePositionMsToFrame(seconds * 1000, false);
auto msec = millisecondsFromFloat(seconds * 1000);
int64_t pos = TranslatePositionMsToFrame(msec, false);
if (CalcMaxFFTime(pos) < 0)
return true;
// Reach end of recording, go to 1 or 3s before the end
Expand All @@ -862,7 +863,8 @@ bool MythPlayer::Rewind(float seconds)
float dest = current - seconds;
if (dest < 0)
{
int64_t pos = TranslatePositionMsToFrame(seconds * 1000, false);
auto msec = millisecondsFromFloat(seconds * 1000);
int64_t pos = TranslatePositionMsToFrame(msec, false);
if (CalcRWTime(pos) < 0)
return true;
dest = 0;
Expand Down Expand Up @@ -1408,7 +1410,8 @@ long long MythPlayer::CalcRWTime(long long rw) const
return rw;
}

m_playerCtx->m_tvchain->JumpToNext(false, ((int64_t)m_framesPlayed - rw) / m_videoFrameRate);
auto seconds = secondsFromFloat((m_framesPlayed - rw) / m_videoFrameRate);
m_playerCtx->m_tvchain->JumpToNext(false, seconds);

return -1;
}
Expand Down Expand Up @@ -1440,7 +1443,9 @@ long long MythPlayer::CalcMaxFFTime(long long ffframes, bool setjump) const
{
ret = -1;
// Number of frames to be skipped is from the end of the current segment
m_playerCtx->m_tvchain->JumpToNext(true, ((int64_t)m_totalFrames - (int64_t)m_framesPlayed - ffframes) / m_videoFrameRate);
auto seconds = secondsFromFloat((m_totalFrames - m_framesPlayed - ffframes)
/ m_videoFrameRate);
m_playerCtx->m_tvchain->JumpToNext(true, seconds);
}
}
else if (islivetvcur || IsWatchingInprogress())
Expand All @@ -1459,8 +1464,10 @@ long long MythPlayer::CalcMaxFFTime(long long ffframes, bool setjump) const
if (behind < maxtime) // if we're close, do nothing
ret = 0;
else if (behind - ff <= maxtime)
ret = TranslatePositionMsToFrame(1000 * (secsWritten - maxtime),
true) - m_framesPlayed;
{
auto msec = millisecondsFromFloat(1000 * (secsWritten - maxtime));
ret = TranslatePositionMsToFrame(msec, true) - m_framesPlayed;
}

if (behind < maxtime * 3)
m_limitKeyRepeat = true;
Expand All @@ -1478,8 +1485,10 @@ long long MythPlayer::CalcMaxFFTime(long long ffframes, bool setjump) const
if (secsMax <= 0.F)
ret = 0;
else if (secsMax < secsPlayed + ff)
ret = TranslatePositionMsToFrame(1000 * secsMax, true)
- m_framesPlayed;
{
auto msec = millisecondsFromFloat(1000 * secsMax);
ret = TranslatePositionMsToFrame(msec, true) - m_framesPlayed;
}
}

return ret;
Expand Down Expand Up @@ -1751,8 +1760,9 @@ uint64_t MythPlayer::FindFrame(float offset, bool use_cutlist) const
{
bool islivetvcur = (m_liveTV && m_playerCtx->m_tvchain &&
!m_playerCtx->m_tvchain->HasNext());
uint64_t length_ms = TranslatePositionFrameToMs(m_totalFrames, use_cutlist);
uint64_t position_ms = 0;
std::chrono::milliseconds length_ms = TranslatePositionFrameToMs(m_totalFrames, use_cutlist);
std::chrono::milliseconds position_ms = 0ms;
auto offset_ms = std::chrono::milliseconds(llroundf(fabsf(offset) * 1000));

if (signbit(offset))
{
Expand All @@ -1768,18 +1778,16 @@ uint64_t MythPlayer::FindFrame(float offset, bool use_cutlist) const
TranslatePositionFrameToMs(framesWritten, use_cutlist);
}
}
uint64_t offset_ms = llroundf(-offset * 1000);
position_ms = (offset_ms > length_ms) ? 0 : length_ms - offset_ms;
position_ms = (offset_ms > length_ms) ? 0ms : length_ms - offset_ms;
}
else
{
position_ms = llroundf(offset * 1000);

if (offset > length_ms)
position_ms = offset_ms;
if (offset_ms > length_ms)
{
// Make sure we have an updated totalFrames
if ((islivetvcur || IsWatchingInprogress()) &&
(length_ms < offset))
(length_ms < offset_ms))
{
long long framesWritten =
m_playerCtx->m_recorder->GetFramesWritten();
Expand All @@ -1796,7 +1804,7 @@ uint64_t MythPlayer::FindFrame(float offset, bool use_cutlist) const
// If position == -1, it signifies that we are computing the current
// duration of an in-progress recording. In this case, we fetch the
// current frame rate and frame count from the recorder.
uint64_t MythPlayer::TranslatePositionFrameToMs(uint64_t position,
std::chrono::milliseconds MythPlayer::TranslatePositionFrameToMs(uint64_t position,
bool use_cutlist) const
{
float frameRate = GetFrameRate();
Expand Down Expand Up @@ -1826,7 +1834,7 @@ int MythPlayer::GetCurrentChapter()
return 0;
}

void MythPlayer::GetChapterTimes(QList<long long> &times)
void MythPlayer::GetChapterTimes(QList<std::chrono::seconds> &times)
{
if (m_decoder)
m_decoder->GetChapterTimes(times);
Expand Down
20 changes: 10 additions & 10 deletions mythtv/libs/libmythtv/mythplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class MTV_PUBLIC MythPlayer : public QObject
virtual void InitFrameInterval();

// Public Sets
void SetLength(int len) { m_totalLength = len; }
void SetLength(std::chrono::seconds len) { m_totalLength = len; }
void SetFramesPlayed(uint64_t played);
void SetEof(EofState eof);
void SetWatchingRecording(bool mode);
Expand All @@ -122,8 +122,8 @@ class MTV_PUBLIC MythPlayer : public QObject
bool ForceUpdate, int ReferenceFrames,
FrameScanType /*scan*/ = kScan_Ignore,
const QString& codecName = QString());
void SetFileLength(int total, int frames);
void SetDuration(int duration);
void SetFileLength(std::chrono::seconds total, int frames);
void SetDuration(std::chrono::seconds duration);
void SetFrameRate(double fps);

// Gets
Expand All @@ -138,7 +138,7 @@ class MTV_PUBLIC MythPlayer : public QObject
float GetPlaySpeed(void) const { return m_playSpeed; }
AudioPlayer* GetAudio(void) { return &m_audio; }
float GetNextPlaySpeed(void) const { return m_nextPlaySpeed; }
int GetLength(void) const { return m_totalLength; }
std::chrono::seconds GetLength(void) const { return m_totalLength; }
uint64_t GetTotalFrameCount(void) const { return m_totalFrames; }
uint64_t GetCurrentFrameCount(void) const;
uint64_t GetFramesPlayed(void) const { return m_framesPlayed; }
Expand Down Expand Up @@ -216,7 +216,7 @@ class MTV_PUBLIC MythPlayer : public QObject
// Chapter public stuff
virtual int GetNumChapters(void);
virtual int GetCurrentChapter(void);
virtual void GetChapterTimes(QList<long long> &times);
virtual void GetChapterTimes(QList<std::chrono::seconds> &times);

// Title public stuff
virtual int GetNumTitles(void) const { return 0; }
Expand Down Expand Up @@ -257,9 +257,9 @@ class MTV_PUBLIC MythPlayer : public QObject
// Complicated gets
virtual long long CalcMaxFFTime(long long ff, bool setjump = true) const;
long long CalcRWTime(long long rw) const;
uint64_t TranslatePositionFrameToMs(uint64_t position,
std::chrono::milliseconds TranslatePositionFrameToMs(uint64_t position,
bool use_cutlist) const;
uint64_t TranslatePositionMsToFrame(uint64_t position,
uint64_t TranslatePositionMsToFrame(std::chrono::milliseconds position,
bool use_cutlist) const {
return m_deleteMap.TranslatePositionMsToFrame(position,
GetFrameRate(),
Expand All @@ -275,7 +275,7 @@ class MTV_PUBLIC MythPlayer : public QObject
return m_deleteMap.TranslatePositionRelToAbs(position);
}
float ComputeSecs(uint64_t position, bool use_cutlist) const {
return TranslatePositionFrameToMs(position, use_cutlist) / 1000.0;
return TranslatePositionFrameToMs(position, use_cutlist).count() / 1000.0;
}
uint64_t FindFrame(float offset, bool use_cutlist) const;

Expand Down Expand Up @@ -428,8 +428,8 @@ class MTV_PUBLIC MythPlayer : public QObject
int m_videobufRetries {0};
uint64_t m_framesPlayed {0};
uint64_t m_totalFrames {0};
long long m_totalLength {0};
int64_t m_totalDuration {0};
std::chrono::seconds m_totalLength {0s};
std::chrono::seconds m_totalDuration {0s};
long long m_rewindTime {0};
int64_t m_latestVideoTimecode {-1};
MythPlayerAVSync m_avSync;
Expand Down
20 changes: 10 additions & 10 deletions mythtv/libs/libmythtv/mythplayercaptionsui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,32 +632,32 @@ void MythPlayerCaptionsUI::SetStream(const QString& Stream)
{
// Restore livetv
SetEof(kEofStateDelayed);
m_playerCtx->m_tvchain->JumpToNext(false, 0);
m_playerCtx->m_tvchain->JumpToNext(true, 0);
m_playerCtx->m_tvchain->JumpToNext(false, 0s);
m_playerCtx->m_tvchain->JumpToNext(true, 0s);
}
}

// Called from the interactiveTV (MHIContext) thread
long MythPlayerCaptionsUI::GetStreamPos()
std::chrono::milliseconds MythPlayerCaptionsUI::GetStreamPos()
{
return static_cast<long>((1000 * GetFramesPlayed()) / SafeFPS());
return millisecondsFromFloat((1000 * GetFramesPlayed()) / SafeFPS());
}

// Called from the interactiveTV (MHIContext) thread
long MythPlayerCaptionsUI::GetStreamMaxPos()
std::chrono::milliseconds MythPlayerCaptionsUI::GetStreamMaxPos()
{
auto maxpos = static_cast<long>(1000 * (m_totalDuration > 0 ? m_totalDuration : m_totalLength));
std::chrono::seconds maxsecs = m_totalDuration > 0s ? m_totalDuration : m_totalLength;
auto maxpos = duration_cast<std::chrono::milliseconds>(maxsecs);
auto pos = GetStreamPos();
return maxpos > pos ? maxpos : pos;
}

long MythPlayerCaptionsUI::SetStreamPos(long Position)
void MythPlayerCaptionsUI::SetStreamPos(std::chrono::milliseconds Position)
{
auto frameNum = static_cast<uint64_t>((Position * SafeFPS()) / 1000);
auto frameNum = static_cast<uint64_t>((Position.count() * SafeFPS()) / 1000);
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("SetStreamPos %1 mS = frame %2, now=%3")
.arg(Position).arg(frameNum).arg(GetFramesPlayed()) );
.arg(Position.count()).arg(frameNum).arg(GetFramesPlayed()) );
JumpToFrame(frameNum);
return Position;
}

void MythPlayerCaptionsUI::StreamPlay(bool Playing)
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/mythplayercaptionsui.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MTV_PUBLIC MythPlayerCaptionsUI : public MythPlayerAudioUI
void CaptionsStateChanged(MythCaptionsState& CaptionsState);
void ResizeForInteractiveTV(const QRect& Rect);
void SetInteractiveStream(const QString& Stream);
void SetInteractiveStreamPos(long Position);
void SetInteractiveStreamPos(std::chrono::seconds Position);
void PlayInteractiveStream(bool Play);

public:
Expand All @@ -29,8 +29,8 @@ class MTV_PUBLIC MythPlayerCaptionsUI : public MythPlayerAudioUI

bool SetAudioByComponentTag(int Tag);
bool SetVideoByComponentTag(int Tag);
long GetStreamPos();
long GetStreamMaxPos();
std::chrono::milliseconds GetStreamPos();
std::chrono::milliseconds GetStreamMaxPos();
InteractiveTV* GetInteractiveTV() override;

protected slots:
Expand Down Expand Up @@ -58,7 +58,7 @@ class MTV_PUBLIC MythPlayerCaptionsUI : public MythPlayerAudioUI
private slots:
void ExternalSubtitlesUpdated();
void SetStream(const QString& Stream);
long SetStreamPos(long Position);
void SetStreamPos(std::chrono::milliseconds Position);
void StreamPlay(bool Playing = true);

protected:
Expand Down
64 changes: 30 additions & 34 deletions mythtv/libs/libmythtv/mythplayeroverlayui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void MythPlayerOverlayUI::UpdateSliderInfo(osdInfo &Info, bool PaddedFields)
Info.values.insert("progbefore", 0);
Info.values.insert("progafter", 0);

int playbackLen = 0;
std::chrono::seconds playbackLen = 0s;
bool fixed_playbacklen = false;

if (m_liveTV && m_playerCtx->m_tvchain)
Expand Down Expand Up @@ -187,42 +187,42 @@ void MythPlayerOverlayUI::UpdateSliderInfo(osdInfo &Info, bool PaddedFields)

QString relPrefix = (honorCutList ? "rel" : "");
if (!fixed_playbacklen)
playbackLen = static_cast<int>(GetTotalSeconds(honorCutList));
int secsplayed = static_cast<int>(GetSecondsPlayed(honorCutList));
playbackLen = GetTotalSeconds(honorCutList);
std::chrono::seconds secsplayed = GetSecondsPlayed(honorCutList);

stillFrame = (secsplayed < 0);
playbackLen = std::max(playbackLen, 0);
secsplayed = std::min(playbackLen, std::max(secsplayed, 0));
int secsbehind = std::max((playbackLen - secsplayed), 0);
stillFrame = (secsplayed < 0s);
playbackLen = std::max(playbackLen, 0s);
secsplayed = std::clamp(secsplayed, 0s, playbackLen);
std::chrono::seconds secsbehind = std::max((playbackLen - secsplayed), 0s);

if (playbackLen > 0)
pos = static_cast<int>(1000.0F * (secsplayed / static_cast<float>(playbackLen)));
if (playbackLen > 0s)
pos = static_cast<int>(1000.0F * secsplayed.count() / playbackLen.count());

Info.values.insert(relPrefix + "secondsplayed", secsplayed);
Info.values.insert(relPrefix + "totalseconds", playbackLen);
Info.values.insert(relPrefix + "secondsplayed", secsplayed.count());
Info.values.insert(relPrefix + "totalseconds", playbackLen.count());
Info.values[relPrefix + "position"] = pos;

QString text1;
QString text2;
QString text3;
if (PaddedFields)
{
text1 = MythFormatTime(std::chrono::seconds(secsplayed), "HH:mm:ss");
text2 = MythFormatTime(std::chrono::seconds(playbackLen), "HH:mm:ss");
text3 = MythFormatTime(std::chrono::seconds(secsbehind), "HH:mm:ss");
text1 = MythFormatTime(secsplayed, "HH:mm:ss");
text2 = MythFormatTime(playbackLen, "HH:mm:ss");
text3 = MythFormatTime(secsbehind, "HH:mm:ss");
}
else
{
QString fmt = (playbackLen >= ONEHOURINSEC) ? "H:mm:ss" : "m:ss";
text1 = MythFormatTime(std::chrono::seconds(secsplayed), fmt);
text2 = MythFormatTime(std::chrono::seconds(playbackLen), fmt);

if (secsbehind >= ONEHOURINSEC)
text3 = MythFormatTime(std::chrono::seconds(secsbehind), "H:mm:ss");
else if (secsbehind >= ONEMININSEC)
text3 = MythFormatTime(std::chrono::seconds(secsbehind), "m:ss");
QString fmt = (playbackLen >= 1h) ? "H:mm:ss" : "m:ss";
text1 = MythFormatTime(secsplayed, fmt);
text2 = MythFormatTime(playbackLen, fmt);

if (secsbehind >= 1h)
text3 = MythFormatTime(secsbehind, "H:mm:ss");
else if (secsbehind >= 1min)
text3 = MythFormatTime(secsbehind, "m:ss");
else
text3 = tr("%n second(s)", "", secsbehind);
text3 = tr("%n second(s)", "", secsbehind.count());
}

QString desc = stillFrame ? tr("Still Frame") : tr("%1 of %2").arg(text1).arg(text2);
Expand All @@ -234,20 +234,16 @@ void MythPlayerOverlayUI::UpdateSliderInfo(osdInfo &Info, bool PaddedFields)
}
}

// GetSecondsPlayed() and GetTotalSeconds() internally calculate
// in terms of milliseconds and divide the result by 1000. This
// divisor can be passed in as an argument, e.g. pass divisor=1 to
// return the time in milliseconds.
int64_t MythPlayerOverlayUI::GetSecondsPlayed(bool HonorCutList, int Divisor)
std::chrono::milliseconds MythPlayerOverlayUI::GetMillisecondsPlayed(bool HonorCutList)
{
uint64_t pos = TranslatePositionFrameToMs(m_framesPlayed, HonorCutList);
LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("GetSecondsPlayed: framesPlayed %1, honorCutList %2, divisor %3, pos %4")
.arg(m_framesPlayed).arg(HonorCutList).arg(Divisor).arg(pos));
return static_cast<int64_t>(TranslatePositionFrameToMs(m_framesPlayed, HonorCutList) / static_cast<uint64_t>(Divisor));
std::chrono::milliseconds pos = TranslatePositionFrameToMs(m_framesPlayed, HonorCutList);
LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("GetSecondsPlayed: framesPlayed %1, honorCutList %2, pos %3")
.arg(m_framesPlayed).arg(HonorCutList).arg(pos.count()));
return pos;
}

int64_t MythPlayerOverlayUI::GetTotalSeconds(bool HonorCutList, int Divisor) const
std::chrono::milliseconds MythPlayerOverlayUI::GetTotalMilliseconds(bool HonorCutList) const
{
uint64_t pos = IsWatchingInprogress() ? UINT64_MAX : m_totalFrames;
return static_cast<int64_t>(TranslatePositionFrameToMs(pos, HonorCutList) / static_cast<uint64_t>(Divisor));
return TranslatePositionFrameToMs(pos, HonorCutList);
}
8 changes: 6 additions & 2 deletions mythtv/libs/libmythtv/mythplayeroverlayui.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ class MTV_PUBLIC MythPlayerOverlayUI : public MythPlayerUIBase
void UpdateOSDPosition();

protected:
virtual int64_t GetSecondsPlayed(bool HonorCutList, int Divisor = 1000);
virtual int64_t GetTotalSeconds(bool HonorCutList, int Divisor = 1000) const;
virtual std::chrono::milliseconds GetMillisecondsPlayed(bool HonorCutList);
virtual std::chrono::milliseconds GetTotalMilliseconds(bool HonorCutList) const;
std::chrono::seconds GetSecondsPlayed(bool HonorCutList) {
return duration_cast<std::chrono::seconds>(GetMillisecondsPlayed(HonorCutList)); };
std::chrono::seconds GetTotalSeconds(bool HonorCutList) const {
return duration_cast<std::chrono::seconds>(GetTotalMilliseconds(HonorCutList)); };

OSD m_osd;
QMutex m_osdLock { QMutex::Recursive };
Expand Down
34 changes: 17 additions & 17 deletions mythtv/libs/libmythtv/mythplayerui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void MythPlayerUI::EventLoop()
if (m_isDummy && m_playerCtx->m_tvchain && m_playerCtx->m_tvchain->HasNext())
{
// Switch from the dummy recorder to the tuned program in livetv
m_playerCtx->m_tvchain->JumpToNext(true, 0);
m_playerCtx->m_tvchain->JumpToNext(true, 0s);
JumpToProgram();
}
else if ((!m_allPaused || GetEof() != kEofStateNone) &&
Expand Down Expand Up @@ -242,7 +242,7 @@ void MythPlayerUI::EventLoop()
if (m_playerCtx->m_tvchain && m_playerCtx->m_tvchain->HasNext())
{
LOG(VB_GENERAL, LOG_NOTICE, LOC + "LiveTV forcing JumpTo 1");
m_playerCtx->m_tvchain->JumpToNext(true, 0);
m_playerCtx->m_tvchain->JumpToNext(true, 0s);
return;
}

Expand Down Expand Up @@ -949,9 +949,9 @@ void MythPlayerUI::JumpToStream(const QString &stream)
}

m_watchingRecording = false;
m_totalLength = 0;
m_totalLength = 0s;
m_totalFrames = 0;
m_totalDuration = 0;
m_totalDuration = 0s;

// 120 retries ~= 60 seconds
if (OpenFile(120) < 0)
Expand All @@ -962,16 +962,16 @@ void MythPlayerUI::JumpToStream(const QString &stream)
return;
}

if (m_totalLength == 0)
if (m_totalLength == 0s)
{
long long len = m_playerCtx->m_buffer->GetRealFileSize();
m_totalLength = static_cast<int>(len / ((m_decoder->GetRawBitrate() * 1000) / 8));
m_totalFrames = static_cast<uint64_t>(m_totalLength * SafeFPS());
m_totalLength = std::chrono::seconds(len / ((m_decoder->GetRawBitrate() * 1000) / 8));
m_totalFrames = static_cast<uint64_t>(m_totalLength.count() * SafeFPS());
}

LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("JumpToStream length %1 bytes @ %2 Kbps = %3 Secs, %4 frames @ %5 fps")
.arg(m_playerCtx->m_buffer->GetRealFileSize()).arg(m_decoder->GetRawBitrate())
.arg(m_totalLength).arg(m_totalFrames).arg(m_decoder->GetFPS()) );
.arg(m_totalLength.count()).arg(m_totalFrames).arg(m_decoder->GetFPS()) );

SetEof(kEofStateNone);

Expand Down Expand Up @@ -1109,7 +1109,7 @@ void MythPlayerUI::JumpToProgram()
bool discontinuity = false;
bool newtype = false;
int newid = -1;
long long nextpos = m_playerCtx->m_tvchain->GetJumpPos();
std::chrono::seconds nextpos = m_playerCtx->m_tvchain->GetJumpPos();
ProgramInfo *pginfo = m_playerCtx->m_tvchain->GetSwitchProgram(discontinuity, newtype, newid);
if (!pginfo)
return;
Expand Down Expand Up @@ -1202,26 +1202,26 @@ void MythPlayerUI::JumpToProgram()
// check that we aren't too close to the end of program.
// and if so set it to 10s from the end if completed recordings
// or 3s if live
long long duration = m_playerCtx->m_tvchain->GetLengthAtCurPos();
int maxpos = m_playerCtx->m_tvchain->HasNext() ? 10 : 3;
std::chrono::seconds duration = m_playerCtx->m_tvchain->GetLengthAtCurPos();
std::chrono::seconds maxpos = m_playerCtx->m_tvchain->HasNext() ? 10s : 3s;

if (nextpos > (duration - maxpos))
{
nextpos = duration - maxpos;
if (nextpos < 0)
nextpos = 0;
if (nextpos < 0s)
nextpos = 0s;
}
else if (nextpos < 0)
else if (nextpos < 0s)
{
// it's a relative position to the end
nextpos += duration;
}

// nextpos is the new position to use in seconds
nextpos = static_cast<int64_t>(TranslatePositionMsToFrame(static_cast<uint64_t>(nextpos) * 1000, true));
uint64_t nextframe = TranslatePositionMsToFrame(nextpos, true);

if (nextpos > 10)
DoJumpToFrame(static_cast<uint64_t>(nextpos), kInaccuracyNone);
if (nextpos > 10s)
DoJumpToFrame(nextframe, kInaccuracyNone);

m_playerCtx->SetPlayerChangingBuffers(false);
LOG(VB_PLAYBACK, LOG_INFO, LOC + "JumpToProgram - end");
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/playercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,9 @@ void PlayerContext::SetPlayingInfo(const ProgramInfo *info)

void PlayerContext::SetPlayGroup(const QString &group)
{
m_fftime = PlayGroup::GetSetting(group, "skipahead", 30);
m_rewtime = PlayGroup::GetSetting(group, "skipback", 5);
m_jumptime = PlayGroup::GetSetting(group, "jump", 10);
m_fftime = PlayGroup::GetDurSetting<std::chrono::seconds>(group, "skipahead", 30s);
m_rewtime = PlayGroup::GetDurSetting<std::chrono::seconds>(group, "skipback", 5s);
m_jumptime = PlayGroup::GetDurSetting<std::chrono::minutes>(group, "jump", 10min);
m_tsNormal = PlayGroup::GetSetting(group, "timestretch", 100) * 0.01F;
m_tsAlt = (m_tsNormal == 1.0F) ? 1.5F : 1.0F;
}
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/playercontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class MTV_PUBLIC PlayerContext
LiveTVChain *m_tvchain {nullptr};
MythMediaBuffer *m_buffer {nullptr};
ProgramInfo *m_playingInfo {nullptr}; ///< Currently playing info
long long m_playingLen {0}; ///< Initial CalculateLength()
std::chrono::seconds m_playingLen {0s}; ///< Initial CalculateLength()
int m_lastCardid {-1}; ///< CardID of current/last recorder
/// 0 == normal, +1 == fast forward, -1 == rewind
int m_ffRewState {0};
Expand All @@ -133,9 +133,9 @@ class MTV_PUBLIC PlayerContext
ProgramInfo *m_pseudoLiveTVRec {nullptr};
PseudoState m_pseudoLiveTVState {kPseudoNormalLiveTV};

int m_fftime {0};
int m_rewtime {0};
int m_jumptime {0};
std::chrono::seconds m_fftime {0s};
std::chrono::seconds m_rewtime {0s};
std::chrono::minutes m_jumptime {0min};
/** \brief Time stretch speed, 1.0F for normal playback.
*
* Begins at 1.0F meaning normal playback, but can be increased
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/recorders/cetonrtsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ bool CetonRTSP::Setup(ushort clientPort1, ushort clientPort2,

if (params.contains("timeout"))
{
m_timeout = params["timeout"].toInt();
m_timeout = std::chrono::seconds(params["timeout"].toInt());
}

QString transport = readParameters("Transport", params);
Expand Down Expand Up @@ -472,10 +472,10 @@ void CetonRTSP::StartKeepAlive()
{
if (m_timer)
return;
int timeout = std::max(m_timeout - 5, 5);
auto timeout = std::max(m_timeout - 5s, 5s);
LOG(VB_RECORD, LOG_DEBUG, LOC +
QString("Start KeepAlive, every %1s").arg(timeout));
m_timer = startTimer(timeout * 1000);
QString("Start KeepAlive, every %1s").arg(timeout.count()));
m_timer = startTimer(timeout);
}

void CetonRTSP::StopKeepAlive()
Expand Down
4 changes: 3 additions & 1 deletion mythtv/libs/libmythtv/recorders/cetonrtsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <QUrl>
#include <QTimerEvent>

using namespace std::chrono_literals;

class QTcpSocket;
class QUdpSocket;

Expand Down Expand Up @@ -62,7 +64,7 @@ class CetonRTSP : QObject
QString m_responseMessage;
Params m_responseHeaders;
QByteArray m_responseContent;
int m_timeout {60};
std::chrono::seconds m_timeout {60s};
int m_timer {0};
bool m_canGetParameter {false};

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/channelbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ bool ChannelBase::CheckChannel(const QString &channum) const
ChannelBase *ChannelBase::CreateChannel(
TVRec *tvrec,
const GeneralDBOptions &genOpt,
DVBDBOptions dvbOpt,
const DVBDBOptions &dvbOpt,
const FireWireDBOptions &fwOpt,
const QString &startchannel,
bool enter_power_save_mode,
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/channelbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ChannelBase
static ChannelBase *CreateChannel(
TVRec *tvrec,
const GeneralDBOptions &genOpt,
DVBDBOptions dvbOpt,
const DVBDBOptions &dvbOpt,
const FireWireDBOptions &fwOpt,
const QString &startchannel,
bool enter_power_save_mode,
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/dtvrecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void DTVRecorder::FinishRecording(void)

if (m_curRecording)
{
SetDuration((int64_t)(m_totalDuration * 1000));
SetDuration(millisecondsFromFloat(m_totalDuration * 1000));
SetTotalFrames(m_framesWrittenCount);
}

Expand Down
14 changes: 8 additions & 6 deletions mythtv/libs/libmythtv/recorders/dvbchannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,10 +953,10 @@ bool DVBChannel::Tune(const DTVMultiplex &tuning,
}

// Extra delay to add for broken DVB drivers
if (m_tuningDelay)
std::this_thread::sleep_for(std::chrono::milliseconds(m_tuningDelay));
if (m_tuningDelay > 0ms)
std::this_thread::sleep_for(m_tuningDelay);

WaitForBackend(50); // msec
WaitForBackend(50ms);

m_prevTuning = tuning;
m_firstTune = false;
Expand Down Expand Up @@ -1561,7 +1561,7 @@ void DVBChannel::DrainDVBEvents(void)
}
}

/** \fn WaitForBackend(int)
/**
* \brief Waits for backend to get tune message.
*
* With linux 2.6.12 or later this should block
Expand All @@ -1583,10 +1583,12 @@ void DVBChannel::DrainDVBEvents(void)
*
* \param timeout_ms timeout before FE_READ_STATUS in milliseconds
*/
bool DVBChannel::WaitForBackend(int timeout_ms)
bool DVBChannel::WaitForBackend(std::chrono::milliseconds timeout_ms)
{
const int fd = m_fdFrontend;
struct timeval select_timeout = { timeout_ms/1000, (timeout_ms % 1000) * 1000 /*usec*/};
auto seconds = duration_cast<std::chrono::seconds>(timeout_ms);
auto usecs = duration_cast<std::chrono::microseconds>(timeout_ms) - seconds;
struct timeval select_timeout = { seconds.count(), usecs.count()};
fd_set fd_select_set;
FD_ZERO( &fd_select_set); // NOLINT(readability-isolate-declaration)
FD_SET (fd, &fd_select_set);
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/recorders/dvbchannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class DVBChannel : public DTVChannel
// Sets
void SetPMT(const ProgramMapTable *pmt);
void SetTimeOffset(double offset);
void SetSlowTuning(uint how_slow_in_ms)
{ m_tuningDelay = how_slow_in_ms; }
void SetSlowTuning(std::chrono::milliseconds how_slow)
{ m_tuningDelay = how_slow; }

// Gets
bool IsOpen(void) const override; // ChannelBase
Expand Down Expand Up @@ -127,7 +127,7 @@ class DVBChannel : public DTVChannel
double GetUncorrectedBlockCountDVBv5(bool *ok) const;

void DrainDVBEvents(void);
bool WaitForBackend(int timeout_ms);
bool WaitForBackend(std::chrono::milliseconds timeout_ms);

private:
IsOpenMap m_isOpen;
Expand Down Expand Up @@ -161,7 +161,7 @@ class DVBChannel : public DTVChannel

uint m_lastLnbDevId {(uint)~0x0};

uint m_tuningDelay {0}; // Extra delay to add for broken drivers
std::chrono::milliseconds m_tuningDelay { 0ms}; // Extra delay to add for broken drivers
std::chrono::milliseconds m_sigMonDelay {25ms}; // Minimum delay between FE_LOCK checks
bool m_firstTune {true}; // Used to force hardware reset

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/iptvstreamhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void IPTVStreamHandlerWriteHelper::SendRTCPReport(void)
}
int seq_delta = m_lastSequenceNumber - m_previousLastSequenceNumber;
RTCPDataPacket rtcp =
RTCPDataPacket(m_lastTimestamp, m_lastTimestamp + RTCP_TIMER * 1000,
RTCPDataPacket(m_lastTimestamp, m_lastTimestamp + RTCP_TIMER.count(),
m_lastSequenceNumber, m_lastSequenceNumber + seq_delta,
m_lost, m_lostInterval, m_parent->m_rtspSsrc);
QByteArray buf = rtcp.GetData();
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/recorders/iptvstreamhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "streamhandler.h"

#define IPTV_SOCKET_COUNT 3
#define RTCP_TIMER 10
static constexpr std::chrono::milliseconds RTCP_TIMER { 10s };

class IPTVStreamHandler;
class DTVSignalMonitor;
Expand Down Expand Up @@ -54,11 +54,11 @@ class IPTVStreamHandlerWriteHelper : QObject

void Start(void)
{
m_timer = startTimer(200);
m_timer = startTimer(200ms);
}
void StartRTCPRR(void)
{
m_timerRtcp = startTimer(RTCP_TIMER * 1000);
m_timerRtcp = startTimer(RTCP_TIMER);
}

void SendRTCPReport(void);
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/recorderbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ void RecorderBase::AudioCodecChange(AVCodecID aCodec)
}
}

void RecorderBase::SetDuration(uint64_t duration)
void RecorderBase::SetDuration(std::chrono::milliseconds duration)
{
if (m_curRecording)
m_curRecording->SaveTotalDuration(duration);
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 @@ -303,7 +303,7 @@ class MTV_PUBLIC RecorderBase : public QRunnable

/** \brief Note the total duration in the recordedmark table
*/
void SetDuration(uint64_t duration);
void SetDuration(std::chrono::milliseconds duration);

/** \brief Note the total frames in the recordedmark table
*/
Expand Down
15 changes: 9 additions & 6 deletions mythtv/libs/libmythtv/recorders/satiprtsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ bool SatIPRTSP::Setup(const QUrl& url)

QStringList parts = sessionTimeoutRegex.capturedTexts();
m_sessionid = parts.at(1);
m_timeout = (parts.length() > 1 ? parts.at(2).toInt() / 2 : 30) * 1000;
m_timeout = parts.length() > 1 ? std::chrono::seconds(parts.at(2).toInt() / 2) : 30s;

LOG(VB_RECORD, LOG_DEBUG, LOC + QString("Sat>IP protocol timeout:%1 ms").arg(m_timeout));
LOG(VB_RECORD, LOG_DEBUG, LOC + QString("Sat>IP protocol timeout:%1 ms")
.arg(m_timeout.count()));
}
else
{
Expand All @@ -159,7 +160,8 @@ bool SatIPRTSP::Setup(const QUrl& url)

LOG(VB_RECORD, LOG_DEBUG, LOC +
QString("Setup completed, sessionID = %1, streamID = %2, timeout = %3s")
.arg(m_sessionid).arg(m_streamid).arg(m_timeout / 1000));
.arg(m_sessionid).arg(m_streamid)
.arg(duration_cast<std::chrono::seconds>(m_timeout).count()));
emit startKeepAlive(m_timeout);

// Reset tuner lock status
Expand Down Expand Up @@ -377,12 +379,13 @@ bool SatIPRTSP::sendMessage(const QUrl& url, const QString& msg, QStringList *ad
return true;
}

void SatIPRTSP::startKeepAliveRequested(int timeout)
void SatIPRTSP::startKeepAliveRequested(std::chrono::milliseconds timeout)
{
if (m_timer)
return;
m_timer = startTimer(timeout);
LOG(VB_RECORD, LOG_INFO, LOC + QString("startKeepAliveRequested(%1) m_timer:%2").arg(timeout).arg(m_timer));
LOG(VB_RECORD, LOG_INFO, LOC + QString("startKeepAliveRequested(%1) m_timer:%2")
.arg(timeout.count()).arg(m_timer));
}

void SatIPRTSP::stopKeepAliveRequested()
Expand Down Expand Up @@ -532,7 +535,7 @@ SatIPRTSPWriteHelper::SatIPRTSPWriteHelper(SatIPRTSP* parent, SatIPStreamHandler
: m_parent(parent)
, m_streamHandler(handler)
{
m_timer = startTimer(100);
m_timer = startTimer(100ms);
}

void SatIPRTSPWriteHelper::timerEvent(QTimerEvent* /*event*/)
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/recorders/satiprtsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

// C++ includes
#include <cstdint>
#include <chrono>

// Qt includes
#include <QObject>
Expand All @@ -18,6 +17,7 @@
#include <QTime>

// MythTV includes
#include "mythchrono.h"
#include "packetbuffer.h"

class SatIPRTSP;
Expand Down Expand Up @@ -114,11 +114,11 @@ class SatIPRTSP : public QObject
void SetSigmonValues(bool lock, int level);

signals:
void startKeepAlive(int timeout);
void startKeepAlive(std::chrono::milliseconds timeout);
void stopKeepAlive(void);

protected slots:
void startKeepAliveRequested(int timeout);
void startKeepAliveRequested(std::chrono::milliseconds timeout);
void stopKeepAliveRequested(void);

protected:
Expand All @@ -137,7 +137,7 @@ class SatIPRTSP : public QObject
Headers m_headers;

int m_timer {0};
int m_timeout {0};
std::chrono::milliseconds m_timeout {0ms};

QMutex m_ctrlSocketLock;
QMutex m_sigmonLock;
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythtv/recordinginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,8 +1204,7 @@ void RecordingInfo::FinishedRecording(bool allowReRecord)

qint64 starttime = m_recStartTs.toSecsSinceEpoch();
qint64 endtime = m_recEndTs.toSecsSinceEpoch();
int64_t duration = (endtime - starttime) * 1000000;
SaveTotalDuration(duration);
SaveTotalDuration(std::chrono::seconds(endtime - starttime));

QString msg = "Finished recording";
QString msg_subtitle = m_subtitle.isEmpty() ? "" :
Expand Down
52 changes: 26 additions & 26 deletions mythtv/libs/libmythtv/tv_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ bool TV::CreatePlayer(TVState State, bool Muted)
else
player = new MythPlayerUI(m_mainWindow, this, &m_playerContext, flags);

player->SetLength(static_cast<int>(m_playerContext.m_playingLen));
player->SetLength(m_playerContext.m_playingLen);

bool isWatchingRecording = (State == kState_WatchingRecording);
player->SetWatchingRecording(isWatchingRecording);
Expand Down Expand Up @@ -1419,11 +1419,11 @@ void TV::GetStatus()
{
if (!info.text["totalchapters"].isEmpty())
{
QList<long long> chapters;
QList<std::chrono::seconds> chapters;
m_player->GetChapterTimes(chapters);
QVariantList var;
for (long long chapter : qAsConst(chapters))
var << QVariant(chapter);
for (std::chrono::seconds chapter : qAsConst(chapters))
var << QVariant((long long)chapter.count());
status.insert("chaptertimes", var);
}

Expand Down Expand Up @@ -5064,8 +5064,8 @@ void TV::DoSeek(float Time, const QString &Msg, bool TimeIsOffset, bool HonorCut
}
else
{
auto time = static_cast<uint64_t>(Time);
uint64_t desiredFrameRel = m_player->TranslatePositionMsToFrame(time * 1000, HonorCutlist);
auto time = duration_cast<std::chrono::milliseconds>(secondsFromFloat(Time));
uint64_t desiredFrameRel = m_player->TranslatePositionMsToFrame(time, HonorCutlist);
m_playerContext.UnlockDeletePlayer(__FILE__, __LINE__);
DoPlayerSeekToFrame(desiredFrameRel);
}
Expand Down Expand Up @@ -5350,7 +5350,7 @@ int TV::GetNumChapters()
return num_chapters;
}

void TV::GetChapterTimes(QList<long long> &Times)
void TV::GetChapterTimes(QList<std::chrono::seconds> &Times)
{
m_playerContext.LockDeletePlayer(__FILE__, __LINE__);
if (m_player)
Expand Down Expand Up @@ -6690,7 +6690,7 @@ void TV::ShowLCDDVDInfo()
int totalParts = dvd->NumPartsInTitle();

mainStatus = tr("Title: %1 (%2)").arg(playingTitle)
.arg(MythFormatTime(std::chrono::seconds(dvd->GetTotalTimeOfTitle()), "HH:mm"));
.arg(MythFormatTime(dvd->GetTotalTimeOfTitle(), "HH:mm"));
subStatus = tr("Chapter: %1/%2").arg(playingPart).arg(totalParts);
}
if ((dvdName != m_lcdCallsign) || (mainStatus != m_lcdTitle) || (subStatus != m_lcdSubtitle))
Expand Down Expand Up @@ -7332,13 +7332,13 @@ void TV::customEvent(QEvent *Event)
}
else if (message.startsWith("DONE_RECORDING"))
{
int seconds = 0;
std::chrono::seconds seconds = 0s;
//long long frames = 0;
int NUMTOKENS = 4; // Number of tokens expected
if (tokens.size() == NUMTOKENS)
{
cardnum = tokens[1].toUInt();
seconds = tokens[2].toInt();
seconds = std::chrono::seconds(tokens[2].toInt());
//frames = tokens[3].toLongLong();
}
else
Expand All @@ -7360,7 +7360,7 @@ void TV::customEvent(QEvent *Event)
if (m_player)
{
m_player->SetWatchingRecording(false);
if (seconds > 0)
if (seconds > 0s)
m_player->SetLength(seconds);
}
m_playerContext.UnlockDeletePlayer(__FILE__, __LINE__);
Expand All @@ -7378,7 +7378,7 @@ void TV::customEvent(QEvent *Event)
if (m_player)
{
m_player->SetWatchingRecording(false);
if (seconds > 0)
if (seconds > 0s)
m_player->SetLength(seconds);
}
m_playerContext.UnlockDeletePlayer(__FILE__, __LINE__);
Expand Down Expand Up @@ -8744,7 +8744,7 @@ bool TV::MenuItemDisplayPlayback(const MythTVMenuItemContext& Context, MythOSDDi
{
QString chapter1 = QString("%1").arg(i+1, size, 10, QChar(48));
QString chapter2 = QString("%1").arg(i+1, 3 , 10, QChar(48));
QString timestr = MythFormatTime(std::chrono::seconds(m_tvmChapterTimes[i]), "HH:mm:ss");
QString timestr = MythFormatTime(m_tvmChapterTimes[i], "HH:mm:ss");
QString desc = chapter1 + QString(" (%1)").arg(timestr);
QString action = prefix + chapter2;
active = (m_tvmCurrentChapter == (i + 1));
Expand Down Expand Up @@ -9686,7 +9686,7 @@ void TV::UnpauseLiveTV(bool Quietly)
if (m_playerContext.HasPlayer() && m_playerContext.m_tvchain)
{
m_playerContext.ReloadTVChain();
m_playerContext.m_tvchain->JumpTo(-1, 1);
m_playerContext.m_tvchain->JumpTo(-1, 1s);
m_playerContext.LockDeletePlayer(__FILE__, __LINE__);
if (m_player)
m_player->Play(m_playerContext.m_tsNormal, true, false);
Expand Down Expand Up @@ -9735,7 +9735,7 @@ void TV::DoJumpFFWD()
else if (GetNumChapters() > 0)
DoJumpChapter(9999);
else
DoSeek(m_playerContext.m_jumptime * 60, tr("Jump Ahead"), /*timeIsOffset*/true, /*honorCutlist*/true);
DoSeek(m_playerContext.m_jumptime, tr("Jump Ahead"), /*timeIsOffset*/true, /*honorCutlist*/true);
}

void TV::DoSeekFFWD()
Expand All @@ -9750,7 +9750,7 @@ void TV::DoJumpRWND()
else if (GetNumChapters() > 0)
DoJumpChapter(-1);
else
DoSeek(-m_playerContext.m_jumptime * 60, tr("Jump Back"), /*timeIsOffset*/true, /*honorCutlist*/true);
DoSeek(-m_playerContext.m_jumptime, tr("Jump Back"), /*timeIsOffset*/true, /*honorCutlist*/true);
}

void TV::DoSeekRWND()
Expand All @@ -9777,11 +9777,11 @@ void TV::DVDJumpBack()
}
else
{
uint titleLength = dvd->GetTotalTimeOfTitle();
uint chapterLength = dvd->GetChapterLength();
if ((titleLength == chapterLength) && chapterLength > 300)
std::chrono::seconds titleLength = dvd->GetTotalTimeOfTitle();
std::chrono::seconds chapterLength = dvd->GetChapterLength();
if ((titleLength == chapterLength) && chapterLength > 5min)
{
DoSeek(-m_playerContext.m_jumptime * 60, tr("Jump Back"), /*timeIsOffset*/true, /*honorCutlist*/true);
DoSeek(-m_playerContext.m_jumptime, tr("Jump Back"), /*timeIsOffset*/true, /*honorCutlist*/true);
}
else
{
Expand Down Expand Up @@ -9817,13 +9817,13 @@ void TV::DVDJumpForward()
}
else if (!in_still && !in_menu)
{
uint titleLength = dvd->GetTotalTimeOfTitle();
uint chapterLength = dvd->GetChapterLength();
uint currentTime = static_cast<uint>(dvd->GetCurrentTime());
if ((titleLength == chapterLength) && chapterLength > 300 &&
(currentTime < (chapterLength - (static_cast<uint>(m_playerContext.m_jumptime) * 60))))
std::chrono::seconds titleLength = dvd->GetTotalTimeOfTitle();
std::chrono::seconds chapterLength = dvd->GetChapterLength();
std::chrono::seconds currentTime = dvd->GetCurrentTime();
if ((titleLength == chapterLength) && (chapterLength > 5min) &&
(currentTime < (chapterLength - (duration_cast<std::chrono::seconds>(m_playerContext.m_jumptime)))))
{
DoSeek(m_playerContext.m_jumptime * 60, tr("Jump Ahead"), /*timeIsOffset*/true, /*honorCutlist*/true);
DoSeek(m_playerContext.m_jumptime, tr("Jump Ahead"), /*timeIsOffset*/true, /*honorCutlist*/true);
}
else
{
Expand Down
6 changes: 4 additions & 2 deletions mythtv/libs/libmythtv/tv_play.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ class MTV_PUBLIC TV : public TVPlaybackState, public MythTVMenuItemDisplayer, pu

// Seek, skip, jump, speed
void DoSeek(float Time, const QString &Msg, bool TimeIsOffset, bool HonorCutlist);
void DoSeek(std::chrono::seconds Time, const QString &Msg, bool TimeIsOffset, bool HonorCutlist) {
DoSeek(Time.count(), Msg, TimeIsOffset, HonorCutlist); };
bool DoPlayerSeek(float Time);
bool DoPlayerSeekToFrame(uint64_t FrameNum);
enum ArbSeekWhence { ARBSEEK_SET = 0, ARBSEEK_REWIND, ARBSEEK_FORWARD, ARBSEEK_END };
Expand All @@ -382,7 +384,7 @@ class MTV_PUBLIC TV : public TVPlaybackState, public MythTVMenuItemDisplayer, pu

// Chapters, titles and angles
int GetNumChapters();
void GetChapterTimes(QList<long long> &Times);
void GetChapterTimes(QList<std::chrono::seconds> &Times);
int GetCurrentChapter();
int GetNumTitles();
int GetCurrentTitle();
Expand Down Expand Up @@ -712,7 +714,7 @@ class MTV_PUBLIC TV : public TVPlaybackState, public MythTVMenuItemDisplayer, pu
// Navigate
int m_tvmNumChapters {0};
int m_tvmCurrentChapter {0};
QList<long long> m_tvmChapterTimes;
QList<std::chrono::seconds> m_tvmChapterTimes;
int m_tvmNumAngles {0};
int m_tvmCurrentAngle {0};
int m_tvmNumTitles {0};
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/tv_rec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@ bool TVRec::GetDevices(uint inputid,
// DVB options
uint dvboff = 9;
dvb_opts.m_dvbOnDemand = query.value(dvboff + 0).toBool();
dvb_opts.m_dvbTuningDelay = query.value(dvboff + 1).toUInt();
dvb_opts.m_dvbTuningDelay = std::chrono::milliseconds(query.value(dvboff + 1).toUInt());
dvb_opts.m_dvbEitScan = query.value(dvboff + 2).toBool();

// Firewire options
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/tv_rec.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class DVBDBOptions
DVBDBOptions() = default;

bool m_dvbOnDemand {false};
uint m_dvbTuningDelay {0};
std::chrono::milliseconds m_dvbTuningDelay {0ms};
bool m_dvbEitScan {true};
};

Expand Down
12 changes: 6 additions & 6 deletions mythtv/libs/libmythupnp/upnphelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace UPnPDateTime
{

QString DurationFormat(uint32_t msec)
QString DurationFormat(std::chrono::milliseconds msec)
{
// Appendix D. Date&Time Syntax - UPnP ContentDirectory Service 2008, 2013
// duration ::= 'P' [n 'D'] time
Expand All @@ -19,11 +19,11 @@ QString DurationFormat(uint32_t msec)

QString durationStr = "P%1%2";
QString dayStr;
if ( msec > (1000 * 3600 * 24) )
if ( msec > 24h )
{
dayStr = QString("D%1").arg(msec % (1000 * 3600 * 24)); // 24 Hours
dayStr = QString("D%1").arg((msec % 24h).count());
}
QString timeStr = UPnPDateTime::TimeFormat(msec);
QString timeStr = UPnPDateTime::TimeFormat(msec.count());

return durationStr.arg(dayStr).arg(timeStr);
}
Expand Down Expand Up @@ -78,7 +78,7 @@ QString NamedDayFormat(const QDate date)
}
}

QString resDurationFormat(uint32_t msec)
QString resDurationFormat(std::chrono::milliseconds msec)
{
// Appendix B.2 Resource Encoding Characteristics Properties
// B.2.1.4 res@duration
Expand All @@ -88,7 +88,7 @@ QString resDurationFormat(uint32_t msec)
// M = Minutes (2 digits, 0 prefix)
// S = Seconds (2 digits, 0 prefix)
// FS = Fractional Seconds (milliseconds)
QTime time = QTime::fromMSecsSinceStartOfDay(msec);
QTime time = QTime::fromMSecsSinceStartOfDay(msec.count());
return time.toString("H:mm:ss:zzz");
}

Expand Down
7 changes: 5 additions & 2 deletions mythtv/libs/libmythupnp/upnphelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
#include <QTime>
#include <QSize>

#include <chrono>
#include <cstdint>

#include "upnpexp.h"
#include "compat.h"

using namespace std::chrono_literals;

// NOTE These are for formatting to the UPnP related specs or extracting data
// from UPnP formatted strings ONLY.
//
Expand Down Expand Up @@ -52,7 +55,7 @@ namespace UPnPDateTime
* res\@duration Format
* B.2.1.4 res\@duration - UPnP ContentDirectory Service 2008, 2013
*/
UPNP_PUBLIC QString resDurationFormat(uint32_t msec);
UPNP_PUBLIC QString resDurationFormat(std::chrono::milliseconds msec);

//-----------------------------------------------------------------------
// Appendix D. EBNF Syntax Definitions
Expand All @@ -65,7 +68,7 @@ namespace UPnPDateTime
* UPnP ContentDirectory Service 2008, 2013
* Appendix D.1 Date&Time Syntax
*/
UPNP_PUBLIC QString DurationFormat(uint32_t msec);
UPNP_PUBLIC QString DurationFormat(std::chrono::milliseconds msec);

/**
* Time Format
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythbackend/upnpcdsmusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ bool UPnpCDSMusic::LoadTracks(const UPnpCDSRequest *pRequest,
int nTrackNum = query.value( 6).toInt();
QString sDescription = query.value( 7).toString();
QString sFileName = query.value( 8).toString();
uint32_t nLengthMS = query.value( 9).toUInt();
auto nLengthMS = std::chrono::milliseconds(query.value( 9).toUInt());
uint64_t nFileSize = query.value(10).toULongLong();

int nPlaybackCount = query.value(11).toInt();
Expand Down
14 changes: 7 additions & 7 deletions mythtv/programs/mythbackend/upnpcdstv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ bool UPnpCDSTv::LoadRecordings(const UPnpCDSRequest* pRequest,

pItem->SetPropValue( "scheduledStartTime" , UPnPDateTime::DateTimeFormat(dtProgStart));
pItem->SetPropValue( "scheduledEndTime" , UPnPDateTime::DateTimeFormat(dtProgEnd));
int msecs = dtProgEnd.toMSecsSinceEpoch() - dtProgStart.toMSecsSinceEpoch();
auto msecs = std::chrono::milliseconds(dtProgEnd.toMSecsSinceEpoch() - dtProgStart.toMSecsSinceEpoch());
pItem->SetPropValue( "scheduledDuration" , UPnPDateTime::DurationFormat(msecs));
pItem->SetPropValue( "recordedStartDateTime", UPnPDateTime::DateTimeFormat(dtStartTime));
pItem->SetPropValue( "recordedDayOfWeek" , UPnPDateTime::NamedDayFormat(dtStartTime));
Expand Down Expand Up @@ -1187,7 +1187,7 @@ bool UPnpCDSTv::LoadRecordings(const UPnpCDSRequest* pRequest,
// if ( pRequest->m_eClient == CDS_ClientSonyDB )
// sMimeType = "video/avi";

uint32_t nDurationMS = 0;
std::chrono::milliseconds nDurationMS { 0ms };

// NOTE We intentionally don't use the chanid, recstarttime constructor
// to avoid an unnecessary db query. At least until the time that we're
Expand All @@ -1199,12 +1199,12 @@ bool UPnpCDSTv::LoadRecordings(const UPnpCDSRequest* pRequest,
nDurationMS = recInfo.QueryTotalDuration();
// Older recordings won't have their precise duration stored in
// recordedmarkup
if (nDurationMS == 0)
if (nDurationMS == 0ms)
{
qint64 uiStart = dtStartTime.toMSecsSinceEpoch();
qint64 uiEnd = dtEndTime.toMSecsSinceEpoch();
auto uiStart = std::chrono::milliseconds(dtStartTime.toMSecsSinceEpoch());
auto uiEnd = std::chrono::milliseconds(dtEndTime.toMSecsSinceEpoch());
nDurationMS = (uiEnd - uiStart);
nDurationMS = (nDurationMS > 0) ? nDurationMS : 0;
nDurationMS = std::max(0ms, nDurationMS);
}

pItem->SetPropValue( "recordedDuration", UPnPDateTime::DurationFormat(nDurationMS));
Expand Down Expand Up @@ -1264,7 +1264,7 @@ bool UPnpCDSTv::LoadRecordings(const UPnpCDSRequest* pRequest,
Resource *pRes = pItem->AddResource( sProtocol, resURI.toEncoded() );
// Must be the duration of the entire video not the scheduled programme duration
// Appendix B.2.1.4 - res@duration
if (nDurationMS > 0)
if (nDurationMS > 0ms)
pRes->AddAttribute ( "duration" , UPnPDateTime::resDurationFormat(nDurationMS) );
if (nVideoHeight > 0 && nVideoWidth > 0)
pRes->AddAttribute ( "resolution" , QString("%1x%2").arg(nVideoWidth).arg(nVideoHeight) );
Expand Down
4 changes: 1 addition & 3 deletions mythtv/programs/mythbackend/upnpcdsvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,7 @@ bool UPnpCDSVideo::LoadVideos(const UPnpCDSRequest* pRequest,
int nYear = query.value( 7).toInt();
// int nUserRating = query.value( 8).toInt();

uint32_t nLength = query.value( 9).toUInt();
// Convert from minutes to milliseconds
nLength = (nLength * 60 *1000);
auto nLength = std::chrono::minutes(query.value( 9).toUInt());

int nSeason = query.value(10).toInt();
int nEpisode = query.value(11).toInt();
Expand Down