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 <AVFoundation/AVAudioSession.h>
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||||
|
#include <AudioToolbox/AudioToolbox.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@interface CoreAudioSessionObserver : NSObject
|
@interface CoreAudioSessionObserver : NSObject
|
||||||
@@ -79,19 +83,24 @@ QT_BEGIN_NAMESPACE
|
|||||||
self->m_sessionManager = sessionManager;
|
self->m_sessionManager = sessionManager;
|
||||||
self->m_audioSession = [AVAudioSession sharedInstance];
|
self->m_audioSession = [AVAudioSession sharedInstance];
|
||||||
|
|
||||||
//Set up observers
|
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0)
|
||||||
selector:@selector(audioSessionInterruption:)
|
#endif
|
||||||
name:AVAudioSessionInterruptionNotification
|
{
|
||||||
object:self->m_audioSession];
|
//Set up observers
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(audioSessionMediaServicesWereReset:)
|
selector:@selector(audioSessionInterruption:)
|
||||||
name:AVAudioSessionMediaServicesWereResetNotification
|
name:AVAudioSessionInterruptionNotification
|
||||||
object:self->m_audioSession];
|
object:self->m_audioSession];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(audioSessionRouteChange:)
|
selector:@selector(audioSessionMediaServicesWereReset:)
|
||||||
name:AVAudioSessionRouteChangeNotification
|
name:AVAudioSessionMediaServicesWereResetNotification
|
||||||
object:self->m_audioSession];
|
object:self->m_audioSession];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(audioSessionRouteChange:)
|
||||||
|
name:AVAudioSessionRouteChangeNotification
|
||||||
|
object:self->m_audioSession];
|
||||||
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -101,15 +110,22 @@ QT_BEGIN_NAMESPACE
|
|||||||
#ifdef QT_DEBUG_COREAUDIO
|
#ifdef QT_DEBUG_COREAUDIO
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
#endif
|
#endif
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
||||||
name:AVAudioSessionInterruptionNotification
|
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||||
object:self->m_audioSession];
|
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0)
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
#endif
|
||||||
name:AVAudioSessionMediaServicesWereResetNotification
|
{
|
||||||
object:self->m_audioSession];
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
name:AVAudioSessionInterruptionNotification
|
||||||
name:AVAudioSessionRouteChangeNotification
|
object:self->m_audioSession];
|
||||||
object:self->m_audioSession];
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||||
|
name:AVAudioSessionMediaServicesWereResetNotification
|
||||||
|
object:self->m_audioSession];
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||||
|
name:AVAudioSessionRouteChangeNotification
|
||||||
|
object:self->m_audioSession];
|
||||||
|
}
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,6 +285,9 @@ bool CoreAudioSessionManager::setCategory(CoreAudioSessionManager::AudioSessionC
|
|||||||
targetCategory = AVAudioSessionCategoryAudioProcessing;
|
targetCategory = AVAudioSessionCategoryAudioProcessing;
|
||||||
break;
|
break;
|
||||||
case CoreAudioSessionManager::MultiRoute:
|
case CoreAudioSessionManager::MultiRoute:
|
||||||
|
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||||
|
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0)
|
||||||
|
#endif
|
||||||
targetCategory = AVAudioSessionCategoryMultiRoute;
|
targetCategory = AVAudioSessionCategoryMultiRoute;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -276,9 +295,16 @@ bool CoreAudioSessionManager::setCategory(CoreAudioSessionManager::AudioSessionC
|
|||||||
if (targetCategory == nil)
|
if (targetCategory == nil)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return [[m_sessionObserver audioSession] setCategory:targetCategory
|
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||||
withOptions:(AVAudioSessionCategoryOptions)options
|
if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_6_0) {
|
||||||
error:nil];
|
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)
|
bool CoreAudioSessionManager::setMode(CoreAudioSessionManager::AudioSessionModes mode)
|
||||||
@@ -301,6 +327,9 @@ bool CoreAudioSessionManager::setMode(CoreAudioSessionManager::AudioSessionModes
|
|||||||
targetMode = AVAudioSessionModeMeasurement;
|
targetMode = AVAudioSessionModeMeasurement;
|
||||||
break;
|
break;
|
||||||
case CoreAudioSessionManager::MoviePlayback:
|
case CoreAudioSessionManager::MoviePlayback:
|
||||||
|
#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0)
|
||||||
|
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0)
|
||||||
|
#endif
|
||||||
targetMode = AVAudioSessionModeMoviePlayback;
|
targetMode = AVAudioSessionModeMoviePlayback;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -329,7 +358,11 @@ CoreAudioSessionManager::AudioSessionCategorys CoreAudioSessionManager::category
|
|||||||
localCategory = PlayAndRecord;
|
localCategory = PlayAndRecord;
|
||||||
} else if (category == AVAudioSessionCategoryAudioProcessing) {
|
} else if (category == AVAudioSessionCategoryAudioProcessing) {
|
||||||
localCategory = AudioProcessing;
|
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;
|
localCategory = MultiRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,7 +384,11 @@ CoreAudioSessionManager::AudioSessionModes CoreAudioSessionManager::mode()
|
|||||||
localMode = VideoRecording;
|
localMode = VideoRecording;
|
||||||
} else if (mode == AVAudioSessionModeMeasurement) {
|
} else if (mode == AVAudioSessionModeMeasurement) {
|
||||||
localMode = Measurement;
|
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;
|
localMode = MoviePlayback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,12 +417,32 @@ QList<QByteArray> CoreAudioSessionManager::outputDevices()
|
|||||||
|
|
||||||
float CoreAudioSessionManager::currentIOBufferDuration()
|
float CoreAudioSessionManager::currentIOBufferDuration()
|
||||||
{
|
{
|
||||||
return [[m_sessionObserver audioSession] IOBufferDuration];
|
#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()
|
float CoreAudioSessionManager::preferredSampleRate()
|
||||||
{
|
{
|
||||||
return [[m_sessionObserver audioSession] 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
|
#ifdef QT_DEBUG_COREAUDIO
|
||||||
|
|||||||
Reference in New Issue
Block a user