MythTV  master
mythplayeroverlayui.cpp
Go to the documentation of this file.
1 #include <chrono>
2 
3 // MythTV
4 #include "libmythbase/mythdate.h"
5 
6 #include "tv_play.h"
7 #include "livetvchain.h"
8 #include "mythplayeroverlayui.h"
9 
10 #define LOC QString("PlayerOverlay: ")
11 
12 // N.B. Overlay is initialised without a player - it must be set before it can be used
14  : MythPlayerUIBase(MainWindow, Tv, Context, Flags),
15  m_osd(MainWindow, Tv, nullptr, m_painter)
16 {
17  // Register our state type for signalling
18  qRegisterMetaType<MythOverlayState>();
19 
20  m_positionUpdateTimer.setInterval(999ms);
23  connect(m_tv, &TV::ChangeOSDMessage, this, qOverload<const QString&>(&MythPlayerOverlayUI::UpdateOSDMessage));
24 
25  // Signalled directly from TV to OSD
27  connect(m_tv, &TV::HideAll, &m_osd, &OSD::HideAll);
28  connect(m_tv, &TV::EmbedPlayback, &m_osd, &OSD::Embed);
29 }
30 
32 {
33  m_browsing = Browsing;
35 }
36 
38 {
39  m_editing = Editing;
41 }
42 
44 {
45  if (Enable)
46  m_positionUpdateTimer.start();
47  else
48  m_positionUpdateTimer.stop();
49 }
50 
60 {
61  m_osdLock.lock();
63  {
64  osdInfo info;
65  UpdateSliderInfo(info);
68  }
69  else
70  {
72  }
73  m_osdLock.unlock();
74 }
75 
76 void MythPlayerOverlayUI::UpdateOSDMessage(const QString& Message)
77 {
79 }
80 
81 void MythPlayerOverlayUI::UpdateOSDMessage(const QString& Message, OSDTimeout Timeout)
82 {
83  m_osdLock.lock();
84  InfoMap map;
85  map.insert("message_text", Message);
86  m_osd.SetText(OSD_WIN_MESSAGE, map, Timeout);
87  m_osdLock.unlock();
88 }
89 
91 {
92  m_osdLock.lock();
93  osdInfo info;
94  UpdateSliderInfo(info);
95  info.text.insert("title", title);
98  m_osdLock.unlock();
99 }
100 
102 {
103  m_osdLock.lock();
105  m_osd.SetValues(OSD_WIN_STATUS, Info.values, Timeout);
106  m_osd.SetText(OSD_WIN_STATUS, Info.text, Timeout);
107  if (Type != kOSDFunctionalType_Default)
109  m_osdLock.unlock();
110 }
111 
112 void MythPlayerOverlayUI::UpdateOSDStatus(const QString& Title, const QString& Desc,
113  const QString& Value, int Type, const QString& Units,
114  int Position, OSDTimeout Timeout)
115 {
116  osdInfo info;
117  info.values.insert("position", Position);
118  info.values.insert("relposition", Position);
119  info.text.insert("title", Title);
120  info.text.insert("description", Desc);
121  info.text.insert("value", Value);
122  info.text.insert("units", Units);
123  UpdateOSDStatus(info, Type, Timeout);
124 }
125 
126 void MythPlayerOverlayUI::UpdateSliderInfo(osdInfo &Info, bool PaddedFields)
127 {
128  if (!m_decoder)
129  return;
130 
131  bool islive = false;
132  Info.text.insert("chapteridx", QString());
133  Info.text.insert("totalchapters", QString());
134  Info.text.insert("titleidx", QString());
135  Info.text.insert("totaltitles", QString());
136  Info.text.insert("angleidx", QString());
137  Info.text.insert("totalangles", QString());
138  Info.values.insert("position", 0);
139  Info.values.insert("progbefore", 0);
140  Info.values.insert("progafter", 0);
141 
142  std::chrono::seconds playbackLen = 0s;
143  bool fixed_playbacklen = false;
144 
146  {
147  Info.values["progbefore"] = static_cast<int>(m_playerCtx->m_tvchain->HasPrev());
148  Info.values["progafter"] = static_cast<int>(m_playerCtx->m_tvchain->HasNext());
149  playbackLen = m_playerCtx->m_tvchain->GetLengthAtCurPos();
150  islive = true;
151  fixed_playbacklen = true;
152  }
153  else if (IsWatchingInprogress())
154  {
155  islive = true;
156  }
157  else
158  {
159  int chapter = GetCurrentChapter();
160  int chapters = GetNumChapters();
161  if (chapter && chapters > 1)
162  {
163  Info.text["chapteridx"] = QString::number(chapter + 1);
164  Info.text["totalchapters"] = QString::number(chapters);
165  }
166 
167  int title = GetCurrentTitle();
168  int titles = GetNumTitles();
169  if (title && titles > 1)
170  {
171  Info.text["titleidx"] = QString::number(title + 1);
172  Info.text["totaltitles"] = QString::number(titles);
173  }
174 
175  int angle = GetCurrentAngle();
176  int angles = GetNumAngles();
177  if (angle && angles > 1)
178  {
179  Info.text["angleidx"] = QString::number(angle + 1);
180  Info.text["totalangles"] = QString::number(angles);
181  }
182  }
183 
184  // Set the raw values, followed by the translated values.
185  for (int i = 0; i < 2 ; ++i)
186  {
187  bool honorCutList = (i > 0);
188  bool stillFrame = false;
189  int pos = 0;
190 
191  QString relPrefix = (honorCutList ? "rel" : "");
192  if (!fixed_playbacklen)
193  playbackLen = GetTotalSeconds(honorCutList);
194  std::chrono::seconds secsplayed = GetSecondsPlayed(honorCutList);
195 
196  stillFrame = (secsplayed < 0s);
197  playbackLen = std::max(playbackLen, 0s);
198  secsplayed = std::clamp(secsplayed, 0s, playbackLen);
199  std::chrono::seconds secsbehind = std::max((playbackLen - secsplayed), 0s);
200 
201  if (playbackLen > 0s)
202  pos = static_cast<int>(1000.0F * secsplayed.count() / playbackLen.count());
203 
204  Info.values.insert(relPrefix + "secondsplayed", static_cast<int>(secsplayed.count()));
205  Info.values.insert(relPrefix + "totalseconds", static_cast<int>(playbackLen.count()));
206  Info.values[relPrefix + "position"] = pos;
207 
208  QString text1;
209  QString text2;
210  QString text3;
211  if (PaddedFields)
212  {
213  text1 = MythDate::formatTime(secsplayed, "HH:mm:ss");
214  text2 = MythDate::formatTime(playbackLen, "HH:mm:ss");
215  text3 = MythDate::formatTime(secsbehind, "HH:mm:ss");
216  }
217  else
218  {
219  QString fmt = (playbackLen >= 1h) ? "H:mm:ss" : "m:ss";
220  text1 = MythDate::formatTime(secsplayed, fmt);
221  text2 = MythDate::formatTime(playbackLen, fmt);
222 
223  if (secsbehind >= 1h)
224  text3 = MythDate::formatTime(secsbehind, "H:mm:ss");
225  else if (secsbehind >= 1min)
226  text3 = MythDate::formatTime(secsbehind, "m:ss");
227  else
228  text3 = tr("%n second(s)", "", static_cast<int>(secsbehind.count()));
229  }
230 
231  QString desc = stillFrame ? tr("Still Frame") : tr("%1 of %2").arg(text1, text2);
232  Info.text[relPrefix + "description"] = desc;
233  Info.text[relPrefix + "playedtime"] = text1;
234  Info.text[relPrefix + "totaltime"] = text2;
235  Info.text[relPrefix + "remainingtime"] = islive ? QString() : text3;
236  Info.text[relPrefix + "behindtime"] = islive ? text3 : QString();
237  QString dtformat = gCoreContext->GetSetting("DateFormat", "ddd MMMM d yyyy")
238  + ", " + gCoreContext->GetSetting("TimeFormat", "hh:mm");
239 
241  {
242  QDateTime recordedtime =
243  m_playerCtx->m_playingRecStart.addSecs(static_cast<qint64>(secsplayed.count()));
244  Info.text[relPrefix + "recordedtime"] = recordedtime.toLocalTime().toString(dtformat);
245  }
246 
247  if (i == 0)
248  {
249  LOG(VB_OSD, LOG_INFO, LOC +
250  QString(" playbackLen:%1").arg(playbackLen.count()) +
251  QString(" secsplayed:%1").arg(secsplayed.count()));
252  }
253  }
254 }
255 
256 std::chrono::milliseconds MythPlayerOverlayUI::GetMillisecondsPlayed(bool HonorCutList)
257 {
258  std::chrono::milliseconds pos = TranslatePositionFrameToMs(m_framesPlayed, HonorCutList);
259  LOG(VB_PLAYBACK, LOG_DEBUG, LOC + QString("GetSecondsPlayed: framesPlayed %1, honorCutList %2, pos %3")
260  .arg(m_framesPlayed).arg(HonorCutList).arg(pos.count()));
261  return pos;
262 }
263 
264 std::chrono::seconds MythPlayerOverlayUI::GetSecondsPlayed(bool HonorCutList)
265 {
266  return duration_cast<std::chrono::seconds>(GetMillisecondsPlayed(HonorCutList));
267 }
268 
269 std::chrono::milliseconds MythPlayerOverlayUI::GetTotalMilliseconds(bool HonorCutList) const
270 {
271  uint64_t pos = IsWatchingInprogress() ? UINT64_MAX : m_totalFrames;
272  return TranslatePositionFrameToMs(pos, HonorCutList);
273 }
274 
275 std::chrono::seconds MythPlayerOverlayUI::GetTotalSeconds(bool HonorCutList) const
276 {
277  return duration_cast<std::chrono::seconds>(GetTotalMilliseconds(HonorCutList));
278 }
279 
280 
MythPlayerOverlayUI::GetSecondsPlayed
std::chrono::seconds GetSecondsPlayed(bool HonorCutList)
Definition: mythplayeroverlayui.cpp:264
PlayerContext::GetState
TVState GetState(void) const
Definition: playercontext.cpp:325
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:102
osdInfo
Definition: playercontext.h:34
TVPlaybackState::OverlayStateChanged
void OverlayStateChanged(MythOverlayState OverlayState)
Definition: tvplaybackstate.cpp:18
LiveTVChain::HasNext
bool HasNext(void) const
Definition: livetvchain.cpp:406
MythPlayer::GetNumAngles
virtual int GetNumAngles(void) const
Definition: mythplayer.h:224
OSD::IsWindowVisible
bool IsWindowVisible(const QString &Window)
Definition: osd.cpp:625
MythPlayerOverlayUI::BrowsingChanged
void BrowsingChanged(bool Browsing)
Definition: mythplayeroverlayui.cpp:31
TVPlaybackState::ChangeOSDMessage
void ChangeOSDMessage(const QString &Message)
PlayerContext::m_playingRecStart
QDateTime m_playingRecStart
Definition: playercontext.h:119
MythPlayer::GetNumTitles
virtual int GetNumTitles(void) const
Definition: mythplayer.h:218
OSD::ResetWindow
void ResetWindow(const QString &Window)
Definition: osd.cpp:633
MythDate::formatTime
QString formatTime(std::chrono::milliseconds msecs, QString fmt)
Format a milliseconds time value.
Definition: mythdate.cpp:233
MythPlayerOverlayUI::GetTotalMilliseconds
virtual std::chrono::milliseconds GetTotalMilliseconds(bool HonorCutList) const
Definition: mythplayeroverlayui.cpp:269
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
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:275
MythPlayerOverlayUI::EditingChanged
void EditingChanged(bool Editing)
Definition: mythplayeroverlayui.cpp:37
PlayerFlags
PlayerFlags
Definition: mythplayer.h:64
MythPlayerOverlayUI::SetOSDStatus
void SetOSDStatus(const QString &Title, OSDTimeout Timeout)
Definition: mythplayeroverlayui.cpp:90
OSD_WIN_MESSAGE
static constexpr const char * OSD_WIN_MESSAGE
Definition: osd.h:29
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
MythPlayerOverlayUI::UpdateOSDMessage
void UpdateOSDMessage(const QString &Message)
Definition: mythplayeroverlayui.cpp:76
OSD_WIN_STATUS
static constexpr const char * OSD_WIN_STATUS
Definition: osd.h:32
MythPlayer::m_decoder
DecoderBase * m_decoder
Definition: mythplayer.h:362
mythdate.h
MythPlayer::m_framesPlayed
uint64_t m_framesPlayed
Definition: mythplayer.h:424
MythPlayerOverlayUI::OverlayStateChanged
void OverlayStateChanged(MythOverlayState OverlayState)
MythPlayerOverlayUI::GetMillisecondsPlayed
virtual std::chrono::milliseconds GetMillisecondsPlayed(bool HonorCutList)
Definition: mythplayeroverlayui.cpp:256
OSDTimeout
OSDTimeout
Definition: osd.h:55
LOC
#define LOC
Definition: mythplayeroverlayui.cpp:10
kOSDFunctionalType_Default
@ kOSDFunctionalType_Default
Definition: osd.h:46
osdInfo::values
QHash< QString, int > values
Definition: playercontext.h:37
MythPlayerOverlayUI::ChangeOSDPositionUpdates
void ChangeOSDPositionUpdates(bool Enable)
Definition: mythplayeroverlayui.cpp:43
MythPlayerOverlayUI::m_editing
bool m_editing
Definition: mythplayeroverlayui.h:48
osdInfo::text
InfoMap text
Definition: playercontext.h:36
mythplayeroverlayui.h
MythPlayerOverlayUI::UpdateOSDPosition
void UpdateOSDPosition()
Update the OSD status/position window.
Definition: mythplayeroverlayui.cpp:59
MythPlayerOverlayUI::MythPlayerOverlayUI
MythPlayerOverlayUI(MythMainWindow *MainWindow, TV *Tv, PlayerContext *Context, PlayerFlags Flags)
Definition: mythplayeroverlayui.cpp:13
TVPlaybackState::HideAll
void HideAll(bool KeepSubs=true, MythScreenType *Except=nullptr, bool DropNotification=false)
MythPlayer::m_totalFrames
uint64_t m_totalFrames
Definition: mythplayer.h:425
MythPlayerOverlayUI::m_browsing
bool m_browsing
Definition: mythplayeroverlayui.h:47
TVPlaybackState::DialogQuit
void DialogQuit()
OSD::SetFunctionalWindow
void SetFunctionalWindow(const QString &Window, enum OSDFunctionalType Type)
Definition: osd.cpp:664
MythPlayer::m_playerCtx
PlayerContext * m_playerCtx
Definition: mythplayer.h:366
kOSDTimeout_Ignore
@ kOSDTimeout_Ignore
Definition: osd.h:57
MythPlayerOverlayUI::m_positionUpdateTimer
QTimer m_positionUpdateTimer
Definition: mythplayeroverlayui.h:54
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
MythPlayer::GetCurrentAngle
virtual int GetCurrentAngle(void) const
Definition: mythplayer.h:225
MythPlayerOverlayUI::m_osd
OSD m_osd
Definition: mythplayeroverlayui.h:45
PlayerContext::m_tvchain
LiveTVChain * m_tvchain
Definition: playercontext.h:115
MythPlayer::TranslatePositionFrameToMs
std::chrono::milliseconds TranslatePositionFrameToMs(uint64_t position, bool use_cutlist) const
Definition: mythplayer.cpp:1802
MythPlayer::GetNumChapters
virtual int GetNumChapters(void)
Definition: mythplayer.cpp:1818
MythPlayer::GetCurrentTitle
virtual int GetCurrentTitle(void) const
Definition: mythplayer.h:219
kState_WatchingPreRecorded
@ kState_WatchingPreRecorded
Watching Pre-recorded is a TV only state for when we are watching a pre-existing recording.
Definition: tv.h:67
livetvchain.h
MythPlayer::m_liveTV
bool m_liveTV
Definition: mythplayer.h:403
MythPlayer::IsWatchingInprogress
bool IsWatchingInprogress(void) const
Definition: mythplayer.cpp:130
MythPlayerOverlayUI::m_osdLock
QRecursiveMutex m_osdLock
Definition: mythplayeroverlayui.h:46
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:717
PlayerContext
Definition: playercontext.h:49
MythPlayerOverlayUI::UpdateOSDStatus
void UpdateOSDStatus(osdInfo &Info, int Type, enum OSDTimeout Timeout)
Definition: mythplayeroverlayui.cpp:101
OSD::SetValues
void SetValues(const QString &Window, const QHash< QString, int > &Map, OSDTimeout Timeout)
Definition: osd.cpp:151
OSDFunctionalType
OSDFunctionalType
Definition: osd.h:44
LiveTVChain::GetLengthAtCurPos
std::chrono::seconds GetLengthAtCurPos(void)
Definition: livetvchain.cpp:361
LiveTVChain::HasPrev
bool HasPrev(void) const
Definition: livetvchain.h:62
kOSDTimeout_Med
@ kOSDTimeout_Med
Definition: osd.h:60
OSD::Embed
void Embed(bool Embedding)
Definition: osd.cpp:77
MythPlayerOverlayUI::UpdateSliderInfo
virtual void UpdateSliderInfo(osdInfo &Info, bool PaddedFields=false)
Definition: mythplayeroverlayui.cpp:126
MythMainWindow
Definition: mythmainwindow.h:28
MythPlayerUIBase
Definition: mythplayeruibase.h:7
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:898
tv_play.h
MythPlayer::GetCurrentChapter
virtual int GetCurrentChapter(void)
Definition: mythplayer.cpp:1825
TV
Control TV playback.
Definition: tv_play.h:152