MythTV  master
bdringbuffer.h
Go to the documentation of this file.
1 #ifndef BD_RING_BUFFER_H_
2 #define BD_RING_BUFFER_H_
3 
4 #include "config.h"
5 
6 #define BD_BLOCK_SIZE 6144LL
7 
8 //Qt headers
9 #include <QString>
10 #include <QRect>
11 #include <QHash>
12 #include <QImage>
13 #include <QCoreApplication>
14 
15 // external/libmythbluray
16 #include "libbluray/bluray.h"
17 #if CONFIG_LIBBLURAY_EXTERNAL
18 #include "libbluray/overlay.h"
19 #else
20 #include "libbluray/decoders/overlay.h"
21 #endif
22 
23 #include "ringbuffer.h"
24 
26 {
27  friend class BDRingBuffer;
29 
30  public:
31  explicit BDInfo(const QString &filename);
32  ~BDInfo(void) = default;
33  bool IsValid(void) const { return m_isValid; }
34  bool GetNameAndSerialNum(QString &name, QString &serialnum);
35  QString GetLastError(void) const { return m_lastError; }
36 
37 protected:
38  static void GetNameAndSerialNum(BLURAY* nav,
39  QString &name,
40  QString &serialnum,
41  const QString &filename,
42  const QString &logPrefix);
43 
44  protected:
45  QString m_name;
46  QString m_serialnumber;
47  QString m_lastError;
48  bool m_isValid {true};
49 };
50 
51 class BDOverlay
52 {
53  public:
54  BDOverlay() = default;
55  explicit BDOverlay(const bd_overlay_s * overlay);
56  explicit BDOverlay(const bd_argb_overlay_s * overlay);
57 
58  void setPalette(const BD_PG_PALETTE_ENTRY *palette);
59  void wipe();
60  void wipe(int x, int y, int width, int height);
61 
62  QImage m_image;
63  int64_t m_pts {-1};
64  int m_x {0};
65  int m_y {0};
66 };
67 
74 {
75  Q_DECLARE_TR_FUNCTIONS(BDRingBuffer);
76 
77  public:
78  explicit BDRingBuffer(const QString &lfilename);
79  ~BDRingBuffer() override;
80 
81  bool IsStreamed(void) override { return true; } // RingBuffer
82 
83  void ProgressUpdate(void);
84 
85  // Player interaction
86  bool BDWaitingForPlayer(void) { return m_playerWait; }
87  void SkipBDWaitingForPlayer(void) { m_playerWait = false; }
88  void IgnoreWaitStates(bool ignore) override { m_ignorePlayerWait = ignore; } // RingBuffer
89  bool StartFromBeginning(void) override; // RingBuffer
90  bool GetNameAndSerialNum(QString& _name, QString& _serialnum);
91  bool GetBDStateSnapshot(QString& state);
92  bool RestoreBDStateSnapshot(const QString &state);
93 
94  void ClearOverlays(void);
95  BDOverlay* GetOverlay(void);
96  void SubmitOverlay(const bd_overlay_s * overlay);
97  void SubmitARGBOverlay(const bd_argb_overlay_s * overlay);
98 
99  uint32_t GetNumTitles(void) const { return m_numTitles; }
100  int GetCurrentTitle(void);
101  uint64_t GetCurrentAngle(void) const { return m_currentAngle; }
102  int GetTitleDuration(int title);
103  // Get the size in bytes of the current title (playlist item).
104  uint64_t GetTitleSize(void) const { return m_titlesize; }
105  // Get The total duration of the current title in 90Khz ticks.
106  uint64_t GetTotalTimeOfTitle(void) const { return (m_currentTitleLength / 90000); }
107  uint64_t GetCurrentTime(void) { return (m_currentTime / 90000); }
108  long long GetReadPosition(void) const override; // RingBuffer
109  uint64_t GetTotalReadPosition(void);
110  uint32_t GetNumChapters(void);
111  uint32_t GetCurrentChapter(void);
112  uint64_t GetNumAngles(void) { return m_currentTitleAngleCount; }
113  uint64_t GetChapterStartTime(uint32_t chapter);
114  uint64_t GetChapterStartFrame(uint32_t chapter);
115  bool IsOpen(void) const override { return m_bdnav; } // RingBuffer
116  bool IsHDMVNavigation(void) const { return m_isHDMVNavigation; }
117  bool IsInMenu(void) const override { return m_inMenu; } // RingBuffer
118  bool IsInStillFrame(void) const override; // RingBuffer
119  bool TitleChanged(void);
120  bool IsValidStream(int streamid);
121  void UnblockReading(void) { m_processState = PROCESS_REPROCESS; }
122  bool IsReadingBlocked(void) { return (m_processState == PROCESS_WAIT); }
123  int64_t AdjustTimestamp(int64_t timestamp);
124 
125  void GetDescForPos(QString &desc);
126  double GetFrameRate(void);
127 
128  int GetAudioLanguage(uint streamID);
129  int GetSubtitleLanguage(uint streamID);
130 
131  // commands
132  bool HandleAction(const QStringList &actions, int64_t pts) override; // RingBuffer
133  bool OpenFile(const QString &lfilename,
134  uint retry_ms = kDefaultOpenTimeout) override; // RingBuffer
135  void close(void);
136 
137  bool GoToMenu(const QString &str, int64_t pts);
138  bool SwitchTitle(uint32_t index);
139  bool SwitchPlaylist(uint32_t index);
140  bool SwitchAngle(uint angle);
141 
142  protected:
143  int safe_read(void *data, uint sz) override; // RingBuffer
144  long long SeekInternal(long long pos, int whence) override; // RingBuffer
145  uint64_t SeekInternal(uint64_t pos);
146 
147  private:
148  // private player interaction
149  void WaitForPlayer(void);
150 
151  // private title handling
152  bool UpdateTitleInfo(void);
153  BLURAY_TITLE_INFO* GetTitleInfo(uint32_t index);
154  BLURAY_TITLE_INFO* GetPlaylistInfo(uint32_t index);
155 
156  // private menu handling methods
157  void PressButton(int32_t key, int64_t pts); // Keyboard
158  void ClickButton(int64_t pts, uint16_t x, uint16_t y); // Mouse
159 
160  // private bluray event handling
161  bool HandleBDEvents(void);
162  void HandleBDEvent(BD_EVENT &event);
163 
164  const BLURAY_STREAM_INFO* FindStream(int streamid, BLURAY_STREAM_INFO* streams, int streamCount) const;
165 
166 
167  typedef enum
168  {
171  PROCESS_WAIT
172  }processState_t;
173 
174  BLURAY *m_bdnav {nullptr};
175  bool m_isHDMVNavigation {false};
176  bool m_tryHDMVNavigation {false};
177  bool m_topMenuSupported {false};
178  bool m_firstPlaySupported {false};
179 
180  uint32_t m_numTitles {0};
181  // Index number of main title
182  uint32_t m_mainTitle {0};
183  // Selected title's duration, in ticks (90Khz)
184  uint64_t m_currentTitleLength {0};
185  // Selected title info from struct in bluray.h
186  BLURAY_TITLE_INFO *m_currentTitleInfo {nullptr};
187  uint64_t m_titlesize {0};
188  uint64_t m_currentTitleAngleCount {0};
189  uint64_t m_currentTime {0};
190 
191  int m_imgHandle {-1};
192 
193  int m_currentAngle {0};
194  int m_currentTitle {-1};
195  int m_currentPlaylist {0};
196  int m_currentPlayitem {0};
197  int m_currentChapter {0};
198 
199  int m_currentAudioStream {0};
200  int m_currentIGStream {0};
201  int m_currentPGTextSTStream {0};
202  int m_currentSecondaryAudioStream {0};
203  int m_currentSecondaryVideoStream {0};
204 
205  bool m_PGTextSTEnabled {false};
206  bool m_secondaryAudioEnabled {false};
207  bool m_secondaryVideoEnabled {false};
208  bool m_secondaryVideoIsFullscreen {false};
209 
210  bool m_titleChanged {false};
211 
212  bool m_playerWait {false};
213  bool m_ignorePlayerWait {true};
214 
216  QList<BDOverlay*> m_overlayImages;
217  QVector<BDOverlay*> m_overlayPlanes;
218 
219  uint8_t m_stillTime {0};
220  uint8_t m_stillMode {BLURAY_STILL_NONE};
221  volatile bool m_inMenu {false};
222  BD_EVENT m_lastEvent;
223  processState_t m_processState {PROCESS_NORMAL};
224  QByteArray m_pendingData;
225  int64_t m_timeDiff {0};
226 
227  QHash<uint32_t,BLURAY_TITLE_INFO*> m_cachedTitleInfo;
228  QHash<uint32_t,BLURAY_TITLE_INFO*> m_cachedPlaylistInfo;
229  QMutex m_infoLock {QMutex::Recursive};
230  QString m_name;
231  QString m_serialNumber;
232 
233  QThread *m_mainThread {nullptr};
234 };
235 #endif
virtual bool OpenFile(const QString &lfilename, uint retry_ms=kDefaultOpenTimeout)=0
Opens a file for reading.
BD_EVENT m_lastEvent
Definition: bdringbuffer.h:222
bool IsValid(void) const
Definition: bdringbuffer.h:33
bool GetNameAndSerialNum(QString &_name, QString &_serialnum)
void IgnoreWaitStates(bool ignore) override
Definition: bdringbuffer.h:88
QList< BDOverlay * > m_overlayImages
Definition: bdringbuffer.h:216
bool IsReadingBlocked(void)
Definition: bdringbuffer.h:122
QImage m_image
Definition: bdringbuffer.h:62
QString GetLastError(void) const
Definition: bdringbuffer.h:35
unsigned int uint
Definition: compat.h:140
virtual long long SeekInternal(long long pos, int whence)=0
void SkipBDWaitingForPlayer(void)
Definition: bdringbuffer.h:87
uint64_t GetCurrentTime(void)
Definition: bdringbuffer.h:107
uint64_t GetCurrentAngle(void) const
Definition: bdringbuffer.h:101
QVector< BDOverlay * > m_overlayPlanes
Definition: bdringbuffer.h:217
bool IsHDMVNavigation(void) const
Definition: bdringbuffer.h:116
#define MTV_PUBLIC
Definition: mythtvexp.h:15
#define close
Definition: compat.h:16
virtual bool IsInStillFrame(void) const
uint32_t GetNumTitles(void) const
Definition: bdringbuffer.h:99
QHash< uint32_t, BLURAY_TITLE_INFO * > m_cachedPlaylistInfo
Definition: bdringbuffer.h:228
void wipe()
unsigned short uint16_t
Definition: iso6937tables.h:1
bool BDWaitingForPlayer(void)
Definition: bdringbuffer.h:86
const char * name
Definition: ParseText.cpp:328
BDOverlay()=default
virtual long long GetReadPosition(void) const =0
Returns how far into the file we have read.
QString m_serialNumber
Definition: bdringbuffer.h:231
QMutex m_overlayLock
Definition: bdringbuffer.h:215
QHash< uint32_t, BLURAY_TITLE_INFO * > m_cachedTitleInfo
Definition: bdringbuffer.h:227
virtual int safe_read(void *data, uint sz)=0
bool IsInMenu(void) const override
Definition: bdringbuffer.h:117
uint64_t GetNumAngles(void)
Definition: bdringbuffer.h:112
int64_t m_pts
Definition: bdringbuffer.h:63
virtual bool StartFromBeginning(void)
bool IsStreamed(void) override
Definition: bdringbuffer.h:81
QString m_name
Definition: bdringbuffer.h:230
QString m_name
Definition: bdringbuffer.h:45
QByteArray m_pendingData
Definition: bdringbuffer.h:224
uint64_t GetTitleSize(void) const
Definition: bdringbuffer.h:104
Implements a file/stream reader/writer.
void setPalette(const BD_PG_PALETTE_ENTRY *palette)
QString m_serialnumber
Definition: bdringbuffer.h:46
void UnblockReading(void)
Definition: bdringbuffer.h:121
bool IsOpen(void) const override
Returns true if open for either reading or writing.
Definition: bdringbuffer.h:115
Q_DECLARE_TR_FUNCTIONS(BDRingBuffer)
QString m_lastError
Definition: bdringbuffer.h:47
uint64_t GetTotalTimeOfTitle(void) const
Definition: bdringbuffer.h:106
virtual bool HandleAction(const QStringList &, int64_t)