mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-13 14:12:31 +00:00
EBML: Retain all audio tracks
This commit is contained in:
parent
9233d4a063
commit
16bb3c0959
1 changed files with 35 additions and 9 deletions
|
@ -66,7 +66,7 @@ impl EbmlExtension {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct SegmentInfo {
|
||||
pub(crate) timestamp_scale: u64,
|
||||
pub(crate) muxing_app: String,
|
||||
|
@ -96,6 +96,17 @@ impl SegmentInfo {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for SegmentInfo {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
// https://matroska.org/technical/elements.html
|
||||
timestamp_scale: 1_000_000,
|
||||
muxing_app: String::new(),
|
||||
writing_app: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct AudioTrackDescriptor {
|
||||
pub(crate) number: u64,
|
||||
|
@ -211,7 +222,7 @@ pub struct EbmlProperties {
|
|||
pub(crate) header: EbmlHeaderProperties,
|
||||
pub(crate) extensions: Vec<EbmlExtension>,
|
||||
pub(crate) segment_info: SegmentInfo,
|
||||
pub(crate) default_audio_track: AudioTrackDescriptor,
|
||||
pub(crate) audio_tracks: Vec<AudioTrackDescriptor>,
|
||||
}
|
||||
|
||||
impl EbmlProperties {
|
||||
|
@ -228,29 +239,44 @@ impl EbmlProperties {
|
|||
&self.extensions
|
||||
}
|
||||
|
||||
/// Information from the Matroska `\EBML\Segment\Info` element
|
||||
/// Information from the `\EBML\Segment\Info` element
|
||||
pub fn segment_info(&self) -> &SegmentInfo {
|
||||
&self.segment_info
|
||||
}
|
||||
|
||||
/// All audio tracks in the file
|
||||
///
|
||||
/// This includes all audio tracks in the Matroska `\EBML\Segment\Tracks` element.
|
||||
///
|
||||
/// NOTE: The first audio track is **always** the default audio track.
|
||||
pub fn audio_tracks(&self) -> &[AudioTrackDescriptor] {
|
||||
&self.audio_tracks
|
||||
}
|
||||
|
||||
/// Information about the default audio track
|
||||
///
|
||||
/// The information is extracted from the first audio track with its default flag set
|
||||
/// in the Matroska `\EBML\Segment\Tracks` element.
|
||||
pub fn default_audio_track(&self) -> &AudioTrackDescriptor {
|
||||
&self.default_audio_track
|
||||
/// in the `\EBML\Segment\Tracks` element.
|
||||
///
|
||||
/// NOTE: This will always return `Some` unless [`ParseOptions::read_properties`](crate::config::ParseOptions::read_properties) is set to `false`.
|
||||
pub fn default_audio_track(&self) -> Option<&AudioTrackDescriptor> {
|
||||
self.audio_tracks.first()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EbmlProperties> for FileProperties {
|
||||
fn from(input: EbmlProperties) -> Self {
|
||||
let Some(default_audio_track) = input.default_audio_track() else {
|
||||
return FileProperties::default();
|
||||
};
|
||||
|
||||
Self {
|
||||
duration: todo!("Support duration"),
|
||||
overall_bitrate: todo!("Support bitrate"),
|
||||
audio_bitrate: todo!("Support bitrate"),
|
||||
sample_rate: Some(input.default_audio_track.settings.sampling_frequency),
|
||||
bit_depth: input.default_audio_track.settings.bit_depth,
|
||||
channels: Some(input.default_audio_track.settings.channels),
|
||||
sample_rate: Some(default_audio_track.settings.sampling_frequency),
|
||||
bit_depth: default_audio_track.settings.bit_depth,
|
||||
channels: Some(default_audio_track.settings.channels),
|
||||
channel_mask: todo!("Channel mask"),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue