diff --git a/src/common/ebml.cpp b/src/common/ebml.cpp index 49317e650..cc022a130 100644 --- a/src/common/ebml.cpp +++ b/src/common/ebml.cpp @@ -647,6 +647,34 @@ remove_ietf_language_elements(libebml::EbmlMaster &master) { } } +void +remove_mandatory_elements_set_to_their_default(libebml::EbmlMaster &master) { + auto idx = 0u; + + while (idx < master.ListSize()) { + auto child = master[idx]; + + if (dynamic_cast(child)) { + remove_mandatory_elements_set_to_their_default(*static_cast(child)); + ++idx; + continue; + } + + if (!child->IsDefaultValue()) { + ++idx; + continue; + } + + auto semantic = find_ebml_semantic(KaxSegment::ClassInfos, libebml::EbmlId(*child)); + + if (!semantic || !semantic->IsMandatory()) + ++idx; + else { + delete child; + master.Remove(idx); + } + } +} static bool must_be_present_in_master_by_id(EbmlId const &id) { diff --git a/src/common/ebml.h b/src/common/ebml.h index 39c20a9b2..86f5d2a72 100644 --- a/src/common/ebml.h +++ b/src/common/ebml.h @@ -410,6 +410,7 @@ void remove_voids_from_master(libebml::EbmlElement *element); void move_children(libebml::EbmlMaster &source, libebml::EbmlMaster &destination); bool remove_master_from_parent_if_empty_or_only_defaults(libebml::EbmlMaster *parent, libebml::EbmlMaster *child, std::unordered_map &handled); void remove_ietf_language_elements(libebml::EbmlMaster &master); +void remove_mandatory_elements_set_to_their_default(libebml::EbmlMaster &master); const libebml::EbmlCallbacks *find_ebml_callbacks(const libebml::EbmlCallbacks &base, const libebml::EbmlId &id); const libebml::EbmlCallbacks *find_ebml_callbacks(const libebml::EbmlCallbacks &base, const char *debug_name);