#pragma once

#include "kpi_decoder.h"
#include "kpi_impl.h"
#include "opus/include/opus.h"
#include "opusfile/include/opusfile.h"

class KbOpusDecoder : public KbKpiUnknownImpl<IKpiDecoder>
{
private:
    enum{
        NCH = 2,
        SAMPLE_RATE = 48000,
        BLOCK_ALIGN = sizeof(float) * NCH,
        OPUS_BLOCKSIZE = 5760
    };
    KPI_MEDIAINFO  m_MediaInfo;
    OggOpusFile   *m_pOpusFile;
    IKpiFile      *m_pFile;
    BYTE           m_DecodedBuffer[OPUS_BLOCKSIZE*BLOCK_ALIGN];
    DWORD          m_dwPointer;//サンプル単位
    DWORD          m_dwRemain; //サンプル単位
    void  __fastcall GetTagInfo(IKpiTagInfo *pTagInfo, DWORD dwTagGetFlags);
public:
    DWORD __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;}
    KbOpusDecoder(void);
    ~KbOpusDecoder(void);
};
