📄 cpi_player_codec_winampplugin.c
字号:
}
}
//
//
//
void CP_InitialiseCodec_WinAmpPlugin(CPs_CoDecModule* pCoDec)
{
CPs_CoDec_WinAmpPlugin *pContext;
// Setup functions
pCoDec->Uninitialise = CPP_OMAPLG_Uninitialise;
pCoDec->OpenFile = CPP_OMAPLG_OpenFile;
pCoDec->CloseFile = CPP_OMAPLG_CloseFile;
pCoDec->Seek = CPP_OMAPLG_Seek;
pCoDec->GetFileInfo = CPP_OMAPLG_GetFileInfo;
pCoDec->GetPCMBlock = CPP_OMAPLG_GetPCMBlock;
pCoDec->GetCurrentPos_secs = CPP_OMAPLG_GetCurrentPos_secs;
// Setup private data
pCoDec->m_pModuleCookie = malloc(sizeof(CPs_CoDec_WinAmpPlugin));
pContext = (CPs_CoDec_WinAmpPlugin*)pCoDec->m_pModuleCookie;
pContext->m_pFirstPlugIn = 0L;
pContext->m_pActivePluginModule = NULL;
pContext->m_hModPlugin = NULL;
pContext->m_pInModule = NULL;
pContext->m_bModuleIsPlaying = FALSE;
memset(&pContext->m_FakeOutModule, 0, sizeof(pContext->m_FakeOutModule));
pContext->m_FakeOutModule.version = OUT_VER;
pContext->m_FakeOutModule.Open = CP_OutPI_Open;
pContext->m_FakeOutModule.Close = CP_OutPI_Close;
pContext->m_FakeOutModule.Write = CP_OutPI_Write;
pContext->m_FakeOutModule.CanWrite = CP_OutPI_CanWrite;
pContext->m_FakeOutModule.IsPlaying = CP_OutPI_IsPlaying;
pContext->m_FakeOutModule.Flush = CP_OutPI_Flush;
pContext->m_FakeOutModule.Pause = CP_Dummy_Pause;
pContext->m_FakeOutModule.SetVolume = CP_Dummy_SetVolume;
pContext->m_FakeOutModule.SetPan = CP_Dummy_SetPan;
pContext->m_FakeOutModule.GetOutputTime = CP_Dummy_GetOutputTime;
pContext->m_FakeOutModule.GetWrittenTime = CP_Dummy_GetWrittenTime;
// Global data
InitializeCriticalSection(&glb_OutputData.m_csGlobal);
glb_OutputData.m_evtFileInfoValid = NULL;
memset(&glb_OutputData.m_FileInfo, 0, sizeof(glb_OutputData.m_FileInfo));
glb_OutputData.m_pCBuffer = NULL;
glb_OutputData.m_iCurrentTime_ms = 0;
glb_OutputData.m_evtSeekComplete = NULL;
CPFA_InitialiseFileAssociations(pCoDec);
// Look in the current directory for WinAmp plugins - these have the format
// in_*.dll
{
char pcCurrentModuleDirectory[MAX_PATH];
main_get_program_path(GetModuleHandle(NULL), pcCurrentModuleDirectory, MAX_PATH);
AddWinAmpModulesInPath(pCoDec, pcCurrentModuleDirectory);
}
/*
Some plugins have problems running outside of the WinAmp directory - so we will only
use plugins from the current dir (until someone has inspiration!!)
*/
/*
// Try to track down the WinAmp plugins directory (and add them too)
{
LONG lResult;
HKEY hKeyWinAmp;
lResult = RegOpenKey(HKEY_CLASSES_ROOT,
"WinAmp.File\\shell\\open\\command",
&hKeyWinAmp);
if(lResult == ERROR_SUCCESS)
{
char cWinAmpPath[255];
char* pcValue;
LONG iValueLen;
RegQueryValue(hKeyWinAmp, NULL, NULL, &iValueLen);
pcValue = (char*)malloc(iValueLen);
RegQueryValue(hKeyWinAmp, NULL, pcValue, &iValueLen);
if(sscanf(pcValue, "\"%255[^\"]", cWinAmpPath) == 1)
{
int iLastSlashPos, iCharIDX;
// Remove the WinAmp exe name
iLastSlashPos = CP_INVALIDCHARPOS;
for(iCharIDX=0; cWinAmpPath[iCharIDX]; iCharIDX++)
{
if(cWinAmpPath[iCharIDX] == '\\')
iLastSlashPos = iCharIDX;
}
// We must exist in some kind of directory!!!
CP_ASSERT(iLastSlashPos != CP_INVALIDCHARPOS);
cWinAmpPath[iLastSlashPos+1] = '\0';
// Append the Plugins folder
strcat(cWinAmpPath, "Plugins\\");
AddWinAmpModulesInPath(pCoDec, cWinAmpPath);
}
// Cleanup
free(pcValue);
RegCloseKey(hKeyWinAmp);
}
}
*/
}
//
//
//
void CPP_OMAPLG_Uninitialise(CPs_CoDecModule* pModule)
{
CPs_CoDec_WinAmpPlugin *pContext = (CPs_CoDec_WinAmpPlugin*)pModule->m_pModuleCookie;
CP_PlugInModule* pPlugInCursor;
CP_PlugInModule* pPlugInCursor_Next;
CP_CHECKOBJECT(pContext);
// Cleanup plug in module list
pPlugInCursor_Next = NULL;
for(pPlugInCursor = pContext->m_pFirstPlugIn; pPlugInCursor; pPlugInCursor = pPlugInCursor_Next)
{
pPlugInCursor_Next = (CP_PlugInModule*)pPlugInCursor->m_pNext;
free(pPlugInCursor->m_pcModuleName);
free(pPlugInCursor);
}
// Global output data
DeleteCriticalSection(&glb_OutputData.m_csGlobal);
free(pContext);
CPFA_EmptyFileAssociations(pModule);
}
//
//
//
void InitialiseGlobalData()
{
EnterCriticalSection(&glb_OutputData.m_csGlobal);
// Stuff for the file information
CP_ASSERT(!glb_OutputData.m_evtFileInfoValid);
glb_OutputData.m_evtFileInfoValid = CreateEvent(NULL, TRUE, FALSE, NULL);
memset(&glb_OutputData.m_FileInfo, 0, sizeof(glb_OutputData.m_FileInfo));
// Stuff for the data buffer
CP_ASSERT(!glb_OutputData.m_pCBuffer);
glb_OutputData.m_pCBuffer = CP_CreateCircleBuffer(CIC_CIRCLE_DATABUFFER_SIZE);
glb_OutputData.m_iCurrentTime_ms = 0;
CP_ASSERT(!glb_OutputData.m_evtSeekComplete);
glb_OutputData.m_evtSeekComplete = CreateEvent(NULL, FALSE, FALSE, NULL);
LeaveCriticalSection(&glb_OutputData.m_csGlobal);
}
//
//
//
void UnitialiseGlobalData()
{
EnterCriticalSection(&glb_OutputData.m_csGlobal);
// Stuff for the file information
CP_ASSERT(glb_OutputData.m_evtFileInfoValid);
CloseHandle(glb_OutputData.m_evtFileInfoValid);
glb_OutputData.m_evtFileInfoValid = NULL;
// Stuff for the data buffer
CP_ASSERT(glb_OutputData.m_pCBuffer);
glb_OutputData.m_pCBuffer->Uninitialise(glb_OutputData.m_pCBuffer);
glb_OutputData.m_pCBuffer = NULL;
CP_ASSERT(glb_OutputData.m_evtSeekComplete);
CloseHandle(glb_OutputData.m_evtSeekComplete);
glb_OutputData.m_evtSeekComplete = NULL;
LeaveCriticalSection(&glb_OutputData.m_csGlobal);
}
//
//
//
void CloseCurrentModule(CPs_CoDec_WinAmpPlugin *pContext)
{
CP_CHECKOBJECT(pContext);
CP_ASSERT(pContext->m_pActivePluginModule);
CP_ASSERT(pContext->m_hModPlugin);
CP_ASSERT(pContext->m_pInModule);
CP_ASSERT(pContext->m_pInModule->Stop);
CP_ASSERT(pContext->m_pInModule->Quit);
CP_TRACE1("Free module: \"%s\"", pContext->m_pActivePluginModule->m_pcModuleName);
if(pContext->m_bModuleIsPlaying)
pContext->m_pInModule->Stop();
pContext->m_pInModule->Quit();
FreeLibrary(pContext->m_hModPlugin);
pContext->m_pActivePluginModule = NULL;
pContext->m_hModPlugin = NULL;
pContext->m_pInModule = NULL;
pContext->m_bModuleIsPlaying = FALSE;
}
//
//
//
void SetupCurrentInputPluginModule(CPs_CoDec_WinAmpPlugin *pContext)
{
CP_CHECKOBJECT(pContext);
CP_ASSERT(pContext->m_pActivePluginModule);
CP_ASSERT(pContext->m_hModPlugin);
CP_ASSERT(pContext->m_pInModule);
pContext->m_pInModule->hMainWindow = (HWND)0x2398;
pContext->m_pInModule->hDllInstance = pContext->m_hModPlugin;
// Setup functions
pContext->m_pInModule->SAVSAInit = CP_Dummy_SAVSAInit;
pContext->m_pInModule->SAVSADeInit = CP_Dummy_SAVSADeInit;
pContext->m_pInModule->SAAddPCMData = CP_Dummy_SAAddPCMData;
pContext->m_pInModule->SAGetMode = CP_Dummy_SAGetMode;
pContext->m_pInModule->SAAdd = CP_Dummy_SAAdd;
pContext->m_pInModule->VSAAddPCMData = CP_Dummy_VSAAddPCMData;
pContext->m_pInModule->VSAGetMode = CP_Dummy_VSAGetMode;
pContext->m_pInModule->VSAAdd = CP_Dummy_VSAAdd;
pContext->m_pInModule->dsp_isactive = CP_Dummy_dsp_isactive;
pContext->m_pInModule->dsp_dosamples = CP_Dummy_dsp_dosamples;
pContext->m_pInModule->VSASetInfo = CP_Dummy_VSASetInfo;
pContext->m_pInModule->SetInfo = CP_Dummy_SetInfo;
pContext->m_pInModule->outMod = &pContext->m_FakeOutModule;
}
//
//
//
BOOL CPP_OMAPLG_OpenFile(CPs_CoDecModule* pModule, const char* pcFilename, DWORD dwCookie, HWND hWndOwner)
{
CPs_CoDec_WinAmpPlugin *pContext = (CPs_CoDec_WinAmpPlugin*)pModule->m_pModuleCookie;
CP_PlugInModule* pSelectedPlugInModule = (CP_PlugInModule*)dwCookie;
int iError;
CP_CHECKOBJECT(pContext);
if(!pSelectedPlugInModule) return FALSE;
// Open output module
{
// Module has changed
wp_winampGetInModule2 pfnGetInModule;
if(pContext->m_pActivePluginModule)
CloseCurrentModule(pContext);
// Load plugin and get EP
CP_TRACE1("Load module: \"%s\"", pSelectedPlugInModule->m_pcModuleName);
pContext->m_hModPlugin = LoadLibrary(pSelectedPlugInModule->m_pcModuleName);
if(!pContext->m_hModPlugin)
return FALSE;
pfnGetInModule = (wp_winampGetInModule2)GetProcAddress(pContext->m_hModPlugin, "winampGetInModule2");
if(!pfnGetInModule)
{
FreeLibrary(pContext->m_hModPlugin);
pContext->m_hModPlugin = NULL;
return FALSE;
}
pContext->m_pActivePluginModule = pSelectedPlugInModule;
pContext->m_pInModule = pfnGetInModule();
SetupCurrentInputPluginModule(pContext);
pContext->m_pInModule->Init();
InitialiseGlobalData();
}
iError = pContext->m_pInModule->Play(pcFilename);
if(iError != 0)
{
CP_TRACE1("**** Failed to open file: \"%s\"", pcFilename);
CloseCurrentModule(pContext);
UnitialiseGlobalData();
return FALSE;
}
pContext->m_bModuleIsPlaying = TRUE;
return TRUE; // Success
}
//
//
//
void CPP_OMAPLG_CloseFile(CPs_CoDecModule* pModule)
{
CPs_CoDec_WinAmpPlugin *pContext = (CPs_CoDec_WinAmpPlugin*)pModule->m_pModuleCookie;
CP_CHECKOBJECT(pContext);
UnitialiseGlobalData();
if(pContext->m_pActivePluginModule)
CloseCurrentModule(pContext);
}
//
//
//
void CPP_OMAPLG_Seek(CPs_CoDecModule* pModule, const int iNumerator, const int iDenominator)
{
CPs_CoDec_WinAmpPlugin *pContext = (CPs_CoDec_WinAmpPlugin*)pModule->m_pModuleCookie;
int iStreamLength_ms;
CP_CHECKOBJECT(pContext);
CP_ASSERT(pContext->m_pActivePluginModule);
iStreamLength_ms = pContext->m_pInModule->GetLength();
pContext->m_pInModule->SetOutputTime( (iNumerator*iStreamLength_ms) / iDenominator);
WaitForSingleObject(glb_OutputData.m_evtSeekComplete, CIC_WAITTIMEOUT);
}
//
//
//
BOOL CPP_OMAPLG_GetPCMBlock(CPs_CoDecModule* pModule, void* _pBlock, DWORD* pdwBlockSize)
{
CPs_CoDec_WinAmpPlugin *pContext = (CPs_CoDec_WinAmpPlugin*)pModule->m_pModuleCookie;
CP_CHECKOBJECT(pContext);
return glb_OutputData.m_pCBuffer->Read(glb_OutputData.m_pCBuffer, _pBlock, *pdwBlockSize, pdwBlockSize);
}
//
//
//
void CPP_OMAPLG_GetFileInfo(CPs_CoDecModule* pModule, CPs_FileInfo* pInfo)
{
CPs_CoDec_WinAmpPlugin *pContext = (CPs_CoDec_WinAmpPlugin*)pModule->m_pModuleCookie;
DWORD dwWaitResult;
CP_CHECKOBJECT(pContext);
CP_ASSERT(pContext->m_pActivePluginModule);
// Wait up to 1 second for the plugin to return the stream format - if it doesn't
// set the file info into something that we know will be unsupported
dwWaitResult = WaitForSingleObject(glb_OutputData.m_evtFileInfoValid, CIC_WAITTIMEOUT);
if(dwWaitResult == WAIT_OBJECT_0)
{
EnterCriticalSection(&glb_OutputData.m_csGlobal);
memcpy(pInfo, &glb_OutputData.m_FileInfo, sizeof(*pInfo));
LeaveCriticalSection(&glb_OutputData.m_csGlobal);
}
else
{
CP_TRACE0("Module did not respond in time - setting bogus stream params");
memset(pInfo, 0, sizeof(*pInfo));
}
pInfo->m_iFileLength_Secs = pContext->m_pInModule->GetLength() / 1000;
}
//
//
//
int CPP_OMAPLG_GetCurrentPos_secs(CPs_CoDecModule* pModule)
{
CPs_CoDec_WinAmpPlugin *pContext = (CPs_CoDec_WinAmpPlugin*)pModule->m_pModuleCookie;
int iCurrentPos_secs;
CP_CHECKOBJECT(pContext);
CP_ASSERT(pContext->m_pActivePluginModule);
EnterCriticalSection(&glb_OutputData.m_csGlobal);
iCurrentPos_secs = glb_OutputData.m_iCurrentTime_ms / 1000;
LeaveCriticalSection(&glb_OutputData.m_csGlobal);
return iCurrentPos_secs;
}
//
//
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -