7 changes: 4 additions & 3 deletions mythtv/libs/libmythtv/captions/subtitlereader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {
#include "libavcodec/avcodec.h"
}

#include "mythchrono.h"
#include "mythdeque.h"
#include "textsubtitleparser.h"

Expand All @@ -25,7 +26,7 @@ class RawTextSubs
RawTextSubs(void) = default;

QStringList m_buffers;
uint64_t m_duration {0};
std::chrono::milliseconds m_duration {0ms};
QMutex m_lock;
};

Expand Down Expand Up @@ -54,8 +55,8 @@ class SubtitleReader : public QObject
bool HasTextSubtitles(void);
void LoadExternalSubtitles(const QString &subtitleFileName, bool isInProgress);

QStringList GetRawTextSubtitles(uint64_t &duration);
void AddRawTextSubtitle(const QStringList& list, uint64_t duration);
QStringList GetRawTextSubtitles(std::chrono::milliseconds &duration);
void AddRawTextSubtitle(const QStringList& list, std::chrono::milliseconds duration);
void ClearRawTextSubtitles(void);

private:
Expand Down
77 changes: 40 additions & 37 deletions mythtv/libs/libmythtv/captions/subtitlescreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ class SubWrapper
{
protected:
SubWrapper(const MythRect &rect,
long long expireTime,
std::chrono::milliseconds expireTime,
int whichImageCache = -1) :
m_swOrigArea(rect),
m_swWhichImageCache(whichImageCache),
m_swExpireTime(expireTime)
{
}
public:
long long GetExpireTime(void) const { return m_swExpireTime; }
std::chrono::milliseconds GetExpireTime(void) const { return m_swExpireTime; }
MythRect GetOrigArea(void) const { return m_swOrigArea; }
int GetWhichImageCache(void) const { return m_swWhichImageCache; }
protected:
// Returns true if the object was deleted.
const MythRect m_swOrigArea;
const int m_swWhichImageCache; // cc708 only; -1 = none
const long long m_swExpireTime; // avsubs only; -1 = none
const std::chrono::milliseconds m_swExpireTime; // avsubs only; -1 = none
};

class SubSimpleText : public MythUISimpleText, public SubWrapper
Expand All @@ -48,7 +48,7 @@ class SubSimpleText : public MythUISimpleText, public SubWrapper
SubSimpleText(const QString &text, const MythFontProperties &font,
QRect rect, Qt::Alignment align,
MythUIType *parent, const QString &name,
int whichImageCache, long long expireTime) :
int whichImageCache, std::chrono::milliseconds expireTime) :
MythUISimpleText(text, font, rect, align, parent, name),
SubWrapper(MythRect(rect), expireTime, whichImageCache) {}
};
Expand All @@ -57,7 +57,7 @@ class SubShape : public MythUIShape, public SubWrapper
{
public:
SubShape(MythUIType *parent, const QString &name, const MythRect &area,
int whichImageCache, long long expireTime) :
int whichImageCache, std::chrono::milliseconds expireTime) :
MythUIShape(parent, name),
SubWrapper(area, expireTime, whichImageCache) {}
};
Expand All @@ -66,7 +66,7 @@ class SubImage : public MythUIImage, public SubWrapper
{
public:
SubImage(MythUIType *parent, const QString &name, const MythRect &area,
long long expireTime) :
std::chrono::milliseconds expireTime) :
MythUIImage(parent, name),
SubWrapper(area, expireTime) {}
MythImage *GetImage(void) { return m_images[0]; }
Expand Down Expand Up @@ -140,7 +140,8 @@ class SubtitleFormat
const CC708CharacterAttribute &attr,
const MythRect &area,
int whichImageCache,
int start, int duration);
std::chrono::milliseconds start,
std::chrono::milliseconds duration);
int GetBackgroundAlpha(const QString &family);
static QString MakePrefix(const QString &family,
const CC708CharacterAttribute &attr);
Expand Down Expand Up @@ -599,8 +600,8 @@ SubtitleFormat::GetBackground(MythUIType *parent, const QString &name,
const CC708CharacterAttribute &attr,
const MythRect &area,
int whichImageCache,
int start,
int duration)
std::chrono::milliseconds start,
std::chrono::milliseconds duration)
{
QString prefix = MakePrefix(family, attr);
if (!m_shapeMap.contains(prefix))
Expand Down Expand Up @@ -638,7 +639,7 @@ int SubtitleFormat::GetBackgroundAlpha(const QString &family)
// background alpha value from osd_subtitle.xml.
CC708CharacterAttribute attr(false, false, false, Qt::white);
SubShape *bgShape = GetBackground(nullptr, "dummyName", family, attr,
MythRect(), -1, 0, -1);
MythRect(), -1, 0ms, -1ms);
return bgShape->m_fillBrush.color().alpha();
}

Expand Down Expand Up @@ -1719,7 +1720,8 @@ void SubtitleScreen::Pulse(void)

MythVideoOutput *videoOut = m_player->GetVideoOutput();
MythVideoFrame *currentFrame = videoOut ? videoOut->GetLastShownFrame() : nullptr;
long long now = currentFrame ? currentFrame->m_timecode : LLONG_MAX;
std::chrono::milliseconds now =
currentFrame ? currentFrame->m_timecode : std::chrono::milliseconds::max();
bool needRescale = (m_textFontZoom != m_textFontZoomPrev);

for (it = m_childrenList.begin(); it != m_childrenList.end(); it = itNext)
Expand All @@ -1731,16 +1733,16 @@ void SubtitleScreen::Pulse(void)
continue;

// Expire the subtitle object if needed.
long long expireTime = wrapper->GetExpireTime();
if (expireTime > 0 && expireTime < now)
std::chrono::milliseconds expireTime = wrapper->GetExpireTime();
if (expireTime > 0ms && expireTime < now)
{
DeleteChild(child);
SetElementDeleted();
continue;
}

// Rescale the AV subtitle image if the zoom changed.
if (expireTime > 0 && needRescale)
if (expireTime > 0ms && needRescale)
{
auto *image = dynamic_cast<SubImage *>(child);
if (image)
Expand Down Expand Up @@ -1848,16 +1850,16 @@ void SubtitleScreen::DisplayAVSubtitles(void)
while (!subs->m_buffers.empty())
{
AVSubtitle subtitle = subs->m_buffers.front();
if (subtitle.start_display_time > currentFrame->m_timecode)
if (subtitle.start_display_time > currentFrame->m_timecode.count())
break;

long long displayfor = subtitle.end_display_time -
subtitle.start_display_time;
if (displayfor == 0)
displayfor = 60000;
displayfor = (displayfor < 50) ? 50 : displayfor;
long long late = currentFrame->m_timecode -
subtitle.start_display_time;
auto displayfor = std::chrono::milliseconds(subtitle.end_display_time -
subtitle.start_display_time);
if (displayfor == 0ms)
displayfor = 60s;
displayfor = (displayfor < 50ms) ? 50ms : displayfor;
std::chrono::milliseconds late = currentFrame->m_timecode -
std::chrono::milliseconds(subtitle.start_display_time);

ClearDisplayedSubtitles();
subs->m_buffers.pop_front();
Expand All @@ -1868,7 +1870,7 @@ void SubtitleScreen::DisplayAVSubtitles(void)
bool displaysub = true;
if (!subs->m_buffers.empty() &&
subs->m_buffers.front().end_display_time <
currentFrame->m_timecode)
currentFrame->m_timecode.count())
{
displaysub = false;
}
Expand Down Expand Up @@ -1906,7 +1908,7 @@ void SubtitleScreen::DisplayAVSubtitles(void)
// split into upper/lower to allow zooming
QRect bbox;
int uh = display.height() / 2 - rect->y;
long long displayuntil = currentFrame->m_timecode + displayfor;
std::chrono::milliseconds displayuntil = currentFrame->m_timecode + displayfor;
if (uh > 0)
{
bbox = QRect(0, 0, rect->w, uh);
Expand Down Expand Up @@ -1946,8 +1948,8 @@ int SubtitleScreen::DisplayScaledAVSubtitles(const AVSubtitleRect *rect,
QRect &bbox, bool top,
QRect &display, int forced,
const QString& imagename,
long long displayuntil,
long long late)
std::chrono::milliseconds displayuntil,
std::chrono::milliseconds late)
{
// split image vertically if it spans middle of display
// - split point is empty line nearest the middle
Expand Down Expand Up @@ -2094,9 +2096,9 @@ int SubtitleScreen::DisplayScaledAVSubtitles(const AVSubtitleRect *rect,
if (uiimage)
{
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Display %1AV sub until %2ms")
.arg(forced ? "FORCED " : "").arg(displayuntil));
if (late > 50)
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("AV Sub was %1ms late").arg(late));
.arg(forced ? "FORCED " : "").arg(displayuntil.count()));
if (late > 50ms)
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("AV Sub was %1ms late").arg(late.count()));
}

return (ysplit + 1);
Expand Down Expand Up @@ -2146,7 +2148,7 @@ void SubtitleScreen::DisplayTextSubtitles(void)
// playPos = (uint64_t)
// ((currentFrame->frameNumber / video_frame_rate) * 1000);
//else
auto tc_ms = std::chrono::milliseconds(currentFrame->m_timecode);
auto tc_ms = currentFrame->m_timecode;
playPos = m_player->GetDecoder()->NormalizeVideoTimecode(tc_ms).count();
}
playPos -= playPosAdj;
Expand Down Expand Up @@ -2175,15 +2177,15 @@ void SubtitleScreen::DisplayTextSubtitles(void)
}

subs->Unlock();
DrawTextSubtitles(rawsubs, 0, 0);
DrawTextSubtitles(rawsubs, 0ms, 0ms);
}

void SubtitleScreen::DisplayRawTextSubtitles(void)
{
if (!m_player || !m_subreader)
return;

uint64_t duration = 0;
std::chrono::milliseconds duration = 0ms;
QStringList subs = m_subreader->GetRawTextSubtitles(duration);
if (subs.empty())
return;
Expand All @@ -2205,7 +2207,8 @@ void SubtitleScreen::DisplayRawTextSubtitles(void)
}

void SubtitleScreen::DrawTextSubtitles(const QStringList &subs,
uint64_t start, uint64_t duration)
std::chrono::milliseconds start,
std::chrono::milliseconds duration)
{
auto *fsub = new FormattedTextSubtitleSRT(m_family, m_safeArea, start,
duration, this, subs);
Expand Down Expand Up @@ -2309,7 +2312,7 @@ void SubtitleScreen::AddScaledImage(QImage &img, QRect &pos)
if (image)
{
image->Assign(img);
MythUIImage *uiimage = new SubImage(this, "dvd_button", MythRect(scaled), 0);
MythUIImage *uiimage = new SubImage(this, "dvd_button", MythRect(scaled), 0ms);
if (uiimage)
{
uiimage->SetImage(image);
Expand Down Expand Up @@ -2485,7 +2488,7 @@ void SubtitleScreen::ResizeAssRenderer(void)
ass_set_font_scale(m_assRenderer, 1.0);
}

void SubtitleScreen::RenderAssTrack(uint64_t timecode)
void SubtitleScreen::RenderAssTrack(std::chrono::milliseconds timecode)
{
if (!m_player || !m_assRenderer || !m_assTrack)
return;
Expand All @@ -2500,7 +2503,7 @@ void SubtitleScreen::RenderAssTrack(uint64_t timecode)
ResizeAssRenderer();

int changed = 0;
ASS_Image *images = ass_render_frame(m_assRenderer, m_assTrack, timecode, &changed);
ASS_Image *images = ass_render_frame(m_assRenderer, m_assTrack, timecode.count(), &changed);
if (!changed)
return;

Expand Down Expand Up @@ -2555,7 +2558,7 @@ void SubtitleScreen::RenderAssTrack(uint64_t timecode)
{
image->Assign(qImage);
QString name = QString("asssub%1").arg(count);
uiimage = new SubImage(this, name, MythRect(img_rect), 0);
uiimage = new SubImage(this, name, MythRect(img_rect), 0ms);
if (uiimage)
{
uiimage->SetImage(image);
Expand Down
24 changes: 13 additions & 11 deletions mythtv/libs/libmythtv/captions/subtitlescreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class FormattedTextSubtitle
{
protected:
FormattedTextSubtitle(QString base, QRect safearea,
uint64_t start, uint64_t duration,
std::chrono::milliseconds start,
std::chrono::milliseconds duration,
SubtitleScreen *p) :
m_base(std::move(base)), m_safeArea(safearea),
m_start(start), m_duration(duration), m_subScreen(p) {}
Expand All @@ -96,8 +97,8 @@ class FormattedTextSubtitle
QString m_base;
QVector<FormattedTextLine> m_lines;
const QRect m_safeArea;
uint64_t m_start {0};
uint64_t m_duration {0};
std::chrono::milliseconds m_start {0ms};
std::chrono::milliseconds m_duration {0ms};
SubtitleScreen *m_subScreen {nullptr}; // where fonts and sizes are kept
int m_xAnchorPoint {0}; // 0=left, 1=center, 2=right
int m_yAnchorPoint {0}; // 0=top, 1=center, 2=bottom
Expand All @@ -111,8 +112,8 @@ class FormattedTextSubtitleSRT : public FormattedTextSubtitle
public:
FormattedTextSubtitleSRT(const QString &base,
QRect safearea,
uint64_t start,
uint64_t duration,
std::chrono::milliseconds start,
std::chrono::milliseconds duration,
SubtitleScreen *p,
const QStringList &subs) :
FormattedTextSubtitle(base, safearea, start, duration, p)
Expand All @@ -131,7 +132,7 @@ class FormattedTextSubtitle608 : public FormattedTextSubtitle
const QString &base = "",
QRect safearea = QRect(),
SubtitleScreen *p = nullptr) :
FormattedTextSubtitle(base, safearea, 0, 0, p)
FormattedTextSubtitle(base, safearea, 0ms, 0ms, p)
{
Init(buffers);
}
Expand All @@ -150,7 +151,7 @@ class FormattedTextSubtitle708 : public FormattedTextSubtitle
QRect safearea = QRect(),
SubtitleScreen *p = nullptr,
float aspect = 1.77777F) :
FormattedTextSubtitle(base, safearea, 0, 0, p),
FormattedTextSubtitle(base, safearea, 0ms, 0ms, p),
m_num(num),
m_bgFillAlpha(win.GetFillAlpha()),
m_bgFillColor(win.GetFillColor())
Expand Down Expand Up @@ -221,11 +222,12 @@ class SubtitleScreen : public MythScreenType
int DisplayScaledAVSubtitles(const AVSubtitleRect *rect, QRect &bbox,
bool top, QRect &display, int forced,
const QString& imagename,
long long displayuntil, long long late);
std::chrono::milliseconds displayuntil,
std::chrono::milliseconds late);
void DisplayTextSubtitles(void);
void DisplayRawTextSubtitles(void);
void DrawTextSubtitles(const QStringList &subs, uint64_t start,
uint64_t duration);
void DrawTextSubtitles(const QStringList &subs, std::chrono::milliseconds start,
std::chrono::milliseconds duration);
void DisplayCC608Subtitles(void);
void DisplayCC708Subtitles(void);
void AddScaledImage(QImage &img, QRect &pos);
Expand Down Expand Up @@ -263,7 +265,7 @@ class SubtitleScreen : public MythScreenType
void CleanupAssTrack(void);
void AddAssEvent(char *event);
void ResizeAssRenderer(void);
void RenderAssTrack(uint64_t timecode);
void RenderAssTrack(std::chrono::milliseconds timecode);

ASS_Library *m_assLibrary {nullptr};
ASS_Renderer *m_assRenderer {nullptr};
Expand Down
12 changes: 6 additions & 6 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2897,11 +2897,11 @@ void AvFormatDecoder::DecodeCCx08(const uint8_t *buf, uint buf_size, bool scte)
field = 1;

// flush decoder
m_ccd608->FormatCC(0, -1, -1);
m_ccd608->FormatCC(0ms, -1, -1);
}

had_608 = true;
m_ccd608->FormatCCField(m_lastCcPtsu / 1000, field, data);
m_ccd608->FormatCCField(std::chrono::milliseconds(m_lastCcPtsu/1000), field, data);

m_lastScteField = field;
}
Expand Down Expand Up @@ -3752,7 +3752,7 @@ bool AvFormatDecoder::ProcessVideoFrame(AVStream *Stream, AVFrame *AvFrame)
// Retrieve HDR metadata
MythHDRMetadata::Populate(frame, AvFrame);

m_parent->ReleaseNextVideoFrame(frame, temppts);
m_parent->ReleaseNextVideoFrame(frame, std::chrono::milliseconds(temppts));
m_mythCodecCtx->PostProcessFrame(context, frame);

m_nextDecodedFrameIsKeyFrame = false;
Expand Down Expand Up @@ -3838,7 +3838,7 @@ void AvFormatDecoder::ProcessVBIDataPacket(
{
int data = (buf[2] << 8) | buf[1];
if (cc608_good_parity(m_cc608ParityTable, data))
m_ccd608->FormatCCField(utc/1000, field, data);
m_ccd608->FormatCCField(std::chrono::milliseconds(utc/1000), field, data);
utc += 33367;
}
break;
Expand Down Expand Up @@ -4031,7 +4031,7 @@ bool AvFormatDecoder::ProcessRawTextPacket(AVPacket* Packet)
#else
auto list = text.split('\n', Qt::SkipEmptyParts);
#endif
m_parent->GetSubReader(id)->AddRawTextSubtitle(list, static_cast<uint64_t>(Packet->duration));
m_parent->GetSubReader(id)->AddRawTextSubtitle(list, std::chrono::milliseconds(Packet->duration));
return true;
}

Expand Down Expand Up @@ -5143,7 +5143,7 @@ bool AvFormatDecoder::GenerateDummyVideoFrames(void)
frame->m_frameNumber = m_framesPlayed;
frame->m_frameCounter = m_frameCounter++;

m_parent->ReleaseNextVideoFrame(frame, m_lastVPts);
m_parent->ReleaseNextVideoFrame(frame, std::chrono::milliseconds(m_lastVPts));
m_parent->DeLimboFrame(frame);

m_decodedVideoFrame = frame;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/decoders/avformatdecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class AvFormatDecoder : public DecoderBase

/// This is a No-op for this class.
void WriteStoredData(MythMediaBuffer *Buffer, bool storevid,
long timecodeOffset) override // DecoderBase
std::chrono::milliseconds timecodeOffset) override // DecoderBase
{ (void)Buffer; (void)storevid; (void)timecodeOffset;}

/// This is a No-op for this class.
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/decoders/decoderbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class DecoderBase

virtual bool IsLastFrameKey(void) const = 0;
virtual void WriteStoredData(MythMediaBuffer *Buffer, bool storevid,
long timecodeOffset) = 0;
std::chrono::milliseconds timecodeOffset) = 0;
virtual void ClearStoredData(void) { }
virtual void SetRawAudioState(bool state) { m_getRawFrames = state; }
virtual bool GetRawAudioState(void) const { return m_getRawFrames; }
Expand Down
3 changes: 2 additions & 1 deletion mythtv/libs/libmythtv/dummydecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class DummyDecoder : public DecoderBase
bool GetFrame(DecodeType /*Type*/, bool &/*Retry*/) override
{ usleep(10000); return false; }
bool IsLastFrameKey(void) const override { return true; }
void WriteStoredData(MythMediaBuffer* /*Buffer*/, bool /*storevid*/, long /*timecodeOffset*/) override {}
void WriteStoredData(MythMediaBuffer* /*Buffer*/, bool /*storevid*/,
std::chrono::milliseconds /*timecodeOffset*/) override {}
long UpdateStoredFrameNum(long /*frame*/) override { return 0; }
QString GetCodecDecoderName(void) const override { return "dummy"; }
MythCodecID GetVideoCodecID(void) const override { return kCodec_NONE; }
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ struct kfatable_entry
struct vidbuffertype
{
int sample;
int timecode;
std::chrono::milliseconds timecode;
int freeToEncode;
int freeToBuffer;
unsigned char *buffer;
Expand All @@ -154,15 +154,15 @@ struct vidbuffertype
struct audbuffertype
{
int sample;
int timecode;
std::chrono::milliseconds timecode;
int freeToEncode;
int freeToBuffer;
unsigned char *buffer;
};

struct txtbuffertype
{
int timecode;
std::chrono::milliseconds timecode;
int pagenr;
int freeToEncode;
int freeToBuffer;
Expand Down
22 changes: 11 additions & 11 deletions mythtv/libs/libmythtv/io/mythavformatwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ int MythAVFormatWriter::WriteVideoFrame(MythVideoFrame *Frame)
if (!got_pkt)
return ret;

long long tc = Frame->m_timecode;
std::chrono::milliseconds tc = Frame->m_timecode;

if (!m_bufferedVideoFrameTimes.isEmpty())
tc = m_bufferedVideoFrameTimes.takeFirst();
Expand All @@ -238,11 +238,11 @@ int MythAVFormatWriter::WriteVideoFrame(MythVideoFrame *Frame)
pkt.flags |= AV_PKT_FLAG_KEY;
}

if (m_startingTimecodeOffset == -1)
m_startingTimecodeOffset = tc - 1;
if (m_startingTimecodeOffset == -1ms)
m_startingTimecodeOffset = tc - 1ms;
tc -= m_startingTimecodeOffset;

pkt.pts = tc * m_videoStream->time_base.den / m_videoStream->time_base.num / 1000;
pkt.pts = tc.count() * m_videoStream->time_base.den / m_videoStream->time_base.num / 1000;
pkt.dts = AV_NOPTS_VALUE;
pkt.stream_index= m_videoStream->index;

Expand All @@ -267,7 +267,7 @@ static void bswap_16_buf(short int *buf, int buf_cnt, int audio_channels)
}
#endif

int MythAVFormatWriter::WriteAudioFrame(unsigned char *Buffer, int /*FrameNumber*/, long long &Timecode)
int MythAVFormatWriter::WriteAudioFrame(unsigned char *Buffer, int /*FrameNumber*/, std::chrono::milliseconds &Timecode)
{
#if HAVE_BIGENDIAN
bswap_16_buf((short int*) buf, m_audioFrameSize, m_audioChannels);
Expand Down Expand Up @@ -338,19 +338,19 @@ int MythAVFormatWriter::WriteAudioFrame(unsigned char *Buffer, int /*FrameNumber
if (!got_packet)
return ret;

long long tc = Timecode;
std::chrono::milliseconds tc = Timecode;

if (!m_bufferedAudioFrameTimes.empty())
tc = m_bufferedAudioFrameTimes.takeFirst();

if (m_startingTimecodeOffset == -1)
m_startingTimecodeOffset = tc - 1;
if (m_startingTimecodeOffset == -1ms)
m_startingTimecodeOffset = tc - 1ms;
tc -= m_startingTimecodeOffset;

if (m_avVideoCodec)
pkt.pts = tc * m_videoStream->time_base.den / m_videoStream->time_base.num / 1000;
pkt.pts = tc.count() * m_videoStream->time_base.den / m_videoStream->time_base.num / 1000;
else
pkt.pts = tc * m_audioStream->time_base.den / m_audioStream->time_base.num / 1000;
pkt.pts = tc.count() * m_audioStream->time_base.den / m_audioStream->time_base.num / 1000;

pkt.dts = AV_NOPTS_VALUE;
pkt.flags |= AV_PKT_FLAG_KEY;
Expand All @@ -366,7 +366,7 @@ int MythAVFormatWriter::WriteAudioFrame(unsigned char *Buffer, int /*FrameNumber
}

int MythAVFormatWriter::WriteTextFrame(int /*VBIMode*/, unsigned char* /*Buffer*/, int /*Length*/,
long long /*Timecode*/, int /*PageNumber*/)
std::chrono::milliseconds /*Timecode*/, int /*PageNumber*/)
{
return 1;
}
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/io/mythavformatwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class MTV_PUBLIC MythAVFormatWriter : public MythMediaWriter
bool OpenFile (void) override;
bool CloseFile (void) override;
int WriteVideoFrame (MythVideoFrame *Frame) override;
int WriteAudioFrame (unsigned char *Buffer, int FrameNumber, long long &Timecode) override;
int WriteAudioFrame (unsigned char *Buffer, int FrameNumber, std::chrono::milliseconds &Timecode) override;
int WriteTextFrame (int VBIMode, unsigned char *Buffer, int Length,
long long Timecode, int PageNumber) override;
std::chrono::milliseconds Timecode, int PageNumber) override;
int WriteSeekTable (void) override;
bool SwitchToNextFile (void) override;

Expand Down Expand Up @@ -58,9 +58,9 @@ class MTV_PUBLIC MythAVFormatWriter : public MythMediaWriter
AVFrame *m_audPicture { nullptr };
unsigned char *m_audioInBuf { nullptr };
unsigned char *m_audioInPBuf { nullptr };
QList<long long> m_bufferedVideoFrameTimes;
QList<std::chrono::milliseconds> m_bufferedVideoFrameTimes;
QList<int> m_bufferedVideoFrameTypes;
QList<long long> m_bufferedAudioFrameTimes;
QList<std::chrono::milliseconds> m_bufferedAudioFrameTimes;
};

#endif
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/io/mythmediawriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void MythMediaWriter::SetThreadCount(int Count)
m_encodingThreadCount = Count;
}

void MythMediaWriter::SetTimecodeOffset(long long Offset)
void MythMediaWriter::SetTimecodeOffset(std::chrono::milliseconds Offset)
{
m_startingTimecodeOffset = Offset;
}
Expand All @@ -116,7 +116,7 @@ long long MythMediaWriter::GetFramesWritten(void) const
return m_framesWritten;
}

long long MythMediaWriter::GetTimecodeOffset(void) const
std::chrono::milliseconds MythMediaWriter::GetTimecodeOffset(void) const
{
return m_startingTimecodeOffset;
}
Expand Down
11 changes: 6 additions & 5 deletions mythtv/libs/libmythtv/io/mythmediawriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class MTV_PUBLIC MythMediaWriter
virtual bool OpenFile (void) = 0;
virtual bool CloseFile (void) = 0;
virtual int WriteVideoFrame (MythVideoFrame *Frame) = 0;
virtual int WriteAudioFrame (unsigned char *Buffer, int FrameNumber, long long &Timecode) = 0;
virtual int WriteAudioFrame (unsigned char *Buffer, int FrameNumber,
std::chrono::milliseconds &Timecode) = 0;
virtual int WriteTextFrame (int VBIMode, unsigned char *Buffer, int Length,
long long Timecode, int PageNumber) = 0;
std::chrono::milliseconds Timecode, int PageNumber) = 0;
virtual int WriteSeekTable (void) = 0;
virtual bool SwitchToNextFile (void) = 0;

Expand All @@ -39,11 +40,11 @@ class MTV_PUBLIC MythMediaWriter
void SetAudioFrameRate (int Rate);
void SetAudioFormat (AudioFormat Format);
void SetThreadCount (int Count);
void SetTimecodeOffset (long long Offset);
void SetTimecodeOffset (std::chrono::milliseconds Offset);
void SetEncodingPreset (const QString& Preset);
void SetEncodingTune (const QString& Tune);
long long GetFramesWritten (void) const;
long long GetTimecodeOffset (void) const;
std::chrono::milliseconds GetTimecodeOffset (void) const;
int GetAudioFrameSize (void) const; // Number of audio samples (per channel) in an AVFrame

protected:
Expand All @@ -64,7 +65,7 @@ class MTV_PUBLIC MythMediaWriter
int m_audioFrameSize { -1 };
int m_encodingThreadCount { 1 };
long long m_framesWritten { 0 };
long long m_startingTimecodeOffset { -1 };
std::chrono::milliseconds m_startingTimecodeOffset { -1ms };
QString m_encodingPreset;
QString m_encodingTune;
};
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 @@ -84,7 +84,7 @@ void MythCCExtractorPlayer::OnGotNewFrame(void)
if (fps <= 0)
fps = GetDecoder()->GetFPS();
double duration = 1 / fps + static_cast<double>(frame->m_repeatPic) * 0.5 / fps;
m_curTime += std::chrono::seconds(static_cast<int64_t>(duration));
m_curTime += secondsFromFloat(duration);
m_videoOutput->DoneDisplayingFrame(frame);
}

Expand Down Expand Up @@ -630,14 +630,14 @@ void MythCCExtractorPlayer::IngestDVBSubtitles(void)
"There are unhandled text dvb subtitles");
}

uint64_t duration = 0;
std::chrono::milliseconds duration = 0ms;
const QStringList rawSubs =
(*subit).m_reader->GetRawTextSubtitles(duration);
if (!rawSubs.isEmpty())
{
LOG(VB_VBI, LOG_DEBUG,
QString("There are also %1 raw text subtitles with duration %2")
.arg(rawSubs.size()).arg(duration));
.arg(rawSubs.size()).arg(duration.count()));
}
/// INFO -- end

Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/mythdeinterlacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void MythDeinterlacer::Filter(MythVideoFrame *Frame, FrameScanType Scan,
m_frame->width = Frame->m_width;
m_frame->height = Frame->m_height;
m_frame->format = Frame->m_pixFmt;
m_frame->pts = Frame->m_timecode;
m_frame->pts = Frame->m_timecode.count();

auto AddFrame = [](AVFilterContext* Source, AVFrame* AvFrame)
{ return av_buffersrc_add_frame(Source, AvFrame); };
Expand Down Expand Up @@ -264,7 +264,7 @@ void MythDeinterlacer::Filter(MythVideoFrame *Frame, FrameScanType Scan,
MythVideoFrame::GetHeightForPlane(m_inputType, m_frame->height, plane));
}

Frame->m_timecode = m_frame->pts;
Frame->m_timecode = std::chrono::milliseconds(m_frame->pts);
Frame->m_alreadyDeinterlaced = true;

// Free frame data
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/mythframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void MythVideoFrame::ClearMetadata()
m_frameRate = -1.0 ;
m_frameNumber = 0;
m_frameCounter = 0;
m_timecode = 0;
m_timecode = 0ms;
m_displayTimecode = 0ms;
m_priv = { nullptr };
m_interlaced = 0;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/mythframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MTV_PUBLIC MythVideoFrame
double m_frameRate { -1.0 };
long long m_frameNumber { 0 };
uint64_t m_frameCounter { 0 };
long long m_timecode { 0 };
std::chrono::milliseconds m_timecode { 0ms };
std::chrono::milliseconds m_displayTimecode { 0ms };
std::array<uint8_t*,4> m_priv { nullptr };
int m_interlaced { 0 };
Expand Down
10 changes: 5 additions & 5 deletions mythtv/libs/libmythtv/mythplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ MythVideoFrame *MythPlayer::GetNextVideoFrame(void)
* \brief Places frame on the queue of frames ready for display.
*/
void MythPlayer::ReleaseNextVideoFrame(MythVideoFrame *buffer,
int64_t timecode,
std::chrono::milliseconds timecode,
bool wrap)
{
if (wrap)
Expand Down Expand Up @@ -1267,12 +1267,12 @@ bool MythPlayer::DoGetFrame(DecodeType Type)
return ret;
}

void MythPlayer::WrapTimecode(int64_t &timecode, TCTypes tc_type)
void MythPlayer::WrapTimecode(std::chrono::milliseconds &timecode, TCTypes tc_type)
{
timecode += m_tcWrap[tc_type];
}

bool MythPlayer::PrepareAudioSample(int64_t &timecode)
bool MythPlayer::PrepareAudioSample(std::chrono::milliseconds &timecode)
{
WrapTimecode(timecode, TC_AUDIO);
return false;
Expand Down Expand Up @@ -1662,9 +1662,9 @@ void MythPlayer::ClearAfterSeek(bool clearvideobuffers)
if (clearvideobuffers && m_videoOutput)
m_videoOutput->ClearAfterSeek();

int64_t savedTC = m_tcWrap[TC_AUDIO];
std::chrono::milliseconds savedTC = m_tcWrap[TC_AUDIO];

m_tcWrap.fill(0);
m_tcWrap.fill(0ms);
m_tcWrap[TC_AUDIO] = savedTC;
m_audio.Reset();

Expand Down
12 changes: 6 additions & 6 deletions mythtv/libs/libmythtv/mythplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ enum TCTypes
TC_CC
};
#define TCTYPESMAX 4
using tctype_arr = std::array<int64_t,TCTYPESMAX>;
using tctype_arr = std::array<std::chrono::milliseconds,TCTYPESMAX>;

enum PlayerFlags
{
Expand Down Expand Up @@ -177,7 +177,7 @@ class MTV_PUBLIC MythPlayer : public QObject
// Decoder stuff..
MythVideoFrame *GetNextVideoFrame(void);
void DeLimboFrame(MythVideoFrame *frame);
virtual void ReleaseNextVideoFrame(MythVideoFrame *buffer, int64_t timecode,
virtual void ReleaseNextVideoFrame(MythVideoFrame *buffer, std::chrono::milliseconds timecode,
bool wrap = true);
void DiscardVideoFrame(MythVideoFrame *buffer);
void DiscardVideoFrames(bool KeyFrame, bool Flushed);
Expand All @@ -188,7 +188,7 @@ class MTV_PUBLIC MythPlayer : public QObject
void ForceSetupAudioStream(void);

// Add data
virtual bool PrepareAudioSample(int64_t &timecode);
virtual bool PrepareAudioSample(std::chrono::milliseconds &timecode);

// Public Closed caption and teletext stuff
virtual uint GetCaptionMode() const { return kDisplayNone; }
Expand Down Expand Up @@ -360,7 +360,7 @@ class MTV_PUBLIC MythPlayer : public QObject
virtual int64_t GetChapter(int chapter);

// Private A/V Sync Stuff
void WrapTimecode(int64_t &timecode, TCTypes tc_type);
void WrapTimecode(std::chrono::milliseconds &timecode, TCTypes tc_type);
void SetFrameInterval(FrameScanType scan, double frame_period);

protected:
Expand Down Expand Up @@ -431,7 +431,7 @@ class MTV_PUBLIC MythPlayer : public QObject
std::chrono::seconds m_totalLength {0s};
std::chrono::seconds m_totalDuration {0s};
long long m_rewindTime {0};
int64_t m_latestVideoTimecode {-1};
std::chrono::milliseconds m_latestVideoTimecode {-1ms};
MythPlayerAVSync m_avSync;

// -- end state stuff --
Expand Down Expand Up @@ -500,7 +500,7 @@ class MTV_PUBLIC MythPlayer : public QObject

// Time Code stuff
tctype_arr m_tcWrap {};
int64_t m_savedAudioTimecodeOffset {0};
std::chrono::milliseconds m_savedAudioTimecodeOffset {0ms};

// LiveTV
bool m_isDummy {false};
Expand Down
15 changes: 8 additions & 7 deletions mythtv/libs/libmythtv/mythplayeraudioui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ MythPlayerAudioUI::MythPlayerAudioUI(MythMainWindow* MainWindow, TV *Tv,

// Setup
MythPlayerAudioUI::SetupAudioOutput(Context->m_tsNormal);
MythPlayerAudioUI::AdjustAudioTimecodeOffset(0, gCoreContext->GetNumSetting("AudioSyncOffset", 0));
auto offset = gCoreContext->GetDurSetting<std::chrono::milliseconds>("AudioSyncOffset", 0ms);
MythPlayerAudioUI::AdjustAudioTimecodeOffset(0ms, offset);
}

/// \brief Initialise audio and signal initial state
Expand Down Expand Up @@ -180,21 +181,21 @@ void MythPlayerAudioUI::SetupAudioOutput(float TimeStretch)
m_audio.SetStretchFactor(TimeStretch);
}

void MythPlayerAudioUI::AdjustAudioTimecodeOffset(int64_t Delta, int Value)
void MythPlayerAudioUI::AdjustAudioTimecodeOffset(std::chrono::milliseconds Delta, std::chrono::milliseconds Value)
{
int64_t oldwrap = m_tcWrap[TC_AUDIO];
std::chrono::milliseconds oldwrap = m_tcWrap[TC_AUDIO];

if ((Value >= -1000) && (Value <= 1000))
if ((Value >= -1000ms) && (Value <= 1000ms))
m_tcWrap[TC_AUDIO] = Value;
else
m_tcWrap[TC_AUDIO] += Delta;

int64_t newwrap = m_tcWrap[TC_AUDIO];
std::chrono::milliseconds newwrap = m_tcWrap[TC_AUDIO];
if (!(m_browsing || m_editing))
{
UpdateOSDStatus(tr("Adjust Audio Sync"), tr("Audio Sync"),
QString::number(newwrap), kOSDFunctionalType_AudioSyncAdjust,
"ms", (static_cast<int>(newwrap) / 2) + 500, kOSDTimeout_None);
QString::number(newwrap.count()), kOSDFunctionalType_AudioSyncAdjust,
"ms", (newwrap / 2 + 500ms).count(), kOSDTimeout_None);
ChangeOSDPositionUpdates(false);
}

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/mythplayeraudioui.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MTV_PUBLIC MythPlayerAudioUI : public MythPlayerOverlayUI
void ReinitAudio();
void EnableUpmix(bool Enable, bool Toggle = false);
void PauseAudioUntilBuffered();
void AdjustAudioTimecodeOffset(int64_t Delta, int Value);
void AdjustAudioTimecodeOffset(std::chrono::milliseconds Delta, std::chrono::milliseconds Value);

public:
MythPlayerAudioUI(MythMainWindow* MainWindow, TV* Tv, PlayerContext* Context, PlayerFlags Flags);
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/mythplayeravsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ std::chrono::microseconds MythPlayerAVSync::AVSync(AudioPlayer *Audio, MythVideo
{
if (Frame)
{
videotimecode = std::chrono::milliseconds(Frame->m_timecode & 0x0000ffffffffffff);
videotimecode = std::chrono::milliseconds(Frame->m_timecode.count() & 0x0000ffffffffffff);
// Detect bogus timecodes from DVD and ignore them.
if (videotimecode != std::chrono::milliseconds(Frame->m_timecode))
if (videotimecode != Frame->m_timecode)
videotimecode = m_maxTcVal;
}

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/mythplayerstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ MythOverlayState::MythOverlayState(bool Browsing, bool Editing)
* \brief A simple wrapper around audio state used to signal changes
* in the current state.
*/
MythAudioState::MythAudioState(AudioPlayer* Player, int64_t Offset)
MythAudioState::MythAudioState(AudioPlayer* Player, std::chrono::milliseconds Offset)
: m_hasAudioOut(Player->HasAudioOut()),
m_volumeControl(Player->ControlsVolume()),
m_volume(Player->GetVolume()),
Expand Down
5 changes: 3 additions & 2 deletions mythtv/libs/libmythtv/mythplayerstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// MythTV
#include "mythtvexp.h"
#include "mythchrono.h"
#include "volumebase.h"
#include "videoouttypes.h"
#include "audiooutputsettings.h"
Expand Down Expand Up @@ -47,7 +48,7 @@ class MTV_PUBLIC MythAudioState
{
public:
MythAudioState() = default;
MythAudioState(AudioPlayer* Player, int64_t Offset);
MythAudioState(AudioPlayer* Player, std::chrono::milliseconds Offset);

bool m_hasAudioOut { true };
bool m_volumeControl { true };
Expand All @@ -56,7 +57,7 @@ class MTV_PUBLIC MythAudioState
bool m_canUpmix { false };
bool m_isUpmixing { false };
bool m_paused { false };
int64_t m_audioOffset { 0 };
std::chrono::milliseconds m_audioOffset { 0ms };
};

Q_DECLARE_METATYPE(MythAudioState)
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/mythplayerui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ void MythPlayerUI::RefreshPauseFrame()
if (m_deleteMap.IsEditing())
{
m_osdLock.lock();
DeleteMap::UpdateOSD(std::chrono::milliseconds(m_latestVideoTimecode), &m_osd);
DeleteMap::UpdateOSD(m_latestVideoTimecode, &m_osd);
m_osdLock.unlock();
}
}
Expand Down Expand Up @@ -1287,7 +1287,7 @@ void MythPlayerUI::EnableEdit()
SetupAudioGraph(m_videoFrameRate);

m_savedAudioTimecodeOffset = m_tcWrap[TC_AUDIO];
m_tcWrap[TC_AUDIO] = 0;
m_tcWrap[TC_AUDIO] = 0ms;

m_speedBeforeEdit = m_playSpeed;
m_pausedBeforeEdit = Pause();
Expand Down Expand Up @@ -1333,7 +1333,7 @@ void MythPlayerUI::DisableEdit(int HowToSave)
m_playerCtx->UnlockPlayingInfo(__FILE__, __LINE__);
ClearAudioGraph();
m_tcWrap[TC_AUDIO] = m_savedAudioTimecodeOffset;
m_savedAudioTimecodeOffset = 0;
m_savedAudioTimecodeOffset = 0ms;

if (!m_pausedBeforeEdit)
Play(m_speedBeforeEdit);
Expand Down
44 changes: 21 additions & 23 deletions mythtv/libs/libmythtv/recorders/NuppelVideoRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,7 @@ void NuppelVideoRecorder::BufferIt(unsigned char *buf, int len, bool forcekey)
// record the time at the start of this frame.
// 'tcres' is at the end of the frame, so subtract the right # of ms
m_videoBuffer[act]->timecode =
(m_ntscFrameRate) ? (tcres.count() - 33) : (tcres.count() - 40);
(m_ntscFrameRate) ? (tcres - 33ms) : (tcres - 40ms);

memcpy(m_videoBuffer[act]->buffer, buf, len);
m_videoBuffer[act]->bufferlen = len;
Expand Down Expand Up @@ -2140,7 +2140,7 @@ void NuppelVideoRecorder::Reset(void)
{
vidbuffertype *vidbuf = m_videoBuffer[i];
vidbuf->sample = 0;
vidbuf->timecode = 0;
vidbuf->timecode = 0ms;
vidbuf->freeToEncode = 0;
vidbuf->freeToBuffer = 1;
vidbuf->forcekey = false;
Expand All @@ -2150,7 +2150,7 @@ void NuppelVideoRecorder::Reset(void)
{
audbuffertype *audbuf = m_audioBuffer[i];
audbuf->sample = 0;
audbuf->timecode = 0;
audbuf->timecode = 0ms;
audbuf->freeToEncode = 0;
audbuf->freeToBuffer = 1;
}
Expand Down Expand Up @@ -2262,12 +2262,12 @@ void NuppelVideoRecorder::doAudioThread(void)

/* calculate timecode. First compute the difference
between now and stm (start time) */
m_audioBuffer[act]->timecode = (anow.tv_sec - m_stm.tv_sec) * 1000 +
anow.tv_usec / 1000 - m_stm.tv_usec / 1000;
m_audioBuffer[act]->timecode =
durationFromTimevalDelta<std::chrono::milliseconds>(anow, m_stm);
/* We want the timestamp to point to the start of this
audio chunk. So, subtract off the length of the chunk
and the length of audio still in the capture buffer. */
m_audioBuffer[act]->timecode -= (int)(
m_audioBuffer[act]->timecode -= millisecondsFromFloat(
(bytes_read + m_audioBufferSize)
* 1000.0 / (m_audioSampleRate * m_audioBytesPerSample));

Expand Down Expand Up @@ -2304,8 +2304,8 @@ void NuppelVideoRecorder::FormatTT(struct VBIData *vbidata)

// calculate timecode:
// compute the difference between now and stm (start time)
m_textBuffer[act]->timecode = (tnow.tv_sec-m_stm.tv_sec) * 1000 +
tnow.tv_usec/1000 - m_stm.tv_usec/1000;
m_textBuffer[act]->timecode =
durationFromTimevalDelta<std::chrono::milliseconds>(tnow, m_stm);
m_textBuffer[act]->pagenr = (vbidata->teletextpage.pgno << 16) +
vbidata->teletextpage.subno;

Expand Down Expand Up @@ -2460,14 +2460,12 @@ void NuppelVideoRecorder::FormatCC(uint code1, uint code2)

// calculate timecode:
// compute the difference between now and stm (start time)
int tc = (tnow.tv_sec - m_stm.tv_sec) * 1000 +
tnow.tv_usec / 1000 - m_stm.tv_usec / 1000;

auto tc = durationFromTimevalDelta<std::chrono::milliseconds>(tnow, m_stm);
m_ccd->FormatCC(tc, code1, code2);
}

void NuppelVideoRecorder::AddTextData(unsigned char *buf, int len,
int64_t timecode, char /*type*/)
std::chrono::milliseconds timecode, char /*type*/)
{
int act = m_actTextBuffer;
if (!m_textBuffer[act]->freeToBuffer)
Expand Down Expand Up @@ -2525,7 +2523,7 @@ void NuppelVideoRecorder::doWriteThread(void)
ACTION_AUDIO,
ACTION_TEXT
} action = ACTION_NONE;
int firsttimecode = -1;
std::chrono::milliseconds firsttimecode = -1ms;

if (m_videoBuffer[m_actVideoEncode]->freeToEncode)
{
Expand Down Expand Up @@ -2665,7 +2663,7 @@ void NuppelVideoRecorder::WriteVideo(MythVideoFrame *frame, bool skipsync,
frame->m_buffer + frame->m_offsets[1],
frame->m_buffer + frame->m_offsets[2] };
int fnum = frame->m_frameNumber;
long long timecode = frame->m_timecode;
std::chrono::milliseconds timecode = frame->m_timecode;

if (m_lf == 0)
{ // this will be triggered every new file
Expand Down Expand Up @@ -2799,7 +2797,7 @@ void NuppelVideoRecorder::WriteVideo(MythVideoFrame *frame, bool skipsync,
}

frameheader.frametype = 'V'; // video frame
frameheader.timecode = timecode;
frameheader.timecode = timecode.count();
m_lastTimecode = frameheader.timecode;
frameheader.filters = 0; // no filters applied

Expand Down Expand Up @@ -2878,13 +2876,13 @@ static void bswap_16_buf(short int *buf, int buf_cnt, int audio_channels)
}
#endif

void NuppelVideoRecorder::WriteAudio(unsigned char *buf, int fnum, int timecode)
void NuppelVideoRecorder::WriteAudio(unsigned char *buf, int fnum, std::chrono::milliseconds timecode)
{
struct rtframeheader frameheader {};

if (m_lastBlock == 0)
{
m_firstTc = -1;
m_firstTc = -1ms;
}

if (m_lastBlock != 0)
Expand All @@ -2898,14 +2896,14 @@ void NuppelVideoRecorder::WriteAudio(unsigned char *buf, int fnum, int timecode)
}

frameheader.frametype = 'A'; // audio frame
frameheader.timecode = timecode;
frameheader.timecode = timecode.count();

if (m_firstTc == -1)
if (m_firstTc == -1ms)
{
m_firstTc = timecode;
#if 0
LOG(VB_GENERAL, LOG_DEBUG, LOC +
QString("first timecode=%1").arg(m_firstTc));
QString("first timecode=%1").arg(m_firstTc.count()));
#endif
}
else
Expand All @@ -2917,7 +2915,7 @@ void NuppelVideoRecorder::WriteAudio(unsigned char *buf, int fnum, int timecode)
auto abytes = (double)m_audioBytes; // - (double)m_audioBufferSize;
// wrong guess ;-)
// need seconds instead of msec's
auto mt = (double)timecode;
auto mt = (double)timecode.count();
if (mt > 0.0)
{
double eff = (abytes / mt) * (100000.0 / m_audioBytesPerSample);
Expand Down Expand Up @@ -3009,13 +3007,13 @@ void NuppelVideoRecorder::WriteAudio(unsigned char *buf, int fnum, int timecode)
m_lastBlock = fnum;
}

void NuppelVideoRecorder::WriteText(unsigned char *buf, int len, int timecode,
void NuppelVideoRecorder::WriteText(unsigned char *buf, int len, std::chrono::milliseconds timecode,
int pagenr)
{
struct rtframeheader frameheader {};

frameheader.frametype = 'T'; // text frame
frameheader.timecode = timecode;
frameheader.timecode = timecode.count();

if (VBIMode::PAL_TT == m_vbiMode)
{
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/recorders/NuppelVideoRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class MTV_PUBLIC NuppelVideoRecorder : public V4LRecorder, public CC608Input
void SetVideoAspect(float newAspect) {m_videoAspect = newAspect; };
void WriteVideo(MythVideoFrame *frame, bool skipsync = false,
bool forcekey = false);
void WriteAudio(unsigned char *buf, int fnum, int timecode);
void WriteText(unsigned char *buf, int len, int timecode, int pagenr);
void WriteAudio(unsigned char *buf, int fnum, std::chrono::milliseconds timecode);
void WriteText(unsigned char *buf, int len, std::chrono::milliseconds timecode, int pagenr);

void SetNewVideoParams(double newaspect);

Expand Down Expand Up @@ -152,7 +152,7 @@ class MTV_PUBLIC NuppelVideoRecorder : public V4LRecorder, public CC608Input

void FormatTT(struct VBIData *vbidata) override; // V4LRecorder
void FormatCC(uint code1, uint code2) override; // V4LRecorder
void AddTextData(unsigned char*buf, int len, int64_t timecode, char type) override; // CC608Input
void AddTextData(unsigned char *buf, int len, std::chrono::milliseconds timecode, char type) override; // CC608Input

void UpdateResolutions(void);

Expand Down Expand Up @@ -240,7 +240,7 @@ class MTV_PUBLIC NuppelVideoRecorder : public V4LRecorder, public CC608Input
double m_heightMultiplier {1.0};

int m_lastBlock {0};
int m_firstTc {0};
std::chrono::milliseconds m_firstTc {0ms};
std::chrono::milliseconds m_oldTc {0ms};
int m_startNum {0};
int m_frameOfGop {0};
Expand Down
20 changes: 10 additions & 10 deletions mythtv/libs/libmythtv/tv_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ void TV::GetStatus()
status.insert("audiotracks", tracks);

status.insert("playspeed", m_player->GetPlaySpeed());
status.insert("audiosyncoffset", static_cast<long long>(m_audioState.m_audioOffset));
status.insert("audiosyncoffset", static_cast<long long>(m_audioState.m_audioOffset.count()));

if (m_audioState.m_volumeControl)
{
Expand Down Expand Up @@ -3708,13 +3708,13 @@ bool TV::AudioSyncHandleAction(const QStringList& Actions)
bool handled = true;

if (IsActionable(ACTION_LEFT, Actions))
emit ChangeAudioOffset(-1);
emit ChangeAudioOffset(-1ms);
else if (IsActionable(ACTION_RIGHT, Actions))
emit ChangeAudioOffset(1);
emit ChangeAudioOffset(1ms);
else if (IsActionable(ACTION_UP, Actions))
emit ChangeAudioOffset(10);
emit ChangeAudioOffset(10ms);
else if (IsActionable(ACTION_DOWN, Actions))
emit ChangeAudioOffset(-10);
emit ChangeAudioOffset(-10ms);
else if (IsActionable({ ACTION_TOGGELAUDIOSYNC, ACTION_SELECT }, Actions))
ClearOSD();
else
Expand Down Expand Up @@ -3778,7 +3778,7 @@ bool TV::DiscMenuHandleAction(const QStringList& Actions) const
MythVideoFrame *frame = output->GetLastShownFrame();
// convert timecode (msec) to pts (90kHz)
if (frame)
pts = static_cast<int64_t>(frame->m_timecode * 90);
pts = static_cast<int64_t>(frame->m_timecode.count() * 90);
}
if (m_playerContext.m_buffer)
return m_playerContext.m_buffer->HandleAction(Actions, pts);
Expand Down Expand Up @@ -4068,7 +4068,7 @@ bool TV::ToggleHandleAction(const QStringList &Actions, bool IsDVD)
else if (IsActionable("TOGGLEFILL", Actions))
emit ChangeAdjustFill();
else if (IsActionable(ACTION_TOGGELAUDIOSYNC, Actions))
emit ChangeAudioOffset(0); // just display
emit ChangeAudioOffset(0ms); // just display
else if (IsActionable(ACTION_TOGGLESUBTITLEZOOM, Actions))
emit AdjustSubtitleZoom(0); // just display
else if (IsActionable(ACTION_TOGGLESUBTITLEDELAY, Actions))
Expand Down Expand Up @@ -7289,7 +7289,7 @@ void TV::customEvent(QEvent *Event)
if (message == ACTION_SETVOLUME)
VolumeChange(false, value);
else if (message == ACTION_SETAUDIOSYNC)
emit ChangeAudioOffset(0, value);
emit ChangeAudioOffset(0ms, std::chrono::milliseconds(value));
else if (message == ACTION_SETBRIGHTNESS)
emit ChangePictureAttribute(kPictureAttribute_Brightness, false, value);
else if (message == ACTION_SETCONTRAST)
Expand Down Expand Up @@ -7684,7 +7684,7 @@ void TV::HandleOSDClosed(int OSDType)
break;
case kOSDFunctionalType_AudioSyncAdjust:
m_audiosyncAdjustment = false;
gCoreContext->SaveSetting("AudioSyncOffset", QString::number(m_audioState.m_audioOffset));
gCoreContext->SaveSetting("AudioSyncOffset", QString::number(m_audioState.m_audioOffset.count()));
break;
case kOSDFunctionalType_SubtitleZoomAdjust:
m_subtitleZoomAdjustment = false;
Expand Down Expand Up @@ -8144,7 +8144,7 @@ void TV::OSDDialogEvent(int Result, const QString& Text, QString Action)
else if (Action.startsWith("SELECTSCAN_"))
OverrideScan(static_cast<FrameScanType>(Action.rightRef(1).toInt()));
else if (Action.startsWith(ACTION_TOGGELAUDIOSYNC))
emit ChangeAudioOffset(0);
emit ChangeAudioOffset(0ms);
else if (Action == ACTION_TOGGLESUBTITLEZOOM)
emit AdjustSubtitleZoom(0);
else if (Action == ACTION_TOGGLESUBTITLEDELAY)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/tvplaybackstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MTV_PUBLIC TVPlaybackState : public QObject
void ChangeMuteState(bool CycleChannels = false);
void ChangeVolume(bool Direction, int Volume);
void ChangeUpmix(bool Enable, bool Toggle = false);
void ChangeAudioOffset(int64_t Delta, int Value = -9999);
void ChangeAudioOffset(std::chrono::milliseconds Delta, std::chrono::milliseconds Value = -9999ms);

// Audio and captions
void SetTrack(uint Type, uint TrackNo);
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/videobuffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ void VideoBuffers::ClearAfterSeek(void)
QMutexLocker locker(&m_globalLock);

for (uint i = 0; i < Size(); i++)
At(i)->m_timecode = 0;
At(i)->m_timecode = 0ms;

for (uint i = 0; (i < Size()) && (m_used.count() > 1); i++)
{
Expand Down
3 changes: 2 additions & 1 deletion mythtv/programs/mythtranscode/mythtranscodeplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ long MythTranscodePlayer::UpdateStoredFrameNum(long CurrentFrameNum)
}

bool MythTranscodePlayer::WriteStoredData(MythMediaBuffer* OutBuffer,
bool Writevideo, long TimecodeOffset)
bool Writevideo,
std::chrono::milliseconds TimecodeOffset)
{
if (!m_decoder)
return false;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythtranscode/mythtranscodeplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MythTranscodePlayer : public MythPlayer
void InitForTranscode (bool CopyAudio, bool CopyVideo);
void SetCutList (const frm_dir_map_t& CutList);
bool TranscodeGetNextFrame (int& DidFF, bool& KeyFrame, bool HonorCutList);
bool WriteStoredData (MythMediaBuffer* OutBuffer, bool WriteVideo, long TimecodeOffset);
bool WriteStoredData (MythMediaBuffer* OutBuffer, bool WriteVideo, std::chrono::milliseconds TimecodeOffset);
long UpdateStoredFrameNum (long CurrentFrameNum);
};

Expand Down
83 changes: 40 additions & 43 deletions mythtv/programs/mythtranscode/transcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static bool get_bool_option(RecordingProfile *profile, const QString &name)
}

static void TranscodeWriteText(void *ptr, unsigned char *buf, int len,
int timecode, int pagenr)
std::chrono::milliseconds timecode, int pagenr)
{
auto *nvr = (NuppelVideoRecorder *)ptr;
nvr->WriteText(buf, len, timecode, pagenr);
Expand Down Expand Up @@ -1003,6 +1003,7 @@ int Transcode::TranscodeFile(const QString &inputname,

float rateTimeConv = arb->m_eff_audiorate / 1000.0F;
float vidFrameTime = 1000.0F / video_frame_rate;
auto vidFrameTimeMs = millisecondsFromFloat(vidFrameTime);
int wait_recover = 0;
MythVideoOutput *videoOutput = player->GetVideoOutput();
bool is_key = false;
Expand Down Expand Up @@ -1059,8 +1060,8 @@ int Transcode::TranscodeFile(const QString &inputname,
frame.m_timecode = lastDecode->m_timecode;

// if the timecode jumps backwards just use the last frame's timecode plus the duration of a frame
if (frame.m_timecode < lasttimecode.count())
frame.m_timecode = (long long)(lasttimecode.count() + vidFrameTime);
if (frame.m_timecode < lasttimecode)
frame.m_timecode = lasttimecode + vidFrameTimeMs;

if (m_fifow)
{
Expand All @@ -1076,27 +1077,27 @@ int Transcode::TranscodeFile(const QString &inputname,
sws_scale(scontext, imageIn.data, imageIn.linesize, 0,
lastDecode->m_height, imageOut.data, imageOut.linesize);

totalAudio += arb->GetSamples(std::chrono::milliseconds(frame.m_timecode));
int audbufTime = (int)(totalAudio / rateTimeConv);
int auddelta = frame.m_timecode - audbufTime;
int vidTime = lroundf(curFrameNum * vidFrameTime);
int viddelta = frame.m_timecode - vidTime;
int delta = viddelta - auddelta;
int absdelta = delta < 0 ? -delta : delta;
if (absdelta < 500 && absdelta >= vidFrameTime)
totalAudio += arb->GetSamples(frame.m_timecode);
std::chrono::milliseconds audbufTime = millisecondsFromFloat(totalAudio / rateTimeConv);
std::chrono::milliseconds auddelta = frame.m_timecode - audbufTime;
std::chrono::milliseconds vidTime = millisecondsFromFloat(curFrameNum * vidFrameTime);
std::chrono::milliseconds viddelta = frame.m_timecode - vidTime;
std::chrono::milliseconds delta = viddelta - auddelta;
std::chrono::milliseconds absdelta = std::chrono::abs(delta);
if (absdelta < 500ms && absdelta >= vidFrameTimeMs)
{
QString msg = QString("Audio is %1ms %2 video at # %3: "
"auddelta=%4, viddelta=%5")
.arg(absdelta)
.arg(((delta > 0) ? "ahead of" : "behind"))
.arg(absdelta.count())
.arg(((delta > 0ms) ? "ahead of" : "behind"))
.arg((int)curFrameNum)
.arg(auddelta)
.arg(viddelta);
.arg(auddelta.count())
.arg(viddelta.count());
LOG(VB_GENERAL, LOG_INFO, msg);
dropvideo = (delta > 0) ? 1 : -1;
dropvideo = (delta > 0ms) ? 1 : -1;
wait_recover = 0;
}
else if (delta >= 500 && delta < 10000)
else if (delta >= 500ms && delta < 10s)
{
if (wait_recover == 0)
{
Expand All @@ -1107,13 +1108,13 @@ int Transcode::TranscodeFile(const QString &inputname,
{
// Video is badly lagging. Try to catch up.
int count = 0;
while (delta > vidFrameTime)
while (delta > vidFrameTimeMs)
{
if (!cutter || !cutter->InhibitDummyFrame())
m_fifow->FIFOWrite(0, frame.m_buffer, frame.m_bufferSize);

count++;
delta -= (int)vidFrameTime;
delta -= vidFrameTimeMs;
}
QString msg = QString("Added %1 blank video frames")
.arg(count);
Expand All @@ -1136,12 +1137,12 @@ int Transcode::TranscodeFile(const QString &inputname,
LOG(VB_GENERAL, LOG_DEBUG,
QString("%1: video time: %2 audio time: %3 "
"buf: %4 exp: %5 delta: %6")
.arg(curFrameNum) .arg(frame.timecode)
.arg(arb->last_audiotime) .arg(buflen) .arg(audbufTime)
.arg(delta));
.arg(curFrameNum) .arg(frame.m_timecode.count())
.arg(arb->last_audiotime) .arg(buflen) .arg(audbufTime.count())
.arg(delta.count()));
#endif
AudioBuffer *ab = nullptr;
while ((ab = arb->GetData(std::chrono::milliseconds(frame.m_timecode))) != nullptr)
while ((ab = arb->GetData(frame.m_timecode)) != nullptr)
{
if (!cutter ||
!cutter->InhibitUseAudioFrames(ab->m_frames, &totalAudio))
Expand Down Expand Up @@ -1175,7 +1176,7 @@ int Transcode::TranscodeFile(const QString &inputname,
}
videoOutput->DoneDisplayingFrame(lastDecode);
player->GetCC608Reader()->FlushTxtBuffers();
lasttimecode = std::chrono::milliseconds(frame.m_timecode);
lasttimecode = frame.m_timecode;
}
else if (copyaudio)
{
Expand Down Expand Up @@ -1228,15 +1229,13 @@ int Transcode::TranscodeFile(const QString &inputname,

if (did_ff == 1)
{
timecodeOffset += (std::chrono::milliseconds(frame.m_timecode) -
lasttimecode -
std::chrono::milliseconds((int)vidFrameTime));
timecodeOffset += (frame.m_timecode - lasttimecode - vidFrameTimeMs);
}
lasttimecode = std::chrono::milliseconds(frame.m_timecode);
lasttimecode = frame.m_timecode;
// from here on the timecode is on the output time base
frame.m_timecode -= timecodeOffset.count();
frame.m_timecode -= timecodeOffset;

if (!player->WriteStoredData(m_outBuffer, (did_ff == 0), timecodeOffset.count()))
if (!player->WriteStoredData(m_outBuffer, (did_ff == 0), timecodeOffset))
{
if (video_aspect != new_aspect)
{
Expand Down Expand Up @@ -1296,9 +1295,8 @@ int Transcode::TranscodeFile(const QString &inputname,
if (did_ff == 1)
{
did_ff = 2;
timecodeOffset += (std::chrono::milliseconds(frame.m_timecode) -
lasttimecode -
std::chrono::milliseconds((int)vidFrameTime));
timecodeOffset += (frame.m_timecode - lasttimecode -
millisecondsFromFloat(vidFrameTime));
}

if (video_aspect != new_aspect)
Expand Down Expand Up @@ -1351,20 +1349,19 @@ int Transcode::TranscodeFile(const QString &inputname,
if (did_ff != 1)
{
std::chrono::milliseconds tc = ab->m_time - timecodeOffset;
long long tc_tmp = tc.count();
avfw->WriteAudioFrame(buf, audioFrame, tc_tmp);
avfw->WriteAudioFrame(buf, audioFrame, tc);

if (avfw2)
{
if ((avfw2->GetTimecodeOffset() == -1) &&
(avfw->GetTimecodeOffset() != -1))
if ((avfw2->GetTimecodeOffset() == -1ms) &&
(avfw->GetTimecodeOffset() != -1ms))
{
avfw2->SetTimecodeOffset(
avfw->GetTimecodeOffset());
}

tc = ab->m_time - timecodeOffset;
avfw2->WriteAudioFrame(buf, audioFrame, tc_tmp);
avfw2->WriteAudioFrame(buf, audioFrame, tc);
}

++audioFrame;
Expand All @@ -1375,7 +1372,7 @@ int Transcode::TranscodeFile(const QString &inputname,
{
m_nvr->SetOption("audioframesize", ab->size());
m_nvr->WriteAudio(buf, audioFrame++,
(ab->m_time - timecodeOffset).count());
(ab->m_time - timecodeOffset));
if (m_nvr->IsErrored())
{
LOG(VB_GENERAL, LOG_ERR,
Expand Down Expand Up @@ -1403,8 +1400,8 @@ int Transcode::TranscodeFile(const QString &inputname,
return REENCODE_ERROR;
#endif
}
lasttimecode = std::chrono::milliseconds(frame.m_timecode);
frame.m_timecode -= timecodeOffset.count();
lasttimecode = frame.m_timecode;
frame.m_timecode -= timecodeOffset;

if (m_avfMode)
{
Expand Down Expand Up @@ -1432,7 +1429,7 @@ int Transcode::TranscodeFile(const QString &inputname,

if (avfw->WriteVideoFrame(rescale ? &frame : lastDecode) > 0)
{
lastWrittenTime = std::chrono::milliseconds(frame.m_timecode) + timecodeOffset;
lastWrittenTime = frame.m_timecode + timecodeOffset;
if (hls)
++hlsSegmentFrames;
}
Expand All @@ -1446,7 +1443,7 @@ int Transcode::TranscodeFile(const QString &inputname,
m_nvr->WriteVideo(rescale ? &frame : lastDecode, true, true);
else
m_nvr->WriteVideo(rescale ? &frame : lastDecode);
lastWrittenTime = std::chrono::milliseconds(frame.m_timecode) + timecodeOffset;
lastWrittenTime = frame.m_timecode + timecodeOffset;
}
#endif
}
Expand Down