From f8f9aff03ee174f19329e264fb9fbd9ba9ff0ea9 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Wed, 26 Apr 2023 20:52:31 +0200 Subject: [PATCH 1/4] Improve log msg for deprecated Elements --- Cargo.toml | 1 + src/ebml/mod.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++++ src/ebml/parse.rs | 4 ++-- src/permutation.rs | 11 ++++++++--- 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 97d08b5..aef8eba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ circular = "0.3" log = "0.4" crc = "3.0.1" uuid = "1.3.0" +phf = { version = "0.11.1", features = ["macros"] } [dev-dependencies] quickcheck = "1" diff --git a/src/ebml/mod.rs b/src/ebml/mod.rs index 8d1b26b..a1c9db6 100644 --- a/src/ebml/mod.rs +++ b/src/ebml/mod.rs @@ -25,3 +25,50 @@ self::macros::impl_ebml_master! { pub fn ebml_header(input: &[u8]) -> EbmlResult { ebml_element(0x1A45DFA3)(input) } + +/// Map of known deprecated Element IDs and their EBML Paths +pub static DEPRECATED: phf::Map = phf::phf_map! { + 0x8E_u32 => r"\Segment\Cluster\BlockGroup\Slices", + 0x97_u32 => r"\Segment\Cues\CuePoint\CueTrackPositions\CueReference\CueRefCluster", + 0xA2_u32 => r"\Segment\Cluster\BlockGroup\BlockVirtual", + 0xAA_u32 => r"\Segment\Tracks\TrackEntry\CodecDecodeAll", + 0xAF_u32 => r"\Segment\Cluster\EncryptedBlock", + 0xC0_u32 => r"\Segment\Tracks\TrackEntry\TrickTrackUID", + 0xC1_u32 => r"\Segment\Tracks\TrackEntry\TrickTrackSegmentUID", + 0xC4_u32 => r"\Segment\Tracks\TrackEntry\TrickMasterTrackSegmentUID", + 0xC6_u32 => r"\Segment\Tracks\TrackEntry\TrickTrackFlag", + 0xC7_u32 => r"\Segment\Tracks\TrackEntry\TrickMasterTrackUID", + 0xC8_u32 => r"\Segment\Cluster\BlockGroup\ReferenceFrame", + 0xC9_u32 => r"\Segment\Cluster\BlockGroup\ReferenceFrame\ReferenceOffset", + 0xCA_u32 => r"\Segment\Cluster\BlockGroup\ReferenceFrame\ReferenceTimestamp", + 0xCB_u32 => r"\Segment\Cluster\BlockGroup\Slices\TimeSlice\BlockAdditionID", + 0xCC_u32 => r"\Segment\Cluster\BlockGroup\Slices\TimeSlice\LaceNumber", + 0xCD_u32 => r"\Segment\Cluster\BlockGroup\Slices\TimeSlice\FrameNumber", + 0xCE_u32 => r"\Segment\Cluster\BlockGroup\Slices\TimeSlice\Delay", + 0xCF_u32 => r"\Segment\Cluster\BlockGroup\Slices\TimeSlice\SliceDuration", + 0xE8_u32 => r"\Segment\Cluster\BlockGroup\Slices\TimeSlice", + 0xEB_u32 => r"\Segment\Cues\CuePoint\CueTrackPositions\CueReference\CueRefCodecState", + 0xFD_u32 => r"\Segment\Cluster\BlockGroup\ReferenceVirtual", + 0x44B4_u32 => r"\Segment\Tags\Tag\+SimpleTag\TagDefaultBogus", + 0x4661_u32 => r"\Segment\Attachments\AttachedFile\FileUsedStartTime", + 0x4662_u32 => r"\Segment\Attachments\AttachedFile\FileUsedEndTime", + 0x4675_u32 => r"\Segment\Attachments\AttachedFile\FileReferral", + 0x47E3_u32 => r"\Segment\Tracks\TrackEntry\ContentEncodings\ContentEncoding\ContentEncryption\ContentSignature", + 0x47E4_u32 => r"\Segment\Tracks\TrackEntry\ContentEncodings\ContentEncoding\ContentEncryption\ContentSigKeyID", + 0x47E5_u32 => r"\Segment\Tracks\TrackEntry\ContentEncodings\ContentEncoding\ContentEncryption\ContentSigAlgo", + 0x47E6_u32 => r"\Segment\Tracks\TrackEntry\ContentEncodings\ContentEncoding\ContentEncryption\ContentSigHashAlgo", + 0x535F_u32 => r"\Segment\Cues\CuePoint\CueTrackPositions\CueReference\CueRefNumber", + 0x537F_u32 => r"\Segment\Tracks\TrackEntry\TrackOffset", + 0x54B3_u32 => r"\Segment\Tracks\TrackEntry\Video\AspectRatioType", + 0x5854_u32 => r"\Segment\Cluster\SilentTracks", + 0x58D7_u32 => r"\Segment\Cluster\SilentTracks\SilentTrackNumber", + 0x6DE7_u32 => r"\Segment\Tracks\TrackEntry\MinCache", + 0x6DF8_u32 => r"\Segment\Tracks\TrackEntry\MaxCache", + 0x6FAB_u32 => r"\Segment\Tracks\TrackEntry\TrackOverlay", + 0x7D7B_u32 => r"\Segment\Tracks\TrackEntry\Audio\ChannelPositions", + 0x2383E3_u32 => r"\Segment\Tracks\TrackEntry\Video\FrameRate", + 0x26B240_u32 => r"\Segment\Tracks\TrackEntry\CodecDownloadURL", + 0x2FB523_u32 => r"\Segment\Tracks\TrackEntry\Video\GammaValue", + 0x3A9697_u32 => r"\Segment\Tracks\TrackEntry\CodecSettings", + 0x3B4040_u32 => r"\Segment\Tracks\TrackEntry\CodecInfoURL", +}; diff --git a/src/ebml/parse.rs b/src/ebml/parse.rs index 3bb8737..81152e7 100644 --- a/src/ebml/parse.rs +++ b/src/ebml/parse.rs @@ -152,8 +152,8 @@ pub fn void(input: &[u8]) -> EbmlResult<&[u8]> { ebml_element(0xEC)(input) } -/// Consumes an entire Master Element, and returns the ID if successful. -pub fn skip_master(input: &[u8]) -> EbmlResult { +/// Consumes an entire EBML Element, and returns the ID if successful. +pub fn skip_element(input: &[u8]) -> EbmlResult { let (i, (id, size, crc)) = tuple((vid, elem_size, crc))(input)?; let size = if crc.is_some() { size - 6 } else { size }; checksum(crc, take(size))(i)?; diff --git a/src/permutation.rs b/src/permutation.rs index 0b1f56b..53fdac8 100644 --- a/src/permutation.rs +++ b/src/permutation.rs @@ -116,9 +116,14 @@ macro_rules! permutation_trait_impl( // Have all parsers (including void) failed? if l == input.len() { // Skip unknown Element if possible. - if let Error { id: _, kind: crate::ebml::ErrorKind::MissingElement } = err { - if let Ok((i, id)) = crate::ebml::skip_master(input) { - log::warn!("Skipped unknown Element 0x{id:X}"); + if let Error { id: _, kind: $crate::ebml::ErrorKind::MissingElement } = err { + if let Ok((i, id)) = $crate::ebml::skip_element(input) { + if let Some(name) = $crate::ebml::DEPRECATED.get(&id) { + log::warn!("Skipped deprecated Element '{name}' ({id:#0X})"); + } else { + log::warn!("Skipped unknown Element {id:#0X}"); + } + input = i; continue; } From b0c4ea2a34aa84a8582a60217238546726736b85 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Wed, 26 Apr 2023 21:30:15 +0200 Subject: [PATCH 2/4] Remove deprecated Matroska Elements --- src/demuxer.rs | 38 +------------------- src/elements.rs | 35 ------------------ src/muxer.rs | 4 --- src/serializer/elements.rs | 72 ++++---------------------------------- tools/src/matroska_info.rs | 8 ----- 5 files changed, 8 insertions(+), 149 deletions(-) diff --git a/src/demuxer.rs b/src/demuxer.rs index 32b6901..36df403 100644 --- a/src/demuxer.rs +++ b/src/demuxer.rs @@ -210,15 +210,9 @@ fn track_entry_audio_kind(audio: &Audio) -> Option { let rate = audio .output_sampling_frequency .unwrap_or(audio.sampling_frequency); - // TODO: complete it - let map = if audio.channel_positions.is_none() { - Some(ChannelMap::default_map(audio.channels as usize)) - } else { - unimplemented!("Convert matroska map to rust-av map") - }; let a = AudioInfo { rate: rate as usize, - map, + map: Some(ChannelMap::default_map(audio.channels as usize)), format: None, }; Some(MediaKind::Audio(a)) @@ -406,12 +400,9 @@ mod tests { flag_default: 1, flag_forced: 0, flag_lacing: 0, - min_cache: None, - max_cache: None, default_duration: None, default_decoded_field_duration: None, track_timestamp_scale: 1.0, - track_offset: None, max_block_addition_id: 0, name: None, language: String::from("eng"), @@ -420,18 +411,8 @@ mod tests { codec_private: None, codec_name: None, attachment_link: None, - codec_settings: None, - codec_info_url: None, - codec_download_url: None, - codec_decode_all: None, - track_overlay: None, codec_delay: 0, seek_pre_roll: 0, - trick_track_uid: None, - trick_track_segment_uid: None, - trick_track_flag: None, - trick_master_track_uid: None, - trick_master_track_segment_uid: None, video: Some(Video { flag_interlaced: 0, field_order: 2, @@ -447,10 +428,7 @@ mod tests { display_width: Some(640), display_height: Some(360), display_unit: 3, - aspect_ratio_type: None, colour_space: None, - gamma_value: None, - frame_rate: None, colour: None, projection: None }), @@ -468,12 +446,9 @@ mod tests { flag_default: 1, flag_forced: 0, flag_lacing: 0, - min_cache: None, - max_cache: None, default_duration: None, default_decoded_field_duration: None, track_timestamp_scale: 1.0, - track_offset: None, max_block_addition_id: 0, name: None, language: String::from("eng"), @@ -485,24 +460,13 @@ mod tests { ]), codec_name: None, attachment_link: None, - codec_settings: None, - codec_info_url: None, - codec_download_url: None, - codec_decode_all: None, - track_overlay: None, codec_delay: 6500000, seek_pre_roll: 0, - trick_track_uid: None, - trick_track_segment_uid: None, - trick_track_flag: None, - trick_master_track_uid: None, - trick_master_track_segment_uid: None, video: None, audio: Some(Audio { sampling_frequency: 48000.0, output_sampling_frequency: None, channels: 1, - channel_positions: None, bit_depth: Some(32), }), track_translate: vec![], diff --git a/src/elements.rs b/src/elements.rs index a74336d..af1cb44 100644 --- a/src/elements.rs +++ b/src/elements.rs @@ -120,20 +120,10 @@ impl_ebml_master! { #[derive(Debug, Clone, PartialEq)] struct Cluster<'a> { [0xE7] timestamp: (u64), - [0x5854] silent_tracks: (Option), [0xA7] position: (Option), [0xAB] prev_size: (Option), [0xA3] simple_block: (Vec<&'a [u8]>) [0..], [0xA0] block_group: (Vec>) [0..], - [0xAF] encrypted_block: (Option<&'a [u8]>), - } -} - -impl_ebml_master! { - // Element ID 0x5854 - #[derive(Debug, Clone, PartialEq, Eq)] - struct SilentTracks { - [0x58D7] numbers: (Vec) [0..], } } @@ -142,16 +132,12 @@ impl_ebml_master! { #[derive(Debug, Clone, PartialEq, Eq)] struct BlockGroup<'a> { [0xA1] block: (&'a [u8]), - [0xA2] block_virtual: (Option>), // [0x75A1] block_additions: (Option), [0x9B] block_duration: (Option), [0xFA] reference_priority: (u64) = 0, [0xFB] reference_block: (Option), - [0xFD] reference_virtual: (Option), [0xA4] codec_state: (Option>), [0x75A2] discard_padding: (Option), - // [0x8E] slices: (Option), - // [0xC8] reference_frame: (Option), } } @@ -300,13 +286,10 @@ impl_ebml_master! { [0x88] flag_default: (u64) = 1, [0x55AA] flag_forced: (u64) = 0, [0x9C] flag_lacing: (u64) = 1, - [0x6DE7] min_cache: (Option), - [0x6DF8] max_cache: (Option), [0x23E383] default_duration: (Option), [0x234E7A] default_decoded_field_duration: (Option), // FIXME: reimplement float_or handling [0x23314F] track_timestamp_scale: (f64) = 1.0, - [0x537F] track_offset: (Option), [0x55EE] max_block_addition_id: (u64) = 0, [0x536E] name: (Option), [0x22B59C] language: (String) = String::from("eng"), @@ -315,18 +298,8 @@ impl_ebml_master! { [0x63A2] codec_private: (Option>), [0x258688] codec_name: (Option), [0x7446] attachment_link: (Option), - [0x3A9697] codec_settings: (Option), - [0x3B4040] codec_info_url: (Option), - [0x26B240] codec_download_url: (Option), - [0xAA] codec_decode_all: (Option), - [0x6FAB] track_overlay: (Option), [0x56AA] codec_delay: (u64) = 0, [0x56BB] seek_pre_roll: (u64) = 0, - [0xC0] trick_track_uid: (Option), - [0xC1] trick_track_segment_uid: (Option), - [0xC6] trick_track_flag: (Option), - [0xC7] trick_master_track_uid: (Option), - [0xC4] trick_master_track_segment_uid: (Option), [0xE0] video: (Option