aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-09-14 02:01:35 -0700
committerChris Robinson <[email protected]>2011-09-14 02:01:35 -0700
commit97024151e49d97ed3ae9d73a9426de0f1a9ebb0f (patch)
tree841c413a23725d55a6b872b531bcc38689ba96cd
parent62dfea43c699cb18a7538980794106d3ac0edca6 (diff)
Return an error from the CaptureSamples method instead of setting it
-rw-r--r--Alc/ALc.c17
-rw-r--r--Alc/backends/alsa.c10
-rw-r--r--Alc/backends/coreaudio.c55
-rw-r--r--Alc/backends/oss.c14
-rw-r--r--Alc/backends/portaudio.c15
-rw-r--r--Alc/backends/pulseaudio.c10
-rw-r--r--Alc/backends/winmm.c10
-rw-r--r--OpenAL32/Include/alMain.h2
8 files changed, 66 insertions, 67 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 7d9793aa..c5329cfa 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -1730,17 +1730,16 @@ ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
{
- if(!(device=VerifyDevice(device)) || !device->IsCaptureDevice)
+ ALCenum err = ALC_INVALID_DEVICE;
+ if((device=VerifyDevice(device)) != NULL && device->IsCaptureDevice)
{
- alcSetError(device, ALC_INVALID_DEVICE);
- if(device) ALCdevice_DecRef(device);
- return;
+ LockDevice(device);
+ err = ALCdevice_CaptureSamples(device, buffer, samples);
+ UnlockDevice(device);
}
- LockDevice(device);
- ALCdevice_CaptureSamples(device, buffer, samples);
- UnlockDevice(device);
-
- ALCdevice_DecRef(device);
+ if(err != ALC_NO_ERROR)
+ alcSetError(device, err);
+ if(device) ALCdevice_DecRef(device);
}
/*
diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c
index 7fa8f7b8..d953f52f 100644
--- a/Alc/backends/alsa.c
+++ b/Alc/backends/alsa.c
@@ -1040,14 +1040,14 @@ static ALCuint alsa_available_samples(ALCdevice *Device)
return RingBufferSize(data->ring);
}
-static void alsa_capture_samples(ALCdevice *Device, ALCvoid *Buffer, ALCuint Samples)
+static ALCenum alsa_capture_samples(ALCdevice *Device, ALCvoid *Buffer, ALCuint Samples)
{
alsa_data *data = (alsa_data*)Device->ExtraData;
- if(Samples <= alsa_available_samples(Device))
- ReadRingBuffer(data->ring, Buffer, Samples);
- else
- alcSetError(Device, ALC_INVALID_VALUE);
+ if(alsa_available_samples(Device) < Samples)
+ return ALC_INVALID_VALUE;
+ ReadRingBuffer(data->ring, Buffer, Samples);
+ return ALC_NO_ERROR;
}
diff --git a/Alc/backends/coreaudio.c b/Alc/backends/coreaudio.c
index b0c600d3..8cb50edf 100644
--- a/Alc/backends/coreaudio.c
+++ b/Alc/backends/coreaudio.c
@@ -642,43 +642,42 @@ static ALCuint ca_available_samples(ALCdevice *device)
return RingBufferSize(data->ring) / data->sampleRateRatio;
}
-static void ca_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples)
+static ALCenum ca_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples)
{
ca_data *data = (ca_data*)device->ExtraData;
+ AudioBufferList *list;
+ UInt32 frameCount;
+ OSStatus err;
- if(samples <= ca_available_samples(device))
- {
- AudioBufferList *list;
- UInt32 frameCount;
- OSStatus err;
+ if(ca_available_samples(device) < samples)
+ return ALC_INVALID_VALUE;
- // If no samples are requested, just return
- if(samples == 0)
- return;
+ // If no samples are requested, just return
+ if(samples == 0)
+ return ALC_NO_ERROR;
- // Allocate a temporary AudioBufferList to use as the return resamples data
- list = alloca(sizeof(AudioBufferList) + sizeof(AudioBuffer));
+ // Allocate a temporary AudioBufferList to use as the return resamples data
+ list = alloca(sizeof(AudioBufferList) + sizeof(AudioBuffer));
- // Point the resampling buffer to the capture buffer
- list->mNumberBuffers = 1;
- list->mBuffers[0].mNumberChannels = data->format.mChannelsPerFrame;
- list->mBuffers[0].mDataByteSize = samples * data->frameSize;
- list->mBuffers[0].mData = buffer;
-
- // Resample into another AudioBufferList
- frameCount = samples;
- err = AudioConverterFillComplexBuffer(data->audioConverter, ca_capture_conversion_callback, device,
- &frameCount, list, NULL);
- if(err != noErr)
- {
- ERR("AudioConverterFillComplexBuffer error: %d\n", err);
- alcSetError(device, ALC_INVALID_VALUE);
- }
+ // Point the resampling buffer to the capture buffer
+ list->mNumberBuffers = 1;
+ list->mBuffers[0].mNumberChannels = data->format.mChannelsPerFrame;
+ list->mBuffers[0].mDataByteSize = samples * data->frameSize;
+ list->mBuffers[0].mData = buffer;
+
+ // Resample into another AudioBufferList
+ frameCount = samples;
+ err = AudioConverterFillComplexBuffer(data->audioConverter, ca_capture_conversion_callback,
+ device, &frameCount, list, NULL);
+ if(err != noErr)
+ {
+ ERR("AudioConverterFillComplexBuffer error: %d\n", err);
+ return ALC_INVALID_VALUE;
}
- else
- alcSetError(device, ALC_INVALID_VALUE);
+ return ALC_NO_ERROR;
}
+
static const BackendFuncs ca_funcs = {
ca_open_playback,
ca_close_playback,
diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c
index c94e3044..79830c06 100644
--- a/Alc/backends/oss.c
+++ b/Alc/backends/oss.c
@@ -461,19 +461,19 @@ static void oss_stop_capture(ALCdevice *pDevice)
data->doCapture = 0;
}
-static void oss_capture_samples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint lSamples)
+static ALCuint oss_available_samples(ALCdevice *pDevice)
{
oss_data *data = (oss_data*)pDevice->ExtraData;
- if(lSamples <= (ALCuint)RingBufferSize(data->ring))
- ReadRingBuffer(data->ring, pBuffer, lSamples);
- else
- alcSetError(pDevice, ALC_INVALID_VALUE);
+ return RingBufferSize(data->ring);
}
-static ALCuint oss_available_samples(ALCdevice *pDevice)
+static ALCenum oss_capture_samples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint lSamples)
{
oss_data *data = (oss_data*)pDevice->ExtraData;
- return RingBufferSize(data->ring);
+ if(oss_available_samples(pDevice) < lSamples)
+ return ALC_INVALID_VALUE;
+ ReadRingBuffer(data->ring, pBuffer, lSamples);
+ return ALC_NO_ERROR;
}
diff --git a/Alc/backends/portaudio.c b/Alc/backends/portaudio.c
index c3898ef8..2345a282 100644
--- a/Alc/backends/portaudio.c
+++ b/Alc/backends/portaudio.c
@@ -377,19 +377,20 @@ static void pa_stop_capture(ALCdevice *device)
ERR("Error stopping stream: %s\n", Pa_GetErrorText(err));
}
-static void pa_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples)
+static ALCuint pa_available_samples(ALCdevice *device)
{
pa_data *data = device->ExtraData;
- if(samples <= (ALCuint)RingBufferSize(data->ring))
- ReadRingBuffer(data->ring, buffer, samples);
- else
- alcSetError(device, ALC_INVALID_VALUE);
+ return RingBufferSize(data->ring);
}
-static ALCuint pa_available_samples(ALCdevice *device)
+static ALCenum pa_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples)
{
pa_data *data = device->ExtraData;
- return RingBufferSize(data->ring);
+
+ if(pa_available_samples(device) < samples)
+ return ALC_INVALID_VALUE;
+ ReadRingBuffer(data->ring, buffer, samples);
+ return ALC_NO_ERROR;
}
diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c
index 804ceacb..2382a708 100644
--- a/Alc/backends/pulseaudio.c
+++ b/Alc/backends/pulseaudio.c
@@ -1297,14 +1297,14 @@ static ALCuint pulse_available_samples(ALCdevice *device) //{{{
return RingBufferSize(data->ring);
} //}}}
-static void pulse_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples) //{{{
+static ALCenum pulse_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples) //{{{
{
pulse_data *data = device->ExtraData;
- if(pulse_available_samples(device) >= samples)
- ReadRingBuffer(data->ring, buffer, samples);
- else
- alcSetError(device, ALC_INVALID_VALUE);
+ if(pulse_available_samples(device) < samples)
+ return ALC_INVALID_VALUE;
+ ReadRingBuffer(data->ring, buffer, samples);
+ return ALC_NO_ERROR;
} //}}}
diff --git a/Alc/backends/winmm.c b/Alc/backends/winmm.c
index 0a186662..1a9f099b 100644
--- a/Alc/backends/winmm.c
+++ b/Alc/backends/winmm.c
@@ -683,14 +683,14 @@ static ALCuint WinMMAvailableSamples(ALCdevice *pDevice)
return RingBufferSize(pData->pRing);
}
-static void WinMMCaptureSamples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint lSamples)
+static ALCenum WinMMCaptureSamples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint lSamples)
{
WinMMData *pData = (WinMMData*)pDevice->ExtraData;
- if(WinMMAvailableSamples(pDevice) >= lSamples)
- ReadRingBuffer(pData->pRing, pBuffer, lSamples);
- else
- alcSetError(pDevice, ALC_INVALID_VALUE);
+ if(WinMMAvailableSamples(pDevice) < lSamples)
+ return ALC_INVALID_VALUE;
+ ReadRingBuffer(pData->pRing, pBuffer, lSamples);
+ return ALC_NO_ERROR;
}
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 5b770691..bbe66bd2 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -418,7 +418,7 @@ typedef struct {
void (*CloseCapture)(ALCdevice*);
void (*StartCapture)(ALCdevice*);
void (*StopCapture)(ALCdevice*);
- void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
+ ALCenum (*CaptureSamples)(ALCdevice*, void*, ALCuint);
ALCuint (*AvailableSamples)(ALCdevice*);
} BackendFuncs;