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