Skip to content

Commit

Permalink
added remb test
Browse files Browse the repository at this point in the history
  • Loading branch information
giangndm committed Nov 19, 2023
1 parent 85353b0 commit 30b7c75
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/bwe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{rtp_::Mid, Rtc};

pub use crate::rtp_::Bitrate;

#[derive(Debug)]
#[derive(Debug, PartialEq)]
/// Bandwidth estimation kind.
pub enum BweKind {
/// Transport wide congestion control.
Expand Down
10 changes: 9 additions & 1 deletion src/rtp/rtcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,15 @@ impl<'a> TryFrom<&'a [u8]> for Rtcp {
}
PayloadType::FullIntraRequest => Rtcp::Fir(buf.try_into()?),
PayloadType::ApplicationLayer => {
return Err("Ignore PayloadType: ApplicationLayer")
match header.rtcp_type() {

Check failure on line 440 in src/rtp/rtcp/mod.rs

View workflow job for this annotation

GitHub Actions / lint

you seem to be trying to use `match` for an equality check. Consider using `if`
RtcpType::PayloadSpecificFeedback => {
if let Ok(remb) = Remb::try_from(buf) {
return Ok(Rtcp::Remb(remb));
}
}
_ => {}
}
return Err("Ignore PayloadType: ApplicationLayer");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rtp/rtcp/rtcpfb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl RtcpFb {
RtcpFb::Pli(v) => *v,
RtcpFb::Fir(v) => v.ssrc,
RtcpFb::Twcc(v) => v.ssrc,
RtcpFb::Remb(v) => v.ssrc,
RtcpFb::Remb(v) => v.ssrcs.first().map(|ssrc| (*ssrc).into()).unwrap_or(v.ssrc),
}
}
}
76 changes: 76 additions & 0 deletions tests/remb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use std::net::Ipv4Addr;
use std::time::Duration;

use str0m::bwe::{Bitrate, BweKind};
use str0m::media::{Direction, MediaKind};
use str0m::{Candidate, Event, Rtc, RtcError};
use tracing::{info, info_span};

Check warning on line 7 in tests/remb.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

unused import: `info`

Check warning on line 7 in tests/remb.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest, stable)

unused import: `info`

Check warning on line 7 in tests/remb.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest, stable)

unused import: `info`

Check warning on line 7 in tests/remb.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest, 1.65.0)

unused import: `info`

Check warning on line 7 in tests/remb.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta)

unused import: `info`

Check warning on line 7 in tests/remb.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.65.0)

unused import: `info`

Check warning on line 7 in tests/remb.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest, beta)

unused import: `info`

Check warning on line 7 in tests/remb.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.65.0)

unused import: `info`

Check warning on line 7 in tests/remb.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest, beta)

unused import: `info`

mod common;
use common::{init_log, negotiate, progress, TestRtc};

#[test]
pub fn remb() -> Result<(), RtcError> {
init_log();
let l_rtc = Rtc::builder().build();
let r_rtc = Rtc::builder().build();

let mut l = TestRtc::new_with_rtc(info_span!("L"), l_rtc);
let mut r = TestRtc::new_with_rtc(info_span!("R"), r_rtc);

let host1 = Candidate::host((Ipv4Addr::new(1, 1, 1, 1), 1000).into(), "udp")?;
let host2 = Candidate::host((Ipv4Addr::new(2, 2, 2, 2), 2000).into(), "udp")?;
l.add_local_candidate(host1);
r.add_local_candidate(host2);

let mid = negotiate(&mut l, &mut r, |change| {
change.add_media(MediaKind::Video, Direction::SendOnly, None, None)
});

loop {
if l.is_connected() || r.is_connected() {
break;
}
progress(&mut l, &mut r)?;
}

//wait for srtp success
let settle_time = l.duration() + Duration::from_millis(20);
loop {
progress(&mut l, &mut r)?;

if l.duration() > settle_time {
break;
}
}

r.direct_api()
.stream_rx_by_mid(mid, None)
.expect("Should has rx")
.request_remb(Bitrate::bps(123456));

let settle_time = l.duration() + Duration::from_millis(20);
loop {
progress(&mut l, &mut r)?;

if l.duration() > settle_time {
break;
}
}

let l_remb: Vec<_> = l
.events
.iter()
.filter_map(|(_, e)| {
if let Event::EgressBitrateEstimate(event) = e {
Some(event)
} else {
None
}
})
.collect();

assert_eq!(l_remb, vec![&BweKind::Remb(mid, Bitrate::bps(123456))]);

Ok(())
}

0 comments on commit 30b7c75

Please sign in to comment.