Help with Barcode Capture

I am developing an app that requires barcode scanning and outputting the metadata to a label. This feature uses AVCaptureSession to capture the data and AVCaptureVideoPreviewLayer to preview the camera view.

I have the barcode scanning working properly, but need help capturing the barcode more accurately. Right now the barcode is being captured anywhere within the preview layer, which fills the entire view. I am looking for a way to define some sort of capture area that will scan the barcode only if the barcode is within the capture area.

I've included a picture to help explain this. In the picture the red line is where the camera detects a barcode. I am trying to make it so the barcode is detected and scanned only within the open black box at the center.

Ideally I would like to keep the preview layer fullscreen, while having a small "capture area" that captures the barcode data.

Any help would be appreciated!

Image link:![IMG_0274|375x500](upload://iHt7kGX2NnWMM0oOS0abCZtGhkX.jpeg)