00001 #ifndef DECODERBASE_H_
00002 #define DECODERBASE_H_
00003
00004 #include <stdint.h>
00005
00006 #include <vector>
00007 using namespace std;
00008
00009 #include "ringbuffer.h"
00010 #include "remoteencoder.h"
00011 #include "mythcontext.h"
00012 #include "mythdbcon.h"
00013 #include "programinfo.h"
00014 #include "mythcodecid.h"
00015
00016 class RingBuffer;
00017 class TeletextViewer;
00018 class MythPlayer;
00019 class AudioPlayer;
00020
00021 const int kDecoderProbeBufferSize = 256 * 1024;
00022
00024 typedef enum TrackTypes
00025 {
00026 kTrackTypeAudio = 0,
00027 kTrackTypeVideo,
00028 kTrackTypeSubtitle,
00029 kTrackTypeCC608,
00030 kTrackTypeCC708,
00031 kTrackTypeTeletextCaptions,
00032 kTrackTypeTeletextMenu,
00033 kTrackTypeRawText,
00034 kTrackTypeAttachment,
00035 kTrackTypeCount,
00036
00037 kTrackTypeTextSubtitle,
00038 } TrackType;
00039 QString toString(TrackType type);
00040 int to_track_type(const QString &str);
00041
00042 typedef enum DecodeTypes
00043 {
00044 kDecodeNothing = 0x00,
00045 kDecodeVideo = 0x01,
00046 kDecodeAudio = 0x02,
00047 kDecodeAV = 0x03,
00048 } DecodeType;
00049
00050 typedef enum AudioTrackType
00051 {
00052 kAudioTypeNormal = 0,
00053 kAudioTypeAudioDescription,
00054 kAudioTypeCommentary
00055 } AudioTrackType;
00056
00057 class StreamInfo
00058 {
00059 public:
00060 StreamInfo() :
00061 av_stream_index(-1), av_substream_index(-1),
00062 language(-2), language_index(0),
00063 stream_id(-1), easy_reader(false),
00064 wide_aspect_ratio(false), orig_num_channels(2), forced(false),
00065 audio_type(kAudioTypeNormal) {}
00066 StreamInfo(int a, int b, uint c, int d, int e, bool f = false,
00067 bool g = false, bool h = false,
00068 AudioTrackType i = kAudioTypeNormal) :
00069 av_stream_index(a), av_substream_index(-1),
00070 language(b), language_index(c), stream_id(d),
00071 easy_reader(f), wide_aspect_ratio(g), orig_num_channels(e), forced(h),
00072 audio_type(i) {}
00073 StreamInfo(int a, int b, uint c, int d, int e, int f,
00074 bool g = false, bool h = false, bool i = false,
00075 AudioTrackType j = kAudioTypeNormal) :
00076 av_stream_index(a), av_substream_index(e),
00077 language(b), language_index(c), stream_id(d),
00078 easy_reader(g), wide_aspect_ratio(h), orig_num_channels(f), forced(i),
00079 audio_type(j) {}
00080
00081 public:
00082 int av_stream_index;
00084 int av_substream_index;
00085 int language;
00086 uint language_index;
00087 int stream_id;
00088 bool easy_reader;
00089 bool wide_aspect_ratio;
00090 int orig_num_channels;
00091 bool forced;
00092 AudioTrackType audio_type;
00093
00094 bool operator<(const StreamInfo& b) const
00095 {
00096 return (this->stream_id < b.stream_id);
00097 }
00098 };
00099 typedef vector<StreamInfo> sinfo_vec_t;
00100
00101 class DecoderBase
00102 {
00103 public:
00104 DecoderBase(MythPlayer *parent, const ProgramInfo &pginfo);
00105 virtual ~DecoderBase();
00106
00107 virtual void Reset(bool reset_video_data, bool seek_reset, bool reset_file);
00108
00109 virtual int OpenFile(RingBuffer *rbuffer, bool novideo,
00110 char testbuf[kDecoderProbeBufferSize],
00111 int testbufsize = kDecoderProbeBufferSize) = 0;
00112
00113 virtual void SetEof(bool eof) { ateof = eof; }
00114 bool GetEof(void) const { return ateof; }
00115
00116 void SetSeekSnap(uint64_t snap) { seeksnap = snap; }
00117 uint64_t GetSeekSnap(void) const { return seeksnap; }
00118 void SetLiveTVMode(bool live) { livetv = live; }
00119
00120
00121 void SetProgramInfo(const ProgramInfo &pginfo);
00122
00123 void SetLowBuffers(bool low) { lowbuffers = low; }
00125 virtual void SetDisablePassThrough(bool disable) { (void)disable; }
00126
00127 virtual void SetWatchingRecording(bool mode);
00129 virtual bool GetFrame(DecodeType) = 0;
00130 MythPlayer *GetPlayer() { return m_parent; }
00131
00132 virtual int GetNumChapters(void) { return 0; }
00133 virtual int GetCurrentChapter(long long framesPlayed) { return 0; }
00134 virtual void GetChapterTimes(QList<long long> ×) { return; }
00135 virtual long long GetChapter(int chapter) { return framesPlayed; }
00136 virtual bool DoRewind(long long desiredFrame, bool doflush = true);
00137 virtual bool DoFastForward(long long desiredFrame, bool doflush = true);
00138
00139 float GetVideoAspect(void) const { return current_aspect; }
00140
00141 virtual int64_t NormalizeVideoTimecode(int64_t timecode) { return timecode; }
00142
00143 virtual bool IsLastFrameKey(void) const = 0;
00144 virtual bool IsCodecMPEG(void) const { return false; }
00145 virtual void WriteStoredData(RingBuffer *rb, bool storevid,
00146 long timecodeOffset) = 0;
00147 virtual void ClearStoredData(void) { return; }
00148 virtual void SetRawAudioState(bool state) { getrawframes = state; }
00149 virtual bool GetRawAudioState(void) const { return getrawframes; }
00150 virtual void SetRawVideoState(bool state) { getrawvideo = state; }
00151 virtual bool GetRawVideoState(void) const { return getrawvideo; }
00152
00153 virtual long UpdateStoredFrameNum(long frame) = 0;
00154
00155 virtual double GetFPS(void) const { return fps; }
00157 uint GetRawBitrate(void) const { return bitrate; }
00158
00159 virtual void UpdateFramesPlayed(void);
00160 long long GetFramesRead(void) const { return framesRead; }
00161 long long GetFramesPlayed(void) const { return framesPlayed; }
00162
00163 virtual QString GetCodecDecoderName(void) const = 0;
00164 virtual QString GetRawEncodingType(void) { return QString(); }
00165 virtual MythCodecID GetVideoCodecID(void) const = 0;
00166 virtual void *GetVideoCodecPrivate(void) { return NULL; }
00167
00168 virtual void ResetPosMap(void);
00169 virtual bool SyncPositionMap(void);
00170 virtual bool PosMapFromDb(void);
00171 virtual bool PosMapFromEnc(void);
00172
00173 virtual bool FindPosition(long long desired_value, bool search_adjusted,
00174 int &lower_bound, int &upper_bound);
00175
00176 uint64_t SavePositionMapDelta(uint64_t first_frame, uint64_t last_frame);
00177 virtual void SeekReset(long long newkey, uint skipFrames,
00178 bool doFlush, bool discardFrames);
00179
00180 void SetTranscoding(bool value) { transcoding = value; }
00181
00182 bool IsErrored() const { return errored; }
00183
00184 void SetWaitForChange(void);
00185 bool GetWaitForChange(void) const;
00186 void SetReadAdjust(long long adjust);
00187
00188
00189 void SetDecodeAllSubtitles(bool val) { decodeAllSubtitles = val; }
00190 virtual QStringList GetTracks(uint type) const;
00191 virtual uint GetTrackCount(uint type) const
00192 { return tracks[type].size(); }
00193
00194 virtual int GetTrackLanguageIndex(uint type, uint trackNo) const;
00195 virtual QString GetTrackDesc(uint type, uint trackNo) const;
00196 virtual int SetTrack(uint type, int trackNo);
00197 int GetTrack(uint type) const { return currentTrack[type]; }
00198 StreamInfo GetTrackInfo(uint type, uint trackNo) const;
00199 inline int IncrementTrack(uint type);
00200 inline int DecrementTrack(uint type);
00201 inline int ChangeTrack(uint type, int dir);
00202 virtual bool InsertTrack(uint type, const StreamInfo&);
00203 inline int NextTrack(uint type);
00204
00205 virtual int GetTeletextDecoderType(void) const { return -1; }
00206
00207 virtual QString GetXDS(const QString&) const { return QString::null; }
00208 virtual QByteArray GetSubHeader(uint trackNo) const { return QByteArray(); }
00209 virtual void GetAttachmentData(uint trackNo, QByteArray &filename,
00210 QByteArray &data) {}
00211
00212
00213 virtual bool SetAudioByComponentTag(int) { return false; }
00214 virtual bool SetVideoByComponentTag(int) { return false; }
00215
00216 void SaveTotalDuration(void);
00217 void ResetTotalDuration(void) { totalDuration = 0; }
00218 void SaveTotalFrames(void);
00219
00220 protected:
00221 virtual int AutoSelectTrack(uint type);
00222 inline void AutoSelectTracks(void);
00223 inline void ResetTracks(void);
00224
00225 void FileChanged(void);
00226
00227 virtual bool DoRewindSeek(long long desiredFrame);
00228 virtual void DoFastForwardSeek(long long desiredFrame, bool &needflush);
00229
00230 long long ConditionallyUpdatePosMap(long long desiredFrame);
00231 long long GetLastFrameInPosMap(void) const;
00232 unsigned long GetPositionMapSize(void) const;
00233
00234 typedef struct posmapentry
00235 {
00236 long long index;
00237 long long adjFrame;
00238 long long pos;
00239 } PosMapEntry;
00240 long long GetKey(const PosMapEntry &entry) const;
00241
00242 MythPlayer *m_parent;
00243 ProgramInfo *m_playbackinfo;
00244 AudioPlayer *m_audio;
00245 RingBuffer *ringBuffer;
00246
00247 int current_width;
00248 int current_height;
00249 float current_aspect;
00250 double fps;
00251 uint bitrate;
00252
00253 long long framesPlayed;
00254 long long framesRead;
00255 int64_t totalDuration;
00256 long long lastKey;
00257 int keyframedist;
00258 long long indexOffset;
00259
00260 bool ateof;
00261 bool exitafterdecoded;
00262 bool transcoding;
00263
00264 bool hasFullPositionMap;
00265 bool recordingHasPositionMap;
00266 bool posmapStarted;
00267 MarkTypes positionMapType;
00268
00269 mutable QMutex m_positionMapLock;
00270 vector<PosMapEntry> m_positionMap;
00271 bool dontSyncPositionMap;
00272
00273 uint64_t seeksnap;
00274 bool livetv;
00275 bool watchingrecording;
00276
00277 bool hasKeyFrameAdjustTable;
00278
00279 bool lowbuffers;
00280
00281 bool getrawframes;
00282 bool getrawvideo;
00283
00284 bool errored;
00285
00286 bool waitingForChange;
00287 long long readAdjust;
00288 bool justAfterChange;
00289
00290
00291 bool decodeAllSubtitles;
00292 int currentTrack[kTrackTypeCount];
00293 sinfo_vec_t tracks[kTrackTypeCount];
00294 StreamInfo wantedTrack[kTrackTypeCount];
00295 StreamInfo selectedTrack[(uint)kTrackTypeCount];
00297 vector<int> languagePreference;
00298 };
00299
00300 inline int DecoderBase::IncrementTrack(uint type)
00301 {
00302 int next_track = -1;
00303 int size = tracks[type].size();
00304 if (size)
00305 next_track = (max(-1, currentTrack[type]) + 1) % size;
00306 return SetTrack(type, next_track);
00307 }
00308
00309 inline int DecoderBase::DecrementTrack(uint type)
00310 {
00311 int next_track = -1;
00312 int size = tracks[type].size();
00313 if (size)
00314 next_track = (max(+0, currentTrack[type]) + size - 1) % size;
00315 return SetTrack(type, next_track);
00316 }
00317
00318 inline int DecoderBase::ChangeTrack(uint type, int dir)
00319 {
00320 if (dir > 0)
00321 return IncrementTrack(type);
00322 else
00323 return DecrementTrack(type);
00324 }
00325
00326 inline void DecoderBase::AutoSelectTracks(void)
00327 {
00328 for (uint i = 0; i < kTrackTypeCount; i++)
00329 AutoSelectTrack(i);
00330 }
00331
00332 inline void DecoderBase::ResetTracks(void)
00333 {
00334 for (uint i = 0; i < kTrackTypeCount; i++)
00335 currentTrack[i] = -1;
00336 }
00337
00338 inline int DecoderBase::NextTrack(uint type)
00339 {
00340 int next_track = -1;
00341 int size = tracks[type].size();
00342 if (size)
00343 next_track = (max(0, currentTrack[type]) + 1) % size;
00344 return next_track;
00345 }
00346 #endif