MythTV  master
mythdvdbuffer.h
Go to the documentation of this file.
1 #ifndef MYTH_DVD_BUFFER_H_
2 #define MYTH_DVD_BUFFER_H_
3 
4 // C++
5 #include <array>
6 
7 // Qt
8 #include <QMap>
9 #include <QString>
10 #include <QMutex>
11 #include <QRect>
12 #if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
13 #include <QRecursiveMutex>
14 #endif
15 #include <QCoreApplication>
16 
17 // MythTV
18 #include "libmythbase/mythdate.h"
21 
22 #include "mythdvdcontext.h"
23 #include "mythdvdinfo.h"
24 
25 // FFmpeg
26 extern "C" {
27 #include "libavcodec/avcodec.h"
28 }
29 
30 static constexpr int32_t DVD_MENU_MAX { 7 };
31 
32 class MythDVDPlayer;
33 
34 using CLUTArray = std::array<uint32_t,16>;
35 using AlphaArray = std::array<uint8_t,4>;
36 using PaletteArray = std::array<uint8_t,4>;
37 using ColorArray = std::array<uint8_t,256>;
38 
40 {
41  Q_DECLARE_TR_FUNCTIONS(MythDVDBuffer)
42 
43  public:
44  explicit MythDVDBuffer(const QString &Filename);
45  ~MythDVDBuffer() override;
46 
47  bool IsOpen (void) const override;
48  bool IsBookmarkAllowed (void) override;
49  bool IsSeekingAllowed (void) override;
50  int BestBufferSize (void) override { return 2048; }
51  bool IsInStillFrame (void) const override;
52  bool OpenFile (const QString &Filename,
53  std::chrono::milliseconds Retry = kDefaultOpenTimeout) override;
54  bool HandleAction (const QStringList &Actions, mpeg::chrono::pts Pts) override;
55  void IgnoreWaitStates (bool Ignore) override;
56  bool StartFromBeginning (void) override;
57  long long GetReadPosition (void) const override;
58  bool GetNameAndSerialNum (QString& Name, QString& SerialNumber) override;
59 
60  int GetTitle (void) const;
61  bool DVDWaitingForPlayer (void) const;
62  int GetPart (void) const;
63  int GetCurrentAngle (void) const;
64  int GetNumAngles (void) const;
65  long long GetTotalReadPosition (void) const;
66  std::chrono::seconds GetChapterLength (void) const;
67  void GetChapterTimes (QList<std::chrono::seconds> &Times);
68  std::chrono::seconds GetChapterTimes (int Title);
69  void GetDescForPos (QString &Description) const;
70  void GetPartAndTitle (int &Part, int &Title) const;
71  std::chrono::seconds GetTotalTimeOfTitle (void) const;
72  float GetAspectOverride (void) const;
73  std::chrono::seconds GetCellStart (void) const;
74  bool PGCLengthChanged (void);
75  bool CellChanged (void);
76  bool IsStillFramePending (void) const;
77  bool AudioStreamsChanged (void) const;
78  bool IsWaiting (void) const;
79  int NumPartsInTitle (void) const;
80  void GetMenuSPUPkt (uint8_t *Buffer, int Size, int StreamID, uint32_t StartTime);
81  uint32_t AdjustTimestamp (uint32_t Timestamp) const;
82  int64_t AdjustTimestamp (int64_t Timestamp) const;
83  MythDVDContext* GetDVDContext (void);
84  int32_t GetLastEvent (void) const;
85  AVSubtitle* GetMenuSubtitle (uint &Version);
86  int NumMenuButtons (void) const;
87  QRect GetButtonCoords (void);
88  void ReleaseMenuButton (void);
89  uint GetSubtitleLanguage (int Id);
90  int8_t GetSubtitleTrackNum (uint StreamId);
91  bool DecodeSubtitles (AVSubtitle* Subtitle, int* GotSubtitles,
92  const uint8_t* SpuPkt, int BufSize, uint32_t StartTime);
93  uint GetAudioLanguage (int Index);
94  int GetAudioTrackNum (uint StreamId);
95  int GetAudioTrackType (uint Index);
96  bool GetDVDStateSnapshot (QString& State);
97  bool RestoreDVDStateSnapshot(const QString& State);
98  double GetFrameRate (void);
99  bool StartOfTitle (void) const;
100  bool EndOfTitle (void) const;
101  void PlayTitleAndPart (int Title, int Part);
102  void CloseDVD (void);
103  bool PlayTrack (int Track);
104  bool NextTrack (void);
105  void PrevTrack (void);
106  long long NormalSeek (long long Time);
107  bool SectorSeek (uint64_t Sector);
108  void SkipStillFrame (void);
109  void WaitSkip (void);
110  void SkipDVDWaitingForPlayer(void);
111  void UnblockReading (void);
112  bool IsReadingBlocked (void);
113  bool GoToMenu (const QString &str);
114  void GoToNextProgram (void);
115  void GoToPreviousProgram (void);
116  bool GoBack (void);
117  void AudioStreamsChanged (bool Change);
118  std::chrono::seconds GetCurrentTime (void) const;
119  std::chrono::seconds TitleTimeLeft (void) const;
120  void SetTrack (uint Type, int TrackNo);
121  int GetTrack (uint Type) const;
122  uint16_t GetNumAudioChannels (int Index);
123  void SetDVDSpeed (void);
124  void SetDVDSpeed (int Speed);
125  bool SwitchAngle (int Angle);
126  void SetParent (MythDVDPlayer *Parent);
127 
128  protected:
129  int SafeRead (void *Buffer, uint Size) override;
130  long long SeekInternal (long long Position, int Whence) override;
131 
132  void ActivateButton (void);
133  void MoveButtonLeft (void);
134  void MoveButtonRight (void);
135  void MoveButtonUp (void);
136  void MoveButtonDown (void);
137  bool DVDButtonUpdate (bool ButtonMode);
138  void ClearMenuSPUParameters (void);
139  void ClearMenuButton (void);
140  long long Seek (long long Time);
141  void ClearChapterCache (void);
142  void SelectDefaultButton(void);
143  void WaitForPlayer (void);
144 
145  static uint ConvertLangCode (uint16_t Code);
146  static uint GetNibble (const uint8_t *Buffer, int NibbleOffset);
147  static int DecodeRLE (uint8_t *Bitmap, int Linesize, int Width, int Height,
148  const uint8_t *Buffer, int NibbleOffset, int BufferSize);
149  void GuessPalette (uint32_t *RGBAPalette, PaletteArray Palette,
150  AlphaArray Alpha);
151  static int IsTransparent (const uint8_t *Buffer, int Pitch, int Num,
152  const ColorArray& Colors);
153  static int FindSmallestBoundingRectangle(AVSubtitle *Subtitle);
154 
155  dvdnav_t *m_dvdnav { nullptr };
156  DvdBuffer m_dvdBlockWriteBuf { 0 };
157  unsigned char *m_dvdBlockReadBuf { nullptr };
158  int m_dvdBlockRPos { 0 };
159  int m_dvdBlockWPos { 0 };
160  mpeg::chrono::pts m_pgLength { 0_pts };
161  mpeg::chrono::pts m_pgcLength { 0_pts };
162  mpeg::chrono::pts m_cellStart { 0_pts };
163  bool m_cellChanged { false };
164  bool m_pgcLengthChanged { false };
165  long long m_pgStart { 0 };
166  long long m_currentpos { 0 };
167  int32_t m_part { 0 };
168  int32_t m_lastPart { 0 };
169  int32_t m_title { 0 };
170  int32_t m_lastTitle { 0 };
171  bool m_playerWait { false };
172  int32_t m_titleParts { 0 };
173  bool m_gotStop { false };
174  int m_currentTitleAngleCount { 0 };
175  int64_t m_endPts { 0 };
176  int64_t m_timeDiff { 0 };
177  std::chrono::seconds m_still { 0s };
178  std::chrono::seconds m_lastStill { 0s };
179  bool m_audioStreamsChanged { false };
180  bool m_dvdWaiting { false };
181  long long m_titleLength { 0 };
182  bool m_skipstillorwait { true };
183  long long m_cellstartPos { 0 };
184  bool m_buttonSelected { false };
185  bool m_buttonExists { false };
186  bool m_buttonSeenInCell { false };
187  bool m_lastButtonSeenInCell { false };
188  int m_cellid { 0 };
189  int m_lastcellid { 0 };
190  int m_vobid { 0 };
191  int m_lastvobid { 0 };
192  bool m_cellRepeated { false };
193  int m_curAudioTrack { 0 };
194  int8_t m_curSubtitleTrack { 0 };
195  bool m_autoselectsubtitle { true };
196  bool m_seeking { false };
197  mpeg::chrono::pts m_seektime { 0_pts };
198  mpeg::chrono::pts m_currentTime { 0_pts };
199  static const QMap<int, int> kSeekSpeedMap;
200  QMap<int, QList<std::chrono::seconds> > m_chapterMap;
201  MythDVDPlayer *m_parent { nullptr };
202  float m_forcedAspect { -1.0F };
203 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
204  QMutex m_contextLock { QMutex::Recursive };
205 #else
206  QRecursiveMutex m_contextLock;
207 #endif
208  MythDVDContext *m_context { nullptr };
209  dvdnav_status_t m_dvdStat { DVDNAV_STATUS_OK };
210  int32_t m_dvdEvent { 0 };
211  int32_t m_dvdEventSize { 0 };
212  uint m_buttonVersion { 1 };
213  int m_buttonStreamID { 0 };
214  CLUTArray m_clut { 0 };
215  AlphaArray m_buttonColor { 0 };
216  PaletteArray m_buttonAlpha { 0 };
217  QRect m_hlButton { 0, 0, 0, 0 };
218  uint8_t *m_menuSpuPkt { nullptr };
219  int m_menuBuflength { 0 };
220  AVSubtitle m_dvdMenuButton { };
222  QMutex m_seekLock;
223 };
224 
225 #endif
AlphaArray
std::array< uint8_t, 4 > AlphaArray
Definition: mythdvdbuffer.h:35
MythMediaBuffer::SafeRead
virtual int SafeRead(void *Buffer, uint Size)=0
MythMediaBuffer::Seek
long long Seek(long long Position, int Whence, bool HasLock=false)
Definition: mythmediabuffer.cpp:473
DvdBuffer
std::array< uint8_t, DVD_BLOCK_SIZE > DvdBuffer
Definition: mythdvdinfo.h:17
mythopticalbuffer.h
MythDVDBuffer::m_menuBtnLock
QMutex m_menuBtnLock
Definition: mythdvdbuffer.h:221
DVD_MENU_MAX
static constexpr int32_t DVD_MENU_MAX
Definition: mythdvdbuffer.h:30
MythMediaBuffer::IgnoreWaitStates
virtual void IgnoreWaitStates(bool)
Definition: mythmediabuffer.h:130
MythMediaBuffer::HandleAction
virtual bool HandleAction(const QStringList &, mpeg::chrono::pts)
Definition: mythmediabuffer.h:134
Bitmap
Definition: polygon.h:7
MythOpticalBuffer::GetNameAndSerialNum
virtual bool GetNameAndSerialNum(QString &Name, QString &SerialNumber)=0
MythMediaBuffer::StartFromBeginning
virtual bool StartFromBeginning(void)
Definition: mythmediabuffer.h:129
StreamID
Contains listing of PMT Stream ID's for various A/V Stream types.
Definition: mpegtables.h:109
ColorArray
std::array< uint8_t, 256 > ColorArray
Definition: mythdvdbuffer.h:37
mythdate.h
MythMediaBuffer::SeekInternal
virtual long long SeekInternal(long long Position, int Whence)=0
MythDVDBuffer::m_contextLock
QRecursiveMutex m_contextLock
Definition: mythdvdbuffer.h:206
MythDVDPlayer
Definition: mythdvdplayer.h:10
State
State
Definition: zmserver.h:68
MythDVDContext
Encapsulates playback context at any given moment.
Definition: mythdvdcontext.h:16
MythDVDBuffer::m_chapterMap
QMap< int, QList< std::chrono::seconds > > m_chapterMap
Definition: mythdvdbuffer.h:200
uint
unsigned int uint
Definition: compat.h:81
MythDVDBuffer::kSeekSpeedMap
static const QMap< int, int > kSeekSpeedMap
Definition: mythdvdbuffer.h:199
referencecounter.h
mythdvdinfo.h
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
MythMediaBuffer::IsBookmarkAllowed
virtual bool IsBookmarkAllowed(void)
Definition: mythmediabuffer.h:127
Buffer
Definition: MythExternControl.h:36
MythMediaBuffer::IsInStillFrame
virtual bool IsInStillFrame(void) const
Definition: mythmediabuffer.h:132
Name
Definition: channelsettings.cpp:71
MythMediaBuffer::OpenFile
virtual bool OpenFile(const QString &Filename, std::chrono::milliseconds Retry=kDefaultOpenTimeout)=0
MythMediaBuffer::GetReadPosition
virtual long long GetReadPosition(void) const =0
MythOpticalBuffer
Definition: mythopticalbuffer.h:7
MythDVDBuffer::BestBufferSize
int BestBufferSize(void) override
Definition: mythdvdbuffer.h:50
mpeg::chrono::pts
std::chrono::duration< CHRONO_TYPE, std::ratio< 1, 90000 > > pts
Definition: mythchrono.h:55
uint16_t
unsigned short uint16_t
Definition: iso6937tables.h:3
mythdvdcontext.h
CLUTArray
std::array< uint32_t, 16 > CLUTArray
Definition: mythdvdbuffer.h:34
MythDVDBuffer
Definition: mythdvdbuffer.h:39
MythMediaBuffer::IsSeekingAllowed
virtual bool IsSeekingAllowed(void)
Definition: mythmediabuffer.h:126
PaletteArray
std::array< uint8_t, 4 > PaletteArray
Definition: mythdvdbuffer.h:36
MythDVDBuffer::m_seekLock
QMutex m_seekLock
Definition: mythdvdbuffer.h:222
MythMediaBuffer::IsOpen
virtual bool IsOpen(void) const =0