audio/coreaudio.c: Fix deprecation warnings
cover audio/coreaudio.c: Fix deprecation warnings
The coreaudio.c code has for some years now produced compilation warnings about our use of various APIs that were deprecated starting with OSX 10.6. This patchset updates our code to use their replacements.
I have been a bit conservative with the approach to moving away from AudioDeviceGetProperty/AudioDeviceSetProperty, because different sources on the web suggest either 10.6 or 10.5 was the point at which you could move to AudioObjectGetProperty/AudioObjectSetProperty, but I don't have a 10.5 system to test with. So I've left the old code in for when building on 10.5 (removing it would be a trivial matter of dropping a lot of ifdeffed code).
Incidentally, on the subject of OSX 10.5, I think we should finally drop support for it unless anybody would like to volunteer to actually test building on it. I'll send a separate email about that.
(This patch set is intended for 2.6, not 2.5.)
Peter Maydell (5):
audio/coreaudio.c: Factor out use of AudioHardwareGetProperty audio/coreaudio.c: Use new-in-OSX-10.6 API for getting default voice audio/coreaudio.c: Factor out uses of AudioDeviceGet/SetProperty audio/coreaudio.c: Use new-in-OSX-10.6 APIs when available audio/coreaudio.c: Avoid deprecated AudioDeviceAdd/RemoveIOProc APIs
audio/coreaudio.c | 314 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 252 insertions(+), 62 deletions(-)
Signature · 1 line
2.6.2
PATCH 1/5 audio/coreaudio.c: Factor out use of AudioHardwareGetProperty
The CoreAudio function AudioHardwareGetProperty has been deprecated starting with OSX 10.6, so factor out our call to it so we can provide an equivalent with the new APIs when they exist.
--- audio/coreaudio.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
audio/coreaudio.c +11 -6
@@ -50,6 +50,16 @@ typedef struct coreaudioVoiceOut {int rpos; } coreaudioVoiceOut; +static OSStatus coreaudio_get_voice (AudioDeviceID *id) +{ +UInt32 size =sizeof (*id); + +return AudioHardwareGetProperty ( + kAudioHardwarePropertyDefaultOutputDevice, + &size, + id); +} +static void coreaudio_logstatus (OSStatus status) {const char *str ="BUG" ;
@@ -303,12 +313,7 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,audio_pcm_init_info (&hw->info, as); -/* open default output device */ - propertySize =sizeof (core->outputDeviceID); - status =AudioHardwareGetProperty ( - kAudioHardwarePropertyDefaultOutputDevice, - &propertySize, - &core->outputDeviceID); + status =coreaudio_get_voice (&core->outputDeviceID);if (status != kAudioHardwareNoError) {coreaudio_logerr2 (status, typ,"Could not get default output Device\n" );
Signature · 1 line
2.6.2
PATCH 2/5 audio/coreaudio.c: Use new-in-OSX-10.6 API for getting default voice
In reply to Peter MaydellIf we're building for OSX 10.6 or better, use the new API AudioObjectGetPropertyData for getting the default voice.
--- audio/coreaudio.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
audio/coreaudio.c +27 -0
@@ -32,6 +32,10 @@#define AUDIO_CAP "coreaudio"#include "audio_int.h" +#ifndef MAC_OS_X_VERSION_10_6 +#define MAC_OS_X_VERSION_10_6 1060 +#endif +static int isAtexit; typedef struct {
@@ -50,6 +54,28 @@ typedef struct coreaudioVoiceOut {int rpos; } coreaudioVoiceOut; +#if MAC_OS_X_VERSION_MAX_ALLOWED >=MAC_OS_X_VERSION_10_6 +/* The APIs used here only become available from 10.6 */ + +static OSStatus coreaudio_get_voice (AudioDeviceID *id) +{ +UInt32 size =sizeof (*id); +AudioObjectPropertyAddress addr = { + kAudioHardwarePropertyDefaultOutputDevice, + kAudioObjectPropertyScopeGlobal, + kAudioObjectPropertyElementMaster + }; + +return AudioObjectGetPropertyData (kAudioObjectSystemObject, + &addr, +0 , +NULL , + &size, + id); +} +#else +/* Legacy versions of functions using deprecated APIs */ +static OSStatus coreaudio_get_voice (AudioDeviceID *id) {UInt32 size =sizeof (*id);
@@ -59,6 +85,7 @@ static OSStatus coreaudio_get_voice(AudioDeviceID *id) &size, id); } +#endif static void coreaudio_logstatus (OSStatus status) {
Signature · 1 line
2.6.2
PATCH 3/5 audio/coreaudio.c: Factor out uses of AudioDeviceGet/SetProperty
In reply to Peter MaydellThe CoreAudio APIs AudioDeviceGetProperty and AudioDeviceSetProperty are deprecated from OSX 10.6, so factor out our calls to them so we can provide versions which use the replacement APIs on OSX newer than 10.5.
--- audio/coreaudio.c | 141 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 94 insertions(+), 47 deletions(-)
audio/coreaudio.c +94 -47
@@ -87,6 +87,89 @@ static OSStatus coreaudio_get_voice(AudioDeviceID *id) }#endif +static OSStatus coreaudio_get_framesizerange (AudioDeviceID id, +AudioValueRange *framerange) +{ +UInt32 size =sizeof (*framerange); + +return AudioDeviceGetProperty ( + id, +0 , +0 , + kAudioDevicePropertyBufferFrameSizeRange, + &size, + framerange); +} + +static OSStatus coreaudio_get_framesize (AudioDeviceID id,UInt32 *framesize) +{ +UInt32 size =sizeof (*framesize); + +return AudioDeviceGetProperty ( + id, +0 , + false, + kAudioDevicePropertyBufferFrameSize, + &size, + framesize); +} + +static OSStatus coreaudio_set_framesize (AudioDeviceID id,UInt32 *framesize) +{ +UInt32 size =sizeof (*framesize); + +return AudioDeviceSetProperty ( + id, +NULL , +0 , + false, + kAudioDevicePropertyBufferFrameSize, + size, + framesize); +} + +static OSStatus coreaudio_get_streamformat (AudioDeviceID id, +AudioStreamBasicDescription *d) +{ +UInt32 size =sizeof (*d); + +return AudioDeviceGetProperty ( + id, +0 , + false, + kAudioDevicePropertyStreamFormat, + &size, + d); +} + +static OSStatus coreaudio_set_streamformat (AudioDeviceID id, +AudioStreamBasicDescription *d) +{ +UInt32 size =sizeof (*d); + +return AudioDeviceSetProperty ( + id, +0 , +0 , +0 , + kAudioDevicePropertyStreamFormat, + size, + d); +} + +static OSStatus coreaudio_get_isrunning (AudioDeviceID id,UInt32 *result) +{ +UInt32 size =sizeof (*result); + +return AudioDeviceGetProperty ( + id, +0 , +0 , + kAudioDevicePropertyDeviceIsRunning, + &size, + result); +} +static void coreaudio_logstatus (OSStatus status) {const char *str ="BUG" ;
@@ -181,10 +264,7 @@ static inline UInt32 isPlaying (AudioDeviceID outputDeviceID) {OSStatus status;UInt32 result =0 ; -UInt32 propertySize =sizeof (outputDeviceID); - status =AudioDeviceGetProperty ( - outputDeviceID,0 ,0 , - kAudioDevicePropertyDeviceIsRunning, &propertySize, &result); + status =coreaudio_get_isrunning (outputDeviceID, &result);if (status != kAudioHardwareNoError) {coreaudio_logerr (status,"Could not determine whether Device is playing\n" );
@@ -325,7 +405,6 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, {OSStatus status;coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; -UInt32 propertySize;int err;const char *typ ="playback" ;AudioValueRange frameRange;
@@ -352,14 +431,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, }/* get minimum and maximum buffer frame sizes */ - propertySize =sizeof (frameRange); - status =AudioDeviceGetProperty ( - core->outputDeviceID, -0 , -0 , - kAudioDevicePropertyBufferFrameSizeRange, - &propertySize, - &frameRange); + status =coreaudio_get_framesizerange (core->outputDeviceID, + &frameRange);if (status != kAudioHardwareNoError) {coreaudio_logerr2 (status, typ,"Could not get device buffer frame range\n" );
@@ -379,15 +452,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, }/* set Buffer Frame Size */ - propertySize =sizeof (core->audioDevicePropertyBufferFrameSize); - status =AudioDeviceSetProperty ( - core->outputDeviceID, -NULL , -0 , - false, - kAudioDevicePropertyBufferFrameSize, - propertySize, - &core->audioDevicePropertyBufferFrameSize); + status =coreaudio_set_framesize (core->outputDeviceID, + &core->audioDevicePropertyBufferFrameSize);if (status != kAudioHardwareNoError) { coreaudio_logerr2 (status, typ, "Could not set device buffer frame size %" PRIu32 "\n",
@@ -396,14 +462,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, }/* get Buffer Frame Size */ - propertySize =sizeof (core->audioDevicePropertyBufferFrameSize); - status =AudioDeviceGetProperty ( - core->outputDeviceID, -0 , - false, - kAudioDevicePropertyBufferFrameSize, - &propertySize, - &core->audioDevicePropertyBufferFrameSize); + status =coreaudio_get_framesize (core->outputDeviceID, + &core->audioDevicePropertyBufferFrameSize);if (status != kAudioHardwareNoError) {coreaudio_logerr2 (status, typ,"Could not get device buffer frame size\n" );
@@ -412,14 +472,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, hw->samples = conf->nbuffers * core->audioDevicePropertyBufferFrameSize;/* get StreamFormat */ - propertySize =sizeof (core->outputStreamBasicDescription); - status =AudioDeviceGetProperty ( - core->outputDeviceID, -0 , - false, - kAudioDevicePropertyStreamFormat, - &propertySize, - &core->outputStreamBasicDescription); + status =coreaudio_get_streamformat (core->outputDeviceID, + &core->outputStreamBasicDescription);if (status != kAudioHardwareNoError) {coreaudio_logerr2 (status, typ,"Could not get Device Stream properties\n" );
@@ -429,15 +483,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,/* set Samplerate */ core->outputStreamBasicDescription.mSampleRate = (Float64 ) as->freq; - propertySize =sizeof (core->outputStreamBasicDescription); - status =AudioDeviceSetProperty ( - core->outputDeviceID, -0 , -0 , -0 , - kAudioDevicePropertyStreamFormat, - propertySize, - &core->outputStreamBasicDescription); + status =coreaudio_set_streamformat (core->outputDeviceID, + &core->outputStreamBasicDescription);if (status != kAudioHardwareNoError) {coreaudio_logerr2 (status, typ,"Could not set samplerate %d\n" , as->freq);
Signature · 1 line
2.6.2
PATCH 4/5 audio/coreaudio.c: Use new-in-OSX-10.6 APIs when available
In reply to Peter MaydellUse the new-in-OSX 10.6 API AudioObjectGetPropertyData() instead of the deprecated AudioDeviceGetProperty() and AudioDeviceSetProperty() functions when possible.
--- audio/coreaudio.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-)
audio/coreaudio.c +106 -1
@@ -73,6 +73,111 @@ static OSStatus coreaudio_get_voice(AudioDeviceID *id) &size, id); } + +static OSStatus coreaudio_get_framesizerange (AudioDeviceID id, +AudioValueRange *framerange) +{ +UInt32 size =sizeof (*framerange); +AudioObjectPropertyAddress addr = { + kAudioDevicePropertyBufferFrameSizeRange, + kAudioDevicePropertyScopeOutput, + kAudioObjectPropertyElementMaster + }; + +return AudioObjectGetPropertyData (id, + &addr, +0 , +NULL , + &size, + framerange); +} + +static OSStatus coreaudio_get_framesize (AudioDeviceID id,UInt32 *framesize) +{ +UInt32 size =sizeof (*framesize); +AudioObjectPropertyAddress addr = { + kAudioDevicePropertyBufferFrameSize, + kAudioDevicePropertyScopeOutput, + kAudioObjectPropertyElementMaster + }; + +return AudioObjectGetPropertyData (id, + &addr, +0 , +NULL , + &size, + framesize); +} + +static OSStatus coreaudio_set_framesize (AudioDeviceID id,UInt32 *framesize) +{ +UInt32 size =sizeof (*framesize); +AudioObjectPropertyAddress addr = { + kAudioDevicePropertyBufferFrameSize, + kAudioDevicePropertyScopeOutput, + kAudioObjectPropertyElementMaster + }; + +return AudioObjectSetPropertyData (id, + &addr, +0 , +NULL , + size, + framesize); +} + +static OSStatus coreaudio_get_streamformat (AudioDeviceID id, +AudioStreamBasicDescription *d) +{ +UInt32 size =sizeof (*d); +AudioObjectPropertyAddress addr = { + kAudioDevicePropertyStreamFormat, + kAudioDevicePropertyScopeOutput, + kAudioObjectPropertyElementMaster + }; + +return AudioObjectGetPropertyData (id, + &addr, +0 , +NULL , + &size, + d); +} + +static OSStatus coreaudio_set_streamformat (AudioDeviceID id, +AudioStreamBasicDescription *d) +{ +UInt32 size =sizeof (*d); +AudioObjectPropertyAddress addr = { + kAudioDevicePropertyStreamFormat, + kAudioDevicePropertyScopeOutput, + kAudioObjectPropertyElementMaster + }; + +return AudioObjectSetPropertyData (id, + &addr, +0 , +NULL , + size, + d); +} + +static OSStatus coreaudio_get_isrunning (AudioDeviceID id,UInt32 *result) +{ +UInt32 size =sizeof (*result); +AudioObjectPropertyAddress addr = { + kAudioDevicePropertyDeviceIsRunning, + kAudioDevicePropertyScopeOutput, + kAudioObjectPropertyElementMaster + }; + +return AudioObjectGetPropertyData (id, + &addr, +0 , +NULL , + &size, + result); +}#else /* Legacy versions of functions using deprecated APIs */
@@ -85,7 +190,6 @@ static OSStatus coreaudio_get_voice(AudioDeviceID *id) &size, id); } -#endif static OSStatus coreaudio_get_framesizerange (AudioDeviceID id,AudioValueRange *framerange)
@@ -169,6 +273,7 @@ static OSStatus coreaudio_get_isrunning(AudioDeviceID id, UInt32 *result) &size, result); } +#endif static void coreaudio_logstatus (OSStatus status) {
Signature · 1 line
2.6.2
PATCH 5/5 audio/coreaudio.c: Avoid deprecated AudioDeviceAdd/RemoveIOProc APIs
In reply to Peter MaydellThe AudioDeviceAddIOProc() and AudioDeviceRemoveIOProc() functions were deprecated in OSX 10.5. Since we don't support any earlier versions of OSX, we can simply replace them with the new APIs AudioDeviceCreateIOProcID() and AudioDeviceRemoveIOProcID().
--- audio/coreaudio.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
audio/coreaudio.c +15 -9
@@ -49,6 +49,7 @@ typedef struct coreaudioVoiceOut {AudioDeviceID outputDeviceID;UInt32 audioDevicePropertyBufferFrameSize;AudioStreamBasicDescription outputStreamBasicDescription; +AudioDeviceIOProcID ioprocid;int live;int decr;int rpos;
@@ -598,8 +599,12 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as, }/* set Callback */ - status =AudioDeviceAddIOProc (core->outputDeviceID, audioDeviceIOProc, hw); -if (status != kAudioHardwareNoError) { + core->ioprocid =NULL ; + status =AudioDeviceCreateIOProcID (core->outputDeviceID, + audioDeviceIOProc, + hw, + &core->ioprocid); +if (status != kAudioHardwareNoError || core->ioprocid ==NULL ) {coreaudio_logerr2 (status, typ,"Could not set IOProc\n" ); core->outputDeviceID = kAudioDeviceUnknown;return -1 ;
@@ -607,10 +612,10 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,/* start Playback */ if (!isPlaying (core->outputDeviceID)) { - status =AudioDeviceStart (core->outputDeviceID, audioDeviceIOProc); + status =AudioDeviceStart (core->outputDeviceID, core->ioprocid);if (status != kAudioHardwareNoError) {coreaudio_logerr2 (status, typ,"Could not start playback\n" ); -AudioDeviceRemoveIOProc (core->outputDeviceID, audioDeviceIOProc); +AudioDeviceDestroyIOProcID (core->outputDeviceID, core->ioprocid); core->outputDeviceID = kAudioDeviceUnknown;return -1 ; }
@@ -628,15 +633,15 @@ static void coreaudio_fini_out (HWVoiceOut *hw)if (!isAtexit) {/* stop playback */ if (isPlaying (core->outputDeviceID)) { - status =AudioDeviceStop (core->outputDeviceID, audioDeviceIOProc); + status =AudioDeviceStop (core->outputDeviceID, core->ioprocid);if (status != kAudioHardwareNoError) {coreaudio_logerr (status,"Could not stop playback\n" ); } }/* remove callback */ - status =AudioDeviceRemoveIOProc (core->outputDeviceID, - audioDeviceIOProc); + status =AudioDeviceDestroyIOProcID (core->outputDeviceID, + core->ioprocid);if (status != kAudioHardwareNoError) {coreaudio_logerr (status,"Could not remove IOProc\n" ); }
@@ -659,7 +664,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)case VOICE_ENABLE :/* start playback */ if (!isPlaying (core->outputDeviceID)) { - status =AudioDeviceStart (core->outputDeviceID, audioDeviceIOProc); + status =AudioDeviceStart (core->outputDeviceID, core->ioprocid);if (status != kAudioHardwareNoError) {coreaudio_logerr (status,"Could not resume playback\n" ); }
@@ -670,7 +675,8 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)/* stop playback */ if (!isAtexit) {if (isPlaying (core->outputDeviceID)) { - status =AudioDeviceStop (core->outputDeviceID, audioDeviceIOProc); + status =AudioDeviceStop (core->outputDeviceID, + core->ioprocid);if (status != kAudioHardwareNoError) {coreaudio_logerr (status,"Could not pause playback\n" ); }
Signature · 1 line
2.6.2
Quoted 25 lines · Peter Maydell
The
coreaudio.ccode has for some years now produced compilation warnings about our use of various APIs that were deprecated starting with OSX 10.6. This patchset updates our code to use their replacements.I have been a bit conservative with the approach to moving away from AudioDeviceGetProperty/AudioDeviceSetProperty, because different sources on the web suggest either 10.6 or 10.5 was the point at which you could move to AudioObjectGetProperty/AudioObjectSetProperty, but I don't have a 10.5 system to test with. So I've left the old code in for when building on 10.5 (removing it would be a trivial matter of dropping a lot of ifdeffed code).
Incidentally, on the subject of OSX 10.5, I think we should finally drop support for it unless anybody would like to volunteer to actually test building on it. I'll send a separate email about that.
(This patch set is intended for 2.6, not 2.5.)
Peter Maydell (5):
audio/coreaudio.c: Factor out use of AudioHardwareGetPropertyaudio/coreaudio.c: Use new-in-OSX-10.6 API for getting default voiceaudio/coreaudio.c: Factor out uses of AudioDeviceGet/SetPropertyaudio/coreaudio.c: Use new-in-OSX-10.6 APIs when availableaudio/coreaudio.c: Avoid deprecated AudioDeviceAdd/RemoveIOProc APIs
Quoted 5 lines
audio/coreaudio.c| 314 +++++++++++++++++++++++++++++++++++++++++++-----------1 file changed, 252 insertions(+), 62 deletions(-)Signature · 1 line
2.6.2
All the patches applied and compiled without problem on Mac OS 10.6.8. I played video and mp3 files in QEMU running a Windows XP guest. They all played perfectly.
I really was against the idea of removing Mac OS 10.5 support when I first heard the idea. But I did think about it before saying anything. I personally started out building QEMU on Mac OS 10.3. But that was years ago. Technology has moved on. Everyone wants to run their emulator on the fastest hardware they have. This hardware is probably not going to include anything running Mac OS 10.5. Removing Mac OS 10.5 support might be a good idea. I don't think we would inconvenience anyone. The only evidence I found of someone using Mac OS 10.5 to build QEMU was from 2012.
We are only removing support for Mac OS 10.5 because of a warning message that appears during compilation. We could just disable warnings for that file. But the depreciated audio functions might not be around in the future, so probably better to say goodbye to them now before they cause real problems.
Quoted 3 lines · Programmingkid
All the patches applied and compiled without problem on Mac OS 10.6.8. I played video and mp3 files in QEMU running a Windows XP guest. They all played perfectly.
Cool, thanks for the testing.
Quoted 9 lines
I really was against the idea of removing Mac OS 10.5 support when I first heard the idea. But I did think about it before saying anything. I personally started out building QEMU on Mac OS 10.3. But that was years ago. Technology has moved on. Everyone wants to run their emulator on the fastest hardware they have. This hardware is probably not going to include anything running Mac OS 10.5. Removing Mac OS 10.5 support might be a good idea. I don't think we would inconvenience anyone. The only evidence I found of someone using Mac OS 10.5 to build QEMU was from 2012.
Yep. I actually would be happy retaining the 10.5 support even for a single user, provided that that user was interacting with us on qemu-devel and testing that our code still builds on their setup and so on. That's why I propose to announce the deprecation in the release notes, so if such a person exists they can come and talk to us about it.
Quoted 5 lines
We are only removing support for Mac OS 10.5 because of a warning message that appears during compilation. We could just disable warnings for that file. But the depreciated audio functions might not be around in the future, so probably better to say goodbye to them now before they cause real problems.
Note that this patch set does *not* drop 10.5 support -- the 10.5 versions of the functions are all present so in theory it should build fine there. The only problem is that (as usual) nobody is actually testing that it really does compile on 10.5.
thanks
-- PMM