XQuartz: Fix a possible buffer overrun in quartzAudio
Also dropped deprecated API while there
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
(cherry picked from commit 4e8bf12b13
)
This commit is contained in:
parent
4d8ad88b57
commit
8dda9ba67a
|
@ -62,7 +62,6 @@ typedef struct QuartzAudioRec {
|
|||
UInt32 curFrame;
|
||||
UInt32 remainingFrames;
|
||||
UInt32 totalFrames;
|
||||
UInt32 bytesPerFrame;
|
||||
double sampleRate;
|
||||
UInt32 fadeLength;
|
||||
|
||||
|
@ -117,9 +116,9 @@ static void QuartzFillBuffer(
|
|||
unsigned int bufferFrameCount;
|
||||
float multiplier, v;
|
||||
int i;
|
||||
|
||||
|
||||
buffer = (float *)audiobuffer->mData;
|
||||
bufferFrameCount = audiobuffer->mDataByteSize / data->bytesPerFrame;
|
||||
bufferFrameCount = audiobuffer->mDataByteSize / (sizeof(float) * audiobuffer->mNumberChannels);
|
||||
|
||||
frameCount = min(bufferFrameCount, data->remainingFrames);
|
||||
|
||||
|
@ -141,7 +140,7 @@ static void QuartzFillBuffer(
|
|||
data->prevFrame = 0;
|
||||
|
||||
// adjust for space eaten by prev fade
|
||||
buffer += audiobuffer->mNumberChannels*frame;
|
||||
b += audiobuffer->mNumberChannels*frame;
|
||||
bufferFrameCount -= frame;
|
||||
frameCount = min(bufferFrameCount, data->remainingFrames);
|
||||
}
|
||||
|
@ -204,7 +203,8 @@ QuartzAudioIOProc(
|
|||
if (wasPlaying && !data->playing) {
|
||||
OSStatus err;
|
||||
err = AudioDeviceStop(inDevice, QuartzAudioIOProc);
|
||||
fprintf(stderr, "Error stopping audio device: %ld\n", (long int)err);
|
||||
if(err != noErr)
|
||||
fprintf(stderr, "Error stopping audio device: %ld\n", (long int)err);
|
||||
}
|
||||
pthread_mutex_unlock(&data->lock);
|
||||
return 0;
|
||||
|
@ -263,16 +263,17 @@ void QuartzAudioInit(void)
|
|||
UInt32 propertySize;
|
||||
OSStatus status;
|
||||
AudioDeviceID outputDevice;
|
||||
AudioStreamBasicDescription outputStreamDescription;
|
||||
double sampleRate;
|
||||
|
||||
AudioObjectPropertyAddress devicePropertyAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
|
||||
AudioObjectPropertyAddress sampleRatePropertyAddress = { kAudioDevicePropertyNominalSampleRate, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
|
||||
|
||||
// Get the default output device
|
||||
propertySize = sizeof(outputDevice);
|
||||
status = AudioHardwareGetProperty(
|
||||
kAudioHardwarePropertyDefaultOutputDevice,
|
||||
&propertySize, &outputDevice);
|
||||
status = AudioObjectGetPropertyData(kAudioObjectSystemObject, &devicePropertyAddress,
|
||||
0, NULL,
|
||||
&propertySize, &outputDevice);
|
||||
if (status) {
|
||||
ErrorF("QuartzAudioInit: AudioHardwareGetProperty returned %ld\n",
|
||||
ErrorF("QuartzAudioInit: AudioObjectGetPropertyData(output device) returned %ld\n",
|
||||
(long)status);
|
||||
return;
|
||||
}
|
||||
|
@ -282,23 +283,22 @@ void QuartzAudioInit(void)
|
|||
}
|
||||
|
||||
// Get the basic device description
|
||||
propertySize = sizeof(outputStreamDescription);
|
||||
status = AudioDeviceGetProperty(outputDevice, 0, FALSE,
|
||||
kAudioDevicePropertyStreamFormat,
|
||||
&propertySize, &outputStreamDescription);
|
||||
sampleRate = 0.;
|
||||
propertySize = sizeof(sampleRate);
|
||||
status = AudioObjectGetPropertyData(outputDevice, &sampleRatePropertyAddress,
|
||||
0, NULL,
|
||||
&propertySize, &sampleRate);
|
||||
if (status) {
|
||||
ErrorF("QuartzAudioInit: GetProperty(stream format) returned %ld\n",
|
||||
ErrorF("QuartzAudioInit: AudioObjectGetPropertyData(sample rate) returned %ld\n",
|
||||
(long)status);
|
||||
return;
|
||||
}
|
||||
sampleRate = outputStreamDescription.mSampleRate;
|
||||
|
||||
// Fill in the playback data
|
||||
data.frequency = 0;
|
||||
data.amplitude = 0;
|
||||
data.curFrame = 0;
|
||||
data.remainingFrames = 0;
|
||||
data.bytesPerFrame = outputStreamDescription.mBytesPerFrame;
|
||||
data.sampleRate = sampleRate;
|
||||
// data.bufferByteCount = bufferByteCount;
|
||||
data.playing = FALSE;
|
||||
|
|
Loading…
Reference in New Issue
Block a user