mpeg_ts_reader_c::mpeg_ts_reader_c(const track_info_c &ti, const mm_io_cptr &in) : generic_reader_c(ti, in) , PAT_found{} , PMT_found{} , PMT_pid(-1) , es_to_process{} , m_global_timecode_offset{} , input_status(INPUT_PROBE) , track_buffer_ready(-1) , file_done{} , m_packet_sent_to_packetizer{} , m_dont_use_audio_pts{ debugging_requested("mpeg_ts|mpeg_ts_dont_use_audio_pts")} , m_debug_resync{ debugging_requested("mpeg_ts|mpeg_ts_resync")} , m_debug_pat_pmt{ debugging_requested("mpeg_ts|mpeg_ts_pat|mpeg_ts_pmt")} , m_debug_aac{ debugging_requested("mpeg_ts|mpeg_aac")} , m_debug_timecode_wrapping{debugging_requested("mpeg_ts|mpeg_ts_timecode_wrapping")} , m_detected_packet_size{} { auto mpls_in = mm_mpls_multi_file_io_c::open_multi(m_in.get()); if (!mpls_in) return; m_in = mpls_in; m_size = m_in->get_size(); m_chapter_timecodes = std::static_pointer_cast<mm_mpls_multi_file_io_c>(mpls_in)->get_chapters(); }
cues_c::cues_c() : m_num_cue_points_postprocessed{} , m_no_cue_duration{hack_engaged(ENGAGE_NO_CUE_DURATION)} , m_no_cue_relative_position{hack_engaged(ENGAGE_NO_CUE_RELATIVE_POSITION)} , m_debug_cue_duration{debugging_requested("cues|cues_cue_duration")} , m_debug_cue_relative_position{debugging_requested("cues|cues_cue_relative_position")} { }
dts_reader_c::dts_reader_c(const track_info_c &ti, const mm_io_cptr &in) : generic_reader_c(ti, in) , m_af_buf(memory_c::alloc(2 * READ_SIZE)) , m_cur_buf(0) , m_dts14_to_16(false) , m_swap_bytes(false) , m_debug(debugging_requested("dts") || debugging_requested("dts_reader")) { m_buf[0] = reinterpret_cast<unsigned short *>(m_af_buf->get_buffer()); m_buf[1] = reinterpret_cast<unsigned short *>(m_af_buf->get_buffer() + READ_SIZE); }
mm_write_buffer_io_c::mm_write_buffer_io_c(mm_io_c *out, size_t buffer_size, bool delete_out) : mm_proxy_io_c(out, delete_out) , m_af_buffer(memory_c::alloc(buffer_size)) , m_buffer(m_af_buffer->get_buffer()) , m_fill(0) , m_size(buffer_size) , m_debug_seek( debugging_requested("write_buffer_io") || debugging_requested("write_buffer_io_read")) , m_debug_write(debugging_requested("write_buffer_io") || debugging_requested("write_buffer_io_write")) { }
std::string translation_c::get_default_ui_locale() { std::string locale; #if defined(HAVE_LIBINTL_H) # if defined(SYS_WINDOWS) std::string env_var = get_environment_variable("LC_MESSAGES"); if (!env_var.empty() && (-1 != look_up_translation(env_var))) return env_var; env_var = get_environment_variable("LANG"); if (!env_var.empty() && (-1 != look_up_translation(env_var))) return env_var; char *data; int len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, NULL, 0); if (0 < len) { data = (char *)safemalloc(len); memset(data, 0, len); if (0 != GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, data, len)) locale = data; safefree(data); int idx = translation_c::look_up_translation(locale); if (-1 != idx) locale = ms_available_translations[idx].get_locale(); } # else // SYS_WINDOWS char *data = setlocale(LC_MESSAGES, NULL); if (NULL != data) { std::string previous_locale = data; if (debugging_requested("locale")) mxinfo(boost::format("[get_default_ui_locale previous %1%]\n") % previous_locale); setlocale(LC_MESSAGES, ""); data = setlocale(LC_MESSAGES, NULL); if (NULL != data) locale = data; if (debugging_requested("locale")) mxinfo(boost::format("[get_default_ui_locale new %1%]\n") % locale); setlocale(LC_MESSAGES, previous_locale.c_str()); } else if (debugging_requested("locale")) mxinfo(boost::format("[get_default_ui_locale get previous failed]\n")); # endif // SYS_WINDOWS #endif // HAVE_LIBINTL_H return locale; }
void mpeg_ts_track_c::set_pid(uint16_t new_pid) { pid = new_pid; std::string arg; m_debug_delivery = debugging_requested("mpeg_ts") || ( debugging_requested("mpeg_ts_delivery", &arg) && (arg.empty() || (arg == to_string(pid)))); m_debug_timecode_wrapping = debugging_requested("mpeg_ts") || ( debugging_requested("mpeg_ts_timecode_wrapping", &arg) && (arg.empty() || (arg == to_string(pid)))); }
static mtx::xml::document_cptr retrieve_and_parse_xml(std::string const &url) { bool debug = debugging_requested("version_check|releases_info|curl"); std::string data; auto result = url_retriever_c().set_timeout(10, 20).retrieve(url, data); if (0 != result) { mxdebug_if(debug, boost::format("CURL error for %2%: %1%\n") % static_cast<unsigned int>(result) % url); return mtx::xml::document_cptr(); } try { data = compressor_c::create_from_file_name(url)->decompress(data); mtx::xml::document_cptr doc(new pugi::xml_document); std::stringstream sdata(data); auto xml_result = doc->load(sdata); if (xml_result) { mxdebug_if(debug, boost::format("Doc loaded fine from %1%\n") % url); return doc; } else mxdebug_if(debug, boost::format("Doc load error for %1%: %1% at %2%\n") % url % xml_result.description() % xml_result.offset); } catch (mtx::compression_x &ex) { mxdebug_if(debug, boost::format("Decompression exception for %2%: %1%\n") % ex.what() % url); } return mtx::xml::document_cptr(); }
mtx::xml::document_cptr get_releases_info() { std::string url = MTX_RELEASES_INFO_URL; debugging_requested("releases_info_url", &url); return retrieve_and_parse_xml(url + ".gz"); }
AttachmentModel::AttachmentModel(QObject *parent, QList<AttachmentPtr> &attachments) : QAbstractItemModel(parent) , m_attachments(&attachments) , m_debug(debugging_requested("attachment_model")) { }
xtr_oggopus_c::xtr_oggopus_c(const std::string &codec_id, int64_t tid, track_spec_t &tspec) : xtr_oggbase_c{codec_id, tid, tspec} , m_position{timecode_c::ns(0)} { m_debug = debugging_requested("opus|opus_extrator"); }
void translation_c::set_active_translation(const std::string &locale) { int idx = look_up_translation(locale); ms_active_translation_idx = std::max(idx, 0); if (debugging_requested("locale")) mxinfo(boost::format("[translation_c::set_active_translation() active_translation_idx %1% for locale %2%]\n") % ms_active_translation_idx % locale); }
mm_read_buffer_io_c::mm_read_buffer_io_c(mm_io_c *in, size_t buffer_size, bool delete_in) : mm_proxy_io_c(in, delete_in) , m_af_buffer(memory_c::alloc(buffer_size)) , m_buffer(m_af_buffer->get_buffer()) , m_cursor(0) , m_eof(false) , m_fill(0) , m_offset(0) , m_size(buffer_size) , m_buffering(true) , m_debug_seek(debugging_requested("read_buffer_io") || debugging_requested("read_buffer_io_read")) , m_debug_read(debugging_requested("read_buffer_io") || debugging_requested("read_buffer_io_read")) { setFilePointer(0, seek_beginning); }
version_number_t::version_number_t(const std::string &s) : valid(false) { memset(parts, 0, 5 * sizeof(unsigned int)); if (debugging_requested("version_check")) mxinfo(boost::format("version check: Parsing %1%\n") % s); // Match the following: // 4.4.0 // 4.4.0.5 build 123 // 4.4.0-build20101201-123 // mkvmerge v4.4.0 // * Optional prefix "mkvmerge v" // * At least three digits separated by dots // * Optional fourth digit separated by a dot // * Optional build number that can have two forms: // - " build nnn" // - "-buildYYYYMMDD-nnn" (date is ignored) static boost::regex s_version_number_re("^ (?: mkv[a-z]+ \\s+ v)?" // Optional prefix mkv... v "(\\d+) \\. (\\d+) \\. (\\d+)" // Three digitss separated by dots; $1 - $3 "(?: \\. (\\d+) )?" // Optional fourth digit separated by a dot; $4 "(?:" // Optional build number including its prefix " (?: \\s* build \\s*" // Build number prefix: either " build " or... " | - build \\d{8} - )" // ... "-buildYYYYMMDD-" " (\\d+)" // The build number itself; $5 ")?", boost::regex::perl | boost::regex::mod_x); boost::smatch matches; if (!boost::regex_search(s, matches, s_version_number_re)) return; size_t idx; for (idx = 1; 5 >= idx; ++idx) if (!matches[idx].str().empty()) parse_number(matches[idx].str(), parts[idx - 1]); valid = true; if (debugging_requested("version_check")) mxinfo(boost::format("version check: parse OK; result: %1%\n") % to_string()); }
mtx_release_version_t get_latest_release_version() { bool debug = debugging_requested("version_check|curl"); std::string url = MTX_VERSION_CHECK_URL; debugging_requested("version_check_url", &url); mxdebug_if(debug, boost::format("Update check started with URL %1%\n") % url); mtx_release_version_t release; auto doc = retrieve_and_parse_xml(url + ".gz"); #if defined(HAVE_BZLIB_H) if (!doc) doc = retrieve_and_parse_xml(url + ".bz2"); #endif // HAVE_BZLIB_H if (!doc) doc = retrieve_and_parse_xml(url); if (!doc) return release; release.latest_source = version_number_t(doc->select_single_node("/mkvtoolnix-releases/latest-source/version").node().child_value()); release.latest_windows_build = version_number_t((boost::format("%1% build %2%") % doc->select_single_node("/mkvtoolnix-releases/latest-windows-pre/version").node().child_value() % doc->select_single_node("/mkvtoolnix-releases/latest-windows-pre/build").node().child_value()).str()); release.valid = release.latest_source.valid; release.urls["general"] = doc->select_single_node("/mkvtoolnix-releases/latest-source/url").node().child_value(); release.urls["source_code"] = doc->select_single_node("/mkvtoolnix-releases/latest-source/source-code-url").node().child_value(); release.urls["windows_pre_build"] = doc->select_single_node("/mkvtoolnix-releases/latest-windows-pre/url").node().child_value(); for (auto arch : std::vector<std::string>{ "x86", "amd64" }) for (auto package : std::vector<std::string>{ "installer", "portable" }) release.urls[std::string{"windows_"} + arch + "_" + package] = doc->select_single_node((std::string{"/mkvtoolnix-releases/latest-windows-binary/"} + package + "-url/" + arch).c_str()).node().child_value(); if (debug) { std::stringstream urls; brng::for_each(release.urls, [&](std::pair<std::string, std::string> const &kv) { urls << " " << kv.first << ":" << kv.second; }); mxdebug(boost::format("update check: current %1% latest source %2% latest winpre %3% URLs%4%\n") % release.current_version.to_string() % release.latest_source.to_string() % release.latest_windows_build.to_string() % urls); } return release; }
mtx::xml::document_cptr get_releases_info() { std::string url = MTX_RELEASES_INFO_URL; debugging_requested("releases_info_url", &url); #if defined(HAVE_BZLIB_H) auto doc = retrieve_and_parse_xml(url + ".bz2"); if (doc) return doc; #endif // HAVE_BZLIB_H return retrieve_and_parse_xml(url + ".gz"); }
void header_editor_frame_c::on_file_open(wxCommandEvent &) { if (debugging_requested("he_open_std")) { wxString home; wxGetEnv(wxT("HOME"), &home); open_file(wxFileName(wxString::Format(wxT("%s/prog/video/mkvtoolnix/data/muh.mkv"), home.c_str()))); return; } wxFileDialog dlg(this, Z("Open a Matroska file"), last_open_dir, wxEmptyString, wxString::Format(Z("Matroska files (*.mkv;*.mka;*.mks;*.mk3d)|*.mkv;*.mka;*.mks;*.mk3d|%s"), ALLFILES.c_str()), wxFD_OPEN); if (dlg.ShowModal() != wxID_OK) return; open_file(wxFileName(dlg.GetPath())); }
TrackModel::TrackModel(QObject *parent) : QAbstractItemModel(parent) , m_tracks(nullptr) , m_audioIcon(":/icons/16x16/knotify.png") , m_videoIcon(":/icons/16x16/tool-animator.png") , m_subtitleIcon(":/icons/16x16/subtitles.png") , m_attachmentIcon(":/icons/16x16/mail-attachment.png") , m_chaptersIcon(":/icons/16x16/clock.png") , m_tagsIcon(":/icons/16x16/mail-tagged.png") , m_genericIcon(":/icons/16x16/application-octet-stream.png") , m_yesIcon(":/icons/16x16/dialog-ok-apply.png") , m_noIcon(":/icons/16x16/dialog-cancel.png") , m_debug(debugging_requested("track_model")) { }
/** \brief Setup and high level program control Calls the functions for setup, handling the command line arguments, the actual processing and cleaning up. */ int main(int argc, char **argv) { setup(); options_cptr options = propedit_cli_parser_c(command_line_utf8(argc, argv)).run(); if (debugging_requested("dump_options")) { mxinfo("\nDumping options after parsing the command line\n\n"); options->dump_info(); } run(options); mxexit(); }
static void run(options_cptr &options) { console_kax_analyzer_cptr analyzer; try { if (!kax_analyzer_c::probe(options->m_file_name)) mxerror(boost::format("The file '%1%' is not a Matroska file or it could not be found.\n") % options->m_file_name); analyzer = console_kax_analyzer_cptr(new console_kax_analyzer_c(options->m_file_name)); } catch (...) { mxerror(boost::format("The file '%1%' could not be opened for read/write access.\n") % options->m_file_name); } mxinfo(Y("The file is analyzed.\n")); analyzer->set_show_progress(options->m_show_progress); if (!analyzer->process(options->m_parse_mode)) mxerror(Y("This file could not be opened or parsed.\n")); options->find_elements(analyzer.get_object()); options->validate(); if (debugging_requested("dump_options")) { mxinfo("\nDumping options after file and element analysis\n\n"); options->dump_info(); } options->execute(); mxinfo(Y("The changes are written to the file.\n")); write_changes(options, analyzer.get_object()); mxinfo(Y("Done.\n")); mxexit(0); }
void ebml_segmentinfo_converter_c::setup_maps() { m_debug_to_tag_name_map["NextUID"] = "NextSegmentUID"; m_debug_to_tag_name_map["PrevUID"] = "PreviousSegmentUID"; m_debug_to_tag_name_map["NextFilename"] = "NextSegmentFilename"; m_debug_to_tag_name_map["PrevFilename"] = "PreviousSegmentFilename"; m_invalid_elements_map["TimecodeScale"] = true; m_invalid_elements_map["DateUTC"] = true; m_invalid_elements_map["MuxingApp"] = true; m_invalid_elements_map["WritingApp"] = true; m_invalid_elements_map["Duration"] = true; m_invalid_elements_map["Title"] = true; m_limits["SegmentUID"] = limits_t{ true, true, 16, 16 }; m_limits["SegmentFamily"] = limits_t{ true, true, 16, 16 }; m_limits["NextSegmentUID"] = limits_t{ true, true, 16, 16 }; m_limits["PreviousSegmentUID"] = limits_t{ true, true, 16, 16 }; reverse_debug_to_tag_name_map(); if (debugging_requested("ebml_converter_semantics")) dump_semantics("Info"); }
void ebml_chapters_converter_c::setup_maps() { m_formatter_map["ChapterTimeStart"] = format_timecode; m_formatter_map["ChapterTimeEnd"] = format_timecode; m_parser_map["ChapterTimeStart"] = parse_timecode; m_parser_map["ChapterTimeEnd"] = parse_timecode; m_limits["EditionUID"] = limits_t{ true, false, 1, 0 }; m_limits["EditionFlagHidden"] = limits_t{ true, true, 0, 1 }; m_limits["EditionFlagDefault"] = limits_t{ true, true, 0, 1 }; m_limits["EditionFlagOrdered"] = limits_t{ true, true, 0, 1 }; m_limits["ChapterFlagHidden"] = limits_t{ true, true, 0, 1 }; m_limits["ChapterFlagEnabled"] = limits_t{ true, true, 0, 1 }; m_limits["ChapterUID"] = limits_t{ true, false, 1, 0 }; m_limits["ChapterSegmentUID"] = limits_t{ true, false, 1, 0 }; m_limits["ChapterSegmentEditionUID"] = limits_t{ true, false, 1, 0 }; m_limits["ChapterTrackNumber"] = limits_t{ true, false, 1, 0 }; reverse_debug_to_tag_name_map(); if (debugging_requested("ebml_converter_semantics")) dump_semantics("Chapters"); }
void init_locales(std::string locale) { translation_c::initialize_available_translations(); if (debugging_requested("locale")) mxinfo(boost::format("[init_locales start: locale %1%]\n") % locale); std::string locale_dir; std::string default_locale = translation_c::get_default_ui_locale(); if (-1 == translation_c::look_up_translation(locale)) { if (debugging_requested("locale")) mxinfo(boost::format("[init_locales lookup failed; clearing locale]\n")); locale = ""; } if (locale.empty()) { locale = default_locale; if (debugging_requested("locale")) mxinfo(boost::format("[init_locales setting to default locale %1%]\n") % locale); } # if defined(SYS_WINDOWS) set_environment_variable("LANGUAGE", ""); if (!locale.empty()) { // The Windows system headers define LC_MESSAGES but // Windows itself doesn't know it and treats "set_locale(LC_MESSAGES, ...)" // as an error. gettext uses the LANG and LC_MESSAGE environment variables instead. // Windows knows two environments: the system environment that's // modified by SetEnvironmentVariable() and the C library's cache // of said environment which is modified via _putenv(). set_environment_variable("LANG", locale); set_environment_variable("LC_MESSAGES", locale); translation_c::set_active_translation(locale); // Boost's path class uses wide chars on Windows for path // names. Tell that all narrow strings are encoded in UTF-8. std::locale utf8_locale(std::locale(), new mtx::utf8_codecvt_facet); std::locale::global(utf8_locale); boost::filesystem::path::imbue(utf8_locale); } locale_dir = get_installation_path() + "\\locale"; # else // SYS_WINDOWS std::string chosen_locale; try { locale_string_c loc_default(default_locale); std::string loc_req_with_default_codeset(locale_string_c(locale).set_codeset_and_modifier(loc_default).str()); if (setlocale(LC_MESSAGES, loc_req_with_default_codeset.c_str()) != NULL) chosen_locale = loc_req_with_default_codeset; else if (setlocale(LC_MESSAGES, locale.c_str()) != NULL) chosen_locale = locale; else { std::string loc_req_with_utf8 = locale_string_c(locale).set_codeset_and_modifier(locale_string_c("dummy.UTF-8")).str(); if (setlocale(LC_MESSAGES, loc_req_with_utf8.c_str()) != NULL) chosen_locale = loc_req_with_utf8; } } catch (mtx::locale_string_format_x &error) { if (debugging_requested("locale")) mxinfo(boost::format("[init_locales format error in %1%]\n") % error.error()); } if (debugging_requested("locale")) mxinfo(boost::format("[init_locales chosen locale %1%]\n") % chosen_locale); // Hard fallback to "C" locale if no suitable locale was // selected. This can happen if the system has no locales for // "en_US" or "en_US.UTF-8" compiled. if (chosen_locale.empty() && (setlocale(LC_MESSAGES, "C") != NULL)) chosen_locale = "C"; if (chosen_locale.empty()) mxerror(Y("The locale could not be set properly. Check the LANG, LC_ALL and LC_MESSAGES environment variables.\n")); std::locale utf8_locale(std::locale(), new mtx::utf8_codecvt_facet); std::locale::global(utf8_locale); translation_c::set_active_translation(chosen_locale); locale_dir = MTX_LOCALE_DIR; # endif // SYS_WINDOWS # if defined(SYS_APPLE) int result = setenv("LC_MESSAGES", chosen_locale.c_str(), 1); if (debugging_requested("locale")) mxinfo(boost::format("[init_locales setenv() return code: %1%]\n") % result); # endif bindtextdomain("mkvtoolnix", locale_dir.c_str()); textdomain("mkvtoolnix"); bind_textdomain_codeset("mkvtoolnix", "UTF-8"); }