From 1e84dd23d75259b0102ad05a97ce156ddf7f9ac8 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 1 Jun 2013 19:01:43 +0200 Subject: [PATCH] Hide atrac3+ option if no codec dll/.so installed --- Core/Config.cpp | 4 ++ Core/Config.h | 3 +- Core/HLE/sceAtrac.cpp | 12 ++-- Core/HW/atrac3plus.cpp | 121 +++++++++++++++++++++++++++++------------ Core/HW/atrac3plus.h | 17 ++++-- UI/MenuScreens.cpp | 5 +- UI/MenuScreens.h | 1 - native | 2 +- 8 files changed, 116 insertions(+), 49 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 79da056b2e..178202608d 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -170,7 +170,11 @@ void Config::Save() } IniFile::Section *general = iniFile.GetOrCreateSection("General"); + + // Need to do this somewhere... + bFirstRun = false; general->Set("FirstRun", bFirstRun); + general->Set("AutoLoadLast", bAutoLoadLast); general->Set("AutoRun", bAutoRun); general->Set("Browse", bBrowse); diff --git a/Core/Config.h b/Core/Config.h index f756b391a9..0d7f4336e3 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -33,9 +33,10 @@ public: // Whether to save the config on close. bool bSaveSettings; + bool bFirstRun; + // These are broken bool bAutoLoadLast; - bool bFirstRun; bool bSpeedLimit; bool bConfirmOnQuit; bool bAutoRun; // start immediately diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 6bca54da9c..f4179e87f6 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -129,7 +129,7 @@ struct Atrac { delete [] data_buf; data_buf = 0; - Atrac3plus_Decoder::closeContext(&decoder_context); + Atrac3plus_Decoder::CloseContext(&decoder_context); sampleQueue.clear(); } @@ -275,7 +275,7 @@ void __AtracInit() { av_register_all(); #endif // USE_FFMPEG - Atrac3plus_Decoder::initdecoder(); + Atrac3plus_Decoder::Init(); } void __AtracDoState(PointerWrap &p) { @@ -291,7 +291,7 @@ void __AtracShutdown() { } atracMap.clear(); - Atrac3plus_Decoder::shutdowndecoder(); + Atrac3plus_Decoder::Shutdown(); } Atrac *getAtrac(int atracID) { @@ -544,7 +544,7 @@ u32 sceAtracDecodeData(int atracID, u32 outAddr, u32 numSamplesAddr, u32 finishF int inbytes = std::max((int)atrac->first.filesize - (int)atrac->decodePos, 0); inbytes = std::min(inbytes, (int)atrac->atracBytesPerFrame); if (inbytes > 0) { - Atrac3plus_Decoder::atrac3plus_decode(atrac->decoder_context, atrac->data_buf + atrac->decodePos, inbytes, &decodebytes, buf); + Atrac3plus_Decoder::Decode(atrac->decoder_context, atrac->data_buf + atrac->decodePos, inbytes, &decodebytes, buf); DEBUG_LOG(HLE, "decodebytes: %i outbuf: %p", decodebytes, buf); atrac->sampleQueue.push(buf, decodebytes); } @@ -884,7 +884,7 @@ int64_t _AtracSeekbuffer(void *opaque, int64_t offset, int whence) int __AtracSetContext(Atrac *atrac) { if (atrac->codeType == PSP_MODE_AT_3_PLUS) { - atrac->decoder_context = Atrac3plus_Decoder::openContext(); + atrac->decoder_context = Atrac3plus_Decoder::OpenContext(); return 0; } @@ -1419,7 +1419,7 @@ int sceAtracLowLevelDecode(int atracID, u32 sourceAddr, u32 sourceBytesConsumedA static u8 buf[0x8000]; if (sourcebytes > 0) { int decodebytes = 0; - Atrac3plus_Decoder::atrac3plus_decode(atrac->decoder_context, Memory::GetPointer(sourceAddr), sourcebytes, &decodebytes, buf); + Atrac3plus_Decoder::Decode(atrac->decoder_context, Memory::GetPointer(sourceAddr), sourcebytes, &decodebytes, buf); atrac->sampleQueue.push(buf, decodebytes); } s16* out = (s16*)Memory::GetPointer(samplesAddr); diff --git a/Core/HW/atrac3plus.cpp b/Core/HW/atrac3plus.cpp index 591f4f15f2..5bd08b7544 100644 --- a/Core/HW/atrac3plus.cpp +++ b/Core/HW/atrac3plus.cpp @@ -15,6 +15,7 @@ #include "base/logging.h" #include "Core/Config.h" #include "Common/FileUtil.h" +#include "Core/HW/atrac3plus.h" extern std::string externalDirectory; @@ -33,16 +34,90 @@ namespace Atrac3plus_Decoder { ATRAC3PLUS_OPENCONTEXT open_context = 0; ATRAC3PLUS_CLOSECONTEXT close_context = 0; - int initdecoder() { + std::string GetInstalledFilename() { +#if defined(ANDROID) && defined(ARM) + std::string internalFilename = g_Config.internalDataDirectory + "libat3plusdecoder.so"; +#else +#ifdef _M_X64 + std::string internalFilename = "at3plusdecoder64.dll"; +#else + std::string internalFilename = "at3plusdecoder.dll"; +#endif +#endif + return internalFilename; + } + std::string GetAutoInstallFilename() { +#if ARMEABI_V7A + return g_Config.memCardDirectory + "PSP/libs/armeabi-v7a/libat3plusdecoder.so"; +#else + return g_Config.memCardDirectory + "PSP/libs/armeabi/libat3plusdecoder.so"; +#endif + } + + // Android-only: From SD card. .so files must be in internal memory to load on many devices. + bool CanAutoInstall() { +#if defined(ANDROID) && defined(ARM) + // Android will auto install from SD card + if (File::Exists(GetAutoInstallFilename())) + return true; +#endif + + // Other platforms can't. + return false; + } + + bool IsInstalled() { + return File::Exists(GetInstalledFilename()); + } + + bool DoAutoInstall() { +#if defined(ANDROID) && defined(ARM) + std::string internalFilename = g_Config.internalDataDirectory + "libat3plusdecoder.so"; +#if ARMEABI_V7A + std::string sdFilename = g_Config.memCardDirectory + "PSP/libs/armeabi-v7a/libat3plusdecoder.so"; +#else + std::string sdFilename = g_Config.memCardDirectory + "PSP/libs/armeabi/libat3plusdecoder.so"; +#endif + + // SD cards are often mounted no-exec. + if (!File::Exists(internalFilename)) { + if (!File::Copy(sdFilename, internalFilename)) { + ELOG("Failed to copy %s to %s", sdFilename.c_str(), internalFilename.c_str()); + return false; + } + if (chmod(internalFilename.c_str(), 0777) < 0) { + ELOG("Failed to chmod %s, continuing anyway", internalFilename.c_str()); + } + } +#else + ELOG("Autoinstall is for android only"); +#endif + return true; + } + + int Init() { + if (!g_Config.bEnableAtrac3plus) + return -1; + // Let's always autoinstall if we can, to get the latest version. + // TODO: Make this look at file dates. + if (CanAutoInstall()) { + DoAutoInstall(); + } + + if (!IsInstalled()) { + // Okay, we're screwed. Let's bail. + return -1; + } + #ifdef _WIN32 #ifdef _M_X64 - hlib = LoadLibraryA("at3plusdecoder64.dll"); + hlib = LoadLibraryA(GetInstalledFilename().c_str()); #else - hlib = LoadLibraryA("at3plusdecoder.dll"); + hlib = LoadLibraryA(GetInstalledFilename().c_str()); #endif - if (hlib && g_Config.bEnableAtrac3plus) { + if (hlib) { frame_decoder = (ATRAC3PLUS_DECODEFRAME)GetProcAddress(hlib, "Atrac3plusDecoder_decodeFrame"); open_context = (ATRAC3PLUS_OPENCONTEXT)GetProcAddress(hlib, "Atrac3plusDecoder_openContext"); close_context = (ATRAC3PLUS_CLOSECONTEXT)GetProcAddress(hlib, "Atrac3plusDecoder_closeContext"); @@ -51,32 +126,9 @@ namespace Atrac3plus_Decoder { } #else -#if defined(ANDROID) && defined(ARM) - std::string sdFilename; - std::string internalFilename = g_Config.internalDataDirectory + "libat3plusdecoder.so"; -#if ARMEABI_V7A - sdFilename = g_Config.memCardDirectory + "PSP/libs/armeabi-v7a/libat3plusdecoder.so"; -#else - sdFilename = g_Config.memCardDirectory + "PSP/libs/armeabi/libat3plusdecoder.so"; -#endif - - // SD cards are often mounted no-exec. - if (!File::Exists(internalFilename)) { - if (!File::Copy(sdFilename, internalFilename)) { - ELOG("Failed to copy %s to %s", sdFilename.c_str(), internalFilename.c_str()); - return -1; - } - if (chmod(internalFilename.c_str(), 0777) < 0) { - ELOG("Failed to chmod %s, continuing anyway", internalFilename.c_str()); - } - } - std::string filename = internalFilename; -#else - std::string filename = "libat3plusdecoder.so"; -#endif + std::string filename = GetInstalledFilename(); ILOG("Attempting to load atrac3plus decoder from %s", filename.c_str()); - // TODO: from which directory on Android? so = dlopen(filename.c_str(), RTLD_LAZY); if (so) { frame_decoder = (ATRAC3PLUS_DECODEFRAME)dlsym(so, "Atrac3plusDecoder_decodeFrame"); @@ -100,8 +152,7 @@ namespace Atrac3plus_Decoder { return 0; } - int shutdowndecoder() { - + int Shutdown() { #ifdef _WIN32 if (hlib) { FreeLibrary(hlib); @@ -113,17 +164,19 @@ namespace Atrac3plus_Decoder { so = 0; } #endif // _WIN32 - + frame_decoder = 0; + open_context = 0; + close_context = 0; return 0; } - void* openContext() { + void* OpenContext() { if (!open_context) return 0; return open_context(); } - int closeContext(void** context) { + int CloseContext(Context *context) { if (!close_context || !context) return 0; close_context(*context); @@ -131,7 +184,7 @@ namespace Atrac3plus_Decoder { return 0; } - bool atrac3plus_decode(void* context, void* inbuf, int inbytes, int *outbytes, void* outbuf) { + bool Decode(Context context, void* inbuf, int inbytes, int *outbytes, void* outbuf) { if (!frame_decoder) { *outbytes = 0; return false; diff --git a/Core/HW/atrac3plus.h b/Core/HW/atrac3plus.h index cf5b9a0b7d..8562ee2622 100644 --- a/Core/HW/atrac3plus.h +++ b/Core/HW/atrac3plus.h @@ -2,12 +2,19 @@ #define _ATRAC3PLUS_DECODER_ namespace Atrac3plus_Decoder { - int initdecoder(); - int shutdowndecoder(); - void* openContext(); - int closeContext(void** context); - bool atrac3plus_decode(void* context, void* inbuf, int inbytes, int *outbytes, void* outbuf); + bool IsInstalled(); + bool CanAutoInstall(); + bool DoAutoInstall(); + + int Init(); + int Shutdown(); + + typedef void* Context; + + Context OpenContext(); + int CloseContext(Context *context); + bool Decode(Context context, void* inbuf, int inbytes, int *outbytes, void* outbuf); struct BufferQueue { BufferQueue(int size = 0x20000) { diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index 3f95fece2a..5d197b16bb 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -51,6 +51,7 @@ namespace MainWindow { #include "Common/StringUtils.h" #include "Core/System.h" #include "Core/CoreParameter.h" +#include "Core/HW/atrac3plus.h" #include "GPU/ge_constants.h" #include "GPU/GPUState.h" #include "GPU/GPUInterface.h" @@ -664,7 +665,9 @@ void AudioScreen::render() { int stride = 40; int columnw = 400; UICheckBox(GEN_ID, x, y += stride, a->T("Enable Sound"), ALIGN_TOPLEFT, &g_Config.bEnableSound); - UICheckBox(GEN_ID, x, y += stride, a->T("Enable Atrac3+"), ALIGN_TOPLEFT, &g_Config.bEnableAtrac3plus); + if (Atrac3plus_Decoder::IsInstalled()) { + UICheckBox(GEN_ID, x, y += stride, a->T("Enable Atrac3+"), ALIGN_TOPLEFT, &g_Config.bEnableAtrac3plus); + } UIEnd(); } diff --git a/UI/MenuScreens.h b/UI/MenuScreens.h index 6cc96045ee..2affbf1eab 100644 --- a/UI/MenuScreens.h +++ b/UI/MenuScreens.h @@ -24,7 +24,6 @@ #include "ui/screen.h" #include "ui/ui.h" #include "file/file_util.h" -#include "net/http_client.h" class LogoScreen : public Screen { diff --git a/native b/native index e2378dd970..4267d9903c 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit e2378dd970c2f876fcd3638c80493f3b938cfad8 +Subproject commit 4267d9903c7eb45769c81c48713bc15a4c7039e4