#ifndef ASFREADSTREAM_H
#define ASFREADSTREAM_H

#include <ReadHandlers.h>
#include <StreamInfo.h>
//#include <except.h>
#include <string>
#include <vector>
#include <list>
#include "Iterator.h"

class ASFReadHandler;

class ASFReadStream : public IMediaReadStream
{
friend class ASFReadHandler;
protected:
    ASFStreamHeader m_Header;
    ASFReadHandler* m_pParent;
    mutable StreamInfo m_StreamInfo;
    const ASFStreamSeekInfo* m_pSeekInfo;
    int m_iId;
    Unsigned m_uiPosition;
    Unsigned m_uiReadPosition;
    Iterator* m_pIterator;
    int m_iPointer;
    unsigned int m_uiSubpointer;
    unsigned int m_uiLastTimestamp;
    bool m_bIsAudio;
    
    bool m_bIsScrambled;
    std::vector<char> m_pcScrambleBuf;
    bool m_bValidBuf;
    int m_iScrOffset;
    const ASFAudioScrambleDef* m_pScrambleDef;
    ASFReadStream(ASFReadHandler* parent);
public:
    ASFReadStream() {}//for vector
    ASFReadStream(const ASFReadStream& c);
    ASFReadStream& operator=(const ASFReadStream& c);

    virtual ~ASFReadStream();

    virtual HRESULT GetHeader(void* pheader, size_t size) const;
    virtual bool IsKeyFrame(framepos_t lFrame = ERR) const;
    virtual HRESULT Read(size_t lSamples, void* lpBuffer, size_t cbBuffer,
    			 size_t* plBytes, size_t* plSamples);
    virtual HRESULT ReadInternal(size_t lSamples, void* lpBuffer, size_t cbBuffer,
    				 size_t* plBytes, size_t* plSamples);
    virtual HRESULT Seek(framepos_t lPos);
    virtual HRESULT SeekTime(double time);
    virtual HRESULT SeekToPrevKeyFrame();
    virtual HRESULT SkipFrame();
    virtual HRESULT SkipTo(double pos);
    virtual framepos_t GetPos() const;
    virtual framepos_t GetPrevKeyFrame(framepos_t lFrame = ERR) const;
    virtual framepos_t GetNextKeyFrame(framepos_t lFrame = ERR) const;
    virtual framepos_t GetNearestKeyFrame(framepos_t lFrame = ERR) const;
    virtual size_t GetLength() const;
    virtual double GetLengthTime() const;
    virtual StreamInfo* GetStreamInfo() const;
    virtual double GetSampleTime(framepos_t frame = ERR) const;
    virtual size_t GetSampleSize() const;
    virtual HRESULT GetFormatSize(size_t* plSize) const;
    virtual HRESULT GetFormat(void *pFormat, size_t* plSize) const;
    virtual void ClearCache();
    virtual double CacheSize() const;
    virtual fourcc_t GetFourCC() const;
};

#endif
