0 Replies
      Latest reply on Jan 30, 2020 12:20 AM by bhamin.patel@zeuslearning.com
      bhamin.patel@zeuslearning.com Level 1 Level 1 (0 points)

        Below is the code that i have In broadcast upload extension


        override func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) {

                // 1. create compression session

                let status = VTCompressionSessionCreate(allocator: nil, width: 1280, height: 720, codecType: kCMVideoCodecType_H264,                     encoderSpecification: nil, imageBufferAttributes: nil, compressedDataAllocator: nil, outputCallback: compressionOutputCallback as?                     VTCompressionOutputCallback, refcon: nil, compressionSessionOut: &compression_session)

                if let session = compression_session{

                    VTSessionSetProperty(session, key: kVTCompressionPropertyKey_RealTime, value: kCFBooleanTrue)

                    let retStatus = VTCompressionSessionPrepareToEncodeFrames(session)

                    print("SBC: VTCompressionSessionCreate -", status == noErr, "PrepareToEncodeFrames -", retStatus == noErr)




        override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {

                //print("SBC: processSampleBuffer", sampleBuffer.numSamples, sampleBufferType.rawValue)

                switch sampleBufferType {

                case RPSampleBufferType.video:


                    // Handle video sample buffer

                    let pts = CMSampleBufferGetPresentationTimeStamp(sampleBuffer)

                    let imageBuffer:CVImageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!


                    if let session = compression_session {

                        // 2. encode frame

                        let ret = VTCompressionSessionEncodeFrame(session, imageBuffer: imageBuffer, presentationTimeStamp: pts, duration:                     CMTime.invalid, frameProperties: nil, sourceFrameRefcon: nil, infoFlagsOut: nil)

                        if ret == noErr{

                            print("SBC: VTCompressionSessionEncodeFrame ret", ret)




                case RPSampleBufferType.audioApp:

                    // Handle audio sample buffer for app audio


                case RPSampleBufferType.audioMic:

                    // Handle audio sample buffer for mic audio


                @unknown default:

                    // Handle other sample buffer types

                    fatalError("Unknown type of sample buffer")



        func compressionOutputCallback(outputCallbackRefCon:UnsafeMutableRawPointer?, sourceFrameRefCon:UnsafeMutableRawPointer?,

                    status:OSStatus, infoFlags:VTEncodeInfoFlags, sampleBuffer:CMSampleBuffer) {

                // Do whatever you want with the sampleBuffer


                if status != noErr{

                    NSLog("SBC: Error encoding video", status)

                    print("SBC: Error encoding video", status)



                print("SBC: compressionOutputCallback dataBuffer", status)



        What am i missing? ANY HELP WOULD BE APPRECIATED