Add Muninn media receiver feedback builder
This commit is contained in:
parent
e44a02ef57
commit
60a0bb5d1c
1 changed files with 103 additions and 1 deletions
|
|
@ -1,5 +1,8 @@
|
|||
use anyhow::{Result, anyhow};
|
||||
use odin_core::{MuninnMediaAudioPacketRecord, MuninnMediaVideoAccessUnitRecord};
|
||||
use odin_core::{
|
||||
MuninnMediaAudioPacketRecord, MuninnMediaReceiverFeedbackRecord,
|
||||
MuninnMediaVideoAccessUnitRecord,
|
||||
};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
|
@ -92,6 +95,19 @@ pub struct AudioPacketizeOptions<'a> {
|
|||
pub deadline_ticks: i64,
|
||||
}
|
||||
|
||||
pub struct ReceiverFeedbackOptions<'a> {
|
||||
pub stream_id: &'a str,
|
||||
pub session_id: &'a str,
|
||||
pub receiver_id: &'a str,
|
||||
pub highest_decodable_frame_id: Option<u64>,
|
||||
pub missing_frame_ids: Vec<u64>,
|
||||
pub late_frame_ids: Vec<u64>,
|
||||
pub requested_keyframe: bool,
|
||||
pub jitter_us: i64,
|
||||
pub decode_queue_us: i64,
|
||||
pub observed_at: &'a str,
|
||||
}
|
||||
|
||||
pub fn packetize_video_access_unit(
|
||||
options: VideoFramePacketizeOptions<'_>,
|
||||
access_unit: &VideoAccessUnit,
|
||||
|
|
@ -278,6 +294,52 @@ pub fn reassemble_video_access_unit(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn build_receiver_feedback(
|
||||
options: ReceiverFeedbackOptions<'_>,
|
||||
) -> Result<MuninnMediaReceiverFeedbackRecord> {
|
||||
if options.stream_id.is_empty() {
|
||||
return Err(anyhow!("stream_id must be non-empty"));
|
||||
}
|
||||
if options.session_id.is_empty() {
|
||||
return Err(anyhow!("session_id must be non-empty"));
|
||||
}
|
||||
if options.receiver_id.is_empty() {
|
||||
return Err(anyhow!("receiver_id must be non-empty"));
|
||||
}
|
||||
if options.observed_at.is_empty() {
|
||||
return Err(anyhow!("observed_at must be non-empty"));
|
||||
}
|
||||
if options.jitter_us < 0 {
|
||||
return Err(anyhow!("jitter_us must be non-negative"));
|
||||
}
|
||||
if options.decode_queue_us < 0 {
|
||||
return Err(anyhow!("decode_queue_us must be non-negative"));
|
||||
}
|
||||
|
||||
let mut missing_frame_ids = options.missing_frame_ids;
|
||||
missing_frame_ids.sort_unstable();
|
||||
missing_frame_ids.dedup();
|
||||
|
||||
let mut late_frame_ids = options.late_frame_ids;
|
||||
late_frame_ids.sort_unstable();
|
||||
late_frame_ids.dedup();
|
||||
|
||||
let requested_keyframe = options.requested_keyframe || !missing_frame_ids.is_empty();
|
||||
|
||||
Ok(MuninnMediaReceiverFeedbackRecord {
|
||||
stream_id: options.stream_id.to_string(),
|
||||
session_id: options.session_id.to_string(),
|
||||
receiver_id: options.receiver_id.to_string(),
|
||||
highest_decodable_frame_id: options.highest_decodable_frame_id,
|
||||
missing_frame_ids,
|
||||
late_frame_ids,
|
||||
requested_keyframe,
|
||||
jitter_us: options.jitter_us,
|
||||
decode_queue_us: options.decode_queue_us,
|
||||
observed_at: options.observed_at.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
fn h264_annex_b_nal_units(input: &[u8]) -> Result<Vec<NalUnit<'_>>> {
|
||||
let mut starts = Vec::new();
|
||||
let mut offset = 0_usize;
|
||||
|
|
@ -609,4 +671,44 @@ mod tests {
|
|||
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 {
|
||||
stream_id: "muninn.raven.av.rudp",
|
||||
session_id: "session-1",
|
||||
receiver_id: "starfire.obs",
|
||||
highest_decodable_frame_id: Some(40),
|
||||
missing_frame_ids: vec![43, 42, 43],
|
||||
late_frame_ids: vec![39, 39, 38],
|
||||
requested_keyframe: false,
|
||||
jitter_us: 700,
|
||||
decode_queue_us: 2_000,
|
||||
observed_at: "2026-06-18T00:00:00Z",
|
||||
})?;
|
||||
|
||||
assert_eq!(feedback.missing_frame_ids, vec![42, 43]);
|
||||
assert_eq!(feedback.late_frame_ids, vec![38, 39]);
|
||||
assert!(feedback.requested_keyframe);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_negative_receiver_feedback_timing() {
|
||||
let error = build_receiver_feedback(ReceiverFeedbackOptions {
|
||||
stream_id: "muninn.raven.av.rudp",
|
||||
session_id: "session-1",
|
||||
receiver_id: "starfire.obs",
|
||||
highest_decodable_frame_id: Some(40),
|
||||
missing_frame_ids: Vec::new(),
|
||||
late_frame_ids: Vec::new(),
|
||||
requested_keyframe: false,
|
||||
jitter_us: -1,
|
||||
decode_queue_us: 2_000,
|
||||
observed_at: "2026-06-18T00:00:00Z",
|
||||
})
|
||||
.unwrap_err();
|
||||
|
||||
assert!(error.to_string().contains("jitter_us"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue