Skip to content

Instantly share code, notes, and snippets.

@hk0i
Last active April 18, 2017 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hk0i/7e972e1cbcb1d8b444b58f9f96134136 to your computer and use it in GitHub Desktop.
Save hk0i/7e972e1cbcb1d8b444b58f9f96134136 to your computer and use it in GitHub Desktop.
// MARK: - AVCaptureVideoDataOutputSampleBufferDelegate extension {{{
extension CtsVideoCallView: AVCaptureVideoDataOutputSampleBufferDelegate {
func captureOutput(_ captureOutput: AVCaptureOutput!,
didOutputSampleBuffer sampleBuffer: CMSampleBuffer!,
from: AVCaptureConnection!) {
// get image size for preview and resize preview view accordingly
let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
let attachmentMode = CMAttachmentMode(kCMAttachmentMode_ShouldPropagate)
let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, attachmentMode)
let ciImage:CIImage = CIImage(cvPixelBuffer: pixelBuffer!, options: attachments as! [String : Any]?)
let height = ciImage.extent.height
let width = ciImage.extent.width
let videoSizePx = CGSize(width: width, height: height)
self.localVideoResolution = videoSizePx
// forward call to rtc video capture
if let rtcVideoDataOutput = self.rtcVideoDataOutput {
rtcVideoDataOutput.sampleBufferDelegate.captureOutput?(rtcVideoDataOutput, didOutputSampleBuffer: sampleBuffer, from: from)
}
}
}
// }}} AVCaptureVideoDataOutputSampleBufferDelegate extension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment