player.cpp
来自「这是一个mp3的源代码」· C++ 代码 · 共 1,991 行 · 第 1/4 页
CPP
1,991 行
}
}
}
delete [] path;
delete [] url;
return true;
}
void
Player::
Usage(const char *progname)
{
if(m_didUsage)
return;
printf(The_BRANDING " version " FREEAMP_VERSION " -- Usage:\n\n");
printf("%s [-save] [-ui <UI plugin name>] <MP3 file/stream> "
"[MP3 file/stream] ...\n\n", progname);
printf("Example command line:\n\n");
printf(" %s -ui freeamp.ui mysong1.mp3 mysong2.mp3\n\n", progname);
m_didUsage = true;
}
int32
Player::
CompareNames(const char *p1, const char *p2)
{
// windows plugins and unix plugins are named differently...
#if defined( WIN32 ) || defined ( __BEOS__ )
return strcasecmp(p1, p2);
#else
// ut << "Comparing: " << p1 << " to " << p2 << endl;
if (strcmp(p1, p2))
{
// no direct match, try w/ .ui appended...
char foo[512];
sprintf(foo, "%s.ui", p2);
// ut << "Comparing: " << p1 << " to " << foo << endl;
if (strcmp(p1, foo))
{
// no plugin.ui match, try plugin-arch.ui
char foo[512];
sprintf(foo, "%s.ui", p2);
// cout << "Comparing: " << p1 << " to " << foo << endl;
if (strcmp(p1, foo))
{
// no match
return 1;
}
else
{
return 0;
}
}
else
{
return 0;
}
}
else
{
return 0;
}
#endif
}
void
Player::
Run()
{
uint32 uiListIndex = 0;
char *name = NULL;
uint32 len = 256;
Error error = kError_NoErr;
int32 uisActivated = 0;
bool bValue;
m_context->prefs->GetUseDebugLog(&bValue);
if (bValue)
m_context->log->Open();
m_context->prefs->GetLogInput(&bValue);
if (bValue)
m_context->log->AddLogLevel(LogInput);
m_context->prefs->GetLogOutput(&bValue);
if (bValue)
m_context->log->AddLogLevel(LogOutput);
m_context->prefs->GetLogDecode(&bValue);
if (bValue)
m_context->log->AddLogLevel(LogDecode);
m_context->prefs->GetLogPerformance(&bValue);
if (bValue)
m_context->log->AddLogLevel(LogPerf);
bool loadSecondaryUIs = true;
// which ui should we instantiate first??
if (m_argUIList->size() == 0)
{
const char *pref = kUIPref;
name = new char[len];
#ifdef unix
if (!getenv("DISPLAY")) {
pref = kTextUIPref;
loadSecondaryUIs = false;
}
#endif
while ((error = m_context->prefs->GetPrefString(pref, name, &len)) ==
kError_BufferTooSmall)
{
delete[] name;
len++;
name = new char[len];
}
#ifdef unix
#ifndef HAVE_GTK
if (!strcmp("freeamp.ui", name)) {
pref = kTextUIPref;
while ((error = m_context->prefs->GetPrefString(pref, name, &len)) ==
kError_BufferTooSmall)
{
delete [] name;
len++;
name = new char[len];
}
}
#endif
#endif
}
else
{
char *orig = (*m_argUIList)[uiListIndex++];
// RAK: This pointer is later re-used when the size of the
// contents may have changed. See comment below.
name = new char[strlen(orig) + 1];
strcpy(name, orig);
}
#ifdef HAVE_GTK
if (strcmp("freeamp.ui", name))
loadSecondaryUIs = false;
#endif
len = 255;
char *downloadName = new char[len];
while ((error = m_context->prefs->GetPrefString(kDownloadManagerUIPref,
downloadName, &len)) ==
kError_BufferTooSmall)
{
delete[] downloadName;
len++;
downloadName = new char[len];
}
len = 255;
char *musicBrowserName = new char[len];
while ((error = m_context->prefs->GetPrefString(kMusicBrowserUIPref,
musicBrowserName, &len)) ==
kError_BufferTooSmall)
{
delete[] musicBrowserName;
len++;
musicBrowserName = new char[len];
}
#ifdef WIN32
len = 255;
char *toolbarName = new char[len];
while ((error = m_context->prefs->GetPrefString(kToolbarUIPref,
toolbarName, &len)) ==
kError_BufferTooSmall)
{
delete[] toolbarName;
len++;
toolbarName = new char[len];
}
#endif
if (IsntError(error))
{
while (*name)
{
RegistryItem *item = NULL;
// UserInterface *ui = NULL;
int32 i = 0;
while (NULL != (item = m_uiRegistry->GetItem(i++)))
{
if (!CompareNames(item->Name(), downloadName) && loadSecondaryUIs)
{
m_ui = (UserInterface *) item->InitFunction()(m_context);
Error er = m_ui->Init(SECONDARY_UI_STARTUP);
if (IsntError(er))
{
RegisterActiveUI(m_ui);
m_downloadUI = m_ui;
}
else
{
delete m_ui;
m_ui = NULL;
}
}
else if (!CompareNames(item->Name(), musicBrowserName) &&
loadSecondaryUIs)
{
m_ui = (UserInterface *) item->InitFunction()(m_context);
Error er = m_ui->Init(SECONDARY_UI_STARTUP);
if (IsntError(er))
{
RegisterActiveUI(m_ui);
m_browserUI = m_ui;
}
else
{
delete m_ui;
m_ui = NULL;
}
}
#ifdef WIN32
else
if (!CompareNames(item->Name(), toolbarName))
{
m_ui = (UserInterface *) item->InitFunction()(m_context);
Error er = m_ui->Init(SECONDARY_UI_STARTUP);
if (IsntError(er))
RegisterActiveUI(m_ui);
else
{
delete m_ui;
m_ui = NULL;
}
}
#endif
else if (!CompareNames(item->Name(), name))
{
m_ui = (UserInterface *) item->InitFunction()(m_context);
//m_ui->SetPropManager((Properties *) this);
//m_ui->SetPlaylistManager(m_plm);
//m_ui->SetArgs(m_argc, m_argv);
Error er = m_ui->Init((uisActivated == 0) ? PRIMARY_UI
: SECONDARY_UI_STARTUP);
if (IsntError(er))
{
RegisterActiveUI(m_ui);
uisActivated++;
}
else
{
delete m_ui;
m_ui = NULL;
}
// break; Don't think this'll work now...
}
}
if(uiListIndex < m_argUIList->size())
{
char *p = (*m_argUIList)[uiListIndex++];
// RAK: Boundschecker was pissed about this. This copy
// may be larger than the space allocated on line 524
// So, delete the old pointer and create a new one.
delete name;
name = new char[strlen(p) + 1];
strcpy(name, p);
}
else
{
*name = '\0';
}
}
if (!uisActivated)
{
#ifdef WIN32
MessageBox(NULL, The_BRANDING" cannot find a valid user interface module.\r\n"
"Please make sure that " the_BRANDING" is installed correctly.\r\n"
"You may wish to remove and reinstall " the_BRANDING" to fix this problem",
BRANDING" Error", MB_OK);
#else
const char *thePath = getenv(FREEAMP_PATH_ENV);
if (thePath == NULL)
thePath = m_context->prefs->GetLibDirs();
cerr << "No UI plugin in '" << thePath << "' matched 'plugins/" << name << "' or 'plugins/" << name << ".ui.'" << endl;
cerr << The_BRANDING << " will quit." << endl;
#endif
Event *e = new Event(CMD_QuitPlayer);
AcceptEvent(e);
e = new Event(INFO_ReadyToDieUI);
AcceptEvent(e);
}
}
m_eventServiceThread = Thread::CreateThread();
m_eventServiceThread->Create(Player::EventServiceThreadFunc, this);
delete[] name;
delete[] musicBrowserName;
delete[] downloadName;
#ifdef WIN32
delete[] toolbarName;
#endif
}
void
Player::
EventServiceThreadFunc(void *pPlayer)
{
Player *pP = (Player *) pPlayer;
Event *pC;
int32 rtnVal = 0x0;
while (rtnVal == 0)
{ // serviceEvent will return 1 if error or time
if (pP->m_eventQueue->Peek() == NULL)
pP->m_eventSem->Wait();
pC = pP->m_eventQueue->Read();
if (pC)
{
rtnVal = pP->ServiceEvent(pC);
}
}
}
int32
Player::
RegisterActiveUI(UserInterface * ui)
{
GetUIManipLock();
if (m_uiList && ui)
{
m_uiList->push_back(ui);
ReleaseUIManipLock();
return 0;
}
else
{
ReleaseUIManipLock();
return 255;
}
}
int32
Player::
RegisterLMCs(Registry * registry)
{
int32 result = 0;
m_lmcMutex->Acquire();
if (m_lmcRegistry)
{
Registrar::CleanupRegistry(m_lmcRegistry);
delete m_lmcRegistry;
}
if (m_lmcExtensions)
delete m_lmcExtensions;
m_lmcExtensions = new HashTable<RegistryItem *>;
m_lmcRegistry = registry;
RegistryItem *lmc_item;
LogicalMediaConverter *lmc;
int iItems = registry->CountItems();
for (int iLoop = 0; iLoop < iItems; iLoop++)
{
RegistryItem* temp = registry->GetItem(iLoop);
lmc = (LogicalMediaConverter *)temp->InitFunction()(m_context);
vector<char *> *extList = lmc->GetExtensions();
for (uint32 iextLoop = 0; iextLoop < extList->size(); iextLoop++)
{
lmc_item = new RegistryItem(*temp);
m_lmcExtensions->Insert((*extList)[iextLoop], lmc_item);
}
delete extList;
delete lmc;
}
m_lmcMutex->Release();
return result;
}
int32
Player::
RegisterPMIs(Registry * registry)
{
int32 result = 0;
m_pmiMutex->Acquire();
if (m_pmiRegistry)
{
Registrar::CleanupRegistry(m_pmiRegistry);
delete m_pmiRegistry;
}
m_pmiRegistry = registry;
m_pmiMutex->Release();
return result;
}
int32
Player::
RegisterPMOs(Registry * registry)
{
int32 result = 0;
m_pmoMutex->Acquire();
if (m_pmoRegistry)
{
Registrar::CleanupRegistry(m_pmoRegistry);
delete m_pmoRegistry;
}
m_pmoRegistry = registry;
m_pmoMutex->Release();
return result;
}
int32
Player::
RegisterUIs(Registry * registry)
{
int32 result = 0;
m_uiMutex->Acquire();
if (m_uiRegistry)
{
Registrar::CleanupRegistry(m_uiRegistry);
delete m_uiRegistry;
}
m_uiRegistry = registry;
m_uiMutex->Release();
return result;
}
Registry*
Player::
GetLMCRegistry() const
{
return m_lmcRegistry;
}
Registry*
Player::
GetPMIRegistry() const
{
return m_pmiRegistry;
}
Registry*
Player::
GetPMORegistry() const
{
return m_pmoRegistry;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?