Skip to content

Commit

Permalink
proper formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dedobbin committed Aug 27, 2023
1 parent 879d2e8 commit b0e7d2d
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions symphonia-codec-aac/src/adts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ impl FormatReader for AdtsReader {
let mut params = CodecParameters::new();

params
.for_codec(CODEC_TYPE_AAC)
.with_sample_rate(header.sample_rate)
.with_time_base(TimeBase::new(1, header.sample_rate));
.for_codec(CODEC_TYPE_AAC)
.with_sample_rate(header.sample_rate)
.with_time_base(TimeBase::new(1, header.sample_rate));

if let Some(channels) = header.channels {
params.with_channels(channels);
}

let n_frames = aproximate_frame_count(&mut source);
if let Some (n_frames) = n_frames{
if let Some(n_frames) = n_frames {
params.with_n_frames(n_frames);
}

Expand Down Expand Up @@ -268,10 +268,10 @@ impl FormatReader for AdtsReader {
}

fn aproximate_frame_count(mut source: &mut MediaSourceStream) -> Option<u64> {
if !source.is_seekable(){
if !source.is_seekable() {
return None;
}

const MAX_FRAMES: u32 = 20;

let original_pos = source.pos();
Expand All @@ -282,7 +282,7 @@ fn aproximate_frame_count(mut source: &mut MediaSourceStream) -> Option<u64> {
};

macro_rules! calculate_n_frames {
($n_bytes:expr, $parsed_n_frames:expr, $total_len:expr) => {
($n_bytes:expr, $parsed_n_frames:expr, $total_len:expr) => {
$total_len / ($n_bytes as f64 / $parsed_n_frames as f64) as u64 * SAMPLES_PER_AAC_PACKET
};
}
Expand All @@ -296,9 +296,7 @@ fn aproximate_frame_count(mut source: &mut MediaSourceStream) -> Option<u64> {

let header = match AdtsHeader::read(&mut source) {
Ok(header) => header,
_ => {
break Some(calculate_n_frames!(n_bytes, parsed_n_frames, total_len))
},
_ => break Some(calculate_n_frames!(n_bytes, parsed_n_frames, total_len)),
};

if source.ignore_bytes(header.frame_len as u64).is_err() {
Expand All @@ -312,13 +310,12 @@ fn aproximate_frame_count(mut source: &mut MediaSourceStream) -> Option<u64> {
// Seek_buffered_rev doesn't work when entire file is read. This would bug on very small files.
let res = source.seek(SeekFrom::Start(original_pos));
match res {
Ok(_) => {},
Ok(_) => {}
Err(_) => {
// Not great to panic here, but it's very unlikely to happen.
panic!("aproximate_frame_count: Failed to seek back to original position");
}
}

return n_frames;

}
}

0 comments on commit b0e7d2d

Please sign in to comment.