Fixed error checking and recording reset.

This commit is contained in:
Armin Novak 2015-09-07 09:24:45 +02:00
parent 17834af7bb
commit d07875b7ea

View File

@ -100,7 +100,8 @@ static DWORD audin_winmm_thread_func(void* arg)
char *buffer; char *buffer;
int size, i; int size, i;
WAVEHDR waveHdr[4]; WAVEHDR waveHdr[4];
DWORD status; DWORD status;
MMRESULT rc;
if (!winmm->hWaveIn) if (!winmm->hWaveIn)
{ {
@ -122,44 +123,68 @@ static DWORD audin_winmm_thread_func(void* arg)
waveHdr[i].dwBufferLength = size; waveHdr[i].dwBufferLength = size;
waveHdr[i].dwFlags = 0; waveHdr[i].dwFlags = 0;
waveHdr[i].lpData = buffer; waveHdr[i].lpData = buffer;
if (MMSYSERR_NOERROR != waveInPrepareHeader(winmm->hWaveIn, &waveHdr[i], sizeof(waveHdr[i])))
rc = waveInPrepareHeader(winmm->hWaveIn, &waveHdr[i], sizeof(waveHdr[i]));
if (MMSYSERR_NOERROR != rc)
{ {
DEBUG_DVC("waveInPrepareHeader failed."); DEBUG_DVC("waveInPrepareHeader failed. %d", rc);
if (winmm->rdpcontext) if (winmm->rdpcontext)
setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, "audin_winmm_thread_func reported an error"); setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, "audin_winmm_thread_func reported an error");
} }
if (MMSYSERR_NOERROR != waveInAddBuffer(winmm->hWaveIn, &waveHdr[i], sizeof(waveHdr[i])))
rc = waveInAddBuffer(winmm->hWaveIn, &waveHdr[i], sizeof(waveHdr[i]));
if (MMSYSERR_NOERROR != rc)
{ {
DEBUG_DVC("waveInAddBuffer failed."); DEBUG_DVC("waveInAddBuffer failed. %d", rc);
if (winmm->rdpcontext) if (winmm->rdpcontext)
setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, "audin_winmm_thread_func reported an error"); setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, "audin_winmm_thread_func reported an error");
} }
} }
waveInStart(winmm->hWaveIn);
rc = waveInStart(winmm->hWaveIn);
if (MMSYSERR_NOERROR != rc)
{
DEBUG_DVC("waveInStart failed. %d", rc);
if (winmm->rdpcontext)
setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, "audin_winmm_thread_func reported an error");
}
status = WaitForSingleObject(winmm->stopEvent, INFINITE); status = WaitForSingleObject(winmm->stopEvent, INFINITE);
if (status == WAIT_FAILED) if (status == WAIT_FAILED)
{ {
DEBUG_DVC("WaitForSingleObject failed."); DEBUG_DVC("WaitForSingleObject failed.");
if (winmm->rdpcontext) if (winmm->rdpcontext)
setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, "audin_winmm_thread_func reported an error"); setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, "audin_winmm_thread_func reported an error");
} }
waveInStop(winmm->hWaveIn); rc = waveInReset(winmm->hWaveIn);
if (MMSYSERR_NOERROR != rc)
{
DEBUG_DVC("waveInReset failed. %d", rc);
if (winmm->rdpcontext)
setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, "audin_winmm_thread_func reported an error");
}
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
if (MMSYSERR_NOERROR != waveInUnprepareHeader(winmm->hWaveIn, &waveHdr[i], sizeof(waveHdr[i]))) rc = waveInUnprepareHeader(winmm->hWaveIn, &waveHdr[i], sizeof(waveHdr[i]));
if (MMSYSERR_NOERROR != rc)
{ {
DEBUG_DVC("waveInUnprepareHeader failed."); DEBUG_DVC("waveInUnprepareHeader failed. %d", rc);
if (winmm->rdpcontext) if (winmm->rdpcontext)
setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, "audin_winmm_thread_func reported an error"); setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, "audin_winmm_thread_func reported an error");
} }
free(waveHdr[i].lpData); free(waveHdr[i].lpData);
} }
waveInClose(winmm->hWaveIn); rc = waveInClose(winmm->hWaveIn);
if (MMSYSERR_NOERROR != rc)
{
DEBUG_DVC("waveInClose failed. %d", rc);
if (winmm->rdpcontext)
setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, "audin_winmm_thread_func reported an error");
}
winmm->hWaveIn = NULL; winmm->hWaveIn = NULL;
return 0; return 0;