T1.5: Migrate emit/parse sites to v2 wire format
This commit is contained in:
@@ -4,8 +4,8 @@ use std::collections::HashMap;
|
||||
use std::time::Instant;
|
||||
|
||||
use raptorq::{EncodingPacket, ObjectTransmissionInformation, PayloadId, SourceBlockDecoder};
|
||||
use wzp_proto::error::FecError;
|
||||
use wzp_proto::FecDecoder;
|
||||
use wzp_proto::error::FecError;
|
||||
|
||||
/// Length prefix size (u16 little-endian), must match encoder.
|
||||
const LEN_PREFIX: usize = 2;
|
||||
@@ -140,10 +140,7 @@ impl FecDecoder for RaptorQFecDecoder {
|
||||
frames.push(Vec::new());
|
||||
continue;
|
||||
}
|
||||
let payload_len = u16::from_le_bytes([
|
||||
data[offset],
|
||||
data[offset + 1],
|
||||
]) as usize;
|
||||
let payload_len = u16::from_le_bytes([data[offset], data[offset + 1]]) as usize;
|
||||
let payload_start = offset + LEN_PREFIX;
|
||||
let payload_end = (payload_start + payload_len).min(data.len());
|
||||
frames.push(data[payload_start..payload_end].to_vec());
|
||||
@@ -198,9 +195,7 @@ mod tests {
|
||||
|
||||
// Feed all source symbols (using the length-prefixed padded data).
|
||||
for (i, pkt) in source_pkts.iter().enumerate() {
|
||||
decoder
|
||||
.add_symbol(0, i as u8, false, pkt.data())
|
||||
.unwrap();
|
||||
decoder.add_symbol(0, i as u8, false, pkt.data()).unwrap();
|
||||
}
|
||||
|
||||
let result = decoder.try_decode(0).unwrap();
|
||||
@@ -233,7 +228,11 @@ mod tests {
|
||||
let config = ObjectTransmissionInformation::new(block_len, SYMBOL_SIZE, 1, 1, 1);
|
||||
let mut dec = SourceBlockDecoder::new(0, &config, block_len);
|
||||
let decoded = dec.decode(all);
|
||||
assert!(decoded.is_some(), "Should recover with {:.0}% loss", drop_fraction * 100.0);
|
||||
assert!(
|
||||
decoded.is_some(),
|
||||
"Should recover with {:.0}% loss",
|
||||
drop_fraction * 100.0
|
||||
);
|
||||
|
||||
let data = decoded.unwrap();
|
||||
let ss = SYMBOL_SIZE as usize;
|
||||
@@ -245,13 +244,19 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decode_with_30pct_loss() { run_loss_test(FRAMES_PER_BLOCK, 0.5, 0.3); }
|
||||
fn decode_with_30pct_loss() {
|
||||
run_loss_test(FRAMES_PER_BLOCK, 0.5, 0.3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decode_with_50pct_loss() { run_loss_test(FRAMES_PER_BLOCK, 1.0, 0.5); }
|
||||
fn decode_with_50pct_loss() {
|
||||
run_loss_test(FRAMES_PER_BLOCK, 1.0, 0.5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decode_with_70pct_source_loss_heavy_repair() { run_loss_test(8, 2.0, 0.5); }
|
||||
fn decode_with_70pct_source_loss_heavy_repair() {
|
||||
run_loss_test(8, 2.0, 0.5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expire_removes_old_blocks() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! RaptorQ FEC encoder — accumulates source symbols into blocks and generates repair symbols.
|
||||
|
||||
use raptorq::{EncodingPacket, ObjectTransmissionInformation, PayloadId, SourceBlockEncoder};
|
||||
use wzp_proto::error::FecError;
|
||||
use wzp_proto::FecEncoder;
|
||||
use wzp_proto::error::FecError;
|
||||
|
||||
/// Maximum symbol size in bytes. Audio frames are typically < 200 bytes,
|
||||
/// but we pad to a uniform size within a block.
|
||||
@@ -54,8 +54,7 @@ impl RaptorQFecEncoder {
|
||||
let payload_len = sym.len().min(max_payload);
|
||||
let offset = i * ss;
|
||||
// Write 2-byte little-endian length prefix.
|
||||
data[offset..offset + LEN_PREFIX]
|
||||
.copy_from_slice(&(payload_len as u16).to_le_bytes());
|
||||
data[offset..offset + LEN_PREFIX].copy_from_slice(&(payload_len as u16).to_le_bytes());
|
||||
// Write payload after prefix.
|
||||
data[offset + LEN_PREFIX..offset + LEN_PREFIX + payload_len]
|
||||
.copy_from_slice(&sym[..payload_len]);
|
||||
@@ -81,7 +80,8 @@ impl FecEncoder for RaptorQFecEncoder {
|
||||
}
|
||||
|
||||
let block_data = self.build_block_data();
|
||||
let config = ObjectTransmissionInformation::with_defaults(block_data.len() as u64, self.symbol_size);
|
||||
let config =
|
||||
ObjectTransmissionInformation::with_defaults(block_data.len() as u64, self.symbol_size);
|
||||
let encoder = SourceBlockEncoder::new(self.block_id, &config, &block_data);
|
||||
|
||||
let num_source = self.source_symbols.len() as u32;
|
||||
@@ -130,8 +130,7 @@ fn build_prefixed_block_data(symbols: &[Vec<u8>], symbol_size: u16) -> Vec<u8> {
|
||||
let max_payload = ss - LEN_PREFIX;
|
||||
let payload_len = sym.len().min(max_payload);
|
||||
let offset = i * ss;
|
||||
data[offset..offset + LEN_PREFIX]
|
||||
.copy_from_slice(&(payload_len as u16).to_le_bytes());
|
||||
data[offset..offset + LEN_PREFIX].copy_from_slice(&(payload_len as u16).to_le_bytes());
|
||||
data[offset + LEN_PREFIX..offset + LEN_PREFIX + payload_len]
|
||||
.copy_from_slice(&sym[..payload_len]);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,10 @@ mod tests {
|
||||
|
||||
// Each block should lose exactly 2 (6 losses / 3 blocks)
|
||||
for &loss in &losses_per_block {
|
||||
assert_eq!(loss, 2, "Each block should lose at most 2 symbols from a burst of 6");
|
||||
assert_eq!(
|
||||
loss, 2,
|
||||
"Each block should lose at most 2 symbols from a burst of 6"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ pub mod encoder;
|
||||
pub mod interleave;
|
||||
|
||||
pub use adaptive::AdaptiveFec;
|
||||
pub use block_manager::{DecoderBlockManager, DecoderBlockState, EncoderBlockManager, EncoderBlockState};
|
||||
pub use block_manager::{
|
||||
DecoderBlockManager, DecoderBlockState, EncoderBlockManager, EncoderBlockState,
|
||||
};
|
||||
pub use decoder::RaptorQFecDecoder;
|
||||
pub use encoder::RaptorQFecEncoder;
|
||||
pub use interleave::Interleaver;
|
||||
@@ -24,9 +26,7 @@ pub use interleave::Interleaver;
|
||||
pub use wzp_proto::{FecDecoder, FecEncoder, QualityProfile};
|
||||
|
||||
/// Create an encoder/decoder pair configured for the given quality profile.
|
||||
pub fn create_fec_pair(
|
||||
profile: &QualityProfile,
|
||||
) -> (RaptorQFecEncoder, RaptorQFecDecoder) {
|
||||
pub fn create_fec_pair(profile: &QualityProfile) -> (RaptorQFecEncoder, RaptorQFecDecoder) {
|
||||
let cfg = AdaptiveFec::from_profile(profile);
|
||||
let encoder = cfg.build_encoder();
|
||||
let decoder = RaptorQFecDecoder::new(cfg.frames_per_block, cfg.symbol_size);
|
||||
|
||||
Reference in New Issue
Block a user