webrtc-java
webrtc-java copied to clipboard
Custom video sink
val peerConnectionFactory = PeerConnectionFactory(audioDeviceModule)
val customVideoSource = CustomVideoSource()
val customTrack = peerConnectionFactory.createVideoTrack("custom-src", customVideoSource)
connection = peerConnectionFactory.createPeerConnection(config, peerObserver)
connection.addTrack(customTrack, listOf(customTrack.id))
val data = //generate yuv frame byte array
val nativeI420Buffer = NativeI420Buffer.allocate(width, height)
nativeI420Buffer.dataY.put(0, data, 0, ySize)
nativeI420Buffer.dataU.put(0, data, ySize, uvSize)
nativeI420Buffer.dataV.put(0, data, ySize + uvSize, uvSize)
val videoFrame = VideoFrame(nativeI420Buffer, 0, System.currentTimeMillis() * 1000000)
customVideoSource.OnFrameCaptured(videoFrame)
videoFrame.release()