Producer send rtp packet

Hello I want to do something like this.

const directTransport = await router.createDirectTransport();
const myproducer = await directTransport.produce(
  {
    kind: xxxx, 
    rtpParameters: xxxx,
  });



const consumer2 = await directTransport.consume({ producerId: producer.id,rtpCapabilities});
consumer2.on('rtp', (rtpPacket) => {
	myproducer.send(rtpPacket);
});

Is this possible ?

As far as you mangle the RTP packet so its fields (ssrc, payloadType, etc) matches those you signaled in the Producer rtpParameters… yes. But you are not doing that.

Or you could call directTranspprt.produce() with the consumer.rtpParameters. But for that you should create the Consumer first.

Your code does not make sense because you are creating a Producer, you don’t send any RTP to it and then you are creating a Consumer for it which will not receive any “rtp” event because there is no RTP at all

thank you for the answer

this worked

const directTransport = await router.createDirectTransport();

const consumer2 = await directTransport.consume({ producerId: producer.id,rtpCapabilities});
const producer3 = await directTransport.produce(
  {
  	kind:consumer2.kind,
  	rtpParameters:consumer2.rtpParameters
  });
consumer2.on('rtp', (rtpPacket) => {
	producer3.send(rtpPacket);
});

directTransport.on('rtcp', (Buffer) => {
	directTransport.sendRtcp(Buffer);
});

My goal is to transcode rtp packages with different software and include them in mediasoup again.
mediasoup directTransport.consume -> socket -> c++ -> transcode -> socket -> mediasoup producer -> mediasoup consumers -> client

1 Like

For transcoding you need to implement a RTP jitter buffer to order packets (that may arrive out of order) and wait for complete video frames in order. Easier if just for audio.

Usually this kind of thing is done with a PlainTransport, not a DirectTransport. It looks like:
plainTransport.consume → RTP → Transcoder (ffmpeg,gsteamer,c++ thing,etc) → RTP → plainTransport.produce

This way, your javascript never has to deal with any audo/video packets directly.