Skip to content

Commit

Permalink
deck: added a param to enforce old sort
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
MartinPulec committed Jun 12, 2024
1 parent 342c42c commit a7a0b88
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
16 changes: 10 additions & 6 deletions src/blackmagic_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1103,7 +1103,7 @@ print_bmd_attribute(IDeckLinkProfileAttributes *deckLinkAttributes,
* be destroyed after decklink_uninitialize()).
*/
std::vector<bmd_dev>
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);
Expand Down Expand Up @@ -1139,9 +1139,11 @@ bmd_get_sorted_devices(bool *com_initialized, bool verbose)
std::get<int>(it) = idx++;
}
deckLinkIterator->Release();
std::sort(out.begin(), out.end(), [](bmd_dev &a, bmd_dev &b) {
return std::get<unsigned>(a) < std::get<unsigned>(b);
});
if (!natural_sort) {
std::sort(out.begin(), out.end(), [](bmd_dev &a, bmd_dev &b) {
return std::get<unsigned>(a) < std::get<unsigned>(b);
});
}
// assign new indices
char new_idx = 'a';
for (auto &d : out) {
Expand All @@ -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");

6 changes: 4 additions & 2 deletions src/blackmagic_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
bool decklink_supports_codec(T *deckLink, BMDPixelFormat pf);
Expand All @@ -184,8 +185,9 @@ void print_bmd_attribute(IDeckLinkProfileAttributes *deckLinkAttributes,
*/
using bmd_dev = std::tuple<std::unique_ptr<IDeckLink, void (*)(IDeckLink *)>,
unsigned, int, char>;
std::vector<bmd_dev>
bmd_get_sorted_devices(bool *com_initialized, bool verbose = true);
std::vector<bmd_dev> bmd_get_sorted_devices(bool *com_initialized,
bool verbose = true,
bool natural_sort = false);

#endif // defined BLACKMAGIC_COMMON_HPP

26 changes: 17 additions & 9 deletions src/video_capture/decklink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(d));
char index[STR_LEN] = "";
if (!natural_sort) {
snprintf(index, sizeof index,
TBOLD("%c") ") ", get<char>(d));
}
if (full || natural_sort) {
snprintf(index + strlen(index),
sizeof index - strlen(index), TBOLD("%d") ") ",
get<int>(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<char>(d), numeric_index, get<unsigned>(d),
index, get<unsigned>(d),
deviceName.c_str());

// Increment the total number of DeckLink cards found
Expand All @@ -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(
Expand Down
22 changes: 15 additions & 7 deletions src/video_display/decklink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(d));
char index[STR_LEN] = "";
if (!natural_sort) {
snprintf(index, sizeof index,
TBOLD("%c") ") ", get<char>(d));
}
if (full || natural_sort) {
snprintf(index + strlen(index),
sizeof index - strlen(index), TBOLD("%d") ") ",
get<int>(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<char>(d), numeric_index, get<unsigned>(d),
index, get<unsigned>(d),
deviceName.c_str());
if (full) {
print_output_modes(deckLink, query_prop_fcc);
Expand Down

0 comments on commit a7a0b88

Please sign in to comment.