diff --git a/src/common/chapters/chapters.cpp b/src/common/chapters/chapters.cpp index f10af5789..8d4cc2361 100644 --- a/src/common/chapters/chapters.cpp +++ b/src/common/chapters/chapters.cpp @@ -941,7 +941,7 @@ move_chapters_by_edition(KaxChapters &dst, // Move all atoms from the old edition to the new one. size_t master_idx; for (master_idx = 0; m->ListSize() > master_idx; master_idx++) - if (is_id((*m)[master_idx], KaxChapterAtom)) + if (Is((*m)[master_idx])) ee_dst->PushElement(*(*m)[master_idx]); else delete (*m)[master_idx]; @@ -972,7 +972,7 @@ adjust_chapter_timecodes(EbmlMaster &master, int64_t offset) { size_t master_idx; for (master_idx = 0; master.ListSize() > master_idx; master_idx++) { - if (!is_id(master[master_idx], KaxChapterAtom)) + if (!Is(master[master_idx])) continue; KaxChapterAtom *atom = static_cast(master[master_idx]); @@ -999,7 +999,7 @@ count_chapter_atoms_recursively(EbmlMaster &master, size_t master_idx; for (master_idx = 0; master.ListSize() > master_idx; ++master_idx) - if (is_id(master[master_idx], KaxChapterAtom)) + if (Is(master[master_idx])) ++count; else if (dynamic_cast(master[master_idx])) diff --git a/src/common/chapters/writer.cpp b/src/common/chapters/writer.cpp index c89f10f7d..0372d4e42 100644 --- a/src/common/chapters/writer.cpp +++ b/src/common/chapters/writer.cpp @@ -95,10 +95,10 @@ write_chapter_display_simple(KaxChapterDisplay *display, for (i = 0; i < display->ListSize(); i++) { EbmlElement *e = (*display)[i]; - if (is_id(e, KaxChapterString)) + if (Is(e)) handle_name(level - 1, static_cast(e)->GetValueUTF8().c_str()); - else if (is_id(e, KaxChapterAtom)) + else if (Is(e)) write_chapter_atom_simple((KaxChapterAtom *)e, level + 1); } @@ -112,7 +112,7 @@ write_chapter_track_simple(KaxChapterTrack *track, for (i = 0; i < track->ListSize(); i++) { EbmlElement *e = (*track)[i]; - if (is_id(e, KaxChapterAtom)) + if (Is(e)) write_chapter_atom_simple(static_cast(e), level + 1); } @@ -126,16 +126,16 @@ write_chapter_atom_simple(KaxChapterAtom *atom, for (i = 0; i < atom->ListSize(); i++) { EbmlElement *e = (*atom)[i]; - if (is_id(e, KaxChapterTimeStart)) + if (Is(e)) handle_start_time(level, static_cast(e)->GetValue() / 1000000); - else if (is_id(e, KaxChapterTrack)) + else if (Is(e)) write_chapter_track_simple(static_cast(e), level + 1); - else if (is_id(e, KaxChapterDisplay)) + else if (Is(e)) write_chapter_display_simple(static_cast(e), level + 1); - else if (is_id(e, KaxChapterAtom)) + else if (Is(e)) write_chapter_atom_simple(static_cast(e), level + 1); } @@ -151,12 +151,12 @@ write_chapters_simple(int &chapter_num, size_t chapter_idx; for (chapter_idx = 0; chapters->ListSize() > chapter_idx; chapter_idx++) { - if (is_id((*chapters)[chapter_idx], KaxEditionEntry)) { + if (Is((*chapters)[chapter_idx])) { KaxEditionEntry *edition = static_cast((*chapters)[chapter_idx]); size_t edition_idx; for (edition_idx = 0; edition->ListSize() > edition_idx; edition_idx++) - if (is_id((*edition)[edition_idx], KaxChapterAtom)) + if (Is((*edition)[edition_idx])) write_chapter_atom_simple(static_cast((*edition)[edition_idx]), 2); } } diff --git a/src/common/ebml.h b/src/common/ebml.h index 73544f391..de3a57e61 100644 --- a/src/common/ebml.h +++ b/src/common/ebml.h @@ -47,7 +47,6 @@ int kt_get_v_pixel_height(KaxTrackEntry &track); int write_ebml_element_head(mm_io_c &out, EbmlId const &id, int64_t content_size); -#define is_id(e, ref) (EbmlId(*e) == EBML_ID(ref)) #if !defined(EBML_INFO) #define EBML_INFO(ref) ref::ClassInfos #endif @@ -298,6 +297,18 @@ GetChildValue(EbmlMaster *master) { return GetChild(master).GetValue(); } +template +bool +Is(EbmlId const &id) { + return id == T::ClassInfos.GlobalId; +} + +template +bool +Is(EbmlId const &id) { + return Is(id) || Is(id); +} + template bool Is(EbmlElement *e) { @@ -310,6 +321,18 @@ Is(EbmlElement *e) { return !e ? false : Is(e) || Is(e); } +template +bool +Is(EbmlElement const &e) { + return EbmlId(e) == T::ClassInfos.GlobalId; +} + +template +bool +Is(EbmlElement const &e) { + return Is(e) || Is(e); +} + EbmlElement *empty_ebml_master(EbmlElement *e); EbmlElement *create_ebml_element(const EbmlCallbacks &callbacks, const EbmlId &id); EbmlMaster *sort_ebml_master(EbmlMaster *e); diff --git a/src/common/kax_analyzer.cpp b/src/common/kax_analyzer.cpp index 63530422a..b984d952d 100644 --- a/src/common/kax_analyzer.cpp +++ b/src/common/kax_analyzer.cpp @@ -46,7 +46,7 @@ std::string kax_analyzer_data_c::to_string() const { const EbmlCallbacks *callbacks = find_ebml_callbacks(EBML_INFO(KaxSegment), m_id); - if (!callbacks && (EBML_ID(EbmlVoid) == m_id)) + if (!callbacks && Is(m_id)) callbacks = &EBML_CLASS_CALLBACK(EbmlVoid); std::string name; @@ -239,7 +239,7 @@ kax_analyzer_c::process(kax_analyzer_c::parse_mode_e parse_mode, if (!l0) throw mtx::kax_analyzer_x(Y("Not a valid Matroska file (no segment/level 0 element found)")); - if (EbmlId(*l0) == EBML_ID(KaxSegment)) + if (Is(l0)) break; l0->SkipData(*m_stream, EBML_CONTEXT(l0)); @@ -257,8 +257,8 @@ kax_analyzer_c::process(kax_analyzer_c::parse_mode_e parse_mode, while (l1 && (0 >= upper_lvl_el)) { m_data.push_back(kax_analyzer_data_c::create(EbmlId(*l1), l1->GetElementPosition(), l1->ElementSize(true))); - cluster_found |= is_id(l1, KaxCluster); - meta_seek_found |= is_id(l1, KaxSeekHead); + cluster_found |= Is(l1); + meta_seek_found |= Is(l1); l1->SkipData(*m_stream, EBML_CONTEXT(l1)); delete l1; @@ -449,7 +449,7 @@ kax_analyzer_c::handle_void_elements(size_t data_idx) { // Are the following elements EbmlVoid elements? size_t end_idx = data_idx + 1; - while ((m_data.size() > end_idx) && (m_data[end_idx]->m_id == EBML_ID(EbmlVoid))) + while ((m_data.size() > end_idx) && Is(m_data[end_idx]->m_id)) ++end_idx; if (end_idx > data_idx + 1) @@ -587,7 +587,7 @@ kax_analyzer_c::remove_from_meta_seeks(EbmlId id) { for (data_idx = 0; m_data.size() > data_idx; ++data_idx) { // We only have to do work on SeekHead elements. Skip the others. - if (m_data[data_idx]->m_id != EBML_ID(KaxSeekHead)) + if (!Is(m_data[data_idx]->m_id)) continue; // Read the element from the m_file. Remember its size so that a new @@ -603,7 +603,7 @@ kax_analyzer_c::remove_from_meta_seeks(EbmlId id) { bool modified = false; size_t sh_idx = 0; while (seek_head->ListSize() > sh_idx) { - if (EbmlId(*(*seek_head)[sh_idx]) != EBML_ID(KaxSeek)) { + if (!Is((*seek_head)[sh_idx])) { ++sh_idx; continue; } @@ -680,7 +680,7 @@ kax_analyzer_c::merge_void_elements() { while (m_data.size() > start_idx) { // We only have to do work on EbmlVoid elements. Skip the others. - if (m_data[start_idx]->m_id != EBML_ID(EbmlVoid)) { + if (!Is(m_data[start_idx]->m_id)) { ++start_idx; continue; } @@ -689,7 +689,7 @@ kax_analyzer_c::merge_void_elements() { // there are at this position and calculate the combined size. size_t end_idx = start_idx + 1; size_t new_size = m_data[start_idx]->m_size; - while ((m_data.size() > end_idx) && (m_data[end_idx]->m_id == EBML_ID(EbmlVoid))) { + while ((m_data.size() > end_idx) && Is(m_data[end_idx]->m_id)) { new_size += m_data[end_idx]->m_size; ++end_idx; } @@ -719,7 +719,7 @@ kax_analyzer_c::merge_void_elements() { // See how many void elements there are at the end of the m_file. start_idx = m_data.size(); - while ((0 < start_idx) && (EBML_ID(EbmlVoid) == m_data[start_idx - 1]->m_id)) + while ((0 < start_idx) && Is(m_data[start_idx - 1]->m_id)) --start_idx; // If there are none then we're done. @@ -758,7 +758,7 @@ kax_analyzer_c::write_element(EbmlElement *e, size_t data_idx; for (data_idx = (ps_anywhere == strategy ? 0 : m_data.size() - 1); m_data.size() > data_idx; ++data_idx) { // We're only interested in EbmlVoid elements. Skip the others. - if (m_data[data_idx]->m_id != EBML_ID(EbmlVoid)) + if (!Is(m_data[data_idx]->m_id)) continue; // Skip the element if it doesn't provide enough space. @@ -809,7 +809,7 @@ kax_analyzer_c::add_to_meta_seek(EbmlElement *e) { for (data_idx = 0; m_data.size() > data_idx; ++data_idx) { // We only have to do work on SeekHead elements. Skip the others. - if (m_data[data_idx]->m_id != EBML_ID(KaxSeekHead)) + if (!Is(m_data[data_idx]->m_id)) continue; // Calculate how much free space there is behind the seek head. @@ -817,7 +817,7 @@ kax_analyzer_c::add_to_meta_seek(EbmlElement *e) { // at the end of the m_file and that all consecutive EbmlVoid elements // have been merged into a single element. size_t available_space = m_data[data_idx]->m_size; - if (((data_idx + 1) < m_data.size()) && (m_data[data_idx + 1]->m_id == EBML_ID(EbmlVoid))) + if (((data_idx + 1) < m_data.size()) && Is(m_data[data_idx + 1]->m_id)) available_space += m_data[data_idx + 1]->m_size; // Read the seek head, index the element and see how much space it needs. @@ -909,7 +909,7 @@ kax_analyzer_c::add_to_meta_seek(EbmlElement *e) { for (data_idx = 0; m_data.size() > data_idx; ++data_idx) { // We can only overwrite void elements. Skip the others. - if (m_data[data_idx]->m_id != EBML_ID(EbmlVoid)) + if (!Is(m_data[data_idx]->m_id)) continue; // Skip the element if it doesn't offer enough space for the seek head. @@ -992,7 +992,7 @@ kax_analyzer_c::read_all_meta_seeks() { positions_found[m_data[i]->m_pos] = true; for (i = 0; i < num_entries; i++) - if (EBML_ID(KaxSeekHead) == m_data[i]->m_id) + if (Is(m_data[i]->m_id)) read_meta_seek(m_data[i]->m_pos, positions_found); std::sort(m_data.begin(), m_data.end()); @@ -1014,7 +1014,7 @@ kax_analyzer_c::read_meta_seek(uint64_t pos, if (!l1) return; - if (!is_id(l1, KaxSeekHead)) { + if (!Is(l1)) { delete l1; return; } @@ -1025,7 +1025,7 @@ kax_analyzer_c::read_meta_seek(uint64_t pos, unsigned int i; for (i = 0; master->ListSize() > i; i++) { - if (!is_id((*master)[i], KaxSeek)) + if (!Is((*master)[i])) continue; KaxSeek *seek = static_cast((*master)[i]); @@ -1042,7 +1042,7 @@ kax_analyzer_c::read_meta_seek(uint64_t pos, m_data.push_back(kax_analyzer_data_c::create(the_id, seek_pos, -1)); positions_found[seek_pos] = true; - if (EBML_ID(KaxSeekHead) == the_id) + if (Is(the_id)) read_meta_seek(seek_pos, positions_found); } @@ -1059,7 +1059,7 @@ kax_analyzer_c::fix_element_sizes(uint64_t file_size) { kax_analyzer_c::placement_strategy_e kax_analyzer_c::get_placement_strategy_for(EbmlElement *e) { - return EbmlId(*e) == EBML_ID(KaxTags) ? ps_end : ps_anywhere; + return Is(e) ? ps_end : ps_anywhere; } // ------------------------------------------------------------ diff --git a/src/common/tags/tags.cpp b/src/common/tags/tags.cpp index 12d188016..53015d99d 100644 --- a/src/common/tags/tags.cpp +++ b/src/common/tags/tags.cpp @@ -100,7 +100,7 @@ find_simple_tag(const std::string &name, KaxTagSimple & find_simple_tag(const UTFstring &name, EbmlMaster &m) { - if (EbmlId(m) == EBML_ID(KaxTagSimple)) { + if (Is(&m)) { KaxTagName *tname = FindChild(&m); if (tname && (name == UTFstring(*tname))) return *static_cast(&m); @@ -108,12 +108,11 @@ find_simple_tag(const UTFstring &name, size_t i; for (i = 0; i < m.ListSize(); i++) - if ((EbmlId(*m[i]) == EBML_ID(KaxTag)) || (EbmlId(*m[i]) == EBML_ID(KaxTagSimple))) { + if (Is(m[i])) try { return find_simple_tag(name, *static_cast(m[i])); } catch (...) { } - } throw false; } @@ -202,7 +201,7 @@ convert_old_tags(KaxTags &tags) { size_t tags_idx; for (tags_idx = 0; tags_idx < tags.ListSize(); tags_idx++) { - if (!is_id(tags[tags_idx], KaxTag)) + if (!Is(tags[tags_idx])) continue; KaxTag &tag = *static_cast(tags[tags_idx]); @@ -211,7 +210,7 @@ convert_old_tags(KaxTags &tags) { size_t tag_idx = 0; while (tag_idx < tag.ListSize()) { tag_idx++; - if (!is_id(tag[tag_idx - 1], KaxTagSimple)) + if (!Is(tag[tag_idx - 1])) continue; KaxTagSimple &simple = *static_cast(tag[tag_idx - 1]); @@ -248,7 +247,7 @@ count_simple_tags(EbmlMaster &master) { int count = 0; for (auto child : master) - if (is_id(child, KaxTagSimple)) + if (Is(child)) ++count; else if (dynamic_cast(child)) @@ -260,7 +259,7 @@ count_simple_tags(EbmlMaster &master) { void remove_track_uid_tag_targets(EbmlMaster *tag) { for (auto el : *tag) { - if (!is_id(el, KaxTagTargets)) + if (!Is(el)) continue; KaxTagTargets *targets = static_cast(el); @@ -268,7 +267,7 @@ remove_track_uid_tag_targets(EbmlMaster *tag) { while (targets->ListSize() > idx_target) { EbmlElement *uid_el = (*targets)[idx_target]; - if (is_id(uid_el, KaxTagTrackUID)) { + if (Is(uid_el)) { targets->Remove(idx_target); delete uid_el; diff --git a/src/extract/attachments.cpp b/src/extract/attachments.cpp index d99b3e91a..c74c7c5d9 100644 --- a/src/extract/attachments.cpp +++ b/src/extract/attachments.cpp @@ -64,16 +64,16 @@ attachment_t::parse(KaxAttached &att) { for (k = 0; att.ListSize() > k; ++k) { EbmlElement *e = att[k]; - if (EbmlId(*e) == EBML_ID(KaxFileName)) + if (Is(e)) name = static_cast(e)->GetValueUTF8(); - else if (EbmlId(*e) == EBML_ID(KaxMimeType)) + else if (Is(e)) type = static_cast(e)->GetValue(); - else if (EbmlId(*e) == EBML_ID(KaxFileUID)) + else if (Is(e)) id = static_cast(e)->GetValue(); - else if (EbmlId(*e) == EBML_ID(KaxFileData)) { + else if (Is(e)) { fdata = static_cast(e); size = fdata->GetSize(); } diff --git a/src/extract/cuesheets.cpp b/src/extract/cuesheets.cpp index c8cef027d..d58b51bdc 100644 --- a/src/extract/cuesheets.cpp +++ b/src/extract/cuesheets.cpp @@ -50,7 +50,7 @@ find_tag_for_track(int idx, size_t i; for (i = 0; i < m.ListSize(); i++) { - if (EbmlId(*m[i]) != EBML_ID(KaxTag)) + if (!Is(m[i])) continue; int64_t tag_cuid = get_tag_cuid(*static_cast(m[i])); @@ -85,7 +85,7 @@ get_chapter_index(int idx, size_t i; std::string sidx = (boost::format("INDEX %|1$02d|") % idx).str(); for (i = 0; i < atom.ListSize(); i++) - if ((EbmlId(*atom[i]) == EBML_ID(KaxChapterAtom)) && + if (Is(atom[i]) && (get_chapter_name(*static_cast(atom[i])) == sidx)) return get_chapter_start(*static_cast(atom[i])); @@ -125,7 +125,7 @@ print_comments(const char *prefix, size_t i; for (i = 0; i < tag.ListSize(); i++) - if (is_id(tag[i], KaxTagSimple) + if (Is(tag[i]) && ( (get_simple_tag_name(*static_cast(tag[i])) == "COMMENT") || (get_simple_tag_name(*static_cast(tag[i])) == "COMMENTS"))) out.puts(boost::format("%1%REM \"%2%\"\n") % prefix % get_simple_tag_value(*static_cast(tag[i]))); diff --git a/src/extract/timecodes_v2.cpp b/src/extract/timecodes_v2.cpp index 566e2361b..affb80722 100644 --- a/src/extract/timecodes_v2.cpp +++ b/src/extract/timecodes_v2.cpp @@ -103,7 +103,7 @@ create_timecode_files(KaxTracks &kax_tracks, int track_number = -1; KaxTrackEntry *track = nullptr; for (i = 0; kax_tracks.ListSize() > i; ++i) { - if (!is_id(kax_tracks[i], KaxTrackEntry)) + if (!Is(kax_tracks[i])) continue; ++track_number; @@ -219,7 +219,7 @@ extract_timecodes(const std::string &file_name, show_error(Y("No segment/level 0 element found.")); return; } - if (EbmlId(*l0) == EBML_ID(KaxSegment)) { + if (Is(l0)) { show_element(l0, 0, Y("Segment")); break; } @@ -238,14 +238,14 @@ extract_timecodes(const std::string &file_name, EbmlElement *l3 = nullptr; while (l1 && (0 >= upper_lvl_el)) { - if (EbmlId(*l1) == EBML_ID(KaxInfo)) { + if (Is(l1)) { // General info about this Matroska file show_element(l1, 1, Y("Segment information")); upper_lvl_el = 0; l2 = es->FindNextElement(EBML_CONTEXT(l1), upper_lvl_el, 0xFFFFFFFFL, true, 1); while (l2 && (0 >= upper_lvl_el)) { - if (EbmlId(*l2) == EBML_ID(KaxTimecodeScale)) { + if (Is(l2)) { KaxTimecodeScale &ktc_scale = *static_cast(l2); ktc_scale.ReadData(es->I_O()); tc_scale = ktc_scale.GetValue(); @@ -270,7 +270,7 @@ extract_timecodes(const std::string &file_name, l2 = es->FindNextElement(EBML_CONTEXT(l1), upper_lvl_el, 0xFFFFFFFFL, true); } - } else if ((EbmlId(*l1) == EBML_ID(KaxTracks)) && !tracks_found) { + } else if ((Is(l1)) && !tracks_found) { // Yep, we've found our KaxTracks element. Now find all tracks // contained in this segment. @@ -281,7 +281,7 @@ extract_timecodes(const std::string &file_name, find_and_verify_track_uids(*dynamic_cast(l1), tspecs); create_timecode_files(*dynamic_cast(l1), tspecs, version); - } else if (EbmlId(*l1) == EBML_ID(KaxCluster)) { + } else if (Is(l1)) { show_element(l1, 1, Y("Cluster")); KaxCluster *cluster = (KaxCluster *)l1; uint64_t cluster_tc = 0; @@ -293,20 +293,20 @@ extract_timecodes(const std::string &file_name, l2 = es->FindNextElement(EBML_CONTEXT(l1), upper_lvl_el, 0xFFFFFFFFL, true, 1); while (l2 && (0 >= upper_lvl_el)) { - if (EbmlId(*l2) == EBML_ID(KaxClusterTimecode)) { + if (Is(l2)) { KaxClusterTimecode &ctc = *static_cast(l2); ctc.ReadData(es->I_O()); cluster_tc = ctc.GetValue(); show_element(l2, 2, boost::format(Y("Cluster timecode: %|1$.3f|s")) % ((float)cluster_tc * (float)tc_scale / 1000000000.0)); cluster->InitTimecode(cluster_tc, tc_scale); - } else if (EbmlId(*l2) == EBML_ID(KaxBlockGroup)) { + } else if (Is(l2)) { show_element(l2, 2, Y("Block group")); l2->Read(*es, EBML_CLASS_CONTEXT(KaxBlockGroup), upper_lvl_el, l3, true); handle_blockgroup(*static_cast(l2), *cluster, tc_scale); - } else if (EbmlId(*l2) == EBML_ID(KaxSimpleBlock)) { + } else if (Is(l2)) { show_element(l2, 2, Y("Simple block")); l2->Read(*es, EBML_CLASS_CONTEXT(KaxSimpleBlock), upper_lvl_el, l3, true); diff --git a/src/extract/tracks.cpp b/src/extract/tracks.cpp index f2ffc5b8f..7a459ba9a 100644 --- a/src/extract/tracks.cpp +++ b/src/extract/tracks.cpp @@ -53,7 +53,7 @@ create_extractors(KaxTracks &kax_tracks, int64_t track_id = -1; for (i = 0; i < kax_tracks.ListSize(); i++) { - if (!is_id(kax_tracks[i], KaxTrackEntry)) + if (!Is(kax_tracks[i])) continue; ++track_id; @@ -374,7 +374,7 @@ extract_tracks(const std::string &file_name, return false; } - if (EbmlId(*l0) == EBML_ID(KaxSegment)) { + if (Is(l0)) { show_element(l0, 0, Y("Segment")); break; } @@ -391,7 +391,7 @@ extract_tracks(const std::string &file_name, KaxTags all_tags; while ((l1 = file->read_next_level1_element())) { - if (EbmlId(*l1) == EBML_ID(KaxInfo)) { + if (Is(l1)) { // General info about this Matroska file show_element(l1, 1, Y("Segment information")); @@ -402,7 +402,7 @@ extract_tracks(const std::string &file_name, show_element(ktc_scale, 2, boost::format(Y("Timecode scale: %1%")) % tc_scale); } - } else if ((EbmlId(*l1) == EBML_ID(KaxTracks)) && !tracks_found) { + } else if ((Is(l1)) && !tracks_found) { // Yep, we've found our KaxTracks element. Now find all tracks // contained in this segment. @@ -412,7 +412,7 @@ extract_tracks(const std::string &file_name, find_and_verify_track_uids(*dynamic_cast(l1), tspecs); create_extractors(*dynamic_cast(l1), tspecs); - } else if (EbmlId(*l1) == EBML_ID(KaxCluster)) { + } else if (Is(l1)) { show_element(l1, 1, Y("Cluster")); KaxCluster *cluster = static_cast(l1); @@ -434,11 +434,11 @@ extract_tracks(const std::string &file_name, int64_t max_bg_timecode = -1; EbmlElement *el = (*cluster)[i]; - if (EbmlId(*el) == EBML_ID(KaxBlockGroup)) { + if (Is(el)) { show_element(el, 2, Y("Block group")); max_bg_timecode = handle_blockgroup(*static_cast(el), *cluster, tc_scale); - } else if (EbmlId(*el) == EBML_ID(KaxSimpleBlock)) { + } else if (Is(el)) { show_element(el, 2, Y("SimpleBlock")); max_bg_timecode = handle_simpleblock(*static_cast(el), *cluster); } @@ -449,14 +449,14 @@ extract_tracks(const std::string &file_name, if (-1 != max_timecode) file->set_last_timecode(max_timecode); - } else if (EbmlId(*l1) == EBML_ID(KaxChapters)) { + } else if (Is(l1)) { KaxChapters &chapters = *static_cast(l1); while (chapters.ListSize() > 0) { - if (EbmlId(*chapters[0]) == EBML_ID(KaxEditionEntry)) { + if (Is(chapters[0])) { KaxEditionEntry &entry = *static_cast(chapters[0]); while (entry.ListSize() > 0) { - if (EbmlId(*entry[0]) == EBML_ID(KaxChapterAtom)) + if (Is(entry[0])) all_chapters.PushElement(*entry[0]); entry.Remove(0); } @@ -464,7 +464,7 @@ extract_tracks(const std::string &file_name, chapters.Remove(0); } - } else if (EbmlId(*l1) == EBML_ID(KaxTags)) { + } else if (Is(l1)) { KaxTags &tags = *static_cast(l1); while (tags.ListSize() > 0) { diff --git a/src/info/mkvinfo.cpp b/src/info/mkvinfo.cpp index ebd62267e..c2641c681 100644 --- a/src/info/mkvinfo.cpp +++ b/src/info/mkvinfo.cpp @@ -372,11 +372,11 @@ bool is_global(EbmlStream *es, EbmlElement *l, int level) { - if (is_id(l, EbmlVoid)) { + if (Is(l)) { show_element(l, level, (BF_EBMLVOID % (l->ElementSize() - l->HeadSize())).str()); return true; - } else if (is_id(l, EbmlCrc32)) { + } else if (Is(l)) { show_element(l, level, "EbmlCrc32"); return true; } @@ -452,13 +452,13 @@ handle_chaptertranslate(EbmlStream *&es, show_element(l2, 2, Y("Chapter Translate")); for (auto l3 : *static_cast(l2)) - if (is_id(l3, KaxChapterTranslateEditionUID)) + if (Is(l3)) show_element(l3, 3, boost::format(Y("Chapter Translate Edition UID: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxChapterTranslateCodec)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("Chapter Translate Codec: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxChapterTranslateID)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("Chapter Translate ID: %1%")) % format_binary(static_cast(l3))); } @@ -477,24 +477,24 @@ handle_info(EbmlStream *&es, s_tc_scale = FindChildValue(m1, TIMECODE_SCALE); for (auto l2 : *m1) - if (is_id(l2, KaxTimecodeScale)) { + if (Is(l2)) { s_tc_scale = static_cast(l2)->GetValue(); show_element(l2, 2, boost::format(Y("Timecode scale: %1%")) % s_tc_scale); - } else if (is_id(l2, KaxDuration)) { + } else if (Is(l2)) { KaxDuration &duration = *static_cast(l2); show_element(l2, 2, boost::format(Y("Duration: %|1$.3f|s (%2%)")) % (duration.GetValue() * s_tc_scale / 1000000000.0) % format_timecode(static_cast(duration.GetValue()) * s_tc_scale, 3)); - } else if (is_id(l2, KaxMuxingApp)) + } else if (Is(l2)) show_element(l2, 2, boost::format(Y("Muxing application: %1%")) % static_cast(l2)->GetValueUTF8()); - else if (is_id(l2, KaxWritingApp)) + else if (Is(l2)) show_element(l2, 2, boost::format(Y("Writing application: %1%")) % static_cast(l2)->GetValueUTF8()); - else if (is_id(l2, KaxDateUTC)) { + else if (Is(l2)) { struct tm tmutc; char buffer[40]; time_t temptime = static_cast(l2)->GetEpochDate(); @@ -504,31 +504,31 @@ handle_info(EbmlStream *&es, } else show_element(l2, 2, boost::format(Y("Date (invalid, value: %1%)")) % temptime); - } else if (is_id(l2, KaxSegmentUID)) + } else if (Is(l2)) show_element(l2, 2, boost::format(Y("Segment UID: %1%")) % to_hex(static_cast(l2))); - else if (is_id(l2, KaxSegmentFamily)) + else if (Is(l2)) show_element(l2, 2, boost::format(Y("Family UID: %1%")) % to_hex(static_cast(l2))); - else if (is_id(l2, KaxChapterTranslate)) + else if (Is(l2)) handle_chaptertranslate(es, l2); - else if (is_id(l2, KaxPrevUID)) + else if (Is(l2)) show_element(l2, 2, boost::format(Y("Previous segment UID: %1%")) % to_hex(static_cast(l2))); - else if (is_id(l2, KaxPrevFilename)) + else if (Is(l2)) show_element(l2, 2, boost::format(Y("Previous filename: %1%")) % static_cast(l2)->GetValueUTF8()); - else if (is_id(l2, KaxNextUID)) + else if (Is(l2)) show_element(l2, 2, boost::format(Y("Next segment UID: %1%")) % to_hex(static_cast(l2))); - else if (is_id(l2, KaxNextFilename)) + else if (Is(l2)) show_element(l2, 2, boost::format(Y("Next filename: %1%")) % static_cast(l2)->GetValueUTF8()); - else if (is_id(l2, KaxSegmentFilename)) + else if (Is(l2)) show_element(l2, 2, boost::format(Y("Segment filename: %1%")) % static_cast(l2)->GetValueUTF8()); - else if (is_id(l2, KaxTitle)) + else if (Is(l2)) show_element(l2, 2, boost::format(Y("Title: %1%")) % static_cast(l2)->GetValueUTF8()); } @@ -539,28 +539,28 @@ handle_audio_track(EbmlStream *&es, show_element(l3, 3, "Audio track"); for (auto l4 : *static_cast(l3)) - if (is_id(l4, KaxAudioSamplingFreq)) { + if (Is(l4)) { KaxAudioSamplingFreq &freq = *static_cast(l4); show_element(l4, 4, boost::format(Y("Sampling frequency: %1%")) % freq.GetValue()); summary.push_back((boost::format(Y("sampling freq: %1%")) % freq.GetValue()).str()); - } else if (is_id(l4, KaxAudioOutputSamplingFreq)) { + } else if (Is(l4)) { KaxAudioOutputSamplingFreq &ofreq = *static_cast(l4); show_element(l4, 4, boost::format(Y("Output sampling frequency: %1%")) % ofreq.GetValue()); summary.push_back((boost::format(Y("output sampling freq: %1%")) % ofreq.GetValue()).str()); - } else if (is_id(l4, KaxAudioChannels)) { + } else if (Is(l4)) { KaxAudioChannels &channels = *static_cast(l4); show_element(l4, 4, boost::format(Y("Channels: %1%")) % channels.GetValue()); summary.push_back((boost::format(Y("channels: %1%")) % channels.GetValue()).str()); #if MATROSKA_VERSION >= 2 - } else if (is_id(l4, KaxAudioPosition)) { + } else if (Is(l4)) { KaxAudioPosition &positions = *static_cast(l4); show_element(l4, 4, boost::format(Y("Channel positions: %1%")) % format_binary(positions)); #endif - } else if (is_id(l4, KaxAudioBitDepth)) { + } else if (Is(l4)) { KaxAudioBitDepth &bps = *static_cast(l4); show_element(l4, 4, boost::format(Y("Bit depth: %1%")) % bps.GetValue()); summary.push_back((boost::format(Y("bits per sample: %1%")) % bps.GetValue()).str()); @@ -576,48 +576,48 @@ handle_video_track(EbmlStream *&es, show_element(l3, 3, Y("Video track")); for (auto l4 : *static_cast(l3)) - if (is_id(l4, KaxVideoPixelWidth)) { + if (Is(l4)) { KaxVideoPixelWidth &width = *static_cast(l4); show_element(l4, 4, boost::format(Y("Pixel width: %1%")) % width.GetValue()); summary.push_back((boost::format(Y("pixel width: %1%")) % width.GetValue()).str()); - } else if (is_id(l4, KaxVideoPixelHeight)) { + } else if (Is(l4)) { KaxVideoPixelHeight &height = *static_cast(l4); show_element(l4, 4, boost::format(Y("Pixel height: %1%")) % height.GetValue()); summary.push_back((boost::format(Y("pixel height: %1%")) % height.GetValue()).str()); - } else if (is_id(l4, KaxVideoDisplayWidth)) { + } else if (Is(l4)) { KaxVideoDisplayWidth &width = *static_cast(l4); show_element(l4, 4, boost::format(Y("Display width: %1%")) % width.GetValue()); summary.push_back((boost::format(Y("display width: %1%")) % width.GetValue()).str()); - } else if (is_id(l4, KaxVideoDisplayHeight)) { + } else if (Is(l4)) { KaxVideoDisplayHeight &height = *static_cast(l4); show_element(l4, 4, boost::format(Y("Display height: %1%")) % height.GetValue()); summary.push_back((boost::format(Y("display height: %1%")) % height.GetValue()).str()); - } else if (is_id(l4, KaxVideoPixelCropLeft)) { + } else if (Is(l4)) { KaxVideoPixelCropLeft &left = *static_cast(l4); show_element(l4, 4, boost::format(Y("Pixel crop left: %1%")) % left.GetValue()); summary.push_back((boost::format(Y("pixel crop left: %1%")) % left.GetValue()).str()); - } else if (is_id(l4, KaxVideoPixelCropTop)) { + } else if (Is(l4)) { KaxVideoPixelCropTop &top = *static_cast(l4); show_element(l4, 4, boost::format(Y("Pixel crop top: %1%")) % top.GetValue()); summary.push_back((boost::format(Y("pixel crop top: %1%")) % top.GetValue()).str()); - } else if (is_id(l4, KaxVideoPixelCropRight)) { + } else if (Is(l4)) { KaxVideoPixelCropRight &right = *static_cast(l4); show_element(l4, 4, boost::format(Y("Pixel crop right: %1%")) % right.GetValue()); summary.push_back((boost::format(Y("pixel crop right: %1%")) % right.GetValue()).str()); - } else if (is_id(l4, KaxVideoPixelCropBottom)) { + } else if (Is(l4)) { KaxVideoPixelCropBottom &bottom = *static_cast(l4); show_element(l4, 4, boost::format(Y("Pixel crop bottom: %1%")) % bottom.GetValue()); summary.push_back((boost::format(Y("pixel crop bottom: %1%")) % bottom.GetValue()).str()); #if MATROSKA_VERSION >= 2 - } else if (is_id(l4, KaxVideoDisplayUnit)) { + } else if (Is(l4)) { auto unit = static_cast(l4)->GetValue(); show_element(l4, 4, boost::format(Y("Display unit: %1%%2%")) @@ -628,20 +628,20 @@ handle_video_track(EbmlStream *&es, : 3 == unit ? Y(" (aspect ratio)") : "")); - } else if (is_id(l4, KaxVideoGamma)) + } else if (Is(l4)) show_element(l4, 4, boost::format(Y("Gamma: %1%")) % static_cast(l4)->GetValue()); - else if (is_id(l4, KaxVideoFlagInterlaced)) + else if (Is(l4)) show_element(l4, 4, boost::format(Y("Interlaced: %1%")) % static_cast(l4)->GetValue()); - else if (is_id(l4, KaxVideoStereoMode)) { + else if (Is(l4)) { auto stereo_mode = static_cast(l4)->GetValue(); show_element(l4, 4, boost::format(Y("Stereo mode: %1% (%2%)")) % stereo_mode % stereo_mode_c::translate(static_cast(stereo_mode))); - } else if (is_id(l4, KaxVideoAspectRatio)) { + } else if (Is(l4)) { auto ar_type = static_cast(l4)->GetValue(); show_element(l4, 4, boost::format(Y("Aspect ratio type: %1%%2%")) @@ -651,10 +651,10 @@ handle_video_track(EbmlStream *&es, : 2 == ar_type ? Y(" (fixed)") : "")); #endif - } else if (is_id(l4, KaxVideoColourSpace)) + } else if (Is(l4)) show_element(l4, 4, boost::format(Y("Colour space: %1%")) % format_binary(static_cast(l4))); - else if (is_id(l4, KaxVideoFrameRate)) + else if (Is(l4)) show_element(l4, 4, boost::format(Y("Frame rate: %1%")) % static_cast(l4)->GetValue()); else if (!is_global(es, l4, 4)) @@ -667,14 +667,14 @@ handle_content_encodings(EbmlStream *&es, show_element(l3, 3, Y("Content encodings")); for (auto l4 : *static_cast(l3)) - if (is_id(l4, KaxContentEncoding)) { + if (Is(l4)) { show_element(l4, 4, Y("Content encoding")); for (auto l5 : *static_cast(l4)) - if (is_id(l5, KaxContentEncodingOrder)) + if (Is(l5)) show_element(l5, 5, boost::format(Y("Order: %1%")) % static_cast(l5)->GetValue()); - else if (is_id(l5, KaxContentEncodingScope)) { + else if (Is(l5)) { std::vector scope; auto ce_scope = static_cast(l5)->GetValue(); @@ -688,7 +688,7 @@ handle_content_encodings(EbmlStream *&es, scope.push_back(Y("unknown")); show_element(l5, 5, boost::format(Y("Scope: %1% (%2%)")) % ce_scope % join(", ", scope)); - } else if (is_id(l5, KaxContentEncodingType)) { + } else if (Is(l5)) { auto ce_type = static_cast(l5)->GetValue(); show_element(l5, 5, boost::format(Y("Type: %1% (%2%)")) @@ -697,11 +697,11 @@ handle_content_encodings(EbmlStream *&es, : 1 == ce_type ? Y("encryption") : Y("unknown"))); - } else if (is_id(l5, KaxContentCompression)) { + } else if (Is(l5)) { show_element(l5, 5, Y("Content compression")); for (auto l6 : *static_cast(l5)) - if (is_id(l6, KaxContentCompAlgo)) { + if (Is(l6)) { auto c_algo = static_cast(l6)->GetValue(); show_element(l6, 6, boost::format(Y("Algorithm: %1% (%2%)")) @@ -712,16 +712,16 @@ handle_content_encodings(EbmlStream *&es, : 3 == c_algo ? Y("header removal") : Y("unknown"))); - } else if (is_id(l6, KaxContentCompSettings)) + } else if (Is(l6)) show_element(l6, 6, boost::format(Y("Settings: %1%")) % format_binary(static_cast(l6))); else if (!is_global(es, l6, 6)) show_unknown_element(l6, 6); - } else if (is_id(l5, KaxContentEncryption)) { + } else if (Is(l5)) { show_element(l5, 5, Y("Content encryption")); for (auto l6 : *static_cast(l5)) - if (is_id(l6, KaxContentEncAlgo)) { + if (Is(l6)) { auto e_algo = static_cast(l6)->GetValue(); show_element(l6, 6, boost::format(Y("Encryption algorithm: %1% (%2%)")) @@ -734,10 +734,10 @@ handle_content_encodings(EbmlStream *&es, : 5 == e_algo ? "AES" : Y("unknown"))); - } else if (is_id(l6, KaxContentEncKeyID)) + } else if (Is(l6)) show_element(l6, 6, boost::format(Y("Encryption key ID: %1%")) % format_binary(static_cast(l6))); - else if (is_id(l6, KaxContentSigAlgo)) { + else if (Is(l6)) { auto s_algo = static_cast(l6)->GetValue(); show_element(l6, 6, boost::format(Y("Signature algorithm: %1% (%2%)")) @@ -746,7 +746,7 @@ handle_content_encodings(EbmlStream *&es, : 1 == s_algo ? Y("RSA") : Y("unknown"))); - } else if (is_id(l6, KaxContentSigHashAlgo)) { + } else if (Is(l6)) { auto s_halgo = static_cast(l6)->GetValue(); show_element(l6, 6, boost::format(Y("Signature hash algorithm: %1% (%2%)")) @@ -756,10 +756,10 @@ handle_content_encodings(EbmlStream *&es, : 2 == s_halgo ? Y("MD5") : Y("unknown"))); - } else if (is_id(l6, KaxContentSigKeyID)) + } else if (Is(l6)) show_element(l6, 6, boost::format(Y("Signature key ID: %1%")) % format_binary(static_cast(l6))); - else if (is_id(l6, KaxContentSignature)) + else if (Is(l6)) show_element(l6, 6, boost::format(Y("Signature: %1%")) % format_binary(static_cast(l6))); else if (!is_global(es, l6, 6)) @@ -787,7 +787,7 @@ handle_tracks(EbmlStream *&es, read_master(m1, es, EBML_CONTEXT(l1), upper_lvl_el, element_found); for (auto l2 : *m1) - if (is_id(l2, KaxTrackEntry)) { + if (Is(l2)) { // We actually found a track entry :) We're happy now. show_element(l2, 2, Y("A track")); @@ -797,13 +797,13 @@ handle_tracks(EbmlStream *&es, for (auto l3 : *static_cast(l2)) // Now evaluate the data belonging to this track - if (is_id(l3, KaxTrackAudio)) + if (Is(l3)) handle_audio_track(es, l3, summary); - else if (is_id(l3, KaxTrackVideo)) + else if (Is(l3)) handle_video_track(es, l3, summary); - else if (is_id(l3, KaxTrackNumber)) { + else if (Is(l3)) { track->tnum = static_cast(l3)->GetValue(); auto existing_track = find_track(track->tnum); @@ -819,11 +819,11 @@ handle_tracks(EbmlStream *&es, show_element(l3, 3, boost::format(Y("Track number: %1% (track ID for mkvmerge & mkvextract: %2%)")) % track->tnum % track_id); summary.push_back((boost::format(Y("mkvmerge/mkvextract track ID: %1%")) % track_id).str()); - } else if (is_id(l3, KaxTrackUID)) { + } else if (Is(l3)) { track->tuid = static_cast(l3)->GetValue(); show_element(l3, 3, boost::format(Y("Track UID: %1%")) % track->tuid); - } else if (is_id(l3, KaxTrackType)) { + } else if (Is(l3)) { auto ttype = static_cast(l3)->GetValue(); track->type = track_audio == ttype ? 'a' : track_video == ttype ? 'v' @@ -839,18 +839,18 @@ handle_tracks(EbmlStream *&es, : "unknown")); #if MATROSKA_VERSION >= 2 - } else if (is_id(l3, KaxTrackFlagEnabled)) + } else if (Is(l3)) show_element(l3, 3, boost::format(Y("Enabled: %1%")) % static_cast(l3)->GetValue()); #endif - else if (is_id(l3, KaxTrackName)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("Name: %1%")) % static_cast(l3)->GetValueUTF8()); - else if (is_id(l3, KaxCodecID)) { + else if (Is(l3)) { kax_codec_id = static_cast(l3)->GetValue(); show_element(l3, 3, boost::format(Y("Codec ID: %1%")) % kax_codec_id); - } else if (is_id(l3, KaxCodecPrivate)) { + } else if (Is(l3)) { KaxCodecPrivate &c_priv = *static_cast(l3); fourcc_buffer = create_codec_dependent_private_info(c_priv, track->type, kax_codec_id); @@ -862,33 +862,33 @@ handle_tracks(EbmlStream *&es, show_element(l3, 3, boost::format(Y("CodecPrivate, length %1%%2%")) % c_priv.GetSize() % fourcc_buffer); - } else if (is_id(l3, KaxCodecName)) + } else if (Is(l3)) show_element(l3, 3, boost::format(Y("Codec name: %1%")) % static_cast(l3)->GetValueUTF8()); #if MATROSKA_VERSION >= 2 - else if (is_id(l3, KaxCodecSettings)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("Codec settings: %1%")) % static_cast(l3)->GetValueUTF8()); - else if (is_id(l3, KaxCodecInfoURL)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("Codec info URL: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxCodecDownloadURL)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("Codec download URL: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxCodecDecodeAll)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("Codec decode all: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxTrackOverlay)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("Track overlay: %1%")) % static_cast(l3)->GetValue()); #endif // MATROSKA_VERSION >= 2 - else if (is_id(l3, KaxTrackMinCache)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("MinCache: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxTrackMaxCache)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("MaxCache: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxTrackDefaultDuration)) { + else if (Is(l3)) { track->default_duration = static_cast(l3)->GetValue(); show_element(l3, 3, boost::format(Y("Default duration: %|1$.3f|ms (%|2$.3f| frames/fields per second for a video track)")) @@ -899,34 +899,34 @@ handle_tracks(EbmlStream *&es, % (1000000000.0 / static_cast(track->default_duration)) ).str()); - } else if (is_id(l3, KaxTrackFlagLacing)) + } else if (Is(l3)) show_element(l3, 3, boost::format(Y("Lacing flag: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxTrackFlagDefault)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("Default flag: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxTrackFlagForced)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("Forced flag: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxTrackLanguage)) { + else if (Is(l3)) { auto language = static_cast(l3)->GetValue(); show_element(l3, 3, boost::format(Y("Language: %1%")) % language); summary.push_back((boost::format(Y("language: %1%")) % language).str()); - } else if (is_id(l3, KaxTrackTimecodeScale)) + } else if (Is(l3)) show_element(l3, 3, boost::format(Y("Timecode scale: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxMaxBlockAdditionID)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("Max BlockAddition ID: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxContentEncodings)) + else if (Is(l3)) handle_content_encodings(es, l3); - else if (is_id(l3, KaxCodecDelay)) { + else if (Is(l3)) { auto value = static_cast(l3)->GetValue(); show_element(l3, 3, boost::format(Y("Codec delay: %|1$.3f|ms (%2%ns)")) % (static_cast(value) / 1000000.0) % value); - } else if (is_id(l3, KaxSeekPreRoll)) { + } else if (Is(l3)) { auto value = static_cast(l3)->GetValue(); show_element(l3, 3, boost::format(Y("Seek pre-roll: %|1$.3f|ms (%2%ns)")) % (static_cast(value) / 1000000.0) % value); @@ -967,28 +967,28 @@ handle_seek_head(EbmlStream *&es, read_master(m1, es, EBML_CONTEXT(l1), upper_lvl_el, element_found); for (auto l2 : *m1) - if (is_id(l2, KaxSeek)) { + if (Is(l2)) { show_element(l2, 2, Y("Seek entry")); for (auto l3 : *static_cast(l2)) - if (is_id(l3, KaxSeekID)) { + if (Is(l3)) { KaxSeekID &seek_id = static_cast(*l3); EbmlId id(seek_id.GetBuffer(), seek_id.GetSize()); show_element(l3, 3, boost::format(Y("Seek ID: %1% (%2%)")) % to_hex(seek_id) - % ( EBML_ID(KaxInfo) == id ? "KaxInfo" - : EBML_ID(KaxCluster) == id ? "KaxCluster" - : EBML_ID(KaxTracks) == id ? "KaxTracks" - : EBML_ID(KaxCues) == id ? "KaxCues" - : EBML_ID(KaxAttachments) == id ? "KaxAttachments" - : EBML_ID(KaxChapters) == id ? "KaxChapters" - : EBML_ID(KaxTags) == id ? "KaxTags" - : EBML_ID(KaxSeekHead) == id ? "KaxSeekHead" - : "unknown")); + % ( Is(id) ? "KaxInfo" + : Is(id) ? "KaxCluster" + : Is(id) ? "KaxTracks" + : Is(id) ? "KaxCues" + : Is(id) ? "KaxAttachments" + : Is(id) ? "KaxChapters" + : Is(id) ? "KaxTags" + : Is(id) ? "KaxSeekHead" + : "unknown")); - } else if (is_id(l3, KaxSeekPosition)) + } else if (Is(l3)) show_element(l3, 3, boost::format(Y("Seek position: %1%")) % static_cast(l3)->GetValue()); else if (!is_global(es, l3, 3)) @@ -1015,50 +1015,50 @@ handle_cues(EbmlStream *&es, read_master(m1, es, EBML_CONTEXT(l1), upper_lvl_el, element_found); for (auto l2 : *m1) - if (is_id(l2, KaxCuePoint)) { + if (Is(l2)) { show_element(l2, 2, Y("Cue point")); for (auto l3 : *static_cast(l2)) - if (is_id(l3, KaxCueTime)) + if (Is(l3)) show_element(l3, 3, boost::format(Y("Cue time: %|1$.3f|s")) % (s_tc_scale * static_cast(static_cast(l3)->GetValue()) / 1000000000.0)); - else if (is_id(l3, KaxCueTrackPositions)) { + else if (Is(l3)) { show_element(l3, 3, Y("Cue track positions")); for (auto l4 : *static_cast(l3)) - if (is_id(l4, KaxCueTrack)) + if (Is(l4)) show_element(l4, 4, boost::format(Y("Cue track: %1%")) % static_cast(l4)->GetValue()); - else if (is_id(l4, KaxCueClusterPosition)) + else if (Is(l4)) show_element(l4, 4, boost::format(Y("Cue cluster position: %1%")) % static_cast(l4)->GetValue()); - else if (is_id(l4, KaxCueRelativePosition)) + else if (Is(l4)) show_element(l4, 4, boost::format(Y("Cue relative position: %1%")) % static_cast(l4)->GetValue()); - else if (is_id(l4, KaxCueDuration)) + else if (Is(l4)) show_element(l4, 4, boost::format(Y("Cue duration: %1%")) % format_timecode(static_cast(l4)->GetValue() * s_tc_scale)); - else if (is_id(l4, KaxCueBlockNumber)) + else if (Is(l4)) show_element(l4, 4, boost::format(Y("Cue block number: %1%")) % static_cast(l4)->GetValue()); #if MATROSKA_VERSION >= 2 - else if (is_id(l4, KaxCueCodecState)) + else if (Is(l4)) show_element(l4, 4, boost::format(Y("Cue codec state: %1%")) % static_cast(l4)->GetValue()); - else if (is_id(l4, KaxCueReference)) { + else if (Is(l4)) { show_element(l4, 4, Y("Cue reference")); for (auto l5 : *static_cast(l4)) - if (is_id(l5, KaxCueRefTime)) + if (Is(l5)) show_element(l5, 5, boost::format(Y("Cue ref time: %|1$.3f|s")) % s_tc_scale % (static_cast(l5)->GetValue() / 1000000000.0)); - else if (is_id(l5, KaxCueRefCluster)) + else if (Is(l5)) show_element(l5, 5, boost::format(Y("Cue ref cluster: %1%")) % static_cast(l5)->GetValue()); - else if (is_id(l5, KaxCueRefNumber)) + else if (Is(l5)) show_element(l5, 5, boost::format(Y("Cue ref number: %1%")) % static_cast(l5)->GetValue()); - else if (is_id(l5, KaxCueRefCodecState)) + else if (Is(l5)) show_element(l5, 5, boost::format(Y("Cue ref codec state: %1%")) % static_cast(l5)->GetValue()); else if (!is_global(es, l5, 5)) @@ -1088,23 +1088,23 @@ handle_attachments(EbmlStream *&es, read_master(m1, es, EBML_CONTEXT(l1), upper_lvl_el, element_found); for (auto l2 : *m1) - if (is_id(l2, KaxAttached)) { + if (Is(l2)) { show_element(l2, 2, Y("Attached")); for (auto l3 : *static_cast(l2)) - if (is_id(l3, KaxFileDescription)) + if (Is(l3)) show_element(l3, 3, boost::format(Y("File description: %1%")) % static_cast(l3)->GetValueUTF8()); - else if (is_id(l3, KaxFileName)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("File name: %1%")) % static_cast(l3)->GetValueUTF8()); - else if (is_id(l3, KaxMimeType)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("Mime type: %1%")) % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxFileData)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("File data, size: %1%")) % static_cast(l3)->GetSize()); - else if (is_id(l3, KaxFileUID)) + else if (Is(l3)) show_element(l3, 3, boost::format(Y("File UID: %1%")) % static_cast(l3)->GetValue()); else if (!is_global(es, l3, 3)) @@ -1120,7 +1120,7 @@ handle_silent_track(EbmlStream *&es, show_element(l2, 2, "Silent Tracks"); for (auto l3 : *static_cast(l2)) - if (is_id(l3, KaxClusterSilentTrackNumber)) + if (Is(l3)) show_element(l3, 3, boost::format(Y("Silent Track Number: %1%")) % static_cast(l3)->GetValue()); else if (!is_global(es, l3, 3)) @@ -1147,7 +1147,7 @@ handle_block_group(EbmlStream *&es, float bduration = -1.0; for (auto l3 : *static_cast(l2)) - if (is_id(l3, KaxBlock)) { + if (Is(l3)) { KaxBlock &block = *static_cast(l3); block.SetParent(*cluster); show_element(l3, 3, @@ -1182,12 +1182,12 @@ handle_block_group(EbmlStream *&es, frame_pos -= data.Size(); } - } else if (is_id(l3, KaxBlockDuration)) { + } else if (Is(l3)) { auto duration = static_cast(l3)->GetValue(); bduration = static_cast(duration) * s_tc_scale / 1000000.0; show_element(l3, 3, BF_BLOCK_GROUP_DURATION % (duration * s_tc_scale / 1000000) % (duration * s_tc_scale % 1000000)); - } else if (is_id(l3, KaxReferenceBlock)) { + } else if (Is(l3)) { int64_t reference = static_cast(l3)->GetValue() * s_tc_scale; if (0 >= reference) { @@ -1200,37 +1200,37 @@ handle_block_group(EbmlStream *&es, show_element(l3, 3, BF_BLOCK_GROUP_REFERENCE_2 % (reference / 1000000) % (reference % 1000000)); } - } else if (is_id(l3, KaxReferencePriority)) + } else if (Is(l3)) show_element(l3, 3, BF_BLOCK_GROUP_REFERENCE_PRIORITY % static_cast(l3)->GetValue()); #if MATROSKA_VERSION >= 2 - else if (is_id(l3, KaxBlockVirtual)) + else if (Is(l3)) show_element(l3, 3, BF_BLOCK_GROUP_VIRTUAL % format_binary(static_cast(l3))); - else if (is_id(l3, KaxReferenceVirtual)) + else if (Is(l3)) show_element(l3, 3, BF_BLOCK_GROUP_REFERENCE_VIRTUAL % static_cast(l3)->GetValue()); - else if (is_id(l3, KaxCodecState)) + else if (Is(l3)) show_element(l3, 3, BF_CODEC_STATE % format_binary(static_cast(l3))); - else if (is_id(l3, KaxDiscardPadding)) { + else if (Is(l3)) { auto value = static_cast(l3)->GetValue(); show_element(l3, 3, BF_BLOCK_GROUP_DISCARD_PADDING % (static_cast(value) / 1000000.0) % value); } #endif // MATROSKA_VERSION >= 2 - else if (is_id(l3, KaxBlockAdditions)) { + else if (Is(l3)) { show_element(l3, 3, Y("Additions")); for (auto l4 : *static_cast(l3)) - if (is_id(l4, KaxBlockMore)) { + if (Is(l4)) { show_element(l4, 4, Y("More")); for (auto l5 : *static_cast(l4)) - if (is_id(l5, KaxBlockAddID)) + if (Is(l5)) show_element(l5, 5, BF_BLOCK_GROUP_ADD_ID % static_cast(l5)->GetValue()); - else if (is_id(l5, KaxBlockAdditional)) + else if (Is(l5)) show_element(l5, 5, BF_BLOCK_GROUP_ADDITIONAL % format_binary(static_cast(l5))); else if (!is_global(es, l5, 5)) @@ -1239,27 +1239,27 @@ handle_block_group(EbmlStream *&es, } else if (!is_global(es, l4, 4)) show_unknown_element(l4, 4); - } else if (is_id(l3, KaxSlices)) { + } else if (Is(l3)) { show_element(l3, 3, Y("Slices")); for (auto l4 : *static_cast(l3)) - if (is_id(l4, KaxTimeSlice)) { + if (Is(l4)) { show_element(l4, 4, Y("Time slice")); for (auto l5 : *static_cast(l4)) - if (is_id(l5, KaxSliceLaceNumber)) + if (Is(l5)) show_element(l5, 5, BF_BLOCK_GROUP_SLICE_LACE % static_cast(l5)->GetValue()); - else if (is_id(l5, KaxSliceFrameNumber)) + else if (Is(l5)) show_element(l5, 5, BF_BLOCK_GROUP_SLICE_FRAME % static_cast(l5)->GetValue()); - else if (is_id(l5, KaxSliceDelay)) + else if (Is(l5)) show_element(l5, 5, BF_BLOCK_GROUP_SLICE_DELAY % (static_cast(static_cast(l5)->GetValue()) * s_tc_scale / 1000000.0)); - else if (is_id(l5, KaxSliceDuration)) + else if (Is(l5)) show_element(l5, 5, BF_BLOCK_GROUP_SLICE_DURATION % (static_cast(static_cast(l5)->GetValue()) * s_tc_scale / 1000000.0)); - else if (is_id(l5, KaxSliceBlockAddID)) + else if (Is(l5)) show_element(l5, 5, BF_BLOCK_GROUP_SLICE_ADD_ID % static_cast(l5)->GetValue()); else if (!is_global(es, l5, 5)) @@ -1432,22 +1432,22 @@ handle_cluster(EbmlStream *&es, cluster->InitTimecode(FindChildValue(m1), s_tc_scale); for (auto l2 : *m1) - if (is_id(l2, KaxClusterTimecode)) + if (Is(l2)) show_element(l2, 2, BF_CLUSTER_TIMECODE % (static_cast(static_cast(l2)->GetValue()) * s_tc_scale / 1000000000.0)); - else if (is_id(l2, KaxClusterPosition)) + else if (Is(l2)) show_element(l2, 2, BF_CLUSTER_POSITION % static_cast(l2)->GetValue()); - else if (is_id(l2, KaxClusterPrevSize)) + else if (Is(l2)) show_element(l2, 2, BF_CLUSTER_PREVIOUS_SIZE % static_cast(l2)->GetValue()); - else if (is_id(l2, KaxClusterSilentTracks)) + else if (Is(l2)) handle_silent_track(es, l2); - else if (is_id(l2, KaxBlockGroup)) + else if (Is(l2)) handle_block_group(es, l2, cluster); - else if (is_id(l2, KaxSimpleBlock)) + else if (Is(l2)) handle_simple_block(es, l2, cluster); else if (!is_global(es, l2, 2)) @@ -1538,25 +1538,25 @@ handle_ebml_head(EbmlElement *l0, e->ReadData(*in); - if (is_id(e, EVersion)) + if (Is(e)) show_element(e, 1, boost::format(Y("EBML version: %1%")) % static_cast(e)->GetValue()); - else if (is_id(e, EReadVersion)) + else if (Is(e)) show_element(e, 1, boost::format(Y("EBML read version: %1%")) % static_cast(e)->GetValue()); - else if (is_id(e, EMaxIdLength)) + else if (Is(e)) show_element(e, 1, boost::format(Y("EBML maximum ID length: %1%")) % static_cast(e)->GetValue()); - else if (is_id(e, EMaxSizeLength)) + else if (Is(e)) show_element(e, 1, boost::format(Y("EBML maximum size length: %1%")) % static_cast(e)->GetValue()); - else if (is_id(e, EDocType)) + else if (Is(e)) show_element(e, 1, boost::format(Y("Doc type: %1%")) % std::string(*static_cast(e))); - else if (is_id(e, EDocTypeVersion)) + else if (Is(e)) show_element(e, 1, boost::format(Y("Doc type version: %1%")) % static_cast(e)->GetValue()); - else if (is_id(e, EDocTypeReadVersion)) + else if (Is(e)) show_element(e, 1, boost::format(Y("Doc type read version: %1%")) % static_cast(e)->GetValue()); else @@ -1640,7 +1640,7 @@ process_file(const std::string &file_name) { return false; } - if (is_id(l0, KaxSegment)) { + if (Is(l0)) { if (!l0->IsFiniteSize()) show_element(l0, 0, Y("Segment, size unknown")); else @@ -1662,16 +1662,16 @@ process_file(const std::string &file_name) { while ((l1 = kax_file->read_next_level1_element())) { std::shared_ptr af_l1(l1); - if (is_id(l1, KaxInfo)) + if (Is(l1)) handle_info(es, upper_lvl_el, l1); - else if (is_id(l1, KaxTracks)) + else if (Is(l1)) handle_tracks(es, upper_lvl_el, l1); - else if (is_id(l1, KaxSeekHead)) + else if (Is(l1)) handle_seek_head(es, upper_lvl_el, l1); - else if (is_id(l1, KaxCluster)) { + else if (Is(l1)) { show_element(l1, 1, Y("Cluster")); if ((g_options.m_verbose == 0) && !g_options.m_show_summary) { delete l0; @@ -1681,18 +1681,18 @@ process_file(const std::string &file_name) { } handle_cluster(es, upper_lvl_el, l1, file_size); - } else if (is_id(l1, KaxCues)) + } else if (Is(l1)) handle_cues(es, upper_lvl_el, l1); // Weee! Attachments! - else if (is_id(l1, KaxAttachments)) + else if (Is(l1)) handle_attachments(es, upper_lvl_el, l1); - else if (is_id(l1, KaxChapters)) + else if (Is(l1)) handle_chapters(es, upper_lvl_el, l1); // Let's handle some TAGS. - else if (is_id(l1, KaxTags)) + else if (Is(l1)) handle_tags(es, upper_lvl_el, l1); else if (!is_global(es, l1, 1)) diff --git a/src/input/r_matroska.cpp b/src/input/r_matroska.cpp index d018018ce..3b038cb7b 100644 --- a/src/input/r_matroska.cpp +++ b/src/input/r_matroska.cpp @@ -102,7 +102,7 @@ using namespace libmatroska; #define in_parent(p) \ (!p->IsFiniteSize() || (m_in->getFilePointer() < (p->GetElementPosition() + p->HeadSize() + p->GetSize()))) -#define is_ebmlvoid(e) (EbmlId(*e) == EBML_ID(EbmlVoid)) +#define is_ebmlvoid(e) (Is(e)) #define MAGIC_MKV 0x1a45dfa3 @@ -717,7 +717,7 @@ kax_reader_c::handle_tags(mm_io_c *io, tags->Read(*m_es, EBML_CLASS_CONTEXT(KaxTags), upper_lvl_el, l2, true); while (tags->ListSize() > 0) { - if (!(EbmlId(*(*tags)[0]) == EBML_ID(KaxTag))) { + if (!Is((*tags)[0])) { delete (*tags)[0]; tags->Remove(0); continue; @@ -934,7 +934,7 @@ kax_reader_c::read_headers_tracks(mm_io_c *io, io->save_pos(position); EbmlElement *l1 = m_es->FindNextElement(EBML_CONTEXT(l0), upper_lvl_el, 0xFFFFFFFFL, true); - if (!l1 || !is_id(l1, KaxTracks)) { + if (!l1 || !Is(l1)) { delete l1; io->restore_pos(); @@ -1061,7 +1061,7 @@ kax_reader_c::handle_seek_head(mm_io_c *io, seek_head->Read(*m_es, EBML_CLASS_CONTEXT(KaxSeekHead), upper_lvl_el, l2, true); for (auto l2 : *seek_head) { - if (EbmlId(*l2) != EBML_ID(KaxSeek)) + if (!Is(l2)) continue; KaxSeek &seek = *static_cast(l2); @@ -1076,13 +1076,13 @@ kax_reader_c::handle_seek_head(mm_io_c *io, EbmlId id(k_id->GetBuffer(), k_id->GetSize()); - deferred_l1_type_e type = id == EBML_ID(KaxAttachments) ? dl1t_attachments - : id == EBML_ID(KaxChapters) ? dl1t_chapters - : id == EBML_ID(KaxTags) ? dl1t_tags - : id == EBML_ID(KaxTracks) ? dl1t_tracks - : id == EBML_ID(KaxSeekHead) ? dl1t_seek_head - : id == EBML_ID(KaxInfo) ? dl1t_info - : dl1t_unknown; + deferred_l1_type_e type = Is(id) ? dl1t_attachments + : Is(id) ? dl1t_chapters + : Is(id) ? dl1t_tags + : Is(id) ? dl1t_tracks + : Is(id) ? dl1t_seek_head + : Is(id) ? dl1t_info + : dl1t_unknown; if (dl1t_unknown == type) continue; @@ -1138,7 +1138,7 @@ kax_reader_c::read_headers_internal() { mxwarn(Y("matroska_reader: No segment found.\n")); return false; } - if (!(EbmlId(*l0) == EBML_ID(KaxSegment))) { + if (!Is(l0)) { if (verbose) mxwarn(Y("matroska_reader: No segment found.\n")); return false; @@ -1150,25 +1150,25 @@ kax_reader_c::read_headers_internal() { EbmlElement *l1 = m_es->FindNextElement(EBML_CONTEXT(l0), upper_lvl_el, 0xFFFFFFFFL, true, 1); while (l1 && (0 >= upper_lvl_el)) { - if (EbmlId(*l1) == EBML_ID(KaxInfo)) + if (Is(l1)) m_deferred_l1_positions[dl1t_info].push_back(l1->GetElementPosition()); - else if (EbmlId(*l1) == EBML_ID(KaxTracks)) + else if (Is(l1)) m_deferred_l1_positions[dl1t_tracks].push_back(l1->GetElementPosition()); - else if (EbmlId(*l1) == EBML_ID(KaxAttachments)) + else if (Is(l1)) m_deferred_l1_positions[dl1t_attachments].push_back(l1->GetElementPosition()); - else if (EbmlId(*l1) == EBML_ID(KaxChapters)) + else if (Is(l1)) m_deferred_l1_positions[dl1t_chapters].push_back(l1->GetElementPosition()); - else if (EbmlId(*l1) == EBML_ID(KaxTags)) + else if (Is(l1)) m_deferred_l1_positions[dl1t_tags].push_back(l1->GetElementPosition()); - else if (EbmlId(*l1) == EBML_ID(KaxSeekHead)) + else if (Is(l1)) handle_seek_head(m_in.get(), l0, l1->GetElementPosition()); - else if (EbmlId(*l1) == EBML_ID(KaxCluster)) + else if (Is(l1)) cluster = static_cast(l1); else @@ -1778,7 +1778,7 @@ kax_reader_c::read_first_frames(kax_track_t *t, size_t bgidx; for (bgidx = 0; bgidx < cluster->ListSize(); bgidx++) { - if ((EbmlId(*(*cluster)[bgidx]) == EBML_ID(KaxSimpleBlock))) { + if (Is((*cluster)[bgidx])) { KaxSimpleBlock *block_simple = static_cast((*cluster)[bgidx]); block_simple->SetParent(*cluster); @@ -1799,7 +1799,7 @@ kax_reader_c::read_first_frames(kax_track_t *t, block_track->first_frames_data.back()->grab(); } - } else if ((EbmlId(*(*cluster)[bgidx]) == EBML_ID(KaxBlockGroup))) { + } else if (Is((*cluster)[bgidx])) { KaxBlockGroup *block_group = static_cast((*cluster)[bgidx]); KaxBlock *block = static_cast(block_group->FindFirstElt(EBML_INFO(KaxBlock), false)); @@ -1877,10 +1877,10 @@ kax_reader_c::read(generic_packetizer_c *requested_ptzr, for (bgidx = 0; bgidx < cluster->ListSize(); bgidx++) { EbmlElement *element = (*cluster)[bgidx]; - if (EbmlId(*element) == EBML_ID(KaxSimpleBlock)) + if (Is(element)) process_simple_block(cluster, static_cast(element)); - else if (EbmlId(*element) == EBML_ID(KaxBlockGroup)) + else if (Is(element)) process_block_group(cluster, static_cast(element)); } @@ -2125,7 +2125,7 @@ kax_reader_c::process_block_group(KaxCluster *cluster, auto blockadd = FindChild(block_group); if (blockadd) { for (auto &child : *blockadd) { - if (!(is_id(child, KaxBlockMore))) + if (!(Is(child))) continue; auto blockmore = static_cast(child); diff --git a/src/merge/output_control.cpp b/src/merge/output_control.cpp index d69e8fa70..760d7bdc9 100644 --- a/src/merge/output_control.cpp +++ b/src/merge/output_control.cpp @@ -1748,7 +1748,7 @@ finish_file(bool last_file, } else if (!last_file && g_no_linking) { size_t i; for (i = 0; s_kax_infos->ListSize() > i; ++i) - if (EbmlId(*(*s_kax_infos)[i]) == EBML_ID(KaxNextUID)) { + if (Is((*s_kax_infos)[i])) { delete (*s_kax_infos)[i]; s_kax_infos->Remove(i); changed = 2; diff --git a/src/mmg/header_editor/top_level_page.cpp b/src/mmg/header_editor/top_level_page.cpp index 0bc0ff258..0f2ce3546 100644 --- a/src/mmg/header_editor/top_level_page.cpp +++ b/src/mmg/header_editor/top_level_page.cpp @@ -45,7 +45,7 @@ void he_top_level_page_c::do_modifications() { he_page_base_c::do_modifications(); - if (is_id(m_l1_element, KaxInfo)) + if (Is(m_l1_element.get())) fix_mandatory_segmentinfo_elements(m_l1_element.get()); m_l1_element->UpdateSize(true, true); diff --git a/src/mmg/tabs/chapters.cpp b/src/mmg/tabs/chapters.cpp index a781df0e4..e4fbcb604 100644 --- a/src/mmg/tabs/chapters.cpp +++ b/src/mmg/tabs/chapters.cpp @@ -1672,7 +1672,7 @@ tab_chapters::on_drag_end(wxTreeEvent &evt) { new_parent_id = dst; new_parent_master = !src_node->is_atom ? static_cast(m_chapters) : dst_master; - insert_before_in_master = std::distance(new_parent_master->GetElementList().begin(), brng::find_if(new_parent_master->GetElementList(), Is)); + insert_before_in_master = std::distance(new_parent_master->GetElementList().begin(), brng::find_if(new_parent_master->GetElementList(), [](EbmlElement *e) { return Is(e); })); insert_before_in_tree = 0; } else { diff --git a/src/propedit/track_target.cpp b/src/propedit/track_target.cpp index a92b1bc7f..25918b0e2 100644 --- a/src/propedit/track_target.cpp +++ b/src/propedit/track_target.cpp @@ -127,7 +127,7 @@ track_target_c::set_level1_element(ebml_element_cptr level1_element_cp, size_t i; for (i = 0; track_headers->ListSize() > i; ++i) { - if (!is_id((*track_headers)[i], KaxTrackEntry)) + if (!Is((*track_headers)[i])) continue; KaxTrackEntry *track = dynamic_cast((*track_headers)[i]);