Commit 2e909fc4 authored by Richard Gobeille's avatar Richard Gobeille
Browse files

audiolib: throw errors when vorbis and XMP decoder initialization in a worker...

audiolib: throw errors when vorbis and XMP decoder initialization in a worker thread fails, validate result of worker thread decoder initialization before allowing MV_Mix() to proceed with working with the voice

Untested beyond the obvious stuff like verifying the non-failure cases still produce non-failure results. These errors were still being handled before this commit, but it was in more of a rudimentary "do nothing and silently fail" sort of way.
parent 25b63ddc
......@@ -178,7 +178,7 @@ typedef struct VoiceNode
int handle;
int priority;
async::task<void> task;
async::task<int> task;
} VoiceNode;
typedef struct
......
......@@ -110,6 +110,20 @@ static VoiceNode **MV_Handles;
static bool MV_Mix(VoiceNode * const voice, int const buffer)
{
if (voice->task.valid())
{
if (!voice->task.ready())
return true;
auto result = voice->task.get();
if (result != MV_Ok)
{
MV_Printf("Error playing sound % " PRIdPTR ": %s\n", voice->callbackval, MV_ErrorString(result));
return false;
}
}
if (voice->length == 0 && voice->GetSound(voice) != KeepPlaying)
return false;
......
......@@ -365,7 +365,7 @@ int MV_PlayVorbis(char *ptr, uint32_t length, int loopstart, int loopend, int pi
//if (vd->task.valid() && !vd->task.ready())
// vd->task.wait();
voice->task = async::spawn([voice]
voice->task = async::spawn([voice]() -> int
{
#if defined _WIN32 && !defined NDEBUG
debugThreadName("MV_PlayVorbis");
......@@ -379,7 +379,7 @@ int MV_PlayVorbis(char *ptr, uint32_t length, int loopstart, int loopend, int pi
{
voice->rawdatasiz = 0;
MV_PlayVoice(voice);
return;
return MV_SetErrorCode(MV_VoiceNotFound);
}
int status = ov_open_callbacks((void *)vd, &vd->vf, 0, 0, vorbis_callbacks);
......@@ -394,9 +394,8 @@ int MV_PlayVorbis(char *ptr, uint32_t length, int loopstart, int loopend, int pi
ALIGNED_FREE_AND_NULL(voice->rawdataptr);
voice->rawdatasiz = 0;
MV_SetErrorCode(MV_InvalidFile);
MV_PlayVoice(voice);
return;
return MV_SetErrorCode(MV_InvalidFile);
}
voice->channels = vi->channels;
......@@ -408,6 +407,7 @@ int MV_PlayVorbis(char *ptr, uint32_t length, int loopstart, int loopend, int pi
MV_SetVoicePitch(voice, vi->rate, vd->lastbitstream);
vd->lastbitstream = -1;
MV_PlayVoice(voice);
return MV_Ok;
});
return voice->handle;
......
......@@ -117,7 +117,7 @@ int MV_PlayXMP(char *ptr, uint32_t length, int loopstart, int loopend, int pitch
xd->ptr = ptr;
xd->length = length;
voice->task = async::spawn([voice]
voice->task = async::spawn([voice]() -> int
{
auto xd = (xmp_data *)voice->rawdataptr;
auto ctx = xd->ctx;
......@@ -141,9 +141,8 @@ int MV_PlayXMP(char *ptr, uint32_t length, int loopstart, int loopend, int pitch
ALIGNED_FREE_AND_NULL(voice->rawdataptr);
voice->rawdatasiz = 0;
MV_SetErrorCode(MV_InvalidFile);
MV_PlayVoice(voice);
return;
return MV_SetErrorCode(MV_InvalidFile);
}
xmp_start_player(ctx, MV_MixRate, 0);
......@@ -153,6 +152,7 @@ int MV_PlayXMP(char *ptr, uint32_t length, int loopstart, int loopend, int pitch
voice->RateScale = divideu64((uint64_t)voice->SamplingRate * voice->PitchScale, MV_MixRate);
voice->FixedPointBufferSize = (voice->RateScale * MV_MIXBUFFERSIZE) - voice->RateScale;
MV_PlayVoice(voice);
return MV_Ok;
}
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment