15 changes: 4 additions & 11 deletions mythtv/libs/libmythtv/deletemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "mythplayer.h"
#include "programinfo.h"
#include "mythcorecontext.h" // for MythCoreContext, etc
#include "mythmiscutil.h"
#include "mythtypes.h" // for InfoMap
#include "mythuiactions.h" // for ACTION_DOWN, ACTION_UP
#include "playercontext.h" // for PlayerContext
Expand Down Expand Up @@ -163,18 +164,10 @@ QString DeleteMap::CreateTimeString(uint64_t frame, bool use_cutlist,
const
{
uint64_t ms = TranslatePositionFrameToMs(frame, frame_rate, use_cutlist);
int secs = (int)(ms / 1000);
int remainder = (int)(ms % 1000);
int totalSecs = (int)
(TranslatePositionFrameToMs(frame, frame_rate, use_cutlist) / 1000);
QString timestr;
if (totalSecs >= 3600)
timestr = QString::number(secs / 3600) + ":";
timestr += QString("%1").arg((secs / 60) % 60, 2, 10, QChar(48)) +
QString(":%1").arg(secs % 60, 2, 10, QChar(48));
QString fmt = (ms >= ONEHOURINMS) ? "H:mm:ss" : "mm:ss";
if (full_resolution)
timestr += QString(".%1").arg(remainder, 3, 10, QChar(48));
return timestr;
fmt += ".zzz";
return MythFormatTimeMs(ms, fmt);
}

/**
Expand Down
61 changes: 12 additions & 49 deletions mythtv/libs/libmythtv/mythplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5018,6 +5018,7 @@ void MythPlayer::calcSliderPos(osdInfo &info, bool paddedFields)
stillFrame = (secsplayed < 0);
playbackLen = max(playbackLen, 0);
secsplayed = min(playbackLen, max(secsplayed, 0));
int secsbehind = max((playbackLen - secsplayed), 0);

if (playbackLen > 0)
pos = (int)(1000.0F * (secsplayed / (float)playbackLen));
Expand All @@ -5026,70 +5027,32 @@ void MythPlayer::calcSliderPos(osdInfo &info, bool paddedFields)
info.values.insert(relPrefix + "totalseconds", playbackLen);
info.values[relPrefix + "position"] = pos;

int phours = secsplayed / 3600;
int pmins = (secsplayed - phours * 3600) / 60;
int psecs = (secsplayed - phours * 3600 - pmins * 60);

int shours = playbackLen / 3600;
int smins = (playbackLen - shours * 3600) / 60;
int ssecs = (playbackLen - shours * 3600 - smins * 60);

int secsbehind = max((playbackLen - secsplayed), 0);
int sbhours = secsbehind / 3600;
int sbmins = (secsbehind - sbhours * 3600) / 60;
int sbsecs = (secsbehind - sbhours * 3600 - sbmins * 60);

QString text1;
QString text2;
QString text3;
if (paddedFields)
{
text1 = QString("%1:%2:%3")
.arg(phours, 2, 10, QLatin1Char('0'))
.arg(pmins, 2, 10, QLatin1Char('0'))
.arg(psecs, 2, 10, QLatin1Char('0'));
text2 = QString("%1:%2:%3")
.arg(shours, 2, 10, QLatin1Char('0'))
.arg(smins, 2, 10, QLatin1Char('0'))
.arg(ssecs, 2, 10, QLatin1Char('0'));
text3 = QString("%1:%2:%3")
.arg(sbhours, 2, 10, QLatin1Char('0'))
.arg(sbmins, 2, 10, QLatin1Char('0'))
.arg(sbsecs, 2, 10, QLatin1Char('0'));
text1 = MythFormatTime(secsplayed, "HH:mm:ss");
text2 = MythFormatTime(playbackLen, "HH:mm:ss");
text3 = MythFormatTime(secsbehind, "HH:mm:ss");
}
else
{
if (shours > 0)
{
text1 = QString("%1:%2:%3")
.arg(phours)
.arg(pmins, 2, 10, QLatin1Char('0'))
.arg(psecs, 2, 10, QLatin1Char('0'));
text2 = QString("%1:%2:%3")
.arg(shours)
.arg(smins, 2, 10, QLatin1Char('0'))
.arg(ssecs, 2, 10, QLatin1Char('0'));
}
else
{
text1 = QString("%1:%2").arg(pmins).arg(psecs, 2, 10, QLatin1Char('0'));
text2 = QString("%1:%2").arg(smins).arg(ssecs, 2, 10, QLatin1Char('0'));
}
QString fmt = (playbackLen >= ONEHOURINSEC) ? "H:mm:ss" : "mm:ss";
text1 = MythFormatTime(secsplayed, fmt);
text2 = MythFormatTime(playbackLen, fmt);

if (sbhours > 0)
if (secsbehind >= ONEHOURINSEC)
{
text3 = QString("%1:%2:%3")
.arg(sbhours)
.arg(sbmins, 2, 10, QLatin1Char('0'))
.arg(sbsecs, 2, 10, QLatin1Char('0'));
text3 = MythFormatTime(secsbehind, "H:mm:ss");
}
else if (sbmins > 0)
else if (secsbehind >= ONEMININSEC)
{
text3 = QString("%1:%2").arg(sbmins).arg(sbsecs, 2, 10, QLatin1Char('0'));
text3 = MythFormatTime(secsbehind, "mm:ss");
}
else
{
text3 = tr("%n second(s)", "", sbsecs);
text3 = tr("%n second(s)", "", secsbehind);
}
}

Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythtv/mythplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "programtypes.h" // for frm_dir_map_t, etc
#include "tv.h" // for CommSkipMode
#include "videoouttypes.h" // for FrameScanType, PIPLocation, etc
#include "mythmiscutil.h"

#include "mythtvexp.h"

Expand Down
27 changes: 5 additions & 22 deletions mythtv/libs/libmythtv/tv_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ using namespace std;
#include "mythuihelper.h"
#include "mythdialogbox.h"
#include "mythmainwindow.h"
#include "mythmiscutil.h"
#include "mythscreenstack.h"
#include "mythscreentype.h"
#include "mythuiactions.h" // for ACTION_LEFT, ACTION_RIGHT, etc
Expand Down Expand Up @@ -8338,17 +8339,6 @@ void TV::ShowLCDChannelInfo(const PlayerContext *ctx)
}
}

static void format_time(int seconds, QString &tMin, QString &tHrsMin)
{
int minutes = seconds / 60;
int hours = minutes / 60;
int min = minutes % 60;

tMin = TV::tr("%n minute(s)", "", minutes);
tHrsMin = QString("%1:%2").arg(hours).arg(min, 2, 10, QChar('0'));
}


void TV::ShowLCDDVDInfo(const PlayerContext *ctx)
{
LCD *lcd = LCD::Get();
Expand Down Expand Up @@ -8379,16 +8369,14 @@ void TV::ShowLCDDVDInfo(const PlayerContext *ctx)
}
else
{
QString timeMins;
QString timeHrsMin;
int playingTitle = 0;
int playingPart = 0;

dvd->GetPartAndTitle(playingPart, playingTitle);
int totalParts = dvd->NumPartsInTitle();
format_time(dvd->GetTotalTimeOfTitle(), timeMins, timeHrsMin);

mainStatus = tr("Title: %1 (%2)").arg(playingTitle).arg(timeHrsMin);
mainStatus = tr("Title: %1 (%2)").arg(playingTitle)
.arg(MythFormatTime(dvd->GetTotalTimeOfTitle(), "HH:mm"));
subStatus = tr("Chapter: %1/%2").arg(playingPart).arg(totalParts);
}
if ((dvdName != m_lcdCallsign) || (mainStatus != m_lcdTitle) ||
Expand Down Expand Up @@ -11433,15 +11421,10 @@ bool TV::MenuItemDisplayPlayback(const MenuItemContext &c)
int size = QString::number(m_tvmNumChapters).size();
for (int i = 0; i < m_tvmNumChapters; i++)
{
int hours = m_tvmChapterTimes[i] / 60 / 60;
int minutes = (m_tvmChapterTimes[i] / 60) - (hours * 60);
int secs = m_tvmChapterTimes[i] % 60;
QString chapter1 = QString("%1").arg(i+1, size, 10, QChar(48));
QString chapter2 = QString("%1").arg(i+1, 3 , 10, QChar(48));
QString desc = chapter1 + QString(" (%1:%2:%3)")
.arg(hours, 2, 10, QChar(48))
.arg(minutes, 2, 10, QChar(48))
.arg(secs, 2, 10, QChar(48));
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));
BUTTON(action, desc);
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythtv/tv_play.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ using namespace std;
#include "mythtimer.h"
#include "osd.h"
#include "decoders/decoderbase.h"
#include "mythmiscutil.h"

class QEvent;
class QKeyEvent;
Expand Down
13 changes: 4 additions & 9 deletions mythtv/libs/libmythupnp/upnphelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ QString TimeFormat(const QTime &time)

QString TimeFormat(uint32_t msec)
{
return QString("%1:%2:%3")
.arg((msec / (1000 * 60 * 60)) % 24, 2,10,QChar('0')) // Hours
.arg((msec / (1000 * 60)) % 60, 2,10,QChar('0')) // Minutes
.arg((msec / 1000) % 60, 2,10,QChar('0')); // Seconds
QTime time = QTime::fromMSecsSinceStartOfDay(msec);
return time.toString("HH:mm:ss");
}

QString DateTimeFormat(const QDateTime &dateTime)
Expand Down Expand Up @@ -90,11 +88,8 @@ QString resDurationFormat(uint32_t msec)
// M = Minutes (2 digits, 0 prefix)
// S = Seconds (2 digits, 0 prefix)
// FS = Fractional Seconds (milliseconds)
return QString("%01u:%02u:%02u.%01u")
.arg((msec / (1000 * 60 * 60)) % 24, 1,10,QChar('0')) // Hours
.arg((msec / (1000 * 60)) % 60, 2,10,QChar('0')) // Minutes
.arg((msec / 1000) % 60, 2,10,QChar('0')) // Seconds
.arg(msec % 1000, 1,10,QChar('0'));
QTime time = QTime::fromMSecsSinceStartOfDay(msec);
return time.toString("H:mm:ss:zzz");
}

};
Expand Down
30 changes: 7 additions & 23 deletions mythtv/programs/mythcommflag/CommDetector2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ using namespace std;
#include "compat.h"
#include "mythdb.h"
#include "mythlogging.h"
#include "mythmiscutil.h"
#include "mythplayer.h"
#include "programinfo.h"
#include "channelutil.h"
Expand Down Expand Up @@ -254,34 +255,17 @@ void createDebugDirectory(const QString& dirname, const QString& comment)
QString frameToTimestamp(long long frameno, float fps)
{
int ms = (int)roundf(frameno / fps * 1000);

int ss = ms / 1000;
ms %= 1000;
if (ms >= 500)
ss++;

int mm = ss / 60;
ss %= 60;

int hh = mm / 60;
mm %= 60;

return QString("%1:%2:%3")
.arg(hh).arg(mm, 2, 10, QChar('0')) .arg(ss, 2, 10, QChar('0'));
if (ms % 1000 >= 500)
ms += 500; // Round up to next second
return MythFormatTimeMs(ms, "hh:mm:ss");
}

QString frameToTimestampms(long long frameno, float fps)
{
int ms = (int)roundf(frameno / fps * 1000);

int ss = ms / 1000;
ms %= 1000;

int mm = ss / 60;
ss %= 60;

return QString("%1:%2:%3")
.arg(mm).arg(ss, 2, 10, QChar(QChar('0'))).arg(ms, 2, 10, QChar(QChar('0')));
QString timestr = MythFormatTimeMs(ms, "mm:ss.zzz");
timestr.chop(1); // Chop 1 to return hundredths
return timestr;
}

QString strftimeval(const struct timeval *tv)
Expand Down