Skip to content

Commit 71fb7e8

Browse files
committed
vdisp/decklink: fix pixel format change handling
Since the commit 443fe59 (2023-04-11), the sole CS change was not handled. There can be 2 cases: 1. bit-depth change (without color-space), which was not handled 2. CS changed was even more harmful because no signal was detected then The above cases should be handled. The bit-depth handle should be ignored just if codec= is explicitly specified, in which case the depth is taken from the argument (specified codec CS is not honored - YUV must be captured as YUV, RGB similarly).
1 parent b31b19a commit 71fb7e8

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

src/video_capture/decklink.cpp

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -331,48 +331,49 @@ class VideoDelegate : public IDeckLinkInputCallback {
331331
s->stereo = detected_3d;
332332
s->enable_flags ^= bmdVideoInputDualStream3D;
333333
}
334-
BMDDetectedVideoInputFormatFlags csBitDepth = flags & (csMask | bitDepthMask);
335-
unique_lock<mutex> lk(s->lock);
336-
if (notificationEvents & bmdVideoInputColorspaceChanged && csBitDepth != configuredCsBitDepth) {
337-
configuredCsBitDepth = csBitDepth;
338-
if ((csBitDepth & bitDepthMask) == 0U) { // if no bit depth, assume 8-bit
339-
csBitDepth |= bmdDetectedVideoInput8BitDepth;
340-
}
341-
if (s->requested_bit_depth != 0) {
342-
csBitDepth = (flags & csMask) | s->requested_bit_depth;
343-
}
344-
unordered_map<BMDDetectedVideoInputFormatFlags, codec_t> m = {
345-
{bmdDetectedVideoInputYCbCr422 | bmdDetectedVideoInput8BitDepth, UYVY},
346-
{bmdDetectedVideoInputYCbCr422 | bmdDetectedVideoInput10BitDepth, v210},
347-
{bmdDetectedVideoInputYCbCr422 | bmdDetectedVideoInput12BitDepth, v210}, // weird
348-
{bmdDetectedVideoInputRGB444 | bmdDetectedVideoInput8BitDepth, RGBA},
349-
{bmdDetectedVideoInputRGB444 | bmdDetectedVideoInput10BitDepth, R10k},
350-
{bmdDetectedVideoInputRGB444 | bmdDetectedVideoInput12BitDepth, R12L},
351-
};
352-
if (s->requested_bit_depth == 0 && (csBitDepth & bmdDetectedVideoInput8BitDepth) == 0) {
353-
const string & depth = (flags & bmdDetectedVideoInput10BitDepth) != 0U ? "10"s : "12"s;
354-
LOG(LOG_LEVEL_WARNING)
355-
<< MOD_NAME << "Detected " << depth
356-
<< "-bit signal, use \":codec=UYVY\" to "
357-
"enforce 8-bit capture (old "
358-
"behavior).\n";
359-
}
360334

361-
s->set_codec(m.at(csBitDepth));
335+
// set the codec but only if has changed
336+
BMDDetectedVideoInputFormatFlags csBitDepth = flags & (csMask | bitDepthMask);
337+
if (notificationEvents == bmdVideoInputColorspaceChanged && csBitDepth == configuredCsBitDepth) {
338+
return S_OK;
339+
}
340+
configuredCsBitDepth = csBitDepth;
341+
if ((csBitDepth & bitDepthMask) == 0U) { // if no bit depth, assume 8-bit
342+
csBitDepth |= bmdDetectedVideoInput8BitDepth;
343+
}
344+
if (s->requested_bit_depth != 0) {
345+
csBitDepth = (flags & csMask) | s->requested_bit_depth;
346+
}
347+
unordered_map<BMDDetectedVideoInputFormatFlags, codec_t> m = {
348+
{bmdDetectedVideoInputYCbCr422 | bmdDetectedVideoInput8BitDepth, UYVY},
349+
{bmdDetectedVideoInputYCbCr422 | bmdDetectedVideoInput10BitDepth, v210},
350+
{bmdDetectedVideoInputYCbCr422 | bmdDetectedVideoInput12BitDepth, v210}, // weird
351+
{bmdDetectedVideoInputRGB444 | bmdDetectedVideoInput8BitDepth, RGBA},
352+
{bmdDetectedVideoInputRGB444 | bmdDetectedVideoInput10BitDepth, R10k},
353+
{bmdDetectedVideoInputRGB444 | bmdDetectedVideoInput12BitDepth, R12L},
354+
};
355+
if (s->requested_bit_depth == 0 && (csBitDepth & bmdDetectedVideoInput8BitDepth) == 0) {
356+
const string & depth = (flags & bmdDetectedVideoInput10BitDepth) != 0U ? "10"s : "12"s;
357+
LOG(LOG_LEVEL_WARNING)
358+
<< MOD_NAME << "Detected " << depth
359+
<< "-bit signal, use \":codec=UYVY\" to "
360+
"enforce 8-bit capture (old "
361+
"behavior).\n";
362362
}
363363

364-
if (notificationEvents & bmdVideoInputDisplayModeChanged) {
365-
IDeckLinkInput *deckLinkInput = device.deckLinkInput;
366-
deckLinkInput->PauseStreams();
367-
BMDPixelFormat pf{};
368-
if (HRESULT result = set_display_mode_properties(s, device.tile, mode, /* out */ &pf); FAILED(result)) {
369-
LOG(LOG_LEVEL_ERROR) << MOD_NAME << "set_display_mode_properties: " << bmd_hresult_to_string(result) << "\n";
370-
return result;
371-
}
372-
CALL_AND_CHECK(deckLinkInput->EnableVideoInput(mode->GetDisplayMode(), pf, s->enable_flags), "EnableVideoInput");
373-
deckLinkInput->FlushStreams();
374-
deckLinkInput->StartStreams();
364+
unique_lock<mutex> lk(s->lock);
365+
s->set_codec(m.at(csBitDepth));
366+
367+
IDeckLinkInput *deckLinkInput = device.deckLinkInput;
368+
deckLinkInput->PauseStreams();
369+
BMDPixelFormat pf{};
370+
if (HRESULT result = set_display_mode_properties(s, device.tile, mode, /* out */ &pf); FAILED(result)) {
371+
LOG(LOG_LEVEL_ERROR) << MOD_NAME << "set_display_mode_properties: " << bmd_hresult_to_string(result) << "\n";
372+
return result;
375373
}
374+
CALL_AND_CHECK(deckLinkInput->EnableVideoInput(mode->GetDisplayMode(), pf, s->enable_flags), "EnableVideoInput");
375+
deckLinkInput->FlushStreams();
376+
deckLinkInput->StartStreams();
376377

377378
return S_OK;
378379
}

0 commit comments

Comments
 (0)