/******************************************************** Classes for reading AVIs Copyright 2000 Eugene Kuznetsov (divx@euro.ru) *********************************************************/ #include "config.h" #include #include #include #ifdef HAVE_MALLOC_H #include #else #include #endif #include #include #include #include "AVIReadHandler.h" #include "AVIReadHandler2.h" #include #include #include #include using namespace std; class AviReadStream : public IAviReadStream { friend class AviReadFile; protected: IvAVIReadStream* m_pIStream; AVIIndexEntry2* m_pTable; AVIStreamHeader m_header; Unsigned m_id; char* m_format; long m_format_size; Unsigned m_lockcount; Unsigned m_position; Unsigned m_ch_off;//chunk offset for streams with fixed sample size Unsigned m_sample;//for streams with fixed sample size: total number of samples sent Unsigned m_table_size; offset_t start_offset; int m_streaming; char* rem_buffer; int rem_size; int rem_limit; public: //AviReadStream-specific AviReadStream():rem_size(0), m_pTable(0), m_pIStream(0), m_sample(0), m_ch_off(0), m_position(0), m_format_size(0), m_streaming(0),rem_buffer(0){} HRESULT Init(Unsigned id, IvAVIReadStream* stream); //Generic ~AviReadStream(); StreamType GetType() const; const AVIStreamHeader& GetHeader() const {return m_header;} HRESULT GetVideoFormatInfo(void* bi) const; HRESULT GetAudioFormatInfo(void* bi, char** ext) const; //Size of stream and one frame Unsigned GetEndPos() const {return m_header.dwLength;} double GetEndTime() const; double GetFrameTime() const {return (double)m_header.dwScale / m_header.dwRate;} //Positioning in stream HRESULT Seek(Unsigned pos); Unsigned SeekToKeyframe(Unsigned pos){Seek(pos);return pos;} double GetTime() const; Unsigned GetPos() const; HRESULT GetFrameFlags(int* flags) const; //Reading decompressed data bool IsStreaming() const; IVideoDecoder* GetDecoder(); // HRESULT SetBitDepth(Unsigned depth); HRESULT SetDirection(bool d){return -1;} HRESULT SetOutputFormat(); HRESULT ReadFrame(); CImage* GetFrame(); int GetFrameSize(); HRESULT ReadFrames(void* buffer, Unsigned bufsize, Unsigned samples, Unsigned& samples_read, Unsigned& bytes_read); HRESULT ReadDirect(char* buffer, Unsigned bufsize, Unsigned samples, Unsigned& samples_read, Unsigned& bytes_read); Unsigned GetNextKeyFrame(int frame=-1) const; Unsigned GetPrevKeyFrame(int frame=-1) const; int ToNextKeyFrame(); int ToPrevKeyFrame(); HRESULT Eof() const; }; class AviReadStreamV : public AviReadStream { IVideoDecoder* videodecoder; int flip; public: AviReadStreamV():AviReadStream(),videodecoder(0),flip(0){} ~AviReadStreamV(){StopStreaming();} double SeekToTime(double time); Unsigned SeekToKeyframe(Unsigned pos); HRESULT GetVideoFormatInfo(void* bi) const; HRESULT StartStreaming(); HRESULT StopStreaming(); // HRESULT SetBitDepth(Unsigned depth); IVideoDecoder* GetDecoder(){return videodecoder;} HRESULT GetOutputFormat(void* format, Unsigned size); HRESULT ReadFrame(); HRESULT SetDirection(bool d) { flip=d; return 0; } int GetFrameSize(); HRESULT SetOutputFormat(); CImage* GetFrame(); // HRESULT ReadFrames(char* buffer, Unsigned bufsize, Unsigned samples, // Unsigned& samples_read, Unsigned& bytes_read); }; class AviReadStreamA : public AviReadStream { IAudioDecoder* audiodecoder; public: AviReadStreamA():AviReadStream(){} ~AviReadStreamA(){StopStreaming();} double SeekToTime(double time); HRESULT GetAudioFormatInfo(void* bi, char** ext) const; Unsigned GetPos() const; int GetFrameSize(); HRESULT StartStreaming(); HRESULT StopStreaming(); HRESULT GetOutputFormat(void* format, Unsigned size); HRESULT ReadFrames(void* buffer, Unsigned bufsize, Unsigned samples, Unsigned& samples_read, Unsigned& bytes_read); }; class AviReadFile: public IAviReadFile { private: MainAVIHeader m_header; IvAVIReadHandler* m_pIFile; // AviReadStream* m_streams; vector m_streams; int m_vcount; int m_acount; void _destruct(); public: // AviReadFile():m_pIFile(0), m_streams(0){} AviReadFile(const char* name); ~AviReadFile(); // HRESULT OpenFile(const char* name); Unsigned StreamCount(); Unsigned VideoStreamCount(); Unsigned AudioStreamCount(); IAviReadStream* GetStream(Unsigned stream_id, AviStream::StreamType type); HRESULT GetFileHeader(MainAVIHeader* header); // HRESULT CloseFile(); };