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

Introduce EbmlParsable trait to make the EBML parsing more ergonomic #115

Merged
merged 6 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
26 changes: 9 additions & 17 deletions src/demuxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use av_format::{
};

use crate::{
ebml::{self, ebml_err, ebml_header, EbmlHeader, ErrorKind},
ebml::{self, ebml_err, ebml_header, EbmlHeader, ParseError},
elements::{
segment, segment_element, simple_block, Audio, Cluster, Info, SeekHead, SegmentElement,
TrackEntry, TrackType, Tracks, Video,
Expand Down Expand Up @@ -81,23 +81,23 @@ impl MkvDemuxer {

match element {
SegmentElement::SeekHead(s) => {
trace!("got seek head: {:#?}", s);
trace!("got seek head: {s:#?}");
self.seek_head = if self.seek_head.is_none() {
Some(s)
} else {
return ebml_err(ErrorKind::DuplicateSegment(0x114D9B74));
return ebml_err(0x114D9B74, ParseError::DuplicateSegment);
};
}
SegmentElement::Info(i) => {
trace!("got info: {:#?}", i);
trace!("got info: {i:#?}");
self.info = if self.info.is_none() {
Some(i)
} else {
return ebml_err(ErrorKind::DuplicateSegment(0x1549A966));
return ebml_err(0x1549A966, ParseError::DuplicateSegment);
};
}
SegmentElement::Tracks(t) => {
trace!("got tracks: {:#?}", t);
trace!("got tracks: {t:#?}");
self.tracks = if self.tracks.is_none() {
let mut t = t;

Expand All @@ -111,11 +111,11 @@ impl MkvDemuxer {

Some(t)
} else {
return ebml_err(ErrorKind::DuplicateSegment(0x1654AE6B));
return ebml_err(0x1654AE6B, ParseError::DuplicateSegment);
}
}
el => {
debug!("got element: {:#?}", el);
debug!("got element: {el:#?}");
}
}

Expand Down Expand Up @@ -233,15 +233,7 @@ fn track_entry_media_kind(t: &TrackEntry) -> Option<MediaKind> {
}

pub fn track_to_stream(info: &Info, t: &TrackEntry) -> Stream {
let num = t
.track_timecode_scale
.map_or(info.timecode_scale as i64, |ts| {
if ts != 0. {
(ts * info.timecode_scale as f64) as i64
} else {
info.timecode_scale as i64
}
});
let num = (t.track_timecode_scale * info.timecode_scale as f64) as i64;

Stream {
id: t.track_uid as isize,
Expand Down
Loading