mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-14 06:32:33 +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 struct SegmentInfo {
|
||||||
pub(crate) timestamp_scale: u64,
|
pub(crate) timestamp_scale: u64,
|
||||||
pub(crate) muxing_app: String,
|
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)]
|
#[derive(Debug, Clone, PartialEq, Default)]
|
||||||
pub struct AudioTrackDescriptor {
|
pub struct AudioTrackDescriptor {
|
||||||
pub(crate) number: u64,
|
pub(crate) number: u64,
|
||||||
|
@ -211,7 +222,7 @@ pub struct EbmlProperties {
|
||||||
pub(crate) header: EbmlHeaderProperties,
|
pub(crate) header: EbmlHeaderProperties,
|
||||||
pub(crate) extensions: Vec<EbmlExtension>,
|
pub(crate) extensions: Vec<EbmlExtension>,
|
||||||
pub(crate) segment_info: SegmentInfo,
|
pub(crate) segment_info: SegmentInfo,
|
||||||
pub(crate) default_audio_track: AudioTrackDescriptor,
|
pub(crate) audio_tracks: Vec<AudioTrackDescriptor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EbmlProperties {
|
impl EbmlProperties {
|
||||||
|
@ -228,29 +239,44 @@ impl EbmlProperties {
|
||||||
&self.extensions
|
&self.extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information from the Matroska `\EBML\Segment\Info` element
|
/// Information from the `\EBML\Segment\Info` element
|
||||||
pub fn segment_info(&self) -> &SegmentInfo {
|
pub fn segment_info(&self) -> &SegmentInfo {
|
||||||
&self.segment_info
|
&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
|
/// Information about the default audio track
|
||||||
///
|
///
|
||||||
/// The information is extracted from the first audio track with its default flag set
|
/// The information is extracted from the first audio track with its default flag set
|
||||||
/// in the Matroska `\EBML\Segment\Tracks` element.
|
/// in the `\EBML\Segment\Tracks` element.
|
||||||
pub fn default_audio_track(&self) -> &AudioTrackDescriptor {
|
///
|
||||||
&self.default_audio_track
|
/// 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 {
|
impl From<EbmlProperties> for FileProperties {
|
||||||
fn from(input: EbmlProperties) -> Self {
|
fn from(input: EbmlProperties) -> Self {
|
||||||
|
let Some(default_audio_track) = input.default_audio_track() else {
|
||||||
|
return FileProperties::default();
|
||||||
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
duration: todo!("Support duration"),
|
duration: todo!("Support duration"),
|
||||||
overall_bitrate: todo!("Support bitrate"),
|
overall_bitrate: todo!("Support bitrate"),
|
||||||
audio_bitrate: todo!("Support bitrate"),
|
audio_bitrate: todo!("Support bitrate"),
|
||||||
sample_rate: Some(input.default_audio_track.settings.sampling_frequency),
|
sample_rate: Some(default_audio_track.settings.sampling_frequency),
|
||||||
bit_depth: input.default_audio_track.settings.bit_depth,
|
bit_depth: default_audio_track.settings.bit_depth,
|
||||||
channels: Some(input.default_audio_track.settings.channels),
|
channels: Some(default_audio_track.settings.channels),
|
||||||
channel_mask: todo!("Channel mask"),
|
channel_mask: todo!("Channel mask"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue