MythTV  master
mythplayer.h
Go to the documentation of this file.
1 #ifndef MYTHPLAYER_H
2 #define MYTHPLAYER_H
3 
4 #include <cstdint>
5 
6 #include <QCoreApplication>
7 #include <QList>
8 #include <QMutex> // for QMutex
9 #include <QTime> // for QTime
10 #include <QString> // for QString
11 #include <QRect> // for QRect
12 #include <QSize> // for QSize
13 #include <QStringList> // for QStringList
14 #include <QWaitCondition> // for QWaitCondition
15 
16 #include "playercontext.h"
17 #include "volumebase.h"
18 #include "osd.h"
19 #include "mythvideoout.h"
20 #include "teletextreader.h"
21 #include "subtitlereader.h"
22 #include "cc608reader.h"
23 #include "cc708reader.h"
24 #include "decoders/decoderbase.h"
25 #include "deletemap.h"
26 #include "commbreakmap.h"
27 #include "audioplayer.h"
28 #include "audiooutputgraph.h"
29 #include "mthread.h" // for MThread
30 #include "mythavutil.h" // for VideoFrame
31 #include "mythtypes.h" // for InfoMap
32 #include "programtypes.h" // for frm_dir_map_t, etc
33 #include "tv.h" // for CommSkipMode
34 #include "videoouttypes.h" // for FrameScanType, PIPLocation, etc
35 
36 #include "mythtvexp.h"
37 
38 class MythVideoOutput;
39 class RemoteEncoder;
40 class MythSqlDatabase;
41 class ProgramInfo;
42 class DecoderBase;
43 class VideoSync;
44 class LiveTVChain;
45 class TV;
46 struct SwsContext;
47 class InteractiveTV;
48 class NSAutoreleasePool;
49 class DetectLetterbox;
50 class MythPlayer;
51 class Jitterometer;
52 class QThread;
53 class QWidget;
54 class RingBuffer;
55 
56 using StatusCallback = void (*)(int, void*);
57 
59 enum TCTypes
60 {
61  TC_VIDEO = 0,
65 };
66 #define TCTYPESMAX 4
67 
68 // Caption Display modes
69 enum
70 {
71  kDisplayNone = 0x000,
75  kDisplayCC608 = 0x008,
76  kDisplayCC708 = 0x010,
84 };
85 
87 {
88  kNoFlags = 0x000000,
89  kDecodeLowRes = 0x000001,
91  kDecodeFewBlocks = 0x000004,
92  kDecodeNoLoopFilter = 0x000008,
93  kDecodeNoDecode = 0x000010,
94  kDecodeDisallowCPU = 0x000020, // NB CPU always available by default
95  kDecodeAllowGPU = 0x000040, // VDPAU, VAAPI, DXVA2
96  kDecodeAllowEXT = 0x000080, // VDA, CrystalHD
97  kVideoIsNull = 0x000100,
98  kAudioMuted = 0x010000,
99  kNoITV = 0x020000,
100  kMusicChoice = 0x040000,
101 };
102 
103 #define FlagIsSet(arg) (m_playerFlags & (arg))
104 
105 class DecoderThread : public MThread
106 {
107  public:
108  DecoderThread(MythPlayer *mp, bool start_paused)
109  : MThread("Decoder"), m_mp(mp), m_startPaused(start_paused) { }
110  ~DecoderThread() override { wait(); }
111 
112  protected:
113  void run(void) override; // MThread
114 
115  private:
118 };
119 
121 {
122  public:
123  MythMultiLocker(std::initializer_list<QMutex*> Locks);
124  MythMultiLocker() = delete;
126 
127  void Unlock(void);
128  void Relock(void);
129 
130  private:
131  Q_DISABLE_COPY(MythMultiLocker)
132  QVector<QMutex*> m_locks;
133 };
134 
136 {
137  public:
138  using Callback = void (*)(void*, void*, void*);
139  DecoderCallback() = default;
140  DecoderCallback(QString &Debug, Callback Function, void *Opaque1, void *Opaque2, void *Opaque3)
141  : m_debug(std::move(Debug)),
142  m_function(Function),
143  m_opaque1(Opaque1),
144  m_opaque2(Opaque2),
145  m_opaque3(Opaque3)
146  {
147  }
148 
149  QString m_debug;
150  Callback m_function { nullptr };
151  void* m_opaque1 { nullptr };
152  void* m_opaque2 { nullptr };
153  void* m_opaque3 { nullptr };
154 };
155 
157 {
158  Q_DECLARE_TR_FUNCTIONS(MythPlayer)
159 
160  // Do NOT add a decoder class to this list
161  friend class PlayerContext;
162  friend class CC708Reader;
163  friend class CC608Reader;
164  friend class DecoderThread;
165  friend class DetectLetterbox;
166  friend class TeletextScreen;
167  friend class SubtitleScreen;
168  friend class InteractiveScreen;
169  friend class BDOverlayScreen;
170  friend class VideoPerformanceTest;
171  // TODO remove these
172  friend class TV;
173  friend class Transcode;
174 
175  public:
176  explicit MythPlayer(PlayerFlags flags = kNoFlags);
177  MythPlayer(const MythPlayer& rhs);
178  virtual ~MythPlayer();
179 
180  // Initialisation
181  virtual int OpenFile(int Retries = 4);
182  bool InitVideo(void);
183 
184  // Public Sets
185  void SetPlayerInfo(TV *tv, QWidget *widget, PlayerContext *ctx);
186  void SetLength(int len) { m_totalLength = len; }
187  void SetFramesPlayed(uint64_t played);
188  void SetEof(EofState eof);
189  void SetPIPActive(bool is_active) { m_pipActive = is_active; }
190  void SetPIPVisible(bool is_visible) { m_pipVisible = is_visible; }
191 
192  void SetTranscoding(bool value);
193  void SetWatchingRecording(bool mode);
194  void SetWatched(bool forceWatched = false);
195  void SetKeyframeDistance(int keyframedistance);
196  void SetVideoParams(int w, int h, double fps, float aspect,
197  bool ForceUpdate, int ReferenceFrames,
199  const QString& codecName = QString());
200  void SetFileLength(int total, int frames);
201  void SetDuration(int duration);
202  void SetVideoResize(const QRect &videoRect);
203  void EnableFrameRateMonitor(bool enable = false);
204  void ForceDeinterlacer(bool DoubleRate, MythDeintType Deinterlacer);
205  void SetFrameRate(double fps);
206 
207  // Gets
208  QSize GetVideoBufferSize(void) const { return m_videoDim; }
209  QSize GetVideoSize(void) const { return m_videoDispDim; }
210  float GetVideoAspect(void) const { return m_videoAspect; }
211  float GetFrameRate(void) const { return m_videoFrameRate; }
212  void GetPlaybackData(InfoMap &infoMap);
213  bool IsAudioNeeded(void)
214  { return !(FlagIsSet(kVideoIsNull)) && m_playerCtx->IsAudioNeeded(); }
215  uint GetVolume(void) { return m_audio.GetVolume(); }
216  int GetFreeVideoFrames(void) const;
217  AspectOverrideMode GetAspectOverride(void) const;
218  AdjustFillMode GetAdjustFill(void) const;
219  MuteState GetMuteState(void) { return m_audio.GetMuteState(); }
220 
221  int GetFFRewSkip(void) const { return m_ffrewSkip; }
222  float GetPlaySpeed(void) const { return m_playSpeed; }
223  AudioPlayer* GetAudio(void) { return &m_audio; }
224  const AudioOutputGraph& GetAudioGraph() const { return m_audiograph; }
225  float GetAudioStretchFactor(void) { return m_audio.GetStretchFactor(); }
226  float GetNextPlaySpeed(void) const { return m_nextPlaySpeed; }
227  int GetLength(void) const { return m_totalLength; }
228  uint64_t GetTotalFrameCount(void) const { return m_totalFrames; }
229  uint64_t GetCurrentFrameCount(void) const;
230  uint64_t GetFramesPlayed(void) const { return m_framesPlayed; }
231  // GetSecondsPlayed() and GetTotalSeconds() internally calculate
232  // in terms of milliseconds and divide the result by 1000. This
233  // divisor can be passed in as an argument, e.g. pass divisor=1 to
234  // return the time in milliseconds.
235  virtual int64_t GetSecondsPlayed(bool honorCutList,
236  int divisor = 1000);
237  virtual int64_t GetTotalSeconds(bool honorCutList,
238  int divisor = 1000) const;
239  int64_t GetLatestVideoTimecode() const { return m_latestVideoTimecode; }
240  virtual uint64_t GetBookmark(void);
241  QString GetError(void) const;
242  QString GetEncodingType(void) const;
243  void GetCodecDescription(InfoMap &infoMap);
244  QString GetXDS(const QString &key) const;
245  PIPLocation GetNextPIPLocation(void) const;
246 
247  // Bool Gets
248  bool IsPaused(void) const { return m_allPaused; }
249  bool GetRawAudioState(void) const;
250  bool GetLimitKeyRepeat(void) const { return m_limitKeyRepeat; }
251  EofState GetEof(void) const;
252  bool IsErrored(void) const;
253  bool IsPlaying(uint wait_in_msec = 0, bool wait_for = true) const;
254  bool AtNormalSpeed(void) const { return m_nextNormalSpeed; }
255  bool IsReallyNearEnd(void) const;
256  bool IsNearEnd(void);
257  bool HasAudioOut(void) const { return m_audio.HasAudioOut(); }
258  bool IsPIPActive(void) const { return m_pipActive; }
259  bool IsPIPVisible(void) const { return m_pipVisible; }
260  bool IsMuted(void) { return m_audio.IsMuted(); }
261  bool PlayerControlsVolume(void) const { return m_audio.ControlsVolume(); }
262  bool UsingNullVideo(void) const { return FlagIsSet(kVideoIsNull); }
263  bool HasTVChainNext(void) const;
264  bool CanSupportDoubleRate(void);
265  bool IsWatchingInprogress(void) const;
266 
267  // Non-const gets
268  virtual char *GetScreenGrabAtFrame(uint64_t FrameNum, bool Absolute, int &BufferSize,
269  int &FrameWidth, int &FrameHeight, float &AspectRatio);
270  virtual char *GetScreenGrab(int SecondsIn, int &BufferSize, int &FrameWidth,
271  int &FrameHeight, float &AspectRatio);
272  InteractiveTV *GetInteractiveTV(void);
273  MythVideoOutput *GetVideoOutput(void) { return m_videoOutput; }
274  MythCodecContext *GetMythCodecContext(void) { return m_decoder->GetMythCodecContext(); }
275 
276  // Title stuff
277  virtual bool SwitchTitle(int /*title*/) { return false; }
278  virtual bool NextTitle(void) { return false; }
279  virtual bool PrevTitle(void) { return false; }
280 
281  // Angle stuff
282  virtual bool SwitchAngle(int /*title*/) { return false; }
283  virtual bool NextAngle(void) { return false; }
284  virtual bool PrevAngle(void) { return false; }
285 
286  // Transcode stuff
287  void InitForTranscode(bool copyaudio, bool copyvideo);
288  bool TranscodeGetNextFrame(int &did_ff, bool &is_key, bool honorCutList);
289  bool WriteStoredData(
290  RingBuffer *outRingBuffer, bool writevideo, long timecodeOffset);
291  long UpdateStoredFrameNum(long curFrameNum);
292  void SetCutList(const frm_dir_map_t &newCutList);
293 
294  // Decoder stuff..
295  VideoFrameType* DirectRenderFormats(void);
296  VideoFrame *GetNextVideoFrame(void);
297  VideoFrame *GetRawVideoFrame(long long frameNumber = -1);
298  VideoFrame *GetCurrentFrame(int &w, int &h);
299  void DeLimboFrame(VideoFrame *frame);
300  virtual void ReleaseNextVideoFrame(VideoFrame *buffer, int64_t timecode,
301  bool wrap = true);
302  void ReleaseCurrentFrame(VideoFrame *frame);
303  void DiscardVideoFrame(VideoFrame *buffer);
304  void DiscardVideoFrames(bool KeyFrame, bool Flushed);
306  DecoderBase *GetDecoder(void) { return m_decoder; }
307  virtual bool HasReachedEof(void) const;
308  void SetDisablePassThrough(bool disabled);
309  void ForceSetupAudioStream(void);
310  static void HandleDecoderCallback(MythPlayer *Player, const QString &Debug,
311  DecoderCallback::Callback Function,
312  void *Opaque1, void *Opaque2);
313  void ProcessCallbacks(void);
314  void QueueCallback(QString Debug, DecoderCallback::Callback Function,
315  void *Opaque1, void *Opaque2, void *Opaque3);
316 
317  // Reinit
318  void ReinitVideo(bool ForceUpdate);
319 
320  // Add data
321  virtual bool PrepareAudioSample(int64_t &timecode);
322 
323  // Public Closed caption and teletext stuff
324  uint GetCaptionMode(void) const { return m_textDisplayMode; }
325  virtual CC708Reader *GetCC708Reader(uint /*id*/=0) { return &m_cc708; }
326  virtual CC608Reader *GetCC608Reader(uint /*id*/=0) { return &m_cc608; }
327  virtual SubtitleReader *GetSubReader(uint /*id*/=0) { return &m_subReader; }
328  virtual TeletextReader *GetTeletextReader(uint /*id*/=0) { return &m_ttxReader; }
329 
330  // Public Audio/Subtitle/EIA-608/EIA-708 stream selection - thread safe
331  void TracksChanged(uint trackType);
332  void EnableSubtitles(bool enable);
333  void EnableForcedSubtitles(bool enable);
334  bool ForcedSubtitlesFavored(void) const {
335  return m_allowForcedSubtitles && !m_captionsEnabledbyDefault;
336  }
337  // How to handle forced Subtitles (i.e. when in a movie someone speaks
338  // in a different language than the rest of the movie, subtitles are
339  // forced on even if the user doesn't have them turned on.)
340  // These two functions are not thread-safe (UI thread use only).
341  void SetAllowForcedSubtitles(bool allow);
342  bool GetAllowForcedSubtitles(void) const { return m_allowForcedSubtitles; }
343 
344  // Public MHEG/MHI stream selection
345  bool SetAudioByComponentTag(int tag);
346  bool SetVideoByComponentTag(int tag);
347  bool SetStream(const QString &stream);
348  long GetStreamPos(); // mS
349  long GetStreamMaxPos(); // mS
350  long SetStreamPos(long ms); // mS
351  void StreamPlay(bool play = true);
352 
353  // LiveTV public stuff
354  void CheckTVChain();
355  void FileChangedCallback();
356 
357  // Chapter public stuff
358  virtual int GetNumChapters(void);
359  virtual int GetCurrentChapter(void);
360  virtual void GetChapterTimes(QList<long long> &times);
361 
362  // Title public stuff
363  virtual int GetNumTitles(void) const { return 0; }
364  virtual int GetCurrentTitle(void) const { return 0; }
365  virtual int GetTitleDuration(int /*title*/) const { return 0; }
366  virtual QString GetTitleName(int /*title*/) const { return QString(); }
367 
368  // Angle public stuff
369  virtual int GetNumAngles(void) const { return 0; }
370  virtual int GetCurrentAngle(void) const { return 0; }
371  virtual QString GetAngleName(int /*title*/) const { return QString(); }
372 
373  // DVD public stuff
374  virtual bool GoToMenu(const QString& /*str*/) { return false; }
375  virtual void GoToDVDProgram(bool direction) { (void) direction; }
376  virtual bool IsInStillFrame() const { return false; }
377 
378  // Position Map Stuff
379  bool PosMapFromEnc(uint64_t start,
380  frm_pos_map_t &posMap,
381  frm_pos_map_t &durMap);
382 
383  // OSD locking for TV class
384  bool TryLockOSD(void) { return m_osdLock.tryLock(50); }
385  void LockOSD(void) { m_osdLock.lock(); }
386  void UnlockOSD(void) { m_osdLock.unlock(); }
387 
388  // Public picture controls
389  void ToggleNightMode(void);
390 
391  // Visualisations
392  bool CanVisualise(void);
393  bool IsVisualising(void);
394  QString GetVisualiserName(void);
395  QStringList GetVisualiserList(void);
396  bool EnableVisualisation(bool enable, const QString &name = QString(""));
397  void AutoVisualise(void);
398 
399  void SaveTotalDuration(void);
400  void ResetTotalDuration(void);
401 
404  static const double kInaccuracyNone;
405  static const double kInaccuracyDefault;
406  static const double kInaccuracyEditor;
407  static const double kInaccuracyFull;
408 
409  void SaveTotalFrames(void);
410  void SetErrored(const QString &reason);
411 
412  protected:
413  // Initialization
414  void OpenDummy(void);
415 
416  // Non-public sets
417  virtual void SetBookmark(bool clear = false);
418  bool AddPIPPlayer(MythPlayer *pip, PIPLocation loc);
419  bool RemovePIPPlayer(MythPlayer *pip);
420  void NextScanType(void)
421  { SetScanType((FrameScanType)(((int)m_scan + 1) & 0x3)); }
422  void SetScanType(FrameScanType scan);
423  FrameScanType GetScanType(void) const { return m_scan; }
424  bool IsScanTypeLocked(void) const { return m_scanLocked; }
425  void Zoom(ZoomDirection direction);
426  void ToggleMoveBottomLine(void);
427  void SaveBottomLine(void);
428  void FileChanged(void);
429 
430 
431  // Windowing stuff
432  void EmbedInWidget(QRect rect);
433  void StopEmbedding(void);
434  bool IsEmbedding(void);
435  void WindowResized(const QSize &new_size);
436 
437  // Audio Sets
438  uint AdjustVolume(int change) { return m_audio.AdjustVolume(change); }
439  uint SetVolume(int newvolume) { return m_audio.SetVolume(newvolume); }
440  bool SetMuted(bool mute) { return m_audio.SetMuted(mute); }
441  MuteState SetMuteState(MuteState state) { return m_audio.SetMuteState(state); }
442  MuteState IncrMuteState(void) { return m_audio.IncrMuteState(); }
443 
444  // Non-const gets
445  OSD *GetOSD(void) { return m_osd; }
446  virtual void SeekForScreenGrab(uint64_t &number, uint64_t frameNum,
447  bool absolute);
448 
449  // Complicated gets
450  virtual long long CalcMaxFFTime(long long ff, bool setjump = true) const;
451  long long CalcRWTime(long long rw) const;
452  virtual void calcSliderPos(osdInfo &info, bool paddedFields = false);
453  uint64_t TranslatePositionFrameToMs(uint64_t position,
454  bool use_cutlist) const;
455  uint64_t TranslatePositionMsToFrame(uint64_t position,
456  bool use_cutlist) const {
457  return m_deleteMap.TranslatePositionMsToFrame(position,
458  GetFrameRate(),
459  use_cutlist);
460  }
461  // TranslatePositionAbsToRel and TranslatePositionRelToAbs are
462  // used for frame calculations when seeking relative to a number
463  // of frames rather than by time.
464  uint64_t TranslatePositionAbsToRel(uint64_t position) const {
465  return m_deleteMap.TranslatePositionAbsToRel(position);
466  }
467  uint64_t TranslatePositionRelToAbs(uint64_t position) const {
468  return m_deleteMap.TranslatePositionRelToAbs(position);
469  }
470  float ComputeSecs(uint64_t position, bool use_cutlist) const {
471  return TranslatePositionFrameToMs(position, use_cutlist) / 1000.0;
472  }
473  uint64_t FindFrame(float offset, bool use_cutlist) const;
474 
475  // Commercial stuff
477  { m_commBreakMap.SetAutoCommercialSkip(autoskip, m_framesPlayed); }
478  void SkipCommercials(int direction)
479  { m_commBreakMap.SkipCommercials(direction); }
480  void SetCommBreakMap(frm_dir_map_t &newMap);
482  { return m_commBreakMap.GetAutoCommercialSkip(); }
483 
484  // Toggle Sets
485  void ToggleAspectOverride(AspectOverrideMode aspectMode = kAspect_Toggle);
486  void ToggleAdjustFill(AdjustFillMode adjustfillMode = kAdjustFill_Toggle);
487 
488  // Start/Reset/Stop playing
489  virtual bool StartPlaying(void);
490  virtual void ResetPlaying(bool resetframes = true);
491  virtual void EndPlaying(void) { }
492  virtual void StopPlaying(void);
493 
494  // Pause stuff
495  bool PauseDecoder(void);
496  void UnpauseDecoder(void);
497  bool Pause(void);
498  bool Play(float speed = 1.0, bool normal = true, bool unpauseaudio = true);
499 
500  // Seek stuff
501  virtual bool FastForward(float seconds);
502  virtual bool Rewind(float seconds);
503  virtual bool JumpToFrame(uint64_t frame);
504 
505  // Chapter stuff
506  void JumpChapter(int chapter);
507 
508  // Playback
509  virtual bool PrebufferEnoughFrames(int min_buffers = 0);
510  void SetBuffering(bool new_buffering);
511  void RefreshPauseFrame(void);
512  void CheckAspectRatio(VideoFrame* frame);
513  virtual void DisplayPauseFrame(void);
514  virtual void DisplayNormalFrame(bool check_prebuffer = true);
515  virtual void PreProcessNormalFrame(void);
516  virtual void VideoStart(void);
517  virtual bool VideoLoop(void);
518  virtual void VideoEnd(void);
519  virtual void DecoderStart(bool start_paused);
520  virtual void DecoderLoop(bool pause);
521  virtual void DecoderEnd(void);
522  virtual void DecoderPauseCheck(void);
523  virtual void AudioEnd(void);
524  virtual void EventStart(void);
525  virtual void EventLoop(void);
526  virtual void InitialSeek(void);
527 
528  // Protected MHEG/MHI stuff
529  bool ITVHandleAction(const QString &action);
530  void ITVRestart(uint chanid, uint cardid, bool isLiveTV);
531 
532  // Edit mode stuff
533  bool EnableEdit(void);
534  bool HandleProgramEditorActions(QStringList &actions);
535  bool GetEditMode(void) const { return m_deleteMap.IsEditing(); }
536  void DisableEdit(int howToSave);
537  bool IsInDelete(uint64_t frame);
538  uint64_t GetNearestMark(uint64_t frame, bool right);
539  bool IsTemporaryMark(uint64_t frame);
540  bool HasTemporaryMark(void);
541  bool IsCutListSaved(void) { return m_deleteMap.IsSaved(); }
542  bool DeleteMapHasUndo(void) { return m_deleteMap.HasUndo(); }
543  bool DeleteMapHasRedo(void) { return m_deleteMap.HasRedo(); }
544  QString DeleteMapGetUndoMessage(void) { return m_deleteMap.GetUndoMessage(); }
545  QString DeleteMapGetRedoMessage(void) { return m_deleteMap.GetRedoMessage(); }
546 
547  // Reinit
548  void ReinitOSD(void);
549 
550  // OSD conveniences
551  void SetOSDMessage(const QString &msg, OSDTimeout timeout);
552  void SetOSDStatus(const QString &title, OSDTimeout timeout);
553 
554  // Closed caption and teletext stuff
555  void ResetCaptions(void);
556  bool ToggleCaptions(void);
557  bool ToggleCaptions(uint type);
558  bool HasTextSubtitles(void) { return m_subReader.HasTextSubtitles(); }
559  void SetCaptionsEnabled(bool enable, bool osd_msg=true);
560  bool GetCaptionsEnabled(void);
561  virtual void DisableCaptions(uint mode, bool osd_msg=true);
562  virtual void EnableCaptions(uint mode, bool osd_msg=true);
563 
564  // Audio/Subtitle/EIA-608/EIA-708 stream selection
565  QStringList GetTracks(uint type);
566  uint GetTrackCount(uint type);
567  virtual int SetTrack(uint type, int trackNo);
568  int GetTrack(uint type);
569  int ChangeTrack(uint type, int dir);
570  void ChangeCaptionTrack(int dir);
571  bool HasCaptionTrack(int mode);
572  int NextCaptionTrack(int mode);
573  void DoDisableForcedSubtitles(void);
574  void DoEnableForcedSubtitles(void);
575 
576  // Teletext Menu and non-NUV teletext decoder
577  void EnableTeletext(int page = 0x100);
578  void DisableTeletext(void);
579  void ResetTeletext(void);
580  bool HandleTeletextAction(const QString &action);
581 
582  // Teletext NUV Captions
583  void SetTeletextPage(uint page);
584 
585  // Time Code adjustment stuff
586  int64_t AdjustAudioTimecodeOffset(int64_t v, int newsync = -9999);
587  int64_t GetAudioTimecodeOffset(void) const
588  { return m_tcWrap[TC_AUDIO]; }
589 
590  // Playback (output) zoom automation
592 
593  protected:
594  // Private initialization stuff
595  FrameScanType detectInterlace(FrameScanType newScan, FrameScanType scan,
596  float fps, int video_height);
597  virtual void AutoDeint(VideoFrame* frame, bool allow_lock = true);
598 
599  // Private Sets
600  void SetPlayingInfo(const ProgramInfo &pginfo);
601  void SetPlaying(bool is_playing);
602  void ResetErrored(void);
603 
604  // Private Gets
605  int GetStatusbarPos(void) const;
606 
607  // Private pausing stuff
608  void PauseVideo(void);
609  void UnpauseVideo(void);
610  void PauseBuffer(void);
611  void UnpauseBuffer(void);
612 
613  // Private decoder stuff
614  virtual void CreateDecoder(char *TestBuffer, int TestSize);
615  void SetDecoder(DecoderBase *dec);
617  const DecoderBase *GetDecoder(void) const { return m_decoder; }
618  bool DecodeFrame(struct rtframeheader *frameheader,
619  unsigned char *strm, unsigned char *outbuf);
620 
621  virtual bool DecoderGetFrameFFREW(void);
622  virtual bool DecoderGetFrameREW(void);
623  bool DecoderGetFrame(DecodeType decodetype, bool unsafe = false);
624  bool DoGetFrame(DecodeType DecodeType);
625 
626  // These actually execute commands requested by public members
627  bool UpdateFFRewSkip(void);
628  virtual void ChangeSpeed(void);
629  // The "inaccuracy" argument is generally one of the kInaccuracy* values.
630  bool DoFastForward(uint64_t frames, double inaccuracy);
631  bool DoRewind(uint64_t frames, double inaccuracy);
632  bool DoFastForwardSecs(float secs, double inaccuracy, bool use_cutlist);
633  bool DoRewindSecs(float secs, double inaccuracy, bool use_cutlist);
634  void DoJumpToFrame(uint64_t frame, double inaccuracy);
635 
636  // Private seeking stuff
637  void WaitForSeek(uint64_t frame, uint64_t seeksnap_wanted);
638  void ClearAfterSeek(bool clearvideobuffers = true);
639  void ClearBeforeSeek(uint64_t Frames);
640 
641  // Private chapter stuff
642  virtual bool DoJumpChapter(int chapter);
643  virtual int64_t GetChapter(int chapter);
644 
645  // Private edit stuff
646  void HandleArbSeek(bool right);
647 
648  // Private A/V Sync Stuff
649  void WrapTimecode(int64_t &timecode, TCTypes tc_type);
650  void InitAVSync(void);
651  virtual void AVSync(VideoFrame *buffer);
652  void ResetAVSync(void);
653  void SetFrameInterval(FrameScanType scan, double frame_period);
654  void WaitForTime(int64_t framedue);
655 
656  // Private LiveTV stuff
657  void SwitchToProgram(void);
658  void JumpToProgram(void);
659  void JumpToStream(const QString &stream);
660 
661  protected:
663  DecoderBase *m_decoder {nullptr};
665  QVector<DecoderCallback> m_decoderCallbacks;
666  mutable QMutex m_decoderChangeLock {QMutex::Recursive};
667  MythVideoOutput *m_videoOutput {nullptr};
668  PlayerContext *m_playerCtx {nullptr};
669  DecoderThread *m_decoderThread {nullptr};
670  QThread *m_playerThread {nullptr};
671 
672 #ifdef Q_OS_ANDROID
673  int m_playerThreadId {0};
674 #endif
675 
676  // Window stuff
677  MythDisplay* m_display {nullptr};
678  QWidget *m_parentWidget {nullptr};
679  bool m_embedding {false};
680  QRect m_embedRect {0,0,0,0};
681 
682  // State
683  QWaitCondition m_decoderThreadPause;
684  QWaitCondition m_decoderThreadUnpause;
685  mutable QMutex m_decoderPauseLock;
686  mutable QMutex m_decoderSeekLock;
687  bool m_totalDecoderPause {false};
688  bool m_decoderPaused {false};
689  bool m_inJumpToProgramPause {false};
690  bool m_pauseDecoder {false};
691  bool m_unpauseDecoder {false};
692  bool volatile m_killDecoder {false};
693  int64_t m_decoderSeek {-1};
694  bool m_decodeOneFrame {false};
695  bool m_needNewPauseFrame {false};
696  mutable QMutex m_bufferPauseLock;
697  mutable QMutex m_videoPauseLock;
698  mutable QMutex m_pauseLock;
699  bool m_bufferPaused {false};
700  bool m_videoPaused {false};
701  bool m_allPaused {false};
702  bool m_playing {false};
703 
704  mutable QWaitCondition m_playingWaitCond;
705  mutable QMutex m_vidExitLock;
706  mutable QMutex m_playingLock;
707  bool m_doubleFramerate {false};
708  bool m_liveTV {false};
709  bool m_watchingRecording {false};
710  bool m_transcoding {false};
711  bool m_hasFullPositionMap {false};
712  mutable bool m_limitKeyRepeat {false};
713  mutable QMutex m_errorLock;
714  QString m_errorMsg;
715  int m_errorType {kError_None};
716 
717  // Chapter stuff
718  int m_jumpChapter {0};
719 
720  // Bookmark stuff
721  uint64_t m_bookmarkSeek {0};
722  int m_clearSavedPosition {1};
724 
725  // Seek
728  long long m_ffTime {0};
729 
730  // Playback misc.
732  int m_videobufRetries {0};
733  uint64_t m_framesPlayed {0};
734  // "Fake" frame counter for when the container frame rate doesn't
735  // match the stream frame rate.
736  uint64_t m_framesPlayedExtra {0};
737  uint64_t m_totalFrames {0};
738  long long m_totalLength {0};
739  int64_t m_totalDuration {0};
740  long long m_rewindTime {0};
741  int64_t m_latestVideoTimecode {-1};
742  QElapsedTimer m_avTimer;
743 
744  // Tracks deinterlacer for Debug OSD
745  MythDeintType m_lastDeinterlacer { DEINT_NONE };
746  bool m_lastDeinterlacer2x { false };
747  VideoFrameType m_lastFrameCodec { FMT_NONE };
748 
749  // -- end state stuff --
750 
751  // Input Video Attributes
752  QSize m_videoDispDim {0,0};
753  QSize m_videoDim {0,0};
754  int m_maxReferenceFrames {0};
755  double m_videoFrameRate {29.97};
756  float m_videoAspect {4.0F / 3.0F};
757  float m_forcedVideoAspect {-1};
763  bool m_scanLocked {false};
765  int m_scanTracker {0};
767  bool m_scanInitialized {false};
769  uint m_keyframeDist {30};
771  QString m_codecName;
772 
773  // Buffering
774  bool m_buffering {false};
777 
778  // General Caption/Teletext/Subtitle support
779  uint m_textDisplayMode {kDisplayNone};
780  uint m_prevTextDisplayMode {kDisplayNone};
781  uint m_prevNonzeroTextDisplayMode {kDisplayNone};
782 
783  // Support for analog captions and teletext
784  // (i.e. Vertical Blanking Interval (VBI) encoded data.)
785  uint m_vbiMode {VBIMode::None};
786  int m_ttPageNum {0x888};
787 
788  // Support for captions, teletext, etc. decoded by libav
793  bool m_captionsEnabledbyDefault {false};
794  bool m_textDesired {false};
795  bool m_enableCaptions {false};
796  bool m_disableCaptions {false};
797  bool m_enableForcedSubtitles {false};
798  bool m_disableForcedSubtitles {false};
799  bool m_allowForcedSubtitles {true};
800 
801  // CC608/708
804 
805  // Support for MHEG/MHI
806  bool m_itvVisible {false};
807  InteractiveTV *m_interactiveTV {nullptr};
808  bool m_itvEnabled {false};
809  QMutex m_itvLock;
810  QMutex m_streamLock;
811  QString m_newStream; // Guarded by streamLock
812 
813  // OSD stuff
814  OSD *m_osd {nullptr};
815  bool m_reinitOsd {false};
816  QMutex m_osdLock {QMutex::Recursive};
817 
818  // Audio stuff
821 
822  // Picture-in-Picture
824  volatile bool m_pipActive {false};
825  volatile bool m_pipVisible {true};
827 
828  // Commercial filtering
830  bool m_forcePositionMapSync {false};
831  // Manual editing
833  bool m_pausedBeforeEdit {false};
834  QElapsedTimer m_editUpdateTimer;
835  float m_speedBeforeEdit {1.0F};
836 
837  // Playback (output) speed control
839  QMutex m_decoderLock {QMutex::Recursive};
840  float m_nextPlaySpeed {1.0F};
841  bool m_nextNormalSpeed {true};
842 
843  float m_playSpeed {1.0F};
844  bool m_normalSpeed {true};
845  int m_frameInterval {static_cast<int>((1000000.0F / 30))};
846  int m_frameIntervalPrev {0};
847  int m_fpsMultiplier {1};
848 
849  int m_ffrewSkip {1};
850  int m_ffrewAdjust {0};
851  bool m_fileChanged {false};
852 
853  // Audio and video synchronization stuff
854  VideoSync *m_videoSync {nullptr};
855  int m_avsyncAvg {0};
856  int m_avsyncPredictor {0};
857  int m_refreshRate {0};
858  int64_t m_dispTimecode {0};
859  bool m_avsyncAudioPaused {false};
860  int64_t m_rtcBase {0}; // real time clock base for presentation time (microsecs)
861  int64_t m_maxTcVal {0}; // maximum to date video tc
862  int m_maxTcFrames {0}; // number of frames seen since max to date tc
863  int m_numDroppedFrames {0}; // number of consecutive dropped frames.
864  int64_t m_priorAudioTimecode {0}; // time code from prior frame
865  int64_t m_priorVideoTimecode {0}; // time code from prior frame
866  float m_lastFix {0.0F}; //last sync adjustment to prior frame
867  int64_t m_timeOffsetBase {0};
868 
869  // Time Code stuff
870  int m_prevTc {0};
871  int m_prevRp {0};
872  int64_t m_tcWrap[TCTYPESMAX] {};
873  int64_t m_tcLastVal[TCTYPESMAX] {};
874  int64_t m_savedAudioTimecodeOffset {0};
875 
876  // LiveTV
877  TV *m_tv {nullptr};
878  bool m_isDummy {false};
879 
880  // Counter for buffering messages
881  int m_bufferingCounter {0};
882 
883  // Debugging variables
884  Jitterometer *m_outputJmeter {nullptr};
885 
886  private:
887  void syncWithAudioStretch();
888  bool m_disablePassthrough {false};
889 };
890 
891 #endif
892 
893 /* vim: set expandtab tabstop=4 shiftwidth=4: */
void LockOSD(void)
Definition: mythplayer.h:385
float GetPlaySpeed(void) const
Definition: mythplayer.h:222
void SetPIPActive(bool is_active)
Definition: mythplayer.h:189
virtual CC708Reader * GetCC708Reader(uint=0)
Definition: mythplayer.h:325
bool ForcedSubtitlesFavored(void) const
Definition: mythplayer.h:334
const AudioOutputGraph & GetAudioGraph() const
Definition: mythplayer.h:224
QMap< MythPlayer *, PIPLocation > PIPMap
Definition: mythvideoout.h:32
float ComputeSecs(uint64_t position, bool use_cutlist) const
Definition: mythplayer.h:470
float GetVideoAspect(void) const
Definition: mythplayer.h:210
void SkipCommercials(int direction)
Definition: mythplayer.h:478
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
DetectLetterbox * m_detectLetterBox
Definition: mythplayer.h:591
def scan(profile, smoonURL, gate)
Definition: scan.py:57
QString m_debug
Definition: mythplayer.h:149
int64_t GetAudioTimecodeOffset(void) const
Definition: mythplayer.h:587
void(*)(int, void *) StatusCallback
Definition: mythplayer.h:56
PlayerFlags
Definition: mythplayer.h:86
static int SetCutList(uint chanid, const QDateTime &starttime, QString newCutList)
QElapsedTimer m_editUpdateTimer
Definition: mythplayer.h:834
static const int kNightModeBrightenssAdjustment
Definition: mythplayer.h:402
MuteState IncrMuteState(void)
Definition: mythplayer.h:442
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
bool UsingNullVideo(void) const
Definition: mythplayer.h:262
bool DeleteMapHasRedo(void)
Definition: mythplayer.h:543
void(*)(void *, void *, void *) Callback
Definition: mythplayer.h:138
bool wait(unsigned long time=ULONG_MAX)
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:311
static const double kInaccuracyFull
Definition: mythplayer.h:407
MuteState
Definition: volumebase.h:6
static const double kInaccuracyDefault
Definition: mythplayer.h:405
bool IsAudioNeeded(void)
Definition: mythplayer.h:213
virtual int GetCurrentAngle(void) const
Definition: mythplayer.h:370
void Unlock(void)
Definition: mythplayer.cpp:135
FrameScanType
Definition: videoouttypes.h:78
float GetAudioStretchFactor(void)
Definition: mythplayer.h:225
VideoFrameType
Definition: mythframe.h:23
PIPMap m_pipPlayers
Definition: mythplayer.h:823
int GetLength(void) const
Definition: mythplayer.h:227
DecoderThread(MythPlayer *mp, bool start_paused)
Definition: mythplayer.h:108
virtual bool NextTitle(void)
Definition: mythplayer.h:278
virtual TeletextReader * GetTeletextReader(uint=0)
Definition: mythplayer.h:328
void Relock(void)
Definition: mythplayer.cpp:142
bool DeleteMapHasUndo(void)
Definition: mythplayer.h:542
virtual bool SwitchAngle(int)
Definition: mythplayer.h:282
MythMultiLocker()=delete
QMutex m_playingLock
Definition: mythplayer.h:706
#define SetOSDMessage(CTX, MESSAGE)
Definition: tv_play.cpp:102
CommBreakMap m_commBreakMap
Definition: mythplayer.h:829
MythDeintType
Definition: mythframe.h:120
uint GetVolume(void)
Definition: mythplayer.h:215
uint64_t TranslatePositionRelToAbs(uint64_t position) const
Definition: mythplayer.h:467
#define FlagIsSet(arg)
Definition: mythplayer.h:103
QVector< QMutex * > m_locks
Definition: mythplayer.h:132
QMap< long long, long long > frm_pos_map_t
Frame # -> File offset map.
Definition: programtypes.h:46
EofState
Definition: decoderbase.h:67
QString DeleteMapGetRedoMessage(void)
Definition: mythplayer.h:545
OSDTimeout
Definition: osd.h:57
uint GetCaptionMode(void) const
Definition: mythplayer.h:324
Holds information on recordings and videos.
Definition: programinfo.h:67
AspectOverrideMode
Definition: videoouttypes.h:44
QSize GetVideoSize(void) const
Definition: mythplayer.h:209
QMutex m_errorLock
Definition: mythplayer.h:713
MythCodecContext * GetMythCodecContext(void)
Definition: mythplayer.h:274
MythVideoOutput * GetVideoOutput(void)
Definition: mythplayer.h:273
AudioPlayer * GetAudio(void)
Definition: mythplayer.h:223
virtual void GoToDVDProgram(bool direction)
Definition: mythplayer.h:375
QString m_newStream
Definition: mythplayer.h:811
#define MTV_PUBLIC
Definition: mythtvexp.h:15
QMutex m_decoderSeekLock
Definition: mythplayer.h:686
virtual int GetTitleDuration(int) const
Definition: mythplayer.h:365
static void clear(SettingsMap &cache, SettingsMap &overrides, const QString &myKey)
Definition: mythdb.cpp:846
bool IsScanTypeLocked(void) const
Definition: mythplayer.h:424
QWaitCondition m_decoderThreadPause
Definition: mythplayer.h:683
QMutex m_vidExitLock
Definition: mythplayer.h:705
virtual QString GetTitleName(int) const
Definition: mythplayer.h:366
void NextScanType(void)
Definition: mythplayer.h:420
CommSkipMode
Definition: tv.h:130
FrameScanType GetScanType(void) const
Definition: mythplayer.h:423
virtual int GetNumAngles(void) const
Definition: mythplayer.h:369
virtual bool GoToMenu(const QString &)
Definition: mythplayer.h:374
QMutex m_pauseLock
Definition: mythplayer.h:698
static const double kInaccuracyEditor
Definition: mythplayer.h:406
virtual bool IsInStillFrame() const
Definition: mythplayer.h:376
float GetFrameRate(void) const
Definition: mythplayer.h:211
uint SetVolume(int newvolume)
Definition: mythplayer.h:439
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: mythplayer.cpp:92
Virtual base class for all video synchronization classes.
Definition: vsync.h:45
const DecoderBase * GetDecoder(void) const
Returns the stream decoder currently in use.
Definition: mythplayer.h:617
Control TV playback.
Definition: tv_play.h:279
OSD * GetOSD(void)
Definition: mythplayer.h:445
bool HasTextSubtitles(void)
Definition: mythplayer.h:558
bool GetLimitKeyRepeat(void) const
Definition: mythplayer.h:250
static uint8_t * SetLength(uint8_t *Data, int Length)
Definition: dvbci.cpp:117
virtual int GetNumTitles(void) const
Definition: mythplayer.h:363
QString m_errorMsg
Reason why NVP exited with a error.
Definition: mythplayer.h:714
unsigned int uint
Definition: compat.h:140
DecoderCallback(QString &Debug, Callback Function, void *Opaque1, void *Opaque2, void *Opaque3)
Definition: mythplayer.h:140
QMutex m_itvLock
Definition: mythplayer.h:809
void UnlockOSD(void)
Definition: mythplayer.h:386
MythPlayer * m_mp
Definition: mythplayer.h:116
QWaitCondition m_playingWaitCond
Definition: mythplayer.h:704
QMutex m_videoPauseLock
Definition: mythplayer.h:697
bool PlayerControlsVolume(void) const
Definition: mythplayer.h:261
int GetFFRewSkip(void) const
Definition: mythplayer.h:221
virtual void EndPlaying(void)
Definition: mythplayer.h:491
MuteState SetMuteState(MuteState state)
Definition: mythplayer.h:441
uint AdjustVolume(int change)
Definition: mythplayer.h:438
QVector< DecoderCallback > m_decoderCallbacks
Definition: mythplayer.h:665
virtual bool PrevTitle(void)
Definition: mythplayer.h:279
PIPLocation
Definition: videoouttypes.h:17
AdjustFillMode
Definition: videoouttypes.h:55
bool AtNormalSpeed(void) const
Definition: mythplayer.h:254
static const double kInaccuracyNone
Definition: mythplayer.h:404
QSize GetVideoBufferSize(void) const
Definition: mythplayer.h:208
virtual bool NextAngle(void)
Definition: mythplayer.h:283
bool m_startPaused
Definition: mythplayer.h:117
void SetAutoCommercialSkip(CommSkipMode autoskip)
Definition: mythplayer.h:476
virtual bool SwitchTitle(int)
Definition: mythplayer.h:277
QMutex m_decoderPauseLock
Definition: mythplayer.h:685
uint64_t GetFramesPlayed(void) const
Definition: mythplayer.h:230
AudioPlayer m_audio
Definition: mythplayer.h:819
bool HasAudioOut(void) const
Definition: mythplayer.h:257
AudioOutputGraph m_audiograph
Definition: mythplayer.h:820
DecodeType
Definition: decoderbase.h:47
CC608Reader m_cc608
Definition: mythplayer.h:802
SubtitleReader m_subReader
Definition: mythplayer.h:789
QMutex m_streamLock
Definition: mythplayer.h:810
static const int kNightModeContrastAdjustment
Definition: mythplayer.h:403
QTime m_bufferingStart
Definition: mythplayer.h:775
QWaitCondition m_decoderThreadUnpause
Definition: mythplayer.h:684
uint64_t TranslatePositionAbsToRel(uint64_t position) const
Definition: mythplayer.h:464
int64_t GetLatestVideoTimecode() const
Definition: mythplayer.h:239
~DecoderThread() override
Definition: mythplayer.h:110
uint64_t GetTotalFrameCount(void) const
Definition: mythplayer.h:228
QString DeleteMapGetUndoMessage(void)
Definition: mythplayer.h:544
Definition: osd.h:131
QString m_codecName
Codec Name - used by playback profile.
Definition: mythplayer.h:771
CommSkipMode GetAutoCommercialSkip(void)
Definition: mythplayer.h:481
const char * frames[3]
Definition: element.c:46
MuteState GetMuteState(void)
Definition: mythplayer.h:219
QElapsedTimer m_avTimer
Definition: mythplayer.h:742
uint64_t TranslatePositionMsToFrame(uint64_t position, bool use_cutlist) const
Definition: mythplayer.h:455
int m_endExitPrompt
Definition: mythplayer.h:723
DeleteMap m_deleteMap
Definition: mythplayer.h:832
QMap< uint64_t, MarkTypes > frm_dir_map_t
Frame # -> Mark map.
Definition: programtypes.h:81
bool SetMuted(bool mute)
Definition: mythplayer.h:440
Implements a file/stream reader/writer.
virtual CC608Reader * GetCC608Reader(uint=0)
Definition: mythplayer.h:326
PIPLocation m_pipDefaultLoc
Definition: mythplayer.h:826
QMutex m_decoderCallbackLock
Definition: mythplayer.h:664
virtual QString GetAngleName(int) const
Definition: mythplayer.h:371
bool IsPIPVisible(void) const
Definition: mythplayer.h:259
void SetPIPVisible(bool is_visible)
Definition: mythplayer.h:190
float GetNextPlaySpeed(void) const
Definition: mythplayer.h:226
#define TCTYPESMAX
Definition: mythplayer.h:66
CC708Reader m_cc708
Definition: mythplayer.h:803
virtual bool PrevAngle(void)
Definition: mythplayer.h:284
bool IsPaused(void) const
Definition: mythplayer.h:248
virtual int GetCurrentTitle(void) const
Definition: mythplayer.h:364
bool GetEditMode(void) const
Definition: mythplayer.h:535
ZoomDirection
Definition: videoouttypes.h:26
bool TryLockOSD(void)
Definition: mythplayer.h:384
QTime m_bufferingLastMsg
Definition: mythplayer.h:776
Keeps track of recordings in a current LiveTV instance.
Definition: livetvchain.h:31
PlayerFlags m_playerFlags
Definition: mythplayer.h:662
static int x3
Definition: mythsocket.cpp:62
bool GetAllowForcedSubtitles(void) const
Definition: mythplayer.h:342
DecoderBase * GetDecoder(void)
Returns the stream decoder currently in use.
Definition: mythplayer.h:306
This is the interface between an MHEG engine and a MythTV TV object.
Definition: interactivetv.h:12
TeletextReader m_ttxReader
Definition: mythplayer.h:790
TCTypes
Timecode types.
Definition: mythplayer.h:59
QMutex m_bufferPauseLock
Definition: mythplayer.h:696
bool IsPIPActive(void) const
Definition: mythplayer.h:258
bool IsCutListSaved(void)
Definition: mythplayer.h:541
bool IsMuted(void)
Definition: mythplayer.h:260
virtual SubtitleReader * GetSubReader(uint=0)
Definition: mythplayer.h:327