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