00001 #ifndef IVTVDECODER_H_
00002 #define IVTVDECODER_H_
00003
00004 #include <qstring.h>
00005 #include <qmap.h>
00006
00007 #include "programinfo.h"
00008 #include "format.h"
00009 #include "decoderbase.h"
00010
00011 extern "C" {
00012 #include "frame.h"
00013 #include "../libavcodec/avcodec.h"
00014 #include "../libavformat/avformat.h"
00015 }
00016
00017 class ProgramInfo;
00018 class MythSqlDatabase;
00019
00020 struct IvtvQueuedFrame
00021 {
00022 int raw;
00023 long long actual;
00024 IvtvQueuedFrame(void) { raw = 0; actual = 0; };
00025 IvtvQueuedFrame(int r, long long a) { raw = r; actual = a; };
00026 };
00027 typedef QValueList<IvtvQueuedFrame> ivtv_frame_list_t;
00028
00029 class DeviceInfo
00030 {
00031 public:
00032 DeviceInfo() : works(false), ntsc(true) {}
00033 bool works;
00034 bool ntsc;
00035 };
00036 typedef QMap<QString,DeviceInfo> DevInfoMap;
00037
00038 class IvtvDecoder : public DecoderBase
00039 {
00040 public:
00041 IvtvDecoder(NuppelVideoPlayer *parent, ProgramInfo *pginfo);
00042 ~IvtvDecoder();
00043
00044 static bool CanHandle(char testbuf[kDecoderProbeBufferSize],
00045 const QString &filename,
00046 int testbufsize = kDecoderProbeBufferSize);
00047
00048 int OpenFile(RingBuffer *rbuffer, bool novideo,
00049 char testbuf[kDecoderProbeBufferSize],
00050 int testbufsize = kDecoderProbeBufferSize);
00051 bool GetFrame(int onlyvideo);
00052
00053 bool DoFastForward(long long desiredFrame, bool doflush = true);
00054
00055 bool isLastFrameKey(void) { return false; }
00056 void WriteStoredData(RingBuffer *rb, bool storevid, long timecodeOffset)
00057 { (void)rb; (void)storevid; (void)timecodeOffset;}
00058 void SetRawAudioState(bool state) { (void)state; }
00059 bool GetRawAudioState(void) const { return false; }
00060 void SetRawVideoState(bool state) { (void)state; }
00061 bool GetRawVideoState(void) const { return false; }
00062
00063 long UpdateStoredFrameNum(long frame) { (void)frame; return 0; }
00064 void UpdateFramesPlayed(void);
00065
00066 QString GetCodecDecoderName(void) const { return "ivtv"; }
00067 MythCodecID GetVideoCodecID(void) const { return kCodec_MPEG2; }
00068
00069 protected:
00070 RingBuffer *getRingBuf(void) { return ringBuffer; }
00071
00072 private:
00073 int MpegPreProcessPkt(unsigned char *buf, int len,
00074 long long startpos, long stopframe);
00075 void SeekReset(long long newkey = 0, uint skipframes = 0,
00076 bool needFlush = false, bool discardFrames = false);
00077 bool ReadWrite(int onlyvideo, long stopframe = LONG_MAX);
00078 bool StepFrames(long long start, long long count);
00079
00080 static bool GetDeviceWorks(QString dev);
00081 static bool GetDeviceNTSC(QString dev);
00082 static void SetDeviceInfo(QString dev, bool works, bool ntsc);
00083 static bool CheckDevice(void);
00084
00085 private:
00086 bool validvpts;
00087 bool gotvideo;
00088 bool gopset;
00089 bool needPlay;
00090 unsigned int mpeg_state;
00091
00092 int prevgoppos;
00093 int firstgoppos;
00094
00095 unsigned char *vidbuf;
00096 int vidread;
00097 int vidwrite;
00098 int vidfull;
00099 int vidframes;
00100 int frame_decoded;
00101 long long videoPlayed;
00102 long long lastStartFrame;
00103 long long laststartpos;
00104
00105 int nexttoqueue;
00106 int lastdequeued;
00107 ivtv_frame_list_t queuedlist;
00108
00109 bool needReset;
00110 MythTimer needResetTimer;
00111 MythTimer lastResetTime;
00112 private:
00113 static DevInfoMap devInfo;
00114 static QMutex devInfoLock;
00115 static const uint vidmax;
00116 };
00117
00118 #endif