diff --git a/assets/eof_rpu.bin b/assets/eof_rpu.bin new file mode 100644 index 0000000..d2f1442 Binary files /dev/null and b/assets/eof_rpu.bin differ diff --git a/src/dovi/rpu/mod.rs b/src/dovi/rpu/mod.rs index 1610a61..7976ee9 100644 --- a/src/dovi/rpu/mod.rs +++ b/src/dovi/rpu/mod.rs @@ -29,7 +29,7 @@ pub fn parse_dovi_rpu(data: &[u8]) -> Result { return Err(format!("Invalid RPU\n{:?}", &bytes)); } - let mut dovi_rpu = DoviRpu::read_rpu_data(bytes); + let mut dovi_rpu = DoviRpu::read_rpu_data(bytes, last_byte); assert_eq!(received_crc32, dovi_rpu.rpu_data_crc32); dovi_rpu.dovi_profile = dovi_rpu.header.get_dovi_profile(); diff --git a/src/dovi/rpu/rpu_data.rs b/src/dovi/rpu/rpu_data.rs index aa66be1..88d3ae0 100644 --- a/src/dovi/rpu/rpu_data.rs +++ b/src/dovi/rpu/rpu_data.rs @@ -19,6 +19,7 @@ pub struct DoviRpu { pub vdr_dm_data: Option, pub remaining: BitVec, pub rpu_data_crc32: u32, + pub last_byte: u8, } impl DoviRpu { @@ -30,8 +31,10 @@ impl DoviRpu { } #[inline(always)] - pub fn read_rpu_data(bytes: Vec) -> DoviRpu { + pub fn read_rpu_data(bytes: Vec, end_byte: u8) -> DoviRpu { let mut dovi_rpu = DoviRpu::new(bytes); + dovi_rpu.last_byte = end_byte; + let reader = &mut dovi_rpu.reader; dovi_rpu.header = RpuDataHeader::rpu_data_header(reader); @@ -56,9 +59,16 @@ impl DoviRpu { dovi_rpu.remaining.push(reader.get()); } + // EOF case + let final_len = if end_byte == 0 { + 48 + } else { + 40 + }; + // CRC32 is at the end, apparently sometimes there is more unknown data - if reader.available() != 40 { - while reader.available() != 40 { + if reader.available() != final_len { + while reader.available() != final_len { dovi_rpu.remaining.push(reader.get()); } } @@ -136,6 +146,10 @@ impl DoviRpu { writer.write_n(&computed_crc32.to_be_bytes(), 32); writer.write_n(&[0x80], 8); + if self.last_byte != 0x80 { + writer.write_n(&[self.last_byte], 8); + } + // Back to a u8 slice let mut data_to_write = writer.as_slice().to_vec(); add_start_code_emulation_prevention_3_byte(&mut data_to_write); diff --git a/src/dovi/rpu/tests.rs b/src/dovi/rpu/tests.rs index da5af3d..d8df845 100644 --- a/src/dovi/rpu/tests.rs +++ b/src/dovi/rpu/tests.rs @@ -23,7 +23,7 @@ fn profile5() { assert_eq!(dovi_rpu.dovi_profile, 5); let parsed_data = dovi_rpu.write_rpu_data(mode); - assert_eq!(&original_data[2..], &parsed_data[2..]); + assert_eq!(&original_data, &parsed_data); } #[test] @@ -33,7 +33,7 @@ fn profile8() { assert_eq!(dovi_rpu.dovi_profile, 8); let parsed_data = dovi_rpu.write_rpu_data(mode); - assert_eq!(&original_data[2..], &parsed_data[2..]); + assert_eq!(&original_data, &parsed_data); } #[test] @@ -43,7 +43,7 @@ fn fel() { assert_eq!(dovi_rpu.dovi_profile, 7); let parsed_data = dovi_rpu.write_rpu_data(mode); - assert_eq!(&original_data[2..], &parsed_data[2..]); + assert_eq!(&original_data, &parsed_data); } #[test] @@ -53,7 +53,7 @@ fn mel() { assert_eq!(dovi_rpu.dovi_profile, 7); let parsed_data = dovi_rpu.write_rpu_data(mode); - assert_eq!(&original_data[2..], &parsed_data[2..]); + assert_eq!(&original_data, &parsed_data); } #[test] @@ -63,21 +63,21 @@ fn fel_conversions() { assert_eq!(dovi_rpu.dovi_profile, 7); let mut parsed_data = dovi_rpu.write_rpu_data(mode); - assert_eq!(&original_data[2..], &parsed_data[2..]); + assert_eq!(&original_data, &parsed_data); // FEL to MEL let (mel_data, mel_rpu) = parse_file(PathBuf::from("./assets/fel_to_mel.bin")); assert_eq!(mel_rpu.dovi_profile, 7); parsed_data = dovi_rpu.write_rpu_data(1); - assert_eq!(&mel_data[2..], &parsed_data[2..]); + assert_eq!(&mel_data, &parsed_data); // FEL to 8.1 let (p81_data, p81_rpu) = parse_file(PathBuf::from("./assets/fel_to_81.bin")); assert_eq!(p81_rpu.dovi_profile, 8); parsed_data = dovi_rpu.write_rpu_data(2); - assert_eq!(&p81_data[2..], &parsed_data[2..]); + assert_eq!(&p81_data, &parsed_data); } #[test] @@ -87,7 +87,7 @@ fn fel_to_mel() { assert_eq!(dovi_rpu.dovi_profile, 7); let parsed_data = dovi_rpu.write_rpu_data(mode); - assert_eq!(&original_data[2..], &parsed_data[2..]); + assert_eq!(&original_data, &parsed_data); } #[test] @@ -97,7 +97,7 @@ fn fel_to_profile8() { assert_eq!(dovi_rpu.dovi_profile, 8); let parsed_data = dovi_rpu.write_rpu_data(mode); - assert_eq!(&original_data[2..], &parsed_data[2..]); + assert_eq!(&original_data, &parsed_data); } #[test] @@ -107,21 +107,21 @@ fn mel_conversions() { assert_eq!(dovi_rpu.dovi_profile, 7); let mut parsed_data = dovi_rpu.write_rpu_data(mode); - assert_eq!(&original_data[2..], &parsed_data[2..]); + assert_eq!(&original_data, &parsed_data); // MEL to MEL let (mel_data, mel_rpu) = parse_file(PathBuf::from("./assets/mel_to_mel.bin")); assert_eq!(mel_rpu.dovi_profile, 7); parsed_data = dovi_rpu.write_rpu_data(1); - assert_eq!(&mel_data[2..], &parsed_data[2..]); + assert_eq!(&mel_data, &parsed_data); // MEL to 8.1 let (p81_data, p81_rpu) = parse_file(PathBuf::from("./assets/mel_to_81.bin")); assert_eq!(p81_rpu.dovi_profile, 8); parsed_data = dovi_rpu.write_rpu_data(2); - assert_eq!(&p81_data[2..], &parsed_data[2..]); + assert_eq!(&p81_data, &parsed_data); } #[test] @@ -131,7 +131,7 @@ fn data_before_crc32() { assert_eq!(dovi_rpu.dovi_profile, 7); let parsed_data = dovi_rpu.write_rpu_data(mode); - assert_eq!(&original_data[2..], &parsed_data[2..]); + assert_eq!(&original_data, &parsed_data); } #[test] @@ -141,5 +141,15 @@ fn fix_se_write() { assert_eq!(dovi_rpu.dovi_profile, 7); let parsed_data = dovi_rpu.write_rpu_data(mode); - assert_eq!(&original_data[2..], &parsed_data[2..]); + assert_eq!(&original_data, &parsed_data); } + +#[test] +fn eof_rpu() { + let mode = 0; + let (original_data, mut dovi_rpu) = parse_file(PathBuf::from("./assets/eof_rpu.bin")); + assert_eq!(dovi_rpu.dovi_profile, 7); + let parsed_data = dovi_rpu.write_rpu_data(mode); + + assert_eq!(&original_data, &parsed_data); +} \ No newline at end of file