pub struct Disc<R> { /* private fields */ }Expand description
An opened disc image with its table of contents.
Opening reads only the master TOC and the area TOCs. Audio is read on demand.
§Which call
| To | Decoded audio | Frames as stored |
|---|---|---|
| read a track | Disc::track_audio | Disc::track_frames |
| read a frame range | Disc::range_audio | Disc::range_frames |
| read every accepted frame of an area | Disc::stored_frame_list | |
| hold the reading without a borrow | TrackAudio::into_cursor | TrackFrames::into_cursor |
open a cursor from &self | Disc::audio_cursor | Disc::frames_cursor, Disc::stored_frame_list_cursor |
| read a cursor | Disc::read_track_audio | Disc::read_frames |
| go on to a later track | Disc::continue_track_audio | Disc::continue_track_frames |
| go on to a later range | Disc::continue_range_audio | Disc::continue_range_frames |
For decoded audio with the stored bytes in one pass, use TrackAudio::keep_stored and
TrackAudio::next_with_stored. To start a cursor from your own seek index, or with
another seek policy for that one cursor, use CursorOptions. Disc::area_frames is
the diagnostic form of Disc::stored_frame_list.
Without a Disc, use TrackAudioCursor::new or TrackCursor::new for a track,
TrackAudioCursor::open_range or TrackCursor::open_range for a range,
AreaCursor::new for an area, and continue_to and continue_to_range to go on.
§Several readers
A disc reads through one reader with one position, so its reads take &mut self. For
reads of one image on several threads at once, give each thread a disc of its own made
from this one: Disc::share with another reader of the same image, or clone for a
disc read through a ReadAtReader (no I/O). They share the parsed TOC, warnings,
sector format and log, and the image identifier (Image::id), so a cursor made or
read through one may be read through any other: they read the same bytes.
use std::sync::Arc;
use scarletbook::{Disc, ReadAtReader, Slot};
let file = Arc::new(std::fs::File::open("disc.iso")?);
let disc = Disc::open(ReadAtReader::new(file))?;
let count = disc.toc().area(Slot::TwoChannel).map_or(0, |a| a.tracks.len()) as u32;
std::thread::scope(|s| {
for n in 1..=count {
let mut disc = disc.clone();
s.spawn(move || -> Result<(), scarletbook::Error> {
for frame in disc.track_audio(Slot::TwoChannel, n)? {
let _frame = frame?;
}
Ok(())
});
}
});§Seeking
With a seek index enabled for an area (Disc::enable_seek_index or
Disc::set_seek_index; off by default), every track and range cursor of that area
this disc, or any disc made from it by Disc::share or clone, makes or continues
starts from the index (one index per area, which they all use and grow, from any
thread) (see crate::seek), and the
borrowing iterators (TrackAudio, TrackFrames) and continuations hand the
checkpoints their cursors record back to it as they read. The frames, statuses, counts
and warnings are exactly those without an index; once the index covers a range, opening
it reads at most a few dozen sectors before the range’s own, wherever it lies. A
continuation starts from the index instead of the area’s first sector when the earlier
cursor’s state cannot be reused, and also when the index starts the range more than two
checkpoints past that cursor’s scan (until it first reads, a cursor moved ahead so
reports the malformed sectors and warnings of the scan it was moved from, as a reused
one would). The stored frame list and Disc::area_frames always scan from the area’s
first sector.
use scarletbook::{AreaIndex, Disc, IndexOptions, Slot};
let mut disc = Disc::open(std::io::BufReader::new(std::fs::File::open("disc.iso")?))?;
disc.enable_seek_index(Slot::TwoChannel, IndexOptions::new())?;
// Built by reads as they go, or at once in steps: one pass over the area.
while !disc.extend_seek_index(Slot::TwoChannel, 64 * 1024)? {}
for frame in disc.range_audio(Slot::TwoChannel, 200_000, 200_075)? {
let _frame = frame?;
}
// Kept for the next time: checked again when loaded, and as it is used.
let saved = disc.seek_index(Slot::TwoChannel).map(|i| i.to_bytes()).unwrap_or_default();
let area = disc.toc().area(Slot::TwoChannel).ok_or(scarletbook::Error::NoSuchArea(Slot::TwoChannel))?;
let index = AreaIndex::from_bytes(area, disc.toc().sectors, &saved, scarletbook::seek::DEFAULT_INLINE_BUDGET)?;
disc.set_seek_index(Slot::TwoChannel, index)?;Implementations§
Source§impl Disc<()>
impl Disc<()>
Sourcepub fn options() -> DiscOptions
pub fn options() -> DiscOptions
The options for opening a disc with a sector format or log of the caller’s:
Disc::options().with_format(f).with_log(l).open(reader).
Source§impl<R: Read + Seek> Disc<R>
impl<R: Read + Seek> Disc<R>
Sourcepub fn open(reader: R) -> Result<Self, Error>
pub fn open(reader: R) -> Result<Self, Error>
Opens a disc image, detecting its sector format, logging nothing. Disc::options
chooses a format or a log.
§Errors
One of the rejections of specification 7, 7.7.1, or Error::Io.
Sourcepub fn from_image(image: Image<R>) -> Result<Self, Error>
pub fn from_image(image: Image<R>) -> Result<Self, Error>
A disc of the same image read through reader, with a position of its own, sharing
this disc’s TOC, warnings, sector format, image identifier and log (see Several
readers). Cursors of either disc may be read through the
other. Disc::set_log on one does not change the other’s.
reader is checked: it must have the image’s length, and the master TOC sector
(LSN 510) and the area TOC copies the parse used must hold the same bytes (by a
64-bit digest). This catches another file given by mistake; it cannot prove that the
audio sectors are the same, which stays the caller’s responsibility.
§Errors
Error::InvalidArgument if reader is of another image, Error::Io if it
fails.
Disc::share, with the new disc reporting to log (see crate::log), the
check of reader included.
§Errors
As Disc::share.
Sourcepub fn set_log(&mut self, log: Log)
pub fn set_log(&mut self, log: Log)
Replaces the log this disc reports to, from the next call on. Audio cursors report
to the log of the disc they read through; decoding jobs already started on the pool
(parallel feature) keep the log they started with.
Sourcepub fn cancel_token(&self) -> CancelToken
pub fn cancel_token(&self) -> CancelToken
The cancellation request of this disc’s reads, to cancel them from another thread
(see CancelToken). Every disc of the image (Disc::share, clone) has the
same: cancelling stops the reads of all of them and their cursors.
Sourcepub fn unreadable_sectors(&self) -> UnreadableSectors
pub fn unreadable_sectors(&self) -> UnreadableSectors
The audio sectors of this disc’s image that cannot be read (see
crate::UnreadableSectors, #435), shared with the discs of Disc::share and
clone: mark sectors there and every cursor that reads them afterwards reports
their frames lost instead of decoding them from part of their data.
Sourcepub fn track_timecodes_stored(
&self,
slot: Slot,
number: u32,
) -> Result<(Timecode, Timecode), Error>
pub fn track_timecodes_stored( &self, slot: Slot, number: u32, ) -> Result<(Timecode, Timecode), Error>
The start and duration timecodes of track number (1-based) of the area from slot
as stored in the area TOC’s SACDTRL2 (specification 3, 3.7.2), byte for byte:
before the clamping of 3.9.2 and whatever their range, so that a stored timecode
such as 255:255:255 is given as stored.
crate::Track::start_frame and crate::Track::duration_frames are their frame
numbers after clamping. The area’s play time as stored is crate::Area::playtime.
§Errors
Sourcepub fn warnings(&self) -> &[Warning]
pub fn warnings(&self) -> &[Warning]
The warnings emitted while reading the TOC (specification 7, 7.7.3).
Sourcepub fn enable_seek_index(
&mut self,
slot: Slot,
options: IndexOptions,
) -> Result<(), Error>
pub fn enable_seek_index( &mut self, slot: Slot, options: IndexOptions, ) -> Result<(), Error>
Keeps a seek index of the area from slot, empty to begin with, and makes and
continues that area’s cursors from it (see Seeking); an index
already kept is replaced. Every disc of the image (Disc::share, clone) keeps
the same index: this, Disc::set_seek_index and Disc::take_seek_index change
it for all of them.
§Errors
Error::NoSuchArea, or Error::InvalidArgument for invalid options.
Sourcepub fn set_seek_index(
&mut self,
slot: Slot,
index: AreaIndex,
) -> Result<(), Error>
pub fn set_seek_index( &mut self, slot: Slot, index: AreaIndex, ) -> Result<(), Error>
Keeps index (for example one loaded with AreaIndex::from_bytes) as the seek
index of the area from slot, as Disc::enable_seek_index does an empty one. It
is trusted to be of this disc’s image (see One index per
image): whatever image it was built from in this
process, it takes this disc’s from then on.
An index a disc kept before (saved with AreaIndex::to_bytes from version 2 of
its format on) holds a fingerprint of that disc’s TOC (the master TOC, the area TOC
and the image’s sector count; see AreaIndex): an index of another disc
of the same layout is refused. One without (made with AreaIndex::new, or saved
in version 1) takes this disc’s. Saved confirmations and exact checkpoints are then
trusted for this image whenever the TOC fingerprint and key match, so a re-rip with
different audio bytes would get confirmed or exact readings that differ from its own:
key saved indexes by the image file’s identity (path, size and modification time, or a
content hash) as well.
Verdicts index holds that AreaIndex::take_events has not taken go to
Disc::take_seek_events.
§Errors
Error::NoSuchArea, or Error::InvalidArgument if index is of another area
or image size, or of a disc with another TOC.
Sourcepub fn set_seek_policy(
&mut self,
slot: Slot,
policy: SeekPolicy,
) -> Result<(), Error>
pub fn set_seek_policy( &mut self, slot: Slot, policy: SeekPolicy, ) -> Result<(), Error>
Sets how this disc handle starts ranges of the area from slot that its seek index
(if any) cannot reach cheaply: SeekPolicy::Exact (the default) or
SeekPolicy::Speculative, which allows provisional reading (specification 4, 4.2
item 8, sacd-spec 82eac6c; see SeekPolicy for what it guarantees). The policy is
this handle’s: discs made from it by Disc::share and clone start with a copy,
and each may change its own. It applies to the cursors this handle makes and
continues from then on.
§Errors
Sourcepub fn seek_policy(&self, slot: Slot) -> SeekPolicy
pub fn seek_policy(&self, slot: Slot) -> SeekPolicy
The seek policy of the area from slot for this handle.
Sourcepub fn take_seek_index(&mut self, slot: Slot) -> Option<AreaIndex>
pub fn take_seek_index(&mut self, slot: Slot) -> Option<AreaIndex>
Stops keeping a seek index of the area from slot, and returns it.
Sourcepub fn seek_index(&self, slot: Slot) -> Option<AreaIndex>
pub fn seek_index(&self, slot: Slot) -> Option<AreaIndex>
A copy of the seek index of the area from slot, if one is kept: to save it
(AreaIndex::to_bytes) or to merge it with another.
Sourcepub fn extend_seek_index(
&mut self,
slot: Slot,
max_sectors: u64,
) -> Result<bool, Error>
pub fn extend_seek_index( &mut self, slot: Slot, max_sectors: u64, ) -> Result<bool, Error>
Reads the area from slot on from its seek index’s frontier, about max_sectors
sectors, recording checkpoints (see AreaIndex::extend): whether the index is
now complete. Reading a whole area this way builds the index for all its ranges at
the cost of one pass. It also checks the provisional readings the index now reaches
(AreaIndex::verify): their verdicts go to Disc::take_seek_events and to the
cursors that made them. A complete index says nothing of a reading registered during
this call, which Disc::verify_speculation does account for.
§Errors
Error::InvalidArgument if no seek index is kept for slot or it does not match
the image, Error::Io if a read fails, Error::SectorUnreadable at an
unreadable sector (see AreaIndex::extend).
Sourcepub fn extend_seek_index_past_marks(
&mut self,
slot: Slot,
max_sectors: u64,
) -> Result<bool, Error>
pub fn extend_seek_index_past_marks( &mut self, slot: Slot, max_sectors: u64, ) -> Result<bool, Error>
Reads the area from slot past its unreadable sectors, about max_sectors sectors,
recording the state of a scan that meets them in its seek index’s damage record
(see AreaIndex::extend_past_marks, #443): whether the record now reaches the
area’s end for the sectors marked now. Run in a loop, for example on a clone of the
disc in another thread once sectors are marked, it lets the first range opened past
a new mark start near it instead of scanning the area from its first sector (up to
the 4096 runs of marks a record keeps, see AreaIndex::extend_past_marks). As for
Disc::extend_seek_index, a copy of the index is extended, then joined with the
one kept; this call’s record replaces the kept one’s if their marks differ.
§Errors
Error::InvalidArgument if no seek index is kept for slot or it does not match
the image, Error::Io if a read fails.
Sourcepub fn verify_speculation(
&mut self,
slot: Slot,
max_sectors: u64,
) -> Result<bool, Error>
pub fn verify_speculation( &mut self, slot: Slot, max_sectors: u64, ) -> Result<bool, Error>
Builds the seek index of the area from slot by about max_sectors more sectors
and checks the provisional readings it then reaches (specification 4, 4.2 item 8):
Disc::extend_seek_index, named for what a caller of SeekPolicy::Speculative
runs it for, typically in a loop on a clone of the disc in another thread.
Returns true when, at this call’s last look at the index, the index was complete
and every provisional reading it held had its verdict. Returns false otherwise, with
nothing wrong: call again. That includes a complete index holding a reading that
another disc registered during this call, which this call’s check did not see.
true covers only the readings the index held by then. A reading joins the index when
its first frame is read through a disc’s iterators or
Disc::absorb_seek_checkpoints, and one that joins later, even before this call
returns, has no verdict and no event until a later call. A caller that must have every
verdict runs its while !disc.verify_speculation(..)? {} loop once more after its
readers have finished, then checks each reading’s own speculation(): a reading with
no verdict has no event.
Each call makes one round: about max_sectors sectors of the pass (at least to the
next checkpoint, so that 0 makes progress), then the check of the readings the index
reached and held when the round began. max_sectors does not limit those checks: each
reads a bounded number of sectors, and the number of readings waiting is bounded too.
Once no disc registers new readings, a loop ends: every false either added a
checkpoint or came from a reading that the next call checks.
§Errors
As Disc::extend_seek_index, except Error::SectorUnreadable: an unreadable
sector stops the index (#435), the readings it holds are settled (those past the
sector as Speculation::Unverified), and the call returns true as for a
complete index.
Sourcepub fn take_seek_events(&self, slot: Slot) -> Vec<SeekEvent>
pub fn take_seek_events(&self, slot: Slot) -> Vec<SeekEvent>
Takes the verdicts on provisional readings of the area from slot reached since the
last call, by this disc or any disc made from it by Disc::share or clone
(they share the queue): Speculation::Confirmed, Speculation::Refuted (the
positions below its exact_from are possibly different from the specification’s:
drop or re-read what was served from them; an exact read of them is now cheap, from
the index) or Speculation::Unverified. A provisional reading is checked only
when the disc keeps a seek index of its area (Disc::enable_seek_index).
Sourcepub fn absorb_seek_checkpoints(&self, cursor: &mut impl SeekCursor)
pub fn absorb_seek_checkpoints(&self, cursor: &mut impl SeekCursor)
Takes into the seek index of its area the checkpoints cursor recorded, for a
cursor read without this disc’s iterators (with TrackAudioCursor::next_frame
on Disc::image_mut); the iterators and continuations do this themselves. Only
cursors made from the index by a disc of this image (this one, or one made by
Disc::share or clone) that read this image are taken. Nothing happens for
others: cursors made from a caller’s index or without one, and cursors whose
checkpoints do not join the index. A cursor of another image (of the same size and
layout) stops recording instead, so that its checkpoints never reach this index.
Sourcepub fn area_frames(&mut self, slot: Slot) -> Result<AreaFrames<'_, R>, Error>
pub fn area_frames(&mut self, slot: Slot) -> Result<AreaFrames<'_, R>, Error>
The diagnostic form of Disc::stored_frame_list: the accepted frames of the area
from slot, read from its audio sectors (specification 4, 4.2 to 4.5), whatever the
area’s channel count, without the list’s channel check. To read a disc’s stored
frames, use Disc::stored_frame_list.
§Errors
Error::NoSuchArea if the TOC has no area from that slot.
Sourcepub fn stored_frame_list(
&mut self,
slot: Slot,
) -> Result<AreaFrames<'_, R>, Error>
pub fn stored_frame_list( &mut self, slot: Slot, ) -> Result<AreaFrames<'_, R>, Error>
The stored frame list of the area from slot (specification 4, 4.6.1 item 2):
every accepted frame of the area in frame number order, frames numbered at or past
the play time included, each with its number, kind and bytes as stored. Every audio
sector is processed, with no early stop; positions not in the list are missing.
There are no DST equivalents for the list (4.6.1 item 4: only for tracks and ranges).
These are the frames of Disc::area_frames, offered only for an area whose
channel count is 1 to 6 (4.6.1 item 1).
§Errors
Sourcepub fn stored_frame_list_cursor(&self, slot: Slot) -> Result<AreaCursor, Error>
pub fn stored_frame_list_cursor(&self, slot: Slot) -> Result<AreaCursor, Error>
The reading state of Disc::stored_frame_list, for callers that cannot hold the
borrow; advance it with AreaCursor::next_frame, passing Disc::image_mut.
§Errors
Sourcepub fn area_capacity(&self, slot: Slot) -> Result<AreaCapacity, Error>
pub fn area_capacity(&self, slot: Slot) -> Result<AreaCapacity, Error>
What the TOC of the area from slot claims against the audio sectors this image
holds (specification 4, 4.2 and 4.8): see audio::area_capacity and
AreaCapacity. It reads nothing: the figures come from the TOC and the image
size known since the disc was opened. The consumer chooses the threshold, for
example on AreaCapacity::frames_per_sector.
§Errors
Error::NoSuchArea if the TOC has no area from that slot.
Sourcepub fn check_track(&self, slot: Slot, number: u32) -> Result<(), Error>
pub fn check_track(&self, slot: Slot, number: u32) -> Result<(), Error>
Whether track number of the area from slot produces audio (specification 4,
4.8).
§Errors
The per-track outcomes Error::ChannelCountUnsupported, Error::TrackEmpty
and Error::TrackExceedsCapacity, or Error::NoSuchArea /
Error::NoSuchTrack.
Sourcepub fn track_frames(
&mut self,
slot: Slot,
number: u32,
) -> Result<TrackFrames<'_, R>, Error>
pub fn track_frames( &mut self, slot: Slot, number: u32, ) -> Result<TrackFrames<'_, R>, Error>
The timeline positions of track number (1-based) of the area from slot, each
holding a plain DSD frame, a DST frame or nothing (specification 4, 4.6 and 4.7).
Plain DSD frames are passed through unchanged; see Disc::track_audio for
decoded audio.
§Errors
Sourcepub fn frames_cursor(
&self,
slot: Slot,
span: FrameSpan,
options: CursorOptions<'_>,
) -> Result<TrackCursor, Error>
pub fn frames_cursor( &self, slot: Slot, span: FrameSpan, options: CursorOptions<'_>, ) -> Result<TrackCursor, Error>
The reading state of a track or frame range’s positions (see Disc::track_frames
and Disc::range_frames), from a shared borrow, for callers that cannot hold the
iterator’s; read it with Disc::read_frames. With &mut self,
TrackFrames::into_cursor gives the same. See CursorOptions for the seek index
and policy; by default they are the disc’s for the area.
§Errors
As Disc::check_track or Disc::check_range, then Error::InvalidArgument if
the options’ index is of another area or image size.
Sourcepub fn range_frames(
&mut self,
slot: Slot,
first: u32,
end: u32,
) -> Result<TrackFrames<'_, R>, Error>
pub fn range_frames( &mut self, slot: Slot, first: u32, end: u32, ) -> Result<TrackFrames<'_, R>, Error>
The timeline positions of the frame range [first, end) of the area from slot,
without decoding: for each position, its frame number and the frame as stored (DST
bytes, plain DSD bytes) or nothing, exactly the frames that Disc::range_audio
decodes. The whole area is [0, P) with P the area’s play time.
§Errors
Sourcepub fn continue_track_frames(
&self,
prev: TrackCursor,
slot: Slot,
number: u32,
) -> Result<TrackCursor, Error>
pub fn continue_track_frames( &self, prev: TrackCursor, slot: Slot, number: u32, ) -> Result<TrackCursor, Error>
The reading state of track number’s positions, continuing prev (the state of an
earlier track or range) without rescanning the area when the result is the same,
as Disc::continue_track_audio does for decoded audio.
§Errors
Sourcepub fn continue_range_frames(
&self,
prev: TrackCursor,
slot: Slot,
first: u32,
end: u32,
) -> Result<TrackCursor, Error>
pub fn continue_range_frames( &self, prev: TrackCursor, slot: Slot, first: u32, end: u32, ) -> Result<TrackCursor, Error>
The reading state of the positions of the frame range [first, end), continuing
prev as Disc::continue_range_audio does for decoded audio.
§Errors
Sourcepub fn read_frames(&mut self, cursor: TrackCursor) -> TrackFrames<'_, R> ⓘ
pub fn read_frames(&mut self, cursor: TrackCursor) -> TrackFrames<'_, R> ⓘ
The borrowing iterator over a track (or range) reading state of this disc.
Sourcepub fn track_audio(
&mut self,
slot: Slot,
number: u32,
) -> Result<TrackAudio<'_, R>, Error>
pub fn track_audio( &mut self, slot: Slot, number: u32, ) -> Result<TrackAudio<'_, R>, Error>
The decoded audio of track number (1-based) of the area from slot: every
timeline position as C x 4704 interleaved DSD bytes, DST frames decoded and
missing or invalid frames filled (specification 4, 4.6).
§Errors
Sourcepub fn check_range(&self, slot: Slot, first: u32, end: u32) -> Result<(), Error>
pub fn check_range(&self, slot: Slot, first: u32, end: u32) -> Result<(), Error>
Whether the frame range [first, end) of the area from slot produces audio: it
must lie in the area’s play range, first <= end <= P with P the area’s play
time (crate::Area::playtime_frames), and pass the checks of specification 4,
4.8 as a track would (4.7.1; see audio::check_range).
§Errors
Error::ChannelCountUnsupported, Error::FrameRangeInvalid,
Error::TrackEmpty and Error::TrackExceedsCapacity, or Error::NoSuchArea.
Sourcepub fn range_audio(
&mut self,
slot: Slot,
first: u32,
end: u32,
) -> Result<TrackAudio<'_, R>, Error>
pub fn range_audio( &mut self, slot: Slot, first: u32, end: u32, ) -> Result<TrackAudio<'_, R>, Error>
The decoded audio of the frame range [first, end) of the area from slot: every
timeline position from first to end - 1, exactly as Disc::track_audio gives
a track’s. The whole area, pauses included, is [0, P) with P the area’s play
time. For a track with pause (specification 4, 4.7.1 item 5: track 1 from frame 0,
every other track from its own start; every track to the larger of its own end and
the next-numbered track’s start, the last to the play time; used as they are when
tracks overlap or are out of order), use the range from
Disc::track_range_with_pause.
§Errors
Sourcepub fn audio_cursor(
&self,
slot: Slot,
span: FrameSpan,
options: CursorOptions<'_>,
) -> Result<TrackAudioCursor, Error>
pub fn audio_cursor( &self, slot: Slot, span: FrameSpan, options: CursorOptions<'_>, ) -> Result<TrackAudioCursor, Error>
The decoding state of a track or frame range (see Disc::track_audio and
Disc::range_audio), from a shared borrow, for callers that cannot hold the
iterator’s (for example across an FFI boundary); read it with
Disc::read_track_audio, or advance it with TrackAudioCursor::next_frame,
passing this disc’s Disc::image_mut. With &mut self,
TrackAudio::into_cursor gives the same. See CursorOptions for the seek index
and policy; by default they are the disc’s for the area.
§Errors
Sourcepub fn continue_range_audio(
&self,
prev: TrackAudioCursor,
slot: Slot,
first: u32,
end: u32,
) -> Result<TrackAudioCursor, Error>
pub fn continue_range_audio( &self, prev: TrackAudioCursor, slot: Slot, first: u32, end: u32, ) -> Result<TrackAudioCursor, Error>
The decoding state of the frame range [first, end) of the area from slot,
continuing prev (a cursor of an earlier track or range) without rescanning the
area when the result is the same, as Disc::continue_track_audio does for
tracks. A range that fails Disc::check_range consumes prev without reuse.
§Errors
Sourcepub fn continue_track_audio(
&self,
prev: TrackAudioCursor,
slot: Slot,
number: u32,
) -> Result<TrackAudioCursor, Error>
pub fn continue_track_audio( &self, prev: TrackAudioCursor, slot: Slot, number: u32, ) -> Result<TrackAudioCursor, Error>
The decoding state of track number of the area from slot, continuing prev
(a cursor of an earlier track) without rescanning the area when the result is
the same. Reading an area’s tracks in increasing order this way reads each audio
sector once. The state is reused when the track is in the same area of the same
image and starts at or after the cursor’s position, and no read has failed; the
frames are always exactly those of a fresh scan (specification 4, 4.2 item 5). Frames
of prev not yet returned are dropped, and the counts start again at 0. A track that
fails Disc::check_track consumes prev without reuse, so check first to keep it.
use scarletbook::{CursorOptions, FrameSpan, Slot};
let count = disc.toc().area(Slot::TwoChannel).map_or(0, |a| a.tracks.len()) as u32;
let mut cursor = None;
for n in 1..=count {
if disc.check_track(Slot::TwoChannel, n).is_err() {
continue; // a track without audio; keep the cursor for the next one
}
let next = match cursor.take() {
Some(prev) => disc.continue_track_audio(prev, Slot::TwoChannel, n)?,
None => disc.audio_cursor(Slot::TwoChannel, FrameSpan::Track(n), CursorOptions::new())?,
};
let mut audio = disc.read_track_audio(next);
for frame in audio.by_ref() {
let _frame = frame?;
}
cursor = Some(audio.into_cursor());
}§Errors
Sourcepub fn track_continuation(
&self,
slot: Slot,
number: u32,
) -> Result<Continuation<'_>, Error>
pub fn track_continuation( &self, slot: Slot, number: u32, ) -> Result<Continuation<'_>, Error>
Track number of the area from slot, checked (Disc::check_track), for a
cursor to continue into without failing: Continuation::audio does what
Disc::continue_track_audio does once the checks have passed. A caller that must
not give up prev unless the continuation succeeds checks first, then hands it
over.
§Errors
Sourcepub fn range_continuation(
&self,
slot: Slot,
first: u32,
end: u32,
) -> Result<Continuation<'_>, Error>
pub fn range_continuation( &self, slot: Slot, first: u32, end: u32, ) -> Result<Continuation<'_>, Error>
The frame range [first, end) of the area from slot, checked
(Disc::check_range), for a cursor to continue into without failing (see
Disc::track_continuation).
§Errors
Sourcepub fn track_range_with_pause(
&self,
slot: Slot,
number: u32,
) -> Result<(u32, u32), Error>
pub fn track_range_with_pause( &self, slot: Slot, number: u32, ) -> Result<(u32, u32), Error>
Track number’s track with pause (specification 4, 4.7.1 item 5): see
audio::track_range_with_pause.
Pass it to Disc::range_audio.
§Errors
Sourcepub fn read_track_audio(
&mut self,
cursor: TrackAudioCursor,
) -> TrackAudio<'_, R> ⓘ
pub fn read_track_audio( &mut self, cursor: TrackAudioCursor, ) -> TrackAudio<'_, R> ⓘ
The borrowing iterator over a track (or range) decoding state of this disc.
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Consumes the disc and returns the reader.
Source§impl<R: Read + Seek> Disc<R>
impl<R: Read + Seek> Disc<R>
Sourcepub fn output_layout(
&self,
slot: Slot,
first: u32,
end: u32,
format: Format,
options: &OutputOptions,
) -> Result<Layout, Error>
pub fn output_layout( &self, slot: Slot, first: u32, end: u32, format: Format, options: &OutputOptions, ) -> Result<Layout, Error>
The Layout of the frame range [first, end) of the area from slot as a
format file (specification 8). A track’s range is
(start_frame, start_frame + duration_frames); a track with pause’s is
Disc::track_range_with_pause’s.
§Errors
Error::NoSuchArea, then those of Layout::new.
Sourcepub fn plan_dsf_chain(
&self,
slot: Slot,
bounds: &[u32],
) -> Result<Vec<Result<DsfChainFile, Error>>, Error>
pub fn plan_dsf_chain( &self, slot: Slot, bounds: &[u32], ) -> Result<Vec<Result<DsfChainFile, Error>>, Error>
The DSF files of a chain of ranges of the area from slot (specification 8, 8.2.7;
see plan_dsf_chain), with bounds a_1, ..., a_K, b_K. Each file’s layout is
Disc::output_layout of its range with OutputOptions::with_dsf_chain.
§Errors
Those of plan_dsf_chain.
Sourcepub fn output_layout_dst(
&self,
lengths: &DstLengths,
options: &OutputOptions,
) -> Result<Layout, Error>
pub fn output_layout_dst( &self, lengths: &DstLengths, options: &OutputOptions, ) -> Result<Layout, Error>
The Format::DsdiffDst Layout of the range of lengths of their area (see
Layout::new_dst).
§Errors
Error::NoSuchArea, then those of Layout::new_dst.
Trait Implementations§
Source§impl<A: ReadAt + Clone> Clone for Disc<ReadAtReader<A>>
A disc of the same image through another reader of the same source (see Several
readers): no I/O and no check, the source being the same.
impl<A: ReadAt + Clone> Clone for Disc<ReadAtReader<A>>
A disc of the same image through another reader of the same source (see Several readers): no I/O and no check, the source being the same.
Auto Trait Implementations§
impl<R> !RefUnwindSafe for Disc<R>
impl<R> !UnwindSafe for Disc<R>
impl<R> Forget for Disc<R>
impl<R> Freeze for Disc<R>
impl<R> Move for Disc<R>
impl<R> Send for Disc<R>
impl<R> Sync for Disc<R>
impl<R> Unpin for Disc<R>
impl<R> UnsafeUnpin for Disc<R>where
Image<R>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more