From a7a0b88d151990ab1533138d0f35d77de333669c Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 12 Jun 2024 10:04:20 +0200 Subject: [PATCH] deck: added a param to enforce old sort Added `--param bmd-sort-natural` to enforce old devices' sorting in help + display the old indices instead of new ones. Numeric indices can be used regardless the option (althoug hidden by default). --- src/blackmagic_common.cpp | 16 ++++++++++------ src/blackmagic_common.hpp | 6 ++++-- src/video_capture/decklink.cpp | 26 +++++++++++++++++--------- src/video_display/decklink.cpp | 22 +++++++++++++++------- 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/src/blackmagic_common.cpp b/src/blackmagic_common.cpp index 9b47f877e..0c08187a4 100644 --- a/src/blackmagic_common.cpp +++ b/src/blackmagic_common.cpp @@ -1091,8 +1091,8 @@ print_bmd_attribute(IDeckLinkProfileAttributes *deckLinkAttributes, /** * @returns list of DeckLink devices sorted (indexed) by topological ID * If no topological ID is reported, use UINT_MAX (and lower vals) - * @param[out] com_initialized pointer to be passed to decklnk_uninitialize - (keeps information if COM needs to be unintialized) + * @param verbose - print errors + * @param natural_sort - use the (old) natural sort as given by the iterator * @note Each call of this function should be followed by com_uninitialize() when done with DeckLink. No BMD stuff originating from this function call @@ -1103,7 +1103,7 @@ print_bmd_attribute(IDeckLinkProfileAttributes *deckLinkAttributes, * be destroyed after decklink_uninitialize()). */ std::vector -bmd_get_sorted_devices(bool *com_initialized, bool verbose) +bmd_get_sorted_devices(bool *com_initialized, bool verbose, bool natural_sort) { IDeckLinkIterator *deckLinkIterator = create_decklink_iterator(com_initialized, verbose); @@ -1139,9 +1139,11 @@ bmd_get_sorted_devices(bool *com_initialized, bool verbose) std::get(it) = idx++; } deckLinkIterator->Release(); - std::sort(out.begin(), out.end(), [](bmd_dev &a, bmd_dev &b) { - return std::get(a) < std::get(b); - }); + if (!natural_sort) { + std::sort(out.begin(), out.end(), [](bmd_dev &a, bmd_dev &b) { + return std::get(a) < std::get(b); + }); + } // assign new indices char new_idx = 'a'; for (auto &d : out) { @@ -1152,4 +1154,6 @@ bmd_get_sorted_devices(bool *com_initialized, bool verbose) ADD_TO_PARAM(R10K_FULL_OPT, "* " R10K_FULL_OPT "\n" " Do not do conversion from/to limited range on in/out for R10k on BMD devs.\n"); +ADD_TO_PARAM(BMD_NAT_SORT, "* " BMD_NAT_SORT "\n" + " Use the old BMD device sorting.\n"); diff --git a/src/blackmagic_common.hpp b/src/blackmagic_common.hpp index 30b87b09c..2441c1ae3 100644 --- a/src/blackmagic_common.hpp +++ b/src/blackmagic_common.hpp @@ -162,6 +162,7 @@ std::ostream &operator<<(std::ostream &output, REFIID iid); #define R10K_FULL_OPT "bmd-r10k-full-range" +#define BMD_NAT_SORT "bmd-sort-natural" template bool decklink_supports_codec(T *deckLink, BMDPixelFormat pf); @@ -184,8 +185,9 @@ void print_bmd_attribute(IDeckLinkProfileAttributes *deckLinkAttributes, */ using bmd_dev = std::tuple, unsigned, int, char>; -std::vector -bmd_get_sorted_devices(bool *com_initialized, bool verbose = true); +std::vector bmd_get_sorted_devices(bool *com_initialized, + bool verbose = true, + bool natural_sort = false); #endif // defined BLACKMAGIC_COMMON_HPP diff --git a/src/video_capture/decklink.cpp b/src/video_capture/decklink.cpp index 8c6b78332..0c26a0a68 100644 --- a/src/video_capture/decklink.cpp +++ b/src/video_capture/decklink.cpp @@ -633,22 +633,30 @@ decklink_help(bool full, const char *query_prop_fcc = nullptr) cout << "Devices (idx, topological ID, name):\n"; // Enumerate all cards in this system int numDevices = 0; - for (auto &d : bmd_get_sorted_devices(&com_initialized)) { - IDeckLink *deckLink = get<0>(d).get(); + const bool natural_sort = + get_commandline_param(BMD_NAT_SORT) != nullptr; + for (auto &d : + bmd_get_sorted_devices(&com_initialized, true, natural_sort)) { + IDeckLink *deckLink = get<0>(d).get(); string deviceName = bmd_get_device_name(deckLink); if (deviceName.empty()) { deviceName = "(unable to get name)"; } - char numeric_index[STR_LEN] = ""; - if (full) { - snprintf(numeric_index, sizeof numeric_index, - TBOLD("%d") ") ", get(d)); + char index[STR_LEN] = ""; + if (!natural_sort) { + snprintf(index, sizeof index, + TBOLD("%c") ") ", get(d)); + } + if (full || natural_sort) { + snprintf(index + strlen(index), + sizeof index - strlen(index), TBOLD("%d") ") ", + get(d)); } // *** Print the model name of the DeckLink card - color_printf("\t" TBOLD("%c") ") %s" TBOLD("%6x") ") " TBOLD( + color_printf("\t%s" TBOLD("%6x") ") " TBOLD( TGREEN("%s")) "\n", - get(d), numeric_index, get(d), + index, get(d), deviceName.c_str()); // Increment the total number of DeckLink cards found @@ -657,7 +665,7 @@ decklink_help(bool full, const char *query_prop_fcc = nullptr) if (full) { vidcap_decklink_print_card_info(deckLink, query_prop_fcc); } - } + } if (!full) { col() << "\n(use \"-t decklink:" << SBOLD( diff --git a/src/video_display/decklink.cpp b/src/video_display/decklink.cpp index 47909587f..19fd168c6 100644 --- a/src/video_display/decklink.cpp +++ b/src/video_display/decklink.cpp @@ -632,22 +632,30 @@ show_help(bool full, const char *query_prop_fcc = nullptr) bool com_initialized = false; // Enumerate all cards in this system - for (auto &d : bmd_get_sorted_devices(&com_initialized, true)) { + const bool natural_sort = + get_commandline_param(BMD_NAT_SORT) != nullptr; + for (auto &d : + bmd_get_sorted_devices(&com_initialized, true, natural_sort)) { IDeckLink *deckLink = get<0>(d).get(); string deviceName = bmd_get_device_name(deckLink); if (deviceName.empty()) { deviceName = "(unable to get name)"; } - char numeric_index[STR_LEN] = ""; - if (full) { - snprintf(numeric_index, sizeof numeric_index, - TBOLD("%d") ") ", get(d)); + char index[STR_LEN] = ""; + if (!natural_sort) { + snprintf(index, sizeof index, + TBOLD("%c") ") ", get(d)); + } + if (full || natural_sort) { + snprintf(index + strlen(index), + sizeof index - strlen(index), TBOLD("%d") ") ", + get(d)); } // *** Print the model name of the DeckLink card - color_printf("\t" TBOLD("%c") ") %s" TBOLD("%6x") ") " TBOLD( + color_printf("\t%s" TBOLD("%6x") ") " TBOLD( TGREEN("%s")) "\n", - get(d), numeric_index, get(d), + index, get(d), deviceName.c_str()); if (full) { print_output_modes(deckLink, query_prop_fcc);