Encode Muninn audio packets for media senders
This commit is contained in:
parent
6869376fa1
commit
42a1e1df38
1 changed files with 52 additions and 0 deletions
|
|
@ -183,6 +183,13 @@ pub struct AudioPacketizeOptions<'a> {
|
|||
pub deadline_ticks: i64,
|
||||
}
|
||||
|
||||
pub struct AudioPacketWireOptions<'a> {
|
||||
pub packetize: AudioPacketizeOptions<'a>,
|
||||
pub stored_at: &'a str,
|
||||
pub source_runtime_id: &'a str,
|
||||
pub source_role: &'a str,
|
||||
}
|
||||
|
||||
pub struct ReceiverFeedbackOptions<'a> {
|
||||
pub stream_id: &'a str,
|
||||
pub session_id: &'a str,
|
||||
|
|
@ -1024,6 +1031,19 @@ pub fn encode_video_annex_b_stream_wire_records(
|
|||
)
|
||||
}
|
||||
|
||||
pub fn encode_audio_packet_wire_record(
|
||||
options: AudioPacketWireOptions<'_>,
|
||||
payload: &[u8],
|
||||
) -> Result<Vec<u8>> {
|
||||
let record = packetize_audio_packet(options.packetize, payload)?;
|
||||
encode_media_wire_record(
|
||||
&MuninnMediaWireRecord::Audio(record),
|
||||
options.stored_at,
|
||||
options.source_runtime_id,
|
||||
options.source_role,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn decode_media_wire_record(payload: &[u8]) -> Result<MuninnMediaWireRecord> {
|
||||
let message = decode_cultnet_message_from_slice(payload, CultNetWireContract::CultNetSchemaV0)?;
|
||||
let CultNetMessage::DocumentPutRaw { document, .. } = message else {
|
||||
|
|
@ -2474,6 +2494,38 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn media_wire_encodes_audio_packet_for_sender() -> Result<()> {
|
||||
let wire = encode_audio_packet_wire_record(
|
||||
AudioPacketWireOptions {
|
||||
packetize: AudioPacketizeOptions {
|
||||
stream_id: "muninn.raven.av.rudp",
|
||||
session_id: "session-1",
|
||||
codec: "opus",
|
||||
packet_id: 12,
|
||||
pts_ticks: 48_000,
|
||||
duration_ticks: 960,
|
||||
timebase_num: 1,
|
||||
timebase_den: 48_000,
|
||||
deadline_ticks: 48_960,
|
||||
},
|
||||
stored_at: "2026-06-18T00:00:00Z",
|
||||
source_runtime_id: "muninn-test",
|
||||
source_role: "media-test",
|
||||
},
|
||||
&[0xf8, 0xff, 0xfe],
|
||||
)?;
|
||||
|
||||
let decoded = decode_media_wire_record(&wire)?;
|
||||
let MuninnMediaWireRecord::Audio(decoded) = decoded else {
|
||||
panic!("expected audio media record");
|
||||
};
|
||||
assert_eq!(decoded.packet_id, 12);
|
||||
assert_eq!(decoded.codec, "opus");
|
||||
assert_eq!(decoded.payload, vec![0xf8, 0xff, 0xfe]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn media_wire_round_trips_audio_document() -> Result<()> {
|
||||
let record = packetize_audio_packet(
|
||||
|
|
|
|||
Loading…
Reference in a new issue