Last active
May 9, 2016 22:28
-
-
Save ninjudd/2736cbecf2b372bab778a9068a30aa09 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
// | |
// TWCPixelBufferFrame.swift | |
// | |
// Created by Justin Balthrop on 5/2/16. | |
// | |
import UIKit | |
class TWCPixelBufferFrame: TWCI420Frame { | |
var pixelBuffer: CVPixelBuffer | |
init(pixelBuffer: CVPixelBuffer) { | |
self.pixelBuffer = pixelBuffer | |
} | |
init(sampleBuffer: CMSampleBuffer) { | |
self.pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) | |
} | |
func getPlane(index: Int) -> UnsafePointer<UInt8> { | |
return UnsafePointer<UInt8>(CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, index)) | |
} | |
func bytesPerRowOfPlane(index: Int) -> Int { | |
return CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, index) | |
} | |
func widthOfPlane(index: Int) -> UInt { | |
return UInt(CVPixelBufferGetWidthOfPlane(pixelBuffer, index)) | |
} | |
func heightOfPlane(index: Int) -> UInt { | |
return UInt(CVPixelBufferGetHeightOfPlane(pixelBuffer, index)) | |
} | |
override var yPlane: UnsafePointer<UInt8> { return getPlane(0) } | |
override var uPlane: UnsafePointer<UInt8> { return getPlane(1) } | |
override var vPlane: UnsafePointer<UInt8> { return getPlane(2) } | |
override var yPitch: Int { return bytesPerRowOfPlane(0) } | |
override var uPitch: Int { return bytesPerRowOfPlane(1) } | |
override var vPitch: Int { return bytesPerRowOfPlane(2) } | |
override var width: UInt { return widthOfPlane(0) } | |
override var height: UInt { return heightOfPlane(1) } | |
override var chromaSize: UInt { return heightOfPlane(1) * UInt(bytesPerRowOfPlane(1)) } | |
override var chromaWidth: UInt { return widthOfPlane(1) } | |
override var chromaHeight: UInt { return heightOfPlane(1) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment