MythTV  master
mythplayervideoui.cpp
Go to the documentation of this file.
1 // MythTV
3 
4 #include "mheg/interactivetv.h"
5 #include "mythplayervideoui.h"
6 #include "mythvideooutgpu.h"
7 #include "tv_play.h"
8 
9 #define LOC QString("PlayerVideo: ")
10 
12  : MythPlayerCaptionsUI(MainWindow, Tv, Context, Flags)
13 {
14  // Register our types for signalling
15  qRegisterMetaType<MythVideoBoundsState>();
16  qRegisterMetaType<MythVideoColourState>();
19 }
20 
27 {
28  return m_interopTypes;
29 }
30 
32 {
33  if (!(m_playerCtx && m_decoder))
34  return false;
35 
40  static_cast<float>(m_videoFrameRate),
41  static_cast<uint>(m_playerFlags),
44 
45  if (!video)
46  {
47  LOG(VB_GENERAL, LOG_ERR, LOC + "Couldn't create VideoOutput instance. Exiting..");
48  SetErrored(tr("Failed to initialize video output"));
49  return false;
50  }
51 
52  // Toggle detect letter box
53  auto toggleDetectLetterbox = [&]()
54  {
55  if (m_videoOutput)
56  {
59  }
60  };
61 
62  m_videoOutput = video;
63 
64  // Inbound connections
71  connect(video, &MythVideoBounds::UpdateOSDMessage,
72  this, qOverload<const QString&>(&MythPlayerVideoUI::UpdateOSDMessage));
81  connect(m_tv, &TV::ToggleDetectLetterBox, toggleDetectLetterbox);
82 
83  // Passthrough signals
89  connect(m_tv, &TV::ChangeZoom, video, &MythVideoOutputGPU::Zoom);
98 
99  // Update initial state. MythVideoOutput will have potentially adjusted state
100  // at startup that we need to know about.
101  emit RefreshVideoState();
102  return true;
103 }
104 
106 {
107  if (Supported != m_colourState.m_supportedAttributes)
108  {
111  }
112 }
113 
115 {
116  QString text = toString(Attribute) + " " + toTypeString(kAdjustingPicture_Playback);
117  UpdateOSDStatus(toTitleString(kAdjustingPicture_Playback), text, QString::number(Value),
120  m_colourState.m_attributeValues[Attribute] = Value;
122 };
123 
124 void MythPlayerVideoUI::PictureAttributesUpdated(const std::map<PictureAttribute,int>& Values)
125 {
128 }
129 
136  void* Opaque1, void* Opaque2)
137 {
138  if (!Function)
139  return;
140 
141  m_decoderCallbackLock.lock();
142  QAtomicInt ready{0};
143  QWaitCondition wait;
144  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Queuing callback for %1").arg(Debug));
145  m_decoderCallbacks.append(DecoderCallback(Debug, Function, &ready, &wait, Opaque1, Opaque2));
146  int count = 0;
147  while (!ready && !wait.wait(&m_decoderCallbackLock, 100) && (count += 100))
148  LOG(VB_GENERAL, LOG_WARNING, QString("Waited %1ms for %2").arg(count).arg(Debug));
149  m_decoderCallbackLock.unlock();
150 }
151 
153 {
154  m_decoderCallbackLock.lock();
155  // NOLINTNEXTLINE(readability-qualified-auto) for Qt6
156  for (auto it = m_decoderCallbacks.begin(); it != m_decoderCallbacks.end(); ++it)
157  {
158  if (it->m_function)
159  {
160  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Executing %1").arg(it->m_debug));
161  it->m_function(it->m_opaque1, it->m_opaque2, it->m_opaque3);
162  }
163  if (it->m_ready)
164  it->m_ready->ref();
165  }
166  m_decoderCallbacks.clear();
167  m_decoderCallbackLock.unlock();
168 }
169 
171 {
172  if (m_videoOutput)
173  {
176  ReinitOSD();
177  QString text = toString(m_videoOutput->GetAdjustFill());
178  UpdateOSDMessage(text);
179  }
180 }
181 
183 {
184  if (m_videoOutput)
185  {
186  m_osdLock.lock();
187  QRect visible;
188  QRect total;
189  float aspect = NAN;
190  float scaling = NAN;
191  m_videoOutput->GetOSDBounds(total, visible, aspect, scaling, 1.0F);
192  int stretch = static_cast<int>(lroundf(aspect * 100));
193  if ((m_osd.Bounds() != visible) || (m_osd.GetFontStretch() != stretch))
194  {
197  m_osd.Init(visible, aspect);
198  m_captionsOverlay.Init(visible, aspect);
199  EnableCaptions(old, false);
200  if (m_deleteMap.IsEditing())
201  {
202  bool const changed = m_deleteMap.IsChanged();
203  m_deleteMap.SetChanged(true);
205  m_deleteMap.SetChanged(changed);
206  }
207  }
208 
209  m_reinitOsd = false;
210 
211 #ifdef USING_MHEG
212  if (GetInteractiveTV())
213  {
214  QMutexLocker locker(&m_itvLock);
215  m_interactiveTV->Reinit(total, visible, aspect);
216  m_itvVisible = false;
217  }
218 #endif
219  m_osdLock.unlock();
220  }
221 }
222 
224 {
225  if (!Frame)
226  return;
227 
228  if (!qFuzzyCompare(Frame->m_aspect, m_videoAspect) && Frame->m_aspect > 0.0F)
229  {
230  LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Video Aspect ratio changed from %1 to %2")
231  .arg(static_cast<qreal>(m_videoAspect)).arg(static_cast<qreal>(Frame->m_aspect)));
232  m_videoAspect = Frame->m_aspect;
233  if (m_videoOutput)
234  {
236  ReinitOSD();
237  }
238  }
239 }
240 
TVPlaybackState::ChangePictureAttribute
void ChangePictureAttribute(PictureAttribute Attribute, bool Direction, int Value)
MythPlayerCaptionsUI::GetInteractiveTV
InteractiveTV * GetInteractiveTV() override
Definition: mythplayercaptionsui.cpp:523
MythPlayerVideoUI::m_colourState
MythVideoColourState m_colourState
Definition: mythplayervideoui.h:71
MythVideoOutput::GetOSDBounds
virtual void GetOSDBounds(QRect &Total, QRect &Visible, float &VisibleAspect, float &FontScaling, float ThemeAspect) const
Definition: mythvideoout.cpp:207
MythDate::toString
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:84
PictureAttributeSupported
PictureAttributeSupported
Definition: videoouttypes.h:116
MythPlayerVideoUI::m_interopTypes
MythInteropGPU::InteropMap m_interopTypes
Definition: mythplayervideoui.h:72
MythVideoBounds::VideoAspectRatioChanged
void VideoAspectRatioChanged(float Aspect)
Calls SetVideoAspectRatio(float aspect), then calls MoveResize() to apply changes.
Definition: mythvideobounds.cpp:513
MythVideoOutputGPU::RefreshState
void RefreshState()
MythVideoColourState::m_attributeValues
std::map< PictureAttribute, int > m_attributeValues
Definition: mythplayerstate.h:123
MythPlayerVideoUI::VideoColourStateChanged
void VideoColourStateChanged(const MythVideoColourState &ColourState)
MythPlayerVideoUI::m_decoderCallbackLock
QMutex m_decoderCallbackLock
Definition: mythplayervideoui.h:69
MythPlayer::CheckCallbacks
void CheckCallbacks()
MythVideoBounds::EmbedPlayback
virtual void EmbedPlayback(bool Embed, QRect Rect)
Definition: mythvideobounds.cpp:684
TVPlaybackState::ChangeAspectOverride
void ChangeAspectOverride(AspectOverrideMode AspectMode=kAspect_Toggle)
Mode
Mode
Definition: synaesthesia.h:23
MythPlayerVideoUI::ToggleAdjustFill
void ToggleAdjustFill(AdjustFillMode Mode=kAdjustFill_Toggle)
Definition: mythplayervideoui.cpp:170
MythPlayerCaptionsUI::m_itvVisible
bool m_itvVisible
Definition: mythplayercaptionsui.h:77
Frame
Definition: zmdefines.h:93
MythPlayerVideoUI::PictureAttributeChanged
void PictureAttributeChanged(PictureAttribute Attribute, int Value)
Definition: mythplayervideoui.cpp:114
TVPlaybackState::SaveBottomLine
void SaveBottomLine()
MythPlayerCaptionsUI
Definition: mythplayercaptionsui.h:8
MythVideoOutputGPU::PictureAttributesUpdated
void PictureAttributesUpdated(const std::map< PictureAttribute, int > &Values)
MythPlayerCaptionsUI::m_itvLock
QMutex m_itvLock
Definition: mythplayercaptionsui.h:75
MythMediaOverlay::Bounds
QRect Bounds() const
Definition: mythmediaoverlay.cpp:52
MythPlayerVideoUI::m_detectLetterBox
DetectLetterbox m_detectLetterBox
Definition: mythplayervideoui.h:64
TVPlaybackState::ChangeZoom
void ChangeZoom(ZoomDirection Zoom)
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
PlayerFlags
PlayerFlags
Definition: mythplayer.h:65
DecoderBase::GetVideoCodecID
virtual MythCodecID GetVideoCodecID(void) const =0
InteractiveTV::Reinit
void Reinit(QRect videoRect, QRect dispRect, float aspect)
Definition: interactivetv.cpp:62
MythVideoBounds::UpdateOSDMessage
void UpdateOSDMessage(const QString &Message)
MythCaptionsState::m_textDisplayMode
uint m_textDisplayMode
Definition: mythplayerstate.h:70
MythVideoOutputGPU::ResizeForVideo
void ResizeForVideo(QSize Size=QSize())
Definition: mythvideooutgpu.cpp:708
MythPlayerVideoUI::SupportedAttributesChanged
void SupportedAttributesChanged(PictureAttributeSupported Supported)
Definition: mythplayervideoui.cpp:105
MythPlayer::SetErrored
void SetErrored(const QString &reason)
Definition: mythplayer.cpp:1934
MythVideoBounds::SaveBottomLine
void SaveBottomLine(void)
Definition: mythvideobounds.cpp:897
MythInteropGPU::InteropMap
std::map< VideoFrameType, InteropTypes > InteropMap
Definition: mythinteropgpu.h:44
MythPlayerVideoUI::m_decoderCallbacks
QVector< DecoderCallback > m_decoderCallbacks
Definition: mythplayervideoui.h:70
MythVideoBounds::GetAdjustFill
AdjustFillMode GetAdjustFill(void) const
Definition: mythvideobounds.h:80
MythPlayerOverlayUI::UpdateOSDMessage
void UpdateOSDMessage(const QString &Message)
Definition: mythplayeroverlayui.cpp:76
MythPlayer::m_decoder
DecoderBase * m_decoder
Definition: mythplayer.h:366
DecoderBase::GetCodecDecoderName
virtual QString GetCodecDecoderName(void) const =0
TVPlaybackState::VideoColourStateChanged
void VideoColourStateChanged(const MythVideoColourState &ColourState)
Definition: tvplaybackstate.cpp:43
MythPlayer::m_framesPlayed
uint64_t m_framesPlayed
Definition: mythplayer.h:432
mythlogging.h
MythVideoBounds::SetStereoOverride
void SetStereoOverride(StereoscopicMode Mode)
Definition: mythvideobounds.cpp:928
MythPlayerVideoUI::PictureAttributesUpdated
void PictureAttributesUpdated(const std::map< PictureAttribute, int > &Values)
Definition: mythplayervideoui.cpp:124
TVPlaybackState::ChangeAdjustFill
void ChangeAdjustFill(AdjustFillMode FillMode=kAdjustFill_Toggle)
MythPlayerOverlayUI::ChangeOSDPositionUpdates
void ChangeOSDPositionUpdates(bool Enable)
Definition: mythplayeroverlayui.cpp:43
MythVideoBounds::ToggleAspectOverride
void ToggleAspectOverride(AspectOverrideMode AspectMode=kAspect_Toggle)
Enforce different aspect ratio than detected, then calls VideoAspectRatioChanged(float) to apply them...
Definition: mythvideobounds.cpp:722
MythPlayer::m_videoOutput
MythVideoOutput * m_videoOutput
Definition: mythplayer.h:372
MythVideoOutputGPU::PictureAttributeChanged
void PictureAttributeChanged(PictureAttribute Attribute, int Value)
MythPlayerVideoUI::HandleDecoderCallback
void HandleDecoderCallback(const QString &Debug, DecoderCallback::Callback Function, void *Opaque1, void *Opaque2)
Convenience function to request and wait for a callback into the main thread.
Definition: mythplayervideoui.cpp:135
MythPlayerCaptionsUI::m_captionsOverlay
MythCaptionsOverlay m_captionsOverlay
Definition: mythplayercaptionsui.h:69
MythPlayerUIBase::m_painter
MythPainter * m_painter
Definition: mythplayeruibase.h:20
mythvideooutgpu.h
MythPlayerCaptionsUI::ResizeForInteractiveTV
void ResizeForInteractiveTV(const QRect &Rect)
kAdjustingPicture_Playback
@ kAdjustingPicture_Playback
Definition: tv.h:123
MythPlayerVideoUI::GetInteropTypes
const MythInteropGPU::InteropMap & GetInteropTypes() const
Return a list of interop types supported by the current render device.
Definition: mythplayervideoui.cpp:26
MythPlayer::m_videoFrameRate
double m_videoFrameRate
Video (input) Frame Rate (often inaccurate)
Definition: mythplayer.h:443
MythVideoOutputGPU::Create
static MythVideoOutputGPU * Create(MythMainWindow *MainWindow, MythRender *Render, MythPainter *Painter, MythDisplay *Display, const QString &Decoder, MythCodecID CodecID, QSize VideoDim, QSize VideoDispDim, float VideoAspect, float FrameRate, uint PlayerFlags, const QString &Codec, int ReferenceFrames, const VideoFrameTypes *&RenderFormats)
Definition: mythvideooutgpu.cpp:34
TVPlaybackState::VideoBoundsStateChanged
void VideoBoundsStateChanged(const MythVideoBoundsState &VideoBoundsState)
Definition: tvplaybackstate.cpp:38
MythPlayerOverlayUI::m_reinitOsd
bool m_reinitOsd
Definition: mythplayeroverlayui.h:54
MythPlayer::m_playerCtx
PlayerContext * m_playerCtx
Definition: mythplayer.h:374
MythPlayer::m_videoDispDim
QSize m_videoDispDim
Video (input) width & height.
Definition: mythplayer.h:446
TVPlaybackState::ToggleMoveBottomLine
void ToggleMoveBottomLine()
MythPlayer::m_codecName
QString m_codecName
Codec Name - used by playback profile.
Definition: mythplayer.h:445
toTypeString
QString toTypeString(PictureAdjustType type)
Definition: tv.cpp:49
MythVideoBounds::ToggleAdjustFill
void ToggleAdjustFill(AdjustFillMode AdjustFillMode=kAdjustFill_Toggle)
Sets up letterboxing for various standard video frame and monitor dimensions, then calls MoveResize()...
Definition: mythvideobounds.cpp:566
DecoderCallback
Definition: mythplayervideoui.h:9
uint
unsigned int uint
Definition: compat.h:81
MythPlayerOverlayUI::m_osd
OSD m_osd
Definition: mythplayeroverlayui.h:45
MythVideoColourState::m_supportedAttributes
PictureAttributeSupported m_supportedAttributes
Definition: mythplayerstate.h:122
MythPlayer::m_playerFlags
PlayerFlags m_playerFlags
Definition: mythplayer.h:380
MythPlayer::m_deleteMap
DeleteMap m_deleteMap
Definition: mythplayer.h:486
DetectLetterbox::GetDetectLetterbox
bool GetDetectLetterbox() const
Definition: DetectLetterbox.cpp:328
LOC
#define LOC
Definition: mythplayervideoui.cpp:9
OSD::Init
bool Init(QRect Rect, float FontAspect) override
Definition: osd.cpp:50
MythVideoBounds::ToggleMoveBottomLine
void ToggleMoveBottomLine(void)
Definition: mythvideobounds.cpp:858
DetectLetterbox::SetDetectLetterbox
void SetDetectLetterbox(bool Detect, AdjustFillMode Mode)
Definition: DetectLetterbox.cpp:320
PictureAttribute
PictureAttribute
Definition: videoouttypes.h:103
MythPlayerCaptionsUI::EnableCaptions
virtual void EnableCaptions(uint Mode, bool UpdateOSD=true)
Definition: mythplayercaptionsui.cpp:198
MythMediaOverlay::Init
virtual bool Init(QRect Rect, float FontAspect)
Definition: mythmediaoverlay.cpp:62
MythPlayerCaptionsUI::ToggleCaptionsByType
void ToggleCaptionsByType(uint Type)
Definition: mythplayercaptionsui.cpp:269
MythVideoBounds::SetITVResize
void SetITVResize(QRect Rect)
Definition: mythvideobounds.cpp:632
MythVideoOutputGPU::ChangePictureAttribute
void ChangePictureAttribute(PictureAttribute Attribute, bool Direction, int Value)
TVPlaybackState::ResizeScreenForVideo
void ResizeScreenForVideo(QSize Size={})
MythPlayerVideoUI::CheckAspectRatio
void CheckAspectRatio(MythVideoFrame *Frame)
Definition: mythplayervideoui.cpp:223
MythPlayerOverlayUI::m_osdLock
QRecursiveMutex m_osdLock
Definition: mythplayeroverlayui.h:49
MythPlayer::m_maxReferenceFrames
int m_maxReferenceFrames
Number of reference frames used in the video stream.
Definition: mythplayer.h:448
MythVideoBounds::Zoom
void Zoom(ZoomDirection Direction)
Sets up zooming into to different parts of the video.
Definition: mythvideobounds.cpp:766
TVPlaybackState::ChangeOSDPositionUpdates
void ChangeOSDPositionUpdates(bool Enable)
AdjustFillMode
AdjustFillMode
Definition: videoouttypes.h:71
kOSDFunctionalType_PictureAdjust
@ kOSDFunctionalType_PictureAdjust
Definition: osd.h:47
toTitleString
QString toTitleString(PictureAdjustType type)
Definition: tv.cpp:62
MythPlayerVideoUI::ReinitOSD
void ReinitOSD()
Definition: mythplayervideoui.cpp:182
DecoderCallback::Callback
void(*)(void *, void *, void *) Callback
Definition: mythplayervideoui.h:12
MythPlayerUIBase::m_mainWindow
MythMainWindow * m_mainWindow
Definition: mythplayeruibase.h:17
MythPlayerCaptionsUI::m_interactiveTV
InteractiveTV * m_interactiveTV
Definition: mythplayercaptionsui.h:74
MythPlayerUIBase::m_tv
TV * m_tv
Definition: mythplayeruibase.h:18
TVPlaybackState::EmbedPlayback
void EmbedPlayback(bool Embed, const QRect &Rect={})
MythInteropGPU::GetTypes
static InteropMap GetTypes(MythRender *Render)
Definition: mythinteropgpu.cpp:10
DeleteMap::SetChanged
void SetChanged(bool changed=true)
Definition: deletemap.h:47
PlayerContext
Definition: playercontext.h:53
DeleteMap::IsChanged
bool IsChanged(void) const
Definition: deletemap.h:46
MythPlayer::m_videoDim
QSize m_videoDim
Video (input) buffer width & height.
Definition: mythplayer.h:447
MythMediaOverlay::GetFontStretch
int GetFontStretch() const
Definition: mythmediaoverlay.cpp:57
MythPlayerOverlayUI::UpdateOSDStatus
void UpdateOSDStatus(osdInfo &Info, int Type, enum OSDTimeout Timeout)
Definition: mythplayeroverlayui.cpp:101
interactivetv.h
MythPlayer::m_videoAspect
float m_videoAspect
Video (input) Apect Ratio.
Definition: mythplayer.h:449
MythPlayerVideoUI::MythPlayerVideoUI
MythPlayerVideoUI(MythMainWindow *MainWindow, TV *Tv, PlayerContext *Context, PlayerFlags Flags)
Definition: mythplayervideoui.cpp:11
MythVideoOutputGPU::SupportedAttributesChanged
void SupportedAttributesChanged(PictureAttributeSupported Supported)
MythPlayerCaptionsUI::m_captionsState
MythCaptionsState m_captionsState
Definition: mythplayercaptionsui.h:70
MythVideoFrame
Definition: mythframe.h:88
MythPlayerUIBase::m_render
MythRender * m_render
Definition: mythplayeruibase.h:19
TVPlaybackState::ChangeStereoOverride
void ChangeStereoOverride(StereoscopicMode Mode)
MythPlayerVideoUI::ProcessCallbacks
void ProcessCallbacks()
Definition: mythplayervideoui.cpp:152
TVPlaybackState::WindowResized
void WindowResized(const QSize &Size)
kOSDTimeout_Med
@ kOSDTimeout_Med
Definition: osd.h:60
MythVideoBounds::VideoBoundsStateChanged
void VideoBoundsStateChanged(MythVideoBoundsState VideoState)
DeleteMap::UpdateOSD
void UpdateOSD(uint64_t frame, double frame_rate, OSD *osd)
Show and update the edit mode On Screen Display.
Definition: deletemap.cpp:177
MythPlayerVideoUI::RefreshVideoState
void RefreshVideoState()
mythplayervideoui.h
MythPlayerVideoUI::InitVideo
bool InitVideo() override
Definition: mythplayervideoui.cpp:31
DeleteMap::IsEditing
bool IsEditing(void) const
Definition: deletemap.h:40
MythMainWindow
Definition: mythmainwindow.h:28
TVPlaybackState::ToggleDetectLetterBox
void ToggleDetectLetterBox()
MythPlayer::m_renderFormats
const VideoFrameTypes * m_renderFormats
Definition: mythplayer.h:373
MythVideoOutputGPU::WindowResized
void WindowResized(QSize Size)
Definition: mythvideooutgpu.cpp:267
tv_play.h
MythPlayerUIBase::m_display
MythDisplay * m_display
Definition: mythplayeruibase.h:21
TV
Control TV playback.
Definition: tv_play.h:154