Last active
April 18, 2017 16:57
-
-
Save hk0i/7e972e1cbcb1d8b444b58f9f96134136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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