Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parses simple blocks after a block group are silently ignored. #95

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/demuxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ impl<'a> Cluster<'a> {
pub fn generate_packets(&self, tracks: &Tracks) -> Vec<Event> {
let mut v = Vec::new();

for block_data in self.simple_block.iter() {
if let Ok((i, block)) = simple_block(block_data) {
for block_data in self.block.iter() {
if let Ok((i, block)) = simple_block(block_data.block) {
debug!("parsing simple block: {:?}", block);
if let Some(index) = tracks.lookup(block.track_number) {
let packet = Packet {
Expand Down
29 changes: 20 additions & 9 deletions src/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use nom::{
multi::{many0, many1},
number::streaming::{be_i16, be_u8},
sequence::{pair, tuple},
branch::alt,
IResult,
};

Expand Down Expand Up @@ -178,8 +179,7 @@ pub struct Cluster<'a> {
pub silent_tracks: Option<SilentTracks>,
pub position: Option<u64>,
pub prev_size: Option<u64>,
pub simple_block: Vec<&'a [u8]>,
pub block_group: Vec<BlockGroup<'a>>,
pub block: Vec<BlockGroup<'a>>,
pub encrypted_block: Option<&'a [u8]>,
}

Expand All @@ -189,7 +189,6 @@ pub fn cluster(input: &[u8]) -> IResult<&[u8], SegmentElement, Error> {
complete(silent_tracks),
complete(ebml_uint(0xA7)),
complete(ebml_uint(0xAB)),
many0(complete(ebml_binary_ref(0xA3))),
many0(complete(block_group)),
complete(ebml_binary_ref(0xAF)),
))(input)
Expand All @@ -201,9 +200,8 @@ pub fn cluster(input: &[u8]) -> IResult<&[u8], SegmentElement, Error> {
silent_tracks: t.1,
position: t.2,
prev_size: t.3,
simple_block: value_error(input, t.4)?,
block_group: value_error(input, t.5)?,
encrypted_block: t.6,
block: value_error(input, t.4)?,
encrypted_block: t.5,
}),
))
})
Expand Down Expand Up @@ -238,7 +236,20 @@ pub struct BlockGroup<'a> {

//https://datatracker.ietf.org/doc/html/draft-lhomme-cellar-matroska-03#section-7.3.16
pub fn block_group(input: &[u8]) -> IResult<&[u8], BlockGroup, Error> {
ebml_master(0x5854, |inp| {
alt((map(complete(ebml_binary_ref(0xA3)), |block| BlockGroup{
block,
block_virtual: None,
block_additions: None,
block_duration: None,
reference_priority: 0,
reference_block: None,
reference_virtual: None,
codec_state: None,
discard_padding: None,
slices: None,
reference_frame: None
}),
ebml_master(0xA0, |inp| {
matroska_permutation((
complete(ebml_binary_ref(0xA1)),
complete(ebml_binary(0xA2)),
Expand All @@ -260,7 +271,7 @@ pub fn block_group(input: &[u8]) -> IResult<&[u8], BlockGroup, Error> {
block_virtual: t.1,
block_additions: t.2,
block_duration: t.3,
reference_priority: value_error(inp, t.4)?,
reference_priority: value_error(inp, t.4).unwrap_or(0),
reference_block: t.5,
reference_virtual: t.6,
codec_state: t.7,
Expand All @@ -270,7 +281,7 @@ pub fn block_group(input: &[u8]) -> IResult<&[u8], BlockGroup, Error> {
},
))
})
})(input)
})))(input)
}

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
32 changes: 27 additions & 5 deletions src/muxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use av_format::{common::GlobalInfo, error::*, muxer::*, stream::Stream};
use crate::{
ebml::EBMLHeader,
elements::{
Audio, Cluster, Colour, Info, Lacing, Seek, SeekHead, SimpleBlock, TrackEntry, TrackType,
Audio, Cluster, BlockGroup, Colour, Info, Lacing, Seek, SeekHead, SimpleBlock, TrackEntry, TrackType,
Tracks, Video,
},
serializer::{
Expand Down Expand Up @@ -349,8 +349,19 @@ impl Muxer for MkvMuxer {
silent_tracks: None,
position: None,
prev_size: None,
simple_block: simple_blocks,
block_group: Vec::new(),
block: simple_blocks.iter().map(|block| BlockGroup{
block,
block_virtual: None,
block_additions: None,
block_duration: None,
reference_priority: 0,
reference_block: None,
reference_virtual: None,
codec_state: None,
discard_padding: None,
slices: None,
reference_frame: None
}).collect(),
encrypted_block: None,
};

Expand Down Expand Up @@ -401,8 +412,19 @@ impl Muxer for MkvMuxer {
silent_tracks: None,
position: None,
prev_size: None,
simple_block: simple_blocks,
block_group: Vec::new(),
block: simple_blocks.iter().map(|block| BlockGroup{
block,
block_virtual: None,
block_additions: None,
block_duration: None,
reference_priority: 0,
reference_block: None,
reference_virtual: None,
codec_state: None,
discard_padding: None,
slices: None,
reference_frame: None
}).collect(),
encrypted_block: None,
};

Expand Down
16 changes: 6 additions & 10 deletions src/serializer/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,9 @@ fn gen_track_entry_video_projection<'a, 'b>(

impl<'a> EbmlSize for Cluster<'a> {
fn capacity(&self) -> usize {
self.timecode.size(0xE7) + self.silent_tracks.size(0x5854) + self.position.size(0xA7) +
self.prev_size.size(0xAB) + self.simple_block.size(0xA3) +
// TODO: implement for BlockGroup
// self.block_group.size(0xA0) +
self.encrypted_block.size(0xAF)
/*self.timecode.size(0xE7) + self.silent_tracks.size(0x5854) + self.position.size(0xA7) +
self.prev_size.size(0xAB) + self.block.size(0xA0) +
self.encrypted_block.size(0xAF)*/unimplemented!()
}
}

Expand All @@ -443,20 +441,18 @@ pub(crate) fn gen_cluster<'a, 'b>(
) -> impl Fn((&'b mut [u8], usize)) -> Result<(&'b mut [u8], usize), GenError> + 'a {
move |input| {
let byte_capacity = vint_size(c.capacity() as u64)?;
gen_ebml_master(
/*gen_ebml_master(
0x1F43B675,
byte_capacity,
tuple((
gen_ebml_uint(0xE7, c.timecode),
gen_opt(c.silent_tracks.as_ref(), gen_silent_tracks),
gen_opt_copy(c.position, |v| gen_ebml_uint(0xA7, v)),
gen_opt_copy(c.prev_size, |v| gen_ebml_uint(0xAB, v)),
gen_many(&c.simple_block, |v| gen_ebml_binary(0xA3, v)),
// TODO: implement for BlockGroup
// gen_many(&c.block_group, gen_block_group)
gen_many(&c.block, |v| gen_block_group),
gen_opt(c.encrypted_block.as_ref(), |v| gen_ebml_binary(0xAF, v)),
)),
)(input)
)(input)*/unimplemented!()
}
}

Expand Down