CoreAudio: fix crash on iOS 5.
The plugin was using some iOS 6 APIs, even though we're supposed to support iOS 5. Add version checks for all these APIs. Task-number: QTBUG-44790 Change-Id: I9268963b7d3601222451ce0c948c2d024d37c86f Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
This commit is contained in:
@@ -44,6 +44,10 @@
|
||||
#import <AVFoundation/AVAudioSession.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||
#include <AudioToolbox/AudioToolbox.h>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@interface CoreAudioSessionObserver : NSObject
|
||||
@@ -79,6 +83,10 @@ QT_BEGIN_NAMESPACE
|
||||
self->m_sessionManager = sessionManager;
|
||||
self->m_audioSession = [AVAudioSession sharedInstance];
|
||||
|
||||
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0)
|
||||
#endif
|
||||
{
|
||||
//Set up observers
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(audioSessionInterruption:)
|
||||
@@ -92,6 +100,7 @@ QT_BEGIN_NAMESPACE
|
||||
selector:@selector(audioSessionRouteChange:)
|
||||
name:AVAudioSessionRouteChangeNotification
|
||||
object:self->m_audioSession];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -101,6 +110,11 @@ QT_BEGIN_NAMESPACE
|
||||
#ifdef QT_DEBUG_COREAUDIO
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
#endif
|
||||
|
||||
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0)
|
||||
#endif
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||
name:AVAudioSessionInterruptionNotification
|
||||
object:self->m_audioSession];
|
||||
@@ -110,6 +124,8 @@ QT_BEGIN_NAMESPACE
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||
name:AVAudioSessionRouteChangeNotification
|
||||
object:self->m_audioSession];
|
||||
}
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -269,6 +285,9 @@ bool CoreAudioSessionManager::setCategory(CoreAudioSessionManager::AudioSessionC
|
||||
targetCategory = AVAudioSessionCategoryAudioProcessing;
|
||||
break;
|
||||
case CoreAudioSessionManager::MultiRoute:
|
||||
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0)
|
||||
#endif
|
||||
targetCategory = AVAudioSessionCategoryMultiRoute;
|
||||
break;
|
||||
}
|
||||
@@ -276,10 +295,17 @@ bool CoreAudioSessionManager::setCategory(CoreAudioSessionManager::AudioSessionC
|
||||
if (targetCategory == nil)
|
||||
return false;
|
||||
|
||||
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||
if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_6_0) {
|
||||
return [[m_sessionObserver audioSession] setCategory:targetCategory error:nil];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
return [[m_sessionObserver audioSession] setCategory:targetCategory
|
||||
withOptions:(AVAudioSessionCategoryOptions)options
|
||||
error:nil];
|
||||
}
|
||||
}
|
||||
|
||||
bool CoreAudioSessionManager::setMode(CoreAudioSessionManager::AudioSessionModes mode)
|
||||
{
|
||||
@@ -301,6 +327,9 @@ bool CoreAudioSessionManager::setMode(CoreAudioSessionManager::AudioSessionModes
|
||||
targetMode = AVAudioSessionModeMeasurement;
|
||||
break;
|
||||
case CoreAudioSessionManager::MoviePlayback:
|
||||
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0)
|
||||
#endif
|
||||
targetMode = AVAudioSessionModeMoviePlayback;
|
||||
break;
|
||||
}
|
||||
@@ -329,7 +358,11 @@ CoreAudioSessionManager::AudioSessionCategorys CoreAudioSessionManager::category
|
||||
localCategory = PlayAndRecord;
|
||||
} else if (category == AVAudioSessionCategoryAudioProcessing) {
|
||||
localCategory = AudioProcessing;
|
||||
} else if (category == AVAudioSessionCategoryMultiRoute) {
|
||||
} else if (
|
||||
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||
QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0 &&
|
||||
#endif
|
||||
category == AVAudioSessionCategoryMultiRoute) {
|
||||
localCategory = MultiRoute;
|
||||
}
|
||||
|
||||
@@ -351,7 +384,11 @@ CoreAudioSessionManager::AudioSessionModes CoreAudioSessionManager::mode()
|
||||
localMode = VideoRecording;
|
||||
} else if (mode == AVAudioSessionModeMeasurement) {
|
||||
localMode = Measurement;
|
||||
} else if (mode == AVAudioSessionModeMoviePlayback) {
|
||||
} else if (
|
||||
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||
QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0 &&
|
||||
#endif
|
||||
mode == AVAudioSessionModeMoviePlayback) {
|
||||
localMode = MoviePlayback;
|
||||
}
|
||||
|
||||
@@ -379,14 +416,34 @@ QList<QByteArray> CoreAudioSessionManager::outputDevices()
|
||||
}
|
||||
|
||||
float CoreAudioSessionManager::currentIOBufferDuration()
|
||||
{
|
||||
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||
if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_6_0) {
|
||||
Float32 duration;
|
||||
UInt32 size = sizeof(duration);
|
||||
AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareIOBufferDuration, &size, &duration);
|
||||
return duration;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
return [[m_sessionObserver audioSession] IOBufferDuration];
|
||||
}
|
||||
}
|
||||
|
||||
float CoreAudioSessionManager::preferredSampleRate()
|
||||
{
|
||||
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||
if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_6_0) {
|
||||
Float64 sampleRate;
|
||||
UInt32 size = sizeof(sampleRate);
|
||||
AudioSessionGetProperty(kAudioSessionProperty_PreferredHardwareSampleRate, &size, &sampleRate);
|
||||
return sampleRate;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
return [[m_sessionObserver audioSession] preferredSampleRate];
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef QT_DEBUG_COREAUDIO
|
||||
QDebug operator<<(QDebug dbg, CoreAudioSessionManager::AudioSessionCategorys category)
|
||||
|
||||
Reference in New Issue
Block a user