#pragma once

extern "C"{
#include "neaacdec.h"
}
#include "kpi_decoder.h"
#include "kpi_impl.h"
//#include "kbmp4_decoder.h"

//MP4 コンテナに格納されていない AAC をデコードするクラス
class KbAacDecoder : public KbKpiUnknownImpl<IKpiDecoder>
{
private:
    IKpiFile *m_pFile;
    void     *m_hDecoder;
    unsigned long *m_seek_table;
    int      m_seek_table_length;
    BYTE     m_buffer[FAAD_MIN_STREAMSIZE*2];
    int      m_buffercount;
    BOOL     m_bDecodeDone;
    DWORD    m_dwRemainSample;
    BYTE    *m_pSample;
    KPI_MEDIAINFO m_MediaInfo;
    void __fastcall Close(void);
public:
    void __fastcall GetTagInfo(IKpiTagInfo *pTagInfo,
                               DWORD dwTagGetFlags){}
    BOOL  __fastcall Open(const KPI_MEDIAINFO *cpRequest,
                          IKpiFile   *pFile,
                          IKpiFolder *pFolder);
    DWORD  WINAPI Select(DWORD dwNumber,
                         const KPI_MEDIAINFO **ppMediaInfo,
                         IKpiTagInfo *pTagInfo,
                         DWORD dwTagGetFlags);
    UINT64 WINAPI Seek(UINT64 qwPosSample, DWORD dwFlag);
    DWORD  WINAPI Render(BYTE *pBuffer, DWORD dwSizeSample);
    DWORD  WINAPI UpdateConfig(void *pvReserved){return 0;}

    KbAacDecoder(void);
    ~KbAacDecoder(void);
};
