#pragma once

#include "kpi_decoder.h"
#include "kpi_impl.h"
#include "musepack/libmpcdec/decoder.h"
#include "musepack/libmpcdec/internal.h"
#include "musepack/include/mpc/mpcdec.h"

class KbMpcDecoder : public KbKpiUnknownImpl<IKpiDecoder>
{
private:
    KPI_MEDIAINFO  m_MediaInfo;
    mpc_reader     m_reader;
    mpc_demux     *m_pDemux;
    MPC_SAMPLE_FORMAT m_sample_buffer[MPC_DECODER_BUFFER_LENGTH];
    mpc_uint32_t      m_sample_buffer_remain;
    mpc_uint32_t      m_sample_buffer_length;
    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;}
    KbMpcDecoder(void);
    ~KbMpcDecoder(void);

};
