#pragma once

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

class KbFpdDecoder : public KbKpiUnknownImpl<IKpiDecoder>
{
private:
    KPI_MEDIAINFO m_MediaInfo;
    IKpiFile   *m_pFile;
    IKpiFolder *m_pFolder;
    IKpiConfig *m_pConfig;
    unsigned  m_uThreadId;
    HANDLE  m_hThread;
    HANDLE  m_hEvent;
    FPDPLAY m_FpdPlay;
    char    m_szFileName[MAX_PATH*2];
    char    m_szTempFileName[MAX_PATH*2];
    void  __fastcall Terminate(void);
    IKpiFile **m_ppFpvFiles;
    int        m_nFpvFiles;
    HANDLE __fastcall OpenFpvFromSearcher(const wchar_t *cszFpv);
public:
    HANDLE __fastcall OpenFpvFile(const char *cszFileName);
    static unsigned WINAPI KbFpdThreadProc(LPVOID pParam);
    DWORD  __fastcall Open(const KPI_MEDIAINFO *cpRequest, IKpiFile *pFile, IKpiFolder *pFolder);
    void   __fastcall Close(void);
    DWORD  WINAPI Select(DWORD dwNumber,
                         const KPI_MEDIAINFO **ppMediaInfo,
                         IKpiTagInfo *pTagInfo,
                         DWORD dwTagGetFlags);
    DWORD  WINAPI Render(BYTE *pBuffer, DWORD dwSizeSample);
    UINT64 WINAPI Seek(UINT64 qwPosSample, DWORD dwFlag);
    DWORD  WINAPI UpdateConfig(void *pvReserved){return 0;}
    static void __fastcall Initialize(void);
    static void __fastcall Uninitialize(void);
    KbFpdDecoder(IKpiConfig *pConfig);
    ~KbFpdDecoder(void);
};
