MythTV  master
mythplayeroverlayui.cpp
Go to the documentation of this file.
1 #include <chrono>
2 
3 // MythTV
4 #include "tv_play.h"
5 #include "livetvchain.h"
6 #include "mythplayeroverlayui.h"
7 
8 #define LOC QString("PlayerOverlay: ")
9 
10 // N.B. Overlay is initialised without a player - it must be set before it can be used
12  : MythPlayerUIBase(MainWindow, Tv, Context, Flags),
13  m_osd(MainWindow, Tv, nullptr, m_painter)
14 {
15  // Register our state type for signalling
16  qRegisterMetaType<MythOverlayState>();
17 
18  m_positionUpdateTimer.setInterval(999ms);
21  connect(m_tv, &TV::ChangeOSDMessage, this, QOverload<const QString&>::of(&MythPlayerOverlayUI::UpdateOSDMessage));
22 
23  // Signalled directly from TV to OSD
25  connect(m_tv, &TV::HideAll, &m_osd, &OSD::HideAll);
26 }
27 
29 {
30  m_browsing = Browsing;
32 }
33 
35 {
36  m_editing = Editing;
38 }
39 
41 {
42  if (Enable)
43  m_positionUpdateTimer.start();
44  else
45  m_positionUpdateTimer.stop();
46 }
47 
57 {
58  m_osdLock.lock();
60  {
61  osdInfo info;
62  UpdateSliderInfo(info);
65  }
66  else
67  {
69  }
70  m_osdLock.unlock();
71 }
72 
73 void MythPlayerOverlayUI::UpdateOSDMessage(const QString& Message)
74 {
76 }
77 
78 void MythPlayerOverlayUI::UpdateOSDMessage(const QString& Message, OSDTimeout Timeout)
79 {
80  m_osdLock.lock();
81  InfoMap map;
82  map.insert("message_text", Message);
83  m_osd.SetText(OSD_WIN_MESSAGE, map, Timeout);
84  m_osdLock.unlock();
85 }
86 
88 {
89  m_osdLock.lock();
90  osdInfo info;
91  UpdateSliderInfo(info);
92  info.text.insert("title", title);
95  m_osdLock.unlock();
96 }
97 
99 {
100  m_osdLock.lock();
102  m_osd.SetValues(OSD_WIN_STATUS, Info.values, Timeout);
103  m_osd.SetText(OSD_WIN_STATUS, Info.text, Timeout);
104  if (Type != kOSDFunctionalType_Default)
106  m_osdLock.unlock();
107 }
108 
109 void MythPlayerOverlayUI::UpdateOSDStatus(const QString& Title, const QString& Desc,
110  const QString& Value, int Type, const QString& Units,
111  int Position, OSDTimeout Timeout)
112 {
113  osdInfo info;
114  info.values.insert("position", Position);
115  info.values.insert("relposition", Position);
116  info.text.insert("title", Title);
117  info.text.insert("description", Desc);
118  info.text.insert("value", Value);
119  info.text.insert("units", Units);
120  UpdateOSDStatus(info, Type, Timeout);
121 }
122 
123 void MythPlayerOverlayUI::UpdateSliderInfo(osdInfo &Info, bool PaddedFields)
124 {
125  if (!m_decoder)
126  return;
127 
128  bool islive = false;
129  Info.text.insert("chapteridx", QString());
130  Info.text.insert("totalchapters", QString());
131  Info.text.insert("titleidx", QString());
132  Info.text.insert("totaltitles", QString());
133  Info.text.insert("angleidx", QString());
134  Info.text.insert("totalangles", QString());
135  Info.values.insert("position", 0);
136  Info.values.insert("progbefore", 0);
137  Info.values.insert("progafter", 0);
138 
139  std::chrono::seconds playbackLen = 0s;
140  bool fixed_playbacklen = false;
141 
143  {
144  Info.values["progbefore"] = static_cast<int>(m_playerCtx->m_tvchain->HasPrev());
145  Info.values["progafter"] = static_cast<int>(m_playerCtx->m_tvchain->HasNext());
146  playbackLen = m_playerCtx->m_tvchain->GetLengthAtCurPos();
147  islive = true;
148  fixed_playbacklen = true;
149  }
150  else if (IsWatchingInprogress())
151  {
152  islive = true;
153  }
154  else
155  {
156  int chapter = GetCurrentChapter();
157  int chapters = GetNumChapters();
158  if (chapter && chapters > 1)
159  {
160  Info.text["chapteridx"] = QString::number(chapter + 1);
161  Info.text["totalchapters"] = QString::number(chapters);
162  }
163 
164  int title = GetCurrentTitle();
165  int titles = GetNumTitles();
166  if (title && titles > 1)
167  {
168  Info.text["titleidx"] = QString::number(title + 1);
169  Info.text["totaltitles"] = QString::number(titles);
170  }
171 
172  int angle = GetCurrentAngle();
173  int angles = GetNumAngles();
174  if (angle && angles > 1)
175  {
176  Info.text["angleidx"] = QString::number(angle + 1);
177  Info.text["totalangles"] = QString::number(angles);
178  }
179  }
180 
181  // Set the raw values, followed by the translated values.
182  for (int i = 0; i < 2 ; ++i)
183  {
184  bool honorCutList = (i > 0);
185  bool stillFrame = false;
186  int pos = 0;
187 
188  QString relPrefix = (honorCutList ? "rel" : "");
189  if (!fixed_playbacklen)
190  playbackLen = GetTotalSeconds(honorCutList);
191  std::chrono::seconds secsplayed = GetSecondsPlayed(honorCutList);
192 
193  stillFrame = (secsplayed < 0s);
194  playbackLen = std::max(playbackLen, 0s);
195  secsplayed = std::clamp(secsplayed, 0s, playbackLen);
196  std::chrono::seconds secsbehind = std::max((playbackLen - secsplayed), 0s);
197 
198  if (playbackLen > 0s)
199  pos = static_cast<int>(1000.0F * secsplayed.count() / playbackLen.count());
200 
201  Info.values.insert(relPrefix + "secondsplayed", secsplayed.count());
202  Info.values.insert(relPrefix + "totalseconds", playbackLen.count());
203  Info.values[relPrefix + "position"] = pos;
204 
205  QString text1;
206  QString text2;
207  QString text3;
208  if (PaddedFields)
209  {
210  text1 = MythFormatTime(secsplayed, "HH:mm:ss");
211  text2 = MythFormatTime(playbackLen, "HH:mm:ss");
212  text3 = MythFormatTime(secsbehind, "HH:mm:ss");
213  }
214  else
215  {
216  QString fmt = (playbackLen >= 1h) ? "H:mm:ss" : "m:ss";
217  text1 = MythFormatTime(secsplayed, fmt);
218  text2 = MythFormatTime(playbackLen, fmt);
219 
220  if (secsbehind >= 1h)
221  text3 = MythFormatTime(secsbehind, "H:mm:ss");
222  else if (secsbehind >= 1min)
223  text3 = MythFormatTime(secsbehind, "m:ss");
224  else
225  text3 = tr("%n second(s)", "", secsbehind.count());
226  }
227 
228  QString desc = stillFrame ? tr("Still Frame") : tr("%1 of %2").arg(text1).arg(text2);
229  Info.text[relPrefix + "description"] = desc;
230  Info.text[relPrefix + "playedtime"] = text1;
231  Info.text[relPrefix + "totaltime"] = text2;
232  Info.text[relPrefix + "remainingtime"] = islive ? QString() : text3;
233  Info.text[relPrefix + "behindtime"] = islive ? text3 : QString();
234  }
235 }
236 
237 std::chrono::milliseconds MythPlayerOverlayUI::GetMillisecondsPlayed(bool HonorCutList)
238 {
239  std::chrono::milliseconds pos = TranslatePositionFrameToMs(m_framesPlayed, HonorCutList);
240  LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("GetSecondsPlayed: framesPlayed %1, honorCutList %2, pos %3")
241  .arg(m_framesPlayed).arg(HonorCutList).arg(pos.count()));
242  return pos;
243 }
244 
245 std::chrono::milliseconds MythPlayerOverlayUI::GetTotalMilliseconds(bool HonorCutList) const
246 {
247  uint64_t pos = IsWatchingInprogress() ? UINT64_MAX : m_totalFrames;
248  return TranslatePositionFrameToMs(pos, HonorCutList);
249 }
MythPlayerOverlayUI::GetSecondsPlayed
std::chrono::seconds GetSecondsPlayed(bool HonorCutList)
Definition: mythplayeroverlayui.h:42
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
osdInfo
Definition: playercontext.h:33
TVPlaybackState::OverlayStateChanged
void OverlayStateChanged(MythOverlayState OverlayState)
Definition: tvplaybackstate.cpp:18
LiveTVChain::HasNext
bool HasNext(void) const
Definition: livetvchain.cpp:405
MythPlayer::GetNumAngles
virtual int GetNumAngles(void) const
Definition: mythplayer.h:228
OSD::IsWindowVisible
bool IsWindowVisible(const QString &Window)
Definition: osd.cpp:614
title
QString title
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:636
MythPlayerOverlayUI::BrowsingChanged
void BrowsingChanged(bool Browsing)
Definition: mythplayeroverlayui.cpp:28
TVPlaybackState::ChangeOSDMessage
void ChangeOSDMessage(const QString &Message)
MythPlayer::GetNumTitles
virtual int GetNumTitles(void) const
Definition: mythplayer.h:222
OSD::ResetWindow
void ResetWindow(const QString &Window)
Definition: osd.cpp:622
arg
arg(title).arg(filename).arg(doDelete))
MythPlayerOverlayUI::GetTotalMilliseconds
virtual std::chrono::milliseconds GetTotalMilliseconds(bool HonorCutList) const
Definition: mythplayeroverlayui.cpp:245
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
OSD::HideAll
void HideAll(bool KeepSubs=true, MythScreenType *Except=nullptr, bool DropNotification=false)
Definition: osd.cpp:89
OSD::SetText
void SetText(const QString &Window, const InfoMap &Map, OSDTimeout Timeout)
Definition: osd.cpp:204
MythPlayerOverlayUI::GetTotalSeconds
std::chrono::seconds GetTotalSeconds(bool HonorCutList) const
Definition: mythplayeroverlayui.h:44
MythPlayerOverlayUI::EditingChanged
void EditingChanged(bool Editing)
Definition: mythplayeroverlayui.cpp:34
PlayerFlags
PlayerFlags
Definition: mythplayer.h:62
MythPlayerOverlayUI::SetOSDStatus
void SetOSDStatus(const QString &Title, OSDTimeout Timeout)
Definition: mythplayeroverlayui.cpp:87
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
MythPlayerOverlayUI::UpdateOSDMessage
void UpdateOSDMessage(const QString &Message)
Definition: mythplayeroverlayui.cpp:73
MythPlayer::m_decoder
DecoderBase * m_decoder
Definition: mythplayer.h:367
MythPlayer::m_framesPlayed
uint64_t m_framesPlayed
Definition: mythplayer.h:429
MythPlayerOverlayUI::OverlayStateChanged
void OverlayStateChanged(MythOverlayState OverlayState)
MythPlayerOverlayUI::GetMillisecondsPlayed
virtual std::chrono::milliseconds GetMillisecondsPlayed(bool HonorCutList)
Definition: mythplayeroverlayui.cpp:237
OSDTimeout
OSDTimeout
Definition: osd.h:56
LOC
#define LOC
Definition: mythplayeroverlayui.cpp:8
kOSDFunctionalType_Default
@ kOSDFunctionalType_Default
Definition: osd.h:47
osdInfo::values
QHash< QString, int > values
Definition: playercontext.h:36
MythPlayerOverlayUI::ChangeOSDPositionUpdates
void ChangeOSDPositionUpdates(bool Enable)
Definition: mythplayeroverlayui.cpp:40
MythPlayerOverlayUI::m_editing
bool m_editing
Definition: mythplayeroverlayui.h:50
osdInfo::text
InfoMap text
Definition: playercontext.h:35
mythplayeroverlayui.h
MythPlayerOverlayUI::UpdateOSDPosition
void UpdateOSDPosition()
Update the OSD status/position window.
Definition: mythplayeroverlayui.cpp:56
OSD_WIN_STATUS
#define OSD_WIN_STATUS
Definition: osd.h:33
MythPlayerOverlayUI::MythPlayerOverlayUI
MythPlayerOverlayUI(MythMainWindow *MainWindow, TV *Tv, PlayerContext *Context, PlayerFlags Flags)
Definition: mythplayeroverlayui.cpp:11
clamp
float clamp(float val, float minimum, float maximum)
Definition: mythmiscutil.h:59
TVPlaybackState::HideAll
void HideAll(bool KeepSubs=true, MythScreenType *Except=nullptr, bool DropNotification=false)
MythPlayer::m_totalFrames
uint64_t m_totalFrames
Definition: mythplayer.h:430
MythPlayerOverlayUI::m_browsing
bool m_browsing
Definition: mythplayeroverlayui.h:49
TVPlaybackState::DialogQuit
void DialogQuit()
OSD::SetFunctionalWindow
void SetFunctionalWindow(const QString &Window, enum OSDFunctionalType Type)
Definition: osd.cpp:653
MythPlayer::m_playerCtx
PlayerContext * m_playerCtx
Definition: mythplayer.h:371
kOSDTimeout_Ignore
@ kOSDTimeout_Ignore
Definition: osd.h:58
MythPlayerOverlayUI::m_positionUpdateTimer
QTimer m_positionUpdateTimer
Definition: mythplayeroverlayui.h:57
MythPlayer::GetCurrentAngle
virtual int GetCurrentAngle(void) const
Definition: mythplayer.h:229
MythPlayerOverlayUI::m_osd
OSD m_osd
Definition: mythplayeroverlayui.h:45
MythFormatTime
QString MythFormatTime(std::chrono::milliseconds msecs, const QString &fmt)
Format a milliseconds time value.
Definition: mythmiscutil.cpp:1235
PlayerContext::m_tvchain
LiveTVChain * m_tvchain
Definition: playercontext.h:114
MythPlayer::TranslatePositionFrameToMs
std::chrono::milliseconds TranslatePositionFrameToMs(uint64_t position, bool use_cutlist) const
Definition: mythplayer.cpp:1807
MythPlayer::GetNumChapters
virtual int GetNumChapters(void)
Definition: mythplayer.cpp:1823
MythPlayer::GetCurrentTitle
virtual int GetCurrentTitle(void) const
Definition: mythplayer.h:223
livetvchain.h
MythPlayer::m_liveTV
bool m_liveTV
Definition: mythplayer.h:407
MythPlayer::IsWatchingInprogress
bool IsWatchingInprogress(void) const
Definition: mythplayer.cpp:133
MythPlayerUIBase::m_tv
TV * m_tv
Definition: mythplayeruibase.h:18
OSD::DialogQuit
void DialogQuit()
Definition: osd.cpp:706
OSD_WIN_MESSAGE
#define OSD_WIN_MESSAGE
Definition: osd.h:30
PlayerContext
Definition: playercontext.h:48
MythPlayerOverlayUI::UpdateOSDStatus
void UpdateOSDStatus(osdInfo &Info, int Type, enum OSDTimeout Timeout)
Definition: mythplayeroverlayui.cpp:98
OSD::SetValues
void SetValues(const QString &Window, const QHash< QString, int > &Map, OSDTimeout Timeout)
Definition: osd.cpp:146
OSDFunctionalType
OSDFunctionalType
Definition: osd.h:45
LiveTVChain::GetLengthAtCurPos
std::chrono::seconds GetLengthAtCurPos(void)
Definition: livetvchain.cpp:360
LiveTVChain::HasPrev
bool HasPrev(void) const
Definition: livetvchain.h:61
kOSDTimeout_Med
@ kOSDTimeout_Med
Definition: osd.h:61
MythPlayerOverlayUI::UpdateSliderInfo
virtual void UpdateSliderInfo(osdInfo &Info, bool PaddedFields=false)
Definition: mythplayeroverlayui.cpp:123
MythMainWindow
Definition: mythmainwindow.h:35
MythPlayerUIBase
Definition: mythplayeruibase.h:7
tv_play.h
MythPlayer::GetCurrentChapter
virtual int GetCurrentChapter(void)
Definition: mythplayer.cpp:1830
TV
Control TV playback.
Definition: tv_play.h:152
MythPlayerOverlayUI::m_osdLock
QMutex m_osdLock
Definition: mythplayeroverlayui.h:48