MythTV  master
videooutbase.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 #ifndef VIDEOOUTBASE_H_
4 #define VIDEOOUTBASE_H_
5 
6 #include "mythframe.h"
7 #include "filter.h"
8 
9 #include <QSize>
10 #include <QRect>
11 #include <QString>
12 #include <QPoint>
13 #include <QMap>
14 #include <qwindowdefs.h>
15 
16 #include "videobuffers.h"
17 #include "mythcodecid.h"
18 #include "videoouttypes.h"
19 #include "videooutwindow.h"
20 #include "mythdisplay.h"
21 #include "DisplayRes.h"
22 #include "videodisplayprofile.h"
23 #include "videocolourspace.h"
25 #include "mythavutil.h"
26 
27 using namespace std;
28 
29 class MythPainter;
30 class MythYUVAPainter;
31 class MythImage;
32 class MythPlayer;
33 class OSD;
34 class FilterChain;
35 class FilterManager;
36 class AudioPlayer;
37 class MythRender;
38 
39 typedef QMap<MythPlayer*,PIPLocation> PIPMap;
40 
41 extern "C" {
42 struct ImgReSampleContext;
43 struct SwsContext;
44 }
45 
47 {
48  public:
49  static void GetRenderOptions(render_opts &opts);
50  static VideoOutput *Create(
51  const QString &decoder, MythCodecID codec_id, void *codec_priv,
52  PIPState pipState, const QSize &video_dim_buf,
53  const QSize &video_dim_disp, float video_aspect,
54  QWidget *parentwidget, const QRect &embed_rect, float video_prate,
55  uint playerFlags, QString &codecName);
56 
57  VideoOutput();
58  virtual ~VideoOutput();
59 
60  virtual bool Init(const QSize &video_dim_buf,
61  const QSize &video_dim_disp,
62  float aspect,
63  WId winid, const QRect &win_rect, MythCodecID codec_id);
64  virtual void InitOSD(OSD *osd);
65  virtual void SetVideoFrameRate(float);
66  virtual bool SetDeinterlacingEnabled(bool);
67  virtual bool SetupDeinterlace(bool interlaced, const QString& overridefilter="");
68  virtual void FallbackDeint(void);
69  virtual void BestDeint(void);
70  virtual bool NeedsDoubleFramerate(void) const;
71  virtual bool IsBobDeint(void) const;
72  virtual bool IsExtraProcessingRequired(void) const;
73  virtual bool ApproveDeintFilter(const QString& filtername) const;
74  void GetDeinterlacers(QStringList &deinterlacers);
75  QString GetDeinterlacer(void) { return m_deintfiltername; }
76  virtual void PrepareFrame(VideoFrame *buffer, FrameScanType,
77  OSD *osd) = 0;
78  virtual void Show(FrameScanType) = 0;
79  VideoDisplayProfile *GetProfile() { return db_vdisp_profile; }
80 
81 
82  virtual void WindowResized(const QSize &) {}
83 
96  virtual bool InputChanged(const QSize &video_dim_buf,
97  const QSize &video_dim_disp,
98  float aspect,
99  MythCodecID myth_codec_id,
100  void *codec_private,
101  bool &aspect_changed);
102 
103  virtual void VideoAspectRatioChanged(float aspect);
104 
105  virtual void ResizeDisplayWindow(const QRect&, bool);
106  virtual void EmbedInWidget(const QRect &rect);
107  virtual void StopEmbedding(void);
108  virtual void ResizeForGui(void);
109  virtual void ResizeForVideo(uint width = 0, uint height = 0);
110  virtual void MoveResizeWindow(QRect new_rect) = 0;
111 
112  virtual void MoveResize(void);
113  virtual void Zoom(ZoomDirection direction);
114  virtual void ToggleMoveBottomLine(void);
115  virtual void SaveBottomLine(void);
116 
117  virtual void GetOSDBounds(QRect &total, QRect &visible,
118  float &visible_aspect, float &font_scaling,
119  float themeAspect) const;
120  QRect GetMHEGBounds(void);
121  virtual void DrawSlice(VideoFrame *frame, int x, int y, int w, int h);
122 
126  virtual void DrawUnusedRects(bool sync = true) = 0;
127 
129  virtual float GetDisplayAspect(void) const;
130 
133  AspectOverrideMode GetAspectOverride(void) const;
134  virtual void ToggleAspectOverride(
135  AspectOverrideMode aspectMode = kAspect_Toggle);
136 
139  AdjustFillMode GetAdjustFill(void) const;
140  virtual void ToggleAdjustFill(
141  AdjustFillMode adjustFillMode = kAdjustFill_Toggle);
142 
143  QString GetZoomString(void) const { return window.GetZoomString(); }
144 
145  // pass in null to use the pause frame, if it exists.
146  virtual void ProcessFrame(VideoFrame *frame, OSD *osd,
147  FilterChain *filterList,
148  const PIPMap &pipPlayers,
150  void CropToDisplay(VideoFrame *frame);
151 
153  void ExposeEvent(void);
154 
156  { return videoColourSpace.SupportedAttributes(); }
157  int ChangePictureAttribute(PictureAttribute, bool direction);
158  virtual int SetPictureAttribute(PictureAttribute, int newValue);
159  int GetPictureAttribute(PictureAttribute);
160  virtual void InitPictureAttributes(void) { }
161 
162  bool AllowPreviewEPG(void) const;
163 
164  virtual QString GetName(void) const { return QString(); }
165  virtual bool IsPIPSupported(void) const { return false; }
166  virtual bool IsPBPSupported(void) const { return false; }
167  virtual bool NeedExtraAudioDecode(void) const { return false; }
168 
170  virtual bool hasHWAcceleration(void) const { return false; }
171  virtual void* GetDecoderContext(unsigned char*, uint8_t*&) { return nullptr; }
172 
174  virtual void SetFramesPlayed(long long fp) { framesPlayed = fp; };
176  virtual long long GetFramesPlayed(void) { return framesPlayed; };
177 
179  bool IsErrored() const { return errorState != kError_None; }
181  VideoErrorState GetError(void) const { return errorState; }
182  // Video Buffer Management
184  void SetPrebuffering(bool normal) { vbuffers.SetPrebuffering(normal); }
186  virtual void ClearAfterSeek(void) { vbuffers.ClearAfterSeek(); }
187 
189  virtual int ValidVideoFrames(void) const
190  { return vbuffers.ValidVideoFrames(); }
192  int FreeVideoFrames(void) { return vbuffers.FreeVideoFrames(); }
194  bool EnoughFreeFrames(void) { return vbuffers.EnoughFreeFrames(); }
197  bool EnoughDecodedFrames(void) { return vbuffers.EnoughDecodedFrames(); }
200  bool EnoughPrebufferedFrames(void) { return vbuffers.EnoughPrebufferedFrames(); }
201 
203  bool IsEmbedding(void);
204 
209  { return vbuffers.GetNextFreeFrame(); }
212  virtual void ReleaseFrame(VideoFrame *frame) { vbuffers.ReleaseFrame(frame); }
214  virtual void DeLimboFrame(VideoFrame *frame) { vbuffers.DeLimboFrame(frame); }
217  virtual void StartDisplayingFrame(void) { vbuffers.StartDisplayingFrame(); }
220  virtual void DoneDisplayingFrame(VideoFrame *frame)
221  { vbuffers.DoneDisplayingFrame(frame); }
224  virtual void DiscardFrame(VideoFrame *frame) { vbuffers.DiscardFrame(frame); }
227  virtual void DiscardFrames(bool kf) { vbuffers.DiscardFrames(kf); }
230  virtual void ClearDummyFrame(VideoFrame* frame);
231  virtual void CheckFrameStates(void) { }
232 
235  { return vbuffers.GetLastDecodedFrame(); }
236 
240  { return vbuffers.GetLastShownFrame(); }
241 
243  QString GetFrameStatus(void) const { return vbuffers.GetStatus(); }
244 
246  virtual void UpdatePauseFrame(int64_t &disp_timecode) = 0;
247 
249  void SetVideoResize(const QRect &videoRect);
250 
251  void SetVideoScalingAllowed(bool change);
252 
254  bool IsVideoScalingAllowed(void) const;
255 
257  virtual void SetVideoFlip(void) { };
258 
260  virtual QRect GetPIPRect(PIPLocation location,
261  MythPlayer *pipplayer = nullptr,
262  bool do_pixel_adj = true) const;
263  virtual void RemovePIP(MythPlayer *) { }
264 
265  virtual void SetPIPState(PIPState setting);
266 
267  virtual QString GetOSDRenderer(void) const;
268  virtual MythPainter *GetOSDPainter(void) { return (MythPainter*)osd_painter; }
269  virtual bool GetScreenShot(int = 0, int = 0, QString = "") { return false; }
270 
271  QString GetFilters(void) const;
273  QRect GetImageRect(const QRect &rect, QRect *display = nullptr);
274  QRect GetSafeRect(void);
275 
276  // Visualisations
277  bool EnableVisualisation(AudioPlayer *audio, bool enable,
278  const QString &name = QString(""));
279  virtual bool CanVisualise(AudioPlayer *audio, MythRender *render);
280  virtual bool SetupVisualisation(AudioPlayer *audio, MythRender *render,
281  const QString &name);
282  VideoVisual* GetVisualisation(void) { return m_visual; }
283  QString GetVisualiserName(void);
284  virtual QStringList GetVisualiserList(void);
285  void DestroyVisualisation(void);
286 
287  // Hue adjustment for certain vendors (mostly ATI)
288  static int CalcHueBase(const QString &adaptor_name);
289 
290  // 3D TV
291  virtual bool StereoscopicModesAllowed(void) const { return false; }
292  void SetStereoscopicMode(StereoscopicMode mode) { m_stereo = mode; }
293  StereoscopicMode GetStereoscopicMode(void) const { return m_stereo; }
294 
295  protected:
296  void InitBuffers(int numdecode, bool extra_for_pause, int need_free,
297  int needprebuffer_normal, int needprebuffer_small,
298  int keepprebuffer);
299  void InitDisplayMeasurements(uint width, uint height, bool resize);
300  virtual void ShowPIPs(VideoFrame *frame, const PIPMap &pipPlayers);
301  virtual void ShowPIP(VideoFrame *frame,
302  MythPlayer *pipplayer,
303  PIPLocation loc);
304 
305  virtual bool DisplayOSD(VideoFrame *frame, OSD *osd);
306 
307  QRect GetVisibleOSDBounds(float&, float&, float) const;
308  QRect GetTotalOSDBounds(void) const;
309  virtual bool hasFullScreenOSD(void) const { return false; }
310 
311  static void CopyFrame(VideoFrame* to, const VideoFrame* from);
312 
313  void DoPipResize(int pipwidth, int pipheight);
314  void ShutdownPipResize(void);
315 
316  void ResizeVideo(VideoFrame *frame);
317  void DoVideoResize(const QSize &inDim, const QSize &outDim);
318  virtual void ShutdownVideoResize(void);
319 
327 
328  // Video parameters
331 
332  // Picture-in-Picture
336  unsigned char *pip_tmp_buf;
337  unsigned char *pip_tmp_buf2;
338  struct SwsContext *pip_scaling_context;
340 
341  // Video resizing (for ITV)
346  unsigned char *vsz_tmp_buf;
347  struct SwsContext *vsz_scale_context;
348 
349  // Deinterlacing
355 
358 
359  // Various state variables
361  long long framesPlayed;
362 
363  // Custom display resolutions
365 
366  // Display information
367  QSize monitor_sz;
368  QSize monitor_dim;
369 
370  // OSD painter and surface
373  // Hack to ensure osd painter not deleted to soon
375 
376  // Visualisation
378 
379  // 3D TV mode
381 
383 };
384 
385 #endif
virtual void ReleaseFrame(VideoFrame *frame)
Releases a frame from the ready for decoding queue onto the queue of frames ready for display.
Definition: videooutbase.h:212
virtual bool NeedExtraAudioDecode(void) const
Definition: videooutbase.h:167
void SetPrebuffering(bool normal)
Sets whether to use a normal number of buffers or fewer buffers.
Definition: videooutbase.h:184
MythPainter * invalid_osd_painter
Definition: videooutbase.h:374
QString m_deintfiltername
Definition: videooutbase.h:351
virtual long long GetFramesPlayed(void)
Returns the number of frames played.
Definition: videooutbase.h:176
unsigned char * pip_tmp_buf2
Definition: videooutbase.h:337
def scan(profile, smoonURL, gate)
Definition: scan.py:43
int FreeVideoFrames(void)
Returns number of frames available for decoding onto.
Definition: videooutbase.h:192
QMap< MythPlayer *, PIPLocation > PIPMap
Definition: videooutbase.h:37
LetterBoxColour db_letterbox_colour
Definition: videooutbase.h:325
PictureAttributeSupported
MythImage * osd_image
Definition: videooutbase.h:372
bool m_deinterlacing
Definition: videooutbase.h:350
virtual void DiscardFrames(bool kf)
Releases all frames not being actively displayed from any queue onto the queue of frames ready for de...
Definition: videooutbase.h:227
StereoscopicMode GetStereoscopicMode(void) const
Definition: videooutbase.h:293
virtual int ValidVideoFrames(void) const
Returns number of frames that are fully decoded.
Definition: videooutbase.h:189
MythCodecID
Definition: mythcodecid.h:10
VideoColourSpace videoColourSpace
Definition: videooutbase.h:322
MythAVCopy Copy AVFrame<->frame, performing the required conversion if any.
Definition: mythavutil.h:114
virtual void WindowResized(const QSize &)
Definition: videooutbase.h:82
virtual QString GetName(void) const
Definition: videooutbase.h:164
bool EnoughPrebufferedFrames(void)
Returns true iff we have at least the minimum number of decoded frames ready for display.
Definition: videooutbase.h:200
VideoVisual * GetVisualisation(void)
Definition: videooutbase.h:282
FrameScanType
Definition: videoouttypes.h:80
virtual void * GetDecoderContext(unsigned char *, uint8_t *&)
Definition: videooutbase.h:171
QSize db_display_dim
Screen dimensions in millimeters from DB.
Definition: videooutbase.h:321
virtual void SetFramesPlayed(long long fp)
Sets the number of frames played.
Definition: videooutbase.h:174
void SetStereoscopicMode(StereoscopicMode mode)
Definition: videooutbase.h:292
unsigned int uint
Definition: compat.h:140
QSize pip_desired_display_size
Definition: videooutbase.h:333
VideoErrorState
struct SwsContext * pip_scaling_context
Definition: videooutbase.h:338
VideoVisual * m_visual
Definition: videooutbase.h:377
VideoDisplayProfile * db_vdisp_profile
Definition: videooutbase.h:330
VideoDisplayProfile * GetProfile()
Definition: videooutbase.h:79
QString db_deint_filtername
Definition: videooutbase.h:326
virtual void InitPictureAttributes(void)
Definition: videooutbase.h:160
unsigned char * pip_tmp_buf
Definition: videooutbase.h:336
QSize pip_display_size
Definition: videooutbase.h:334
virtual bool StereoscopicModesAllowed(void) const
Definition: videooutbase.h:291
QSize vsz_video_size
Definition: videooutbase.h:345
virtual bool IsPBPSupported(void) const
Definition: videooutbase.h:166
QString GetFrameStatus(void) const
Returns string with status of each frame for debugging.
Definition: videooutbase.h:243
long long framesPlayed
Definition: videooutbase.h:361
AdjustFillMode db_adjustfill
Definition: videooutbase.h:324
virtual void StartDisplayingFrame(void)
Tell GetLastShownFrame() to return the next frame from the head of the queue of frames to display.
Definition: videooutbase.h:217
virtual void ClearAfterSeek(void)
Tells video output to toss decoded buffers due to a seek.
Definition: videooutbase.h:186
This class serves as the base class for all video output methods.
Definition: videooutbase.h:46
VideoFrame pip_tmp_image
Definition: videooutbase.h:339
AspectOverrideMode
Definition: videoouttypes.h:46
virtual bool hasHWAcceleration(void) const
Return true if HW Acceleration is running.
Definition: videooutbase.h:170
VideoBuffers vbuffers
VideoBuffers instance used to track video output buffers.
Definition: videooutbase.h:357
VideoErrorState GetError(void) const
Returns error type.
Definition: videooutbase.h:181
MythCodecID video_codec_id
Definition: videooutbase.h:329
QSize vsz_display_size
Definition: videooutbase.h:344
VideoErrorState errorState
Definition: videooutbase.h:360
virtual VideoFrame * GetNextFreeFrame(void)
Blocks until it is possible to return a frame for decoding onto.
Definition: videooutbase.h:208
virtual void CheckFrameStates(void)
Definition: videooutbase.h:231
virtual bool GetScreenShot(int=0, int=0, QString="")
Definition: videooutbase.h:269
PictureAttribute
Definition: videoouttypes.h:89
QRect vsz_desired_display_rect
Definition: videooutbase.h:343
QString GetDeinterlacer(void)
Definition: videooutbase.h:75
const char * name
Definition: ParseText.cpp:328
virtual void DeLimboFrame(VideoFrame *frame)
Releases a frame for reuse if it is in limbo.
Definition: videooutbase.h:214
unsigned char * vsz_tmp_buf
Definition: videooutbase.h:346
bool IsErrored() const
Returns true if a fatal error has been encountered.
Definition: videooutbase.h:179
virtual void SetVideoFlip(void)
Tells the player to flip the video frames for proper display.
Definition: videooutbase.h:257
bool vsz_enabled
Definition: videooutbase.h:342
QString GetZoomString(void) const
Definition: videooutbase.h:143
MythYUVAPainter * osd_painter
Definition: videooutbase.h:371
DisplayRes * display_res
Definition: videooutbase.h:364
virtual void DoneDisplayingFrame(VideoFrame *frame)
Releases frame returned from GetLastShownFrame() onto the queue of frames ready for decoding onto.
Definition: videooutbase.h:220
virtual bool hasFullScreenOSD(void) const
Definition: videooutbase.h:309
PIPLocation
Definition: videoouttypes.h:19
bool EnoughDecodedFrames(void)
Returns true iff there are plenty of decoded frames ready for display.
Definition: videooutbase.h:197
AdjustFillMode
Definition: videoouttypes.h:57
virtual bool IsPIPSupported(void) const
Definition: videooutbase.h:165
bool EnoughFreeFrames(void)
Returns true iff enough frames are available to decode onto.
Definition: videooutbase.h:194
QSize monitor_dim
Definition: videooutbase.h:368
StereoscopicMode
PIPState
Definition: videoouttypes.h:10
QSize monitor_sz
Definition: videooutbase.h:367
StereoscopicMode m_stereo
Definition: videooutbase.h:380
PictureAttributeSupported GetSupportedPictureAttributes(void)
Definition: videooutbase.h:155
virtual VideoFrame * GetLastShownFrame(void)
Returns frame from the head of the ready to be displayed queue, if StartDisplayingFrame has been call...
Definition: videooutbase.h:239
QSize pip_video_size
Definition: videooutbase.h:335
LetterBoxColour
Definition: videoouttypes.h:72
Definition: osd.h:132
FilterChain * m_deintFilter
Definition: videooutbase.h:353
virtual VideoFrame * GetLastDecodedFrame(void)
Definition: videooutbase.h:234
MythAVCopy m_copyFrame
Definition: videooutbase.h:382
virtual void RemovePIP(MythPlayer *)
Definition: videooutbase.h:263
The DisplayRes module allows for the display resolution and refresh rateto be changed "on the fly".
Definition: DisplayRes.h:32
VideoOutWindow window
Definition: videooutbase.h:320
virtual MythPainter * GetOSDPainter(void)
Definition: videooutbase.h:268
bool m_deinterlaceBeforeOSD
Definition: videooutbase.h:354
FilterManager * m_deintFiltMan
Definition: videooutbase.h:352
This class creates tracks the state of the buffers used by various VideoOutput derived classes.
Definition: videobuffers.h:61
AspectOverrideMode db_aspectoverride
Definition: videooutbase.h:323
ZoomDirection
Definition: videoouttypes.h:28
struct SwsContext * vsz_scale_context
Definition: videooutbase.h:347
virtual void DiscardFrame(VideoFrame *frame)
Releases frame from any queue onto the queue of frames ready for decoding onto.
Definition: videooutbase.h:224