Cut the receiver half of the packetizer; it lives in Ratatoskr now
Frame assembly, the assembly set, reassembly, expired-frame feedback and their tests were kept here after the September dead-code cut as the seed for Ratatoskr's reassembly. That seed has been planted (Ratatoskr 2618184, crates/ratatoskr-core/src/video.rs), so the producer stops carrying code only a consumer runs. 705 lines. What stays is the producer half: packetize, XOR stripe parity, and build_receiver_feedback, which the sender's repair-cache tests use to construct what a receiver would say. Also removes adts_frame, a test helper orphaned by the AAC cut. cargo test -p muninn-daemon -> 151 passed, no warnings Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
a619bd5be9
commit
34776ea27a
2 changed files with 11 additions and 728 deletions
|
|
@ -245,12 +245,6 @@ pub struct ReceiverFeedbackOptions<'a> {
|
|||
pub observed_at: &'a str,
|
||||
}
|
||||
|
||||
pub struct ExpiredVideoFrameFeedbackOptions<'a> {
|
||||
pub receiver_id: &'a str,
|
||||
pub jitter_us: i64,
|
||||
pub decode_queue_us: i64,
|
||||
pub observed_at: &'a str,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -573,214 +567,6 @@ impl AudioPcmStreamSendState {
|
|||
|
||||
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct ExpiredVideoFrame {
|
||||
pub key: VideoFrameKey,
|
||||
pub deadline_ticks: i64,
|
||||
pub missing_video_chunk_keys: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct VideoFrameAssembly {
|
||||
stream_id: String,
|
||||
session_id: String,
|
||||
frame_id: u64,
|
||||
chunk_count: u16,
|
||||
chunks: BTreeMap<u16, GameCultMediaVideoAccessUnitRecord>,
|
||||
}
|
||||
|
||||
impl VideoFrameAssembly {
|
||||
pub fn new(first_chunk: GameCultMediaVideoAccessUnitRecord) -> Result<Self> {
|
||||
if first_chunk.chunk_count == 0 {
|
||||
return Err(anyhow!("video frame assembly chunk_count must be non-zero"));
|
||||
}
|
||||
if first_chunk.chunk_index >= first_chunk.chunk_count {
|
||||
return Err(anyhow!(
|
||||
"video frame assembly chunk_index {} is outside chunk_count {}",
|
||||
first_chunk.chunk_index,
|
||||
first_chunk.chunk_count
|
||||
));
|
||||
}
|
||||
if first_chunk.payload.is_empty() {
|
||||
return Err(anyhow!(
|
||||
"video frame assembly chunk payload must be non-empty"
|
||||
));
|
||||
}
|
||||
|
||||
let mut chunks = BTreeMap::new();
|
||||
chunks.insert(first_chunk.chunk_index, first_chunk.clone());
|
||||
Ok(Self {
|
||||
stream_id: first_chunk.stream_id,
|
||||
session_id: first_chunk.session_id,
|
||||
frame_id: first_chunk.frame_id,
|
||||
chunk_count: first_chunk.chunk_count,
|
||||
chunks,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, chunk: GameCultMediaVideoAccessUnitRecord) -> Result<()> {
|
||||
self.require_matching_frame(&chunk)?;
|
||||
if self.chunks.contains_key(&chunk.chunk_index) {
|
||||
return Err(anyhow!(
|
||||
"video frame assembly has duplicate chunk_index {}",
|
||||
chunk.chunk_index
|
||||
));
|
||||
}
|
||||
self.chunks.insert(chunk.chunk_index, chunk);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn is_complete(&self) -> bool {
|
||||
self.chunks.len() == self.chunk_count as usize
|
||||
}
|
||||
|
||||
pub fn missing_video_chunk_keys(&self) -> Vec<String> {
|
||||
(0..self.chunk_count)
|
||||
.filter(|chunk_index| !self.chunks.contains_key(chunk_index))
|
||||
.map(|chunk_index| video_chunk_feedback_key(self.frame_id, chunk_index))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn deadline_ticks(&self) -> i64 {
|
||||
self.chunks
|
||||
.values()
|
||||
.next()
|
||||
.map(|chunk| chunk.deadline_ticks)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn reassemble(&self) -> Result<VideoAccessUnit> {
|
||||
let chunks = self.chunks.values().cloned().collect::<Vec<_>>();
|
||||
reassemble_video_access_unit(&chunks)
|
||||
}
|
||||
|
||||
fn require_matching_frame(&self, chunk: &GameCultMediaVideoAccessUnitRecord) -> Result<()> {
|
||||
if chunk.stream_id != self.stream_id {
|
||||
return Err(anyhow!("video frame assembly received mixed stream_id"));
|
||||
}
|
||||
if chunk.session_id != self.session_id {
|
||||
return Err(anyhow!("video frame assembly received mixed session_id"));
|
||||
}
|
||||
if chunk.frame_id != self.frame_id {
|
||||
return Err(anyhow!("video frame assembly received mixed frame_id"));
|
||||
}
|
||||
if chunk.chunk_count != self.chunk_count {
|
||||
return Err(anyhow!("video frame assembly received mixed chunk_count"));
|
||||
}
|
||||
if chunk.chunk_index >= self.chunk_count {
|
||||
return Err(anyhow!(
|
||||
"video frame assembly chunk_index {} is outside chunk_count {}",
|
||||
chunk.chunk_index,
|
||||
self.chunk_count
|
||||
));
|
||||
}
|
||||
if chunk.payload.is_empty() {
|
||||
return Err(anyhow!(
|
||||
"video frame assembly chunk payload must be non-empty"
|
||||
));
|
||||
}
|
||||
if let Some(first) = self.chunks.values().next() {
|
||||
if chunk.codec != first.codec
|
||||
|| chunk.pts_ticks != first.pts_ticks
|
||||
|| chunk.duration_ticks != first.duration_ticks
|
||||
|| chunk.timebase_num != first.timebase_num
|
||||
|| chunk.timebase_den != first.timebase_den
|
||||
|| chunk.deadline_ticks != first.deadline_ticks
|
||||
|| chunk.keyframe != first.keyframe
|
||||
|| chunk.dependency_frame_id != first.dependency_frame_id
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"video frame assembly received mixed media metadata"
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct VideoFrameKey {
|
||||
pub stream_id: String,
|
||||
pub session_id: String,
|
||||
pub frame_id: u64,
|
||||
}
|
||||
|
||||
impl VideoFrameKey {
|
||||
pub fn from_chunk(chunk: &GameCultMediaVideoAccessUnitRecord) -> Self {
|
||||
Self {
|
||||
stream_id: chunk.stream_id.clone(),
|
||||
session_id: chunk.session_id.clone(),
|
||||
frame_id: chunk.frame_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct VideoFrameAssemblySet {
|
||||
frames: BTreeMap<VideoFrameKey, VideoFrameAssembly>,
|
||||
}
|
||||
|
||||
impl VideoFrameAssemblySet {
|
||||
pub fn insert_chunk(
|
||||
&mut self,
|
||||
chunk: GameCultMediaVideoAccessUnitRecord,
|
||||
) -> Result<Option<VideoAccessUnit>> {
|
||||
let key = VideoFrameKey::from_chunk(&chunk);
|
||||
if let Some(assembly) = self.frames.get_mut(&key) {
|
||||
assembly.insert(chunk)?;
|
||||
if assembly.is_complete() {
|
||||
let access_unit = assembly.reassemble()?;
|
||||
self.frames.remove(&key);
|
||||
return Ok(Some(access_unit));
|
||||
}
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let assembly = VideoFrameAssembly::new(chunk)?;
|
||||
if assembly.is_complete() {
|
||||
return Ok(Some(assembly.reassemble()?));
|
||||
}
|
||||
self.frames.insert(key, assembly);
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub fn missing_video_chunk_keys(&self, key: &VideoFrameKey) -> Vec<String> {
|
||||
self.frames
|
||||
.get(key)
|
||||
.map(VideoFrameAssembly::missing_video_chunk_keys)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn pending_frame_count(&self) -> usize {
|
||||
self.frames.len()
|
||||
}
|
||||
|
||||
pub fn expire_late_frames(&mut self, now_ticks: i64) -> Vec<ExpiredVideoFrame> {
|
||||
let expired_keys = self
|
||||
.frames
|
||||
.iter()
|
||||
.filter_map(|(key, assembly)| {
|
||||
if assembly.deadline_ticks() <= now_ticks {
|
||||
Some(key.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
expired_keys
|
||||
.into_iter()
|
||||
.filter_map(|key| {
|
||||
self.frames.remove(&key).map(|assembly| ExpiredVideoFrame {
|
||||
key,
|
||||
deadline_ticks: assembly.deadline_ticks(),
|
||||
missing_video_chunk_keys: assembly.missing_video_chunk_keys(),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn packetize_video_access_unit(
|
||||
options: VideoFramePacketizeOptions<'_>,
|
||||
access_unit: &VideoAccessUnit,
|
||||
|
|
@ -1208,99 +994,6 @@ impl AudioPacketBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn reassemble_video_access_unit(
|
||||
chunks: &[GameCultMediaVideoAccessUnitRecord],
|
||||
) -> Result<VideoAccessUnit> {
|
||||
let first = chunks
|
||||
.first()
|
||||
.ok_or_else(|| anyhow!("video access unit requires at least one chunk"))?;
|
||||
if first.chunk_count == 0 {
|
||||
return Err(anyhow!("video access unit chunk_count must be non-zero"));
|
||||
}
|
||||
|
||||
let mut by_index = BTreeMap::new();
|
||||
for chunk in chunks {
|
||||
if chunk.stream_id != first.stream_id {
|
||||
return Err(anyhow!(
|
||||
"video access unit chunks have mixed stream_id values"
|
||||
));
|
||||
}
|
||||
if chunk.session_id != first.session_id {
|
||||
return Err(anyhow!(
|
||||
"video access unit chunks have mixed session_id values"
|
||||
));
|
||||
}
|
||||
if chunk.frame_id != first.frame_id {
|
||||
return Err(anyhow!(
|
||||
"video access unit chunks have mixed frame_id values"
|
||||
));
|
||||
}
|
||||
if chunk.codec != first.codec {
|
||||
return Err(anyhow!("video access unit chunks have mixed codec values"));
|
||||
}
|
||||
if chunk.pts_ticks != first.pts_ticks
|
||||
|| chunk.duration_ticks != first.duration_ticks
|
||||
|| chunk.timebase_num != first.timebase_num
|
||||
|| chunk.timebase_den != first.timebase_den
|
||||
|| chunk.deadline_ticks != first.deadline_ticks
|
||||
{
|
||||
return Err(anyhow!("video access unit chunks have mixed timing values"));
|
||||
}
|
||||
if chunk.keyframe != first.keyframe
|
||||
|| chunk.dependency_frame_id != first.dependency_frame_id
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"video access unit chunks have mixed dependency values"
|
||||
));
|
||||
}
|
||||
if chunk.chunk_count != first.chunk_count {
|
||||
return Err(anyhow!(
|
||||
"video access unit chunks have mixed chunk_count values"
|
||||
));
|
||||
}
|
||||
if chunk.chunk_index >= first.chunk_count {
|
||||
return Err(anyhow!(
|
||||
"video access unit chunk_index {} is outside chunk_count {}",
|
||||
chunk.chunk_index,
|
||||
first.chunk_count
|
||||
));
|
||||
}
|
||||
if chunk.payload.is_empty() {
|
||||
return Err(anyhow!("video access unit chunk payload must be non-empty"));
|
||||
}
|
||||
if by_index
|
||||
.insert(chunk.chunk_index, chunk.payload.as_slice())
|
||||
.is_some()
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"video access unit has duplicate chunk_index {}",
|
||||
chunk.chunk_index
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if by_index.len() != first.chunk_count as usize {
|
||||
return Err(anyhow!(
|
||||
"video access unit is missing chunks: expected {}, received {}",
|
||||
first.chunk_count,
|
||||
by_index.len()
|
||||
));
|
||||
}
|
||||
|
||||
let mut bytes = Vec::new();
|
||||
for index in 0..first.chunk_count {
|
||||
let payload = by_index
|
||||
.get(&index)
|
||||
.ok_or_else(|| anyhow!("video access unit is missing chunk_index {index}"))?;
|
||||
bytes.extend_from_slice(payload);
|
||||
}
|
||||
|
||||
Ok(VideoAccessUnit {
|
||||
bytes,
|
||||
keyframe: first.keyframe,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn build_receiver_feedback(
|
||||
options: ReceiverFeedbackOptions<'_>,
|
||||
) -> Result<GameCultMediaReceiverFeedbackRecord> {
|
||||
|
|
@ -1353,45 +1046,6 @@ pub fn build_receiver_feedback(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn build_feedback_for_expired_video_frames(
|
||||
expired: &[ExpiredVideoFrame],
|
||||
options: ExpiredVideoFrameFeedbackOptions<'_>,
|
||||
) -> Result<Option<GameCultMediaReceiverFeedbackRecord>> {
|
||||
let Some(first) = expired.first() else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let mut late_frame_ids = Vec::with_capacity(expired.len());
|
||||
let mut missing_video_chunk_keys = Vec::new();
|
||||
for frame in expired {
|
||||
if frame.key.stream_id != first.key.stream_id
|
||||
|| frame.key.session_id != first.key.session_id
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"expired video frame feedback requires one stream_id/session_id"
|
||||
));
|
||||
}
|
||||
late_frame_ids.push(frame.key.frame_id);
|
||||
missing_video_chunk_keys.extend(frame.missing_video_chunk_keys.iter().cloned());
|
||||
}
|
||||
|
||||
build_receiver_feedback(ReceiverFeedbackOptions {
|
||||
stream_id: &first.key.stream_id,
|
||||
session_id: &first.key.session_id,
|
||||
receiver_id: options.receiver_id,
|
||||
highest_decodable_frame_id: first.key.frame_id.checked_sub(1),
|
||||
missing_frame_ids: Vec::new(),
|
||||
missing_video_chunk_keys,
|
||||
late_frame_ids,
|
||||
requested_keyframe: true,
|
||||
jitter_us: options.jitter_us,
|
||||
decode_queue_us: options.decode_queue_us,
|
||||
observed_at: options.observed_at,
|
||||
})
|
||||
.map(Some)
|
||||
}
|
||||
|
||||
|
||||
/// Muninn's producer name on the wire. The envelope in CultLib takes this as a
|
||||
/// parameter so it never has to know any producer; this is where Muninn says
|
||||
/// who it is, once.
|
||||
|
|
@ -2319,93 +1973,6 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reassembles_video_chunks_in_chunk_index_order() -> Result<()> {
|
||||
let access_unit = VideoAccessUnit {
|
||||
bytes: vec![1, 2, 3, 4, 5],
|
||||
keyframe: true,
|
||||
};
|
||||
let records = packetize_video_access_unit(
|
||||
VideoFramePacketizeOptions {
|
||||
stream_id: "muninn.raven.av.rudp",
|
||||
session_id: "session-1",
|
||||
codec: "h264",
|
||||
frame_id: 9,
|
||||
pts_ticks: 27_000,
|
||||
duration_ticks: 3_000,
|
||||
timebase_num: 1,
|
||||
timebase_den: 90_000,
|
||||
deadline_ticks: 28_800,
|
||||
max_payload_bytes: 2,
|
||||
},
|
||||
&access_unit,
|
||||
)?;
|
||||
let shuffled = vec![records[2].clone(), records[0].clone(), records[1].clone()];
|
||||
|
||||
let reassembled = reassemble_video_access_unit(&shuffled)?;
|
||||
|
||||
assert_eq!(reassembled, access_unit);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_video_chunks_from_mixed_frames() -> Result<()> {
|
||||
let access_unit = VideoAccessUnit {
|
||||
bytes: vec![1, 2, 3, 4],
|
||||
keyframe: false,
|
||||
};
|
||||
let mut records = packetize_video_access_unit(
|
||||
VideoFramePacketizeOptions {
|
||||
stream_id: "muninn.raven.av.rudp",
|
||||
session_id: "session-1",
|
||||
codec: "h264",
|
||||
frame_id: 9,
|
||||
pts_ticks: 27_000,
|
||||
duration_ticks: 3_000,
|
||||
timebase_num: 1,
|
||||
timebase_den: 90_000,
|
||||
deadline_ticks: 28_800,
|
||||
max_payload_bytes: 2,
|
||||
},
|
||||
&access_unit,
|
||||
)?;
|
||||
records[1].frame_id = 10;
|
||||
|
||||
let error = reassemble_video_access_unit(&records).unwrap_err();
|
||||
|
||||
assert!(error.to_string().contains("mixed frame_id"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_incomplete_video_chunk_sets() -> Result<()> {
|
||||
let access_unit = VideoAccessUnit {
|
||||
bytes: vec![1, 2, 3, 4, 5],
|
||||
keyframe: false,
|
||||
};
|
||||
let mut records = packetize_video_access_unit(
|
||||
VideoFramePacketizeOptions {
|
||||
stream_id: "muninn.raven.av.rudp",
|
||||
session_id: "session-1",
|
||||
codec: "h264",
|
||||
frame_id: 9,
|
||||
pts_ticks: 27_000,
|
||||
duration_ticks: 3_000,
|
||||
timebase_num: 1,
|
||||
timebase_den: 90_000,
|
||||
deadline_ticks: 28_800,
|
||||
max_payload_bytes: 2,
|
||||
},
|
||||
&access_unit,
|
||||
)?;
|
||||
records.pop();
|
||||
|
||||
let error = reassemble_video_access_unit(&records).unwrap_err();
|
||||
|
||||
assert!(error.to_string().contains("missing chunks"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_receiver_feedback_with_sorted_unique_damage_lists() -> Result<()> {
|
||||
let feedback = build_receiver_feedback(ReceiverFeedbackOptions {
|
||||
|
|
@ -2473,278 +2040,6 @@ mod tests {
|
|||
assert!(error.to_string().contains("frame_id"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn video_frame_assembly_reports_missing_chunks_and_reassembles() -> Result<()> {
|
||||
let access_unit = VideoAccessUnit {
|
||||
bytes: vec![1, 2, 3, 4, 5],
|
||||
keyframe: true,
|
||||
};
|
||||
let records = packetize_video_access_unit(
|
||||
VideoFramePacketizeOptions {
|
||||
stream_id: "muninn.raven.av.rudp",
|
||||
session_id: "session-1",
|
||||
codec: "h264",
|
||||
frame_id: 9,
|
||||
pts_ticks: 27_000,
|
||||
duration_ticks: 3_000,
|
||||
timebase_num: 1,
|
||||
timebase_den: 90_000,
|
||||
deadline_ticks: 28_800,
|
||||
max_payload_bytes: 2,
|
||||
},
|
||||
&access_unit,
|
||||
)?;
|
||||
let mut assembly = VideoFrameAssembly::new(records[0].clone())?;
|
||||
|
||||
assert!(!assembly.is_complete());
|
||||
assert_eq!(
|
||||
assembly.missing_video_chunk_keys(),
|
||||
vec![
|
||||
video_chunk_feedback_key(9, 1),
|
||||
video_chunk_feedback_key(9, 2)
|
||||
]
|
||||
);
|
||||
|
||||
assembly.insert(records[2].clone())?;
|
||||
assert_eq!(
|
||||
assembly.missing_video_chunk_keys(),
|
||||
vec![video_chunk_feedback_key(9, 1)]
|
||||
);
|
||||
|
||||
assembly.insert(records[1].clone())?;
|
||||
assert!(assembly.is_complete());
|
||||
assert_eq!(assembly.reassemble()?, access_unit);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn video_frame_assembly_rejects_mixed_metadata() -> Result<()> {
|
||||
let access_unit = VideoAccessUnit {
|
||||
bytes: vec![1, 2, 3, 4],
|
||||
keyframe: false,
|
||||
};
|
||||
let mut records = packetize_video_access_unit(
|
||||
VideoFramePacketizeOptions {
|
||||
stream_id: "muninn.raven.av.rudp",
|
||||
session_id: "session-1",
|
||||
codec: "h264",
|
||||
frame_id: 9,
|
||||
pts_ticks: 27_000,
|
||||
duration_ticks: 3_000,
|
||||
timebase_num: 1,
|
||||
timebase_den: 90_000,
|
||||
deadline_ticks: 28_800,
|
||||
max_payload_bytes: 2,
|
||||
},
|
||||
&access_unit,
|
||||
)?;
|
||||
let mut assembly = VideoFrameAssembly::new(records[0].clone())?;
|
||||
records[1].pts_ticks += 1;
|
||||
|
||||
let error = assembly.insert(records[1].clone()).unwrap_err();
|
||||
|
||||
assert!(error.to_string().contains("metadata"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn video_frame_assembly_set_handles_interleaved_frames() -> Result<()> {
|
||||
let frame_one = VideoAccessUnit {
|
||||
bytes: vec![1, 2, 3, 4, 5],
|
||||
keyframe: true,
|
||||
};
|
||||
let frame_two = VideoAccessUnit {
|
||||
bytes: vec![6, 7, 8, 9],
|
||||
keyframe: false,
|
||||
};
|
||||
let frame_one_chunks = packetize_video_access_unit(
|
||||
VideoFramePacketizeOptions {
|
||||
stream_id: "muninn.raven.av.rudp",
|
||||
session_id: "session-1",
|
||||
codec: "h264",
|
||||
frame_id: 9,
|
||||
pts_ticks: 27_000,
|
||||
duration_ticks: 3_000,
|
||||
timebase_num: 1,
|
||||
timebase_den: 90_000,
|
||||
deadline_ticks: 28_800,
|
||||
max_payload_bytes: 2,
|
||||
},
|
||||
&frame_one,
|
||||
)?;
|
||||
let frame_two_chunks = packetize_video_access_unit(
|
||||
VideoFramePacketizeOptions {
|
||||
stream_id: "muninn.raven.av.rudp",
|
||||
session_id: "session-1",
|
||||
codec: "h264",
|
||||
frame_id: 10,
|
||||
pts_ticks: 30_000,
|
||||
duration_ticks: 3_000,
|
||||
timebase_num: 1,
|
||||
timebase_den: 90_000,
|
||||
deadline_ticks: 31_800,
|
||||
max_payload_bytes: 2,
|
||||
},
|
||||
&frame_two,
|
||||
)?;
|
||||
let key_one = VideoFrameKey::from_chunk(&frame_one_chunks[0]);
|
||||
let mut assemblies = VideoFrameAssemblySet::default();
|
||||
|
||||
assert!(
|
||||
assemblies
|
||||
.insert_chunk(frame_one_chunks[0].clone())?
|
||||
.is_none()
|
||||
);
|
||||
assert!(
|
||||
assemblies
|
||||
.insert_chunk(frame_two_chunks[1].clone())?
|
||||
.is_none()
|
||||
);
|
||||
assert_eq!(assemblies.pending_frame_count(), 2);
|
||||
assert_eq!(
|
||||
assemblies.missing_video_chunk_keys(&key_one),
|
||||
vec![
|
||||
video_chunk_feedback_key(9, 1),
|
||||
video_chunk_feedback_key(9, 2)
|
||||
]
|
||||
);
|
||||
|
||||
assert!(
|
||||
assemblies
|
||||
.insert_chunk(frame_one_chunks[2].clone())?
|
||||
.is_none()
|
||||
);
|
||||
let completed = assemblies
|
||||
.insert_chunk(frame_one_chunks[1].clone())?
|
||||
.expect("frame one should complete");
|
||||
|
||||
assert_eq!(completed, frame_one);
|
||||
assert_eq!(assemblies.pending_frame_count(), 1);
|
||||
assert!(assemblies.missing_video_chunk_keys(&key_one).is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn video_frame_assembly_set_expires_late_incomplete_frames() -> Result<()> {
|
||||
let frame_one = VideoAccessUnit {
|
||||
bytes: vec![1, 2, 3, 4, 5],
|
||||
keyframe: true,
|
||||
};
|
||||
let frame_two = VideoAccessUnit {
|
||||
bytes: vec![6, 7, 8, 9],
|
||||
keyframe: false,
|
||||
};
|
||||
let frame_one_chunks = packetize_video_access_unit(
|
||||
VideoFramePacketizeOptions {
|
||||
stream_id: "muninn.raven.av.rudp",
|
||||
session_id: "session-1",
|
||||
codec: "h264",
|
||||
frame_id: 9,
|
||||
pts_ticks: 27_000,
|
||||
duration_ticks: 3_000,
|
||||
timebase_num: 1,
|
||||
timebase_den: 90_000,
|
||||
deadline_ticks: 28_800,
|
||||
max_payload_bytes: 2,
|
||||
},
|
||||
&frame_one,
|
||||
)?;
|
||||
let frame_two_chunks = packetize_video_access_unit(
|
||||
VideoFramePacketizeOptions {
|
||||
stream_id: "muninn.raven.av.rudp",
|
||||
session_id: "session-1",
|
||||
codec: "h264",
|
||||
frame_id: 10,
|
||||
pts_ticks: 30_000,
|
||||
duration_ticks: 3_000,
|
||||
timebase_num: 1,
|
||||
timebase_den: 90_000,
|
||||
deadline_ticks: 31_800,
|
||||
max_payload_bytes: 2,
|
||||
},
|
||||
&frame_two,
|
||||
)?;
|
||||
let key_one = VideoFrameKey::from_chunk(&frame_one_chunks[0]);
|
||||
let key_two = VideoFrameKey::from_chunk(&frame_two_chunks[0]);
|
||||
let mut assemblies = VideoFrameAssemblySet::default();
|
||||
|
||||
assemblies.insert_chunk(frame_one_chunks[0].clone())?;
|
||||
assemblies.insert_chunk(frame_two_chunks[0].clone())?;
|
||||
|
||||
let expired = assemblies.expire_late_frames(30_000);
|
||||
|
||||
assert_eq!(expired.len(), 1);
|
||||
assert_eq!(expired[0].key, key_one);
|
||||
assert_eq!(
|
||||
expired[0].missing_video_chunk_keys,
|
||||
vec![
|
||||
video_chunk_feedback_key(9, 1),
|
||||
video_chunk_feedback_key(9, 2)
|
||||
]
|
||||
);
|
||||
assert_eq!(assemblies.pending_frame_count(), 1);
|
||||
assert!(!assemblies.missing_video_chunk_keys(&key_two).is_empty());
|
||||
|
||||
let feedback = build_feedback_for_expired_video_frames(
|
||||
&expired,
|
||||
ExpiredVideoFrameFeedbackOptions {
|
||||
receiver_id: "starfire.obs",
|
||||
jitter_us: 700,
|
||||
decode_queue_us: 2_000,
|
||||
observed_at: "2026-06-18T00:00:00Z",
|
||||
},
|
||||
)?
|
||||
.expect("expired frames should produce feedback");
|
||||
|
||||
assert_eq!(feedback.late_frame_ids, vec![9]);
|
||||
assert_eq!(
|
||||
feedback.missing_video_chunk_keys,
|
||||
vec![
|
||||
video_chunk_feedback_key(9, 1),
|
||||
video_chunk_feedback_key(9, 2)
|
||||
]
|
||||
);
|
||||
assert!(feedback.requested_keyframe);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expired_video_feedback_rejects_mixed_streams() {
|
||||
let expired = vec![
|
||||
ExpiredVideoFrame {
|
||||
key: VideoFrameKey {
|
||||
stream_id: "muninn.raven.av.rudp".to_string(),
|
||||
session_id: "session-1".to_string(),
|
||||
frame_id: 9,
|
||||
},
|
||||
deadline_ticks: 28_800,
|
||||
missing_video_chunk_keys: vec![video_chunk_feedback_key(9, 1)],
|
||||
},
|
||||
ExpiredVideoFrame {
|
||||
key: VideoFrameKey {
|
||||
stream_id: "muninn.nightwing.av.rudp".to_string(),
|
||||
session_id: "session-1".to_string(),
|
||||
frame_id: 10,
|
||||
},
|
||||
deadline_ticks: 31_800,
|
||||
missing_video_chunk_keys: vec![video_chunk_feedback_key(10, 1)],
|
||||
},
|
||||
];
|
||||
|
||||
let error = build_feedback_for_expired_video_frames(
|
||||
&expired,
|
||||
ExpiredVideoFrameFeedbackOptions {
|
||||
receiver_id: "starfire.obs",
|
||||
jitter_us: 700,
|
||||
decode_queue_us: 2_000,
|
||||
observed_at: "2026-06-18T00:00:00Z",
|
||||
},
|
||||
)
|
||||
.unwrap_err();
|
||||
|
||||
assert!(error.to_string().contains("one stream_id/session_id"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn media_wire_round_trips_video_document() -> Result<()> {
|
||||
let access_unit = VideoAccessUnit {
|
||||
|
|
@ -2960,21 +2255,6 @@ mod tests {
|
|||
}
|
||||
|
||||
|
||||
fn adts_frame(payload: &[u8]) -> Vec<u8> {
|
||||
let frame_length = 7 + payload.len();
|
||||
let mut frame = vec![
|
||||
0xff,
|
||||
0xf1,
|
||||
0x4c,
|
||||
0x80 | (((frame_length >> 11) & 0x03) as u8),
|
||||
((frame_length >> 3) & 0xff) as u8,
|
||||
(((frame_length & 0x07) << 5) as u8) | 0x1f,
|
||||
0xfc,
|
||||
];
|
||||
frame.extend_from_slice(payload);
|
||||
frame
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn annex_b_stream_send_state_emits_only_completed_frames() -> Result<()> {
|
||||
let mut first_frame = Vec::new();
|
||||
|
|
|
|||
|
|
@ -455,9 +455,14 @@ the header's claims, rather than assuming them). Pinned to CultLib `d1a9eda`.
|
|||
belong in CultLib beside the `gamecult.media_*` records. **Until that moves,
|
||||
Ratatoskr cannot decode a real Muninn stream.**
|
||||
|
||||
The dead-but-kept Rust reassembly/FEC code in `media_packetizer.rs` is the seed
|
||||
for Ratatoskr's other half and should move there, not be deleted. That is why
|
||||
the 2026-09-10 dead-code cut deliberately took only the AAC path.
|
||||
The receiver-side reassembly code that was kept in `media_packetizer.rs` as the
|
||||
seed for Ratatoskr moved there on 2026-09-10 (`Ratatoskr` 2618184,
|
||||
`crates/ratatoskr-core/src/video.rs`) and was cut here (705 lines: frame
|
||||
assembly, the assembly set, reassembly, expired-frame feedback, their tests).
|
||||
Muninn now holds only the producer half: packetize, XOR stripe parity, and the
|
||||
feedback *builder* its sender tests exercise. The contract's erasure code is
|
||||
XOR stripes, one recovered chunk per stripe; the C++ receiver's GF(256) block
|
||||
solver reads fields the v2 record does not carry and stayed in Mimir.
|
||||
|
||||
### Opus, unblocked but unstarted
|
||||
|
||||
|
|
@ -517,13 +522,11 @@ one once the patch is gone.
|
|||
2. **Port the OBS plugin into Ratatoskr** — ~1,200 lines of genuine OBS work
|
||||
(source registration, the ffmpeg audio decode child, program texture source,
|
||||
stem IPC). The ~2,500 lines of transport around it does not come.
|
||||
3. **Frame reassembly and FEC into Ratatoskr.** The dead-but-kept Rust
|
||||
implementation in `media_packetizer.rs` is the seed; that is why the
|
||||
2026-09-10 dead-code cut took only the AAC path.
|
||||
4. **Opus.** Unblocked and measured at 16.8x. `-f aac` in the receiver becomes
|
||||
3. **Opus.** Unblocked and measured at 16.8x. `-f aac` in the receiver becomes
|
||||
codec-driven; framing follows the `aac-adts-padded-v1` precedent (2-byte
|
||||
big-endian length prefix).
|
||||
5. **Receiver feedback** from Ratatoskr, so a producer has something to adapt to.
|
||||
4. **Receiver feedback** from Ratatoskr, so a producer has something to adapt to.
|
||||
The assembler already names what an expired frame lacked.
|
||||
|
||||
### Deliberate breaks, both recorded as passing tests
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue