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