audio_core: hle: mf: use more enum

This commit is contained in:
liushuyu 2019-01-28 22:53:55 -07:00 committed by B3N30
parent be764e4f88
commit 452ac7b874
3 changed files with 14 additions and 12 deletions

View file

@ -104,7 +104,7 @@ void WMFDecoder::Impl::Clear() {
} }
MFOutputState WMFDecoder::Impl::DecodingLoop(ADTSData adts_header, MFOutputState WMFDecoder::Impl::DecodingLoop(ADTSData adts_header,
std::array<std::vector<u8>, 2>& out_streams) { std::array<std::vector<u8>, 2>& out_streams) {
MFOutputState output_status = OK; MFOutputState output_status = OK;
char* output_buffer = nullptr; char* output_buffer = nullptr;
DWORD output_len = 0; DWORD output_len = 0;
@ -184,7 +184,7 @@ std::optional<BinaryResponse> WMFDecoder::Impl::Decode(const BinaryRequest& requ
unique_mfptr<IMFSample> sample; unique_mfptr<IMFSample> sample;
ADTSData adts_header; ADTSData adts_header;
char* aac_tag = (char*)calloc(1, 14); char* aac_tag = (char*)calloc(1, 14);
int input_status = 0; MFInputState input_status = INPUT_OK;
if (DetectMediaType((char*)data, request.size, &adts_header, &aac_tag) != 0) { if (DetectMediaType((char*)data, request.size, &adts_header, &aac_tag) != 0) {
LOG_ERROR(Audio_DSP, "Unable to deduce decoding parameters from ADTS stream"); LOG_ERROR(Audio_DSP, "Unable to deduce decoding parameters from ADTS stream");
@ -215,7 +215,7 @@ std::optional<BinaryResponse> WMFDecoder::Impl::Decode(const BinaryRequest& requ
// if the decode issues are caused by MFT not accepting new samples, try again // if the decode issues are caused by MFT not accepting new samples, try again
// NOTICE: you are required to check the output even if you already knew/guessed // NOTICE: you are required to check the output even if you already knew/guessed
// MFT didn't accept the input sample // MFT didn't accept the input sample
if (input_status == 1) { if (input_status == TRY_AGAIN) {
// try again // try again
continue; continue;
} }

View file

@ -234,26 +234,26 @@ int DetectMediaType(char* buffer, size_t len, ADTSData* output, char** aac_tag)
} }
void MFFlush(IMFTransform* transform) { void MFFlush(IMFTransform* transform) {
HRESULT hr = (transform)->ProcessMessage(MFT_MESSAGE_COMMAND_FLUSH, 0); HRESULT hr = transform->ProcessMessage(MFT_MESSAGE_COMMAND_FLUSH, 0);
if (FAILED(hr)) { if (FAILED(hr)) {
ReportError("MFT: Flush command failed", hr); ReportError("MFT: Flush command failed", hr);
} }
hr = (transform)->ProcessMessage(MFT_MESSAGE_NOTIFY_END_OF_STREAM, 0); hr = transform->ProcessMessage(MFT_MESSAGE_NOTIFY_END_OF_STREAM, 0);
if (FAILED(hr)) { if (FAILED(hr)) {
ReportError("Failed to end streaming for MFT", hr); ReportError("Failed to end streaming for MFT", hr);
} }
} }
int SendSample(IMFTransform* transform, DWORD in_stream_id, IMFSample* in_sample) { MFInputState SendSample(IMFTransform* transform, DWORD in_stream_id, IMFSample* in_sample) {
HRESULT hr = S_OK; HRESULT hr = S_OK;
if (in_sample) { if (in_sample) {
hr = transform->ProcessInput(in_stream_id, in_sample, 0); hr = transform->ProcessInput(in_stream_id, in_sample, 0);
if (hr == MF_E_NOTACCEPTING) { if (hr == MF_E_NOTACCEPTING) {
return 1; // try again return TRY_AGAIN; // try again
} else if (FAILED(hr)) { } else if (FAILED(hr)) {
ReportError("MFT: Failed to process input", hr); ReportError("MFT: Failed to process input", hr);
return -1; return INPUT_ERROR;
} // FAILED(hr) } // FAILED(hr)
} else { } else {
hr = transform->ProcessMessage(MFT_MESSAGE_COMMAND_DRAIN, 0); hr = transform->ProcessMessage(MFT_MESSAGE_COMMAND_DRAIN, 0);
@ -262,7 +262,7 @@ int SendSample(IMFTransform* transform, DWORD in_stream_id, IMFSample* in_sample
} }
} }
return 0; return INPUT_OK;
} }
std::tuple<MFOutputState, unique_mfptr<IMFSample>> ReceiveSample(IMFTransform* transform, std::tuple<MFOutputState, unique_mfptr<IMFSample>> ReceiveSample(IMFTransform* transform,

View file

@ -17,7 +17,8 @@
#include "adts.h" #include "adts.h"
enum MFOutputState { FATAL_ERROR = -1, OK = 0, NEED_MORE_INPUT, NEED_RECONFIG, HAVE_MORE_DATA }; enum MFOutputState { FATAL_ERROR, OK, NEED_MORE_INPUT, NEED_RECONFIG, HAVE_MORE_DATA };
enum MFInputState { INPUT_ERROR, INPUT_OK, TRY_AGAIN };
// utility functions // utility functions
template <class T> template <class T>
@ -36,7 +37,8 @@ void ReportError(std::string msg, HRESULT hr);
bool MFCoInit(); bool MFCoInit();
bool MFDecoderInit(IMFTransform** transform, GUID audio_format = MFAudioFormat_AAC); bool MFDecoderInit(IMFTransform** transform, GUID audio_format = MFAudioFormat_AAC);
void MFDeInit(IMFTransform* transform); void MFDeInit(IMFTransform* transform);
unique_mfptr<IMFSample> CreateSample(void* data, DWORD len, DWORD alignment = 1, LONGLONG duration = 0); unique_mfptr<IMFSample> CreateSample(void* data, DWORD len, DWORD alignment = 1,
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, UINT8* user_data, UINT32 user_data_len,
GUID audio_format = MFAudioFormat_AAC); GUID audio_format = MFAudioFormat_AAC);
@ -44,7 +46,7 @@ int DetectMediaType(char* buffer, size_t len, ADTSData* output, char** aac_tag);
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);
int SendSample(IMFTransform* transform, DWORD in_stream_id, IMFSample* in_sample); MFInputState SendSample(IMFTransform* transform, DWORD in_stream_id, IMFSample* in_sample);
std::tuple<MFOutputState, unique_mfptr<IMFSample>> ReceiveSample(IMFTransform* transform, std::tuple<MFOutputState, unique_mfptr<IMFSample>> ReceiveSample(IMFTransform* transform,
DWORD out_stream_id); DWORD out_stream_id);
int CopySampleToBuffer(IMFSample* sample, void** output, DWORD* len); int CopySampleToBuffer(IMFSample* sample, void** output, DWORD* len);