<commit_before>#include "deck_link_display_mode_detector.h"

namespace gg
{

DeckLinkDisplayModeDetector::DeckLinkDisplayModeDetector()
    : _deck_link_input(nullptr)
    , _display_mode(bmdModeUnknown)
    , _error_msg("This constructor should never be used")
{
    // nop
}


DeckLinkDisplayModeDetector::DeckLinkDisplayModeDetector(IDeckLinkInput * deck_link_input,
                                                         std::vector<BMDDisplayMode> display_modes_to_check,
                                                         BMDPixelFormat pixel_format,
                                                         BMDVideoInputFlags video_input_flags)
    : _deck_link_input(deck_link_input)
    , _display_modes_to_check(display_modes_to_check)
    , _pixel_format(pixel_format)
    , _video_input_flags(video_input_flags)
    , _display_mode(bmdModeUnknown)
    , _frame_rate(0.0)
    , _error_msg("")
{
    // These are output and result variables
    BMDDisplayModeSupport display_mode_support;
    IDeckLinkDisplayMode * deck_link_display_mode = nullptr;
    HRESULT res;

    _deck_link_input->SetCallback(this);
    for (BMDDisplayMode display_mode : _display_modes_to_check)
    {
        // Check whether the mode is supported
        _display_mode = display_mode;
        res = _deck_link_input->DoesSupportVideoMode(
            _display_mode, _pixel_format, _video_input_flags,
            &display_mode_support, &deck_link_display_mode
        );
        // No glory (could not even check mode support)
        if (res != S_OK)
        {
            _error_msg = "Could not check video mode support of Blackmagic DeckLink device";
            break;
        }

        // Mode not supported: go to next one
        if (display_mode_support != bmdDisplayModeSupported
            or deck_link_display_mode == nullptr)
            continue;

        // Enable video input for checking input coming
        res = _deck_link_input->EnableVideoInput(display_mode, _pixel_format, _video_input_flags);
        if (res != S_OK) // No glory: check next display mode
            continue;

        // Disable video input<commit_msg>Issue #5: starting and subsequently stopping streaming in DeckLinkDisplayModeDetector constructor<commit_after>#include "deck_link_display_mode_detector.h"

namespace gg
{

DeckLinkDisplayModeDetector::DeckLinkDisplayModeDetector()
    : _deck_link_input(nullptr)
    , _display_mode(bmdModeUnknown)
    , _error_msg("This constructor should never be used")
{
    // nop
}


DeckLinkDisplayModeDetector::DeckLinkDisplayModeDetector(IDeckLinkInput * deck_link_input,
                                                         std::vector<BMDDisplayMode> display_modes_to_check,
                                                         BMDPixelFormat pixel_format,
                                                         BMDVideoInputFlags video_input_flags)
    : _deck_link_input(deck_link_input)
    , _display_modes_to_check(display_modes_to_check)
    , _pixel_format(pixel_format)
    , _video_input_flags(video_input_flags)
    , _display_mode(bmdModeUnknown)
    , _frame_rate(0.0)
    , _error_msg("")
{
    // These are output and result variables
    BMDDisplayModeSupport display_mode_support;
    IDeckLinkDisplayMode * deck_link_display_mode = nullptr;
    HRESULT res;

    _deck_link_input->SetCallback(this);
    for (BMDDisplayMode display_mode : _display_modes_to_check)
    {
        // Check whether the mode is supported
        _display_mode = display_mode;
        res = _deck_link_input->DoesSupportVideoMode(
            _display_mode, _pixel_format, _video_input_flags,
            &display_mode_support, &deck_link_display_mode
        );
        // No glory (could not even check mode support)
        if (res != S_OK)
        {
            _error_msg = "Could not check video mode support of Blackmagic DeckLink device";
            break;
        }

        // Mode not supported: go to next one
        if (display_mode_support != bmdDisplayModeSupported
            or deck_link_display_mode == nullptr)
            continue;

        // Enable video input for checking input coming
        res = _deck_link_input->EnableVideoInput(display_mode, _pixel_format, _video_input_flags);
        if (res != S_OK) // No glory: check next display mode
            continue;

        // Start streaming for checking input coming
        res = _deck_link_input->StartStreams();
        if (res != S_OK) // No glory: check next display mode
        {
            _deck_link_input->DisableVideoInput();
            continue;
        }

        // Stop streaming and disable video input
        _deck_link_input->StopStreams();
{'fraction_non_alphanumeric': 0.06656710049071901, 'fraction_numerical': 0.0010667804565820354, 'mean_word_length': 2.4094545454545453, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1884587', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1285, 'n_words': 277}