rtci 0.4.1

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

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

/// RFC 7798 section 7.1: absent parameters take their defaults (`profile-space` 0,
/// `profile-id` 1, `tier-flag` 0, `interop-constraints` progressive / non-packed /
/// frame-only, the compatibility bit of `profile-id`, `tx-mode` SRST), and section 7.2.2:
/// every configuration parameter but `level-id` is symmetric.
#[test]
fn h265_formats_match_by_their_configuration_with_the_section_7_1_defaults() {
    let none = h265("");
    assert!(none.match_fmtp(&*h265(
        "profile-space=0;profile-id=1;tier-flag=0;tx-mode=SRST"
    )));
    assert!(none.match_fmtp(&*h265(
        "interop-constraints=B00000000000;profile-compatibility-indicator=40000000"
    )));
    // level-id is not part of the configuration.
    assert!(h265("level-id=93").match_fmtp(&*h265("level-id=180")));
    // The sprop parameters describe a stream, not the format.
    assert!(none.match_fmtp(&*h265("sprop-vps=QAEMAf//;sprop-max-don-diff=2")));

    assert!(
        !none.match_fmtp(&*h265("profile-id=2")),
        "Main 10 is another format"
    );
    assert!(!none.match_fmtp(&*h265("tier-flag=1")));
    assert!(!none.match_fmtp(&*h265("profile-space=1")));
    assert!(!none.match_fmtp(&*h265("interop-constraints=000000000000")));
    assert!(!none.match_fmtp(&*h265("profile-compatibility-indicator=60000000")));
    assert!(
        !none.match_fmtp(&*h265("tx-mode=MRST")),
        "only SRST by default"
    );
    assert!(h265("tx-mode=mrst").match_fmtp(&*h265("tx-mode=MRST")));
    assert!(
        !h265("tx-mode=XYZ").match_fmtp(&*h265("tx-mode=XYZ")),
        "not a mode"
    );
}

/// RFC 7798 section 7.1: `level-id` 93 (level 3.1) when absent.
#[test]
fn an_absent_h265_level_id_is_93() {
    let fmtp = h265("");
    let fmtp = fmtp.as_any().downcast_ref::<H265Fmtp>().expect("H.265");
    assert_eq!(Some(93), fmtp.level_id());
    assert_eq!(Some("SRST"), fmtp.tx_mode());
}

/// RFC 7798 section 7.2.2: "A receiver SHOULD understand all media type parameters". Every
/// parameter section 7.1 registers has its Table 1 row (`sprop-sei`, which Table 1 does not
/// list, as the parameter sets it travels with).
#[test]
fn every_rfc_7798_parameter_has_its_table_1_role() {
    let section_7_1 = [
        "profile-space",
        "tier-flag",
        "level-id",
        "profile-id",
        "interop-constraints",
        "profile-compatibility-indicator",
        "sprop-sub-layer-id",
        "recv-sub-layer-id",
        "max-recv-level-id",
        "tx-mode",
        "sprop-vps",
        "sprop-sps",
        "sprop-pps",
        "sprop-sei",
        "max-lsr",
        "max-lps",
        "max-cpb",
        "max-dpb",
        "max-br",
        "max-tr",
        "max-tc",
        "max-fps",
        "sprop-max-don-diff",
        "sprop-depack-buf-nalus",
        "sprop-depack-buf-bytes",
        "depack-buf-cap",
        "sprop-segmentation-id",
        "sprop-spatial-segmentation-idc",
        "dec-parallel-cap",
        "include-dph",
    ];
    assert_eq!(PARAMETERS.len(), section_7_1.len());
    for name in section_7_1 {
        assert!(
            PARAMETERS.iter().any(|r| r.name == name),
            "{name} has no Table 1 row"
        );
    }
    let role = |name: &str| PARAMETERS.iter().find(|r| r.name == name).unwrap();
    assert_eq!(role("level-id").role, ParameterRole::Configuration);
    assert_eq!(role("max-lsr").role, ParameterRole::ReceiverCapability);
    assert!(!role("max-lsr").sendonly);
    assert!(!role("sprop-vps").recvonly && role("sprop-vps").sendonly);
    assert!(role("sprop-segmentation-id").recvonly && role("sprop-segmentation-id").sendonly);
    assert_eq!(
        role("recv-sub-layer-id").role,
        ParameterRole::OperationPoint
    );
}

/// What a description of each direction keeps of an H.265 line, and `recv-sub-layer-id`
/// never in an offer nor in a sendonly answer.
#[test]
fn an_h265_line_keeps_what_the_direction_uses() {
    let line = "level-id=93;profile-id=1;max-fps=3000;sprop-vps=QAEMAf//;\
                sprop-segmentation-id=0;recv-sub-layer-id=1";
    let h265 =
        |sends, receives, offer| written_parameters("video/H265", line, sends, receives, offer);
    assert_eq!(h265(true, true, false), line);
    assert_eq!(
        h265(true, true, true),
        "level-id=93;profile-id=1;max-fps=3000;sprop-vps=QAEMAf//;sprop-segmentation-id=0"
    );
    assert_eq!(
        h265(true, false, false),
        "level-id=93;profile-id=1;sprop-vps=QAEMAf//;sprop-segmentation-id=0"
    );
    assert_eq!(
        h265(false, true, false),
        "level-id=93;profile-id=1;max-fps=3000;sprop-segmentation-id=0;recv-sub-layer-id=1"
    );
}