MythTV master
mythplayervideoui.cpp
Go to the documentation of this file.
1// MythTV
2#include "libmythbase/mythconfig.h"
4
6#include "mythplayervideoui.h"
7#include "mythvideooutgpu.h"
8#include "tv_play.h"
9
10#define LOC QString("PlayerVideo: ")
11
13 : MythPlayerCaptionsUI(MainWindow, Tv, Context, Flags)
14{
15 // Register our types for signalling
16 qRegisterMetaType<MythVideoBoundsState>();
17 qRegisterMetaType<MythVideoColourState>();
20}
21
28{
29 return m_interopTypes;
30}
31
33{
34 if (!(m_playerCtx && m_decoder))
35 return false;
36
41 static_cast<float>(m_videoFrameRate),
42 static_cast<uint>(m_playerFlags),
45
46 if (!video)
47 {
48 LOG(VB_GENERAL, LOG_ERR, LOC + "Couldn't create VideoOutput instance. Exiting..");
49 SetErrored(tr("Failed to initialize video output"));
50 return false;
51 }
52
53 // Toggle detect letter box
54 auto toggleDetectLetterbox = [&]()
55 {
56 if (m_videoOutput)
57 {
60 }
61 };
62
63 m_videoOutput = video;
64
65 // Inbound connections
73 this, qOverload<const QString&>(&MythPlayerVideoUI::UpdateOSDMessage));
82 connect(m_tv, &TV::ToggleDetectLetterBox, this, toggleDetectLetterbox);
83
84 // Passthrough signals
99
100 // Update initial state. MythVideoOutput will have potentially adjusted state
101 // at startup that we need to know about.
102 emit RefreshVideoState();
103 return true;
104}
105
107{
108 if (Supported != m_colourState.m_supportedAttributes)
109 {
112 }
113}
114
116{
117 QString text = toString(Attribute) + " " + toTypeString(kAdjustingPicture_Playback);
118 UpdateOSDStatus(toTitleString(kAdjustingPicture_Playback), text, QString::number(Value),
121 m_colourState.m_attributeValues[Attribute] = Value;
123};
124
125void MythPlayerVideoUI::PictureAttributesUpdated(const std::map<PictureAttribute,int>& Values)
126{
129}
130
137 void* Opaque1, void* Opaque2)
138{
139 if (!Function)
140 return;
141
143 QAtomicInt ready{0};
144 QWaitCondition wait;
145 LOG(VB_GENERAL, LOG_INFO, LOC + QString("Queuing callback for %1").arg(Debug));
146 m_decoderCallbacks.append(DecoderCallback(Debug, Function, &ready, &wait, Opaque1, Opaque2));
147 int count = 0;
148 while (!ready && !wait.wait(&m_decoderCallbackLock, 100) && (count += 100))
149 LOG(VB_GENERAL, LOG_WARNING, QString("Waited %1ms for %2").arg(count).arg(Debug));
150 m_decoderCallbackLock.unlock();
151}
152
154{
156 // NOLINTNEXTLINE(readability-qualified-auto) for Qt6
157 for (auto it = m_decoderCallbacks.begin(); it != m_decoderCallbacks.end(); ++it)
158 {
159 if (it->m_function)
160 {
161 LOG(VB_GENERAL, LOG_INFO, LOC + QString("Executing %1").arg(it->m_debug));
162 it->m_function(it->m_opaque1, it->m_opaque2, it->m_opaque3);
163 }
164 if (it->m_ready)
165 it->m_ready->ref();
166 }
167 m_decoderCallbacks.clear();
168 m_decoderCallbackLock.unlock();
169}
170
172{
173 if (m_videoOutput)
174 {
177 ReinitOSD();
178 QString text = toString(m_videoOutput->GetAdjustFill());
179 UpdateOSDMessage(text);
180 }
181}
182
184{
185 if (m_videoOutput)
186 {
187 m_osdLock.lock();
188 QRect visible;
189 QRect total;
190 float aspect = NAN;
191 float scaling = NAN;
192 m_videoOutput->GetOSDBounds(total, visible, aspect, scaling, 1.0F);
193 int stretch = static_cast<int>(lroundf(aspect * 100));
194 if ((m_osd.Bounds() != visible) || (m_osd.GetFontStretch() != stretch))
195 {
198 m_osd.Init(visible, aspect);
199 m_captionsOverlay.Init(visible, aspect);
200 EnableCaptions(old, false);
202 {
203 bool const changed = m_deleteMap.IsChanged();
206 m_deleteMap.SetChanged(changed);
207 }
208 }
209
210 m_reinitOsd = false;
211
212#if CONFIG_MHEG
213 if (GetInteractiveTV())
214 {
215 QMutexLocker locker(&m_itvLock);
216 m_interactiveTV->Reinit(total, visible, aspect);
217 m_itvVisible = false;
218 }
219#endif
220 m_osdLock.unlock();
221 }
222}
223
225{
226 if (!Frame)
227 return;
228
229 if (!qFuzzyCompare(Frame->m_aspect, m_videoAspect) && Frame->m_aspect > 0.0F)
230 {
231 LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Video Aspect ratio changed from %1 to %2")
232 .arg(static_cast<qreal>(m_videoAspect)).arg(static_cast<qreal>(Frame->m_aspect)));
233 m_videoAspect = Frame->m_aspect;
234 if (m_videoOutput)
235 {
237 ReinitOSD();
238 }
239 }
240}
241
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:361
DeleteMap m_deleteMap
Definition: mythplayer.h:478
const VideoFrameTypes * m_renderFormats
Definition: mythplayer.h:364
uint64_t m_framesPlayed
Definition: mythplayer.h:423
void SetErrored(const QString &reason)
PlayerFlags m_playerFlags
Definition: mythplayer.h:371
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:365
MythVideoOutput * m_videoOutput
Definition: mythplayer.h:363
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: compat.h:60
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
PlayerFlags
Definition: mythplayer.h:64
#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:20
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