Skip to content

Commit

Permalink
formatting and debug print
Browse files Browse the repository at this point in the history
  • Loading branch information
dedobbin committed Feb 9, 2024
1 parent 8ddf94b commit 9a41b6d
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions symphonia-codec-aac/src/adts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ impl FormatReader for AdtsReader {
}

fn aproximate_frame_count(mut source: &mut MediaSourceStream) -> Option<u64> {

let original_pos = source.pos();

let total_len = match source.byte_len() {
Some(len) => len - original_pos,
_ => return None,
Expand Down Expand Up @@ -297,12 +296,11 @@ fn aproximate_frame_count(mut source: &mut MediaSourceStream) -> Option<u64> {
let mut parsed_n_frames = 0;
let mut n_bytes = 0;
let step = 2000;
//let step = 200;
let n_frames = loop {
// Find header without going over max_bytes boundry.
// Find header without going over max_bytes boundry.
let mut sync = 0u16;
while sync != 0xfff1 {
if source.pos() + 1 >= max_bytes{
if source.pos() + 1 >= max_bytes {
break;
}
let val = source.read_u8().unwrap(); //TODO: dont unwrap..
Expand All @@ -311,11 +309,11 @@ fn aproximate_frame_count(mut source: &mut MediaSourceStream) -> Option<u64> {
// AdtsHeader::read will also attempt to sync. Go 2 bytes back so this will line up.
source.seek_buffered_rev(2);

// Since we are synced up, AdtsHeader::read will always read exactly AdtsHeader::SIZE bytes.
// Since we are synced up, AdtsHeader::read will always read exactly AdtsHeader::SIZE bytes.
if source.pos() + AdtsHeader::SIZE as u64 >= max_bytes {
break calculate_n_frames!(n_bytes, parsed_n_frames, total_len);
}

let header = match AdtsHeader::read(&mut source) {
Ok(header) => header,
_ => {
Expand All @@ -332,17 +330,17 @@ fn aproximate_frame_count(mut source: &mut MediaSourceStream) -> Option<u64> {
}

parsed_n_frames += 1;
n_bytes += header.frame_len + AdtsHeader::SIZE;
n_bytes += header.frame_len + AdtsHeader::SIZE;

// seek_buffered_rel can read < step bytes, so even though this is not 100% accurate,
// seek_buffered_rel can read < step bytes, so even though this is not 100% accurate,
// it will never read > step bytes, so max_bytes boundry will never be crossed
if source.pos() + step >= max_bytes {
break calculate_n_frames!(n_bytes, parsed_n_frames, total_len);
}
source.seek_buffered_rel(step as isize);

};
debug!("Read {}/{} bytes (max bytes: {})", source.pos() - original_pos, total_len, max_bytes);
source.seek_buffered_rev((source.pos() - original_pos) as usize);

return n_frames;
}
}

0 comments on commit 9a41b6d

Please sign in to comment.