Tune Muninn RUDP profile for recoverable LAN bursts
This commit is contained in:
parent
42328e3aeb
commit
7d348a1847
2 changed files with 110 additions and 72 deletions
|
|
@ -54,7 +54,7 @@ const MUNINN_COMMAND_RUDP_CONNECTION_ID: u32 = 0x6d75_0002;
|
|||
const MUNINN_MEDIA_RUDP_CONNECTION_ID: u32 = 0x6d75_0001;
|
||||
const MUNINN_OBS_CATALOG_RUDP_CONNECTION_ID: u32 = 0x6d75_0003;
|
||||
const MUNINN_RUDP_MEDIA_PROFILE_ID: &str = "muninn.rudp.low_latency_h264_lan.v1";
|
||||
const MUNINN_RUDP_MEDIA_VIDEO_BITRATE_KBPS: u32 = 16_000;
|
||||
const MUNINN_RUDP_MEDIA_VIDEO_BITRATE_KBPS: u32 = 12_000;
|
||||
const MUNINN_RUDP_MEDIA_VBV_FRAME_BUDGETS: u32 = 1;
|
||||
const MUNINN_RUDP_MEDIA_LOW_DELAY_KEY_FRAME_SCALE: u32 = 4;
|
||||
const MUNINN_RUDP_MEDIA_VIDEO_DPB_SIZE: u32 = 1;
|
||||
|
|
@ -65,7 +65,7 @@ const MUNINN_RUDP_MEDIA_MAX_FRAGMENT_BYTES: usize = MUNINN_RUDP_IPV4_UDP_PAYLOAD
|
|||
- MUNINN_RUDP_FIXED_HEADER_BYTES
|
||||
- crate::media_packetizer::MUNINN_MEDIA_RUDP_CHANNEL.len();
|
||||
const MUNINN_RUDP_MEDIA_RESEND_DELAY_MS: u64 = 5;
|
||||
const MUNINN_RUDP_MEDIA_RECEIVER_ASSEMBLY_DEADLINE_MS: u64 = 1_200;
|
||||
const MUNINN_RUDP_MEDIA_RECEIVER_ASSEMBLY_DEADLINE_MS: u64 = 2_000;
|
||||
const MUNINN_RUDP_MEDIA_RECEIVER_GAP_WAIT_MS: u64 = 16;
|
||||
const MUNINN_RUDP_MEDIA_REPAIR_CACHE_CHUNKS: usize = 16_384;
|
||||
const MUNINN_RUDP_MEDIA_REPAIR_BURST_CHUNKS: usize = 1_024;
|
||||
|
|
@ -6627,8 +6627,8 @@ mod tests {
|
|||
MUNINN_RUDP_MEDIA_RECEIVER_ASSEMBLY_DEADLINE_MS as u32
|
||||
);
|
||||
assert!(decoded.urls[0].contains("delivery=unreliable"));
|
||||
assert!(decoded.urls[0].contains("reliable_expire_after_ms=1200"));
|
||||
assert!(decoded.urls[0].contains("assembly_deadline_ms=1200"));
|
||||
assert!(decoded.urls[0].contains("reliable_expire_after_ms=2000"));
|
||||
assert!(decoded.urls[0].contains("assembly_deadline_ms=2000"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -6817,7 +6817,7 @@ mod tests {
|
|||
assert_eq!(
|
||||
plan.targets,
|
||||
vec![
|
||||
"rudp://10.77.0.2:5204/muninn.raven.av.rudp?channel=media&format=muninn-typed-media&connection=0x6d750001&profile=muninn.rudp.low_latency_h264_lan.v1&delivery=unreliable&sender_resend_delay_ms=5&reliable_expire_after_ms=1200&assembly_deadline_ms=1200&gap_wait_ms=16"
|
||||
"rudp://10.77.0.2:5204/muninn.raven.av.rudp?channel=media&format=muninn-typed-media&connection=0x6d750001&profile=muninn.rudp.low_latency_h264_lan.v1&delivery=unreliable&sender_resend_delay_ms=5&reliable_expire_after_ms=2000&assembly_deadline_ms=2000&gap_wait_ms=16"
|
||||
]
|
||||
);
|
||||
assert!(!plan.command_line.contains("tee"));
|
||||
|
|
@ -6894,15 +6894,15 @@ mod tests {
|
|||
);
|
||||
assert!(
|
||||
args.windows(2)
|
||||
.any(|pair| pair[0] == "-b:v" && pair[1] == "16000k")
|
||||
.any(|pair| pair[0] == "-b:v" && pair[1] == "12000k")
|
||||
);
|
||||
assert!(
|
||||
args.windows(2)
|
||||
.any(|pair| pair[0] == "-maxrate" && pair[1] == "16000k")
|
||||
.any(|pair| pair[0] == "-maxrate" && pair[1] == "12000k")
|
||||
);
|
||||
assert!(
|
||||
args.windows(2)
|
||||
.any(|pair| pair[0] == "-bufsize" && pair[1] == "267k")
|
||||
.any(|pair| pair[0] == "-bufsize" && pair[1] == "200k")
|
||||
);
|
||||
assert!(
|
||||
args.windows(2)
|
||||
|
|
@ -6988,11 +6988,11 @@ mod tests {
|
|||
|
||||
assert_eq!(
|
||||
muninn_rudp_video_vbv_buffer_arg(&thirty_fps, &profile),
|
||||
"534k"
|
||||
"400k"
|
||||
);
|
||||
assert_eq!(
|
||||
muninn_rudp_video_vbv_buffer_arg(&sixty_fps, &profile),
|
||||
"267k"
|
||||
"200k"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -7194,7 +7194,7 @@ mod tests {
|
|||
"--audio-sample-rate",
|
||||
"48000",
|
||||
"--rudp-latency-budget-ms",
|
||||
"1200",
|
||||
"2000",
|
||||
]
|
||||
.into_iter()
|
||||
.map(String::from),
|
||||
|
|
@ -7202,8 +7202,8 @@ mod tests {
|
|||
.unwrap();
|
||||
let profile = muninn_rudp_media_profile_for_options(&options);
|
||||
|
||||
assert_eq!(profile.sender_queue_deadline_ms, 1200);
|
||||
assert_eq!(profile.sender_reliable_expire_after_ms, 1200);
|
||||
assert_eq!(profile.sender_queue_deadline_ms, 2000);
|
||||
assert_eq!(profile.sender_reliable_expire_after_ms, 2000);
|
||||
assert_eq!(
|
||||
profile.sender_pace_every_payloads,
|
||||
MUNINN_RUDP_MEDIA_SEND_PACE_EVERY_PAYLOADS
|
||||
|
|
@ -7212,10 +7212,10 @@ mod tests {
|
|||
profile.sender_pace_sleep_us,
|
||||
MUNINN_RUDP_MEDIA_SEND_PACE_SLEEP_US
|
||||
);
|
||||
assert_eq!(profile.receiver_assembly_deadline_ms, 1200);
|
||||
assert_eq!(rudp_media_deadline_delay_ticks(&profile), 108_000);
|
||||
assert_eq!(rudp_audio_deadline_delay_ticks(&options, &profile), 57_600);
|
||||
assert!(rudp_endpoint_for_options(&options).contains("assembly_deadline_ms=1200"));
|
||||
assert_eq!(profile.receiver_assembly_deadline_ms, 2000);
|
||||
assert_eq!(rudp_media_deadline_delay_ticks(&profile), 180_000);
|
||||
assert_eq!(rudp_audio_deadline_delay_ticks(&options, &profile), 96_000);
|
||||
assert!(rudp_endpoint_for_options(&options).contains("assembly_deadline_ms=2000"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -8038,7 +8038,7 @@ Device 00:07:04:A8:00:D0 (public)
|
|||
media_profile
|
||||
.get("video_bitrate")
|
||||
.and_then(|value| value.as_str()),
|
||||
Some("16000k")
|
||||
Some("12000k")
|
||||
);
|
||||
assert_eq!(
|
||||
media_profile
|
||||
|
|
|
|||
|
|
@ -922,11 +922,13 @@ pub fn packetize_video_access_unit(
|
|||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn build_video_parity_shard(
|
||||
const MUNINN_VIDEO_PARITY_STRIPES: u16 = 16;
|
||||
|
||||
pub fn build_video_parity_shards(
|
||||
chunks: &[MuninnMediaVideoAccessUnitRecord],
|
||||
) -> Result<Option<MuninnMediaVideoParityShardRecord>> {
|
||||
) -> Result<Vec<MuninnMediaVideoParityShardRecord>> {
|
||||
if chunks.len() <= 1 {
|
||||
return Ok(None);
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let first = chunks
|
||||
.first()
|
||||
|
|
@ -966,48 +968,59 @@ pub fn build_video_parity_shard(
|
|||
}
|
||||
}
|
||||
|
||||
let mut payload_len = 0_usize;
|
||||
let mut chunk_payload_len = 0_usize;
|
||||
let mut last_chunk_payload_bytes = 0_u32;
|
||||
for index in 0..first.chunk_count {
|
||||
let chunk = by_index
|
||||
.get(&index)
|
||||
.ok_or_else(|| anyhow!("video parity missing chunk_index {index}"))?;
|
||||
payload_len = payload_len.max(chunk.payload.len());
|
||||
chunk_payload_len = chunk_payload_len.max(chunk.payload.len());
|
||||
if index == first.chunk_count - 1 {
|
||||
last_chunk_payload_bytes = u32::try_from(chunk.payload.len())
|
||||
.context("video parity last chunk payload length exceeds u32")?;
|
||||
}
|
||||
}
|
||||
let chunk_payload_bytes =
|
||||
u32::try_from(payload_len).context("video parity chunk payload length exceeds u32")?;
|
||||
|
||||
let mut parity = vec![0_u8; payload_len];
|
||||
for index in 0..first.chunk_count {
|
||||
let chunk = by_index.get(&index).expect("chunk index was checked above");
|
||||
for (offset, byte) in chunk.payload.iter().enumerate() {
|
||||
parity[offset] ^= *byte;
|
||||
let chunk_payload_bytes = u32::try_from(chunk_payload_len)
|
||||
.context("video parity chunk payload length exceeds u32")?;
|
||||
let parity_count = first.chunk_count.min(MUNINN_VIDEO_PARITY_STRIPES);
|
||||
let mut records = Vec::with_capacity(parity_count as usize);
|
||||
for parity_index in 0..parity_count {
|
||||
let mut parity_len = 0_usize;
|
||||
for index in (parity_index..first.chunk_count).step_by(parity_count as usize) {
|
||||
let chunk = by_index.get(&index).expect("chunk index was checked above");
|
||||
parity_len = parity_len.max(chunk.payload.len());
|
||||
}
|
||||
if parity_len == 0 {
|
||||
continue;
|
||||
}
|
||||
let mut parity = vec![0_u8; parity_len];
|
||||
for index in (parity_index..first.chunk_count).step_by(parity_count as usize) {
|
||||
let chunk = by_index.get(&index).expect("chunk index was checked above");
|
||||
for (offset, byte) in chunk.payload.iter().enumerate() {
|
||||
parity[offset] ^= *byte;
|
||||
}
|
||||
}
|
||||
records.push(MuninnMediaVideoParityShardRecord {
|
||||
stream_id: first.stream_id.clone(),
|
||||
session_id: first.session_id.clone(),
|
||||
frame_id: first.frame_id,
|
||||
codec: first.codec.clone(),
|
||||
pts_ticks: first.pts_ticks,
|
||||
duration_ticks: first.duration_ticks,
|
||||
timebase_num: first.timebase_num,
|
||||
timebase_den: first.timebase_den,
|
||||
keyframe: first.keyframe,
|
||||
dependency_frame_id: first.dependency_frame_id,
|
||||
deadline_ticks: first.deadline_ticks,
|
||||
chunk_count: first.chunk_count,
|
||||
parity_index,
|
||||
parity_count,
|
||||
chunk_payload_bytes,
|
||||
last_chunk_payload_bytes,
|
||||
payload: parity,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(Some(MuninnMediaVideoParityShardRecord {
|
||||
stream_id: first.stream_id.clone(),
|
||||
session_id: first.session_id.clone(),
|
||||
frame_id: first.frame_id,
|
||||
codec: first.codec.clone(),
|
||||
pts_ticks: first.pts_ticks,
|
||||
duration_ticks: first.duration_ticks,
|
||||
timebase_num: first.timebase_num,
|
||||
timebase_den: first.timebase_den,
|
||||
keyframe: first.keyframe,
|
||||
dependency_frame_id: first.dependency_frame_id,
|
||||
deadline_ticks: first.deadline_ticks,
|
||||
chunk_count: first.chunk_count,
|
||||
parity_index: 0,
|
||||
parity_count: 1,
|
||||
chunk_payload_bytes,
|
||||
last_chunk_payload_bytes,
|
||||
payload: parity,
|
||||
}))
|
||||
Ok(records)
|
||||
}
|
||||
|
||||
fn video_wire_records_with_parity(
|
||||
|
|
@ -1032,7 +1045,7 @@ fn video_wire_records_with_parity(
|
|||
.cloned()
|
||||
.map(MuninnMediaWireRecord::Video),
|
||||
);
|
||||
if let Some(parity) = build_video_parity_shard(frame_records)? {
|
||||
for parity in build_video_parity_shards(frame_records)? {
|
||||
wire_records.push(MuninnMediaWireRecord::VideoParity(parity));
|
||||
}
|
||||
offset = end;
|
||||
|
|
@ -1789,9 +1802,14 @@ fn validate_video_parity_record(record: &MuninnMediaVideoParityShardRecord) -> R
|
|||
"video parity media record chunk_count must be non-zero"
|
||||
));
|
||||
}
|
||||
if record.parity_count != 1 || record.parity_index != 0 {
|
||||
if record.parity_count == 0 || record.parity_index >= record.parity_count {
|
||||
return Err(anyhow!(
|
||||
"video parity media record currently supports exactly one XOR parity shard"
|
||||
"video parity media record has invalid parity stripe metadata"
|
||||
));
|
||||
}
|
||||
if record.parity_count > record.chunk_count {
|
||||
return Err(anyhow!(
|
||||
"video parity media record parity_count exceeds chunk_count"
|
||||
));
|
||||
}
|
||||
if record.chunk_payload_bytes == 0 || record.last_chunk_payload_bytes == 0 {
|
||||
|
|
@ -1809,9 +1827,9 @@ fn validate_video_parity_record(record: &MuninnMediaVideoParityShardRecord) -> R
|
|||
"video parity media record payload must be non-empty"
|
||||
));
|
||||
}
|
||||
if record.chunk_payload_bytes as usize != record.payload.len() {
|
||||
if record.payload.len() > record.chunk_payload_bytes as usize {
|
||||
return Err(anyhow!(
|
||||
"video parity media record payload length does not match declared chunk length"
|
||||
"video parity media record payload exceeds declared chunk length"
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -2341,9 +2359,9 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn builds_video_parity_shard_for_single_chunk_loss_recovery() -> Result<()> {
|
||||
fn builds_video_parity_shards_for_burst_loss_recovery() -> Result<()> {
|
||||
let access_unit = VideoAccessUnit {
|
||||
bytes: vec![1, 2, 3, 4, 5],
|
||||
bytes: (1_u8..=40).collect(),
|
||||
keyframe: false,
|
||||
};
|
||||
let records = packetize_video_access_unit(
|
||||
|
|
@ -2362,23 +2380,40 @@ mod tests {
|
|||
&access_unit,
|
||||
)?;
|
||||
|
||||
let parity = build_video_parity_shard(&records)?.expect("multi-chunk frame gets parity");
|
||||
let parity = build_video_parity_shards(&records)?;
|
||||
|
||||
assert_eq!(parity.chunk_count, 3);
|
||||
assert_eq!(parity.parity_index, 0);
|
||||
assert_eq!(parity.parity_count, 1);
|
||||
assert_eq!(parity.chunk_payload_bytes, 2);
|
||||
assert_eq!(parity.last_chunk_payload_bytes, 1);
|
||||
assert_eq!(parity.payload, vec![1 ^ 3 ^ 5, 2 ^ 4]);
|
||||
assert_eq!(records.len(), 20);
|
||||
assert_eq!(parity.len(), 16);
|
||||
assert!(
|
||||
parity.iter().enumerate().all(
|
||||
|(index, shard)| shard.parity_index == index as u16 && shard.parity_count == 16
|
||||
)
|
||||
);
|
||||
assert!(parity.iter().all(|shard| shard.chunk_payload_bytes == 2));
|
||||
|
||||
let mut recovered = parity.payload.clone();
|
||||
for chunk in [&records[0], &records[2]] {
|
||||
for (offset, byte) in chunk.payload.iter().enumerate() {
|
||||
recovered[offset] ^= *byte;
|
||||
let mut recovered_tail = Vec::new();
|
||||
for missing_index in 16_u16..20 {
|
||||
let shard = parity
|
||||
.iter()
|
||||
.find(|shard| shard.parity_index == missing_index % shard.parity_count)
|
||||
.expect("tail chunk stripe exists");
|
||||
let mut recovered = shard.payload.clone();
|
||||
for chunk in records.iter().filter(|chunk| {
|
||||
chunk.chunk_index != missing_index
|
||||
&& chunk.chunk_index % shard.parity_count == shard.parity_index
|
||||
}) {
|
||||
for (offset, byte) in chunk.payload.iter().enumerate() {
|
||||
recovered[offset] ^= *byte;
|
||||
}
|
||||
}
|
||||
recovered.truncate(records[missing_index as usize].payload.len());
|
||||
recovered_tail.extend(recovered);
|
||||
}
|
||||
recovered.truncate(parity.chunk_payload_bytes as usize);
|
||||
assert_eq!(recovered, records[1].payload);
|
||||
let expected_tail: Vec<u8> = records[16..20]
|
||||
.iter()
|
||||
.flat_map(|record| record.payload.iter().copied())
|
||||
.collect();
|
||||
assert_eq!(recovered_tail, expected_tail);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -3252,7 +3287,10 @@ mod tests {
|
|||
},
|
||||
&access_unit,
|
||||
)?;
|
||||
let parity = build_video_parity_shard(&records)?.expect("multi-chunk frame gets parity");
|
||||
let parity = build_video_parity_shards(&records)?
|
||||
.into_iter()
|
||||
.next()
|
||||
.expect("multi-chunk frame gets parity");
|
||||
|
||||
let wire = encode_media_wire_record(
|
||||
&MuninnMediaWireRecord::VideoParity(parity.clone()),
|
||||
|
|
|
|||
Loading…
Reference in a new issue