X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdecklink%2Futil%2Futil.h;h=09bca51967ca77e19e1f19d2e0c71570f3bdc3da;hb=ac7b3acb915f90de6b224e54a2240023fc221e5a;hp=803ffe2e9e7b27861790d6f74da7254073da4613;hpb=745f022a44f0d347e56acbbd597ff71e06eab894;p=casparcg diff --git a/modules/decklink/util/util.h b/modules/decklink/util/util.h index 803ffe2e9..09bca5196 100644 --- a/modules/decklink/util/util.h +++ b/modules/decklink/util/util.h @@ -1,12 +1,39 @@ +/* +* copyright (c) 2010 Sveriges Television AB +* +* This file is part of CasparCG. +* +* CasparCG is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* CasparCG is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with CasparCG. If not, see . +* +*/ #pragma once +#include +#include #include #include "../interop/DeckLinkAPI_h.h" -namespace caspar { +#include + +#include + +#include + +namespace caspar { namespace decklink { -static BMDDisplayMode GetDecklinkVideoFormat(core::video_format::type fmt) +static BMDDisplayMode get_decklink_video_format(core::video_format::type fmt) { switch(fmt) { @@ -25,44 +52,104 @@ static BMDDisplayMode GetDecklinkVideoFormat(core::video_format::type fmt) case core::video_format::x1080p2500: return bmdModeHD1080p25; case core::video_format::x1080p2997: return bmdModeHD1080p2997; case core::video_format::x1080p3000: return bmdModeHD1080p30; - default: return (BMDDisplayMode)ULONG_MAX; + case core::video_format::x1080p5000: return bmdModeHD1080p50; + default: return (BMDDisplayMode)ULONG_MAX; } } - -static IDeckLinkDisplayMode* get_display_mode(IDeckLinkOutput* output, BMDDisplayMode format) -{ - IDeckLinkDisplayModeIterator* iterator; - IDeckLinkDisplayMode* mode; - - if(FAILED(output->GetDisplayModeIterator(&iterator))) - return nullptr; - while(SUCCEEDED(iterator->Next(&mode)) && mode != nullptr) - { - if(mode->GetDisplayMode() == format) - return mode; +static core::video_format::type get_caspar_video_format(BMDDisplayMode fmt) +{ + switch(fmt) + { + case bmdModePAL: return core::video_format::pal; + case bmdModeNTSC: return core::video_format::ntsc; + case bmdModeHD720p50: return core::video_format::x720p5000; + case bmdModeHD720p5994: return core::video_format::x720p5994; + case bmdModeHD720p60: return core::video_format::x720p6000; + case bmdModeHD1080p2398: return core::video_format::x1080p2397; + case bmdModeHD1080p24: return core::video_format::x1080p2400; + case bmdModeHD1080i50: return core::video_format::x1080i5000; + case bmdModeHD1080i5994: return core::video_format::x1080i5994; + case bmdModeHD1080i6000: return core::video_format::x1080i6000; + case bmdModeHD1080p25: return core::video_format::x1080p2500; + case bmdModeHD1080p2997: return core::video_format::x1080p2997; + case bmdModeHD1080p30: return core::video_format::x1080p3000; + case bmdModeHD1080p50: return core::video_format::x1080p5000; + default: return core::video_format::invalid; } - iterator->Release(); - return nullptr; } -static IDeckLinkDisplayMode* get_display_mode(IDeckLinkOutput* output, core::video_format::type fmt) +template +BMDDisplayMode get_display_mode(const T& device, BMDDisplayMode format, BMDPixelFormat pix_fmt, F flag) { - return get_display_mode(output, GetDecklinkVideoFormat(fmt)); + CComPtr iterator; + CComPtr mode; + + if(SUCCEEDED(device->GetDisplayModeIterator(&iterator))) + { + while(SUCCEEDED(iterator->Next(&mode)) && + mode != nullptr && + mode->GetDisplayMode() != format){} + } + + if(!mode) + BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Device could not find requested video-format.") + << arg_value_info(boost::lexical_cast(format)) + << arg_name_info("format")); + + BMDDisplayModeSupport displayModeSupport; + if(FAILED(device->DoesSupportVideoMode(mode->GetDisplayMode(), pix_fmt, flag, &displayModeSupport, nullptr)) || displayModeSupport == bmdDisplayModeNotSupported) + CASPAR_LOG(warning) << L"Device does not support video-format."; + //BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Device does not support requested video-format.") + // << arg_value_info(boost::lexical_cast(format)) + // << arg_name_info("format")); + else if(displayModeSupport == bmdDisplayModeSupportedWithConversion) + CASPAR_LOG(warning) << L"Device supports video-format with conversion."; + + return mode->GetDisplayMode(); +} + +template +static BMDDisplayMode get_display_mode(const T& device, core::video_format::type fmt, BMDPixelFormat pix_fmt, F flag) +{ + return get_display_mode(device, get_decklink_video_format(fmt), pix_fmt, flag); } template -static std::wstring get_version(T& deckLinkIterator) +static std::wstring get_version(T& iterator) { - IDeckLinkAPIInformation* deckLinkAPIInformation; - if (FAILED(deckLinkIterator->QueryInterface(IID_IDeckLinkAPIInformation, (void**)&deckLinkAPIInformation))) + CComQIPtr info = iterator; + if (!info) return L"Unknown"; BSTR ver; - deckLinkAPIInformation->GetString(BMDDeckLinkAPIVersion, &ver); - deckLinkAPIInformation->Release(); + info->GetString(BMDDeckLinkAPIVersion, &ver); return ver; } -} \ No newline at end of file +static CComPtr get_device(size_t device_index) +{ + CComPtr pDecklinkIterator; + if(FAILED(pDecklinkIterator.CoCreateInstance(CLSID_CDeckLinkIterator))) + BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("No Decklink drivers installed.")); + + size_t n = 0; + CComPtr decklink; + while(n < device_index && pDecklinkIterator->Next(&decklink) == S_OK){++n;} + + if(n != device_index || !decklink) + BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Decklink device not found.") << arg_name_info("device_index") << arg_value_info(boost::lexical_cast(device_index))); + + return decklink; +} + +template +static std::wstring get_model_name(const T& device) +{ + BSTR pModelName; + device->GetModelName(&pModelName); + return std::wstring(pModelName); +} + +}} \ No newline at end of file