#pragma once

#include "kpi_decoder.h"
#include "kpi_impl.h"

interface IPMDWIN;
class FMPMD_FileIO;

class KbPmdDecoder : public KbKpiUnknownImpl<IKpiDecoder>
{
private:
    KPI_MEDIAINFO m_MediaInfo;
    FMPMD_FileIO *m_pFileIO;
    IKpiFile     *m_pFile;
    IKpiFile    **m_ppPcmFiles;
    int           m_nPcmFiles;
    IKpiConfig   *m_pConfig;
    IPMDWIN      *m_pPmdWin;
    UINT64        m_qwCurrentSample;
    UINT64        m_qwLastSample;
    bool          m_bUpdateConfig; //設定が更新されたら true
    void  __fastcall GetPcmFiles(IKpiFile *pFile, IKpiFolder *pFolder);
    void  __fastcall ApplySettings(void);
    static BOOL __fastcall LoadPmdWin(IKpiConfig *pConfig);
public:
    KbPmdDecoder(IKpiConfig *pConfig);
    ~KbPmdDecoder(void);
    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);
    void __fastcall GetTagInfo(IKpiTagInfo *pTagInfo, DWORD dwTagGetFlags);
    static BOOL __fastcall Initialize(HINSTANCE hDll, IKpiConfig *pConfig, int *pnPmdWinVersion);
    static void __fastcall Uninitialize(void);
};
