00001 #ifndef DECODERBASE_H_
00002 #define DECODERBASE_H_
00003
00004 #include "RingBuffer.h"
00005 #include "NuppelVideoPlayer.h"
00006 #include "remoteencoder.h"
00007 #include "mythcontext.h"
00008 #include "mythdbcon.h"
00009 #include "programinfo.h"
00010 #include "mythcodecid.h"
00011
00012 class RingBuffer;
00013 class TeletextViewer;
00014
00015 const int kDecoderProbeBufferSize = 65536;
00016
00017 class StreamInfo
00018 {
00019 public:
00020 StreamInfo() :
00021 av_stream_index(-1), av_substream_index(-1),
00022 language(-2), language_index(0),
00023 stream_id(-1), easy_reader(false),
00024 wide_aspect_ratio(false), dvd_track_num(-1) {}
00025 StreamInfo(int a, int b, uint c, int d, bool e = false, bool f = false) :
00026 av_stream_index(a), av_substream_index(-1),
00027 language(b), language_index(c), stream_id(d),
00028 easy_reader(e), wide_aspect_ratio(f),
00029 dvd_track_num(-1) {}
00030 StreamInfo(int a, int b, uint c, int d, int e,
00031 bool f = false, bool g = false) :
00032 av_stream_index(a), av_substream_index(e),
00033 language(b), language_index(c), stream_id(d),
00034 easy_reader(f), wide_aspect_ratio(g),
00035 dvd_track_num(-1) {}
00036
00037 public:
00038 int av_stream_index;
00040 int av_substream_index;
00041 int language;
00042 uint language_index;
00043 int stream_id;
00044 bool easy_reader;
00045 bool wide_aspect_ratio;
00046 int dvd_track_num;
00047
00048 bool operator<(const StreamInfo& b) const
00049 {
00050 if (this->dvd_track_num >= 0)
00051 return (this->dvd_track_num < b.dvd_track_num);
00052 return (this->stream_id < b.stream_id);
00053 }
00054 };
00055 typedef vector<StreamInfo> sinfo_vec_t;
00056
00057 class DecoderBase
00058 {
00059 public:
00060 DecoderBase(NuppelVideoPlayer *parent, ProgramInfo *pginfo);
00061 virtual ~DecoderBase();
00062
00063 virtual void Reset(void);
00064
00065 virtual int OpenFile(RingBuffer *rbuffer, bool novideo,
00066 char testbuf[kDecoderProbeBufferSize],
00067 int testbufsize = kDecoderProbeBufferSize) = 0;
00068
00069 void setExactSeeks(bool exact) { exactseeks = exact; }
00070 void setLiveTVMode(bool live) { livetv = live; }
00071 void setRecorder(RemoteEncoder *recorder) { nvr_enc = recorder; }
00072
00073
00074 void SetProgramInfo(ProgramInfo *pginfo);
00075
00076 void SetLowBuffers(bool low) { lowbuffers = low; }
00078 virtual void SetDisablePassThrough(bool disable) { (void)disable; }
00079
00080 virtual void setWatchingRecording(bool mode);
00084 virtual bool GetFrame(int onlyvideo) = 0;
00085 NuppelVideoPlayer *GetNVP() { return m_parent; }
00086
00087 virtual bool DoRewind(long long desiredFrame, bool doflush = true);
00088 virtual bool DoFastForward(long long desiredFrame, bool doflush = true);
00089
00090 virtual bool isLastFrameKey() = 0;
00091 virtual void WriteStoredData(RingBuffer *rb, bool storevid,
00092 long timecodeOffset) = 0;
00093 virtual void ClearStoredData(void) { return; };
00094 virtual void SetRawAudioState(bool state) { getrawframes = state; }
00095 virtual bool GetRawAudioState(void) const { return getrawframes; }
00096 virtual void SetRawVideoState(bool state) { getrawvideo = state; }
00097 virtual bool GetRawVideoState(void) const { return getrawvideo; }
00098
00099 virtual long UpdateStoredFrameNum(long frame) = 0;
00100
00101 virtual double GetFPS(void) const { return fps; }
00103 uint GetRawBitrate(void) const { return bitrate; }
00104
00105 virtual void UpdateFramesPlayed(void);
00106 long long GetFramesRead(void) const { return framesRead; };
00107
00108 virtual QString GetCodecDecoderName(void) const = 0;
00109 virtual MythCodecID GetVideoCodecID(void) const = 0;
00110 virtual void *GetVideoCodecPrivate(void) { return NULL; }
00111
00112 virtual bool SyncPositionMap(void);
00113 virtual bool PosMapFromDb(void);
00114 virtual bool PosMapFromEnc(void);
00115
00116 virtual bool FindPosition(long long desired_value, bool search_adjusted,
00117 int &lower_bound, int &upper_bound);
00118
00119 virtual void SetPositionMap(void);
00120 virtual void SeekReset(long long newkey, uint skipFrames,
00121 bool doFlush, bool discardFrames);
00122
00123 void setTranscoding(bool value) { transcoding = value; };
00124
00125 bool IsErrored() { return errored; }
00126
00127 void SetWaitForChange(void);
00128 bool GetWaitForChange(void);
00129 void SetReadAdjust(long long adjust);
00130
00131
00132 void ChangeDVDTrack(bool ffw);
00133 long long DVDFindPosition(long long desiredFrame);
00134 void UpdateDVDFramesPlayed(void);
00135
00136
00137 virtual QStringList GetTracks(uint type) const;
00138 virtual uint GetTrackCount(uint type) const
00139 { return tracks[type].size(); }
00140
00141 virtual int GetTrackLanguageIndex(uint type, uint trackNo) const;
00142 virtual QString GetTrackDesc(uint type, uint trackNo) const;
00143 virtual int SetTrack(uint type, int trackNo);
00144 int GetTrack(uint type) const { return currentTrack[type]; }
00145 StreamInfo GetTrackInfo(uint type, uint trackNo) const;
00146 inline int IncrementTrack(uint type);
00147 inline int DecrementTrack(uint type);
00148 inline int ChangeTrack(uint type, int dir);
00149 virtual bool InsertTrack(uint type, const StreamInfo&);
00150
00151 virtual int GetTeletextDecoderType(void) const { return -1; }
00152 virtual void SetTeletextDecoderViewer(TeletextViewer*) {;}
00153
00154 virtual QString GetXDS(const QString&) const { return QString::null; }
00155
00156
00157 virtual bool SetAudioByComponentTag(int) { return false; }
00158 virtual bool SetVideoByComponentTag(int) { return false; }
00159
00160 protected:
00161 virtual int AutoSelectTrack(uint type);
00162 inline void AutoSelectTracks(void);
00163 inline void ResetTracks(void);
00164
00165 void FileChanged(void);
00166
00167 bool DoRewindSeek(long long desiredFrame);
00168 void DoFastForwardSeek(long long desiredFrame, bool &needflush);
00169
00170 long long GetLastFrameInPosMap(long long desiredFrame);
00171
00172 typedef struct posmapentry
00173 {
00174 long long index;
00175 long long adjFrame;
00176 long long pos;
00177 } PosMapEntry;
00178 long long GetKey(PosMapEntry &entry) const;
00179
00180 NuppelVideoPlayer *m_parent;
00181 ProgramInfo *m_playbackinfo;
00182
00183 RingBuffer *ringBuffer;
00184 RemoteEncoder *nvr_enc;
00185
00186 int current_width;
00187 int current_height;
00188 float current_aspect;
00189 double fps;
00190 uint bitrate;
00191
00192 long long framesPlayed;
00193 long long framesRead;
00194 long long lastKey;
00195 int keyframedist;
00196 long long indexOffset;
00197
00198 bool ateof;
00199 bool exitafterdecoded;
00200 bool transcoding;
00201
00202 bool hasFullPositionMap;
00203 bool recordingHasPositionMap;
00204 bool posmapStarted;
00205 MarkTypes positionMapType;
00206
00207 QValueVector<PosMapEntry> m_positionMap;
00208 bool dontSyncPositionMap;
00209
00210 bool exactseeks;
00211 bool livetv;
00212 bool watchingrecording;
00213
00214 bool hasKeyFrameAdjustTable;
00215
00216 bool lowbuffers;
00217
00218 bool getrawframes;
00219 bool getrawvideo;
00220
00221 bool errored;
00222
00223 bool waitingForChange;
00224 long long readAdjust;
00225 bool justAfterChange;
00226
00227
00228 int currentTrack[kTrackTypeCount];
00229 sinfo_vec_t tracks[kTrackTypeCount];
00230 StreamInfo wantedTrack[kTrackTypeCount];
00231 StreamInfo selectedTrack[(uint)kTrackTypeCount];
00233 vector<int> languagePreference;
00234 };
00235
00236 inline int DecoderBase::IncrementTrack(uint type)
00237 {
00238 int next_track = -1;
00239 int size = tracks[type].size();
00240 if (size)
00241 next_track = (max(-1, currentTrack[type]) + 1) % size;
00242 return SetTrack(type, next_track);
00243 }
00244
00245 inline int DecoderBase::DecrementTrack(uint type)
00246 {
00247 int next_track = -1;
00248 int size = tracks[type].size();
00249 if (size)
00250 next_track = (max(+0, currentTrack[type]) + size - 1) % size;
00251 return SetTrack(type, next_track);
00252 }
00253
00254 inline int DecoderBase::ChangeTrack(uint type, int dir)
00255 {
00256 if (dir > 0)
00257 return IncrementTrack(type);
00258 else
00259 return DecrementTrack(type);
00260 }
00261
00262 inline void DecoderBase::AutoSelectTracks(void)
00263 {
00264 for (uint i = 0; i < kTrackTypeCount; i++)
00265 AutoSelectTrack(i);
00266 }
00267
00268 inline void DecoderBase::ResetTracks(void)
00269 {
00270 for (uint i = 0; i < kTrackTypeCount; i++)
00271 currentTrack[i] = -1;
00272 }
00273
00274 #endif