mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-27 20:14:17 +01:00
audio_core: mf: make initialize function return smart pointer
This commit is contained in:
parent
c91f5029ff
commit
168f2ee79a
@ -72,8 +72,9 @@ std::optional<BinaryResponse> WMFDecoder::Impl::Initalize(const BinaryRequest& r
|
|||||||
BinaryResponse response;
|
BinaryResponse response;
|
||||||
std::memcpy(&response, &request, sizeof(response));
|
std::memcpy(&response, &request, sizeof(response));
|
||||||
response.unknown1 = 0x0;
|
response.unknown1 = 0x0;
|
||||||
|
transform = MFDecoderInit();
|
||||||
|
|
||||||
if (!MFDecoderInit(Amp(transform))) {
|
if (transform == nullptr) {
|
||||||
LOG_CRITICAL(Audio_DSP, "Can't init decoder");
|
LOG_CRITICAL(Audio_DSP, "Can't init decoder");
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@ -116,7 +117,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 (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);
|
||||||
|
@ -45,11 +45,12 @@ bool MFCoInit() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MFDecoderInit(IMFTransform** transform, GUID audio_format) {
|
unique_mfptr<IMFTransform> MFDecoderInit(GUID audio_format) {
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
MFT_REGISTER_TYPE_INFO reg = {0};
|
MFT_REGISTER_TYPE_INFO reg = {0};
|
||||||
GUID category = MFT_CATEGORY_AUDIO_DECODER;
|
GUID category = MFT_CATEGORY_AUDIO_DECODER;
|
||||||
IMFActivate** activate;
|
IMFActivate** activate;
|
||||||
|
unique_mfptr<IMFTransform> transform;
|
||||||
UINT32 num_activate;
|
UINT32 num_activate;
|
||||||
|
|
||||||
reg.guidMajorType = MFMediaType_Audio;
|
reg.guidMajorType = MFMediaType_Audio;
|
||||||
@ -61,22 +62,24 @@ bool MFDecoderInit(IMFTransform** transform, GUID audio_format) {
|
|||||||
if (FAILED(hr) || num_activate < 1) {
|
if (FAILED(hr) || num_activate < 1) {
|
||||||
ReportError("Failed to enumerate decoders", hr);
|
ReportError("Failed to enumerate decoders", hr);
|
||||||
CoTaskMemFree(activate);
|
CoTaskMemFree(activate);
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
LOG_INFO(Audio_DSP, "Windows(R) Media Foundation found {} suitable decoder(s)", num_activate);
|
LOG_INFO(Audio_DSP, "Windows(R) Media Foundation found {} suitable decoder(s)", num_activate);
|
||||||
for (unsigned int n = 0; n < num_activate; n++) {
|
for (unsigned int n = 0; n < num_activate; n++) {
|
||||||
hr = activate[n]->ActivateObject(IID_IMFTransform, (void**)transform);
|
hr = activate[n]->ActivateObject(
|
||||||
|
IID_IMFTransform,
|
||||||
|
reinterpret_cast<void**>(static_cast<IMFTransform**>(Amp(transform))));
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
*transform = nullptr;
|
transform = nullptr;
|
||||||
activate[n]->Release();
|
activate[n]->Release();
|
||||||
}
|
}
|
||||||
if (*transform == nullptr) {
|
if (transform == nullptr) {
|
||||||
ReportError("Failed to initialize MFT", hr);
|
ReportError("Failed to initialize MFT", hr);
|
||||||
CoTaskMemFree(activate);
|
CoTaskMemFree(activate);
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
CoTaskMemFree(activate);
|
CoTaskMemFree(activate);
|
||||||
return true;
|
return std::move(transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFDeInit(IMFTransform* transform) {
|
void MFDeInit(IMFTransform* transform) {
|
||||||
|
@ -60,7 +60,7 @@ void ReportError(std::string msg, HRESULT hr);
|
|||||||
|
|
||||||
// exported functions
|
// exported functions
|
||||||
bool MFCoInit();
|
bool MFCoInit();
|
||||||
bool MFDecoderInit(IMFTransform** transform, GUID audio_format = MFAudioFormat_AAC);
|
unique_mfptr<IMFTransform> MFDecoderInit(GUID audio_format = MFAudioFormat_AAC);
|
||||||
void MFDeInit(IMFTransform* transform);
|
void MFDeInit(IMFTransform* transform);
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user