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  connect(m_tv, &TV::EmbedPlayback, &m_osd, &OSD::Embed);
27 }
28 
30 {
31  m_browsing = Browsing;
33 }
34 
36 {
37  m_editing = Editing;
39 }
40 
42 {
43  if (Enable)
44  m_positionUpdateTimer.start();
45  else
46  m_positionUpdateTimer.stop();
47 }
48 
58 {
59  m_osdLock.lock();
61  {
62  osdInfo info;
63  UpdateSliderInfo(info);
66  }
67  else
68  {
70  }
71  m_osdLock.unlock();
72 }
73 
74 void MythPlayerOverlayUI::UpdateOSDMessage(const QString& Message)
75 {
77 }
78 
79 void MythPlayerOverlayUI::UpdateOSDMessage(const QString& Message, OSDTimeout Timeout)
80 {
81  m_osdLock.lock();
82  InfoMap map;
83  map.insert("message_text", Message);
84  m_osd.SetText(OSD_WIN_MESSAGE, map, Timeout);
85  m_osdLock.unlock();
86 }
87 
89 {
90  m_osdLock.lock();
91  osdInfo info;
92  UpdateSliderInfo(info);
93  info.text.insert("title", title);
96  m_osdLock.unlock();
97 }
98 
100 {
101  m_osdLock.lock();
103  m_osd.SetValues(OSD_WIN_STATUS, Info.values, Timeout);
104  m_osd.SetText(OSD_WIN_STATUS, Info.text, Timeout);
105  if (Type != kOSDFunctionalType_Default)
107  m_osdLock.unlock();
108 }
109 
110 void MythPlayerOverlayUI::UpdateOSDStatus(const QString& Title, const QString& Desc,
111  const QString& Value, int Type, const QString& Units,
112  int Position, OSDTimeout Timeout)
113 {
114  osdInfo info;
115  info.values.insert("position", Position);
116  info.values.insert("relposition", Position);
117  info.text.insert("title", Title);
118  info.text.insert("description", Desc);
119  info.text.insert("value", Value);
120  info.text.insert("units", Units);
121  UpdateOSDStatus(info, Type, Timeout);
122 }
123 
124 void MythPlayerOverlayUI::UpdateSliderInfo(osdInfo &Info, bool PaddedFields)
125 {
126  if (!m_decoder)
127  return;
128 
129  bool islive = false;
130  Info.text.insert("chapteridx", QString());
131  Info.text.insert("totalchapters", QString());
132  Info.text.insert("titleidx", QString());
133  Info.text.insert("totaltitles", QString());
134  Info.text.insert("angleidx", QString());
135  Info.text.insert("totalangles", QString());
136  Info.values.insert("position", 0);
137  Info.values.insert("progbefore", 0);
138  Info.values.insert("progafter", 0);
139 
140  std::chrono::seconds playbackLen = 0s;
141  bool fixed_playbacklen = false;
142 
144  {
145  Info.values["progbefore"] = static_cast<int>(m_playerCtx->m_tvchain->HasPrev());
146  Info.values["progafter"] = static_cast<int>(m_playerCtx->m_tvchain->HasNext());
147  playbackLen = m_playerCtx->m_tvchain->GetLengthAtCurPos();
148  islive = true;
149  fixed_playbacklen = true;
150  }
151  else if (IsWatchingInprogress())
152  {
153  islive = true;
154  }
155  else
156  {
157  int chapter = GetCurrentChapter();
158  int chapters = GetNumChapters();
159  if (chapter && chapters > 1)
160  {
161  Info.text["chapteridx"] = QString::number(chapter + 1);
162  Info.text["totalchapters"] = QString::number(chapters);
163  }
164 
165  int title = GetCurrentTitle();
166  int titles = GetNumTitles();
167  if (title && titles > 1)
168  {
169  Info.text["titleidx"] = QString::number(title + 1);
170  Info.text["totaltitles"] = QString::number(titles);
171  }
172 
173  int angle = GetCurrentAngle();
174  int angles = GetNumAngles();
175  if (angle && angles > 1)
176  {
177  Info.text["angleidx"] = QString::number(angle + 1);
178  Info.text["totalangles"] = QString::number(angles);
179  }
180  }
181 
182  // Set the raw values, followed by the translated values.
183  for (int i = 0; i < 2 ; ++i)
184  {
185  bool honorCutList = (i > 0);
186  bool stillFrame = false;
187  int pos = 0;
188 
189  QString relPrefix = (honorCutList ? "rel" : "");
190  if (!fixed_playbacklen)
191  playbackLen = GetTotalSeconds(honorCutList);
192  std::chrono::seconds secsplayed = GetSecondsPlayed(honorCutList);
193 
194  stillFrame = (secsplayed < 0s);
195  playbackLen = std::max(playbackLen, 0s);
196  secsplayed = std::clamp(secsplayed, 0s, playbackLen);
197  std::chrono::seconds secsbehind = std::max((playbackLen - secsplayed), 0s);
198 
199  if (playbackLen > 0s)
200  pos = static_cast<int>(1000.0F * secsplayed.count() / playbackLen.count());
201 
202  Info.values.insert(relPrefix + "secondsplayed", static_cast<int>(secsplayed.count()));
203  Info.values.insert(relPrefix + "totalseconds", static_cast<int>(playbackLen.count()));
204  Info.values[relPrefix + "position"] = pos;
205 
206  QString text1;
207  QString text2;
208  QString text3;
209  if (PaddedFields)
210  {
211  text1 = MythFormatTime(secsplayed, "HH:mm:ss");
212  text2 = MythFormatTime(playbackLen, "HH:mm:ss");
213  text3 = MythFormatTime(secsbehind, "HH:mm:ss");
214  }
215  else
216  {
217  QString fmt = (playbackLen >= 1h) ? "H:mm:ss" : "m:ss";
218  text1 = MythFormatTime(secsplayed, fmt);
219  text2 = MythFormatTime(playbackLen, fmt);
220 
221  if (secsbehind >= 1h)
222  text3 = MythFormatTime(secsbehind, "H:mm:ss");
223  else if (secsbehind >= 1min)
224  text3 = MythFormatTime(secsbehind, "m:ss");
225  else
226  text3 = tr("%n second(s)", "", static_cast<int>(secsbehind.count()));
227  }
228 
229  QString desc = stillFrame ? tr("Still Frame") : tr("%1 of %2").arg(text1, text2);
230  Info.text[relPrefix + "description"] = desc;
231  Info.text[relPrefix + "playedtime"] = text1;
232  Info.text[relPrefix + "totaltime"] = text2;
233  Info.text[relPrefix + "remainingtime"] = islive ? QString() : text3;
234  Info.text[relPrefix + "behindtime"] = islive ? text3 : QString();
235  }
236 }
237 
238 std::chrono::milliseconds MythPlayerOverlayUI::GetMillisecondsPlayed(bool HonorCutList)
239 {
240  std::chrono::milliseconds pos = TranslatePositionFrameToMs(m_framesPlayed, HonorCutList);
241  LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("GetSecondsPlayed: framesPlayed %1, honorCutList %2, pos %3")
242  .arg(m_framesPlayed).arg(HonorCutList).arg(pos.count()));
243  return pos;
244 }
245 
246 std::chrono::seconds MythPlayerOverlayUI::GetSecondsPlayed(bool HonorCutList)
247 {
248  return duration_cast<std::chrono::seconds>(GetMillisecondsPlayed(HonorCutList));
249 }
250 
251 std::chrono::milliseconds MythPlayerOverlayUI::GetTotalMilliseconds(bool HonorCutList) const
252 {
253  uint64_t pos = IsWatchingInprogress() ? UINT64_MAX : m_totalFrames;
254  return TranslatePositionFrameToMs(pos, HonorCutList);
255 }
256 
257 std::chrono::seconds MythPlayerOverlayUI::GetTotalSeconds(bool HonorCutList) const
258 {
259  return duration_cast<std::chrono::seconds>(GetTotalMilliseconds(HonorCutList));
260 }
261 
262 
MythPlayerOverlayUI::GetSecondsPlayed
std::chrono::seconds GetSecondsPlayed(bool HonorCutList)
Definition: mythplayeroverlayui.cpp:246
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
osdInfo
Definition: playercontext.h:37
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:229
OSD::IsWindowVisible
bool IsWindowVisible(const QString &Window)
Definition: osd.cpp:622
MythPlayerOverlayUI::BrowsingChanged
void BrowsingChanged(bool Browsing)
Definition: mythplayeroverlayui.cpp:29
TVPlaybackState::ChangeOSDMessage
void ChangeOSDMessage(const QString &Message)
MythPlayer::GetNumTitles
virtual int GetNumTitles(void) const
Definition: mythplayer.h:223
OSD::ResetWindow
void ResetWindow(const QString &Window)
Definition: osd.cpp:630
MythPlayerOverlayUI::GetTotalMilliseconds
virtual std::chrono::milliseconds GetTotalMilliseconds(bool HonorCutList) const
Definition: mythplayeroverlayui.cpp:251
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:94
OSD::SetText
void SetText(const QString &Window, const InfoMap &Map, OSDTimeout Timeout)
Definition: osd.cpp:209
MythPlayerOverlayUI::GetTotalSeconds
std::chrono::seconds GetTotalSeconds(bool HonorCutList) const
Definition: mythplayeroverlayui.cpp:257
MythPlayerOverlayUI::EditingChanged
void EditingChanged(bool Editing)
Definition: mythplayeroverlayui.cpp:35
PlayerFlags
PlayerFlags
Definition: mythplayer.h:65
MythPlayerOverlayUI::SetOSDStatus
void SetOSDStatus(const QString &Title, OSDTimeout Timeout)
Definition: mythplayeroverlayui.cpp:88
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
MythPlayerOverlayUI::UpdateOSDMessage
void UpdateOSDMessage(const QString &Message)
Definition: mythplayeroverlayui.cpp:74
MythPlayer::m_decoder
DecoderBase * m_decoder
Definition: mythplayer.h:366
MythPlayer::m_framesPlayed
uint64_t m_framesPlayed
Definition: mythplayer.h:432
MythPlayerOverlayUI::OverlayStateChanged
void OverlayStateChanged(MythOverlayState OverlayState)
MythPlayerOverlayUI::GetMillisecondsPlayed
virtual std::chrono::milliseconds GetMillisecondsPlayed(bool HonorCutList)
Definition: mythplayeroverlayui.cpp:238
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:40
MythPlayerOverlayUI::ChangeOSDPositionUpdates
void ChangeOSDPositionUpdates(bool Enable)
Definition: mythplayeroverlayui.cpp:41
MythPlayerOverlayUI::m_editing
bool m_editing
Definition: mythplayeroverlayui.h:52
osdInfo::text
InfoMap text
Definition: playercontext.h:39
mythplayeroverlayui.h
MythPlayerOverlayUI::UpdateOSDPosition
void UpdateOSDPosition()
Update the OSD status/position window.
Definition: mythplayeroverlayui.cpp:57
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:56
TVPlaybackState::HideAll
void HideAll(bool KeepSubs=true, MythScreenType *Except=nullptr, bool DropNotification=false)
MythPlayer::m_totalFrames
uint64_t m_totalFrames
Definition: mythplayer.h:433
MythPlayerOverlayUI::m_browsing
bool m_browsing
Definition: mythplayeroverlayui.h:51
TVPlaybackState::DialogQuit
void DialogQuit()
OSD::SetFunctionalWindow
void SetFunctionalWindow(const QString &Window, enum OSDFunctionalType Type)
Definition: osd.cpp:661
MythPlayer::m_playerCtx
PlayerContext * m_playerCtx
Definition: mythplayer.h:374
kOSDTimeout_Ignore
@ kOSDTimeout_Ignore
Definition: osd.h:58
MythPlayerOverlayUI::m_positionUpdateTimer
QTimer m_positionUpdateTimer
Definition: mythplayeroverlayui.h:58
MythPlayer::GetCurrentAngle
virtual int GetCurrentAngle(void) const
Definition: mythplayer.h:230
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:118
MythPlayer::TranslatePositionFrameToMs
std::chrono::milliseconds TranslatePositionFrameToMs(uint64_t position, bool use_cutlist) const
Definition: mythplayer.cpp:1834
MythPlayer::GetNumChapters
virtual int GetNumChapters(void)
Definition: mythplayer.cpp:1850
MythPlayer::GetCurrentTitle
virtual int GetCurrentTitle(void) const
Definition: mythplayer.h:224
livetvchain.h
MythPlayer::m_liveTV
bool m_liveTV
Definition: mythplayer.h:410
MythPlayer::IsWatchingInprogress
bool IsWatchingInprogress(void) const
Definition: mythplayer.cpp:133
MythPlayerOverlayUI::m_osdLock
QRecursiveMutex m_osdLock
Definition: mythplayeroverlayui.h:49
MythPlayerUIBase::m_tv
TV * m_tv
Definition: mythplayeruibase.h:18
TVPlaybackState::EmbedPlayback
void EmbedPlayback(bool Embed, const QRect &Rect={})
OSD::DialogQuit
void DialogQuit()
Definition: osd.cpp:714
OSD_WIN_MESSAGE
#define OSD_WIN_MESSAGE
Definition: osd.h:30
PlayerContext
Definition: playercontext.h:52
MythPlayerOverlayUI::UpdateOSDStatus
void UpdateOSDStatus(osdInfo &Info, int Type, enum OSDTimeout Timeout)
Definition: mythplayeroverlayui.cpp:99
OSD::SetValues
void SetValues(const QString &Window, const QHash< QString, int > &Map, OSDTimeout Timeout)
Definition: osd.cpp:151
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:64
kOSDTimeout_Med
@ kOSDTimeout_Med
Definition: osd.h:61
OSD::Embed
void Embed(bool Embedding)
Definition: osd.cpp:77
MythPlayerOverlayUI::UpdateSliderInfo
virtual void UpdateSliderInfo(osdInfo &Info, bool PaddedFields=false)
Definition: mythplayeroverlayui.cpp:124
MythMainWindow
Definition: mythmainwindow.h:35
MythPlayerUIBase
Definition: mythplayeruibase.h:7
tv_play.h
MythPlayer::GetCurrentChapter
virtual int GetCurrentChapter(void)
Definition: mythplayer.cpp:1857
TV
Control TV playback.
Definition: tv_play.h:154