私はAVCaptureSessionを使用して、iPhoneの拡張現実タイプのアプリでビデオをプレビューしています。ビデオプレビューの上にOpenGLグラフィックも描画しているので、このアプリは非常にエネルギーを消費します。バッテリーを節約するためにCPU使用率を最小限に抑えたい。
Instruments / Energyの使用量でアプリを確認すると、CPUのかなりの部分(約20%)がオーディオ処理で「無駄になっている」ことがわかります。キャプチャセッションを削除すると、予想どおり、オーディオ処理にCPUは使用されません。
オーディオデバイス入力を追加していないため、キャプチャセッションがオーディオ処理を行っている理由がわかりません。セッションの設定方法は次のとおりです。
if(!captureSession) {
captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (videoDevice) {
NSError *error;
AVCaptureDeviceInput *videoIn = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
if (!error) {
if ([captureSession canAddInput:videoIn]) {
[captureSession addInput:videoIn];
}
}
}
}
if(!previewLayer) {
previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:captureSession];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
}
CGRect layerRect = [[viewBg layer] bounds];
[previewLayer setBounds:layerRect];
[previewLayer setPosition:CGPointMake(CGRectGetMidX(layerRect), CGRectGetMidY(layerRect))];
[[viewBg layer] addSublayer:previewLayer];
[captureSession startRunning];
オーディオ(入力)を完全に無効にする方法はありますか、またはビデオ入力のプレビュー中にオーディオ処理のCPU使用率を取り除くにはどうすればよいですか?