@@ -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