mirror of
https://github.com/love2d/love-android.git
synced 2026-08-21 21:15:34 +02:00
added dependencies and build files (loosely inspired by Sebastian Dorda's love-native-android)
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
protected:
|
||||
|
||||
::FILE *m_pFile;
|
||||
|
||||
PBYTE m_pucMemData;
|
||||
DWORD m_dwLength;
|
||||
DWORD m_dwReadPos;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,139 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "libMPG123_d.lib")
|
||||
#else
|
||||
#pragma comment(lib, "libMPG123.lib")
|
||||
#endif
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "../DShowBase/streams.h"
|
||||
|
||||
#include <CORE/SourceFilter_AsyncIO.H>
|
||||
#include <CORE/SourceFilter_AsyncReader.H>
|
||||
|
||||
#include "../../libMPG123/MPG123.H"
|
||||
|
||||
#include <IIEP_FileIn.H>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
#define WAVE_HEADER_LENGTH 44
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
#define MP3_DECODE_LEN 0x4000
|
||||
|
||||
#define MP3_DECODE_BUF_LEN 0x8000
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace IIEP
|
||||
{
|
||||
class CMP3Stream : public CAsyncStream
|
||||
{
|
||||
public:
|
||||
|
||||
CMP3Stream(void);
|
||||
~CMP3Stream(void);
|
||||
|
||||
void SetSeekFlag(void);
|
||||
|
||||
bool Open(const WORD *pcwsFileName, CMediaType &coMT, DWORD dwKBPerSec = INFINITE);
|
||||
void Close(void);
|
||||
|
||||
HRESULT SetPointer(LONGLONG llPos);
|
||||
HRESULT Read(PBYTE pucBuffer,
|
||||
DWORD dwBytesToRead,
|
||||
BOOL bAlign,
|
||||
LPDWORD pdwBytesRead);
|
||||
|
||||
LONGLONG Size(LONGLONG *pSizeAvailable);
|
||||
|
||||
DWORD Alignment(void);
|
||||
|
||||
void Lock (void);
|
||||
void Unlock(void);
|
||||
|
||||
bool DecodeFrame(void);
|
||||
|
||||
//
|
||||
|
||||
bool OpenFile(const WORD *pcwsFileName);
|
||||
|
||||
DWORD ReadFile(PVOID pBuf , DWORD dwLen );
|
||||
long SeekFile(long nOffset, int iOrigin);
|
||||
|
||||
//
|
||||
|
||||
private:
|
||||
|
||||
CCritSec m_csLock;
|
||||
|
||||
DWORD m_dwKBPerSec;
|
||||
DWORD m_dwTimeStart;
|
||||
|
||||
mpg123_handle *m_pcoMH;
|
||||
|
||||
DWORD m_dwTotalBlocks;
|
||||
DWORD m_dwAlignment;
|
||||
|
||||
DWORD m_dwLength;
|
||||
DWORD m_dwPosition;
|
||||
|
||||
BYTE m_ucHeader[WAVE_HEADER_LENGTH];
|
||||
|
||||
//
|
||||
|
||||
DWORD m_dwDataBufPos;
|
||||
DWORD m_dwDataBufLen;
|
||||
BYTE m_ucDataBuffer[MP3_DECODE_BUF_LEN];
|
||||
|
||||
//
|
||||
|
||||
bool m_bSeekFlag;
|
||||
|
||||
//
|
||||
|
||||
IIEP::CFileIn m_coFileIn;
|
||||
long m_nDataBegin;
|
||||
long m_nDataTotal;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
|
||||
class CMP3Reader : public CAsyncReader
|
||||
{
|
||||
public:
|
||||
|
||||
// We're not going to be CoCreate'd so we don't need registration stuff etc
|
||||
|
||||
STDMETHODIMP Register(void)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP Unregister(void)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CMP3Reader(CMP3Stream *pcoStream,
|
||||
CMediaType *pcoMT,
|
||||
HRESULT *phr) :
|
||||
CAsyncReader(NAME("MP3 Reader\0"),
|
||||
NULL,
|
||||
pcoStream,
|
||||
phr)
|
||||
{
|
||||
m_coMT = *pcoMT;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,206 @@
|
||||
//
|
||||
// __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __
|
||||
// /_//_//_//_/\ /_//_//_//_/\ /_//_//_//_/\ /_//_//_//_/\
|
||||
// \_/_//_/\\_\/ \_/_//_/\\_\//_/\\_\\_\\_\//_/\\_\\_/_/\/
|
||||
// /_//_/\/ /_//_/\/ /_/\/ __ /_/\/ __ /_/\/
|
||||
// /_//_/\/ /_//_/\/ /_//_//_/\ /_//_//_//_/\/
|
||||
// /_//_/\/ /_//_/\/ /_/\\_\\_\/ /_/\\_\\_\\_\/
|
||||
// __ /_//_/\/ __ /_//_/\/ /_/\/ __ __ /_/\/
|
||||
// /_//_//_//_/\ /_//_//_//_/\ /_//_//_//_/\ /_/\/
|
||||
// \_\\_\\_\\_\/ \_\\_\\_\\_\/ \_\\_\\_\\_\/ \_\/
|
||||
//
|
||||
//
|
||||
// ..:: Interactive Internet Entertainment Platform ::..
|
||||
//
|
||||
// (C) 2000-2006, FAN YI PENG. ALL RIGHTS RESERVED
|
||||
//
|
||||
// ________________________________________________________________________________________________
|
||||
//
|
||||
/// @file IIEP_Def.H
|
||||
/// @brief 基本定义
|
||||
// ________________________________________________________________________________________________
|
||||
//
|
||||
//
|
||||
// _____________________________________
|
||||
// | |
|
||||
// | DATA |
|
||||
// _____________________________|_____________________________________|____________________________
|
||||
//
|
||||
// __________
|
||||
// __________________________________________| CONFIG |__________________________________________
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "IIEP_DBG.LIB")
|
||||
#else
|
||||
#pragma comment(lib, "IIEP.LIB")
|
||||
#endif
|
||||
|
||||
// ____________________________________________ CONFIG ____________________________________________
|
||||
//
|
||||
// __________
|
||||
// __________________________________________| DEFINE |__________________________________________
|
||||
//
|
||||
// _____________
|
||||
// ____/ Data Type \_____________________________________________________________________________
|
||||
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned long DWORD;
|
||||
typedef __int64 QWORD;
|
||||
|
||||
typedef BYTE *PBYTE;
|
||||
typedef WORD *PWORD;
|
||||
typedef DWORD *PDWORD;
|
||||
typedef QWORD *PQWORD;
|
||||
|
||||
typedef void *PVOID;
|
||||
|
||||
// ______ Data Type _______________________________________________________________________________
|
||||
//
|
||||
// ___________
|
||||
// ____/ Release \_______________________________________________________________________________
|
||||
|
||||
#define SAFE_DELETE(p) if (p) { delete (p); (p) = 0; }
|
||||
#define SAFE_DELETE_ARRAY(p) if (p) { delete[] (p); (p) = 0; }
|
||||
#define SAFE_RELEASE(p) if (p) { (p) -> Release(); (p) = 0; }
|
||||
|
||||
// ______ Release _________________________________________________________________________________
|
||||
//
|
||||
// __________
|
||||
// ____/ Assert \________________________________________________________________________________
|
||||
|
||||
#ifndef ASSERT
|
||||
#ifdef _DEBUG
|
||||
namespace IIEP { bool AssertFunction(bool, long, const char *, const char *); }
|
||||
#define ASSERT(expression) \
|
||||
if (IIEP::AssertFunction((bool) (expression), __LINE__, __FILE__, __FUNCTION__)) {_asm {int 3}}
|
||||
#else
|
||||
#define ASSERT(expression)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// ______ Assert __________________________________________________________________________________
|
||||
//
|
||||
// _______
|
||||
// ____/ LOG \___________________________________________________________________________________
|
||||
|
||||
namespace IIEP
|
||||
{
|
||||
void DebugLog(const char *pcszFormat, ...);
|
||||
void DebugLog(const WORD *pcwsFormat, ...);
|
||||
|
||||
void WriteLog(const char *pcszFormat, ...);
|
||||
void WriteLog(const WORD *pcwsFormat, ...);
|
||||
}
|
||||
|
||||
// ______ LOG _____________________________________________________________________________________
|
||||
//
|
||||
// ________
|
||||
// ____/ TODO \__________________________________________________________________________________
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define TODO \
|
||||
IIEP::DebugLog("\n[TODO] %d: \"%s\"- %s()\n~~~~~~\n", __LINE__, __FILE__, __FUNCTION__);
|
||||
#define ToDo(x) \
|
||||
IIEP::DebugLog("\n[TODO] %d: \"%s\"- %s(): %s\n~~~~~~\n", __LINE__, __FILE__, __FUNCTION__, (x));
|
||||
#else
|
||||
#define TODO
|
||||
#define ToDo(x)
|
||||
#endif
|
||||
|
||||
// ______ TODO ____________________________________________________________________________________
|
||||
//
|
||||
// ________
|
||||
// ____/ Path \__________________________________________________________________________________
|
||||
|
||||
namespace IIEP
|
||||
{
|
||||
void ResetToExePath(void);
|
||||
}
|
||||
|
||||
// ______ Path ____________________________________________________________________________________
|
||||
//
|
||||
// __________
|
||||
// ____/ CMutex \________________________________________________________________________________
|
||||
|
||||
namespace IIEP
|
||||
{
|
||||
class CMutex
|
||||
{
|
||||
public:
|
||||
|
||||
CMutex(void) { m_bLocked = false; }
|
||||
~CMutex(void) {}
|
||||
|
||||
void Lock(void);
|
||||
void Unlock(void) { m_bLocked = false; }
|
||||
void Set(void) { m_bLocked = true; }
|
||||
void Wait(void);
|
||||
|
||||
bool IsLock(void) const { return m_bLocked; }
|
||||
|
||||
private:
|
||||
|
||||
volatile bool m_bLocked;
|
||||
};
|
||||
}
|
||||
|
||||
// ______ CMutex __________________________________________________________________________________
|
||||
//
|
||||
// _________
|
||||
// ____/ SRect \_________________________________________________________________________________
|
||||
|
||||
namespace IIEP
|
||||
{
|
||||
/// @brief 矩形结构
|
||||
|
||||
struct SRect
|
||||
{
|
||||
SRect(void) {}
|
||||
|
||||
SRect(long nX, long nY, long nWidth, long nHeight)
|
||||
{
|
||||
m_nX = nX;
|
||||
m_nY = nY;
|
||||
m_nWidth = nWidth;
|
||||
m_nHeight = nHeight;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
|
||||
void Set(long nX, long nY, long nWidth, long nHeight)
|
||||
{
|
||||
m_nX = nX;
|
||||
m_nY = nY;
|
||||
m_nWidth = nWidth;
|
||||
m_nHeight = nHeight;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
|
||||
long m_nX; ///< 矩形左上角 X 轴坐标
|
||||
long m_nY; ///< 矩形左上角 Y 轴坐标
|
||||
long m_nWidth; ///< 矩形宽度
|
||||
long m_nHeight; ///< 矩形高度
|
||||
};
|
||||
}
|
||||
|
||||
// ______ SRect ___________________________________________________________________________________
|
||||
//
|
||||
// ___________________________
|
||||
// ____/ Sample Grabber CallBack \_______________________________________________________________
|
||||
|
||||
namespace IIEP
|
||||
{
|
||||
typedef void (*CALLBACK_SampleGrabberBuffer) (PVOID, DWORD);
|
||||
}
|
||||
|
||||
// ______ Sample Grabber CallBack _________________________________________________________________
|
||||
//
|
||||
// ____________________________________________ DEFINE ____________________________________________
|
||||
//
|
||||
// ____________________________________________________________________________________ DATA ______
|
||||
//
|
||||
// ___________________________________________ FILE END ___________________________________________
|
||||
@@ -0,0 +1,167 @@
|
||||
//
|
||||
// __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __
|
||||
// /_//_//_//_/\ /_//_//_//_/\ /_//_//_//_/\ /_//_//_//_/\
|
||||
// \_/_//_/\\_\/ \_/_//_/\\_\//_/\\_\\_\\_\//_/\\_\\_/_/\/
|
||||
// /_//_/\/ /_//_/\/ /_/\/ __ /_/\/ __ /_/\/
|
||||
// /_//_/\/ /_//_/\/ /_//_//_/\ /_//_//_//_/\/
|
||||
// /_//_/\/ /_//_/\/ /_/\\_\\_\/ /_/\\_\\_\\_\/
|
||||
// __ /_//_/\/ __ /_//_/\/ /_/\/ __ __ /_/\/
|
||||
// /_//_//_//_/\ /_//_//_//_/\ /_//_//_//_/\ /_/\/
|
||||
// \_\\_\\_\\_\/ \_\\_\\_\\_\/ \_\\_\\_\\_\/ \_\/
|
||||
//
|
||||
//
|
||||
// ..:: Interactive Internet Entertainment Platform ::..
|
||||
//
|
||||
// (C) 2000-2005, FAN YI PENG. ALL RIGHTS RESERVED
|
||||
//
|
||||
// ________________________________________________________________________________________________
|
||||
//
|
||||
/// @file IIEP_FileIn.H
|
||||
/// @brief 文件输入接口类
|
||||
// ________________________________________________________________________________________________
|
||||
//
|
||||
//
|
||||
// _____________________________________
|
||||
// | |
|
||||
// | DATA |
|
||||
// _____________________________|_____________________________________|____________________________
|
||||
//
|
||||
// __________
|
||||
// __________________________________________| CONFIG |__________________________________________
|
||||
|
||||
#pragma once
|
||||
|
||||
// ____________________________________________ CONFIG ____________________________________________
|
||||
//
|
||||
// __________
|
||||
// __________________________________________| HEADER |__________________________________________
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include <IIEP_Def.H>
|
||||
|
||||
// ____________________________________________ HEADER ____________________________________________
|
||||
//
|
||||
// __________
|
||||
// __________________________________________| DEFINE |__________________________________________
|
||||
//
|
||||
// ___________
|
||||
// ____/ CFileIn \_______________________________________________________________________________
|
||||
|
||||
namespace IIEP
|
||||
{
|
||||
/// @brief 文件输入接口类
|
||||
|
||||
class CFileIn
|
||||
{
|
||||
public:
|
||||
|
||||
CFileIn(void);
|
||||
~CFileIn(void);
|
||||
|
||||
bool Open(const char *pcszFileName);
|
||||
bool Open(const WORD *pcwsFileName);
|
||||
|
||||
void Close(void);
|
||||
|
||||
DWORD GetFileSize(void) const;
|
||||
DWORD GetReadPosition(void) const;
|
||||
|
||||
bool Seek(long nOffset, long nOrigin = 0); // SEEK_SET = 0 SEEK_CUR = 1 SEEK_END = 2
|
||||
|
||||
bool Skip(long nOffset) { return Seek(nOffset, 1); }
|
||||
|
||||
DWORD Read(PVOID pDataBuffer, DWORD dwReadSize);
|
||||
|
||||
bool ReadB(BYTE &ucData)
|
||||
{
|
||||
return (1 == Read(&ucData, 1));
|
||||
}
|
||||
|
||||
bool ReadW(WORD &wData)
|
||||
{
|
||||
return (2 == Read(&wData, 2));
|
||||
}
|
||||
|
||||
bool ReadDW(DWORD &dwData)
|
||||
{
|
||||
return (4 == Read(&dwData, 4));
|
||||
}
|
||||
|
||||
bool ReadInverseW(WORD &wData)
|
||||
{
|
||||
if (2 == Read(&wData, 2))
|
||||
{
|
||||
_asm
|
||||
{
|
||||
MOV ECX, wData
|
||||
MOV AX, [ECX]
|
||||
XCHG AH, AL
|
||||
MOV [ECX], AX
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ReadInverseDW(DWORD &dwData)
|
||||
{
|
||||
if (4 == Read(&dwData, 4))
|
||||
{
|
||||
_asm
|
||||
{
|
||||
MOV ECX, dwData
|
||||
MOV EAX, [ECX]
|
||||
BSWAP EAX
|
||||
MOV [ECX], EAX
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
bool ReadAnsiLine(std::string &strLine);
|
||||
bool ReadUnicodeLine(std::wstring &wstrLine, bool bBigEndian);
|
||||
|
||||
bool ReadAnsiString (char *pszBuffer, DWORD dwBufferLength);
|
||||
bool ReadUnicodeString(WORD *pwzBuffer, DWORD dwBufferLength);
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
CFileIn(const CFileIn &); // forbidden
|
||||
CFileIn & operator = (const CFileIn &); // forbidden
|
||||
|
||||
#include <CORE/CORE_FileIn.H>
|
||||
};
|
||||
}
|
||||
|
||||
// ______ CFileIn _________________________________________________________________________________
|
||||
//
|
||||
// _______________
|
||||
// ____/ Memory File \___________________________________________________________________________
|
||||
|
||||
namespace IIEP
|
||||
{
|
||||
bool CreateMemoryFile(PVOID pMemory, DWORD dwLength, const char *pcszFileName);
|
||||
bool CreateMemoryFile(PVOID pMemory, DWORD dwLength, const WORD *pcwsFileName);
|
||||
bool RemoveMemoryFile(const char *pcszFileName);
|
||||
bool RemoveMemoryFile(const WORD *pcwsFileName);
|
||||
void RemoveMemoryFile(void);
|
||||
}
|
||||
|
||||
// ______ Memory File _____________________________________________________________________________
|
||||
//
|
||||
// ____________________________________________ DEFINE ____________________________________________
|
||||
//
|
||||
// ____________________________________________________________________________________ DATA ______
|
||||
//
|
||||
// ___________________________________________ FILE END ___________________________________________
|
||||
@@ -0,0 +1,4 @@
|
||||
This is a MS Visual C++ project plus wrapper class for libmpg123, contributed by "Gates Fan" <gatesfan@gmail.com>.
|
||||
You need to copy the stuff from mgp123-x.y.z/src/libmpg123 to the libMPG123 directory and also ensure that you produce a valid mpg123.h from the mpg123.h.in (replace the @BLABLA@ with the appropriate #includes).
|
||||
|
||||
Thomas.
|
||||
@@ -0,0 +1,462 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <IIEP_FileIn.H>
|
||||
#include <IIEP_Hash.H>
|
||||
#include <IIEP_String.H>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
struct MEM_FILE_IDX
|
||||
{
|
||||
MEM_FILE_IDX(void)
|
||||
{
|
||||
m_dwID = 0;
|
||||
m_dwLength = 0;
|
||||
m_pucData = 0;
|
||||
}
|
||||
|
||||
DWORD m_dwID; // hash ID of filename
|
||||
DWORD m_dwLength; // file length
|
||||
PBYTE m_pucData; // memory pointer
|
||||
};
|
||||
|
||||
static std::vector <MEM_FILE_IDX> s_vecMemFile;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: SearchMemFile()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
static std::vector <MEM_FILE_IDX> :: iterator SearchMemFile(PCWSTR pcwsFileName)
|
||||
{
|
||||
DWORD dwID = IIEP::HashFNV_1a(pcwsFileName);
|
||||
|
||||
std::vector <MEM_FILE_IDX>::iterator it;
|
||||
|
||||
for (it = s_vecMemFile.begin(); it < s_vecMemFile.end(); it ++)
|
||||
{
|
||||
if (it -> m_dwID == dwID) return it;
|
||||
}
|
||||
|
||||
return s_vecMemFile.end();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
static std::vector <MEM_FILE_IDX> :: iterator SearchMemFile(const char *pcszFileName)
|
||||
{
|
||||
WORD wzNameBuffer[0x1000];
|
||||
|
||||
wzNameBuffer[0] = 0;
|
||||
|
||||
IIEP::StringFromANSI(pcszFileName, wzNameBuffer, 0x1000);
|
||||
|
||||
return SearchMemFile(wzNameBuffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: CreateMemoryFile()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::CreateMemoryFile(PVOID pMemory, DWORD dwLength, PCWSTR pcwsFileName)
|
||||
{
|
||||
if (0 == pcwsFileName || 0 == *pcwsFileName) return false;
|
||||
|
||||
RemoveMemoryFile(pcwsFileName);
|
||||
|
||||
DWORD dwID = IIEP::HashFNV_1a(pcwsFileName);
|
||||
|
||||
MEM_FILE_IDX soIDX;
|
||||
|
||||
soIDX.m_dwID = dwID;
|
||||
soIDX.m_dwLength = dwLength;
|
||||
soIDX.m_pucData = (PBYTE) pMemory;
|
||||
|
||||
s_vecMemFile.push_back(soIDX);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::CreateMemoryFile(PVOID pMemory, DWORD dwLength, const char *pcszFileName)
|
||||
{
|
||||
WORD wzNameBuffer[0x1000];
|
||||
|
||||
wzNameBuffer[0] = 0;
|
||||
|
||||
StringFromANSI(pcszFileName, wzNameBuffer, 0x1000);
|
||||
|
||||
return CreateMemoryFile(pMemory, dwLength, wzNameBuffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: RemoveMemoryFile()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::RemoveMemoryFile(PCWSTR pcwsFileName)
|
||||
{
|
||||
if (0 == pcwsFileName || 0 == *pcwsFileName) return false;
|
||||
|
||||
std::vector <MEM_FILE_IDX>::iterator it = SearchMemFile(pcwsFileName);
|
||||
|
||||
if (it == s_vecMemFile.end()) return false;
|
||||
|
||||
s_vecMemFile.erase(it);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::RemoveMemoryFile(const char *pcszFileName)
|
||||
{
|
||||
WORD wzNameBuffer[0x1000];
|
||||
|
||||
wzNameBuffer[0] = 0;
|
||||
|
||||
StringFromANSI(pcszFileName, wzNameBuffer, 0x1000);
|
||||
|
||||
return RemoveMemoryFile(wzNameBuffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void IIEP::RemoveMemoryFile(void)
|
||||
{
|
||||
s_vecMemFile.clear();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: CFileIn()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
IIEP::CFileIn::CFileIn(void)
|
||||
{
|
||||
m_pFile = 0;
|
||||
m_pucMemData = 0;
|
||||
m_dwLength = 0;
|
||||
m_dwReadPos = 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: ~CFileIn()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
IIEP::CFileIn::~CFileIn(void)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Open()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::CFileIn::Open(const char *pcszFileName)
|
||||
{
|
||||
WORD wzNameBuffer[0x1000];
|
||||
|
||||
wzNameBuffer[0] = 0;
|
||||
|
||||
StringFromANSI(pcszFileName, wzNameBuffer, 0x1000);
|
||||
|
||||
return Open(wzNameBuffer);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::CFileIn::Open(const WORD *pcwsFileName)
|
||||
{
|
||||
Close();
|
||||
|
||||
if (0 == pcwsFileName || 0 == *pcwsFileName) return false;
|
||||
|
||||
std::vector <MEM_FILE_IDX>::iterator it = SearchMemFile(pcwsFileName);
|
||||
|
||||
if (it == s_vecMemFile.end()) // not found in memory
|
||||
{
|
||||
m_pFile = _wfopen(pcwsFileName, L"rb");
|
||||
|
||||
if (m_pFile)
|
||||
{
|
||||
return true; // found DOS file
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (s_vecMemFile.empty()) return false;
|
||||
|
||||
m_pucMemData = it -> m_pucData;
|
||||
m_dwLength = it -> m_dwLength;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Close()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void IIEP::CFileIn::Close(void)
|
||||
{
|
||||
if (m_pFile)
|
||||
{
|
||||
fclose(m_pFile);
|
||||
|
||||
m_pFile = 0;
|
||||
}
|
||||
|
||||
m_pucMemData = 0;
|
||||
m_dwLength = 0;
|
||||
m_dwReadPos = 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: GetFileSize()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
DWORD IIEP::CFileIn::GetFileSize(void) const
|
||||
{
|
||||
if (m_pFile)
|
||||
{
|
||||
DWORD dwPostion = ftell(m_pFile);
|
||||
|
||||
fseek(m_pFile, 0, SEEK_END);
|
||||
|
||||
DWORD dwFileSize = ftell(m_pFile);
|
||||
|
||||
fseek(m_pFile, dwPostion, SEEK_SET);
|
||||
|
||||
return dwFileSize;
|
||||
}
|
||||
|
||||
return m_dwLength;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: GetReadPosition()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
DWORD IIEP::CFileIn::GetReadPosition(void) const
|
||||
{
|
||||
if (m_pFile)
|
||||
{
|
||||
return ftell(m_pFile);
|
||||
}
|
||||
|
||||
return m_dwReadPos;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Seek()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::CFileIn::Seek(long nOffset, long nOrigin)
|
||||
{
|
||||
if (m_pFile)
|
||||
{
|
||||
return (0 == fseek(m_pFile, nOffset, nOrigin));
|
||||
}
|
||||
|
||||
if (m_pucMemData)
|
||||
{
|
||||
switch (nOrigin)
|
||||
{
|
||||
case SEEK_SET:
|
||||
if (nOffset < 0 || nOffset >= (long) m_dwLength) return false;
|
||||
m_dwReadPos = nOffset;
|
||||
return true;
|
||||
|
||||
case SEEK_CUR:
|
||||
nOffset += m_dwReadPos;
|
||||
if (nOffset < 0 || nOffset >= (long) m_dwLength) return false;
|
||||
m_dwReadPos = nOffset;
|
||||
return true;
|
||||
|
||||
case SEEK_END:
|
||||
ASSERT(nOffset <= 0); // Õâ¸ö±ØÐëÊǸºÊý
|
||||
nOffset = m_dwLength - 1 + nOffset;
|
||||
if (nOffset < 0 || nOffset >= (long) m_dwLength) return false;
|
||||
m_dwReadPos = nOffset;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Read()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
DWORD IIEP::CFileIn::Read(PVOID pDataBuffer, DWORD dwReadSize)
|
||||
{
|
||||
if (m_pFile)
|
||||
{
|
||||
return (DWORD) fread(pDataBuffer, 1, dwReadSize, m_pFile);
|
||||
}
|
||||
|
||||
if (m_pucMemData)
|
||||
{
|
||||
if (m_dwReadPos + dwReadSize > m_dwLength) dwReadSize = m_dwLength - m_dwReadPos;
|
||||
|
||||
memcpy(pDataBuffer, m_pucMemData + m_dwReadPos, dwReadSize);
|
||||
|
||||
m_dwReadPos += dwReadSize;
|
||||
|
||||
return dwReadSize;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: ReadAnsiLine()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::CFileIn::ReadAnsiLine(std::string &strLine)
|
||||
{
|
||||
BYTE ucChar = 0;
|
||||
|
||||
strLine.clear();
|
||||
|
||||
while (ReadB(ucChar))
|
||||
{
|
||||
if (0x0D == ucChar)
|
||||
{
|
||||
}
|
||||
else
|
||||
if (0x0A == ucChar)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
strLine.push_back(ucChar);
|
||||
}
|
||||
}
|
||||
|
||||
if (strLine.empty()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: ReadUnicodeLine()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::CFileIn::ReadUnicodeLine(std::wstring &wstrLine, bool bBigEndian)
|
||||
{
|
||||
WORD wChar = 0;
|
||||
|
||||
wstrLine.clear();
|
||||
|
||||
while (bBigEndian ? ReadInverseW(wChar) : ReadW(wChar))
|
||||
{
|
||||
if (0x000D == wChar)
|
||||
{
|
||||
}
|
||||
else
|
||||
if (0x000A == wChar)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
wstrLine.push_back(wChar);
|
||||
}
|
||||
}
|
||||
|
||||
if (wstrLine.empty()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: ReadAnsiString()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::CFileIn::ReadAnsiString(char *pszBuffer, DWORD dwBufferLength)
|
||||
{
|
||||
DWORD dwIndex = 0;
|
||||
BYTE ucChar;
|
||||
|
||||
while (ReadB(ucChar))
|
||||
{
|
||||
if (dwIndex >= dwBufferLength) return true;
|
||||
|
||||
pszBuffer[dwIndex ++] = ucChar;
|
||||
|
||||
if (0 == ucChar)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: ReadUnicodeString()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::CFileIn::ReadUnicodeString(WORD *pwzBuffer, DWORD dwBufferLength)
|
||||
{
|
||||
DWORD dwIndex = 0;
|
||||
WORD wChar;
|
||||
|
||||
ReadInverseW(wChar);
|
||||
|
||||
if (wChar == 0xFFFE) // Unicode
|
||||
{
|
||||
while (ReadW(wChar))
|
||||
{
|
||||
if (dwIndex >= dwBufferLength) return true;
|
||||
|
||||
pwzBuffer[dwIndex ++] = wChar;
|
||||
|
||||
if (0 == wChar)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (wChar == 0xFEFF) // Unicode big endian
|
||||
{
|
||||
while (ReadInverseW(wChar))
|
||||
{
|
||||
if (dwIndex >= dwBufferLength) return true;
|
||||
|
||||
pwzBuffer[dwIndex ++] = wChar;
|
||||
|
||||
if (0 == wChar)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,122 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <IIEP_Def.H>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
static bool s_bLogFileOpened = false;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: DebugLog()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void IIEP::DebugLog(const char *pcszFormat, ...)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
char cBuffer[0x8000];
|
||||
|
||||
va_list pcArg;
|
||||
|
||||
va_start(pcArg, pcszFormat);
|
||||
_vsnprintf(cBuffer, 0x8000, pcszFormat, pcArg);
|
||||
va_end(pcArg);
|
||||
|
||||
::OutputDebugStringA(cBuffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void IIEP::DebugLog(const WORD *pcwsFormat, ...)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
WCHAR wcBuffer[0x8000];
|
||||
|
||||
va_list pcArg;
|
||||
|
||||
va_start(pcArg, pcwsFormat);
|
||||
_vsnwprintf(wcBuffer, 0x8000, pcwsFormat, pcArg);
|
||||
va_end(pcArg);
|
||||
|
||||
::OutputDebugStringW(wcBuffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: WriteLog()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void IIEP::WriteLog(const char *pcszFormat, ...)
|
||||
{
|
||||
char cBuffer[0x8000];
|
||||
|
||||
va_list pcArg;
|
||||
|
||||
va_start(pcArg, pcszFormat);
|
||||
_vsnprintf(cBuffer, 0x8000, pcszFormat, pcArg);
|
||||
va_end(pcArg);
|
||||
|
||||
FILE *phFile;
|
||||
|
||||
#define LOG_FILE "C:\\IIEP.LOG"
|
||||
|
||||
if (s_bLogFileOpened)
|
||||
{
|
||||
phFile = fopen(LOG_FILE, "a+");
|
||||
}
|
||||
else
|
||||
{
|
||||
phFile = fopen(LOG_FILE, "w");
|
||||
|
||||
s_bLogFileOpened = true;
|
||||
}
|
||||
|
||||
if (phFile)
|
||||
{
|
||||
fprintf(phFile, cBuffer);
|
||||
fclose(phFile);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void IIEP::WriteLog(const WORD *pcwsFormat, ...)
|
||||
{
|
||||
WCHAR wcBuffer[0x8000];
|
||||
|
||||
va_list pcArg;
|
||||
|
||||
va_start(pcArg, pcwsFormat);
|
||||
_vsnwprintf(wcBuffer, 0x8000, pcwsFormat, pcArg);
|
||||
va_end(pcArg);
|
||||
|
||||
FILE *phFile;
|
||||
|
||||
#define LOG_FILE "C:\\IIEP.LOG"
|
||||
|
||||
if (s_bLogFileOpened)
|
||||
{
|
||||
phFile = fopen(LOG_FILE, "a");
|
||||
}
|
||||
else
|
||||
{
|
||||
phFile = fopen(LOG_FILE, "w");
|
||||
|
||||
s_bLogFileOpened = true;
|
||||
}
|
||||
|
||||
if (phFile)
|
||||
{
|
||||
fwprintf(phFile, wcBuffer);
|
||||
fclose(phFile);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,35 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <IIEP_Def.H>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Lock()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void IIEP::CMutex::Lock(void)
|
||||
{
|
||||
while (m_bLocked)
|
||||
{
|
||||
::Sleep(1);
|
||||
}
|
||||
|
||||
m_bLocked = true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Wait()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void IIEP::CMutex::Wait(void)
|
||||
{
|
||||
while (m_bLocked)
|
||||
{
|
||||
::Sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,586 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
#include <IIEP_Def.H>
|
||||
|
||||
#include <CORE/SourceFilter_MP3.H>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
extern BYTE g_ucWaveHeader[WAVE_HEADER_LENGTH];
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: CMP3Stream()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
static size_t read_sub(int fd, void *pBuf, size_t nSize)
|
||||
{
|
||||
if (fd)
|
||||
{
|
||||
IIEP::CMP3Stream *pcoStream = (IIEP::CMP3Stream *) fd;
|
||||
|
||||
return pcoStream -> ReadFile(pBuf, nSize);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: CMP3Stream()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
static off_t seek_sub(int fd, off_t nOffset, int iOrigin)
|
||||
{
|
||||
if (fd)
|
||||
{
|
||||
IIEP::CMP3Stream *pcoStream = (IIEP::CMP3Stream *) fd;
|
||||
|
||||
return pcoStream -> SeekFile(nOffset, iOrigin);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: CMP3Stream()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
IIEP::CMP3Stream::CMP3Stream(void)
|
||||
{
|
||||
m_dwKBPerSec = INFINITE;
|
||||
m_dwTimeStart = 0;
|
||||
|
||||
m_pcoMH = 0;
|
||||
|
||||
m_dwTotalBlocks = 0;
|
||||
m_dwAlignment = 4;
|
||||
|
||||
m_dwLength = 0;
|
||||
m_dwPosition = 0;
|
||||
|
||||
memcpy(m_ucHeader, g_ucWaveHeader, WAVE_HEADER_LENGTH);
|
||||
|
||||
m_dwDataBufPos = 0;
|
||||
m_dwDataBufLen = 0;
|
||||
|
||||
m_bSeekFlag = false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: ~CMP3Stream()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
IIEP::CMP3Stream::~CMP3Stream(void)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: SetSeekFlag()
|
||||
// desc: called by IIEP::CPlayer::SetMediaPosition(QWORD qwPosition)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void IIEP::CMP3Stream::SetSeekFlag(void)
|
||||
{
|
||||
m_bSeekFlag = true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Open()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::CMP3Stream::Open(const WORD *pcwsFileName, CMediaType &coMT, DWORD dwKBPerSec)
|
||||
{
|
||||
Close();
|
||||
|
||||
//
|
||||
|
||||
if (MPG123_OK != mpg123_init())
|
||||
{
|
||||
goto OPEN_FAIL;
|
||||
}
|
||||
|
||||
m_pcoMH = mpg123_new(NULL, NULL);
|
||||
|
||||
if (0 == m_pcoMH)
|
||||
{
|
||||
goto OPEN_FAIL;
|
||||
}
|
||||
|
||||
if (false == OpenFile(pcwsFileName))
|
||||
{
|
||||
goto OPEN_FAIL;
|
||||
}
|
||||
|
||||
if (MPG123_OK != mpg123_replace_reader(m_pcoMH, read_sub, seek_sub))
|
||||
{
|
||||
goto OPEN_FAIL;
|
||||
}
|
||||
|
||||
if (MPG123_OK != mpg123_open_fd(m_pcoMH, (int) this))
|
||||
{
|
||||
goto OPEN_FAIL;
|
||||
}
|
||||
|
||||
long nRate;
|
||||
int iChannels;
|
||||
int iEncoding;
|
||||
|
||||
if (MPG123_OK != mpg123_getformat(m_pcoMH, &nRate, &iChannels, &iEncoding))
|
||||
{
|
||||
goto OPEN_FAIL;
|
||||
}
|
||||
|
||||
// Ensure that this output format will not change (it could, when we allow it)
|
||||
|
||||
mpg123_format_none(m_pcoMH);
|
||||
mpg123_format(m_pcoMH, nRate, iChannels, iEncoding);
|
||||
|
||||
// scan & get total samples
|
||||
|
||||
mpg123_scan(m_pcoMH);
|
||||
|
||||
off_t nOff = mpg123_length(m_pcoMH);
|
||||
|
||||
if (nOff < 0)
|
||||
{
|
||||
goto OPEN_FAIL;
|
||||
}
|
||||
|
||||
m_dwTotalBlocks = (DWORD) nOff;
|
||||
|
||||
// set other format
|
||||
|
||||
m_dwAlignment = iChannels * 2;
|
||||
|
||||
if (0 == m_dwAlignment)
|
||||
{
|
||||
m_dwAlignment = 4;
|
||||
}
|
||||
|
||||
m_dwLength = m_dwTotalBlocks * m_dwAlignment + WAVE_HEADER_LENGTH;
|
||||
|
||||
WORD wChannels = (WORD ) iChannels;
|
||||
DWORD dwSamplesPerSec = (DWORD) nRate;
|
||||
DWORD dwAvgBytesPerSec = m_dwAlignment * dwSamplesPerSec;
|
||||
WORD wBlockAlign = (WORD ) m_dwAlignment;
|
||||
WORD wBitsPerSample = 16;
|
||||
|
||||
PWORD pwData;
|
||||
PDWORD pdwData;
|
||||
|
||||
pdwData = (PDWORD) &m_ucHeader[0x04];
|
||||
*pdwData = m_dwTotalBlocks * m_dwAlignment + WAVE_HEADER_LENGTH - 8;
|
||||
|
||||
pwData = (PWORD) &m_ucHeader[0x16];
|
||||
*pwData = wChannels;
|
||||
|
||||
pdwData = (PDWORD) &m_ucHeader[0x18];
|
||||
*pdwData = dwSamplesPerSec;
|
||||
|
||||
pdwData = (PDWORD) &m_ucHeader[0x1C];
|
||||
*pdwData = dwAvgBytesPerSec;
|
||||
|
||||
pwData = (PWORD) &m_ucHeader[0x20];
|
||||
*pwData = wBlockAlign;
|
||||
|
||||
pwData = (PWORD) &m_ucHeader[0x22];
|
||||
*pwData = wBitsPerSample;
|
||||
|
||||
pdwData = (PDWORD) &m_ucHeader[0x28];
|
||||
*pdwData = m_dwTotalBlocks * m_dwAlignment;
|
||||
|
||||
coMT.majortype = MEDIATYPE_Stream;
|
||||
coMT.subtype = MEDIASUBTYPE_WAVE;
|
||||
|
||||
SetPointer(0);
|
||||
|
||||
m_dwTimeStart = ::timeGetTime();
|
||||
|
||||
return true;
|
||||
|
||||
OPEN_FAIL:
|
||||
|
||||
Close();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Close()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void IIEP::CMP3Stream::Close(void)
|
||||
{
|
||||
m_coFileIn.Close();
|
||||
|
||||
if (m_pcoMH)
|
||||
{
|
||||
mpg123_close (m_pcoMH);
|
||||
mpg123_delete(m_pcoMH);
|
||||
|
||||
m_pcoMH = 0;
|
||||
}
|
||||
|
||||
mpg123_exit();
|
||||
|
||||
m_dwTimeStart = 0;
|
||||
m_dwTotalBlocks = 0;
|
||||
|
||||
m_dwLength = 0;
|
||||
m_dwPosition = 0;
|
||||
|
||||
m_bSeekFlag = false;
|
||||
|
||||
m_nDataBegin = 0;
|
||||
m_nDataTotal = 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: SetPointer()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
HRESULT IIEP::CMP3Stream::SetPointer(LONGLONG llPos)
|
||||
{
|
||||
if (llPos < 0 || llPos > (LONGLONG) m_dwLength)
|
||||
{
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
m_dwPosition = (DWORD) llPos;
|
||||
|
||||
if (llPos < WAVE_HEADER_LENGTH)
|
||||
{
|
||||
mpg123_seek(m_pcoMH, 0, SEEK_SET);
|
||||
|
||||
m_dwDataBufLen = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_bSeekFlag && m_dwAlignment > 0)
|
||||
{
|
||||
m_bSeekFlag = false;
|
||||
|
||||
mpg123_seek(m_pcoMH, (long) (m_dwPosition - WAVE_HEADER_LENGTH) / m_dwAlignment, SEEK_SET);
|
||||
|
||||
m_dwDataBufLen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Read()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
HRESULT IIEP::CMP3Stream::Read(PBYTE pucBuffer,
|
||||
DWORD dwBytesToRead,
|
||||
BOOL bAlign,
|
||||
LPDWORD pdwBytesRead)
|
||||
{
|
||||
if (0 == m_pcoMH) return S_FALSE;
|
||||
|
||||
CAutoLock lck(&m_csLock);
|
||||
|
||||
DWORD dwReadLength;
|
||||
|
||||
// wait until the bytes are here
|
||||
|
||||
DWORD dwTime = ::timeGetTime();
|
||||
|
||||
if (m_dwPosition + dwBytesToRead > m_dwLength)
|
||||
{
|
||||
dwReadLength = m_dwLength - m_dwPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
dwReadLength = dwBytesToRead;
|
||||
}
|
||||
|
||||
DWORD dwTimeToArrive = (m_dwPosition + dwReadLength) / m_dwKBPerSec;
|
||||
|
||||
if (dwTime - m_dwTimeStart < dwTimeToArrive)
|
||||
{
|
||||
::Sleep(dwTimeToArrive - dwTime + m_dwTimeStart);
|
||||
}
|
||||
|
||||
// read data
|
||||
|
||||
DWORD dwRead = 0;
|
||||
|
||||
if (m_dwPosition < WAVE_HEADER_LENGTH)
|
||||
{
|
||||
DWORD dwPatchLen = WAVE_HEADER_LENGTH - m_dwPosition;
|
||||
|
||||
if (dwReadLength < dwPatchLen)
|
||||
{
|
||||
dwPatchLen = dwReadLength;
|
||||
}
|
||||
|
||||
memcpy(pucBuffer, m_ucHeader + m_dwPosition, dwPatchLen);
|
||||
|
||||
m_dwPosition += dwPatchLen;
|
||||
dwReadLength -= dwPatchLen;
|
||||
|
||||
pucBuffer += dwPatchLen;
|
||||
dwRead += dwPatchLen;
|
||||
}
|
||||
|
||||
if (dwReadLength > 0)
|
||||
{
|
||||
while (m_dwDataBufLen < dwReadLength)
|
||||
{
|
||||
if (m_dwDataBufLen > 0)
|
||||
{
|
||||
memcpy(pucBuffer, m_ucDataBuffer + m_dwDataBufPos, m_dwDataBufLen);
|
||||
|
||||
dwRead += m_dwDataBufLen;
|
||||
|
||||
dwReadLength -= m_dwDataBufLen;
|
||||
|
||||
pucBuffer += m_dwDataBufLen;
|
||||
m_dwDataBufPos += m_dwDataBufLen;
|
||||
m_dwDataBufLen = 0;
|
||||
}
|
||||
|
||||
if (DecodeFrame() == false) break;
|
||||
}
|
||||
|
||||
if (dwReadLength > 0)
|
||||
{
|
||||
if (m_dwDataBufLen >= dwReadLength)
|
||||
{
|
||||
memcpy(pucBuffer, m_ucDataBuffer + m_dwDataBufPos, dwReadLength);
|
||||
|
||||
dwRead += dwReadLength;
|
||||
|
||||
m_dwDataBufPos += dwReadLength;
|
||||
m_dwDataBufLen -= dwReadLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_dwPosition += dwRead;
|
||||
*pdwBytesRead = dwRead;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Size()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
LONGLONG IIEP::CMP3Stream::Size(LONGLONG *pSizeAvailable)
|
||||
{
|
||||
// LONGLONG llCurrentAvailable = Int32x32To64((::timeGetTime() - m_dwTimeStart), m_dwKBPerSec);
|
||||
LONGLONG llLength = (LONGLONG) m_dwTotalBlocks * m_dwAlignment + WAVE_HEADER_LENGTH;
|
||||
|
||||
if (pSizeAvailable)
|
||||
{
|
||||
// *pSizeAvailable = min(llLength, llCurrentAvailable);
|
||||
*pSizeAvailable = llLength;
|
||||
}
|
||||
|
||||
return llLength;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Alignment()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
DWORD IIEP::CMP3Stream::Alignment(void)
|
||||
{
|
||||
return m_dwAlignment;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Lock()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void IIEP::CMP3Stream::Lock(void)
|
||||
{
|
||||
m_csLock.Lock();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: Unlock()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void IIEP::CMP3Stream::Unlock(void)
|
||||
{
|
||||
m_csLock.Unlock();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: DecodeFrame()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::CMP3Stream::DecodeFrame(void)
|
||||
{
|
||||
if (0 == m_dwDataBufLen)
|
||||
{
|
||||
m_dwDataBufPos = 0;
|
||||
}
|
||||
|
||||
if (m_dwDataBufPos + m_dwDataBufLen + MP3_DECODE_LEN > MP3_DECODE_BUF_LEN)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t nBytesRead = 0;
|
||||
|
||||
mpg123_read(m_pcoMH, m_ucDataBuffer + m_dwDataBufPos + m_dwDataBufLen, MP3_DECODE_LEN, &nBytesRead);
|
||||
|
||||
m_dwDataBufLen += (DWORD) nBytesRead;
|
||||
|
||||
return (m_dwDataBufLen > 0);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: OpenFile()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
bool IIEP::CMP3Stream::OpenFile(const WORD *pcwsFileName)
|
||||
{
|
||||
if (m_coFileIn.Open(pcwsFileName))
|
||||
{
|
||||
m_nDataBegin = 0;
|
||||
m_nDataTotal = m_coFileIn.GetFileSize();
|
||||
|
||||
// check ID3 Tag V2.x
|
||||
|
||||
BYTE ucBuffer[8];
|
||||
bool bFound;
|
||||
|
||||
TRY_ID3_AGAIN:
|
||||
|
||||
bFound = false;
|
||||
|
||||
if (6 == m_coFileIn.Read(ucBuffer, 6))
|
||||
{
|
||||
if (ucBuffer[0] == 'I' &&
|
||||
ucBuffer[1] == 'D' &&
|
||||
ucBuffer[2] == '3')
|
||||
{
|
||||
bFound = true;
|
||||
|
||||
DWORD dwHeaderSize;
|
||||
|
||||
if (m_coFileIn.ReadInverseDW(dwHeaderSize))
|
||||
{
|
||||
dwHeaderSize = ((dwHeaderSize & 0x7F000000) >> 3) +
|
||||
((dwHeaderSize & 0x007F0000) >> 2) +
|
||||
((dwHeaderSize & 0x00007F00) >> 1) +
|
||||
((dwHeaderSize & 0x0000007F) );
|
||||
|
||||
dwHeaderSize += 10;
|
||||
|
||||
m_nDataBegin += dwHeaderSize;
|
||||
m_nDataTotal -= dwHeaderSize;
|
||||
|
||||
if (ucBuffer[3] >= 0x03) // ID3 Tag version >= 2.3
|
||||
{
|
||||
if (ucBuffer[5] & 0x40) // has extended header
|
||||
{
|
||||
if (m_coFileIn.ReadInverseDW(dwHeaderSize))
|
||||
{
|
||||
dwHeaderSize = ((dwHeaderSize & 0x7F000000) >> 3) +
|
||||
((dwHeaderSize & 0x007F0000) >> 2) +
|
||||
((dwHeaderSize & 0x00007F00) >> 1) +
|
||||
((dwHeaderSize & 0x0000007F) );
|
||||
|
||||
dwHeaderSize += 4;
|
||||
|
||||
m_nDataBegin += dwHeaderSize;
|
||||
m_nDataTotal -= dwHeaderSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SeekFile(0, SEEK_SET);
|
||||
|
||||
if (bFound)
|
||||
{
|
||||
goto TRY_ID3_AGAIN;
|
||||
}
|
||||
/*
|
||||
m_coFileIn.Read(ucBuffer, 2);
|
||||
|
||||
if (ucBuffer[0] != 0xFF || ucBuffer[1] < 0xF0)
|
||||
{
|
||||
m_nDataBegin ++;
|
||||
m_nDataTotal --;
|
||||
|
||||
SeekFile(0, SEEK_SET);
|
||||
|
||||
goto TRY_ID3_AGAIN;
|
||||
}
|
||||
|
||||
SeekFile(0, SEEK_SET);
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: ReadFile()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
DWORD IIEP::CMP3Stream::ReadFile(PVOID pBuf, DWORD dwLen)
|
||||
{
|
||||
return m_coFileIn.Read(pBuf, dwLen);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// name: SeekFile()
|
||||
// desc:
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
long IIEP::CMP3Stream::SeekFile(long nOffset, int iOrigin)
|
||||
{
|
||||
switch (iOrigin)
|
||||
{
|
||||
case SEEK_SET:
|
||||
if (nOffset < 0 || nOffset >= m_nDataTotal) return -1;
|
||||
break;
|
||||
|
||||
case SEEK_CUR:
|
||||
nOffset += (m_coFileIn.GetReadPosition() - m_nDataBegin);
|
||||
if (nOffset < 0 || nOffset >= m_nDataTotal) return -1;
|
||||
break;
|
||||
|
||||
case SEEK_END:
|
||||
nOffset = m_nDataTotal - 1 + nOffset;
|
||||
if (nOffset < 0 || nOffset >= m_nDataTotal) return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_coFileIn.Seek(nOffset + m_nDataBegin, SEEK_SET))
|
||||
{
|
||||
return nOffset;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,245 @@
|
||||
<?xml version="1.0" encoding="gb2312"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="libMPG123"
|
||||
ProjectGUID="{5227AA93-1E16-49FC-AE09-939AA023A7C1}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="..\LIB"
|
||||
IntermediateDirectory="\TEMP\libMPG123\Debug"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="REAL_IS_FLOAT;OPT_X86;OPT_GENERIC; WIN32;_DEBUG;_LIB"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="FALSE"
|
||||
DebugInformationFormat="3"
|
||||
DisableSpecificWarnings="4305"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="$(OutDir)/libMPG123_d.lib"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="..\LIB"
|
||||
IntermediateDirectory="\TEMP\libMPG123\Release"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="1"
|
||||
GlobalOptimizations="TRUE"
|
||||
ImproveFloatingPointConsistency="TRUE"
|
||||
FavorSizeOrSpeed="2"
|
||||
OmitFramePointers="TRUE"
|
||||
EnableFiberSafeOptimizations="TRUE"
|
||||
OptimizeForProcessor="2"
|
||||
OptimizeForWindowsApplication="TRUE"
|
||||
PreprocessorDefinitions="REAL_IS_FLOAT;OPT_X86;OPT_GENERIC; WIN32;NDEBUG;_LIB"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="0"
|
||||
StructMemberAlignment="1"
|
||||
BufferSecurityCheck="FALSE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="FALSE"
|
||||
DebugInformationFormat="0"
|
||||
DisableSpecificWarnings="4305"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile="$(OutDir)/libMPG123.lib"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="libMPG123"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\compat.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\compat.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dct64.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dct64_i386.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\debug.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\decode.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\decode.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\decode_2to1.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\decode_4to1.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\decode_i386.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\decode_ntom.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\decode_sse3d.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dnoise.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\equalizer.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\format.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\frame.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\frame.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\getbits.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\getcpuflags.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\huffman.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\icy.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\icy.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\id3.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\id3.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\l2tables.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\layer1.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\layer2.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\layer3.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\libmpg123.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\mangle.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\mpg123lib_intern.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\optimize.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\optimize.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\parse.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\parse.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\reader.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\readers.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stringbuf.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tabinit.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\testcpu.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\true.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\config.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\mpg123.h">
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
Reference in New Issue
Block a user