rtci 0.5.0

A sans-I/O WebRTC implementation: peer connections with ICE, DTLS-SRTP, SCTP data channels, RTP/RTCP and JSEP negotiation
Documentation
use super::*;

fn av1(line: &str) -> Box<dyn Fmtp> {
    parse("video/AV1", line)
}

/// AV1 RTP section 7.2: absent parameters are inferred (`profile` 0, `level-idx` 5, `tier`
/// 0), and only the profile makes two formats different (section 7.2.3).
#[test]
fn an_av1_format_is_its_profile_with_the_absent_parameters_inferred() {
    let none = av1("");
    let fmtp = none
        .as_any()
        .downcast_ref::<Av1Fmtp>()
        .expect("an AV1 fmtp");
    assert_eq!(
        (Some(0), Some(5), Some(0)),
        (fmtp.profile(), fmtp.level_idx(), fmtp.tier())
    );

    assert!(none.match_fmtp(&*av1("profile=0")));
    assert!(!none.match_fmtp(&*av1("profile=1")));
    assert!(av1("profile=1;level-idx=8;tier=1").match_fmtp(&*av1("profile=1;level-idx=5")));
    assert!(!av1("profile=2").match_fmtp(&*av1("profile=1")));
    assert!(!av1("profile=x").match_fmtp(&*av1("profile=x")));
}

// vector-set av1-rtp-7.3: 6 cases
/// The examples of AV1 RTP section 7.3: the `a=fmtp` line of each (7.3 and 7.3.2 to 7.3.4
/// share `profile=2; level-idx=8; tier=1;`, 7.3.1 is an offer and an answer) read as printed,
/// with a space after each `;` and a trailing `;`, and give the example's profile, level and
/// tier; the level-upgrading offer and answer of 7.3.1 (levels 2.0 and 3.0 / tier 1) are the
/// same format, as the section accepts them.
#[test]
fn the_fmtp_lines_of_the_av1_section_7_3_examples_read_as_printed() {
    let read = |line: &str| {
        let fmtp = av1(line);
        let av1 = fmtp
            .as_any()
            .downcast_ref::<Av1Fmtp>()
            .expect("an AV1 fmtp");
        (av1.profile(), av1.level_idx(), av1.tier())
    };
    let examples = [
        ("7.3", "profile=2; level-idx=8; tier=1;", (2, 8, 1)),
        ("7.3.1 offer", "profile=0; level-idx=0;", (0, 0, 0)),
        ("7.3.1 answer", "profile=0; level-idx=4; tier=1;", (0, 4, 1)),
        ("7.3.2", "profile=2; level-idx=8; tier=1;", (2, 8, 1)),
        ("7.3.3", "profile=2; level-idx=8; tier=1;", (2, 8, 1)),
        ("7.3.4", "profile=2; level-idx=8; tier=1;", (2, 8, 1)),
    ];
    assert_eq!(examples.len(), 6);
    for (section, line, (profile, level, tier)) in examples {
        assert_eq!(
            read(line),
            (Some(profile), Some(level), Some(tier)),
            "{section}: {line}"
        );
    }
    assert!(av1("profile=0; level-idx=0;").match_fmtp(&*av1("profile=0; level-idx=4; tier=1;")));
    assert!(!av1("profile=0; level-idx=0;").match_fmtp(&*av1("profile=2; level-idx=8; tier=1;")));
}