This file contains hidden or 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
struct ContentView: View { | |
var body: some View { | |
VStack { | |
Button("Server") { | |
server?.start() | |
} | |
Spacer() | |
Button("Client") { | |
client.start() | |
} |
This file contains hidden or 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
// | |
// AVManager.swift | |
// VideoToolboxArticle | |
// | |
// Created by michal on 26/10/2020. | |
// | |
import AVFoundation | |
class AVManager { |
This file contains hidden or 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
import AVFoundation | |
import UIKit | |
class AVSampleBufferView: UIView { | |
var bufferLayer: AVSampleBufferDisplayLayer { | |
return layer as! AVSampleBufferDisplayLayer | |
} | |
override static var layerClass: AnyClass { |
This file contains hidden or 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
import AVFoundation | |
import UIKit | |
class ViewController: UIViewController { | |
private let cameraView = AVSampleBufferView() | |
private let encodedView = AVSampleBufferView() | |
private let decodedView = AVSampleBufferView() |
This file contains hidden or 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
import AVFoundation | |
import UIKit | |
class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate { | |
private let avManager = AVManager() | |
private let cameraView = AVSampleBufferView() | |
private let encodedView = AVSampleBufferView() |
This file contains hidden or 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
import AVFoundation | |
import VideoToolbox | |
class H264Coder { | |
var session: VTCompressionSession? | |
let outputCallback: VTCompressionOutputCallback = { refcon, sourceFrameRefCon, status, infoFlags, sampleBuffer in | |
guard let refcon = refcon, | |
status == noErr, |
This file contains hidden or 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
init(width: Int32, height: Int32) { | |
let status = VTCompressionSessionCreate(allocator: kCFAllocatorDefault, | |
width: width, | |
height: height, | |
codecType: kCMVideoCodecType_H264, | |
encoderSpecification: nil, | |
imageBufferAttributes: nil, | |
compressedDataAllocator: nil, | |
outputCallback: outputCallback, | |
refcon: Unmanaged.passUnretained(self).toOpaque(), |
This file contains hidden or 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
import AVFoundation | |
import UIKit | |
class AVSampleBufferView: UIView { | |
var bufferLayer: AVSampleBufferDisplayLayer { | |
return layer as! AVSampleBufferDisplayLayer | |
} | |
override static var layerClass: AnyClass { |
This file contains hidden or 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
import AVFoundation | |
import VideoToolbox | |
class H264Coder { | |
var session: VTCompressionSession? | |
var onFrame: ((CMSampleBuffer) -> Void)? | |
let outputCallback: VTCompressionOutputCallback = { refcon, sourceFrameRefCon, status, infoFlags, sampleBuffer in | |
guard let refcon = refcon, |
This file contains hidden or 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
import Accelerate | |
import AVFoundation | |
func reverse(fromUrl: URL) -> URL? { | |
do { | |
let input = try AVAudioFile(forReading: fromUrl) | |
let format = input.processingFormat | |
let frameCount = AVAudioFrameCount(input.length) | |
let outSettings = [AVNumberOfChannelsKey: format.channelCount, |