16bit processing
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <new>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
@@ -25,6 +26,42 @@ std::string BstrToUtf8(BSTR value)
|
||||
|
||||
return std::string(utf8Name.data());
|
||||
}
|
||||
|
||||
bool InputSupportsFormat(IDeckLinkInput* input, BMDDisplayMode displayMode, BMDPixelFormat pixelFormat)
|
||||
{
|
||||
if (input == nullptr)
|
||||
return false;
|
||||
|
||||
BOOL supported = FALSE;
|
||||
BMDDisplayMode actualMode = bmdModeUnknown;
|
||||
const HRESULT result = input->DoesSupportVideoMode(
|
||||
bmdVideoConnectionUnspecified,
|
||||
displayMode,
|
||||
pixelFormat,
|
||||
bmdNoVideoInputConversion,
|
||||
bmdSupportedVideoModeDefault,
|
||||
&actualMode,
|
||||
&supported);
|
||||
return result == S_OK && supported != FALSE;
|
||||
}
|
||||
|
||||
bool OutputSupportsFormat(IDeckLinkOutput* output, BMDDisplayMode displayMode, BMDPixelFormat pixelFormat)
|
||||
{
|
||||
if (output == nullptr)
|
||||
return false;
|
||||
|
||||
BOOL supported = FALSE;
|
||||
BMDDisplayMode actualMode = bmdModeUnknown;
|
||||
const HRESULT result = output->DoesSupportVideoMode(
|
||||
bmdVideoConnectionUnspecified,
|
||||
displayMode,
|
||||
pixelFormat,
|
||||
bmdNoVideoOutputConversion,
|
||||
bmdSupportedVideoModeDefault,
|
||||
&actualMode,
|
||||
&supported);
|
||||
return result == S_OK && supported != FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
DeckLinkSession::~DeckLinkSession()
|
||||
@@ -52,8 +89,6 @@ void DeckLinkSession::ReleaseResources()
|
||||
playoutDelegate.Release();
|
||||
outputVideoFrameQueue.clear();
|
||||
output.Release();
|
||||
|
||||
playoutAllocator.Release();
|
||||
}
|
||||
|
||||
bool DeckLinkSession::DiscoverDevicesAndModes(const VideoFormatSelection& videoModes, std::string& error)
|
||||
@@ -173,11 +208,75 @@ bool DeckLinkSession::DiscoverDevicesAndModes(const VideoFormatSelection& videoM
|
||||
inputDisplayModeName = "No input - black frame";
|
||||
outputMode->GetFrameRate(&frameDuration, &frameTimescale);
|
||||
|
||||
inputFrameRowBytes = inputFrameSize.width * 2u;
|
||||
outputFrameRowBytes = outputFrameSize.width * 4u;
|
||||
captureTextureWidth = inputFrameSize.width / 2u;
|
||||
outputPackTextureWidth = outputFrameSize.width;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeckLinkSession::SelectPreferredFormats(const VideoFormatSelection& videoModes, std::string& error)
|
||||
{
|
||||
if (!output)
|
||||
{
|
||||
error = "Expected an Output DeckLink device";
|
||||
return false;
|
||||
}
|
||||
|
||||
formatStatusMessage.clear();
|
||||
|
||||
const bool inputTenBitSupported = input != nullptr && InputSupportsFormat(input, videoModes.input.displayMode, bmdFormat10BitYUV);
|
||||
inputPixelFormat = input != nullptr ? ChoosePreferredVideoIOFormat(inputTenBitSupported) : VideoIOPixelFormat::Uyvy8;
|
||||
if (input != nullptr && !inputTenBitSupported)
|
||||
formatStatusMessage += "DeckLink input does not report 10-bit YUV support for the configured mode; using 8-bit capture. ";
|
||||
|
||||
const bool outputTenBitSupported = OutputSupportsFormat(output, videoModes.output.displayMode, bmdFormat10BitYUV);
|
||||
outputPixelFormat = ChoosePreferredVideoIOFormat(outputTenBitSupported);
|
||||
if (!outputTenBitSupported)
|
||||
formatStatusMessage += "DeckLink output does not report 10-bit YUV support for the configured mode; using 8-bit BGRA output. ";
|
||||
|
||||
int deckLinkOutputRowBytes = 0;
|
||||
if (output->RowBytesForPixelFormat(OutputIsTenBit() ? bmdFormat10BitYUV : bmdFormat8BitBGRA, outputFrameSize.width, &deckLinkOutputRowBytes) != S_OK)
|
||||
{
|
||||
error = "DeckLink output setup failed while calculating output row bytes.";
|
||||
return false;
|
||||
}
|
||||
outputFrameRowBytes = static_cast<unsigned>(deckLinkOutputRowBytes);
|
||||
outputPackTextureWidth = OutputIsTenBit()
|
||||
? PackedTextureWidthFromRowBytes(outputFrameRowBytes)
|
||||
: outputFrameSize.width;
|
||||
|
||||
if (InputIsTenBit())
|
||||
{
|
||||
int deckLinkInputRowBytes = 0;
|
||||
if (output->RowBytesForPixelFormat(bmdFormat10BitYUV, inputFrameSize.width, &deckLinkInputRowBytes) == S_OK)
|
||||
inputFrameRowBytes = static_cast<unsigned>(deckLinkInputRowBytes);
|
||||
else
|
||||
inputFrameRowBytes = MinimumV210RowBytes(inputFrameSize.width);
|
||||
}
|
||||
else
|
||||
{
|
||||
inputFrameRowBytes = inputFrameSize.width * 2u;
|
||||
}
|
||||
captureTextureWidth = InputIsTenBit()
|
||||
? PackedTextureWidthFromRowBytes(inputFrameRowBytes)
|
||||
: inputFrameSize.width / 2u;
|
||||
|
||||
std::ostringstream status;
|
||||
status << "DeckLink formats: capture " << (input ? VideoIOPixelFormatName(inputPixelFormat) : "none")
|
||||
<< ", output " << (OutputIsTenBit() ? "10-bit YUV v210" : "8-bit BGRA") << ".";
|
||||
if (!formatStatusMessage.empty())
|
||||
status << " " << formatStatusMessage;
|
||||
formatStatusMessage = status.str();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeckLinkSession::ConfigureInput(OpenGLComposite* owner, HDC hdc, HGLRC hglrc, const VideoFormat& inputVideoMode, std::string& error)
|
||||
{
|
||||
(void)hdc;
|
||||
(void)hglrc;
|
||||
|
||||
if (!input)
|
||||
{
|
||||
hasNoInputSource = true;
|
||||
@@ -185,10 +284,26 @@ bool DeckLinkSession::ConfigureInput(OpenGLComposite* owner, HDC hdc, HGLRC hglr
|
||||
return true;
|
||||
}
|
||||
|
||||
CComPtr<IDeckLinkVideoBufferAllocatorProvider> captureAllocator(new (std::nothrow) InputAllocatorPool(hdc, hglrc));
|
||||
|
||||
if (input->EnableVideoInputWithAllocatorProvider(inputVideoMode.displayMode, bmdFormat8BitYUV, bmdVideoInputFlagDefault, captureAllocator) != S_OK)
|
||||
const BMDPixelFormat deckLinkInputPixelFormat = DeckLinkPixelFormatForVideoIO(inputPixelFormat);
|
||||
if (input->EnableVideoInput(inputVideoMode.displayMode, deckLinkInputPixelFormat, bmdVideoInputFlagDefault) != S_OK)
|
||||
{
|
||||
if (inputPixelFormat == VideoIOPixelFormat::V210)
|
||||
{
|
||||
OutputDebugStringA("DeckLink 10-bit input could not be enabled; falling back to 8-bit capture.\n");
|
||||
inputPixelFormat = VideoIOPixelFormat::Uyvy8;
|
||||
inputFrameRowBytes = inputFrameSize.width * 2u;
|
||||
captureTextureWidth = inputFrameSize.width / 2u;
|
||||
if (input->EnableVideoInput(inputVideoMode.displayMode, bmdFormat8BitYUV, bmdVideoInputFlagDefault) == S_OK)
|
||||
{
|
||||
std::ostringstream status;
|
||||
status << "DeckLink formats: capture " << VideoIOPixelFormatName(inputPixelFormat)
|
||||
<< ", output " << (OutputIsTenBit() ? "10-bit YUV v210" : "8-bit BGRA")
|
||||
<< ". DeckLink 10-bit input enable failed; using 8-bit capture.";
|
||||
formatStatusMessage = status.str();
|
||||
goto input_enabled;
|
||||
}
|
||||
}
|
||||
|
||||
OutputDebugStringA("DeckLink input could not be enabled; continuing in output-only black-frame mode.\n");
|
||||
input.Release();
|
||||
hasNoInputSource = true;
|
||||
@@ -196,6 +311,7 @@ bool DeckLinkSession::ConfigureInput(OpenGLComposite* owner, HDC hdc, HGLRC hglr
|
||||
return true;
|
||||
}
|
||||
|
||||
input_enabled:
|
||||
captureDelegate.Attach(new (std::nothrow) CaptureDelegate(owner));
|
||||
if (captureDelegate == nullptr)
|
||||
{
|
||||
@@ -213,19 +329,8 @@ bool DeckLinkSession::ConfigureInput(OpenGLComposite* owner, HDC hdc, HGLRC hglr
|
||||
|
||||
bool DeckLinkSession::ConfigureOutput(OpenGLComposite* owner, HDC hdc, HGLRC hglrc, const VideoFormat& outputVideoMode, bool externalKeyingEnabled, std::string& error)
|
||||
{
|
||||
int outputFrameRowBytes = 0;
|
||||
if (output->RowBytesForPixelFormat(bmdFormat8BitBGRA, outputFrameSize.width, &outputFrameRowBytes) != S_OK)
|
||||
{
|
||||
error = "DeckLink output setup failed while calculating BGRA row bytes.";
|
||||
return false;
|
||||
}
|
||||
|
||||
playoutAllocator.Attach(new (std::nothrow) PinnedMemoryAllocator(hdc, hglrc, VideoFrameTransfer::GPUtoCPU, 1, outputFrameRowBytes * outputFrameSize.height));
|
||||
if (playoutAllocator == nullptr)
|
||||
{
|
||||
error = "DeckLink output setup failed while creating the playout allocator.";
|
||||
return false;
|
||||
}
|
||||
(void)hdc;
|
||||
(void)hglrc;
|
||||
|
||||
if (output->EnableVideoOutput(outputVideoMode.displayMode, bmdVideoOutputFlagDefault) != S_OK)
|
||||
{
|
||||
@@ -264,15 +369,9 @@ bool DeckLinkSession::ConfigureOutput(OpenGLComposite* owner, HDC hdc, HGLRC hgl
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
CComPtr<IDeckLinkMutableVideoFrame> outputFrame;
|
||||
CComPtr<IDeckLinkVideoBuffer> outputFrameBuffer;
|
||||
|
||||
if (playoutAllocator->AllocateVideoBuffer(&outputFrameBuffer) != S_OK)
|
||||
{
|
||||
error = "DeckLink output setup failed while allocating an output frame buffer.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (output->CreateVideoFrameWithBuffer(outputFrameSize.width, outputFrameSize.height, outputFrameRowBytes, bmdFormat8BitBGRA, bmdFrameFlagFlipVertical, outputFrameBuffer, &outputFrame) != S_OK)
|
||||
const BMDPixelFormat deckLinkOutputPixelFormat = OutputIsTenBit() ? bmdFormat10BitYUV : bmdFormat8BitBGRA;
|
||||
if (output->CreateVideoFrame(outputFrameSize.width, outputFrameSize.height, outputFrameRowBytes, deckLinkOutputPixelFormat, bmdFrameFlagFlipVertical, &outputFrame) != S_OK)
|
||||
{
|
||||
error = "DeckLink output setup failed while creating an output video frame.";
|
||||
return false;
|
||||
@@ -294,6 +393,9 @@ bool DeckLinkSession::ConfigureOutput(OpenGLComposite* owner, HDC hdc, HGLRC hgl
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!formatStatusMessage.empty())
|
||||
statusMessage = statusMessage.empty() ? formatStatusMessage : formatStatusMessage + " " + statusMessage;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -312,17 +414,6 @@ IDeckLinkMutableVideoFrame* DeckLinkSession::RotateOutputFrame()
|
||||
return outputVideoFrame.p;
|
||||
}
|
||||
|
||||
bool DeckLinkSession::TransferPlayoutFrame(void* address, GLuint outputTexture)
|
||||
{
|
||||
return playoutAllocator != nullptr && playoutAllocator->transferFrame(address, outputTexture);
|
||||
}
|
||||
|
||||
void DeckLinkSession::WaitForPlayoutTransferComplete(void* address)
|
||||
{
|
||||
if (playoutAllocator != nullptr)
|
||||
playoutAllocator->waitForTransferComplete(address);
|
||||
}
|
||||
|
||||
void DeckLinkSession::AccountForCompletionResult(BMDOutputFrameCompletionResult completionResult)
|
||||
{
|
||||
if (completionResult == bmdOutputFrameDisplayedLate || completionResult == bmdOutputFrameDropped)
|
||||
|
||||
Reference in New Issue
Block a user