Decklink separation

This commit is contained in:
Aiden
2026-05-09 14:42:11 +10:00
parent 4ffbb97abf
commit 46f2f1ece5
4 changed files with 93 additions and 5 deletions

View File

@@ -3,14 +3,73 @@
#include "DeckLinkSession.h"
#include "VideoIOTypes.h"
#include <array>
namespace
{
struct VideoIOBackendRegistration
{
VideoIOBackendDescriptor descriptor;
VideoIODeviceFactory factory;
};
const std::array<VideoIOBackendRegistration, 1>& RegisteredBackends()
{
static const std::array<VideoIOBackendRegistration, 1> backends = { {
{
{
VideoIOBackendId::DeckLink,
"decklink",
"Blackmagic DeckLink",
"Please install the Blackmagic DeckLink drivers to use the features of this application.",
"This application requires the selected video I/O drivers installed."
},
[]() { return std::make_unique<DeckLinkSession>(); }
}
} };
return backends;
}
}
const VideoIOBackendDescriptor* GetVideoIOBackendDescriptor(VideoIOBackendId backendId)
{
for (const VideoIOBackendRegistration& registration : RegisteredBackends())
{
if (registration.descriptor.backendId == backendId)
return &registration.descriptor;
}
return nullptr;
}
std::vector<VideoIOBackendDescriptor> ListVideoIOBackendDescriptors()
{
std::vector<VideoIOBackendDescriptor> descriptors;
descriptors.reserve(RegisteredBackends().size());
for (const VideoIOBackendRegistration& registration : RegisteredBackends())
descriptors.push_back(registration.descriptor);
return descriptors;
}
std::unique_ptr<VideoIODevice> CreateVideoIODevice(VideoIOBackendId backendId, std::string& error)
{
switch (backendId)
for (const VideoIOBackendRegistration& registration : RegisteredBackends())
{
case VideoIOBackendId::DeckLink:
return std::make_unique<DeckLinkSession>();
if (registration.descriptor.backendId != backendId)
continue;
error.clear();
return registration.factory ? registration.factory() : nullptr;
}
error = "Unsupported video I/O backend.";
return nullptr;
}
bool IsVideoIOBackendUnavailableError(VideoIOBackendId backendId, const std::string& error)
{
const VideoIOBackendDescriptor* descriptor = GetVideoIOBackendDescriptor(backendId);
return descriptor != nullptr &&
descriptor->unavailableMessage != nullptr &&
*descriptor->unavailableMessage != '\0' &&
error == descriptor->unavailableMessage;
}

View File

@@ -2,9 +2,25 @@
#include "VideoIOConfig.h"
#include <functional>
#include <memory>
#include <string>
#include <vector>
class VideoIODevice;
struct VideoIOBackendDescriptor
{
VideoIOBackendId backendId = VideoIOBackendId::DeckLink;
const char* backendName = "decklink";
const char* displayName = "Blackmagic DeckLink";
const char* unavailableMessage = "";
const char* unavailableTitle = "Video I/O initialization failed";
};
using VideoIODeviceFactory = std::function<std::unique_ptr<VideoIODevice>()>;
const VideoIOBackendDescriptor* GetVideoIOBackendDescriptor(VideoIOBackendId backendId);
std::vector<VideoIOBackendDescriptor> ListVideoIOBackendDescriptors();
std::unique_ptr<VideoIODevice> CreateVideoIODevice(VideoIOBackendId backendId, std::string& error);
bool IsVideoIOBackendUnavailableError(VideoIOBackendId backendId, const std::string& error);