NDI related tests
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#include "NdiInput.h"
|
||||
|
||||
#include "NdiInputFormat.h"
|
||||
#include "logging/Logger.h"
|
||||
#include "video/core/VideoIOFormat.h"
|
||||
|
||||
#include <Processing.NDI.Lib.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
@@ -44,32 +44,6 @@ bool IsDefaultDeviceName(const std::string& device)
|
||||
return device.empty() || device == "default" || device == "auto";
|
||||
}
|
||||
|
||||
std::string FourCcName(NDIlib_FourCC_video_type_e fourCc)
|
||||
{
|
||||
char text[5] = {};
|
||||
const auto value = static_cast<uint32_t>(fourCc);
|
||||
text[0] = static_cast<char>(value & 0xff);
|
||||
text[1] = static_cast<char>((value >> 8) & 0xff);
|
||||
text[2] = static_cast<char>((value >> 16) & 0xff);
|
||||
text[3] = static_cast<char>((value >> 24) & 0xff);
|
||||
return text;
|
||||
}
|
||||
|
||||
bool MapNdiPixelFormat(NDIlib_FourCC_video_type_e fourCc, VideoIOPixelFormat& pixelFormat)
|
||||
{
|
||||
switch (fourCc)
|
||||
{
|
||||
case NDIlib_FourCC_video_type_BGRA:
|
||||
case NDIlib_FourCC_video_type_BGRX:
|
||||
pixelFormat = VideoIOPixelFormat::Bgra8;
|
||||
return true;
|
||||
case NDIlib_FourCC_video_type_UYVY:
|
||||
pixelFormat = VideoIOPixelFormat::Uyvy8;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NdiInput::NdiInput(InputFrameMailbox& mailbox) :
|
||||
@@ -262,12 +236,12 @@ void NdiInput::HandleVideoFrame(void*, const void* frame)
|
||||
}
|
||||
|
||||
VideoIOPixelFormat pixelFormat = VideoIOPixelFormat::Bgra8;
|
||||
if (!MapNdiPixelFormat(videoFrame.FourCC, pixelFormat))
|
||||
if (!MapNdiFourCcToVideoIOPixelFormat(videoFrame.FourCC, pixelFormat))
|
||||
{
|
||||
mUnsupportedFrames.fetch_add(1, std::memory_order_relaxed);
|
||||
bool expected = false;
|
||||
if (mLoggedUnsupportedFrame.compare_exchange_strong(expected, true, std::memory_order_relaxed))
|
||||
TryLog(LogLevel::Warning, "ndi-input", "Unsupported NDI input frame format " + FourCcName(videoFrame.FourCC) + ".");
|
||||
TryLog(LogLevel::Warning, "ndi-input", std::string("Unsupported NDI input frame format ") + NdiFourCcName(videoFrame.FourCC) + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
35
src/video/ndi/NdiInputFormat.cpp
Normal file
35
src/video/ndi/NdiInputFormat.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "NdiInputFormat.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace RenderCadenceCompositor
|
||||
{
|
||||
const char* NdiFourCcName(NDIlib_FourCC_video_type_e fourCc)
|
||||
{
|
||||
static thread_local std::array<char, 5> text = {};
|
||||
const auto value = static_cast<uint32_t>(fourCc);
|
||||
text[0] = static_cast<char>(value & 0xff);
|
||||
text[1] = static_cast<char>((value >> 8) & 0xff);
|
||||
text[2] = static_cast<char>((value >> 16) & 0xff);
|
||||
text[3] = static_cast<char>((value >> 24) & 0xff);
|
||||
text[4] = '\0';
|
||||
return text.data();
|
||||
}
|
||||
|
||||
bool MapNdiFourCcToVideoIOPixelFormat(NDIlib_FourCC_video_type_e fourCc, VideoIOPixelFormat& pixelFormat)
|
||||
{
|
||||
switch (fourCc)
|
||||
{
|
||||
case NDIlib_FourCC_video_type_BGRA:
|
||||
case NDIlib_FourCC_video_type_BGRX:
|
||||
pixelFormat = VideoIOPixelFormat::Bgra8;
|
||||
return true;
|
||||
case NDIlib_FourCC_video_type_UYVY:
|
||||
pixelFormat = VideoIOPixelFormat::Uyvy8;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/video/ndi/NdiInputFormat.h
Normal file
11
src/video/ndi/NdiInputFormat.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "video/core/VideoIOFormat.h"
|
||||
|
||||
#include <Processing.NDI.Lib.h>
|
||||
|
||||
namespace RenderCadenceCompositor
|
||||
{
|
||||
const char* NdiFourCcName(NDIlib_FourCC_video_type_e fourCc);
|
||||
bool MapNdiFourCcToVideoIOPixelFormat(NDIlib_FourCC_video_type_e fourCc, VideoIOPixelFormat& pixelFormat);
|
||||
}
|
||||
Reference in New Issue
Block a user