Skip to content

Commit

Permalink
print supported pixfmts also for DeckLink capture
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPulec committed Oct 10, 2023
1 parent a986431 commit fd1d808
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 36 deletions.
58 changes: 58 additions & 0 deletions src/blackmagic_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,64 @@ const map<BMDVideoConnection, string> &get_connection_string_map() {
return m;
}

template <typename T> struct bmd_no_conv {
};
template <> struct bmd_no_conv<IDeckLinkInput> {
static constexpr BMDVideoInputConversionMode value =
bmdNoVideoInputConversion;
};
template <> struct bmd_no_conv<IDeckLinkOutput> {
static constexpr BMDVideoOutputConversionMode value =
bmdNoVideoOutputConversion;
};
/**
* This function returns true if any display mode and any output supports the
* codec. The codec, however, may not be supported with actual video mode.
*
* @todo For UltraStudio Pro DoesSupportVideoMode returns E_FAIL on not
* supported pixel formats instead of setting supported to false.
*/
template <typename T>
bool
decklink_supports_codec(T *deckLink, BMDPixelFormat pf)
{
IDeckLinkDisplayModeIterator *displayModeIterator = nullptr;
IDeckLinkDisplayMode *deckLinkDisplayMode = nullptr;

if (FAILED(
deckLink->GetDisplayModeIterator(&displayModeIterator))) {
MSG(ERROR, "Fatal: cannot create display mode iterator.\n");
return false;
}

while (displayModeIterator->Next(&deckLinkDisplayMode) == S_OK) {
BMD_BOOL supported = false;
const HRESULT res = deckLink->DoesSupportVideoMode(
bmdVideoConnectionUnspecified,
deckLinkDisplayMode->GetDisplayMode(), pf,
bmd_no_conv<T>::value, bmdSupportedVideoModeDefault,
nullptr, &supported);
deckLinkDisplayMode->Release();
if (res != S_OK) {
MSG(WARNING, "DoesSupportVideoMode: %s\n",
bmd_hresult_to_string(res).c_str());
continue;
}
if (supported) {
displayModeIterator->Release();
return true;
}
}
displayModeIterator->Release();

return false;
}
template bool
decklink_supports_codec<IDeckLinkOutput>(IDeckLinkOutput *deckLink,
BMDPixelFormat pf);
template bool decklink_supports_codec<IDeckLinkInput>(IDeckLinkInput *deckLink,
BMDPixelFormat pf);

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");

9 changes: 9 additions & 0 deletions src/blackmagic_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,14 @@ std::ostream &operator<<(std::ostream &output, REFIID iid);

#define R10K_FULL_OPT "bmd-r10k-full-range"

template <typename T>
bool decklink_supports_codec(T *deckLink, BMDPixelFormat pf);
extern template bool
decklink_supports_codec<IDeckLinkOutput>(IDeckLinkOutput *deckLink,
BMDPixelFormat pf);
extern template bool
decklink_supports_codec<IDeckLinkInput>(IDeckLinkInput *deckLink,
BMDPixelFormat pf);

#endif // defined BLACKMAGIC_COMMON_HPP

16 changes: 16 additions & 0 deletions src/video_capture/decklink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,22 @@ vidcap_decklink_print_card_info(IDeckLink *deckLink, const char *query_prop_fcc)
cout << "Could not query device attributes.\n\n";
return;
}

IDeckLinkInput *deckLinkInput = nullptr;
color_printf("\n\tsupported pixel formats:" TERM_BOLD);
if ((deckLink->QueryInterface(IID_IDeckLinkInput,
(void **) &deckLinkInput)) == S_OK) {
for (auto &c : uv_to_bmd_codec_map) {
if (decklink_supports_codec(deckLinkInput, c.second)) {
printf(" %s", get_codec_name(c.first));
}
}
RELEASE_IF_NOT_NULL(deckLinkInput);
} else {
color_printf(TRED("(error)"));
}
color_printf(TERM_RESET "\n");

int64_t connections = 0;
if (deckLinkAttributes->GetInt(BMDDeckLinkVideoInputConnections, &connections) != S_OK) {
LOG(LOG_LEVEL_ERROR) << MOD_NAME "Could not get connections.\n";
Expand Down
38 changes: 2 additions & 36 deletions src/video_display/decklink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,40 +1511,6 @@ static void display_decklink_done(void *state)
delete s;
}

/**
* This function returns true if any display mode and any output supports the
* codec. The codec, however, may not be supported with actual video mode.
*
* @todo For UltraStudio Pro DoesSupportVideoMode returns E_FAIL on not supported
* pixel formats instead of setting supported to false.
*/
static bool decklink_display_supports_codec(IDeckLinkOutput *deckLinkOutput, BMDPixelFormat pf) {
IDeckLinkDisplayModeIterator *displayModeIterator;
IDeckLinkDisplayMode* deckLinkDisplayMode;

if (FAILED(deckLinkOutput->GetDisplayModeIterator(&displayModeIterator))) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Fatal: cannot create display mode iterator.\n");
return false;
}

while (displayModeIterator->Next(&deckLinkDisplayMode) == S_OK) {
BMD_BOOL supported;
HRESULT res = deckLinkOutput->DoesSupportVideoMode(bmdVideoConnectionUnspecified, deckLinkDisplayMode->GetDisplayMode(), pf, bmdNoVideoOutputConversion, bmdSupportedVideoModeDefault, nullptr, &supported);
deckLinkDisplayMode->Release();
if (res != S_OK) {
CALL_AND_CHECK(res, "DoesSupportVideoMode");
continue;
}
if (supported) {
displayModeIterator->Release();
return true;
}
}
displayModeIterator->Release();

return false;
}

static bool display_decklink_get_property(void *state, int property, void *val, size_t *len)
{
struct state_decklink *s = (struct state_decklink *)state;
Expand All @@ -1553,7 +1519,7 @@ static bool display_decklink_get_property(void *state, int property, void *val,
interlacing_t supported_il_modes[] = {PROGRESSIVE, INTERLACED_MERGED, SEGMENTED_FRAME};
int count = 0;
for (auto & c : uv_to_bmd_codec_map) {
if (decklink_display_supports_codec(s->deckLinkOutput, c.second)) {
if (decklink_supports_codec(s->deckLinkOutput, c.second)) {
codecs[count++] = c.first;
}
}
Expand Down Expand Up @@ -2144,7 +2110,7 @@ static void print_output_modes (IDeckLink* deckLink)
}
color_printf("\n\tsupported pixel formats:" TERM_BOLD);
for (auto & c : uv_to_bmd_codec_map) {
if (decklink_display_supports_codec(deckLinkOutput, c.second)) {
if (decklink_supports_codec(deckLinkOutput, c.second)) {
printf(" %s", get_codec_name(c.first));
}
}
Expand Down

0 comments on commit fd1d808

Please sign in to comment.