MythTV master
mythplayervideoui.cpp
Go to the documentation of this file.
1// MythTV
3
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
72 this, qOverload<const QString&>(&MythPlayerVideoUI::UpdateOSDMessage));
81 connect(m_tv, &TV::ToggleDetectLetterBox, toggleDetectLetterbox);
82
83 // Passthrough signals
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
124void MythPlayerVideoUI::PictureAttributesUpdated(const std::map<PictureAttribute,int>& Values)
125{
128}
129
136 void* Opaque1, void* Opaque2)
137{
138 if (!Function)
139 return;
140
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{
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);
201 {
202 bool const changed = m_deleteMap.IsChanged();
205 m_deleteMap.SetChanged(changed);
206 }
207 }
208
209 m_reinitOsd = false;
210
211#if CONFIG_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
virtual QString GetCodecDecoderName(void) const =0
virtual MythCodecID GetVideoCodecID(void) const =0
void(*)(void *, void *, void *) Callback
void UpdateOSD(uint64_t frame, double frame_rate, OSD *osd)
Show and update the edit mode On Screen Display.
Definition: deletemap.cpp:177
void SetChanged(bool changed=true)
Definition: deletemap.h:48
bool IsEditing(void) const
Definition: deletemap.h:41
bool IsChanged(void) const
Definition: deletemap.h:47
void SetDetectLetterbox(bool Detect, AdjustFillMode Mode)
bool GetDetectLetterbox() const
std::map< VideoFrameType, InteropTypes > InteropMap
static InteropMap GetTypes(MythRender *Render)
virtual bool Init(QRect Rect, float FontAspect)
QRect Bounds() const
int GetFontStretch() const
InteractiveTV * GetInteractiveTV() override
void ToggleCaptionsByType(uint Type)
MythCaptionsOverlay m_captionsOverlay
MythCaptionsState m_captionsState
void ResizeForInteractiveTV(const QRect &Rect)
InteractiveTV * m_interactiveTV
virtual void EnableCaptions(uint Mode, bool UpdateOSD=true)
void ChangeOSDPositionUpdates(bool Enable)
void UpdateOSDMessage(const QString &Message)
void UpdateOSDStatus(osdInfo &Info, int Type, OSDTimeout Timeout)
QRecursiveMutex m_osdLock
MythDisplay * m_display
MythPainter * m_painter
MythRender * m_render
MythMainWindow * m_mainWindow
DetectLetterbox m_detectLetterBox
void VideoColourStateChanged(const MythVideoColourState &ColourState)
void CheckAspectRatio(MythVideoFrame *Frame)
MythInteropGPU::InteropMap m_interopTypes
void PictureAttributeChanged(PictureAttribute Attribute, int Value)
QVector< DecoderCallback > m_decoderCallbacks
MythPlayerVideoUI(MythMainWindow *MainWindow, TV *Tv, PlayerContext *Context, PlayerFlags Flags)
void RefreshVideoState()
void ToggleAdjustFill(AdjustFillMode Mode=kAdjustFill_Toggle)
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.
void PictureAttributesUpdated(const std::map< PictureAttribute, int > &Values)
const MythInteropGPU::InteropMap & GetInteropTypes() const
Return a list of interop types supported by the current render device.
bool InitVideo() override
MythVideoColourState m_colourState
void SupportedAttributesChanged(PictureAttributeSupported Supported)
DecoderBase * m_decoder
Definition: mythplayer.h:362
DeleteMap m_deleteMap
Definition: mythplayer.h:478
const VideoFrameTypes * m_renderFormats
Definition: mythplayer.h:365
uint64_t m_framesPlayed
Definition: mythplayer.h:424
void SetErrored(const QString &reason)
PlayerFlags m_playerFlags
Definition: mythplayer.h:372
int m_maxReferenceFrames
Number of reference frames used in the video stream.
Definition: mythplayer.h:440
QSize m_videoDispDim
Video (input) width & height.
Definition: mythplayer.h:438
QSize m_videoDim
Video (input) buffer width & height.
Definition: mythplayer.h:439
void CheckCallbacks()
float m_videoAspect
Video (input) Apect Ratio.
Definition: mythplayer.h:441
double m_videoFrameRate
Video (input) Frame Rate (often inaccurate)
Definition: mythplayer.h:435
PlayerContext * m_playerCtx
Definition: mythplayer.h:366
MythVideoOutput * m_videoOutput
Definition: mythplayer.h:364
QString m_codecName
Codec Name - used by playback profile.
Definition: mythplayer.h:437
void SetITVResize(QRect Rect)
virtual void EmbedPlayback(bool Embed, QRect Rect)
AdjustFillMode GetAdjustFill(void) const
void SaveBottomLine(void)
void UpdateOSDMessage(const QString &Message)
void VideoBoundsStateChanged(MythVideoBoundsState VideoState)
void ToggleAdjustFill(AdjustFillMode AdjustFillMode=kAdjustFill_Toggle)
Sets up letterboxing for various standard video frame and monitor dimensions, then calls MoveResize()...
void ToggleAspectOverride(AspectOverrideMode AspectMode=kAspect_Toggle)
Enforce different aspect ratio than detected, then calls VideoAspectRatioChanged(float) to apply them...
void ToggleMoveBottomLine(void)
void VideoAspectRatioChanged(float Aspect)
Calls SetVideoAspectRatio(float aspect), then calls MoveResize() to apply changes.
void Zoom(ZoomDirection Direction)
Sets up zooming into to different parts of the video.
void SetStereoOverride(StereoscopicMode Mode)
PictureAttributeSupported m_supportedAttributes
std::map< PictureAttribute, int > m_attributeValues
void WindowResized(QSize Size)
void PictureAttributesUpdated(const std::map< PictureAttribute, int > &Values)
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)
void ChangePictureAttribute(PictureAttribute Attribute, bool Direction, int Value)
void ResizeForVideo(QSize Size=QSize())
void PictureAttributeChanged(PictureAttribute Attribute, int Value)
void SupportedAttributesChanged(PictureAttributeSupported Supported)
virtual void GetOSDBounds(QRect &Total, QRect &Visible, float &VisibleAspect, float &FontScaling, float ThemeAspect) const
bool Init(QRect Rect, float FontAspect) override
Definition: osd.cpp:51
void ChangeAspectOverride(AspectOverrideMode AspectMode=kAspect_Toggle)
void ChangeZoom(ZoomDirection Zoom)
void ResizeScreenForVideo(QSize Size={})
void EmbedPlayback(bool Embed, const QRect &Rect={})
void ChangeStereoOverride(StereoscopicMode Mode)
void SaveBottomLine()
void ChangeAdjustFill(AdjustFillMode FillMode=kAdjustFill_Toggle)
void WindowResized(const QSize &Size)
void ChangeOSDPositionUpdates(bool Enable)
void ToggleDetectLetterBox()
void ToggleMoveBottomLine()
void VideoBoundsStateChanged(const MythVideoBoundsState &VideoBoundsState)
void ChangePictureAttribute(PictureAttribute Attribute, bool Direction, int Value)
void VideoColourStateChanged(const MythVideoColourState &ColourState)
Control TV playback.
Definition: tv_play.h:156
unsigned int uint
Definition: freesurround.h:24
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
PlayerFlags
Definition: mythplayer.h:65
#define LOC
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:93
@ kOSDFunctionalType_PictureAdjust
Definition: osd.h:47
@ kOSDTimeout_Med
Definition: osd.h:60
Mode
Definition: synaesthesia.h:23
QString toTypeString(PictureAdjustType type)
Definition: tv.cpp:49
QString toTitleString(PictureAdjustType type)
Definition: tv.cpp:62
@ kAdjustingPicture_Playback
Definition: tv.h:126
AdjustFillMode
Definition: videoouttypes.h:72
PictureAttributeSupported
PictureAttribute