#ifndef AVIFILE_AVIMEDIAREADHANDLER_H
#define AVIFILE_AVIMEDIAREADHANDLER_H

#include "Cache.h"
#include <ReadHandlers.h>

class AviMediaReadStream;

class AviMediaReadHandler : public IMediaReadHandler
{
friend class AviMediaReadStream;
    std::vector<AviMediaReadStream> m_Streams;
    MainAVIHeader m_Header;
protected:
    InputStream m_Input;
public:
    AviMediaReadHandler(const char* pszFile) throw(FatalError);
    virtual ~AviMediaReadHandler();
    virtual HRESULT GetHeader(void* pheader, unsigned int size) const;
    virtual IMediaReadStream *GetStream(fourcc_t fccType, streamid_t lParam);
    virtual bool GetURLs(std::vector<std::string>& urls) const {return false;}
    virtual void Interrupt(){}
    /* avi files are opened synchronously */
    virtual bool IsOpened() const {return true;}
    virtual bool IsValid() const {return true;}
    virtual bool IsRedirector() const {return false;}
private:
    inline void checkDword(unsigned int value);
    int readMainHeader(unsigned int);
    int readStreamHeader();
//    void readStreams(int streams_size);
//    int readMovieChunk();
    int readIndexChunk(int index_chunk_size, int movie_chunk_offset);
    void reconstructIndexChunk(int offset);
};

#endif // AVIFILE_AVIMEDIAREADHANDLER_H
