diff --git a/src/common/kax_analyzer.cpp b/src/common/kax_analyzer.cpp index 0e3eb83d8..cc8fc396d 100644 --- a/src/common/kax_analyzer.cpp +++ b/src/common/kax_analyzer.cpp @@ -15,7 +15,6 @@ #include -#include #include #include #include @@ -280,13 +279,20 @@ kax_analyzer_c::process_internal() { m_stream = new EbmlStream(*m_file); // Find the EbmlHead element. Must be the first one. - EbmlElement *l0 = m_stream->FindNextID(EBML_INFO(EbmlHead), 0xFFFFFFFFL); - if (!l0) + m_ebml_head.reset(static_cast(m_stream->FindNextID(EBML_INFO(EbmlHead), 0xFFFFFFFFL))); + if (!m_ebml_head) throw mtx::kax_analyzer_x(Y("Not a valid Matroska file (no EBML head found)")); - // Don't verify its data for now. - l0->SkipData(*m_stream, EBML_CONTEXT(l0)); - delete l0; + EbmlElement *l0{}; + int upper_lvl_el{}; + + m_ebml_head->Read(*m_stream, EBML_CONTEXT(m_ebml_head.get()), upper_lvl_el, l0, true, SCOPE_ALL_DATA); + m_ebml_head->SkipData(*m_stream, EBML_CONTEXT(m_ebml_head.get())); + + if (l0) { + delete l0; + l0 = nullptr; + } while (1) { // Next element must be a segment @@ -302,12 +308,12 @@ kax_analyzer_c::process_internal() { } m_segment = std::shared_ptr(static_cast(l0)); - int upper_lvl_el = 0; bool aborted = false; bool cluster_found = false; bool meta_seek_found = false; m_segment_end = m_segment->IsFiniteSize() ? m_segment->GetElementPosition() + m_segment->HeadSize() + m_segment->GetSize() : m_file->get_size(); EbmlElement *l1 = nullptr; + upper_lvl_el = 0; // In certain situations the caller doesn't way to have to pay the // price for full analysis. Then it can configure the parser to @@ -1431,6 +1437,11 @@ kax_analyzer_c::get_placement_strategy_for(EbmlElement *e) { return Is(e) ? ps_end : ps_anywhere; } +EbmlHead & +kax_analyzer_c::get_ebml_head() { + return *m_ebml_head; +} + uint64_t kax_analyzer_c::get_segment_pos() const { diff --git a/src/common/kax_analyzer.h b/src/common/kax_analyzer.h index 07f9c341a..66e9b9bd0 100644 --- a/src/common/kax_analyzer.h +++ b/src/common/kax_analyzer.h @@ -16,6 +16,7 @@ #include "common/common_pch.h" +#include #include #include "common/ebml.h" @@ -101,6 +102,7 @@ private: mm_io_c *m_file{}; bool m_close_file{true}; std::shared_ptr m_segment; + std::shared_ptr m_ebml_head; uint64_t m_segment_end{}; std::map m_meta_seeks_by_position; EbmlStream *m_stream{}; @@ -131,6 +133,8 @@ public: virtual void with_elements(const EbmlId &id, std::function worker) const; virtual int find(EbmlId const &id); + virtual EbmlHead &get_ebml_head(); + virtual uint64_t get_segment_pos() const; virtual uint64_t get_segment_data_start_pos() const;