Skip to content

flac, isomp4, mkv: optimize length detection by using byte_len() instead of seeking #340

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions symphonia-bundle-flac/src/demuxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use std::io::{Seek, SeekFrom};
use symphonia_core::support_format;

use symphonia_core::codecs::{CodecParameters, VerificationCheck, CODEC_TYPE_FLAC};
use symphonia_core::errors::{decode_error, seek_error, unsupported_error, Result, SeekErrorKind};
use symphonia_core::errors::{
decode_error, seek_error, unsupported_error, Error, Result, SeekErrorKind,
};
use symphonia_core::formats::prelude::*;
use symphonia_core::formats::util::{SeekIndex, SeekSearchResult};
use symphonia_core::io::*;
Expand Down Expand Up @@ -229,7 +231,8 @@ impl FormatReader for FlacReader {
// lower bound is set to the byte offset of the first frame, while the upper bound is
// set to the length of the stream.
let mut start_byte_offset = self.first_frame_offset;
let mut end_byte_offset = self.reader.seek(SeekFrom::End(0))?;
let mut end_byte_offset =
self.reader.byte_len().ok_or(Error::SeekError(SeekErrorKind::Unseekable))?;

// If there is an index, use it to refine the binary search range.
if let Some(ref index) = self.index {
Expand Down
6 changes: 4 additions & 2 deletions symphonia-format-isomp4/src/demuxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use symphonia_core::{errors::end_of_stream_error, support_format};

use symphonia_core::codecs::CodecParameters;
use symphonia_core::errors::{decode_error, seek_error, unsupported_error, Result, SeekErrorKind};
use symphonia_core::errors::{
decode_error, seek_error, unsupported_error, Error, Result, SeekErrorKind,
};
use symphonia_core::formats::prelude::*;
use symphonia_core::io::{MediaSource, MediaSourceStream, ReadBytes, SeekBuffered};
use symphonia_core::meta::{Metadata, MetadataLog};
Expand Down Expand Up @@ -335,7 +337,7 @@ impl FormatReader for IsoMp4Reader {
// Get the total length of the stream, if possible.
let total_len = if is_seekable {
let pos = mss.pos();
let len = mss.seek(SeekFrom::End(0))?;
let len = mss.byte_len().ok_or(Error::SeekError(SeekErrorKind::Unseekable))?;
mss.seek(SeekFrom::Start(pos))?;
info!("stream is seekable with len={} bytes.", len);
Some(len)
Expand Down
2 changes: 1 addition & 1 deletion symphonia-format-mkv/src/demuxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl FormatReader for MkvReader {
// Get the total length of the stream, if possible.
let total_len = if is_seekable {
let pos = reader.pos();
let len = reader.seek(SeekFrom::End(0))?;
let len = reader.byte_len().ok_or(Error::SeekError(SeekErrorKind::Unseekable))?;
reader.seek(SeekFrom::Start(pos))?;
log::info!("stream is seekable with len={} bytes.", len);
Some(len)
Expand Down