diff --git a/src/common/ac3.cpp b/src/common/ac3.cpp index 8fc803a39..caf114b64 100644 --- a/src/common/ac3.cpp +++ b/src/common/ac3.cpp @@ -340,11 +340,11 @@ int ac3::parser_c::find_consecutive_frames(unsigned char const *buffer, size_t buffer_size, size_t num_required_headers) { + static auto s_debug = debugging_option_c{"ac3_consecutive_frames"}; size_t base = 0; - bool debug = debugging_requested("ac3_consecutive_frames"); do { - mxdebug_if(debug, boost::format("Starting search for %2% headers with base %1%, buffer size %3%\n") % base % num_required_headers % buffer_size); + mxdebug_if(s_debug, boost::format("Starting search for %2% headers with base %1%, buffer size %3%\n") % base % num_required_headers % buffer_size); size_t position = base; @@ -352,7 +352,7 @@ ac3::parser_c::find_consecutive_frames(unsigned char const *buffer, while (((position + 8) < buffer_size) && !first_frame.decode_header(&buffer[position], buffer_size - position)) ++position; - mxdebug_if(debug, boost::format("First frame at %1% valid %2%\n") % position % first_frame.m_valid); + mxdebug_if(s_debug, boost::format("First frame at %1% valid %2%\n") % position % first_frame.m_valid); if (!first_frame.m_valid) return -1; @@ -368,27 +368,27 @@ ac3::parser_c::find_consecutive_frames(unsigned char const *buffer, break; if (8 > current_frame.m_bytes) { - mxdebug_if(debug, boost::format("Current frame at %1% has invalid size %2%\n") % offset % current_frame.m_bytes); + mxdebug_if(s_debug, boost::format("Current frame at %1% has invalid size %2%\n") % offset % current_frame.m_bytes); break; } if ( (current_frame.m_bs_id != first_frame.m_bs_id) && (current_frame.m_channels != first_frame.m_channels) && (current_frame.m_sample_rate != first_frame.m_sample_rate)) { - mxdebug_if(debug, + mxdebug_if(s_debug, boost::format("Current frame at %7% differs from first frame. (first/current) BS ID: %1%/%2% channels: %3%/%4% sample rate: %5%/%6%\n") % first_frame.m_bs_id % current_frame.m_bs_id % first_frame.m_channels % current_frame.m_channels % first_frame.m_sample_rate % current_frame.m_sample_rate % offset); break; } - mxdebug_if(debug, boost::format("Current frame at %1% equals first frame, found %2%\n") % offset % (num_headers_found + 1)); + mxdebug_if(s_debug, boost::format("Current frame at %1% equals first frame, found %2%\n") % offset % (num_headers_found + 1)); ++num_headers_found; offset += current_frame.m_bytes; } if (num_headers_found == num_required_headers) { - mxdebug_if(debug, boost::format("Found required number of headers at %1%\n") % position); + mxdebug_if(s_debug, boost::format("Found required number of headers at %1%\n") % position); return position; } diff --git a/src/common/amf.cpp b/src/common/amf.cpp index 72e3e3958..c9d48eef6 100644 --- a/src/common/amf.cpp +++ b/src/common/amf.cpp @@ -24,7 +24,7 @@ script_parser_c::script_parser_c(memory_cptr const &mem) , m_data{*mem.get()} , m_in_meta_data{} , m_level{} - , m_debug{debugging_requested("amf|amf_script_parser")} + , m_debug{"amf|amf_script_parser"} { } diff --git a/src/common/amf.h b/src/common/amf.h index bc12b1cd1..865999bf9 100644 --- a/src/common/amf.h +++ b/src/common/amf.h @@ -64,7 +64,7 @@ private: bool m_in_meta_data; unsigned int m_level; - bool m_debug; + debugging_option_c m_debug; public: script_parser_c(memory_cptr const &mem); diff --git a/src/common/clpi.cpp b/src/common/clpi.cpp index 2eba26baa..85f070b92 100644 --- a/src/common/clpi.cpp +++ b/src/common/clpi.cpp @@ -71,7 +71,7 @@ clpi::program_stream_t::dump() { clpi::parser_c::parser_c(const std::string &file_name) : m_file_name(file_name) , m_ok(false) - , m_debug(debugging_requested("clpi") || debugging_requested("clpi_parser")) + , m_debug{"clpi|clpi_parser"} { } diff --git a/src/common/clpi.h b/src/common/clpi.h index 695c6e072..ec9a647e8 100644 --- a/src/common/clpi.h +++ b/src/common/clpi.h @@ -57,7 +57,8 @@ namespace clpi { class parser_c { protected: std::string m_file_name; - bool m_ok, m_debug; + bool m_ok; + debugging_option_c m_debug; size_t m_sequence_info_start, m_program_info_start; diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp index 7ba857632..e7e74e9b2 100644 --- a/src/common/command_line.cpp +++ b/src/common/command_line.cpp @@ -189,7 +189,7 @@ handle_common_cli_args(std::vector &args, if ((i + 1) == args.size()) mxerror("Missing argument for '--debug'.\n"); - request_debugging(args[i + 1]); + debugging_c::request(args[i + 1]); args.erase(args.begin() + i, args.begin() + i + 2); } else if (args[i] == "--engage") { diff --git a/src/common/common.cpp b/src/common/common.cpp index 4b38fadf0..6dad7e055 100644 --- a/src/common/common.cpp +++ b/src/common/common.cpp @@ -165,7 +165,7 @@ mtx_common_init(std::string const &program_name) { srand(time(nullptr)); - init_debugging(); + debugging_c::init(); init_hacks(); init_locales(); diff --git a/src/common/curl.cpp b/src/common/curl.cpp index 93674c07f..24cfafeb8 100644 --- a/src/common/curl.cpp +++ b/src/common/curl.cpp @@ -44,7 +44,7 @@ url_retriever_c::url_retriever_c() : m_connect_timeout(10) , m_download_timeout(0) , m_total_size(-1) - , m_debug(debugging_requested("curl|url_retriever")) + , m_debug{"curl|url_retriever"} { } diff --git a/src/common/curl.h b/src/common/curl.h index 576499d6d..7fedc7f4e 100644 --- a/src/common/curl.h +++ b/src/common/curl.h @@ -33,7 +33,7 @@ protected: std::string *m_data; int m_connect_timeout, m_download_timeout; int64_t m_total_size; - bool m_debug; + debugging_option_c m_debug; public: url_retriever_c(); diff --git a/src/common/debugging.cpp b/src/common/debugging.cpp index f241d780f..d89c94153 100644 --- a/src/common/debugging.cpp +++ b/src/common/debugging.cpp @@ -16,17 +16,18 @@ #include "common/logger.h" #include "common/strings/editing.h" -static std::map s_debugging_options; +std::unordered_map debugging_c::ms_debugging_options; +bool debugging_c::ms_send_to_logger = false; bool -debugging_requested(const char *option, - std::string *arg) { - std::vector options = split(option, "|"); +debugging_c::requested(const char *option, + std::string *arg) { + auto options = split(option, "|"); for (auto ¤t_option : options) { - std::map::iterator option_ptr = s_debugging_options.find(current_option); + auto option_ptr = ms_debugging_options.find(current_option); - if (s_debugging_options.end() != option_ptr) { + if (ms_debugging_options.end() != option_ptr) { if (arg) *arg = option_ptr->second; return true; @@ -36,45 +37,54 @@ debugging_requested(const char *option, return false; } -bool -debugging_requested(const std::string &option, - std::string *arg) { - return debugging_requested(option.c_str(), arg); -} - void -request_debugging(const std::string &options, - bool enable) { - std::vector all_options = split(options); +debugging_c::request(const std::string &options, + bool enable) { + auto all_options = split(options); for (auto &one_option : all_options) { - std::vector parts = split(one_option, "=", 2); + auto parts = split(one_option, "=", 2); if (!parts[0].size()) continue; if (parts[0] == "!") - s_debugging_options.clear(); + ms_debugging_options.clear(); else if (parts[0] == "to_logger") debugging_c::send_to_logger(true); else if (!enable) - s_debugging_options.erase(parts[0]); + ms_debugging_options.erase(parts[0]); else - s_debugging_options[parts[0]] = 1 == parts.size() ? std::string("") : parts[1]; + ms_debugging_options[parts[0]] = 1 == parts.size() ? std::string("") : parts[1]; } debugging_option_c::invalidate_cache(); } void -init_debugging() { - std::vector env_vars = { "MKVTOOLNIX_DEBUG", "MTX_DEBUG", balg::to_upper_copy(get_program_name()) + "_DEBUG" }; +debugging_c::init() { + auto env_vars = std::vector{ "MKVTOOLNIX_DEBUG", "MTX_DEBUG", balg::to_upper_copy(get_program_name()) + "_DEBUG" }; for (auto &name : env_vars) { auto value = getenv(name.c_str()); if (value) - request_debugging(value); + request(value); } } +void +debugging_c::send_to_logger(bool enable) { + ms_send_to_logger = enable; +} + +void +debugging_c::output(std::string const &msg) { + if (ms_send_to_logger) + log_it(msg); + else + mxmsg(MXMSG_INFO, msg); +} + +// ------------------------------------------------------------ + std::vector debugging_option_c::ms_registered_options; size_t @@ -93,18 +103,3 @@ debugging_option_c::invalidate_cache() { for (auto &opt : ms_registered_options) opt.m_requested = boost::logic::indeterminate; } - -bool debugging_c::ms_send_to_logger = false; - -void -debugging_c::send_to_logger(bool enable) { - ms_send_to_logger = enable; -} - -void -debugging_c::output(std::string const &msg) { - if (ms_send_to_logger) - log_it(msg); - else - mxmsg(MXMSG_INFO, msg); -} diff --git a/src/common/debugging.h b/src/common/debugging.h index 40ff2892d..f6893432d 100644 --- a/src/common/debugging.h +++ b/src/common/debugging.h @@ -16,12 +16,27 @@ #include "common/common_pch.h" -bool debugging_requested(const char *option, std::string *arg = nullptr); -bool debugging_requested(const std::string &option, std::string *arg = nullptr); -void request_debugging(const std::string &options, bool enable = true); -void init_debugging(); +#include -int parse_debug_interval_arg(const std::string &option, int default_value = 1000, int invalid_value = -1); +class debugging_c { +protected: + static bool ms_send_to_logger; + static std::unordered_map ms_debugging_options; + +public: + static void send_to_logger(bool enable); + static void output(std::string const &msg); + static void output(boost::format const &msg) { + output(msg.str()); + } + + static bool requested(const char *option, std::string *arg = nullptr); + static bool requested(const std::string &option, std::string *arg = nullptr) { + return requested(option.c_str(), arg); + } + static void request(const std::string &options, bool enable = true); + static void init(); +}; class debugging_option_c { struct option_c { @@ -36,14 +51,14 @@ class debugging_option_c { bool get() { if (boost::logic::indeterminate(m_requested)) - m_requested = debugging_requested(m_option); + m_requested = debugging_c::requested(m_option); return m_requested; } }; protected: - size_t m_registered_idx; + mutable size_t m_registered_idx; std::string m_option; private: @@ -56,11 +71,11 @@ public: { } - operator bool() { + operator bool() const { if (m_registered_idx == std::numeric_limits::max()) m_registered_idx = register_option(m_option); - return ms_registered_options[m_registered_idx].get(); + return ms_registered_options.at(m_registered_idx).get(); } public: @@ -68,18 +83,6 @@ public: static void invalidate_cache(); }; -class debugging_c { -protected: - static bool ms_send_to_logger; - -public: - static void send_to_logger(bool enable); - static void output(std::string const &msg); - static void output(boost::format const &msg) { - output(msg.str()); - } -}; - #define mxdebug(msg) debugging_c::output((boost::format("Debug> %1%:%2%: %3%") % __FILE__ % __LINE__ % (msg)).str()) #define mxdebug_if(condition, msg) \ diff --git a/src/common/dts.cpp b/src/common/dts.cpp index c10fc33c4..f3cdbe12b 100644 --- a/src/common/dts.cpp +++ b/src/common/dts.cpp @@ -249,6 +249,8 @@ int find_consecutive_dts_headers(const unsigned char *buf, unsigned int size, unsigned int num) { + static auto s_debug = debugging_option_c{"dts_detection"}; + dts_header_s dts_header, new_header; int pos = find_dts_header(buf, size, &dts_header, false); @@ -260,10 +262,9 @@ find_consecutive_dts_headers(const unsigned char *buf, return pos; unsigned int base = pos; - bool debug = debugging_requested("dts_detection"); do { - mxdebug_if(debug, boost::format("find_cons_dts_h: starting with base at %1%\n") % base); + mxdebug_if(s_debug, boost::format("find_cons_dts_h: starting with base at %1%\n") % base); int offset = dts_header.frame_byte_size; unsigned int i; @@ -274,7 +275,7 @@ find_consecutive_dts_headers(const unsigned char *buf, pos = find_dts_header(&buf[base + offset], size - base - offset, &new_header, false); if (0 == pos) { if (new_header == dts_header) { - mxdebug_if(debug, boost::format("find_cons_dts_h: found good header %1%\n") % i); + mxdebug_if(s_debug, boost::format("find_cons_dts_h: found good header %1%\n") % i); offset += new_header.frame_byte_size; continue; } else diff --git a/src/common/kax_analyzer.cpp b/src/common/kax_analyzer.cpp index f8dc257da..63530422a 100644 --- a/src/common/kax_analyzer.cpp +++ b/src/common/kax_analyzer.cpp @@ -66,7 +66,7 @@ kax_analyzer_c::kax_analyzer_c(std::string file_name) , m_file(nullptr) , m_close_file(true) , m_stream(nullptr) - , m_debugging_requested(debugging_requested("kax_analyzer")) + , m_debugging_requested{"kax_analyzer"} { } @@ -75,7 +75,7 @@ kax_analyzer_c::kax_analyzer_c(mm_file_io_c *file) , m_file(file) , m_close_file(false) , m_stream(nullptr) - , m_debugging_requested(debugging_requested("kax_analyzer")) + , m_debugging_requested{"kax_analyzer"} { } @@ -110,7 +110,7 @@ kax_analyzer_c::_log_debug_message(const std::string &message) { bool kax_analyzer_c::analyzer_debugging_requested(const std::string §ion) { - return m_debugging_requested || debugging_requested(std::string("kax_analyzer_") + section); + return m_debugging_requested || debugging_c::requested(std::string("kax_analyzer_") + section); } void @@ -316,13 +316,13 @@ kax_analyzer_c::read_element(kax_analyzer_data_c *element_data) { return e; } -#define call_and_validate(function_call, hook_name) \ - function_call; \ - debug_dump_elements_maybe(hook_name); \ - validate_data_structures(hook_name); \ - if (analyzer_debugging_requested("verify")) \ - verify_data_structures_against_file(hook_name); \ - if (debugging_requested("kax_analyzer_" hook_name "_break")) \ +#define call_and_validate(function_call, hook_name) \ + function_call; \ + debug_dump_elements_maybe(hook_name); \ + validate_data_structures(hook_name); \ + if (analyzer_debugging_requested("verify")) \ + verify_data_structures_against_file(hook_name); \ + if (debugging_c::requested("kax_analyzer_" hook_name "_break")) \ return uer_success; kax_analyzer_c::update_element_result_e diff --git a/src/common/kax_analyzer.h b/src/common/kax_analyzer.h index 78c1706cc..5c3f24dff 100644 --- a/src/common/kax_analyzer.h +++ b/src/common/kax_analyzer.h @@ -98,7 +98,7 @@ private: std::shared_ptr m_segment; std::map m_meta_seeks_by_position; EbmlStream *m_stream; - bool m_debugging_requested; + debugging_option_c m_debugging_requested; public: // Static functions static bool probe(std::string file_name); diff --git a/src/common/kax_file.cpp b/src/common/kax_file.cpp index a6f85f04d..e4970899d 100644 --- a/src/common/kax_file.cpp +++ b/src/common/kax_file.cpp @@ -33,8 +33,8 @@ kax_file_c::kax_file_c(mm_io_cptr &in) , m_timecode_scale{TIMECODE_SCALE} , m_last_timecode{-1} , m_es(new EbmlStream(*m_in)) - , m_debug_read_next(debugging_requested("kax_file|kax_file_read_next")) - , m_debug_resync(debugging_requested( "kax_file|kax_file_resync")) + , m_debug_read_next{"kax_file|kax_file_read_next"} + , m_debug_resync{ "kax_file|kax_file_resync"} { } diff --git a/src/common/kax_file.h b/src/common/kax_file.h index 7bc46b218..2e3472a23 100644 --- a/src/common/kax_file.h +++ b/src/common/kax_file.h @@ -32,7 +32,7 @@ protected: int64_t m_timecode_scale, m_last_timecode; std::shared_ptr m_es; - bool m_debug_read_next, m_debug_resync; + debugging_option_c m_debug_read_next, m_debug_resync; public: kax_file_c(mm_io_cptr &in); diff --git a/src/common/mm_mpls_multi_file_io.cpp b/src/common/mm_mpls_multi_file_io.cpp index 75b642b01..61d5337de 100644 --- a/src/common/mm_mpls_multi_file_io.cpp +++ b/src/common/mm_mpls_multi_file_io.cpp @@ -6,6 +6,8 @@ #include "common/mm_mpls_multi_file_io.h" #include "common/strings/formatting.h" +debugging_option_c mm_mpls_multi_file_io_c::ms_debug{"mpls|mpls_multi_io"}; + mm_mpls_multi_file_io_c::mm_mpls_multi_file_io_c(std::vector const &file_names, std::string const &display_file_name, mtx::mpls::parser_cptr const &mpls_parser) @@ -35,11 +37,10 @@ mm_mpls_multi_file_io_c::open_multi(std::string const &display_file_name) { mm_io_cptr mm_mpls_multi_file_io_c::open_multi(mm_io_c *in) { - bool debug = debugging_requested("mpls|mpls_multi_io"); auto mpls_parser = std::make_shared(); if (!mpls_parser->parse(in) || mpls_parser->get_playlist().items.empty()) { - mxdebug_if(debug, boost::format("Not handling because %1%\n") % (mpls_parser->is_ok() ? "playlist is empty" : "parser not OK")); + mxdebug_if(ms_debug, boost::format("Not handling because %1%\n") % (mpls_parser->is_ok() ? "playlist is empty" : "parser not OK")); return mm_io_cptr{}; } @@ -51,7 +52,7 @@ mm_mpls_multi_file_io_c::open_multi(mm_io_c *in) { auto have_stream_dir = bfs::exists(stream_dir); - mxdebug_if(debug, boost::format("MPLS dir: %1% have stream dir: %2% stream dir: %3%\n") % mpls_dir.string() % have_stream_dir % stream_dir.string()); + mxdebug_if(ms_debug, boost::format("MPLS dir: %1% have stream dir: %2% stream dir: %3%\n") % mpls_dir.string() % have_stream_dir % stream_dir.string()); auto find_file = [mpls_dir,stream_dir,have_stream_dir](mtx::mpls::play_item_t const &item) -> bfs::path { if (have_stream_dir) { @@ -78,7 +79,7 @@ mm_mpls_multi_file_io_c::open_multi(mm_io_c *in) { for (auto const &item : mpls_parser->get_playlist().items) { auto file = find_file(item); - mxdebug_if(debug, boost::format("Item clip ID: %1% codec ID: %2%: have file? %3% file: %4%\n") % item.clip_id % item.codec_id % !file.empty() % file.string()); + mxdebug_if(ms_debug, boost::format("Item clip ID: %1% codec ID: %2%: have file? %3% file: %4%\n") % item.clip_id % item.codec_id % !file.empty() % file.string()); if (file.empty() || file_names_seen[file.string()]) continue; @@ -86,7 +87,7 @@ mm_mpls_multi_file_io_c::open_multi(mm_io_c *in) { file_names_seen[file.string()] = true; } - mxdebug_if(debug, boost::format("Number of files left: %1%\n") % file_names.size()); + mxdebug_if(ms_debug, boost::format("Number of files left: %1%\n") % file_names.size()); if (file_names.empty()) return mm_io_cptr{}; diff --git a/src/common/mm_mpls_multi_file_io.h b/src/common/mm_mpls_multi_file_io.h index d6d8d8726..56420c552 100644 --- a/src/common/mm_mpls_multi_file_io.h +++ b/src/common/mm_mpls_multi_file_io.h @@ -23,6 +23,9 @@ class mm_mpls_multi_file_io_c: public mm_multi_file_io_c { protected: mtx::mpls::parser_cptr m_mpls_parser; +protected: + static debugging_option_c ms_debug; + public: mm_mpls_multi_file_io_c(const std::vector &file_names, std::string const &display_file_name, mtx::mpls::parser_cptr const &mpls_parser); virtual ~mm_mpls_multi_file_io_c(); diff --git a/src/common/mm_read_buffer_io.cpp b/src/common/mm_read_buffer_io.cpp index b93064503..43e9908fe 100644 --- a/src/common/mm_read_buffer_io.cpp +++ b/src/common/mm_read_buffer_io.cpp @@ -29,8 +29,8 @@ mm_read_buffer_io_c::mm_read_buffer_io_c(mm_io_c *in, , 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")) + , m_debug_seek{"read_buffer_io|read_buffer_io_read"} + , m_debug_read{"read_buffer_io|read_buffer_io_read"} { setFilePointer(0, seek_beginning); } diff --git a/src/common/mm_read_buffer_io.h b/src/common/mm_read_buffer_io.h index f0b8c81de..4d020429f 100644 --- a/src/common/mm_read_buffer_io.h +++ b/src/common/mm_read_buffer_io.h @@ -28,7 +28,8 @@ protected: size_t m_fill; int64_t m_offset; const size_t m_size; - bool m_buffering, m_debug_seek, m_debug_read; + bool m_buffering; + debugging_option_c m_debug_seek, m_debug_read; public: mm_read_buffer_io_c(mm_io_c *in, size_t buffer_size = 1 << 12, bool delete_in = true); diff --git a/src/common/mm_write_buffer_io.cpp b/src/common/mm_write_buffer_io.cpp index 6b54ef3dc..ced9d4a34 100644 --- a/src/common/mm_write_buffer_io.cpp +++ b/src/common/mm_write_buffer_io.cpp @@ -25,8 +25,8 @@ mm_write_buffer_io_c::mm_write_buffer_io_c(mm_io_c *out, , 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")) + , m_debug_seek{ "write_buffer_io|write_buffer_io_read"} + , m_debug_write{"write_buffer_io|write_buffer_io_write"} { } diff --git a/src/common/mm_write_buffer_io.h b/src/common/mm_write_buffer_io.h index b05a52174..f7a76209d 100644 --- a/src/common/mm_write_buffer_io.h +++ b/src/common/mm_write_buffer_io.h @@ -25,7 +25,7 @@ protected: unsigned char *m_buffer; size_t m_fill; const size_t m_size; - bool m_debug_seek, m_debug_write; + debugging_option_c m_debug_seek, m_debug_write; public: mm_write_buffer_io_c(mm_io_c *out, size_t buffer_size, bool delete_out = true); diff --git a/src/common/mpeg4_p10.cpp b/src/common/mpeg4_p10.cpp index 70ccd14a2..224fac3e0 100644 --- a/src/common/mpeg4_p10.cpp +++ b/src/common/mpeg4_p10.cpp @@ -978,24 +978,24 @@ mpeg4::p10::avc_es_parser_c::avc_es_parser_c() , m_have_incomplete_frame(false) , m_ignore_nalu_size_length_errors(false) , m_discard_actual_frames(false) - , m_debug_keyframe_detection(debugging_requested("avc_parser|avc_keyframe_detection")) - , m_debug_nalu_types( debugging_requested("avc_parser|avc_nalu_types")) - , m_debug_timecodes( debugging_requested("avc_parser|avc_timecodes")) - , m_debug_sps_info( debugging_requested("avc_parser|avc_sps|avc_sps_info")) + , m_debug_keyframe_detection{"avc_parser|avc_keyframe_detection"} + , m_debug_nalu_types{ "avc_parser|avc_nalu_types"} + , m_debug_timecodes{ "avc_parser|avc_timecodes"} + , m_debug_sps_info{ "avc_parser|avc_sps|avc_sps_info"} { if (m_debug_nalu_types) init_nalu_names(); } mpeg4::p10::avc_es_parser_c::~avc_es_parser_c() { - mxdebug_if(debugging_requested("avc_statistics"), + mxdebug_if(debugging_c::requested("avc_statistics"), boost::format("AVC statistics: #frames: out %1% discarded %2% #timecodes: in %3% generated %4% discarded %5% num_fields: %6% num_frames: %7%\n") % m_stats.num_frames_out % m_stats.num_frames_discarded % m_stats.num_timecodes_in % m_stats.num_timecodes_generated % m_stats.num_timecodes_discarded % m_stats.num_field_slices % m_stats.num_frame_slices); mxdebug_if(m_debug_timecodes, boost::format("stream_position %1% parsed_position %2%\n") % m_stream_position % m_parsed_position); - if (!debugging_requested("avc_num_slices_by_type")) + if (!debugging_c::requested("avc_num_slices_by_type")) return; static const char *s_type_names[] = { diff --git a/src/common/mpeg4_p10.h b/src/common/mpeg4_p10.h index b8470727d..ca567e149 100644 --- a/src/common/mpeg4_p10.h +++ b/src/common/mpeg4_p10.h @@ -263,7 +263,7 @@ protected: bool m_ignore_nalu_size_length_errors, m_discard_actual_frames; - bool m_debug_keyframe_detection, m_debug_nalu_types, m_debug_timecode_statistics, m_debug_timecodes, m_debug_sps_info; + debugging_option_c m_debug_keyframe_detection, m_debug_nalu_types, m_debug_timecodes, m_debug_sps_info; std::map m_nalu_names_by_type; struct stats_t { diff --git a/src/common/mpls.cpp b/src/common/mpls.cpp index 7dec0ac3b..7014e2195 100644 --- a/src/common/mpls.cpp +++ b/src/common/mpls.cpp @@ -104,7 +104,7 @@ stream_t::dump(std::string const &type) parser_c::parser_c() : m_ok{} - , m_debug{debugging_requested("mpls")} + , m_debug{"mpls"} , m_header(header_t()) { } diff --git a/src/common/mpls.h b/src/common/mpls.h index bdf068184..c08633b3c 100644 --- a/src/common/mpls.h +++ b/src/common/mpls.h @@ -82,7 +82,8 @@ struct playlist_t { class parser_c { protected: - bool m_ok, m_debug; + bool m_ok; + debugging_option_c m_debug; header_t m_header; playlist_t m_playlist; diff --git a/src/common/translation.cpp b/src/common/translation.cpp index 61349c16a..de8ef01e2 100644 --- a/src/common/translation.cpp +++ b/src/common/translation.cpp @@ -115,7 +115,7 @@ translation_c::look_up_translation(int language_id, int sub_language_id) { }); int idx = ptr == ms_available_translations.end() ? -1 : std::distance(ms_available_translations.begin(), ptr); - mxdebug_if(debugging_requested("locale"), boost::format("look_up_translation for 0x%|1$04x|/0x%|2$02x|: %3%\n") % language_id % sub_language_id % idx); + mxdebug_if(debugging_c::requested("locale"), boost::format("look_up_translation for 0x%|1$04x|/0x%|2$02x|: %3%\n") % language_id % sub_language_id % idx); return idx; } @@ -123,7 +123,7 @@ translation_c::look_up_translation(int language_id, int sub_language_id) { std::string translation_c::get_default_ui_locale() { std::string locale; - bool debug = debugging_requested("locale"); + bool debug = debugging_c::requested("locale"); #if defined(HAVE_LIBINTL_H) # if defined(SYS_WINDOWS) @@ -185,7 +185,7 @@ 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")) + if (debugging_c::requested("locale")) mxinfo(boost::format("[translation_c::set_active_translation() active_translation_idx %1% for locale %2%]\n") % ms_active_translation_idx % locale); } @@ -227,21 +227,21 @@ void init_locales(std::string locale) { translation_c::initialize_available_translations(); - if (debugging_requested("locale")) + if (debugging_c::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")) + if (debugging_c::requested("locale")) mxinfo(boost::format("[init_locales lookup failed; clearing locale]\n")); locale = ""; } if (locale.empty()) { locale = default_locale; - if (debugging_requested("locale")) + if (debugging_c::requested("locale")) mxinfo(boost::format("[init_locales setting to default locale %1%]\n") % locale); } @@ -291,11 +291,11 @@ init_locales(std::string locale) { } } catch (mtx::locale_string_format_x &error) { - if (debugging_requested("locale")) + if (debugging_c::requested("locale")) mxinfo(boost::format("[init_locales format error in %1%]\n") % error.error()); } - if (debugging_requested("locale")) + if (debugging_c::requested("locale")) mxinfo(boost::format("[init_locales chosen locale %1%]\n") % chosen_locale); // Hard fallback to "C" locale if no suitable locale was @@ -317,7 +317,7 @@ init_locales(std::string locale) { # if defined(SYS_APPLE) int result = setenv("LC_MESSAGES", chosen_locale.c_str(), 1); - if (debugging_requested("locale")) + if (debugging_c::requested("locale")) mxinfo(boost::format("[init_locales setenv() return code: %1%]\n") % result); # endif diff --git a/src/common/version.cpp b/src/common/version.cpp index 5122f6beb..6985cb07a 100644 --- a/src/common/version.cpp +++ b/src/common/version.cpp @@ -38,7 +38,7 @@ version_number_t::version_number_t(const std::string &s) { memset(parts, 0, 5 * sizeof(unsigned int)); - if (debugging_requested("version_check")) + if (debugging_c::requested("version_check")) mxinfo(boost::format("version check: Parsing %1%\n") % s); // Match the following: @@ -73,7 +73,7 @@ version_number_t::version_number_t(const std::string &s) valid = true; - if (debugging_requested("version_check")) + if (debugging_c::requested("version_check")) mxinfo(boost::format("version check: parse OK; result: %1%\n") % to_string()); } @@ -157,7 +157,7 @@ get_current_version() { #if defined(HAVE_CURL_EASY_H) static mtx::xml::document_cptr retrieve_and_parse_xml(std::string const &url) { - bool debug = debugging_requested("version_check|releases_info|curl"); + bool debug = debugging_c::requested("version_check|releases_info|curl"); std::string data; auto result = url_retriever_c().set_timeout(10, 20).retrieve(url, data); @@ -190,9 +190,9 @@ retrieve_and_parse_xml(std::string const &url) { mtx_release_version_t get_latest_release_version() { - bool debug = debugging_requested("version_check|curl"); + bool debug = debugging_c::requested("version_check|curl"); std::string url = MTX_VERSION_CHECK_URL; - debugging_requested("version_check_url", &url); + debugging_c::requested("version_check_url", &url); mxdebug_if(debug, boost::format("Update check started with URL %1%\n") % url); @@ -229,7 +229,7 @@ get_latest_release_version() { mtx::xml::document_cptr get_releases_info() { std::string url = MTX_RELEASES_INFO_URL; - debugging_requested("releases_info_url", &url); + debugging_c::requested("releases_info_url", &url); return retrieve_and_parse_xml(url + ".gz"); } diff --git a/src/common/xml/ebml_chapters_converter.cpp b/src/common/xml/ebml_chapters_converter.cpp index 30e51b585..ef5e10645 100644 --- a/src/common/xml/ebml_chapters_converter.cpp +++ b/src/common/xml/ebml_chapters_converter.cpp @@ -53,7 +53,7 @@ ebml_chapters_converter_c::setup_maps() { reverse_debug_to_tag_name_map(); - if (debugging_requested("ebml_converter_semantics")) + if (debugging_c::requested("ebml_converter_semantics")) dump_semantics("Chapters"); } diff --git a/src/common/xml/ebml_converter.cpp b/src/common/xml/ebml_converter.cpp index 31bd3af44..61d26ce62 100644 --- a/src/common/xml/ebml_converter.cpp +++ b/src/common/xml/ebml_converter.cpp @@ -352,7 +352,7 @@ ebml_converter_c::to_ebml(std::string const &file_name, ebml_root->Remove(0); - if (debugging_requested("ebml_converter")) + if (debugging_c::requested("ebml_converter")) dump_ebml_elements(master, true); return ebml_master_cptr{master}; diff --git a/src/common/xml/ebml_segmentinfo_converter.cpp b/src/common/xml/ebml_segmentinfo_converter.cpp index 7d3ba52aa..fb910e070 100644 --- a/src/common/xml/ebml_segmentinfo_converter.cpp +++ b/src/common/xml/ebml_segmentinfo_converter.cpp @@ -50,7 +50,7 @@ ebml_segmentinfo_converter_c::setup_maps() { reverse_debug_to_tag_name_map(); - if (debugging_requested("ebml_converter_semantics")) + if (debugging_c::requested("ebml_converter_semantics")) dump_semantics("Info"); } diff --git a/src/common/xml/ebml_tags_converter.cpp b/src/common/xml/ebml_tags_converter.cpp index ae4f067ef..b7fbb2b32 100644 --- a/src/common/xml/ebml_tags_converter.cpp +++ b/src/common/xml/ebml_tags_converter.cpp @@ -49,7 +49,7 @@ ebml_tags_converter_c::setup_maps() { reverse_debug_to_tag_name_map(); - if (debugging_requested("ebml_converter_semantics")) + if (debugging_c::requested("ebml_converter_semantics")) dump_semantics("Tags"); } diff --git a/src/extract/xtr_ogg.cpp b/src/extract/xtr_ogg.cpp index 2def163be..e3ad8288e 100644 --- a/src/extract/xtr_ogg.cpp +++ b/src/extract/xtr_ogg.cpp @@ -359,7 +359,7 @@ xtr_oggopus_c::xtr_oggopus_c(const std::string &codec_id, : xtr_oggbase_c{codec_id, tid, tspec} , m_position{timecode_c::ns(0)} { - m_debug = debugging_requested("opus|opus_extrator"); + m_debug = debugging_c::requested("opus|opus_extrator"); } void diff --git a/src/input/r_avi.cpp b/src/input/r_avi.cpp index 6845539cb..86eb3101c 100644 --- a/src/input/r_avi.cpp +++ b/src/input/r_avi.cpp @@ -117,7 +117,7 @@ avi_reader_c::read_headers() { verify_video_track(); parse_subtitle_chunks(); - if (debugging_requested("avi_dump_video_index")) + if (debugging_c::requested("avi_dump_video_index")) debug_dump_video_index(); } diff --git a/src/input/r_coreaudio.cpp b/src/input/r_coreaudio.cpp index fee4e9582..0c35310cc 100644 --- a/src/input/r_coreaudio.cpp +++ b/src/input/r_coreaudio.cpp @@ -50,9 +50,9 @@ coreaudio_reader_c::coreaudio_reader_c(const track_info_c &ti, , m_frames_per_packet{} , m_channels{} , m_bites_per_sample{} - , m_debug_headers{debugging_requested("coreaudio_reader|coreaudio_reader_headers")} - , m_debug_chunks{ debugging_requested("coreaudio_reader|coreaudio_reader_chunks")} - , m_debug_packets{debugging_requested("coreaudio_reader|coreaudio_reader_packets")} + , m_debug_headers{"coreaudio_reader|coreaudio_reader_headers"} + , m_debug_chunks{ "coreaudio_reader|coreaudio_reader_chunks"} + , m_debug_packets{"coreaudio_reader|coreaudio_reader_packets"} { } diff --git a/src/input/r_coreaudio.h b/src/input/r_coreaudio.h index 852bf4cee..daf79a80f 100644 --- a/src/input/r_coreaudio.h +++ b/src/input/r_coreaudio.h @@ -50,7 +50,7 @@ private: samples_to_timecode_converter_c m_frames_to_timecode; - bool m_debug_headers, m_debug_chunks, m_debug_packets; + debugging_option_c m_debug_headers, m_debug_chunks, m_debug_packets; public: coreaudio_reader_c(const track_info_c &ti, const mm_io_cptr &in); diff --git a/src/input/r_dts.cpp b/src/input/r_dts.cpp index 9d34af461..3a84cf393 100644 --- a/src/input/r_dts.cpp +++ b/src/input/r_dts.cpp @@ -57,7 +57,7 @@ dts_reader_c::dts_reader_c(const track_info_c &ti, , m_cur_buf(0) , m_dts14_to_16(false) , m_swap_bytes(false) - , m_debug(debugging_requested("dts") || debugging_requested("dts_reader")) + , m_debug{"dts|dts_reader"} { m_buf[0] = reinterpret_cast(m_af_buf->get_buffer()); m_buf[1] = reinterpret_cast(m_af_buf->get_buffer() + READ_SIZE); diff --git a/src/input/r_dts.h b/src/input/r_dts.h index 39b5ef2d5..9df3e3f3f 100644 --- a/src/input/r_dts.h +++ b/src/input/r_dts.h @@ -30,7 +30,8 @@ private: unsigned short *m_buf[2]; unsigned int m_cur_buf; dts_header_t m_dtsheader; - bool m_dts14_to_16, m_swap_bytes, m_debug; + bool m_dts14_to_16, m_swap_bytes; + debugging_option_c m_debug; public: dts_reader_c(const track_info_c &ti, const mm_io_cptr &in); diff --git a/src/input/r_flv.cpp b/src/input/r_flv.cpp index afb50dd41..9cb9eeb78 100755 --- a/src/input/r_flv.cpp +++ b/src/input/r_flv.cpp @@ -80,7 +80,7 @@ flv_tag_c::flv_tag_c() , m_timecode_extended{} , m_next_position{} , m_ok{} - , m_debug{debugging_requested("flv_full|flv_tags|flv_tag")} + , m_debug{"flv_full|flv_tags|flv_tag"} { } @@ -253,7 +253,7 @@ flv_reader_c::flv_reader_c(track_info_c const &ti, , m_video_track_idx{0} , m_selected_track_idx{-1} , m_file_done{false} - , m_debug{debugging_requested("flv|flv_full")} + , m_debug{"flv|flv_full"} { } diff --git a/src/input/r_flv.h b/src/input/r_flv.h index c17471ca4..0ef823a45 100755 --- a/src/input/r_flv.h +++ b/src/input/r_flv.h @@ -71,7 +71,8 @@ public: uint32_t m_previous_tag_size; uint8_t m_flags; uint64_t m_data_size, m_timecode, m_timecode_extended, m_next_position; - bool m_ok, m_debug; + bool m_ok; + debugging_option_c m_debug; public: flv_tag_c(); @@ -136,7 +137,7 @@ private: std::vector m_tracks; - bool m_debug; + debugging_option_c m_debug; public: flv_reader_c(const track_info_c &ti, const mm_io_cptr &in); diff --git a/src/input/r_mpeg_ps.cpp b/src/input/r_mpeg_ps.cpp index f4cf216a2..0a1f3c9d5 100644 --- a/src/input/r_mpeg_ps.cpp +++ b/src/input/r_mpeg_ps.cpp @@ -64,7 +64,7 @@ mpeg_ps_reader_c::mpeg_ps_reader_c(const track_info_c &ti, const mm_io_cptr &in) : generic_reader_c(ti, in) , file_done(false) - , m_debug_timecodes(debugging_requested("mpeg_ps|mpeg_ps_timecodes")) + , m_debug_timecodes{"mpeg_ps|mpeg_ps_timecodes"} { } diff --git a/src/input/r_mpeg_ps.h b/src/input/r_mpeg_ps.h index 86ea97ec4..0d4b47f81 100644 --- a/src/input/r_mpeg_ps.h +++ b/src/input/r_mpeg_ps.h @@ -17,6 +17,7 @@ #include "common/common_pch.h" #include "common/bit_cursor.h" +#include "common/debugging.h" #include "common/dts.h" #include "common/mm_multi_file_io.h" #include "common/mpeg1_2.h" @@ -200,7 +201,7 @@ private: std::vector tracks; std::map m_ptzr_to_track_map; - bool m_debug_timecodes; + debugging_option_c m_debug_timecodes; public: mpeg_ps_reader_c(const track_info_c &ti, const mm_io_cptr &in); diff --git a/src/input/r_mpeg_ts.cpp b/src/input/r_mpeg_ts.cpp index 63dce6d9a..d38fb127d 100644 --- a/src/input/r_mpeg_ts.cpp +++ b/src/input/r_mpeg_ts.cpp @@ -281,12 +281,12 @@ 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) + m_debug_delivery = debugging_c::requested("mpeg_ts") + || ( debugging_c::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) + m_debug_timecode_wrapping = debugging_c::requested("mpeg_ts") + || ( debugging_c::requested("mpeg_ts_timecode_wrapping", &arg) && (arg.empty() || (arg == to_string(pid)))); } @@ -391,11 +391,12 @@ mpeg_ts_reader_c::mpeg_ts_reader_c(const track_info_c &ti, , 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_dont_use_audio_pts{ "mpeg_ts|mpeg_ts_dont_use_audio_pts"} + , m_debug_resync{ "mpeg_ts|mpeg_ts_resync"} + , m_debug_pat_pmt{ "mpeg_ts|mpeg_ts_pat|mpeg_ts_pmt"} + , m_debug_aac{ "mpeg_ts|mpeg_aac"} + , m_debug_timecode_wrapping{"mpeg_ts|mpeg_ts_timecode_wrapping"} + , m_debug_clpi{ "clpi"} , m_detected_packet_size{} { auto mpls_in = mm_mpls_multi_file_io_c::open_multi(m_in.get()); @@ -1264,14 +1265,12 @@ mpeg_ts_reader_c::read(generic_packetizer_c *requested_ptzr, bfs::path mpeg_ts_reader_c::find_clip_info_file() { - bool debug = debugging_requested("clpi"); - auto mpls_multi_in = dynamic_cast(get_underlying_input_as_multi_file_io()); auto clpi_file = mpls_multi_in ? mpls_multi_in->get_file_names()[0] : bfs::path{m_ti.m_fname}; clpi_file.replace_extension(".clpi"); - mxdebug_if(debug, boost::format("Checking %1%\n") % clpi_file.string()); + mxdebug_if(m_debug_clpi, boost::format("Checking %1%\n") % clpi_file.string()); if (bfs::exists(clpi_file)) return clpi_file; @@ -1284,16 +1283,16 @@ mpeg_ts_reader_c::find_clip_info_file() { // return clpi_file; clpi_file = path / ".." / "clipinf" / file_name; - mxdebug_if(debug, boost::format("Checking %1%\n") % clpi_file.string()); + mxdebug_if(m_debug_clpi, boost::format("Checking %1%\n") % clpi_file.string()); if (bfs::exists(clpi_file)) return clpi_file; clpi_file = path / ".." / "CLIPINF" / file_name; - mxdebug_if(debug, boost::format("Checking %1%\n") % clpi_file.string()); + mxdebug_if(m_debug_clpi, boost::format("Checking %1%\n") % clpi_file.string()); if (bfs::exists(clpi_file)) return clpi_file; - mxdebug_if(debug, "CLPI not found\n"); + mxdebug_if(m_debug_clpi, "CLPI not found\n"); return bfs::path(); } diff --git a/src/input/r_mpeg_ts.h b/src/input/r_mpeg_ts.h index 5190257c5..e40ca27d5 100644 --- a/src/input/r_mpeg_ts.h +++ b/src/input/r_mpeg_ts.h @@ -374,7 +374,7 @@ protected: std::vector m_chapter_timecodes; - bool m_dont_use_audio_pts, m_debug_resync, m_debug_pat_pmt, m_debug_aac, m_debug_timecode_wrapping; + debugging_option_c m_dont_use_audio_pts, m_debug_resync, m_debug_pat_pmt, m_debug_aac, m_debug_timecode_wrapping, m_debug_clpi; int m_detected_packet_size; diff --git a/src/input/r_pgssup.cpp b/src/input/r_pgssup.cpp index 9c92d0206..066fa8bf2 100644 --- a/src/input/r_pgssup.cpp +++ b/src/input/r_pgssup.cpp @@ -44,7 +44,7 @@ pgssup_reader_c::probe_file(mm_io_c *in, pgssup_reader_c::pgssup_reader_c(const track_info_c &ti, const mm_io_cptr &in) : generic_reader_c(ti, in) - , m_debug(debugging_requested("pgssup_reader")) + , m_debug{"pgssup_reader"} { } diff --git a/src/input/r_pgssup.h b/src/input/r_pgssup.h index a05d74eee..1236895f1 100644 --- a/src/input/r_pgssup.h +++ b/src/input/r_pgssup.h @@ -16,15 +16,14 @@ #include "common/common_pch.h" -#include - +#include "common/debugging.h" #include "common/error.h" #include "common/mm_io.h" #include "merge/pr_generic.h" class pgssup_reader_c: public generic_reader_c { private: - bool m_debug; + debugging_option_c m_debug; public: pgssup_reader_c(const track_info_c &ti, const mm_io_cptr &in); diff --git a/src/input/r_qtmp4.cpp b/src/input/r_qtmp4.cpp index a7560ae1e..fb0a76024 100644 --- a/src/input/r_qtmp4.cpp +++ b/src/input/r_qtmp4.cpp @@ -131,11 +131,11 @@ qtmp4_reader_c::qtmp4_reader_c(const track_info_c &ti, , m_compression_algorithm{} , m_main_dmx(-1) , m_audio_encoder_delay_samples(0) - , m_debug_chapters( debugging_requested("qtmp4") || debugging_requested("qtmp4_full") || debugging_requested("qtmp4_chapters")) - , m_debug_headers( debugging_requested("qtmp4") || debugging_requested("qtmp4_full") || debugging_requested("qtmp4_headers")) - , m_debug_tables( debugging_requested("qtmp4_full") || debugging_requested("qtmp4_tables")) - , m_debug_interleaving(debugging_requested("qtmp4") || debugging_requested("qtmp4_full") || debugging_requested("qtmp4_interleaving")) - , m_debug_resync( debugging_requested("qtmp4|qtmp4_full|qtmp4_resync")) + , m_debug_chapters{ "qtmp4|qtmp4_full|qtmp4_chapters"} + , m_debug_headers{ "qtmp4|qtmp4_full|qtmp4_headers"} + , m_debug_tables{ "qtmp4_full|qtmp4_tables"} + , m_debug_interleaving{"qtmp4|qtmp4_full|qtmp4_interleaving"} + , m_debug_resync{ "qtmp4|qtmp4_full|qtmp4_resync"} { } diff --git a/src/input/r_qtmp4.h b/src/input/r_qtmp4.h index 29eab9b55..67f4487d4 100644 --- a/src/input/r_qtmp4.h +++ b/src/input/r_qtmp4.h @@ -178,7 +178,7 @@ struct qtmp4_demuxer_c { std::string language; - bool m_debug_tables, m_debug_fps, m_debug_headers, m_debug_editlists; + debugging_option_c m_debug_tables, m_debug_fps, m_debug_headers, m_debug_editlists; qtmp4_demuxer_c() : ok{false} @@ -208,10 +208,10 @@ struct qtmp4_demuxer_c { , a_aac_config_parsed{false} , warning_printed{false} , ptzr{-1} - , m_debug_tables{ debugging_requested( "qtmp4_full|qtmp4_tables")} - , m_debug_fps{ debugging_requested("qtmp4|qtmp4_full|qtmp4_fps")} - , m_debug_headers{ debugging_requested("qtmp4|qtmp4_full|qtmp4_headers")} - , m_debug_editlists{debugging_requested("qtmp4|qtmp4_full|qtmp4_editlists")} + , m_debug_tables{ "qtmp4_full|qtmp4_tables"} + , m_debug_fps{ "qtmp4|qtmp4_full|qtmp4_fps"} + , m_debug_headers{ "qtmp4|qtmp4_full|qtmp4_headers"} + , m_debug_editlists{"qtmp4|qtmp4_full|qtmp4_editlists"} { memset(&esds, 0, sizeof(esds_t)); } @@ -334,7 +334,7 @@ private: unsigned int m_audio_encoder_delay_samples; - bool m_debug_chapters, m_debug_headers, m_debug_tables, m_debug_interleaving, m_debug_resync; + debugging_option_c m_debug_chapters, m_debug_headers, m_debug_tables, m_debug_interleaving, m_debug_resync; public: qtmp4_reader_c(const track_info_c &ti, const mm_io_cptr &in); diff --git a/src/input/r_wav.cpp b/src/input/r_wav.cpp index ccac351ae..03ecbeeed 100644 --- a/src/input/r_wav.cpp +++ b/src/input/r_wav.cpp @@ -505,7 +505,7 @@ wav_reader_c::parse_file() { if ((m_cur_data_chunk_idx = find_chunk("data", 0, false)) == -1) throw mtx::input::header_parsing_x(); - if (debugging_requested("wav_reader") || debugging_requested("wav_reader_headers")) + if (debugging_c::requested("wav_reader|wav_reader_headers")) dump_headers(); m_in->setFilePointer(m_chunks[m_cur_data_chunk_idx].pos + sizeof(struct chunk_struct), seek_beginning); @@ -613,7 +613,7 @@ wav_reader_c::read(generic_packetizer_c *, void wav_reader_c::scan_chunks() { wav_chunk_t new_chunk; - bool debug_chunks = debugging_requested("wav_reader") || debugging_requested("wav_reader_chunks"); + bool debug_chunks = debugging_c::requested("wav_reader|wav_reader_chunks"); try { int64_t file_size = m_in->get_size(); diff --git a/src/merge/cluster_helper.cpp b/src/merge/cluster_helper.cpp index bda0d63e5..c984e32d8 100644 --- a/src/merge/cluster_helper.cpp +++ b/src/merge/cluster_helper.cpp @@ -55,10 +55,10 @@ cluster_helper_c::cluster_helper_c() , m_current_split_point(m_split_points.begin()) , m_discarding{false} , m_splitting_and_processed_fully{false} - , m_debug_splitting{debugging_requested("cluster_helper|splitting")} - , m_debug_packets{ debugging_requested("cluster_helper|cluster_helper_packets")} - , m_debug_duration{ debugging_requested("cluster_helper|cluster_helper_duration")} - , m_debug_rendering{debugging_requested("cluster_helper|cluster_helper_rendering")} + , m_debug_splitting{"cluster_helper|splitting"} + , m_debug_packets{ "cluster_helper|cluster_helper_packets"} + , m_debug_duration{ "cluster_helper|cluster_helper_duration"} + , m_debug_rendering{"cluster_helper|cluster_helper_rendering"} { } diff --git a/src/merge/cluster_helper.h b/src/merge/cluster_helper.h index 7de08fc8f..8a3dade99 100644 --- a/src/merge/cluster_helper.h +++ b/src/merge/cluster_helper.h @@ -61,7 +61,7 @@ private: bool m_discarding, m_splitting_and_processed_fully; - bool m_debug_splitting, m_debug_packets, m_debug_duration, m_debug_rendering; + debugging_option_c m_debug_splitting, m_debug_packets, m_debug_duration, m_debug_rendering; public: cluster_helper_c(); diff --git a/src/merge/cues.cpp b/src/merge/cues.cpp index 27e1d9e8c..98a590127 100644 --- a/src/merge/cues.cpp +++ b/src/merge/cues.cpp @@ -29,8 +29,8 @@ 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")} + , m_debug_cue_duration{ "cues|cues_cue_duration"} + , m_debug_cue_relative_position{"cues|cues_cue_relative_position"} { } diff --git a/src/merge/cues.h b/src/merge/cues.h index 51d2c6900..5335ff37d 100644 --- a/src/merge/cues.h +++ b/src/merge/cues.h @@ -38,7 +38,8 @@ protected: std::map m_id_timecode_duration_map, m_codec_state_position_map; size_t m_num_cue_points_postprocessed; - bool m_no_cue_duration, m_no_cue_relative_position, m_debug_cue_duration, m_debug_cue_relative_position; + bool m_no_cue_duration, m_no_cue_relative_position; + debugging_option_c m_debug_cue_duration, m_debug_cue_relative_position; protected: static cues_cptr s_cues; diff --git a/src/merge/debugging.cpp b/src/merge/debugging.cpp deleted file mode 100644 index 4ffcd21c0..000000000 --- a/src/merge/debugging.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - mkvmerge -- utility for splicing together matroska files - from component media subtypes - - Distributed under the GPL - see the file COPYING for details - or visit http://www.gnu.org/copyleft/gpl.html - - mkvmerge debugging routines - - Written by Moritz Bunkus . -*/ - -#include "common/common_pch.h" - -#include "common/fs_sys_helpers.h" -#include "common/output.h" -#include "common/strings/editing.h" -#include "common/strings/parsing.h" -#include "merge/debugging.h" -#include "merge/output_control.h" - -static int s_debug_memory_usage_details = -1; - -static void -debug_memory_usage_details_hook() { - if (-1 == s_debug_memory_usage_details) - return; - - static int64_t s_previous_call = 0; - - int64_t now = get_current_time_millis(); - if ((now - s_previous_call) < s_debug_memory_usage_details) - return; - - s_previous_call = now; - - std::string timecode = (boost::format("memory_usage_details :: %1%.%|2$04d| :: ") % (now / 1000) % (now % 1000)).str(); - - for (auto &file : g_files) { - mxinfo(boost::format("%1%reader :: %2% :: %3%\n") % timecode % file.name % file.reader->get_queued_bytes()); - - for (auto packetizer : file.reader->m_reader_packetizers) - mxinfo(boost::format("%1%packetizer :: %2% :: %3% :: %4%\n") % timecode % packetizer->m_ti.m_id % typeid(*packetizer).name() % packetizer->get_queued_bytes()); - } -} - -int -parse_debug_interval_arg(const std::string &option, - int default_value, - int invalid_value) { - int value = invalid_value; - - std::string arg; - if (!debugging_requested(option, &arg)) - return value; - - if (arg.empty() || !parse_number(arg, value) || (0 >= value)) - value = default_value; - - if (250 > value) - value *= 1000; - - return value; -} - -void -debug_run_main_loop_hooks() { - static bool s_main_loop_hooks_initialized = false; - if (!s_main_loop_hooks_initialized) { - s_main_loop_hooks_initialized = true; - - s_debug_memory_usage_details = parse_debug_interval_arg("memory_usage_details"); - } - - debug_memory_usage_details_hook(); -} - diff --git a/src/merge/debugging.h b/src/merge/debugging.h deleted file mode 100644 index c041fda3e..000000000 --- a/src/merge/debugging.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - mkvmerge -- utility for splicing together matroska files - from component media subtypes - - Distributed under the GPL - see the file COPYING for details - or visit http://www.gnu.org/copyleft/gpl.html - - mkvmerge debugging routines - - Written by Moritz Bunkus . -*/ - -#ifndef MTX_MERGE_DEBUGGING_H -#define MTX_MERGE_DEBUGGING_H - -void debug_run_main_loop_hooks(); - -#endif // MTX_MERGE_DEBUGGING_H diff --git a/src/merge/output_control.cpp b/src/merge/output_control.cpp index 3e97194f6..d69e8fa70 100644 --- a/src/merge/output_control.cpp +++ b/src/merge/output_control.cpp @@ -112,7 +112,6 @@ #include "merge/cues.h" #include "merge/mkvmerge.h" #include "merge/output_control.h" -#include "merge/debugging.h" #include "merge/webm.h" using namespace libmatroska; @@ -193,8 +192,8 @@ std::string g_splitting_by_chapters_arg; append_mode_e g_append_mode = APPEND_MODE_FILE_BASED; bool s_appending_files = false; -bool s_debug_appending = false; -bool s_debug_rerender_track_headers = false; +auto s_debug_appending = debugging_option_c{"append|appending"}; +auto s_debug_rerender_track_headers = debugging_option_c{"rerender|rerender_track_headers"}; bool g_stereo_mode_used = false; @@ -521,13 +520,10 @@ determine_display_reader() { */ static void display_progress(bool is_100percent = false) { - static boost::tribool s_no_progress{boost::logic::indeterminate}; + static auto s_no_progress = debugging_option_c{"no_progress"}; static int64_t s_previous_progress_on = 0; static int s_previous_percentage = -1; - if (boost::logic::indeterminate(s_no_progress)) - s_no_progress = debugging_requested("no_progress"); - if (s_no_progress) return; @@ -645,7 +641,7 @@ set_timecode_scale() { highest_sample_rate = std::max(static_cast(ptzr.packetizer->get_audio_sampling_freq()), highest_sample_rate); } - bool debug = debugging_requested("set_timecode_scale|timecode_scale"); + bool debug = debugging_c::requested("set_timecode_scale|timecode_scale"); mxdebug_if(debug, boost::format("timecode_scale: %1% audio present: %2% video present: %3% highest sample rate: %4%\n") % ( TIMECODE_SCALE_MODE_NORMAL == g_timecode_scale_mode ? "normal" @@ -1609,7 +1605,8 @@ prepare_tags_for_rendering() { */ void create_next_output_file() { - mxdebug_if(debugging_requested("splitting"), boost::format("splitting: Create next output file; splitting? %1% discarding? %2%\n") % g_cluster_helper->splitting() % g_cluster_helper->discarding()); + auto s_debug = debugging_option_c{"splitting"}; + mxdebug_if(s_debug, boost::format("splitting: Create next output file; splitting? %1% discarding? %2%\n") % g_cluster_helper->splitting() % g_cluster_helper->discarding()); auto this_outfile = g_cluster_helper->split_mode_produces_many_files() ? create_output_name() : g_outfile; g_kax_segment = new KaxSegment(); @@ -1642,9 +1639,9 @@ create_next_output_file() { static void add_chapters_for_current_part() { - bool debug = debugging_requested("splitting_chapters"); + auto s_debug = debugging_option_c{"splitting_chapters"}; - mxdebug_if(debug, boost::format("Adding chapters. have_global? %1% splitting? %2%\n") % !!g_kax_chapters % g_cluster_helper->splitting()); + mxdebug_if(s_debug, boost::format("Adding chapters. have_global? %1% splitting? %2%\n") % !!g_kax_chapters % g_cluster_helper->splitting()); if (!g_cluster_helper->splitting()) { s_chapters_in_this_file = clone(g_kax_chapters); @@ -1660,7 +1657,7 @@ add_chapters_for_current_part() { auto chapters_here = clone(g_kax_chapters); bool have_chapters_in_timeframe = select_chapters_in_timeframe(chapters_here.get(), start, end, offset); - mxdebug_if(debug, boost::format("offset %1% start %2% end %3% have chapters in timeframe? %4% chapters in this file? %5%\n") % offset % start % end % have_chapters_in_timeframe % !!s_chapters_in_this_file); + mxdebug_if(s_debug, boost::format("offset %1% start %2% end %3% have chapters in timeframe? %4% chapters in this file? %5%\n") % offset % start % end % have_chapters_in_timeframe % !!s_chapters_in_this_file); if (!have_chapters_in_timeframe) return; @@ -1676,9 +1673,9 @@ add_chapters_for_current_part() { static void render_chapters() { - bool debug = debugging_requested("splitting_chapters"); + auto s_debug = debugging_option_c{"splitting_chapters"}; - mxdebug_if(debug, + mxdebug_if(s_debug, boost::format("render_chapters: have void? %1% size %2% have chapters? %3% size %4%\n") % !!s_kax_chapters_void % (s_kax_chapters_void ? s_kax_chapters_void ->ElementSize() : 0) % !!s_chapters_in_this_file % (s_chapters_in_this_file ? s_chapters_in_this_file->ElementSize() : 0)); @@ -2203,13 +2200,8 @@ discard_queued_packets() { */ void main_loop() { - s_debug_appending = debugging_requested("append|appending"); - s_debug_rerender_track_headers = debugging_requested("rerender|rerender_track_headers"); - // Let's go! while (1) { - debug_run_main_loop_hooks(); - // Step 1: Make sure a packet is available for each output // as long we haven't already processed the last one. pull_packetizers_for_packets(); diff --git a/src/merge/timecode_factory.h b/src/merge/timecode_factory.h index 1138db1fd..472f209b7 100644 --- a/src/merge/timecode_factory.h +++ b/src/merge/timecode_factory.h @@ -50,7 +50,8 @@ protected: std::string m_file_name, m_source_name; int64_t m_tid; int m_version; - bool m_preserve_duration, m_debug; + bool m_preserve_duration; + debugging_option_c m_debug; public: timecode_factory_c(const std::string &file_name, @@ -62,7 +63,7 @@ public: , m_tid(tid) , m_version(version) , m_preserve_duration(false) - , m_debug(debugging_requested("timecode_factory")) + , m_debug{"timecode_factory"} { } virtual ~timecode_factory_c() { diff --git a/src/mkvtoolnix-gui/attachment_model.cpp b/src/mkvtoolnix-gui/attachment_model.cpp index 64e6533f1..6a2b23b30 100644 --- a/src/mkvtoolnix-gui/attachment_model.cpp +++ b/src/mkvtoolnix-gui/attachment_model.cpp @@ -10,7 +10,7 @@ AttachmentModel::AttachmentModel(QObject *parent, QList &attachments) : QAbstractItemModel(parent) , m_attachments(&attachments) - , m_debug(debugging_requested("attachment_model")) + , m_debug{"attachment_model"} { } diff --git a/src/mkvtoolnix-gui/attachment_model.h b/src/mkvtoolnix-gui/attachment_model.h index 8b2ff5fb4..4c0fdabf6 100644 --- a/src/mkvtoolnix-gui/attachment_model.h +++ b/src/mkvtoolnix-gui/attachment_model.h @@ -25,7 +25,7 @@ protected: QList *m_attachments; - bool m_debug; + debugging_option_c m_debug; public: AttachmentModel(QObject *parent, QList &attachments); diff --git a/src/mkvtoolnix-gui/track_model.cpp b/src/mkvtoolnix-gui/track_model.cpp index 36049fc98..94459f266 100644 --- a/src/mkvtoolnix-gui/track_model.cpp +++ b/src/mkvtoolnix-gui/track_model.cpp @@ -17,7 +17,7 @@ TrackModel::TrackModel(QObject *parent) , 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")) + , m_debug{"track_model"} { } diff --git a/src/mkvtoolnix-gui/track_model.h b/src/mkvtoolnix-gui/track_model.h index 27b2a348e..b03829b56 100644 --- a/src/mkvtoolnix-gui/track_model.h +++ b/src/mkvtoolnix-gui/track_model.h @@ -28,7 +28,7 @@ protected: QList *m_tracks; QIcon m_audioIcon, m_videoIcon, m_subtitleIcon, m_attachmentIcon, m_chaptersIcon, m_tagsIcon, m_genericIcon, m_yesIcon, m_noIcon; - bool m_debug; + debugging_option_c m_debug; public: TrackModel(QObject *parent); diff --git a/src/mmg/header_editor/frame.cpp b/src/mmg/header_editor/frame.cpp index 2366d30c4..661b7991e 100644 --- a/src/mmg/header_editor/frame.cpp +++ b/src/mmg/header_editor/frame.cpp @@ -228,7 +228,7 @@ header_editor_frame_c::clear_pages() { void header_editor_frame_c::on_file_open(wxCommandEvent &) { - if (debugging_requested("he_open_std")) { + if (debugging_c::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()))); diff --git a/src/output/p_avc.cpp b/src/output/p_avc.cpp index c85d16bc1..f6365c8b8 100644 --- a/src/output/p_avc.cpp +++ b/src/output/p_avc.cpp @@ -31,8 +31,8 @@ mpeg4_p10_es_video_packetizer_c(generic_reader_c *p_reader, , m_default_duration_for_interlaced_content(-1) , m_first_frame(true) , m_set_display_dimensions(false) - , m_debug_timecodes( debugging_requested("mpeg4_p10_es|mpeg4_p10_es_timecodes")) - , m_debug_aspect_ratio(debugging_requested("mpeg4_p10_es|mpeg4_p10_es_aspect_ratio")) + , m_debug_timecodes{ "mpeg4_p10_es|mpeg4_p10_es_timecodes"} + , m_debug_aspect_ratio{"mpeg4_p10_es|mpeg4_p10_es_aspect_ratio"} { m_relaxed_timecode_checking = true; diff --git a/src/output/p_avc.h b/src/output/p_avc.h index 7c7c8fb05..aa90f5dd3 100644 --- a/src/output/p_avc.h +++ b/src/output/p_avc.h @@ -25,7 +25,8 @@ class mpeg4_p10_es_video_packetizer_c: public generic_packetizer_c { protected: avc_es_parser_c m_parser; int64_t m_default_duration_for_interlaced_content; - bool m_first_frame, m_set_display_dimensions, m_debug_timecodes, m_debug_aspect_ratio; + bool m_first_frame, m_set_display_dimensions; + debugging_option_c m_debug_timecodes, m_debug_aspect_ratio; public: mpeg4_p10_es_video_packetizer_c(generic_reader_c *p_reader, track_info_c &p_ti); diff --git a/src/output/p_mpeg1_2.cpp b/src/output/p_mpeg1_2.cpp index 037688430..19f9a121e 100644 --- a/src/output/p_mpeg1_2.cpp +++ b/src/output/p_mpeg1_2.cpp @@ -37,7 +37,7 @@ mpeg1_2_video_packetizer_c(generic_reader_c *p_reader, , m_framed{framed} , m_aspect_ratio_extracted{true} , m_num_removed_stuffing_bytes{} - , m_debug_stuffing_removal{debugging_requested("mpeg1_2|mpeg1_2_stuffing_removal")} + , m_debug_stuffing_removal{"mpeg1_2|mpeg1_2_stuffing_removal"} { set_codec_id((boost::format("V_MPEG%1%") % version).str()); diff --git a/src/output/p_mpeg1_2.h b/src/output/p_mpeg1_2.h index 46cbb5b95..e2d615626 100644 --- a/src/output/p_mpeg1_2.h +++ b/src/output/p_mpeg1_2.h @@ -26,7 +26,7 @@ protected: memory_cptr m_seq_hdr; bool m_framed, m_aspect_ratio_extracted; int64_t m_num_removed_stuffing_bytes; - bool m_debug_stuffing_removal; + debugging_option_c m_debug_stuffing_removal; public: mpeg1_2_video_packetizer_c(generic_reader_c *p_reader, track_info_c &p_ti, int version, double fps, int width, int height, int dwidth, int dheight, bool framed); diff --git a/src/output/p_mpeg4_p2.cpp b/src/output/p_mpeg4_p2.cpp index 51406fed6..f52461bfa 100644 --- a/src/output/p_mpeg4_p2.cpp +++ b/src/output/p_mpeg4_p2.cpp @@ -68,7 +68,7 @@ mpeg4_p2_video_packetizer_c(generic_reader_c *p_reader, } mpeg4_p2_video_packetizer_c::~mpeg4_p2_video_packetizer_c() { - if (!debugging_requested("mpeg4_p2_statistics")) + if (!debugging_c::requested("mpeg4_p2_statistics")) return; mxinfo(boost::format("mpeg4_p2_video_packetizer_c statistics:\n" diff --git a/src/output/p_opus.cpp b/src/output/p_opus.cpp index fda56646d..6654a63a2 100644 --- a/src/output/p_opus.cpp +++ b/src/output/p_opus.cpp @@ -23,7 +23,7 @@ using namespace libmatroska; opus_packetizer_c::opus_packetizer_c(generic_reader_c *reader, track_info_c &ti) : generic_packetizer_c(reader, ti) - , m_debug{debugging_requested("opus|opus_packetizer")} + , m_debug{"opus|opus_packetizer"} , m_next_calculated_timecode{timecode_c::ns(0)} , m_id_header(mtx::opus::id_header_t::decode(ti.m_private_data)) { diff --git a/src/output/p_opus.h b/src/output/p_opus.h index 329160a79..b189702df 100644 --- a/src/output/p_opus.h +++ b/src/output/p_opus.h @@ -23,7 +23,7 @@ class opus_packetizer_c: public generic_packetizer_c { private: static bool ms_experimental_warning_shown; - bool m_debug; + debugging_option_c m_debug; timecode_c m_next_calculated_timecode, m_previous_provided_timecode; mtx::opus::id_header_t m_id_header; diff --git a/src/output/p_video.cpp b/src/output/p_video.cpp index ccb243036..7bcc5bdb7 100644 --- a/src/output/p_video.cpp +++ b/src/output/p_video.cpp @@ -39,7 +39,7 @@ video_packetizer_c::video_packetizer_c(generic_reader_c *p_reader, , m_frames_output(0) , m_ref_timecode(-1) , m_duration_shift(0) - , m_rederive_frame_types(debugging_requested("rederive_frame_types")) + , m_rederive_frame_types(debugging_c::requested("rederive_frame_types")) , m_codec_type(video_packetizer_c::ct_unknown) { set_track_type(track_video); diff --git a/src/propedit/propedit.cpp b/src/propedit/propedit.cpp index 66f2f8e20..424eadc7d 100644 --- a/src/propedit/propedit.cpp +++ b/src/propedit/propedit.cpp @@ -109,7 +109,7 @@ run(options_cptr &options) { options->find_elements(analyzer.get()); options->validate(); - if (debugging_requested("dump_options")) { + if (debugging_c::requested("dump_options")) { mxinfo("\nDumping options after file and element analysis\n\n"); options->dump_info(); } @@ -145,7 +145,7 @@ main(int argc, options_cptr options = propedit_cli_parser_c(command_line_utf8(argc, argv)).run(); - if (debugging_requested("dump_options")) { + if (debugging_c::requested("dump_options")) { mxinfo("\nDumping options after parsing the command line\n\n"); options->dump_info(); }