Commit c14927b7 by pidan

修复退出后台,后置摄像头会自动切成前置摄像头的问题

parent 400bae57
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
@property (nonatomic, strong) NSLock *lock; @property (nonatomic, strong) NSLock *lock;
@property (nonatomic, assign) AVCaptureDevicePosition currentCameraPosition;
@end @end
@implementation FUSByteStreamCaptureHelper @implementation FUSByteStreamCaptureHelper
...@@ -60,6 +62,7 @@ ...@@ -60,6 +62,7 @@
// 初始化参数值 // 初始化参数值
_isFirstFrame = YES; _isFirstFrame = YES;
_mySwitch = YES; _mySwitch = YES;
_currentCameraPosition = AVCaptureDevicePositionFront;
[self initBeautyEngine]; [self initBeautyEngine];
[self initStreamingSession]; [self initStreamingSession];
...@@ -75,15 +78,18 @@ ...@@ -75,15 +78,18 @@
- (void)fus_becomeActiveNotification:(NSNotification *)notification { - (void)fus_becomeActiveNotification:(NSNotification *)notification {
AVCaptureDevicePosition position = _capture.cameraPosition;
if (!self.engine.camera.isRunning) { if (!self.engine.camera.isRunning) {
[self.engine.camera startCameraCapture]; [self.engine.camera startCameraCapture];
} }
[self.capture startVideoCapture]; [self.capture startVideoCapture];
self.capture.cameraPosition = self.currentCameraPosition;
} }
- (void)fus_resignActiveNotification:(NSNotification *)notification { - (void)fus_resignActiveNotification:(NSNotification *)notification {
AVCaptureDevicePosition position = _capture.cameraPosition;
if (!self.engine.camera.isRunning) { if (!self.engine.camera.isRunning) {
[self.engine.camera stopCameraCapture]; [self.engine.camera stopCameraCapture];
} }
...@@ -131,7 +137,7 @@ ...@@ -131,7 +137,7 @@
} }
}]; }];
_capture.cameraPosition = AVCaptureDevicePositionFront ; _capture.cameraPosition = AVCaptureDevicePositionFront;
_capture.inPixelFmt = kCVPixelFormatType_32BGRA; _capture.inPixelFmt = kCVPixelFormatType_32BGRA;
[_capture setEnableEffect:YES]; [_capture setEnableEffect:YES];
[_capture resetPreviewView:self.previewContainer]; [_capture resetPreviewView:self.previewContainer];
...@@ -162,6 +168,7 @@ ...@@ -162,6 +168,7 @@
[self.engine.camera setWhiteBalanceMode:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance]; [self.engine.camera setWhiteBalanceMode:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance];
[self.engine.camera setExposureMode:AVCaptureExposureModeContinuousAutoExposure]; [self.engine.camera setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
[self.engine.camera setCaptureFocusMode:AVCaptureFocusModeContinuousAutoFocus]; [self.engine.camera setCaptureFocusMode:AVCaptureFocusModeContinuousAutoFocus];
self.capture.cameraPosition = self.currentCameraPosition;
} }
...@@ -308,6 +315,7 @@ ...@@ -308,6 +315,7 @@
/// 开启推流 /// 开启推流
[self.engine startStreaming]; [self.engine startStreaming];
self.capture.cameraPosition = self.currentCameraPosition;
} }
/** /**
...@@ -319,6 +327,16 @@ ...@@ -319,6 +327,16 @@
if (_engine.isStreaming) { if (_engine.isStreaming) {
[_engine stopStreaming]; [_engine stopStreaming];
} }
// 背景模式
[_engine setEnableAudioCaptureInBackground:NO];
_engine.liveSession.echoCancellationEnabled = NO;
[_engine setEchoCancellationEnabled:NO];
[_engine setupAudioCaptureWithConfig:nil];
if (_engine.liveSession.configuration) {
[_engine setupLiveSessionWithConfig:nil];
}
} }
/** /**
...@@ -330,21 +348,26 @@ ...@@ -330,21 +348,26 @@
return; return;
} }
// 视讯的时候只需要采集。不需要推流操作
if (self.config.captureType == FUSStreamCaptureTypeVideoChat) {
return;
}
BOOL muted = self.mute; BOOL muted = self.mute;
// 在后台期间不做重载操作,容易导致闪退 // 在后台期间不做重载操作,容易导致闪退
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
return; return;
} }
if (self.engine.liveSession.liveSessionState == LiveStreamSessionStateError || if (self.engine.liveSession.liveSessionState == LiveStreamSessionStateReconnecting ||
self.engine.liveSession.liveSessionState == LiveStreamSessionStateReconnecting) { self.engine.liveSession.liveSessionState == LiveStreamSessionStateStarted ||
self.engine.liveSession.liveSessionState == LiveStreamSessionStateStarting) {
[self.engine startStreaming]; [self.engine startStreaming];
self.mute = muted; self.mute = muted;
return; return;
} }
// 视讯的时候只需要采集。不需要推流操作 if (self.engine.liveSession.liveSessionState == LiveStreamSessionStateError) {
if (self.config.captureType != FUSStreamCaptureTypeVideoChat) {
// 重新推流。先把原本的推流对象释放掉。生成新的推流对象,否则会发送推不上流的情况 // 重新推流。先把原本的推流对象释放掉。生成新的推流对象,否则会发送推不上流的情况
[self fus_stopStreamPush]; [self fus_stopStreamPush];
...@@ -356,6 +379,9 @@ ...@@ -356,6 +379,9 @@
[self fus_startStreamPushWithUrl:self.pushUrl completionHandler:self.completionHandler]; [self fus_startStreamPushWithUrl:self.pushUrl completionHandler:self.completionHandler];
self.mute = muted; self.mute = muted;
}); });
} else {
[self fus_setupLiveSessionConfigs];
[self fus_startStreamPushWithUrl:self.pushUrl completionHandler:self.completionHandler];
} }
} }
...@@ -393,6 +419,12 @@ ...@@ -393,6 +419,12 @@
*/ */
- (void)fus_switchCamera - (void)fus_switchCamera
{ {
if (self.currentCameraPosition == AVCaptureDevicePositionBack) {
self.currentCameraPosition = AVCaptureDevicePositionFront;
} else if (self.currentCameraPosition == AVCaptureDevicePositionFront) {
self.currentCameraPosition = AVCaptureDevicePositionBack;
}
[self.engine.camera switchCamera]; [self.engine.camera switchCamera];
[self fus_offTorch]; [self fus_offTorch];
} }
...@@ -418,8 +450,10 @@ ...@@ -418,8 +450,10 @@
{ {
if (position == AVCaptureDevicePositionBack && [self.engine.camera isFrontFacingCameraPresent]) { if (position == AVCaptureDevicePositionBack && [self.engine.camera isFrontFacingCameraPresent]) {
self.engine.camera.bMirrorRearCamera = position; self.engine.camera.bMirrorRearCamera = position;
self.currentCameraPosition = position;
} else if (position == AVCaptureDevicePositionFront && [self.engine.camera isBackFacingCameraPresent]) { } else if (position == AVCaptureDevicePositionFront && [self.engine.camera isBackFacingCameraPresent]) {
self.engine.camera.bMirrorRearCamera = position; self.engine.camera.bMirrorRearCamera = position;
self.currentCameraPosition = position;
} }
} }
...@@ -461,6 +495,7 @@ ...@@ -461,6 +495,7 @@
{ {
if (enable) { if (enable) {
[self.engine.camera startCameraCapture]; [self.engine.camera startCameraCapture];
self.capture.cameraPosition = self.currentCameraPosition;
} else { } else {
[self.engine.camera stopCameraCapture]; [self.engine.camera stopCameraCapture];
} }
......
...@@ -103,7 +103,7 @@ import FUSCommon ...@@ -103,7 +103,7 @@ import FUSCommon
//这里特殊用户有不一样的逻辑 //这里特殊用户有不一样的逻辑
let iconImagesList = ["live_start_openScope_cell","live_start_passwordScope_cell"/*,"live_start_intimacyScope_cell"*/] let iconImagesList = ["live_start_openScope_cell","live_start_passwordScope_cell"/*,"live_start_intimacyScope_cell"*/]
let titlesList = [String.fus_versionLocalString("公开屋"), .fus_versionLocalString("私享屋")/*, .fus_localString("亲密圈")*/] let titlesList = [String.fus_versionLocalString("公开屋"), .fus_versionLocalString("私享屋")/*, .fus_localString("亲密圈")*/]
let subTitlesList = [String.fus_localString("所有人可进入房间"), .fus_versionLocalString("玩家正确输入密码后可进入屋内")/*, .fus_localString("仅亲密好友可进入房间")*/] let subTitlesList = [String.fus_localString("所有人可进入房间"), .fus_versionLocalString("已关闭窗帘,玩家输入密码打开")/*, .fus_localString("仅亲密好友可进入房间")*/]
let itemHeight = 56.0 let itemHeight = 56.0
privacyContentView.snp.makeConstraints { make in privacyContentView.snp.makeConstraints { make in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment