Skip to content

Instantly share code, notes, and snippets.

@zontan
Created September 9, 2020 00:26
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 zontan/b9832bea7b4d04473f37a635c668e9be to your computer and use it in GitHub Desktop.
Save zontan/b9832bea7b4d04473f37a635c668e9be to your computer and use it in GitHub Desktop.
import AgoraRtcKit
/**
A custom video source for the AgoraRtcEngine. This class conforms to the AgoraVideoSourceProtocol and is used to pass the AR pixel buffer as a video source of the Agora stream.
*/
class CustomVideoSource: NSObject, AgoraVideoSourceProtocol {
var consumer: AgoraVideoFrameConsumer?
var rotation: AgoraVideoRotation = .rotation180 //Banuba frames are flipped compared to what Agora expects.
func shouldInitialize() -> Bool { return true }
func shouldStart() { }
func shouldStop() { }
func shouldDispose() { }
func bufferType() -> AgoraVideoBufferType {
return .pixelBuffer
}
func captureType() -> AgoraVideoCaptureType {
return .camera
}
func contentHint() -> AgoraVideoContentHint {
return .motion
}
func sendBuffer(_ buffer: CVPixelBuffer, timestamp: TimeInterval) {
let time = CMTime(seconds: timestamp, preferredTimescale: 1000)
consumer?.consumePixelBuffer(buffer, withTimestamp: time, rotation: rotation)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment