Use current AVCaptureSession on WebRTC on iOS devices

I will talk about my current project and what I want to do.

Current project: I have an iOS application that is currently recording video and saving it to disk. I use Apple's Avfoundation libraries to record and display the capture screen on the device.

I want to do:

I want to keep current functionality by adding webrtc. The problem is that the webrtc project already uses AVCaptureSession, and you cannot have two sessions in one application.

I asked about it, but it seems complicated. Someone told me about writing a subclass of cricket :: VideoCapturer, but I'm not sure that I need to rewrite each class for this in C ++. I also saw that AvCapturesession is written in the rtc_video_capturer_ios.h file, but I don’t understand how to pass my AVCaptureSession to this class from my current project.

Does anyone have an example? I need orientation.

Many thanks for your help.

+4
source share
1 answer

Google WebRTC, , . https://groups.google.com/forum/?fromgroups=&hl=sv#!topic/discuss-webrtc/8TgRy9YWvVc - .

RTCAVFoundationVideoSource, captureSession, , AVCaptureSession.

Google ( , ?), - .

- :

    for output in sourceAVFoundation.captureSession.outputs {
        if let videoOutput = output as? AVCaptureVideoDataOutput {

            self.videoOutput = videoOutput
            NSLog("+++ FOUND A VIDEO OUTPUT: \(videoOutput) -> \(videoOutput.sampleBufferDelegate)")
            externalVideoBufferDelegate = videoOutput.sampleBufferDelegate
            videoOutput.setSampleBufferDelegate(self, queue: videoBufferDelegateQueue)
        }
    }

, videoBufferDelegate (.. WebRTC ), .

AVCaptureVideoDataOutputSampleBufferDelegate () , - :

func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {

    externalVideoBufferDelegate?.captureOutput!(captureOutput, didOutputSampleBuffer: sampleBuffer, fromConnection: connection)

    dispatch_async(videoQueue) {
        if self.assetWriterVideoInput.readyForMoreMediaData {
            self.assetWriterVideoInput.appendSampleBuffer(sampleBuffer)
        }
    }
}

, , - externalVideoBufferDelegate, - WebRTC .

+1

All Articles