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