Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to custom WebRTC video source?

Does someone know how to change WebRTC (https://cocoapods.org/pods/libjingle_peerconnection) video source?

I am working on an screen sharing app. At the moment, I retrieve the rendered frames in real-time in CVPixelBuffer. Does someone know how I could add my frames as video source please? Is it possible to set an other video source instead of camera device source ? Is yes, which format the video has to be and how to do it ?

Thanks.

like image 719
Eric Kevin Avatar asked Mar 26 '18 14:03

Eric Kevin


2 Answers

var connectionFactory :  RTCPeerConnectionFactory = RTCPeerConnectionFactory()
let videoSource :  RTCVideoSource = factory.videoSource()
videoSource.capturer(videoCapturer, didCapture: videoFrame!)
like image 127
Mouni Avatar answered Nov 17 '22 22:11

Mouni


Mounis answer is wrong. This leads to nothing. At least not at the time of this writing. There is simply nothing happening.

In fact, you would need to satisfy this delegate

- (void)capturer:(RTCVideoCapturer *)capturer didCaptureVideoFrame:(RTCVideoFrame *)frame;

(Note the difference to the Swift version: didCapture vs. didCaptureVideoFrame)

Since this delegate is for unclear reasons not available at Swift level (the compiler says you have to use didCapture, since it has been renamed from didCaptureVideoFrame with Swift3) you have to put the code int an ObjC class. I did copy this and this (which is a part of this sample project)into my project, made my videoCapturer an instance of ARDBroadcastSampleHandler

self.videoCapturer = ARDExternalSampleCapturer(delegate: videoSource)

and within the capture callback I'm calling it

let capturer = self.videoCapturer as? ARDExternalSampleCapturer
capturer?.didCapture(sampleBuffer)
like image 3
decades Avatar answered Nov 17 '22 23:11

decades