Skip to content

Commit 754b2dc

Browse files
tonychanchenoldcodefarmer
authored andcommitted
优化前后摄像头设置
Change-Id: Ie26f55501fb204289b0508cceaecba5af4d1917c (cherry picked from commit 6c68d5d)
1 parent 30e222d commit 754b2dc

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Source/SDK/LinkVideo/FLV/TIoTAVCaptionFLV.mm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,31 @@ - (AVCaptureDevice *)cameraWithPosition:(AVCaptureDevicePosition)position
100100
return nil;
101101
}
102102

103+
- (void)changeCameraWithPositon:(AVCaptureDevicePosition)position {
104+
AVCaptureDevice *newCamera = [self cameraWithPosition:position];
105+
AVCaptureDeviceInput *newInput = [AVCaptureDeviceInput deviceInputWithDevice:newCamera error:nil];
106+
if (newInput != nil) {
107+
[self.session beginConfiguration];
108+
//先移除原来的input
109+
[self.session removeInput:self.deviceInput];
110+
if ([self.session canAddInput:newInput]) {
111+
[self.session addInput:newInput];
112+
self.deviceInput = newInput;
113+
}else{
114+
//如果不能加现在的input,就加原来的input
115+
[self.session addInput:self.deviceInput];
116+
}
117+
118+
self.session.sessionPreset = self.resolutionRatioValue;
119+
// 保存Connection,用于SampleBufferDelegate中判断数据来源(video or audio?)
120+
_videoConnection = [_videoOutput connectionWithMediaType:AVMediaTypeVideo];
121+
[_videoConnection setVideoOrientation:AVCaptureVideoOrientationPortrait];
122+
123+
[self.session commitConfiguration];
124+
}
125+
126+
[self setCameraFPS:15];
127+
}
103128
/**
104129
切换前后摄像头
105130
*/
@@ -232,6 +257,9 @@ - (void)setupVideoCapture {
232257
if ([_session canSetSessionPreset:self.resolutionRatioValue]) {
233258
// 设置分辨率
234259
_session.sessionPreset = self.resolutionRatioValue;
260+
261+
//设置传入的position
262+
[self changeCameraWithPositon:self.devicePosition];
235263
}
236264
return;
237265
}

0 commit comments

Comments
 (0)