EBML: Add properties test

This commit is contained in:
Serial 2024-10-12 23:40:04 -04:00
parent 27f3ff5fe2
commit 84f93ad1fd
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
3 changed files with 58 additions and 1 deletions

View file

@ -9,7 +9,7 @@ use lofty_attr::LoftyFile;
// Exports
pub use properties::EbmlProperties;
pub use properties::*;
pub use tag::*;
pub use vint::*;

View file

@ -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,
@ -48,6 +51,7 @@ impl EbmlHeaderProperties {
}
}
/// An EBML DocType extension
#[derive(Debug, Clone, PartialEq, Default)]
pub struct EbmlExtension {
pub(crate) name: String,
@ -66,6 +70,7 @@ impl EbmlExtension {
}
}
/// Information about a segment
#[derive(Debug, Clone, PartialEq)]
pub struct SegmentInfo {
pub(crate) timestamp_scale: u64,
@ -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,
@ -161,6 +167,7 @@ impl AudioTrackDescriptor {
}
}
/// Settings for an audio track
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AudioTrackSettings {
pub(crate) sampling_frequency: u32,
@ -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,

View file

@ -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};
@ -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,
@ -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!(