i faced a such issue and i made this: create CIContext in SampleHandler.init()
if let metalDevice = MTLCreateSystemDefaultDevice() {
coreImageContext = CIContext(mtlDevice: metalDevice)
} else {
coreImageContext = CIContext(options: nil)
}
2. add rotate method
private func rotate(_ sampleBuffer: CMSampleBuffer) -> CVPixelBuffer? {
guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
return nil
}
var newPixelBuffer: CVPixelBuffer?
let error = CVPixelBufferCreate(kCFAllocatorDefault,
CVPixelBufferGetHeight(pixelBuffer),
CVPixelBufferGetWidth(pixelBuffer),
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
nil,
&newPixelBuffer)
guard error == kCVReturnSuccess,
let buffer = newPixelBuffer else {
return nil
}
let ciImage = CIImage(cvPixelBuffer: pixelBuffer).oriented(.left)
coreImageContext.render(ciImage, to: buffer)
return buffer
}
3. use the rotate() method in processSampleBuffer and send rotated buffer to a streaming-service
Post
Replies
Boosts
Views
Activity
I met that situation. So i understood that broadcast-extension terminated earlier than system alert will be appeared. please check my solution:
1 - create property of SampleHandler
private var startedWithError: BroadcastError? = nil
2 - set this error in streamStarted method
override func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) {
guard let streamingSession = streamingSession else {
startedWithError = .failedInitStreamingService
return
}
		// some success code here
}
3 - check error in processSampleBuffer
override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {
if let error = startedWithError {
finishBroadcastWithError(error.nsError)
}
P.S. Also you can use DispatchQueue.global.asyncAfter(.now()+0.5){ self.finishBroadcastWithError(error.nsError) } in broadcastStarted