Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use WebRTC as client for Mediasoup #613

Open
kristian1108 opened this issue Sep 16, 2024 · 0 comments
Open

Use WebRTC as client for Mediasoup #613

kristian1108 opened this issue Sep 16, 2024 · 0 comments

Comments

@kristian1108
Copy link

Hi -- I'm trying to use this library as a client for a MediaSoup server, talking to a MediaSoup producer. See https://docs.rs/mediasoup/latest/mediasoup/

I have the DTLS Transport connected, verified with:

 dtls_transport.on_state_change(Box::new(|state| {
        println!("DTLS state changed: {:?}", state);
        Box::pin(async {})
}));

And I have an RTCRtpSender from:

let track_local = Arc::new(TrackLocalStaticRTP::new(
    RTCRtpCodecCapability {
        mime_type: MIME_TYPE_OPUS.to_string(),
        clock_rate: 48000,
        channels: num_channels,
        sdp_fmtp_line: "".to_string(),
        rtcp_feedback: vec![rtcp_feedback],
    },
    String::from("some-track-id"),
    String::from("some-stream-id")
));
let track_local_clone = track_local.clone();

let r = api.new_rtp_sender(Some(track_local), dtls_transport.clone(), interceptor.clone()).await;

And I have some opus chunks being written like this:

let mut sample_chunks = resampled.chunks(samples_per_buffer);
loop {
    interval_timer.tick().await;

    if let Some(chunk) = sample_chunks.next() {
        let opus_bytes = opus_encoder
            .encode_float(&chunk, &mut opus_output)
            .expect("Opus encoding failed");

        let mut packet = Packet::default();
        packet.payload = Bytes::copy_from_slice(&opus_output[..opus_bytes]);
        packet.header.version = 2;
        packet.header.ssrc = ssrc;
        packet.header.sequence_number = seq_number;
        packet.header.timestamp = timestamp;
        packet.header.payload_type = payload_type;

        println!("Sending RTP packet {:?}", packet);

        match track_local_clone.write_rtp(&packet).await {
            Ok(u) => {
                println!("Sent RTP packet with {} bytes to ssrc {}", u, ssrc);
                seq_number = seq_number.wrapping_add(1);
                timestamp += 960;
            }
            Err(err) => {
                eprintln!("Error sending RTP packet: {:?}", err);
            }
        }
    } else {
        sample_chunks = resampled.chunks(samples_per_buffer);
    }
}

But every time this runs, I get u == 0 (no packets written) from the local track. Has anyone ever tried to use this as a client to a MediaSoup server? I'm trying to stream audio off a bunch of raspberry pi's in real time, back to a central server, where it can be processed and forwarded from there.

Thanks for the help!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant