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 "videooutbase.h"
20 #include "teletextreader.h"
21 #include "subtitlereader.h"
22 #include "cc608reader.h"
23 #include "cc708reader.h"
24 #include "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 VideoOutput;
39 class RemoteEncoder;
40 class MythSqlDatabase;
41 class ProgramInfo;
42 class DecoderBase;
43 class FilterManager;
44 class FilterChain;
45 class VideoSync;
46 class LiveTVChain;
47 class TV;
48 struct SwsContext;
49 class InteractiveTV;
50 class NSAutoreleasePool;
51 class DetectLetterbox;
52 class MythPlayer;
53 class Jitterometer;
54 class QThread;
55 class QWidget;
56 class RingBuffer;
57 
58 typedef void (*StatusCallback)(int, void*);
59 
61 enum TCTypes
62 {
63  TC_VIDEO = 0,
67 };
68 #define TCTYPESMAX 4
69 
70 // Caption Display modes
71 enum
72 {
73  kDisplayNone = 0x000,
77  kDisplayCC608 = 0x008,
78  kDisplayCC708 = 0x010,
86 };
87 
89 {
90  kNoFlags = 0x000000,
91  kDecodeLowRes = 0x000001,
93  kDecodeFewBlocks = 0x000004,
94  kDecodeNoLoopFilter = 0x000008,
95  kDecodeNoDecode = 0x000010,
96  kDecodeDisallowCPU = 0x000020, // NB CPU always available by default
97  kDecodeAllowGPU = 0x000040, // VDPAU, VAAPI, DXVA2
98  kDecodeAllowEXT = 0x000080, // VDA, CrystalHD
99  kVideoIsNull = 0x000100,
100  kAudioMuted = 0x010000,
101  kNoITV = 0x020000,
102  kMusicChoice = 0x040000,
103 };
104 
105 #define FlagIsSet(arg) (playerFlags & arg)
106 
107 class DecoderThread : public MThread
108 {
109  public:
110  DecoderThread(MythPlayer *mp, bool start_paused)
111  : MThread("Decoder"), m_mp(mp), m_start_paused(start_paused) { }
113 
114  protected:
115  void run(void) override; // MThread
116 
117  private:
120 };
121 
123 {
124  Q_DECLARE_TR_FUNCTIONS(MythPlayer)
125 
126  // Do NOT add a decoder class to this list
127  friend class PlayerContext;
128  friend class CC708Reader;
129  friend class CC608Reader;
130  friend class DecoderThread;
131  friend class DetectLetterbox;
132  friend class TeletextScreen;
133  friend class SubtitleScreen;
134  friend class InteractiveScreen;
135  friend class BDOverlayScreen;
136  friend class VideoPerformanceTest;
137  // TODO remove these
138  friend class TV;
139  friend class Transcode;
140 
141  public:
142  explicit MythPlayer(PlayerFlags flags = kNoFlags);
143  MythPlayer(const MythPlayer& rhs);
144  virtual ~MythPlayer();
145 
146  // Initialisation
147  virtual int OpenFile(uint retries = 4);
148  bool InitVideo(void);
149 
150  // Public Sets
151  void SetPlayerInfo(TV *tv, QWidget *widget, PlayerContext *ctx);
152  void SetLength(int len) { totalLength = len; }
153  void SetFramesPlayed(uint64_t played);
154  void SetVideoFilters(const QString &overridefilter);
155  void SetEof(EofState eof);
156  void SetPIPActive(bool is_active) { pip_active = is_active; }
157  void SetPIPVisible(bool is_visible) { pip_visible = is_visible; }
158 
159  void SetTranscoding(bool value);
160  void SetWatchingRecording(bool mode);
161  void SetWatched(bool forceWatched = false);
162  void SetKeyframeDistance(int keyframedistance);
163  void SetVideoParams(int w, int h, double fps,
164  FrameScanType scan = kScan_Ignore, const QString& codecName = QString());
165  void SetFileLength(int total, int frames);
166  void SetDuration(int duration);
167  void SetVideoResize(const QRect &videoRect);
168  void EnableFrameRateMonitor(bool enable = false);
169  void ForceDeinterlacer(const QString &override = QString());
170  void SetFrameRate(double fps);
171 
172  // Gets
173  QSize GetVideoBufferSize(void) const { return video_dim; }
174  QSize GetVideoSize(void) const { return video_disp_dim; }
175  float GetVideoAspect(void) const { return video_aspect; }
176  float GetFrameRate(void) const { return video_frame_rate; }
177  void GetPlaybackData(InfoMap &infoMap);
178  bool IsAudioNeeded(void)
179  { return !(FlagIsSet(kVideoIsNull)) && player_ctx->IsAudioNeeded(); }
180  uint GetVolume(void) { return audio.GetVolume(); }
181  int GetSecondsBehind(void) const;
182  int GetFreeVideoFrames(void) const;
183  AspectOverrideMode GetAspectOverride(void) const;
184  AdjustFillMode GetAdjustFill(void) const;
185  MuteState GetMuteState(void) { return audio.GetMuteState(); }
186 
187  int GetFFRewSkip(void) const { return ffrew_skip; }
188  float GetPlaySpeed(void) const { return play_speed; }
189  AudioPlayer* GetAudio(void) { return &audio; }
190  const AudioOutputGraph& GetAudioGraph() const { return m_audiograph; }
191  float GetAudioStretchFactor(void) { return audio.GetStretchFactor(); }
192  float GetNextPlaySpeed(void) const { return next_play_speed; }
193  int GetLength(void) const { return totalLength; }
194  uint64_t GetTotalFrameCount(void) const { return totalFrames; }
195  uint64_t GetCurrentFrameCount(void) const;
196  uint64_t GetFramesPlayed(void) const { return framesPlayed; }
197  // GetSecondsPlayed() and GetTotalSeconds() internally calculate
198  // in terms of milliseconds and divide the result by 1000. This
199  // divisor can be passed in as an argument, e.g. pass divisor=1 to
200  // return the time in milliseconds.
201  virtual int64_t GetSecondsPlayed(bool honorCutList,
202  int divisor = 1000) const;
203  virtual int64_t GetTotalSeconds(bool honorCutList,
204  int divisor = 1000) const;
205  int64_t GetLatestVideoTimecode() const { return m_latestVideoTimecode; }
206  virtual uint64_t GetBookmark(void);
207  QString GetError(void) const;
208  bool IsErrorRecoverable(void) const
209  { return (errorType & kError_Switch_Renderer); }
210  bool IsDecoderErrored(void) const
211  { return (errorType & kError_Decode); }
212  QString GetEncodingType(void) const;
213  void GetCodecDescription(InfoMap &infoMap);
214  QString GetXDS(const QString &key) const;
215  PIPLocation GetNextPIPLocation(void) const;
216 
217  // Bool Gets
218  bool IsPaused(void) const { return allpaused; }
219  bool GetRawAudioState(void) const;
220  bool GetLimitKeyRepeat(void) const { return limitKeyRepeat; }
221  EofState GetEof(void) const;
222  bool IsErrored(void) const;
223  bool IsPlaying(uint wait_in_msec = 0, bool wait_for = true) const;
224  bool AtNormalSpeed(void) const { return next_normal_speed; }
225  bool IsReallyNearEnd(void) const;
226  bool IsNearEnd(void);
227  bool HasAudioOut(void) const { return audio.HasAudioOut(); }
228  bool IsPIPActive(void) const { return pip_active; }
229  bool IsPIPVisible(void) const { return pip_visible; }
230  bool IsMuted(void) { return audio.IsMuted(); }
231  bool PlayerControlsVolume(void) const { return audio.ControlsVolume(); }
232  bool UsingNullVideo(void) const { return FlagIsSet(kVideoIsNull); }
233  bool HasTVChainNext(void) const;
234  bool CanSupportDoubleRate(void);
235  bool GetScreenShot(int width = 0, int height = 0, QString filename = "");
236  bool IsWatchingInprogress(void) const;
237 
238  // Non-const gets
239  virtual char *GetScreenGrabAtFrame(uint64_t frameNum, bool absolute,
240  int &bufflen, int &vw, int &vh, float &ar);
241  virtual char *GetScreenGrab(int secondsin, int &bufflen,
242  int &vw, int &vh, float &ar);
243  InteractiveTV *GetInteractiveTV(void);
244  VideoOutput *GetVideoOutput(void) { return videoOutput; }
245  MythCodecContext *GetMythCodecContext(void) { return decoder->GetMythCodecContext(); }
246 
247  // Title stuff
248  virtual bool SwitchTitle(int /*title*/) { return false; }
249  virtual bool NextTitle(void) { return false; }
250  virtual bool PrevTitle(void) { return false; }
251 
252  // Angle stuff
253  virtual bool SwitchAngle(int /*title*/) { return false; }
254  virtual bool NextAngle(void) { return false; }
255  virtual bool PrevAngle(void) { return false; }
256 
257  // Transcode stuff
258  void InitForTranscode(bool copyaudio, bool copyvideo);
259  bool TranscodeGetNextFrame(int &did_ff, bool &is_key, bool honorCutList);
260  bool WriteStoredData(
261  RingBuffer *outRingBuffer, bool writevideo, long timecodeOffset);
262  long UpdateStoredFrameNum(long curFrameNum);
263  void SetCutList(const frm_dir_map_t &newCutList);
264 
265  // Decoder stuff..
266  VideoFrame *GetNextVideoFrame(void);
267  VideoFrame *GetRawVideoFrame(long long frameNumber = -1);
268  VideoFrame *GetCurrentFrame(int &w, int &h);
269  void DeLimboFrame(VideoFrame *frame);
270  virtual void ReleaseNextVideoFrame(VideoFrame *buffer, int64_t timecode,
271  bool wrap = true);
272  void ReleaseCurrentFrame(VideoFrame *frame);
273  void ClearDummyVideoFrame(VideoFrame *frame);
274  void DiscardVideoFrame(VideoFrame *buffer);
275  void DiscardVideoFrames(bool next_frame_keyframe);
276  void DrawSlice(VideoFrame *frame, int x, int y, int w, int h);
278  DecoderBase *GetDecoder(void) { return decoder; }
279  void *GetDecoderContext(unsigned char* buf, uint8_t*& id);
280  virtual bool HasReachedEof(void) const;
281  void SetDisablePassThrough(bool disabled);
282  void ForceSetupAudioStream(void);
283 
284  // Preview Image stuff
285  void SaveScreenshot(void);
286 
287  // Reinit
288  void ReinitVideo(void);
289 
290  // Add data
291  virtual bool PrepareAudioSample(int64_t &timecode);
292 
293  // Public Closed caption and teletext stuff
294  uint GetCaptionMode(void) const { return textDisplayMode; }
295  virtual CC708Reader *GetCC708Reader(uint /*id*/=0) { return &cc708; }
296  virtual CC608Reader *GetCC608Reader(uint /*id*/=0) { return &cc608; }
297  virtual SubtitleReader *GetSubReader(uint /*id*/=0) { return &subReader; }
298  virtual TeletextReader *GetTeletextReader(uint /*id*/=0) { return &ttxReader; }
299 
300  // Public Audio/Subtitle/EIA-608/EIA-708 stream selection - thread safe
301  void TracksChanged(uint trackType);
302  void EnableSubtitles(bool enable);
303  void EnableForcedSubtitles(bool enable);
304  bool ForcedSubtitlesFavored(void) const {
305  return allowForcedSubtitles && !captionsEnabledbyDefault;
306  }
307  // How to handle forced Subtitles (i.e. when in a movie someone speaks
308  // in a different language than the rest of the movie, subtitles are
309  // forced on even if the user doesn't have them turned on.)
310  // These two functions are not thread-safe (UI thread use only).
311  void SetAllowForcedSubtitles(bool allow);
312  bool GetAllowForcedSubtitles(void) const { return allowForcedSubtitles; }
313 
314  // Public MHEG/MHI stream selection
315  bool SetAudioByComponentTag(int tag);
316  bool SetVideoByComponentTag(int tag);
317  bool SetStream(const QString &);
318  long GetStreamPos(); // mS
319  long GetStreamMaxPos(); // mS
320  long SetStreamPos(long); // mS
321  void StreamPlay(bool play = true);
322 
323  // LiveTV public stuff
324  void CheckTVChain();
325  void FileChangedCallback();
326 
327  // Chapter public stuff
328  virtual int GetNumChapters(void);
329  virtual int GetCurrentChapter(void);
330  virtual void GetChapterTimes(QList<long long> &times);
331 
332  // Title public stuff
333  virtual int GetNumTitles(void) const { return 0; }
334  virtual int GetCurrentTitle(void) const { return 0; }
335  virtual int GetTitleDuration(int /*title*/) const { return 0; }
336  virtual QString GetTitleName(int /*title*/) const { return QString(); }
337 
338  // Angle public stuff
339  virtual int GetNumAngles(void) const { return 0; }
340  virtual int GetCurrentAngle(void) const { return 0; }
341  virtual QString GetAngleName(int /*title*/) const { return QString(); }
342 
343  // DVD public stuff
344  virtual bool GoToMenu(QString /*str*/) { return false; }
345  virtual void GoToDVDProgram(bool direction) { (void) direction; }
346  virtual bool IsInStillFrame() const { return false; }
347 
348  // Position Map Stuff
349  bool PosMapFromEnc(uint64_t start,
350  frm_pos_map_t &posMap,
351  frm_pos_map_t &durMap);
352 
353  // OSD locking for TV class
354  bool TryLockOSD(void) { return osdLock.tryLock(50); }
355  void LockOSD(void) { osdLock.lock(); }
356  void UnlockOSD(void) { osdLock.unlock(); }
357 
358  // Public picture controls
359  void ToggleStudioLevels(void);
360  void ToggleNightMode(void);
361 
362  // Visualisations
363  bool CanVisualise(void);
364  bool IsVisualising(void);
365  QString GetVisualiserName(void);
366  QStringList GetVisualiserList(void);
367  bool EnableVisualisation(bool enable, const QString &name = QString(""));
368 
369  void SaveTotalDuration(void);
370  void ResetTotalDuration(void);
371 
374  static const double kInaccuracyNone;
375  static const double kInaccuracyDefault;
376  static const double kInaccuracyEditor;
377  static const double kInaccuracyFull;
378 
379  void SaveTotalFrames(void);
380  void SetErrored(const QString &reason);
381 
382  protected:
383  // Initialization
384  void OpenDummy(void);
385 
386  // Non-public sets
387  virtual void SetBookmark(bool clear = false);
388  bool AddPIPPlayer(MythPlayer *pip, PIPLocation loc);
389  bool RemovePIPPlayer(MythPlayer *pip);
390  void NextScanType(void)
391  { SetScanType((FrameScanType)(((int)m_scan + 1) & 0x3)); }
392  void SetScanType(FrameScanType);
393  FrameScanType GetScanType(void) const { return m_scan; }
394  bool IsScanTypeLocked(void) const { return m_scan_locked; }
395  void Zoom(ZoomDirection direction);
396  void ToggleMoveBottomLine(void);
397  void SaveBottomLine(void);
398  void FileChanged(void);
399 
400 
401  // Windowing stuff
402  void EmbedInWidget(QRect rect);
403  void StopEmbedding(void);
404  void ExposeEvent(void);
405  bool IsEmbedding(void);
406  void WindowResized(const QSize &new_size);
407 
408  // Audio Sets
409  uint AdjustVolume(int change) { return audio.AdjustVolume(change); }
410  uint SetVolume(int newvolume) { return audio.SetVolume(newvolume); }
411  bool SetMuted(bool mute) { return audio.SetMuted(mute); }
412  MuteState SetMuteState(MuteState state) { return audio.SetMuteState(state); }
413  MuteState IncrMuteState(void) { return audio.IncrMuteState(); }
414 
415  // Non-const gets
416  OSD *GetOSD(void) { return osd; }
417  virtual void SeekForScreenGrab(uint64_t &number, uint64_t frameNum,
418  bool absolute);
419 
420  // Complicated gets
421  virtual long long CalcMaxFFTime(long long ff, bool setjump = true) const;
422  long long CalcRWTime(long long rw) const;
423  virtual void calcSliderPos(osdInfo &info, bool paddedFields = false);
424  uint64_t TranslatePositionFrameToMs(uint64_t position,
425  bool use_cutlist) const;
426  uint64_t TranslatePositionMsToFrame(uint64_t position,
427  bool use_cutlist) const {
428  return deleteMap.TranslatePositionMsToFrame(position,
429  GetFrameRate(),
430  use_cutlist);
431  }
432  // TranslatePositionAbsToRel and TranslatePositionRelToAbs are
433  // used for frame calculations when seeking relative to a number
434  // of frames rather than by time.
435  uint64_t TranslatePositionAbsToRel(uint64_t position) const {
436  return deleteMap.TranslatePositionAbsToRel(position);
437  }
438  uint64_t TranslatePositionRelToAbs(uint64_t position) const {
439  return deleteMap.TranslatePositionRelToAbs(position);
440  }
441  float ComputeSecs(uint64_t position, bool use_cutlist) const {
442  return TranslatePositionFrameToMs(position, use_cutlist) / 1000.0;
443  }
444  uint64_t FindFrame(float offset, bool use_cutlist) const;
445 
446  // Commercial stuff
448  { commBreakMap.SetAutoCommercialSkip(autoskip, framesPlayed); }
449  void SkipCommercials(int direction)
450  { commBreakMap.SkipCommercials(direction); }
451  void SetCommBreakMap(frm_dir_map_t &newMap);
453  { return commBreakMap.GetAutoCommercialSkip(); }
454 
455  // Toggle Sets
456  void ToggleAspectOverride(AspectOverrideMode aspectMode = kAspect_Toggle);
457  void ToggleAdjustFill(AdjustFillMode adjustfillMode = kAdjustFill_Toggle);
458 
459  // Start/Reset/Stop playing
460  virtual bool StartPlaying(void);
461  virtual void ResetPlaying(bool resetframes = true);
462  virtual void EndPlaying(void) { }
463  virtual void StopPlaying(void);
464 
465  // Pause stuff
466  bool PauseDecoder(void);
467  void UnpauseDecoder(void);
468  bool Pause(void);
469  bool Play(float speed = 1.0, bool normal = true, bool unpauseaudio = true);
470 
471  // Seek stuff
472  virtual bool FastForward(float seconds);
473  virtual bool Rewind(float seconds);
474  virtual bool JumpToFrame(uint64_t frame);
475 
476  // Chapter stuff
477  void JumpChapter(int chapter);
478 
479  // Playback
480  virtual bool PrebufferEnoughFrames(int min_buffers = 0);
481  void SetBuffering(bool new_buffering);
482  void RefreshPauseFrame(void);
483  void CheckAspectRatio(VideoFrame* frame);
484  virtual void DisplayPauseFrame(void);
485  virtual void DisplayNormalFrame(bool check_prebuffer = true);
486  virtual void PreProcessNormalFrame(void);
487  virtual void VideoStart(void);
488  virtual bool VideoLoop(void);
489  virtual void VideoEnd(void);
490  virtual void DecoderStart(bool start_paused);
491  virtual void DecoderLoop(bool pause);
492  virtual void DecoderEnd(void);
493  virtual void DecoderPauseCheck(void);
494  virtual void AudioEnd(void);
495  virtual void EventStart(void);
496  virtual void EventLoop(void);
497  virtual void InitialSeek(void);
498 
499  // Protected MHEG/MHI stuff
500  bool ITVHandleAction(const QString &action);
501  void ITVRestart(uint chanid, uint cardid, bool isLiveTV);
502 
503  // Edit mode stuff
504  bool EnableEdit(void);
505  bool HandleProgramEditorActions(QStringList &actions);
506  bool GetEditMode(void) const { return deleteMap.IsEditing(); }
507  void DisableEdit(int howToSave);
508  bool IsInDelete(uint64_t frame);
509  uint64_t GetNearestMark(uint64_t frame, bool right);
510  bool IsTemporaryMark(uint64_t frame);
511  bool HasTemporaryMark(void);
512  bool IsCutListSaved(void) { return deleteMap.IsSaved(); }
513  bool DeleteMapHasUndo(void) { return deleteMap.HasUndo(); }
514  bool DeleteMapHasRedo(void) { return deleteMap.HasRedo(); }
515  QString DeleteMapGetUndoMessage(void) { return deleteMap.GetUndoMessage(); }
516  QString DeleteMapGetRedoMessage(void) { return deleteMap.GetRedoMessage(); }
517 
518  // Reinit
519  void ReinitOSD(void);
520 
521  // OSD conveniences
522  void SetOSDMessage(const QString &msg, OSDTimeout timeout);
523  void SetOSDStatus(const QString &title, OSDTimeout timeout);
524 
525  // Closed caption and teletext stuff
526  void ResetCaptions(void);
527  bool ToggleCaptions(void);
528  bool ToggleCaptions(uint type);
529  bool HasTextSubtitles(void) { return subReader.HasTextSubtitles(); }
530  void SetCaptionsEnabled(bool, bool osd_msg=true);
531  bool GetCaptionsEnabled(void);
532  virtual void DisableCaptions(uint mode, bool osd_msg=true);
533  virtual void EnableCaptions(uint mode, bool osd_msg=true);
534 
535  // Audio/Subtitle/EIA-608/EIA-708 stream selection
536  QStringList GetTracks(uint type);
537  uint GetTrackCount(uint type);
538  virtual int SetTrack(uint type, int trackNo);
539  int GetTrack(uint type);
540  int ChangeTrack(uint type, int dir);
541  void ChangeCaptionTrack(int dir);
542  bool HasCaptionTrack(int mode);
543  int NextCaptionTrack(int mode);
544  void DoDisableForcedSubtitles(void);
545  void DoEnableForcedSubtitles(void);
546 
547  // Teletext Menu and non-NUV teletext decoder
548  void EnableTeletext(int page = 0x100);
549  void DisableTeletext(void);
550  void ResetTeletext(void);
551  bool HandleTeletextAction(const QString &action);
552 
553  // Teletext NUV Captions
554  void SetTeletextPage(uint page);
555 
556  // Time Code adjustment stuff
557  int64_t AdjustAudioTimecodeOffset(int64_t v, int newsync = -9999);
558  int64_t GetAudioTimecodeOffset(void) const
559  { return tc_wrap[TC_AUDIO]; }
560 
561  // Playback (output) zoom automation
563 
564  protected:
565  // Private initialization stuff
566  void InitFilters(void);
567  FrameScanType detectInterlace(FrameScanType newScan, FrameScanType scan,
568  float fps, int video_height);
569  virtual void AutoDeint(VideoFrame* frame, bool allow_lock = true);
570 
571  // Private Sets
572  void SetPlayingInfo(const ProgramInfo &pginfo);
573  void SetPlaying(bool is_playing);
574  void ResetErrored(void);
575 
576  // Private Gets
577  int GetStatusbarPos(void) const;
578 
579  // Private pausing stuff
580  void PauseVideo(void);
581  void UnpauseVideo(void);
582  void PauseBuffer(void);
583  void UnpauseBuffer(void);
584 
585  // Private decoder stuff
586  virtual void CreateDecoder(char *testbuf, int testreadsize);
587  void SetDecoder(DecoderBase *dec);
589  const DecoderBase *GetDecoder(void) const { return decoder; }
590  bool DecodeFrame(struct rtframeheader *frameheader,
591  unsigned char *strm, unsigned char *outbuf);
592 
593  virtual bool DecoderGetFrameFFREW(void);
594  virtual bool DecoderGetFrameREW(void);
595  bool DecoderGetFrame(DecodeType, bool unsafe = false);
596 
597  // These actually execute commands requested by public members
598  bool UpdateFFRewSkip(void);
599  virtual void ChangeSpeed(void);
600  // The "inaccuracy" argument is generally one of the kInaccuracy* values.
601  bool DoFastForward(uint64_t frames, double inaccuracy);
602  bool DoRewind(uint64_t frames, double inaccuracy);
603  bool DoFastForwardSecs(float secs, double inaccuracy, bool use_cutlist);
604  bool DoRewindSecs(float secs, double inaccuracy, bool use_cutlist);
605  void DoJumpToFrame(uint64_t frame, double inaccuracy);
606 
607  // Private seeking stuff
608  void WaitForSeek(uint64_t frame, uint64_t seeksnap_wanted);
609  void ClearAfterSeek(bool clearvideobuffers = true);
610 
611  // Private chapter stuff
612  virtual bool DoJumpChapter(int chapter);
613  virtual int64_t GetChapter(int chapter);
614 
615  // Private edit stuff
616  void HandleArbSeek(bool right);
617 
618  // Private A/V Sync Stuff
619  void WrapTimecode(int64_t &timecode, TCTypes tc_type);
620  void InitAVSync(void);
621  virtual void AVSync(VideoFrame *buffer, bool limit_delay = false);
622  // New video sync method
623  void AVSync2(VideoFrame *buffer);
624  void ResetAVSync(void);
625  int64_t AVSyncGetAudiotime(void);
626  void SetFrameInterval(FrameScanType scan, double frame_period);
627  void FallbackDeint(void);
628  void WaitForTime(int64_t framedue);
629 
630  // Private LiveTV stuff
631  void SwitchToProgram(void);
632  void JumpToProgram(void);
633  void JumpToStream(const QString&);
634 
635  protected:
637  DecoderBase *decoder {nullptr};
638  mutable QMutex decoder_change_lock {QMutex::Recursive};
639  VideoOutput *videoOutput {nullptr};
640  PlayerContext *player_ctx {nullptr};
641  DecoderThread *decoderThread {nullptr};
642  QThread *playerThread {nullptr};
643 #ifdef Q_OS_ANDROID
644  int playerThreadId {0};
645 #endif
646 
647  // Window stuff
648  QWidget *parentWidget {nullptr};
649  bool embedding {false};
650  QRect embedRect {0,0,0,0};
651  float defaultDisplayAspect {1.7777F};
652 
653  // State
654  QWaitCondition decoderThreadPause;
655  QWaitCondition decoderThreadUnpause;
656  mutable QMutex decoderPauseLock;
657  mutable QMutex decoderSeekLock;
658  bool totalDecoderPause {false};
659  bool decoderPaused {false};
660  bool inJumpToProgramPause {false};
661  bool pauseDecoder {false};
662  bool unpauseDecoder {false};
663  bool volatile killdecoder {false};
664  int64_t decoderSeek {-1};
665  bool decodeOneFrame {false};
666  bool needNewPauseFrame {false};
667  mutable QMutex bufferPauseLock;
668  mutable QMutex videoPauseLock;
669  mutable QMutex pauseLock;
670  bool bufferPaused {false};
671  bool videoPaused {false};
672  bool allpaused {false};
673  bool playing {false};
674 
675  mutable QWaitCondition playingWaitCond;
676  mutable QMutex vidExitLock;
677  mutable QMutex playingLock;
678  bool m_double_framerate {false};
679  bool m_double_process {false};
680  bool m_deint_possible {true};
681  bool livetv {false};
682  bool watchingrecording {false};
683  bool transcoding {false};
684  bool hasFullPositionMap {false};
685  mutable bool limitKeyRepeat {false};
686  mutable QMutex errorLock;
687  QString errorMsg;
688  int errorType {kError_None};
689 
690  // Chapter stuff
691  int jumpchapter {0};
692 
693  // Bookmark stuff
694  uint64_t bookmarkseek {0};
695  int clearSavedPosition {1};
697 
698  // Seek
701  long long fftime {0};
702 
703  // Playback misc.
705  int videobuf_retries {0};
706  uint64_t framesPlayed {0};
707  // "Fake" frame counter for when the container frame rate doesn't
708  // match the stream frame rate.
709  uint64_t framesPlayedExtra {0};
710  uint64_t totalFrames {0};
711  long long totalLength {0};
712  int64_t totalDuration {0};
713  long long rewindtime {0};
714  int64_t m_latestVideoTimecode {-1};
715  QElapsedTimer m_avTimer;
716 
717  // -- end state stuff --
718 
719  // Input Video Attributes
720  QSize video_disp_dim {0,0};
721  QSize video_dim {0,0};
722  double video_frame_rate {29.97F};
723  float video_aspect {4.0F / 3.0F};
724  float forced_video_aspect {-1};
730  bool m_scan_locked {false};
732  int m_scan_tracker {0};
734  bool m_scan_initialized {false};
736  uint keyframedist {30};
738  QString m_codecName;
739 
740  // Buffering
741  bool buffering {false};
744 
745  // General Caption/Teletext/Subtitle support
746  uint textDisplayMode {kDisplayNone};
747  uint prevTextDisplayMode {kDisplayNone};
748  uint prevNonzeroTextDisplayMode {kDisplayNone};
749 
750  // Support for analog captions and teletext
751  // (i.e. Vertical Blanking Interval (VBI) encoded data.)
753  int ttPageNum {0x888};
754 
755  // Support for captions, teletext, etc. decoded by libav
760  bool captionsEnabledbyDefault {false};
761  bool textDesired {false};
762  bool enableCaptions {false};
763  bool disableCaptions {false};
764  bool enableForcedSubtitles {false};
765  bool disableForcedSubtitles {false};
766  bool allowForcedSubtitles {true};
767 
768  // CC608/708
771 
772  // Support for MHEG/MHI
773  bool itvVisible {false};
774  InteractiveTV *interactiveTV {nullptr};
775  bool itvEnabled {false};
776  QMutex itvLock;
777  QMutex streamLock;
778  QString m_newStream; // Guarded by streamLock
779 
780  // OSD stuff
781  OSD *osd {nullptr};
782  bool reinit_osd {false};
783  QMutex osdLock {QMutex::Recursive};
784 
785  // Audio stuff
788 
789  // Picture-in-Picture
791  volatile bool pip_active {false};
792  volatile bool pip_visible {true};
794 
795  // Filters
797  QString videoFiltersForProgram {};
798  QString videoFiltersOverride {};
799  int postfilt_width {0};
800  int postfilt_height {0};
801  FilterChain *videoFilters {nullptr};
802  FilterManager *FiltMan {nullptr};
803 
804  // Commercial filtering
806  bool forcePositionMapSync {false};
807  // Manual editing
809  bool pausedBeforeEdit {false};
811  float speedBeforeEdit {1.0F};
812 
813  // Playback (output) speed control
815  QMutex decoder_lock {QMutex::Recursive};
816  float next_play_speed {1.0F};
817  bool next_normal_speed {true};
818 
819  float play_speed {1.0F};
820  bool normal_speed {true};
821  int frame_interval {(int)(1000000.0F / 30)};
822  int m_frame_interval {0};
823  int m_fpsMultiplier {1};
824 
825  int ffrew_skip {1};
826  int ffrew_adjust {0};
827  bool fileChanged {false};
828 
829  // Audio and video synchronization stuff
830  VideoSync *videosync {nullptr};
831  int avsync_delay {0};
832  int avsync_adjustment {0};
833  int avsync_avg {0};
834  int avsync_predictor {0};
835  bool avsync_predictor_enabled {false};
836  int refreshrate {0};
837  bool lastsync {false};
838  bool decode_extra_audio {false};
839  int repeat_delay {0};
840  int64_t disp_timecode {0};
841  bool avsync_audiopaused {false};
842  float max_diverge {3.0F}; // from setting PlayerMaxDiverge default 2
843  // AVSync for Raspberry Pi digital streams
844  int avsync_averaging {4}; // Number of frames to average
845  int avsync_interval {0}; // Number of frames skip between sync checks
846  int avsync_next {0}; // Frames till next sync check
847 
848  // Time Code stuff
849  int prevtc {0};
850  int prevrp {0};
851  int64_t tc_wrap[TCTYPESMAX] {};
852  int64_t tc_lastval[TCTYPESMAX] {};
853  int64_t savedAudioTimecodeOffset {0};
854 
855  // AVSync2
856  int64_t rtcbase {0}; // real time clock base for presentation time (microsecs)
857  int64_t maxtcval {0}; // maximum to date video tc
858  int maxtcframes {0}; // number of frames seen since max to date tc
859  int64_t avsync2adjustms {10};// number of milliseconds to adjust for av sync errors
860  int numdroppedframes {0}; // number of consecutive dropped frames.
861  int64_t prior_audiotimecode {0}; // time code from prior frame
862  int64_t prior_videotimecode {0}; // time code from prior frame
863  int64_t m_timeOffsetBase {0};
864 
865  // LiveTV
866  TV *m_tv {nullptr};
867  bool isDummy {false};
868 
869  // Counter for buffering messages
870  int bufferingCounter {0};
871 
872  // Debugging variables
873  Jitterometer *output_jmeter {nullptr};
874 
875  private:
876  void syncWithAudioStretch();
877  bool disable_passthrough {false};
878 };
879 
880 #endif
881 
882 /* vim: set expandtab tabstop=4 shiftwidth=4: */
void LockOSD(void)
Definition: mythplayer.h:355
float GetPlaySpeed(void) const
Definition: mythplayer.h:188
bool IsErrorRecoverable(void) const
Definition: mythplayer.h:208
void SetPIPActive(bool is_active)
Definition: mythplayer.h:156
virtual CC708Reader * GetCC708Reader(uint=0)
Definition: mythplayer.h:295
bool ForcedSubtitlesFavored(void) const
Definition: mythplayer.h:304
AudioPlayer audio
Definition: mythplayer.h:786
QString errorMsg
Reason why NVP exited with a error.
Definition: mythplayer.h:687
const AudioOutputGraph & GetAudioGraph() const
Definition: mythplayer.h:190
QMutex itvLock
Definition: mythplayer.h:776
float ComputeSecs(uint64_t position, bool use_cutlist) const
Definition: mythplayer.h:441
float GetVideoAspect(void) const
Definition: mythplayer.h:175
void SkipCommercials(int direction)
Definition: mythplayer.h:449
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
def scan(profile, smoonURL, gate)
Definition: scan.py:46
QTime buffering_last_msg
Definition: mythplayer.h:743
QTime editUpdateTimer
Definition: mythplayer.h:810
int64_t GetAudioTimecodeOffset(void) const
Definition: mythplayer.h:558
QMap< MythPlayer *, PIPLocation > PIPMap
Definition: videooutbase.h:37
PlayerFlags
Definition: mythplayer.h:88
static int SetCutList(uint chanid, const QDateTime &starttime, QString newCutList)
VideoOutput * GetVideoOutput(void)
Definition: mythplayer.h:244
static const int kNightModeBrightenssAdjustment
Definition: mythplayer.h:372
vbimode
Definition: vbilut.h:20
SubtitleReader subReader
Definition: mythplayer.h:756
MuteState IncrMuteState(void)
Definition: mythplayer.h:413
bool UsingNullVideo(void) const
Definition: mythplayer.h:232
bool DeleteMapHasRedo(void)
Definition: mythplayer.h:514
QMutex videofiltersLock
Definition: mythplayer.h:796
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:377
MuteState
Definition: volumebase.h:6
static const double kInaccuracyDefault
Definition: mythplayer.h:375
bool IsAudioNeeded(void)
Definition: mythplayer.h:178
virtual int GetCurrentAngle(void) const
Definition: mythplayer.h:340
FrameScanType
Definition: videoouttypes.h:80
float GetAudioStretchFactor(void)
Definition: mythplayer.h:191
QMap< uint64_t, MarkTypes > frm_dir_map_t
Frame # -> Mark map.
Definition: programtypes.h:81
unsigned int uint
Definition: compat.h:140
int GetLength(void) const
Definition: mythplayer.h:193
DecoderThread(MythPlayer *mp, bool start_paused)
Definition: mythplayer.h:110
virtual bool NextTitle(void)
Definition: mythplayer.h:249
virtual TeletextReader * GetTeletextReader(uint=0)
Definition: mythplayer.h:298
DetectLetterbox * detect_letter_box
Definition: mythplayer.h:562
TeletextReader ttxReader
Definition: mythplayer.h:757
bool DeleteMapHasUndo(void)
Definition: mythplayer.h:513
virtual bool SwitchAngle(int)
Definition: mythplayer.h:253
CommBreakMap commBreakMap
Definition: mythplayer.h:805
QMutex decoderPauseLock
Definition: mythplayer.h:656
#define SetOSDMessage(CTX, MESSAGE)
Definition: tv_play.cpp:103
uint GetVolume(void)
Definition: mythplayer.h:180
uint64_t TranslatePositionRelToAbs(uint64_t position) const
Definition: mythplayer.h:438
#define FlagIsSet(arg)
Definition: mythplayer.h:105
QMutex decoderSeekLock
Definition: mythplayer.h:657
QMutex pauseLock
Definition: mythplayer.h:669
PIPLocation pip_default_loc
Definition: mythplayer.h:793
EofState
Definition: decoderbase.h:67
QString DeleteMapGetRedoMessage(void)
Definition: mythplayer.h:516
OSDTimeout
Definition: osd.h:59
bool m_start_paused
Definition: mythplayer.h:119
uint GetCaptionMode(void) const
Definition: mythplayer.h:294
This class serves as the base class for all video output methods.
Definition: videooutbase.h:46
Holds information on recordings and videos.
Definition: programinfo.h:66
AspectOverrideMode
Definition: videoouttypes.h:46
QSize GetVideoSize(void) const
Definition: mythplayer.h:174
MythCodecContext * GetMythCodecContext(void)
Definition: mythplayer.h:245
AudioPlayer * GetAudio(void)
Definition: mythplayer.h:189
virtual void GoToDVDProgram(bool direction)
Definition: mythplayer.h:345
QString m_newStream
Definition: mythplayer.h:778
#define MTV_PUBLIC
Definition: mythtvexp.h:15
virtual int GetTitleDuration(int) const
Definition: mythplayer.h:335
static void clear(SettingsMap &cache, SettingsMap &overrides, const QString &myKey)
Definition: mythdb.cpp:830
bool IsScanTypeLocked(void) const
Definition: mythplayer.h:394
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
virtual QString GetTitleName(int) const
Definition: mythplayer.h:336
void NextScanType(void)
Definition: mythplayer.h:390
CommSkipMode
Definition: tv.h:130
FrameScanType GetScanType(void) const
Definition: mythplayer.h:393
virtual int GetNumAngles(void) const
Definition: mythplayer.h:339
void(* StatusCallback)(int, void *)
Definition: mythplayer.h:58
CC608Reader cc608
Definition: mythplayer.h:769
static const double kInaccuracyEditor
Definition: mythplayer.h:376
virtual bool IsInStillFrame() const
Definition: mythplayer.h:346
float GetFrameRate(void) const
Definition: mythplayer.h:176
QWaitCondition decoderThreadPause
Definition: mythplayer.h:654
uint SetVolume(int newvolume)
Definition: mythplayer.h:410
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:93
Virtual base class for all video synchronization classes.
Definition: vsync.h:45
virtual bool GoToMenu(QString)
Definition: mythplayer.h:344
QMutex vidExitLock
Definition: mythplayer.h:676
PIPMap pip_players
Definition: mythplayer.h:790
const DecoderBase * GetDecoder(void) const
Returns the stream decoder currently in use.
Definition: mythplayer.h:589
Control TV playback.
Definition: tv_play.h:284
OSD * GetOSD(void)
Definition: mythplayer.h:416
bool HasTextSubtitles(void)
Definition: mythplayer.h:529
bool GetLimitKeyRepeat(void) const
Definition: mythplayer.h:220
static uint8_t * SetLength(uint8_t *Data, int Length)
Definition: dvbci.cpp:117
virtual int GetNumTitles(void) const
Definition: mythplayer.h:333
QMutex streamLock
Definition: mythplayer.h:777
void UnlockOSD(void)
Definition: mythplayer.h:356
MythPlayer * m_mp
Definition: mythplayer.h:118
const char * name
Definition: ParseText.cpp:328
QWaitCondition decoderThreadUnpause
Definition: mythplayer.h:655
bool PlayerControlsVolume(void) const
Definition: mythplayer.h:231
QMutex playingLock
Definition: mythplayer.h:677
int GetFFRewSkip(void) const
Definition: mythplayer.h:187
virtual void EndPlaying(void)
Definition: mythplayer.h:462
MuteState SetMuteState(MuteState state)
Definition: mythplayer.h:412
uint AdjustVolume(int change)
Definition: mythplayer.h:409
enum DecodeTypes DecodeType
virtual bool PrevTitle(void)
Definition: mythplayer.h:250
int endExitPrompt
Definition: mythplayer.h:696
PIPLocation
Definition: videoouttypes.h:19
AdjustFillMode
Definition: videoouttypes.h:57
bool AtNormalSpeed(void) const
Definition: mythplayer.h:224
static const double kInaccuracyNone
Definition: mythplayer.h:374
QSize GetVideoBufferSize(void) const
Definition: mythplayer.h:173
virtual bool NextAngle(void)
Definition: mythplayer.h:254
QWaitCondition playingWaitCond
Definition: mythplayer.h:675
void SetAutoCommercialSkip(CommSkipMode autoskip)
Definition: mythplayer.h:447
QMutex bufferPauseLock
Definition: mythplayer.h:667
virtual bool SwitchTitle(int)
Definition: mythplayer.h:248
uint64_t GetFramesPlayed(void) const
Definition: mythplayer.h:196
bool HasAudioOut(void) const
Definition: mythplayer.h:227
AudioOutputGraph m_audiograph
Definition: mythplayer.h:787
DeleteMap deleteMap
Definition: mythplayer.h:808
QTime buffering_start
Definition: mythplayer.h:742
static const int kNightModeContrastAdjustment
Definition: mythplayer.h:373
QMutex videoPauseLock
Definition: mythplayer.h:668
uint64_t TranslatePositionAbsToRel(uint64_t position) const
Definition: mythplayer.h:435
PlayerFlags playerFlags
Definition: mythplayer.h:636
int64_t GetLatestVideoTimecode() const
Definition: mythplayer.h:205
uint64_t GetTotalFrameCount(void) const
Definition: mythplayer.h:194
QString DeleteMapGetUndoMessage(void)
Definition: mythplayer.h:515
Definition: osd.h:132
QString m_codecName
Codec Name - used by playback profile.
Definition: mythplayer.h:738
bool IsDecoderErrored(void) const
Definition: mythplayer.h:210
CommSkipMode GetAutoCommercialSkip(void)
Definition: mythplayer.h:452
const char * frames[3]
Definition: element.c:46
MuteState GetMuteState(void)
Definition: mythplayer.h:185
QElapsedTimer m_avTimer
Definition: mythplayer.h:715
uint64_t TranslatePositionMsToFrame(uint64_t position, bool use_cutlist) const
Definition: mythplayer.h:426
QMutex errorLock
Definition: mythplayer.h:686
CC708Reader cc708
Definition: mythplayer.h:770
bool SetMuted(bool mute)
Definition: mythplayer.h:411
Implements a file/stream reader/writer.
virtual CC608Reader * GetCC608Reader(uint=0)
Definition: mythplayer.h:296
virtual QString GetAngleName(int) const
Definition: mythplayer.h:341
bool IsPIPVisible(void) const
Definition: mythplayer.h:229
void SetPIPVisible(bool is_visible)
Definition: mythplayer.h:157
float GetNextPlaySpeed(void) const
Definition: mythplayer.h:192
QMap< long long, long long > frm_pos_map_t
Frame # -> File offset map.
Definition: programtypes.h:46
#define TCTYPESMAX
Definition: mythplayer.h:68
virtual bool PrevAngle(void)
Definition: mythplayer.h:255
bool IsPaused(void) const
Definition: mythplayer.h:218
virtual int GetCurrentTitle(void) const
Definition: mythplayer.h:334
bool GetEditMode(void) const
Definition: mythplayer.h:506
ZoomDirection
Definition: videoouttypes.h:28
bool TryLockOSD(void)
Definition: mythplayer.h:354
Keeps track of recordings in a current LiveTV instance.
Definition: livetvchain.h:31
static int x3
Definition: mythsocket.cpp:62
bool GetAllowForcedSubtitles(void) const
Definition: mythplayer.h:312
DecoderBase * GetDecoder(void)
Returns the stream decoder currently in use.
Definition: mythplayer.h:278
This is the interface between an MHEG engine and a MythTV TV object.
Definition: interactivetv.h:12
TCTypes
Timecode types.
Definition: mythplayer.h:61
bool IsPIPActive(void) const
Definition: mythplayer.h:228
bool IsCutListSaved(void)
Definition: mythplayer.h:512
bool IsMuted(void)
Definition: mythplayer.h:230
virtual SubtitleReader * GetSubReader(uint=0)
Definition: mythplayer.h:297