現在レビューに出したアプリでiPadでポートレート対応している機種でのバグが出ている様です。しかし手元にその最新の機種が無いためデバッグできずに困っています。そこで以下のコードを実行した結果を教えていただきたいです。ログに出したものの結果がどうなっているかを知りたいです!
Swift
1import UIKit 2import AVFoundation 3 4class ViewController: UIViewController { 5 6 private var captureSession = AVCaptureSession() 7 private var photoOutput : AVCapturePhotoOutput? 8 private var currentDevice : AVCaptureDevice? 9 private var videoDeviceInput : AVCaptureDeviceInput! 10 private let videoDeviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera, .builtInDualCamera, .builtInTrueDepthCamera], 11 mediaType: .video, position: .unspecified) 12 13 override func viewDidLoad() { 14 super.viewDidLoad() 15 captureSession.sessionPreset = AVCaptureSession.Preset.photo 16 setupCaptureSession(withPosition: AVCaptureDevice.Position.front) 17 } 18 19 func setupCaptureSession(withPosition cameraPosition: AVCaptureDevice.Position) { 20 21 self.captureSession = AVCaptureSession() 22 photoOutput = AVCapturePhotoOutput() 23 guard let photoOutput = photoOutput else { return } 24 25 do { 26 captureSession.beginConfiguration() 27 captureSession.sessionPreset = .photo 28 let devices = self.videoDeviceDiscoverySession.devices 29 for device in devices { 30 if device.position == cameraPosition { 31 currentDevice = device 32 } 33 } 34 35 guard let videoDevice = currentDevice else { return } 36 videoDeviceInput = try AVCaptureDeviceInput(device: videoDevice) 37 38 if captureSession.canAddInput(videoDeviceInput) { 39 captureSession.addInput(videoDeviceInput) 40 } 41 42 43 } catch { 44 print(error) 45 } 46 47 // add audio input to a capture session 48 let audioDevice = AVCaptureDevice.default(for: AVMediaType.audio) 49 let audioInput = try! AVCaptureDeviceInput(device: audioDevice!) 50 self.captureSession.addInput(audioInput) 51 52 if captureSession.canAddOutput(photoOutput) { 53 captureSession.addOutput(photoOutput) 54 55 photoOutput.isHighResolutionCaptureEnabled = true 56 photoOutput.isLivePhotoCaptureEnabled = photoOutput.isLivePhotoCaptureSupported 57 photoOutput.isDepthDataDeliveryEnabled = photoOutput.isDepthDataDeliverySupported 58 print("photoOutput.isDepthDataDeliverySupported:", photoOutput.isDepthDataDeliverySupported) 59 photoOutput.isPortraitEffectsMatteDeliveryEnabled = photoOutput.isPortraitEffectsMatteDeliverySupported 60 print("photoOutput.isPortraitEffectsMatteDeliverySupported:", photoOutput.isPortraitEffectsMatteDeliverySupported) 61 photoOutput.enabledSemanticSegmentationMatteTypes = photoOutput.availableSemanticSegmentationMatteTypes 62 print("photoOutput.availableSemanticSegmentationMatteTypes:", photoOutput.availableSemanticSegmentationMatteTypes) 63 photoOutput.maxPhotoQualityPrioritization = .quality 64 captureSession.commitConfiguration() 65 } 66 67 self.captureSession.startRunning() 68 } 69 70 71 72}
ーーーーーーーーーーーーーーーーーーー変更後ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
レビュワー側では以下のprint("isDepthDataDeliveryEnabled: FALSE")の部分が実行されてしまっている様です。ポートレイト対応機種ならphotoOutput!.isDepthDataDeliveryEnabledはtrueとなっていると思われるのですが、ここが実行されてしまう可能性は何かあるのでしょうか?もしわかる方がいたら教えて頂きたいです。。。
swift
1import UIKit 2import AVFoundation 3 4class ViewController: UIViewController { 5 6 private var captureSession = AVCaptureSession() 7 private var photoOutput : AVCapturePhotoOutput? 8 private var currentDevice : AVCaptureDevice? 9 private var videoDeviceInput : AVCaptureDeviceInput! 10 private var photoQualityPrioritizationMode: AVCapturePhotoOutput.QualityPrioritization = .balanced 11 private let videoDeviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera, .builtInDualCamera, .builtInTrueDepthCamera], 12 mediaType: .video, position: .unspecified) 13 14 override func viewDidLoad() { 15 super.viewDidLoad() 16 captureSession.sessionPreset = AVCaptureSession.Preset.photo 17 setupCaptureSession(withPosition: AVCaptureDevice.Position.front) 18 action() 19 } 20 21 func setupCaptureSession(withPosition cameraPosition: AVCaptureDevice.Position) { 22 23 self.captureSession = AVCaptureSession() 24 photoOutput = AVCapturePhotoOutput() 25 guard let photoOutput = photoOutput else { return } 26 27 do { 28 captureSession.beginConfiguration() 29 captureSession.sessionPreset = .photo 30 let devices = self.videoDeviceDiscoverySession.devices 31 for device in devices { 32 if device.position == cameraPosition { 33 currentDevice = device 34 } 35 } 36 37 guard let videoDevice = currentDevice else { return } 38 videoDeviceInput = try AVCaptureDeviceInput(device: videoDevice) 39 40 if captureSession.canAddInput(videoDeviceInput) { 41 captureSession.addInput(videoDeviceInput) 42 } 43 44 45 } catch { 46 print(error) 47 } 48 49 // add audio input to a capture session 50 let audioDevice = AVCaptureDevice.default(for: AVMediaType.audio) 51 let audioInput = try! AVCaptureDeviceInput(device: audioDevice!) 52 self.captureSession.addInput(audioInput) 53 54 if captureSession.canAddOutput(photoOutput) { 55 captureSession.addOutput(photoOutput) 56 57 photoOutput.isHighResolutionCaptureEnabled = true 58 photoOutput.isLivePhotoCaptureEnabled = photoOutput.isLivePhotoCaptureSupported 59 photoOutput.isDepthDataDeliveryEnabled = photoOutput.isDepthDataDeliverySupported 60 print("photoOutput.isDepthDataDeliverySupported:", photoOutput.isDepthDataDeliverySupported) 61 photoOutput.isPortraitEffectsMatteDeliveryEnabled = photoOutput.isPortraitEffectsMatteDeliverySupported 62 print("photoOutput.isPortraitEffectsMatteDeliverySupported:", photoOutput.isPortraitEffectsMatteDeliverySupported) 63 photoOutput.enabledSemanticSegmentationMatteTypes = photoOutput.availableSemanticSegmentationMatteTypes 64 print("photoOutput.availableSemanticSegmentationMatteTypes:", photoOutput.availableSemanticSegmentationMatteTypes) 65 photoOutput.maxPhotoQualityPrioritization = .quality 66 captureSession.commitConfiguration() 67 } 68 69 self.captureSession.startRunning() 70 } 71 72 func action(){ 73 var settings = AVCapturePhotoSettings() 74 settings = AVCapturePhotoSettings(format: [AVVideoCodecKey: AVVideoCodecType.hevc]) 75 settings.flashMode = .auto 76 settings.isHighResolutionPhotoEnabled = true 77 settings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String: settings.__availablePreviewPhotoPixelFormatTypes.first!] 78 settings.isDepthDataDeliveryEnabled = true 79 settings.isPortraitEffectsMatteDeliveryEnabled = true 80 81 if !(self.photoOutput?.enabledSemanticSegmentationMatteTypes.isEmpty)! { 82 settings.enabledSemanticSegmentationMatteTypes = self.photoOutput?.enabledSemanticSegmentationMatteTypes ?? [AVSemanticSegmentationMatte.MatteType]() 83 } else { 84 print("enabledSemanticSegmentationMatteTypes is Empty") 85 } 86 87 settings.photoQualityPrioritization = self.photoQualityPrioritizationMode 88 89 90 if (!photoOutput!.isDepthDataDeliveryEnabled) { 91 print("isDepthDataDeliveryEnabled: FALSE") 92 } else { 93 print("isDepthDataDeliveryEnabled: TRUE") 94 } 95 96 } 97 98} 99 100
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/04/25 08:33