citra-emu
/
citra-canary
Archived
1
0
Fork 0

FFmpegDL: Added external_dlls folder to user folder

AACDecoder: addressed reviews
This commit is contained in:
B3N30 2018-12-15 21:33:33 +01:00
parent 45b5de7a18
commit 847003cc1c
5 changed files with 27 additions and 18 deletions

View File

@ -9,7 +9,7 @@ namespace AudioCore::HLE {
class AACDecoder::Impl { class AACDecoder::Impl {
public: public:
Impl(Memory::MemorySystem& memory); explicit Impl(Memory::MemorySystem& memory);
~Impl(); ~Impl();
std::optional<BinaryResponse> ProcessRequest(const BinaryRequest& request); std::optional<BinaryResponse> ProcessRequest(const BinaryRequest& request);
@ -77,8 +77,12 @@ std::optional<BinaryResponse> AACDecoder::Impl::Initalize(const BinaryRequest& r
Clear(); Clear();
} }
BinaryResponse response;
std::memcpy(&response, &request, sizeof(response));
response.unknown1 = 0x0;
if (!have_ffmpeg_dl) { if (!have_ffmpeg_dl) {
return {}; return response;
} }
av_packet = av_packet_alloc_dl(); av_packet = av_packet_alloc_dl();
@ -86,31 +90,27 @@ std::optional<BinaryResponse> AACDecoder::Impl::Initalize(const BinaryRequest& r
codec = avcodec_find_decoder_dl(AV_CODEC_ID_AAC); codec = avcodec_find_decoder_dl(AV_CODEC_ID_AAC);
if (!codec) { if (!codec) {
LOG_ERROR(Audio_DSP, "Codec not found\n"); LOG_ERROR(Audio_DSP, "Codec not found\n");
return {}; return response;
} }
parser = av_parser_init_dl(codec->id); parser = av_parser_init_dl(codec->id);
if (!parser) { if (!parser) {
LOG_ERROR(Audio_DSP, "Parser not found\n"); LOG_ERROR(Audio_DSP, "Parser not found\n");
return {}; return response;
} }
av_context = avcodec_alloc_context3_dl(codec); av_context = avcodec_alloc_context3_dl(codec);
if (!av_context) { if (!av_context) {
LOG_ERROR(Audio_DSP, "Could not allocate audio codec context\n"); LOG_ERROR(Audio_DSP, "Could not allocate audio codec context\n");
return {}; return response;
} }
if (avcodec_open2_dl(av_context, codec, NULL) < 0) { if (avcodec_open2_dl(av_context, codec, NULL) < 0) {
LOG_ERROR(Audio_DSP, "Could not open codec\n"); LOG_ERROR(Audio_DSP, "Could not open codec\n");
return {}; return response;
} }
initalized = true; initalized = true;
BinaryResponse response;
std::memcpy(&response, &request, sizeof(response));
response.unknown1 = 0x0;
return response; return response;
} }
@ -139,7 +139,8 @@ std::optional<BinaryResponse> AACDecoder::Impl::Decode(const BinaryRequest& requ
return response; return response;
} }
if (request.src_addr < Memory::FCRAM_PADDR) { if (request.src_addr < Memory::FCRAM_PADDR ||
request.src_addr + request.size > Memory::FCRAM_PADDR + Memory::FCRAM_SIZE) {
LOG_ERROR(Audio_DSP, "Got out of bounds src_addr {:08x}", request.src_addr); LOG_ERROR(Audio_DSP, "Got out of bounds src_addr {:08x}", request.src_addr);
return {}; return {};
} }
@ -190,7 +191,7 @@ std::optional<BinaryResponse> AACDecoder::Impl::Decode(const BinaryRequest& requ
std::size_t size = bytes_per_sample * (decoded_frame->nb_samples); std::size_t size = bytes_per_sample * (decoded_frame->nb_samples);
// FFmpeg converts to 32 signed floating point PCM, we need s32 PCM so we need to // FFmpeg converts to 32 signed floating point PCM, we need s16 PCM so we need to
// convert it // convert it
f32 val_float; f32 val_float;
for (std::size_t current_pos(0); current_pos < size;) { for (std::size_t current_pos(0); current_pos < size;) {
@ -207,14 +208,16 @@ std::optional<BinaryResponse> AACDecoder::Impl::Decode(const BinaryRequest& requ
} }
} }
if (request.dst_addr_ch0 < Memory::FCRAM_PADDR) { if (request.dst_addr_ch0 < Memory::FCRAM_PADDR ||
request.dst_addr_ch0 + out_streams[0].size() > Memory::FCRAM_PADDR + Memory::FCRAM_SIZE) {
LOG_ERROR(Audio_DSP, "Got out of bounds dst_addr_ch0 {:08x}", request.dst_addr_ch0); LOG_ERROR(Audio_DSP, "Got out of bounds dst_addr_ch0 {:08x}", request.dst_addr_ch0);
return {}; return {};
} }
std::memcpy(memory.GetFCRAMPointer(request.dst_addr_ch0 - Memory::FCRAM_PADDR), std::memcpy(memory.GetFCRAMPointer(request.dst_addr_ch0 - Memory::FCRAM_PADDR),
out_streams[0].data(), out_streams[0].size()); out_streams[0].data(), out_streams[0].size());
if (request.dst_addr_ch1 < Memory::FCRAM_PADDR) { if (request.dst_addr_ch1 < Memory::FCRAM_PADDR ||
request.dst_addr_ch1 + out_streams[1].size() > Memory::FCRAM_PADDR + Memory::FCRAM_SIZE) {
LOG_ERROR(Audio_DSP, "Got out of bounds dst_addr_ch1 {:08x}", request.dst_addr_ch1); LOG_ERROR(Audio_DSP, "Got out of bounds dst_addr_ch1 {:08x}", request.dst_addr_ch1);
return {}; return {};
} }

View File

@ -8,6 +8,7 @@
#include <windows.h> #include <windows.h>
#endif // _WIN32 #endif // _WIN32
#include "common/file_util.h"
#include "common/logging/log.h" #include "common/logging/log.h"
extern "C" { extern "C" {
@ -20,9 +21,8 @@ template <typename T>
struct FuncDL { struct FuncDL {
FuncDL() = default; FuncDL() = default;
FuncDL(HMODULE dll, const char* name) { FuncDL(HMODULE dll, const char* name) {
ptr_function = nullptr;
if (dll) { if (dll) {
*(void**)&ptr_function = (void*)GetProcAddress(dll, name); ptr_function = reinterpret_cast<T*>(GetProcAddress(dll, name));
} }
} }
@ -35,7 +35,6 @@ struct FuncDL {
} }
T* ptr_function = nullptr; T* ptr_function = nullptr;
;
}; };
FuncDL<int(AVSampleFormat)> av_get_bytes_per_sample_dl; FuncDL<int(AVSampleFormat)> av_get_bytes_per_sample_dl;
@ -56,6 +55,10 @@ FuncDL<int(AVCodecParserContext*, AVCodecContext*, uint8_t**, int*, const uint8_
FuncDL<void(AVCodecParserContext*)> av_parser_close_dl; FuncDL<void(AVCodecParserContext*)> av_parser_close_dl;
bool InitFFmpegDL() { bool InitFFmpegDL() {
FileUtil::CreateDir(FileUtil::GetUserPath(FileUtil::UserPath::DLLDir));
SetDllDirectoryA(FileUtil::GetUserPath(FileUtil::UserPath::DLLDir).c_str());
HMODULE dll_util = nullptr; HMODULE dll_util = nullptr;
dll_util = LoadLibrary("avutil-56.dll"); dll_util = LoadLibrary("avutil-56.dll");
if (!dll_util) { if (!dll_util) {

View File

@ -38,6 +38,7 @@
#define SYSDATA_DIR "sysdata" #define SYSDATA_DIR "sysdata"
#define LOG_DIR "log" #define LOG_DIR "log"
#define CHEATS_DIR "cheats" #define CHEATS_DIR "cheats"
#define DLL_DIR "external_dlls"
// Filenames // Filenames
// Files in the directory returned by GetUserPath(UserPath::LogDir) // Files in the directory returned by GetUserPath(UserPath::LogDir)

View File

@ -711,6 +711,7 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) {
// TODO: Put the logs in a better location for each OS // TODO: Put the logs in a better location for each OS
paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP); paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP);
paths.emplace(UserPath::CheatsDir, user_path + CHEATS_DIR DIR_SEP); paths.emplace(UserPath::CheatsDir, user_path + CHEATS_DIR DIR_SEP);
paths.emplace(UserPath::DLLDir, user_path + DLL_DIR DIR_SEP);
} }
if (!new_path.empty()) { if (!new_path.empty()) {

View File

@ -24,6 +24,7 @@ enum class UserPath {
CacheDir, CacheDir,
CheatsDir, CheatsDir,
ConfigDir, ConfigDir,
DLLDir,
LogDir, LogDir,
NANDDir, NANDDir,
RootDir, RootDir,