Setting up an RTP Mirror using LibJitsi

Hello,
i am currently trying out LibJitsi for an RTP Streaming Server. To get to know the inner workings i wanted to set up a simple RTP Mirror, a small program that accepts an RTP Audio Stream and sends it to another target. The code i wrote looks like this (LibJitsi.start() is called elsewhere):

var mediaService = LibJitsi.getMediaService();
                
var con = new DefaultStreamConnector(new DatagramSocket(50001), new DatagramSocket(50002));
                
var stream = mediaService.createMediaStream(con, MediaType.AUDIO);
stream.setDirection(MediaDirection.SENDRECV);
                
var format = mediaService.getFormatFactory().createMediaFormat("PCMU", 8000);
                
stream.setFormat(format);

var rtpTarget = new InetSocketAddress(remoteAddr, remotePort);
var crtpTarget = new InetSocketAddress(remoteAddr, remotePort + 1);
var tar = new MediaStreamTarget(rtpTarget, crtpTarget);
stream.setTarget(tar);
                
this.outStream = stream;
                
this.outStream.start();

If i interpret the log output correctly, the RTP Packets arrive correctly, but the Mediastream doesnt have a target to stream to, even tho its explicitly set. My own delving into the Source leads me to believe i need some form of MediaDevice in there.

My Questions:
Is my above approach in the right direction overall?
Does a MediaDevice have to be backed by a hardware device?
What is the RTPTranslator used for in the MediaStream?

Hi Lucas,

Unless you need to transcode, or work with raw audio/video for another reason I suggest to use jitsi-media-transform[0] instead of libjitsi.

The stream in your code should have a target, but without either a MediaDevice or an RtpTranslator it has no output to send.

To forward the RTP stream you receive without transcoding, you can use two MediaStreams with an RtpTranslator. This hooks up the input of one stream to the output of the other. However, for this case I suggest using a different library since libjitsi is not actively developed right now.

If you want to mix audio, you can use an AudioMixerMediaDevice instead of an RtpTranslator. This will again require multiple MediaStreams.

I hope this helps,
Boris

[0] https://github.com/jitsi/jitsi-media-transform