Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use v210 as 10bit pixel format on decklink #21

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CMakeModules/Bootstrap_Linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ endif()
IF (CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86|x64|x86_64|amd64|e2k)")
ADD_COMPILE_OPTIONS (-msse3)
ADD_COMPILE_OPTIONS (-mssse3)
ADD_COMPILE_OPTIONS (-mavx)
ADD_COMPILE_OPTIONS (-msse4.1)
ADD_COMPILE_OPTIONS (-mavx2)
ELSE ()
ADD_COMPILE_DEFINITIONS (USE_SIMDE)
ENDIF ()
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeModules/Bootstrap_Windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ add_definitions(-D_WIN32_WINNT=0x601)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHa /Zi /W4 /WX /MP /fp:fast /Zm192 /FIcommon/compiler/vs/disable_silly_warnings.h")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D TBB_USE_ASSERT=1 /D TBB_USE_DEBUG /bigobj")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /Ot /Gy /bigobj")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /arch:AVX2 /Ot /Gy /bigobj")

if (POLICY CMP0045)
cmake_policy(SET CMP0045 OLD)
Expand Down
4 changes: 3 additions & 1 deletion src/accelerator/ogl/image/image_mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "../util/device.h"
#include "../util/texture.h"

#include <boost/align/aligned_allocator.hpp>

#include <common/array.h>
#include <common/bit_depth.h>
#include <common/future.h>
Expand Down Expand Up @@ -91,7 +93,7 @@ class image_renderer
const core::video_format_desc& format_desc)
{
if (layers.empty()) { // Bypass GPU with empty frame.
static const std::vector<uint8_t> buffer(max_frame_size_, 0);
static const std::vector<uint8_t, boost::alignment::aligned_allocator<uint8_t, 32>> buffer(max_frame_size_, 0);
return make_ready_future(array<const std::uint8_t>(buffer.data(), format_desc.size, true));
}

Expand Down
73 changes: 58 additions & 15 deletions src/modules/decklink/consumer/decklink_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,25 +222,47 @@ class decklink_frame
, public IDeckLinkVideoFrameMetadataExtensions
{
core::video_format_desc format_desc_;
BMDPixelFormat pix_fmt_;
std::shared_ptr<void> data_;
std::atomic<int> ref_count_{0};
int nb_samples_;
const bool hdr_;
core::color_space color_space_;
hdr_meta_configuration hdr_metadata_;
BMDFrameFlags flags_;
BMDPixelFormat pix_fmt_;

public:
decklink_frame(std::shared_ptr<void> data, core::video_format_desc format_desc, int nb_samples, bool hdr, core::color_space color_space, const hdr_meta_configuration& hdr_metadata)
decklink_frame(core::video_format_desc format_desc,
int nb_samples,
bool hdr,
core::color_space color_space,
const hdr_meta_configuration& hdr_metadata,
BMDPixelFormat pix_fmt,
std::shared_ptr<void> data)
: format_desc_(std::move(format_desc))
, pix_fmt_(pix_fmt)
, data_(std::move(data))
, nb_samples_(nb_samples)
, hdr_(hdr)
, color_space_(color_space)
, hdr_metadata_(hdr_metadata)
, flags_(hdr ? bmdFrameFlagDefault | bmdFrameContainsHDRMetadata : bmdFrameFlagDefault)
{
}

decklink_frame(core::video_format_desc format_desc,
int nb_samples,
bool hdr,
core::color_space color_space,
const hdr_meta_configuration& hdr_metadata)
: format_desc_(std::move(format_desc))
, pix_fmt_(get_pixel_format(hdr))
, data_(allocate_frame_data(format_desc, pix_fmt_))
, nb_samples_(nb_samples)
, hdr_(hdr)
, color_space_(color_space)
, hdr_metadata_(hdr_metadata)
, flags_(hdr ? bmdFrameFlagDefault | bmdFrameContainsHDRMetadata : bmdFrameFlagDefault)
{
}

Expand All @@ -255,7 +277,7 @@ class decklink_frame
#else
REFIID iunknown = IID_IUnknown;
#endif
HRESULT result = E_NOINTERFACE;
HRESULT result = E_NOINTERFACE;

if (ppv == nullptr)
return E_INVALIDARG;
Expand Down Expand Up @@ -292,9 +314,12 @@ class decklink_frame

// IDecklinkVideoFrame

long STDMETHODCALLTYPE GetWidth() override { return static_cast<long>(format_desc_.width); }
long STDMETHODCALLTYPE GetHeight() override { return static_cast<long>(format_desc_.height); }
long STDMETHODCALLTYPE GetRowBytes() override { return static_cast<long>(get_row_bytes(format_desc_, hdr_)); }
long STDMETHODCALLTYPE GetWidth() override { return static_cast<long>(format_desc_.width); }
long STDMETHODCALLTYPE GetHeight() override { return static_cast<long>(format_desc_.height); }
long STDMETHODCALLTYPE GetRowBytes() override
{
return static_cast<long>(get_row_bytes(pix_fmt_, format_desc_.width));
}
BMDPixelFormat STDMETHODCALLTYPE GetPixelFormat() override { return pix_fmt_; }
BMDFrameFlags STDMETHODCALLTYPE GetFlags() override { return flags_; }

Expand Down Expand Up @@ -338,7 +363,7 @@ class decklink_frame
HRESULT STDMETHODCALLTYPE GetFloat(BMDDeckLinkFrameMetadataID metadataID, double* value)
{
const auto color_space = (color_space_ == core::color_space::bt2020) ? &REC_2020 : &REC_709;
HRESULT result = S_OK;
HRESULT result = S_OK;

switch (metadataID) {
case bmdDeckLinkFrameMetadataHDRDisplayPrimariesRedX:
Expand Down Expand Up @@ -438,7 +463,7 @@ struct decklink_secondary_port final : public IDeckLinkVideoOutputCallback
const core::video_format_desc decklink_format_desc_;
com_ptr<IDeckLinkDisplayMode> mode_ = get_display_mode(output_,
decklink_format_desc_.format,
get_pixel_format(config_.hdr),
config_.hdr ? bmdFormat10BitYUV : bmdFormat8BitBGRA,
bmdSupportedVideoModeDefault,
config_.hdr);

Expand Down Expand Up @@ -555,7 +580,13 @@ struct decklink_secondary_port final : public IDeckLinkVideoOutputCallback
void schedule_next_video(std::shared_ptr<void> image_data, int nb_samples, BMDTimeValue display_time)
{
auto packed_frame = wrap_raw<com_ptr, IDeckLinkVideoFrame>(
new decklink_frame(std::move(image_data), decklink_format_desc_, nb_samples, config_.hdr, core::color_space::bt709, config_.hdr_meta));
new decklink_frame(decklink_format_desc_,
nb_samples,
config_.hdr,
core::color_space::bt709,
config_.hdr_meta,
config_.hdr ? bmdFormat10BitYUV : bmdFormat8BitBGRA,
std::move(image_data)));
if (FAILED(output_->ScheduleVideoFrame(get_raw(packed_frame),
display_time,
decklink_format_desc_.duration,
Expand Down Expand Up @@ -708,7 +739,8 @@ struct decklink_consumer final : public IDeckLinkVideoOutputCallback
nb_samples);
}

std::shared_ptr<void> image_data = allocate_frame_data(decklink_format_desc_, config_.hdr);
std::shared_ptr<void> image_data =
allocate_frame_data(decklink_format_desc_, config_.hdr ? bmdFormat10BitYUV : bmdFormat8BitBGRA);

schedule_next_video(image_data, nb_samples, video_scheduled_, config_.hdr_meta.default_color_space);
for (auto& context : secondary_port_contexts_) {
Expand Down Expand Up @@ -932,7 +964,8 @@ struct decklink_consumer final : public IDeckLinkVideoOutputCallback
mode_->GetFieldDominance(),
config_.hdr);

schedule_next_video(image_data, nb_samples, video_display_time, frame1.pixel_format_desc().color_space);
schedule_next_video(
image_data, nb_samples, video_display_time, frame1.pixel_format_desc().color_space);

if (config_.embedded_audio) {
schedule_next_audio(std::move(audio_data), nb_samples);
Expand Down Expand Up @@ -992,12 +1025,22 @@ struct decklink_consumer final : public IDeckLinkVideoOutputCallback
audio_scheduled_ += nb_samples; // TODO - what if there are too many/few samples in this frame?
}

void schedule_next_video(std::shared_ptr<void> image_data, int nb_samples, BMDTimeValue display_time, core::color_space color_space)
void schedule_next_video(std::shared_ptr<void> image_data,
int nb_samples,
BMDTimeValue display_time,
core::color_space color_space)
{
auto fill_frame = wrap_raw<com_ptr, IDeckLinkVideoFrame>(
new decklink_frame(std::move(image_data), decklink_format_desc_, nb_samples, config_.hdr, color_space, config_.hdr_meta));
auto frame = wrap_raw<com_ptr, IDeckLinkVideoFrame>(
new decklink_frame(decklink_format_desc_,
nb_samples,
config_.hdr,
color_space,
config_.hdr_meta,
config_.hdr ? bmdFormat10BitYUV : bmdFormat8BitBGRA,
std::move(image_data)));

if (FAILED(output_->ScheduleVideoFrame(
get_raw(fill_frame), display_time, decklink_format_desc_.duration, decklink_format_desc_.time_scale))) {
get_raw(frame), display_time, decklink_format_desc_.duration, decklink_format_desc_.time_scale))) {
CASPAR_LOG(error) << print() << L" Failed to schedule primary video.";
}
}
Expand Down
Loading
Loading