00001
00002 #ifndef DVD_RING_BUFFER_H_
00003 #define DVD_RING_BUFFER_H_
00004
00005 #define DVD_BLOCK_SIZE 2048LL
00006 #define DVD_MENU_MAX 7
00007
00008 #include <QMap>
00009 #include <QString>
00010 #include <QMutex>
00011 #include <QRect>
00012
00013 #include "ringbuffer.h"
00014 #include "mythmiscutil.h"
00015
00016 extern "C" {
00017 #include "libavcodec/avcodec.h"
00018 }
00019
00020 #include "dvdnav/dvdnav.h"
00021
00028 class MythDVDPlayer;
00029
00030 class MTV_PUBLIC DVDInfo
00031 {
00032 public:
00033 DVDInfo(const QString &filename);
00034 ~DVDInfo(void);
00035 bool IsValid(void) const { return m_nav != NULL; }
00036 bool GetNameAndSerialNum(QString &name, QString &serialnum);
00037
00038 protected:
00039 dvdnav_t *m_nav;
00040 const char *m_name;
00041 const char *m_serialnumber;
00042 };
00043
00044 class MTV_PUBLIC DVDRingBuffer : public RingBuffer
00045 {
00046 public:
00047 DVDRingBuffer(const QString &lfilename);
00048 virtual ~DVDRingBuffer();
00049
00050
00051 int GetTitle(void) const { return m_title; }
00052 bool DVDWaitingForPlayer(void) { return m_playerWait; }
00053 int GetPart(void) const { return m_part; }
00054 int GetCurrentAngle(void) const { return m_currentAngle; }
00055 int GetNumAngles(void) { return m_currentTitleAngleCount; }
00056 bool IsOpen(void) const { return m_dvdnav; }
00057 long long GetTotalReadPosition(void) { return m_titleLength; }
00058 uint GetChapterLength(void) const { return m_pgLength / 90000; }
00059 void GetChapterTimes(QList<long long> ×);
00060 uint64_t GetChapterTimes(uint title);
00061 virtual long long GetReadPosition(void) const;
00062 void GetDescForPos(QString &desc);
00063 void GetPartAndTitle(int &_part, int &_title) const
00064 { _part = m_part; _title = m_title; }
00065 uint GetTotalTimeOfTitle(void);
00066 float GetAspectOverride(void) { return m_forcedAspect; }
00067 virtual bool IsBookmarkAllowed(void);
00068 virtual bool IsStreamed(void) { return true; }
00069 virtual int BestBufferSize(void) { return 2048; }
00070
00071 uint GetCellStart(void);
00072 bool PGCLengthChanged(void);
00073 bool CellChanged(void);
00074 bool IsInStillFrame(void) const { return m_still > 0; }
00075 bool NeedsStillFrame(void) { return IsInStillFrame() || NewSequence(); }
00076 bool NewSequence(bool new_sequence = false);
00077 bool AudioStreamsChanged(void) const { return m_audioStreamsChanged; }
00078 bool IsWaiting(void) const { return m_dvdWaiting; }
00079 int NumPartsInTitle(void) const { return m_titleParts; }
00080 void GetMenuSPUPkt(uint8_t *buf, int len, int stream_id);
00081 virtual bool IsInDiscMenuOrStillFrame(void) const
00082 { return IsInMenu() || IsInStillFrame(); }
00083
00084
00085 AVSubtitle *GetMenuSubtitle(uint &version);
00086 int NumMenuButtons(void) const;
00087 QRect GetButtonCoords(void);
00088 void ReleaseMenuButton(void);
00089 bool IsInMenu(void) const { return m_inMenu; }
00090 virtual bool HandleAction(const QStringList &actions, int64_t pts);
00091
00092
00093 uint GetSubtitleLanguage(int key);
00094 bool DecodeSubtitles(AVSubtitle * sub, int * gotSubtitles,
00095 const uint8_t * buf, int buf_size);
00096
00097 uint GetAudioLanguage(int id);
00098 int GetAudioTrackNum(uint key);
00099 int GetAudioTrackType(uint stream_id);
00100
00101 bool GetNameAndSerialNum(QString& _name, QString& _serialnum);
00102 double GetFrameRate(void);
00103 bool StartOfTitle(void) { return (m_part == 0); }
00104 bool EndOfTitle(void) { return ((!m_titleParts) ||
00105 (m_part == (m_titleParts - 1)) ||
00106 (m_titleParts == 1)); }
00107
00108
00109 virtual bool OpenFile(const QString &lfilename,
00110 uint retry_ms = kDefaultOpenTimeout);
00111 void PlayTitleAndPart(int _title, int _part)
00112 { dvdnav_part_play(m_dvdnav, _title, _part); }
00113 virtual bool StartFromBeginning(void);
00114 void CloseDVD(void);
00115 bool playTrack(int track);
00116 bool nextTrack(void);
00117 void prevTrack(void);
00118 virtual int safe_read(void *data, uint sz);
00119 virtual long long Seek(long long pos, int whence, bool has_lock);
00120 long long NormalSeek(long long time);
00121 void SkipStillFrame(void);
00122 void WaitSkip(void);
00123 void SkipDVDWaitingForPlayer(void) { m_playerWait = false; }
00124 bool GoToMenu(const QString str);
00125 void GoToNextProgram(void);
00126 void GoToPreviousProgram(void);
00127
00128 virtual void IgnoreWaitStates(bool ignore) { m_skipstillorwait = ignore; }
00129 void AudioStreamsChanged(bool change) { m_audioStreamsChanged = change; }
00130 uint GetCurrentTime(void) { return (m_currentTime / 90000); }
00131 uint TitleTimeLeft(void);
00132 void SetTrack(uint type, int trackNo);
00133 int GetTrack(uint type);
00134 uint8_t GetNumAudioChannels(int id);
00135 void SetDVDSpeed(void);
00136 void SetDVDSpeed(int speed);
00137 bool SwitchAngle(uint angle);
00138
00139 void SetParent(MythDVDPlayer *p) { m_parent = p; }
00140
00141 protected:
00142 dvdnav_t *m_dvdnav;
00143 unsigned char m_dvdBlockWriteBuf[DVD_BLOCK_SIZE];
00144 unsigned char *m_dvdBlockReadBuf;
00145 int m_dvdBlockRPos;
00146 int m_dvdBlockWPos;
00147 long long m_pgLength;
00148 long long m_pgcLength;
00149 long long m_cellStart;
00150 bool m_cellChanged;
00151 bool m_pgcLengthChanged;
00152 long long m_pgStart;
00153 long long m_currentpos;
00154 dvdnav_t *m_lastNav;
00155 int32_t m_part;
00156 int32_t m_lastPart;
00157 int32_t m_title;
00158 int32_t m_lastTitle;
00159 bool m_playerWait;
00160 int32_t m_titleParts;
00161 bool m_gotStop;
00162 int m_currentAngle;
00163 int m_currentTitleAngleCount;
00164
00165 bool m_newSequence;
00166 int m_still;
00167 int m_lastStill;
00168 bool m_audioStreamsChanged;
00169 bool m_dvdWaiting;
00170 long long m_titleLength;
00171 bool m_skipstillorwait;
00172 long long m_cellstartPos;
00173 bool m_buttonSelected;
00174 bool m_buttonExists;
00175 int m_cellid;
00176 int m_lastcellid;
00177 int m_vobid;
00178 int m_lastvobid;
00179 bool m_cellRepeated;
00180
00181 int m_curAudioTrack;
00182 int8_t m_curSubtitleTrack;
00183 bool m_autoselectsubtitle;
00184 long long m_seekpos;
00185 const char *m_dvdname;
00186 const char *m_serialnumber;
00187 bool m_seeking;
00188 uint64_t m_seektime;
00189 uint m_currentTime;
00190 QMap<uint, uint> m_seekSpeedMap;
00191 QMap<uint, QList<uint64_t> > m_chapterMap;
00192
00193 MythDVDPlayer *m_parent;
00194 float m_forcedAspect;
00195
00196
00197 void ActivateButton(void);
00198 void MoveButtonLeft(void);
00199 void MoveButtonRight(void);
00200 void MoveButtonUp(void);
00201 void MoveButtonDown(void);
00202 bool DVDButtonUpdate(bool b_mode);
00203 void ClearMenuSPUParameters(void);
00204 void ClearMenuButton(void);
00205
00206 bool m_inMenu;
00207 uint m_buttonVersion;
00208 int m_buttonStreamID;
00209 uint32_t m_clut[16];
00210 uint8_t m_button_color[4];
00211 uint8_t m_button_alpha[4];
00212 QRect m_hl_button;
00213 uint8_t *m_menuSpuPkt;
00214 int m_menuBuflength;
00215 AVSubtitle m_dvdMenuButton;
00216 QMutex m_menuBtnLock;
00217
00218 QMutex m_seekLock;
00219 long long Seek(long long time);
00220
00221 void ClearChapterCache(void);
00222 uint ConvertLangCode(uint16_t code);
00223 void SelectDefaultButton(void);
00224 void WaitForPlayer(void);
00225
00226 int get_nibble(const uint8_t *buf, int nibble_offset);
00227 int decode_rle(uint8_t *bitmap, int linesize, int w, int h,
00228 const uint8_t *buf, int nibble_offset, int buf_size);
00229 void guess_palette(uint32_t *rgba_palette,uint8_t *palette,
00230 uint8_t *alpha);
00231 int is_transp(const uint8_t *buf, int pitch, int n,
00232 const uint8_t *transp_color);
00233 int find_smallest_bounding_rectangle(AVSubtitle *s);
00234 };
00235
00236 #endif // DVD_RING_BUFFER_H_