webrtc-java icon indicating copy to clipboard operation
webrtc-java copied to clipboard

Custom video sink

Open kalgecin opened this issue 1 year ago • 7 comments

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()

kalgecin avatar Oct 27 '23 12:10 kalgecin