audio_core: hle: mf: address yet another batch of reviews
This commit is contained in:
parent
ab1f47ed15
commit
6281660844
|
@ -20,4 +20,4 @@ ADTSData ParseADTS(const char* buffer);
|
||||||
|
|
||||||
// last two bytes of MF AAC decoder user data
|
// last two bytes of MF AAC decoder user data
|
||||||
// see https://docs.microsoft.com/en-us/windows/desktop/medfound/aac-decoder#example-media-types
|
// see https://docs.microsoft.com/en-us/windows/desktop/medfound/aac-decoder#example-media-types
|
||||||
u16 MFGetAACTag(const ADTSData input);
|
u16 MFGetAACTag(const ADTSData& input);
|
||||||
|
|
|
@ -50,7 +50,7 @@ ADTSData ParseADTS(const char* buffer) {
|
||||||
// Frame length flag (1 bit)
|
// Frame length flag (1 bit)
|
||||||
// Depends on core coder (1 bit)
|
// Depends on core coder (1 bit)
|
||||||
// Extension flag (1 bit)
|
// Extension flag (1 bit)
|
||||||
u16 MFGetAACTag(const ADTSData input) {
|
u16 MFGetAACTag(const ADTSData& input) {
|
||||||
u16 tag = 0;
|
u16 tag = 0;
|
||||||
|
|
||||||
tag |= input.profile << 11;
|
tag |= input.profile << 11;
|
||||||
|
|
|
@ -22,7 +22,7 @@ private:
|
||||||
|
|
||||||
MFOutputState DecodingLoop(ADTSData adts_header, std::array<std::vector<u8>, 2>& out_streams);
|
MFOutputState DecodingLoop(ADTSData adts_header, std::array<std::vector<u8>, 2>& out_streams);
|
||||||
|
|
||||||
bool initalized = false;
|
bool initialized = false;
|
||||||
bool selected = false;
|
bool selected = false;
|
||||||
|
|
||||||
Memory::MemorySystem& memory;
|
Memory::MemorySystem& memory;
|
||||||
|
@ -36,7 +36,9 @@ WMFDecoder::Impl::Impl(Memory::MemorySystem& memory) : memory(memory) {
|
||||||
MFCoInit();
|
MFCoInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
WMFDecoder::Impl::~Impl() = default;
|
WMFDecoder::Impl::~Impl() {
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<BinaryResponse> WMFDecoder::Impl::ProcessRequest(const BinaryRequest& request) {
|
std::optional<BinaryResponse> WMFDecoder::Impl::ProcessRequest(const BinaryRequest& request) {
|
||||||
if (request.codec != DecoderCodec::AAC) {
|
if (request.codec != DecoderCodec::AAC) {
|
||||||
|
@ -65,7 +67,7 @@ std::optional<BinaryResponse> WMFDecoder::Impl::ProcessRequest(const BinaryReque
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<BinaryResponse> WMFDecoder::Impl::Initalize(const BinaryRequest& request) {
|
std::optional<BinaryResponse> WMFDecoder::Impl::Initalize(const BinaryRequest& request) {
|
||||||
if (initalized) {
|
if (initialized) {
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,16 +91,16 @@ std::optional<BinaryResponse> WMFDecoder::Impl::Initalize(const BinaryRequest& r
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
initalized = true;
|
initialized = true;
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WMFDecoder::Impl::Clear() {
|
void WMFDecoder::Impl::Clear() {
|
||||||
if (initalized) {
|
if (initialized) {
|
||||||
MFFlush(transform.get());
|
MFFlush(transform.get());
|
||||||
MFDeInit(transform.get());
|
MFDestroy();
|
||||||
}
|
}
|
||||||
initalized = false;
|
initialized = false;
|
||||||
selected = false;
|
selected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +119,7 @@ MFOutputState WMFDecoder::Impl::DecodingLoop(ADTSData adts_header,
|
||||||
|
|
||||||
// the following was taken from ffmpeg version of the decoder
|
// the following was taken from ffmpeg version of the decoder
|
||||||
f32 val_f32;
|
f32 val_f32;
|
||||||
for (size_t i = 0; i < output_buffer->size();) {
|
for (std::size_t i = 0; i < output_buffer->size();) {
|
||||||
for (std::size_t channel = 0; channel < adts_header.channels; channel++) {
|
for (std::size_t channel = 0; channel < adts_header.channels; channel++) {
|
||||||
val_f32 = output_buffer->at(i);
|
val_f32 = output_buffer->at(i);
|
||||||
s16 val = static_cast<s16>(0x7FFF * val_f32);
|
s16 val = static_cast<s16>(0x7FFF * val_f32);
|
||||||
|
@ -161,8 +163,8 @@ std::optional<BinaryResponse> WMFDecoder::Impl::Decode(const BinaryRequest& requ
|
||||||
response.num_channels = 2;
|
response.num_channels = 2;
|
||||||
response.num_samples = 1024;
|
response.num_samples = 1024;
|
||||||
|
|
||||||
if (!initalized) {
|
if (!initialized) {
|
||||||
LOG_DEBUG(Audio_DSP, "Decoder not initalized");
|
LOG_DEBUG(Audio_DSP, "Decoder not initialized");
|
||||||
// This is a hack to continue games when decoder failed to initialize
|
// This is a hack to continue games when decoder failed to initialize
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
|
#include "common/string_util.h"
|
||||||
#include "wmf_decoder_utils.h"
|
#include "wmf_decoder_utils.h"
|
||||||
|
|
||||||
// utility functions
|
// utility functions
|
||||||
|
@ -9,16 +10,17 @@ void ReportError(std::string msg, HRESULT hr) {
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LPSTR err;
|
LPWSTR err;
|
||||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
nullptr, hr,
|
nullptr, hr,
|
||||||
// hardcode to use en_US because if any user had problems with this
|
// hardcode to use en_US because if any user had problems with this
|
||||||
// we can help them w/o translating anything
|
// we can help them w/o translating anything
|
||||||
// default is to use the language currently active on the operating system
|
// default is to use the language currently active on the operating system
|
||||||
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPSTR)&err, 0, nullptr);
|
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPWSTR)&err, 0, nullptr);
|
||||||
if (err != nullptr) {
|
if (err != nullptr) {
|
||||||
LOG_CRITICAL(Audio_DSP, "{}: {}", msg, err);
|
LOG_CRITICAL(Audio_DSP, "{}: {}", msg, Common::UTF16ToUTF8(err));
|
||||||
|
LocalFree(err);
|
||||||
}
|
}
|
||||||
LOG_CRITICAL(Audio_DSP, "{}: {:08x}", msg, hr);
|
LOG_CRITICAL(Audio_DSP, "{}: {:08x}", msg, hr);
|
||||||
}
|
}
|
||||||
|
@ -82,8 +84,8 @@ unique_mfptr<IMFTransform> MFDecoderInit(GUID audio_format) {
|
||||||
return std::move(transform);
|
return std::move(transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFDeInit(IMFTransform* transform) {
|
void MFDestroy() {
|
||||||
MFShutdownObject(transform);
|
MFShutdown();
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,11 +128,11 @@ unique_mfptr<IMFSample> CreateSample(void* data, DWORD len, DWORD alignment, LON
|
||||||
ReportError("Unable to set sample duration, but continuing anyway", hr);
|
ReportError("Unable to set sample duration, but continuing anyway", hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::move(sample);
|
return sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SelectInputMediaType(IMFTransform* transform, int in_stream_id, const ADTSData& adts,
|
bool SelectInputMediaType(IMFTransform* transform, int in_stream_id, const ADTSData& adts,
|
||||||
UINT8* user_data, UINT32 user_data_len, GUID audio_format) {
|
const UINT8* user_data, UINT32 user_data_len, GUID audio_format) {
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
unique_mfptr<IMFMediaType> t;
|
unique_mfptr<IMFMediaType> t;
|
||||||
|
|
||||||
|
@ -209,7 +211,7 @@ bool SelectOutputMediaType(IMFTransform* transform, int out_stream_id, GUID audi
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<ADTSMeta> DetectMediaType(char* buffer, size_t len) {
|
std::optional<ADTSMeta> DetectMediaType(char* buffer, std::size_t len) {
|
||||||
if (len < 7) {
|
if (len < 7) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,14 @@ struct MFRelease {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct MFRelease<IMFTransform> {
|
||||||
|
void operator()(IMFTransform* pointer) const {
|
||||||
|
MFShutdownObject(pointer);
|
||||||
|
pointer->Release();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// wrapper facilities for dealing with pointers
|
// wrapper facilities for dealing with pointers
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using unique_mfptr = std::unique_ptr<T, MFRelease<T>>;
|
using unique_mfptr = std::unique_ptr<T, MFRelease<T>>;
|
||||||
|
@ -67,13 +75,13 @@ struct ADTSMeta {
|
||||||
// exported functions
|
// exported functions
|
||||||
bool MFCoInit();
|
bool MFCoInit();
|
||||||
unique_mfptr<IMFTransform> MFDecoderInit(GUID audio_format = MFAudioFormat_AAC);
|
unique_mfptr<IMFTransform> MFDecoderInit(GUID audio_format = MFAudioFormat_AAC);
|
||||||
void MFDeInit(IMFTransform* transform);
|
void MFDestroy();
|
||||||
unique_mfptr<IMFSample> CreateSample(void* data, DWORD len, DWORD alignment = 1,
|
unique_mfptr<IMFSample> CreateSample(void* data, DWORD len, DWORD alignment = 1,
|
||||||
LONGLONG duration = 0);
|
LONGLONG duration = 0);
|
||||||
bool SelectInputMediaType(IMFTransform* transform, int in_stream_id, const ADTSData& adts,
|
bool SelectInputMediaType(IMFTransform* transform, int in_stream_id, const ADTSData& adts,
|
||||||
UINT8* user_data, UINT32 user_data_len,
|
const UINT8* user_data, UINT32 user_data_len,
|
||||||
GUID audio_format = MFAudioFormat_AAC);
|
GUID audio_format = MFAudioFormat_AAC);
|
||||||
std::optional<ADTSMeta> DetectMediaType(char* buffer, size_t len);
|
std::optional<ADTSMeta> DetectMediaType(char* buffer, std::size_t len);
|
||||||
bool SelectOutputMediaType(IMFTransform* transform, int out_stream_id,
|
bool SelectOutputMediaType(IMFTransform* transform, int out_stream_id,
|
||||||
GUID audio_format = MFAudioFormat_PCM);
|
GUID audio_format = MFAudioFormat_PCM);
|
||||||
void MFFlush(IMFTransform* transform);
|
void MFFlush(IMFTransform* transform);
|
||||||
|
|
Reference in New Issue