MythTV  master
mythplayervideoui.cpp
Go to the documentation of this file.
1 // MythTV
2 #include "mythlogging.h"
3 #include "tv_play.h"
4 #include "interactivetv.h"
5 #include "mythvideooutgpu.h"
6 #include "mythplayervideoui.h"
7 
8 #define LOC QString("PlayerVideo: ")
9 
11  : MythPlayerCaptionsUI(MainWindow, Tv, Context, Flags)
12 {
13  // Register our types for signalling
14  qRegisterMetaType<MythVideoBoundsState>();
15  qRegisterMetaType<MythVideoColourState>();
18 }
19 
26 {
27  return m_interopTypes;
28 }
29 
31 {
32  if (!(m_playerCtx && m_decoder))
33  return false;
34 
39  static_cast<float>(m_videoFrameRate),
40  static_cast<uint>(m_playerFlags),
43 
44  if (!video)
45  {
46  LOG(VB_GENERAL, LOG_ERR, LOC + "Couldn't create VideoOutput instance. Exiting..");
47  SetErrored(tr("Failed to initialize video output"));
48  return false;
49  }
50 
51  // Toggle detect letter box
52  auto toggleDetectLetterbox = [&]()
53  {
54  if (m_videoOutput)
55  {
58  }
59  };
60 
62 
63  // Inbound connections
71  this, QOverload<const QString&>::of(&MythPlayerVideoUI::UpdateOSDMessage));
80  connect(m_tv, &TV::ToggleDetectLetterBox, toggleDetectLetterbox);
81 
82  // Passthrough signals
97 
98  // Update initial state. MythVideoOutput will have potentially adjusted state
99  // at startup that we need to know about.
100  emit RefreshVideoState();
101  return true;
102 }
103 
105 {
106  if (Supported != m_colourState.m_supportedAttributes)
107  {
110  }
111 }
112 
114 {
115  QString text = toString(Attribute) + " " + toTypeString(kAdjustingPicture_Playback);
116  UpdateOSDStatus(toTitleString(kAdjustingPicture_Playback), text, QString::number(Value),
119  m_colourState.m_attributeValues[Attribute] = Value;
121 };
122 
123 void MythPlayerVideoUI::PictureAttributesUpdated(const std::map<PictureAttribute,int>& Values)
124 {
127 }
128 
135  void* Opaque1, void* Opaque2)
136 {
137  if (!Function)
138  return;
139 
140  m_decoderCallbackLock.lock();
141  QAtomicInt ready{0};
142  QWaitCondition wait;
143  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Queuing callback for %1").arg(Debug));
144  m_decoderCallbacks.append(DecoderCallback(Debug, Function, &ready, &wait, Opaque1, Opaque2));
145  int count = 0;
146  while (!ready && !wait.wait(&m_decoderCallbackLock, 100) && (count += 100))
147  LOG(VB_GENERAL, LOG_WARNING, QString("Waited %1ms for %2").arg(count).arg(Debug));
148  m_decoderCallbackLock.unlock();
149 }
150 
152 {
153  m_decoderCallbackLock.lock();
154  for (auto *it = m_decoderCallbacks.begin(); it != m_decoderCallbacks.end(); ++it)
155  {
156  if (it->m_function)
157  {
158  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Executing %1").arg(it->m_debug));
159  it->m_function(it->m_opaque1, it->m_opaque2, it->m_opaque3);
160  }
161  if (it->m_ready)
162  it->m_ready->ref();
163  }
164  m_decoderCallbacks.clear();
165  m_decoderCallbackLock.unlock();
166 }
167 
169 {
170  if (m_videoOutput)
171  {
174  ReinitOSD();
175  QString text = toString(m_videoOutput->GetAdjustFill());
176  UpdateOSDMessage(text);
177  }
178 }
179 
181 {
182  if (m_videoOutput)
183  {
184  m_osdLock.lock();
185  QRect visible;
186  QRect total;
187  float aspect = NAN;
188  float scaling = NAN;
189  m_videoOutput->GetOSDBounds(total, visible, aspect, scaling, 1.0F);
190  int stretch = static_cast<int>(lroundf(aspect * 100));
191  if ((m_osd.Bounds() != visible) || (m_osd.GetFontStretch() != stretch))
192  {
195  m_osd.Init(visible, aspect);
196  m_captionsOverlay.Init(visible, aspect);
197  EnableCaptions(old, false);
198  if (m_deleteMap.IsEditing())
199  {
200  bool const changed = m_deleteMap.IsChanged();
201  m_deleteMap.SetChanged(true);
203  m_deleteMap.SetChanged(changed);
204  }
205  }
206 
207  m_reinitOsd = false;
208 
209 #ifdef USING_MHEG
210  if (GetInteractiveTV())
211  {
212  QMutexLocker locker(&m_itvLock);
213  m_interactiveTV->Reinit(total, visible, aspect);
214  m_itvVisible = false;
215  }
216 #endif
217  m_osdLock.unlock();
218  }
219 }
220 
222 {
223  if (!Frame)
224  return;
225 
226  if (!qFuzzyCompare(Frame->m_aspect, m_videoAspect) && Frame->m_aspect > 0.0F)
227  {
228  LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Video Aspect ratio changed from %1 to %2")
229  .arg(static_cast<qreal>(m_videoAspect)).arg(static_cast<qreal>(Frame->m_aspect)));
230  m_videoAspect = Frame->m_aspect;
231  if (m_videoOutput)
232  {
234  ReinitOSD();
235  }
236  }
237 }
238 
TVPlaybackState::ChangePictureAttribute
void ChangePictureAttribute(PictureAttribute Attribute, bool Direction, int Value)
MythPlayerCaptionsUI::GetInteractiveTV
InteractiveTV * GetInteractiveTV() override
Definition: mythplayercaptionsui.cpp:525
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:204
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:512
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:683
TVPlaybackState::ChangeAspectOverride
void ChangeAspectOverride(AspectOverrideMode AspectMode=kAspect_Toggle)
MythPlayerVideoUI::ToggleAdjustFill
void ToggleAdjustFill(AdjustFillMode Mode=kAdjustFill_Toggle)
Definition: mythplayervideoui.cpp:168
MythPlayerCaptionsUI::m_itvVisible
bool m_itvVisible
Definition: mythplayercaptionsui.h:78
Frame
Definition: zmdefines.h:93
MythPlayerVideoUI::PictureAttributeChanged
void PictureAttributeChanged(PictureAttribute Attribute, int Value)
Definition: mythplayervideoui.cpp:113
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:76
arg
arg(title).arg(filename).arg(doDelete))
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:23
PlayerFlags
PlayerFlags
Definition: mythplayer.h:62
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:701
MythPlayerVideoUI::SupportedAttributesChanged
void SupportedAttributesChanged(PictureAttributeSupported Supported)
Definition: mythplayervideoui.cpp:104
video
QDomElement video
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:661
MythPlayer::SetErrored
void SetErrored(const QString &reason)
Definition: mythplayer.cpp:1933
MythVideoBounds::SaveBottomLine
void SaveBottomLine(void)
Definition: mythvideobounds.cpp:896
MythInteropGPU::InteropMap
std::map< VideoFrameType, InteropTypes > InteropMap
Definition: mythinteropgpu.h:45
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:73
toString
QString toString(MarkTypes type)
Definition: programtypes.cpp:26
MythPlayer::m_decoder
DecoderBase * m_decoder
Definition: mythplayer.h:367
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:429
mythlogging.h
MythVideoBounds::SetStereoOverride
void SetStereoOverride(StereoscopicMode Mode)
Definition: mythvideobounds.cpp:927
MythPlayerVideoUI::PictureAttributesUpdated
void PictureAttributesUpdated(const std::map< PictureAttribute, int > &Values)
Definition: mythplayervideoui.cpp:123
TVPlaybackState::ChangeAdjustFill
void ChangeAdjustFill(AdjustFillMode FillMode=kAdjustFill_Toggle)
MythPlayerOverlayUI::ChangeOSDPositionUpdates
void ChangeOSDPositionUpdates(bool Enable)
Definition: mythplayeroverlayui.cpp:40
MythVideoBounds::ToggleAspectOverride
void ToggleAspectOverride(AspectOverrideMode AspectMode=kAspect_Toggle)
Enforce different aspect ratio than detected, then calls VideoAspectRatioChanged(float) to apply them...
Definition: mythvideobounds.cpp:721
MythPlayer::m_videoOutput
MythVideoOutput * m_videoOutput
Definition: mythplayer.h:369
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:134
MythPlayerCaptionsUI::m_captionsOverlay
MythCaptionsOverlay m_captionsOverlay
Definition: mythplayercaptionsui.h:70
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:25
MythPlayer::m_videoFrameRate
double m_videoFrameRate
Video (input) Frame Rate (often inaccurate)
Definition: mythplayer.h:440
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:33
TVPlaybackState::VideoBoundsStateChanged
void VideoBoundsStateChanged(const MythVideoBoundsState &VideoBoundsState)
Definition: tvplaybackstate.cpp:38
MythPlayerOverlayUI::m_reinitOsd
bool m_reinitOsd
Definition: mythplayeroverlayui.h:52
MythPlayer::m_playerCtx
PlayerContext * m_playerCtx
Definition: mythplayer.h:371
MythPlayer::m_videoDispDim
QSize m_videoDispDim
Video (input) width & height.
Definition: mythplayer.h:443
TVPlaybackState::ToggleMoveBottomLine
void ToggleMoveBottomLine()
MythPlayer::m_codecName
QString m_codecName
Codec Name - used by playback profile.
Definition: mythplayer.h:442
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:565
DecoderCallback
Definition: mythplayervideoui.h:9
uint
unsigned int uint
Definition: compat.h:140
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:377
MythPlayer::m_deleteMap
DeleteMap m_deleteMap
Definition: mythplayer.h:485
DetectLetterbox::GetDetectLetterbox
bool GetDetectLetterbox() const
Definition: DetectLetterbox.cpp:325
LOC
#define LOC
Definition: mythplayervideoui.cpp:8
OSD::Init
bool Init(QRect Rect, float FontAspect) override
Definition: osd.cpp:50
MythVideoBounds::ToggleMoveBottomLine
void ToggleMoveBottomLine(void)
Definition: mythvideobounds.cpp:857
DetectLetterbox::SetDetectLetterbox
void SetDetectLetterbox(bool Detect, AdjustFillMode Mode)
Definition: DetectLetterbox.cpp:317
PictureAttribute
PictureAttribute
Definition: videoouttypes.h:103
MythPlayerCaptionsUI::EnableCaptions
virtual void EnableCaptions(uint Mode, bool UpdateOSD=true)
Definition: mythplayercaptionsui.cpp:197
MythMediaOverlay::Init
virtual bool Init(QRect Rect, float FontAspect)
Definition: mythmediaoverlay.cpp:62
MythPlayerCaptionsUI::ToggleCaptionsByType
void ToggleCaptionsByType(uint Type)
Definition: mythplayercaptionsui.cpp:273
MythVideoBounds::SetITVResize
void SetITVResize(QRect Rect)
Definition: mythvideobounds.cpp:631
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:221
MythPlayer::m_maxReferenceFrames
int m_maxReferenceFrames
Number of reference frames used in the video stream.
Definition: mythplayer.h:445
MythVideoBounds::Zoom
void Zoom(ZoomDirection Direction)
Sets up zooming into to different parts of the video.
Definition: mythvideobounds.cpp:765
TVPlaybackState::ChangeOSDPositionUpdates
void ChangeOSDPositionUpdates(bool Enable)
AdjustFillMode
AdjustFillMode
Definition: videoouttypes.h:71
kOSDFunctionalType_PictureAdjust
@ kOSDFunctionalType_PictureAdjust
Definition: osd.h:48
toTitleString
QString toTitleString(PictureAdjustType type)
Definition: tv.cpp:62
MythPlayerVideoUI::ReinitOSD
void ReinitOSD()
Definition: mythplayervideoui.cpp:180
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:75
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:48
DeleteMap::IsChanged
bool IsChanged(void) const
Definition: deletemap.h:46
MythPlayer::m_videoDim
QSize m_videoDim
Video (input) buffer width & height.
Definition: mythplayer.h:444
MythMediaOverlay::GetFontStretch
int GetFontStretch() const
Definition: mythmediaoverlay.cpp:57
MythPlayerOverlayUI::UpdateOSDStatus
void UpdateOSDStatus(osdInfo &Info, int Type, enum OSDTimeout Timeout)
Definition: mythplayeroverlayui.cpp:98
interactivetv.h
MythPlayer::m_videoAspect
float m_videoAspect
Video (input) Apect Ratio.
Definition: mythplayer.h:446
MythPlayerVideoUI::MythPlayerVideoUI
MythPlayerVideoUI(MythMainWindow *MainWindow, TV *Tv, PlayerContext *Context, PlayerFlags Flags)
Definition: mythplayervideoui.cpp:10
MythVideoOutputGPU::SupportedAttributesChanged
void SupportedAttributesChanged(PictureAttributeSupported Supported)
MythPlayerCaptionsUI::m_captionsState
MythCaptionsState m_captionsState
Definition: mythplayercaptionsui.h:71
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:151
TVPlaybackState::WindowResized
void WindowResized(const QSize &Size)
kOSDTimeout_Med
@ kOSDTimeout_Med
Definition: osd.h:61
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:30
DeleteMap::IsEditing
bool IsEditing(void) const
Definition: deletemap.h:40
MythMainWindow
Definition: mythmainwindow.h:35
TVPlaybackState::ToggleDetectLetterBox
void ToggleDetectLetterBox()
MythPlayer::m_renderFormats
const VideoFrameTypes * m_renderFormats
Definition: mythplayer.h:370
MythVideoOutputGPU::WindowResized
void WindowResized(QSize Size)
Definition: mythvideooutgpu.cpp:259
tv_play.h
MythPlayerUIBase::m_display
MythDisplay * m_display
Definition: mythplayeruibase.h:21
TV
Control TV playback.
Definition: tv_play.h:152
MythPlayerOverlayUI::m_osdLock
QMutex m_osdLock
Definition: mythplayeroverlayui.h:48