Skip to content

Commit

Permalink
EBML: Add properties test
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Oct 13, 2024
1 parent f402773 commit 7a55951
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lofty/src/ebml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use lofty_attr::LoftyFile;

// Exports

pub use properties::EbmlProperties;
pub use properties::*;
pub use tag::*;
pub use vint::*;

Expand Down
9 changes: 9 additions & 0 deletions lofty/src/ebml/properties.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::properties::FileProperties;

/// Properties from the EBML header
///
/// These are present for all EBML formats.
#[derive(Debug, Clone, PartialEq, Default)]
pub struct EbmlHeaderProperties {
pub(crate) version: u64,
Expand Down Expand Up @@ -48,6 +51,7 @@ impl EbmlHeaderProperties {
}
}

/// An EBML DocType extension
#[derive(Debug, Clone, PartialEq, Default)]
pub struct EbmlExtension {
pub(crate) name: String,
Expand All @@ -66,6 +70,7 @@ impl EbmlExtension {
}
}

/// Information about a segment
#[derive(Debug, Clone, PartialEq)]
pub struct SegmentInfo {
pub(crate) timestamp_scale: u64,
Expand Down Expand Up @@ -107,6 +112,7 @@ impl Default for SegmentInfo {
}
}

/// A full descriptor for an audio track
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AudioTrackDescriptor {
pub(crate) number: u64,
Expand Down Expand Up @@ -161,6 +167,7 @@ impl AudioTrackDescriptor {
}
}

/// Settings for an audio track
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AudioTrackSettings {
pub(crate) sampling_frequency: u32,
Expand Down Expand Up @@ -199,6 +206,8 @@ impl AudioTrackSettings {
}
}

/// A rarely-used decoder hint that the file must be de-emphasized
#[allow(missing_docs)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum EbmlAudioTrackEmphasis {
None = 0,
Expand Down
48 changes: 48 additions & 0 deletions lofty/src/properties/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::aac::{AACProperties, AacFile};
use crate::ape::{ApeFile, ApeProperties};
use crate::config::ParseOptions;
use crate::ebml::{
AudioTrackDescriptor, AudioTrackSettings, EbmlFile, EbmlHeaderProperties, EbmlProperties,
SegmentInfo,
};
use crate::file::AudioFile;
use crate::flac::{FlacFile, FlacProperties};
use crate::iff::aiff::{AiffFile, AiffProperties};
Expand Down Expand Up @@ -67,6 +71,42 @@ const FLAC_PROPERTIES: FlacProperties = FlacProperties {
signature: 164_506_065_180_489_231_127_156_351_872_182_799_315,
};

#[allow(non_snake_case)]
fn MKA_PROPERTIES() -> EbmlProperties {
EbmlProperties {
header: EbmlHeaderProperties {
version: 1,
read_version: 1,
max_id_length: 4,
max_size_length: 8,
doc_type: String::from("matroska"),
doc_type_version: 4,
doc_type_read_version: 0,
},
extensions: Vec::new(),
segment_info: SegmentInfo {
timestamp_scale: 1000000,
muxing_app: String::from("Lavf60.3.100"),
writing_app: String::from("Lavf60.3.100"),
},
audio_tracks: vec![AudioTrackDescriptor {
number: 0,
uid: 0,
language: String::new(),
default_duration: 0,
codec_id: String::new(),
codec_private: vec![],
settings: AudioTrackSettings {
sampling_frequency: 0,
output_sampling_frequency: 0,
channels: 0,
bit_depth: None,
emphasis: None,
},
}],
}
}

const MP1_PROPERTIES: MpegProperties = MpegProperties {
version: MpegVersion::V1,
layer: Layer::Layer1,
Expand Down Expand Up @@ -325,6 +365,14 @@ fn flac_properties() {
)
}

#[test_log::test]
fn mka_properties() {
assert_eq!(
get_properties::<EbmlFile>("tests/files/assets/minimal/full_test.mka"),
MKA_PROPERTIES()
);
}

#[test_log::test]
fn mp1_properties() {
assert_eq!(
Expand Down

0 comments on commit 7a55951

Please sign in to comment.