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
19
20#include "mythdvdcontext.h"
21#include "mythdvdinfo.h"
22
23// FFmpeg
24extern "C" {
25#include "libavcodec/avcodec.h"
26}
27
28static constexpr int32_t DVD_MENU_MAX { 7 };
29
30class MythDVDPlayer;
31
32using CLUTArray = std::array<uint32_t,16>;
33using AlphaArray = std::array<uint8_t,4>;
34using PaletteArray = std::array<uint8_t,4>;
35using 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 { };
217};
218
219#endif
Definition: polygon.h:8
int BestBufferSize(void) override
Definition: mythdvdbuffer.h:48
QMutex m_menuBtnLock
QRecursiveMutex m_contextLock
static const QMap< int, int > kSeekSpeedMap
QMap< int, QList< std::chrono::seconds > > m_chapterMap
Encapsulates playback context at any given moment.
virtual void IgnoreWaitStates(bool)
virtual bool IsInStillFrame(void) const
virtual bool HandleAction(const QStringList &, mpeg::chrono::pts)
virtual bool OpenFile(const QString &Filename, std::chrono::milliseconds Retry=kDefaultOpenTimeout)=0
virtual bool IsBookmarkAllowed(void)
virtual bool StartFromBeginning(void)
virtual bool IsOpen(void) const =0
long long Seek(long long Position, int Whence, bool HasLock=false)
virtual bool IsSeekingAllowed(void)
virtual long long GetReadPosition(void) const =0
virtual long long SeekInternal(long long Position, int Whence)=0
virtual int SafeRead(void *Buffer, uint Size)=0
virtual bool GetNameAndSerialNum(QString &Name, QString &SerialNumber)=0
Contains listing of PMT Stream ID's for various A/V Stream types.
Definition: mpegtables.h:110
unsigned int uint
Definition: freesurround.h:24
unsigned short uint16_t
Definition: iso6937tables.h:3
std::array< uint8_t, 256 > ColorArray
Definition: mythdvdbuffer.h:35
std::array< uint8_t, 4 > AlphaArray
Definition: mythdvdbuffer.h:33
static constexpr int32_t DVD_MENU_MAX
Definition: mythdvdbuffer.h:28
std::array< uint8_t, 4 > PaletteArray
Definition: mythdvdbuffer.h:34
std::array< uint32_t, 16 > CLUTArray
Definition: mythdvdbuffer.h:32
std::array< uint8_t, DVD_BLOCK_SIZE > DvdBuffer
Definition: mythdvdinfo.h:17
#define MTV_PUBLIC
Definition: mythtvexp.h:15
std::chrono::duration< CHRONO_TYPE, std::ratio< 1, 90000 > > pts
Definition: mythchrono.h:55
State
Definition: zmserver.h:69