London Escorts sunderland escorts 1v1.lol unblocked yohoho 76 https://www.symbaloo.com/mix/yohoho?lang=EN yohoho https://www.symbaloo.com/mix/agariounblockedpvp https://yohoho-io.app/ https://www.symbaloo.com/mix/agariounblockedschool1?lang=EN
6 C
New York
Friday, January 31, 2025

ios – captureOutput(_:didOutput:from:) delegate technique not referred to as on one specific iPhone XR


I’m attempting to seize the digicam frames (CVPixelBuffers) utilizing the captureOutput(:didOutput:from:) delegate technique. For relevance, I then ship these frames to CoreML to categorise the picture.

Concern:
Works on all iOS units I might presumably get my palms on up to now aside from the iPhone XR. By works, I imply to state that the buffers are captured on all units aside from one specific XR oddly.

Specs:

  1. iPhone XR
  2. Concern famous in iOS 16.3 and 16.7 (haven’t tried different iOS variations)

What I’ve tried and blockers:

  1. Bought a refurbished XR from Amazon and it labored on that gadget. It additionally labored on a colleague’s XR.
  2. Sadly, I haven’t got steady entry to the XR the place the delegate technique was not fired as it’s a private cellphone and belongs to a shopper
  3. There appears to be no error thrown by Xcode as nicely – I might anticipate an error stating the buffers couldn’t be captured however sadly, Apple’s documentation solely identifies two delegate strategies (one being the captureOutput and the opposite associated to dropped frames)

Right here is the code the place I outline the view controller:

import Basis
import UIKit
import AVFoundation
import Imaginative and prescient


class TestCameraViewController: UIViewController {
    
    var bufferSize: CGSize = .zero
    non-public var previewView: UIView = UIView()
    non-public var previewLayer: AVCaptureVideoPreviewLayer! = nil

    non-public let session = AVCaptureSession()
    non-public let videoDataOutput = AVCaptureVideoDataOutput()
    non-public var currentVideoDevice: AVCaptureDevice?
                
    override func viewDidLoad() {
        tremendous.viewDidLoad()
        setupView()
        setupAVCapture()
        startCaptureSession()
    }
        
    func setupView() {
        previewView.translatesAutoresizingMaskIntoConstraints = false
        
        view.addSubview(previewView)
        previewView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
        previewView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
        previewView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
        previewView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
    }
    
    func setupAVCapture() {

        var deviceInput: AVCaptureDeviceInput!
        
        // Choose a video gadget, make an enter
        let videoDevice = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: .video, place: .again).units.first
        
        if videoDevice == nil {
            print("Gadget Does Not Exist, properties: nil, stage: .error, skipAnalytics: true")
            return
        }

        do {
            deviceInput = strive AVCaptureDeviceInput(gadget: videoDevice!)

        } catch {
            print("Couldn't create video gadget enter")
            return
        }
        
        session.beginConfiguration()
        session.sessionPreset = .vga640x480 // Mannequin picture dimension is smaller.
        
        // Add a video enter
        guard session.canAddInput(deviceInput) else {
            session.commitConfiguration()
            print("Couldn't add video gadget enter")
            return
        }
        
        session.addInput(deviceInput)
        
        if session.canAddOutput(videoDataOutput) {
            session.addOutput(videoDataOutput)
            videoDataOutput.alwaysDiscardsLateVideoFrames = true
            videoDataOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)]
            videoDataOutput.setSampleBufferDelegate(self, queue: .world())
            
        } else {
            session.commitConfiguration()
            print("Couldn't add video information output.")
            return
        }
                
        let captureConnection = videoDataOutput.connection(with: .video)
        captureConnection?.isEnabled = true
        
        do {
            strive  videoDevice!.lockForConfiguration()
            let dimensions = CMVideoFormatDescriptionGetDimensions((videoDevice?.activeFormat.formatDescription)!)
            bufferSize.width = CGFloat(dimensions.width)
            bufferSize.top = CGFloat(dimensions.top)
            videoDevice!.unlockForConfiguration()
        } catch {
            print("Couldn't lock video gadget configuration.")
            return
        }
        
        session.commitConfiguration()
        previewLayer = AVCaptureVideoPreviewLayer(session: session)
        previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
        self.currentVideoDevice = videoDevice
    }
    
    override func viewDidLayoutSubviews() {
        tremendous.viewDidLayoutSubviews()
        
        if previewLayer != nil {
            previewLayer.body = previewView.bounds
            previewView.layer.addSublayer(previewLayer)
        }
    }
    
    func startCaptureSession() {
        DispatchQueue.world(qos: .background).async {
            self.session.startRunning()
        }
    }
        
    // Clear up seize setup
    func teardownAVCapture() {
        session.stopRunning()
        previewLayer.removeFromSuperlayer()
        previewLayer = nil
    }
}

And right here is the code the place I conform to the delegate (which isn’t fired on the XR)

extension TestCameraViewController: AVCaptureVideoDataOutputSampleBufferDelegate {
    func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
        
        //NOT CALLED on one specific iPhone XR bodily gadget
        
        guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
            return
        }
    }
}

Would admire recommendations and subsequent steps or potential flaws within the code that may result in this behaviour.

Related Articles

Social Media Auto Publish Powered By : XYZScripts.com