Skip to content

Commit

Permalink
HDR, OCIO, Display and LUT working in outputDevice.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Feb 25, 2025
1 parent 3eae16a commit 55eefb3
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/tlCore/HDR.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@ namespace tl
void from_json(const nlohmann::json&, HDRBezier&);

///@}

enum EOTFType : uint8_t
{
EOTF_BT601 = 0,
EOTF_BT709 = 1,
EOTF_BT2020 = 2,
EOTF_BT2100_HLG = 3,
EOTF_BT2100_PQ = 4
};

//! HDR data.
struct HDRData
{
uint8_t eotf = 0;
uint8_t eotf = EOTFType::EOTF_BT709;
//! Default Rec. 2020 color primaries (red, green, blue, white).
std::array<math::Vector2f, HDRPrimaries::Count> primaries =
{
Expand Down
97 changes: 96 additions & 1 deletion lib/tlDevice/NDI/NDIOutputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace tl
namespace
{
const std::chrono::milliseconds timeout(5);
const char* kModule = "NDI";
}

namespace
Expand Down Expand Up @@ -699,7 +700,7 @@ namespace tl
GL_STREAM_READ);
}

if (audioDataChanged && p.thread.render)
if (audioDataChanged && p.thread.render && !config.noAudio)
{
try
{
Expand All @@ -721,6 +722,7 @@ namespace tl
{
try
{
_metadata();
_render(
config,
ocioOptions,
Expand Down Expand Up @@ -1203,6 +1205,10 @@ namespace tl
break;
}
}

void OutputDevice::_metadata()
{
}

void OutputDevice::_render(
const device::DeviceConfig& config,
Expand Down Expand Up @@ -1341,6 +1347,95 @@ namespace tl
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
}

std::shared_ptr<image::HDRData> hdrData;
switch(p.thread.hdrMode)
{
case device::HDRMode::None:
break;
case device::HDRMode::FromFile:
case device::HDRMode::Custom:
if (p.thread.videoData.empty())
return;
hdrData = device::getHDRData(p.thread.videoData[0]);
break;
break;
}

if (hdrData)
{
std::string primariesName = "bt_2020";
std::string transferName = "bt_2020";
std::string matrixName = "bt_2020";
const auto& primaries = hdrData->primaries;
if (primaries[0].x == 0.708F && primaries[0].y == 0.292F &&
primaries[1].x == 0.170F && primaries[1].y == 0.797F &&
primaries[2].x == 0.131F && primaries[2].y == 0.046F &&
primaries[3].x == 0.3127F && primaries[3].y == 0.3290F)
{
primariesName = "bt_2020";
}
else if (primaries[0].x == 0.640F && primaries[0].y == 0.330F &&
primaries[1].x == 0.300F && primaries[1].y == 0.600F &&
primaries[2].x == 0.150F && primaries[2].y == 0.060F &&
primaries[3].x == 0.3127F && primaries[3].y == 0.3290F)
{
primariesName = "bt_709";
}
else if (primaries[0].x == 0.630F && primaries[0].y == 0.340F &&
primaries[1].x == 0.310F && primaries[1].y == 0.595F &&
primaries[2].x == 0.155F && primaries[2].y == 0.070F &&
primaries[3].x == 0.3127F && primaries[3].y == 0.3290F)
{
primariesName = "bt_601";
}
else
{
if (auto context = p.context.lock())
{
auto logSystem = context->getLogSystem();
logSystem->print(
"tl::ndi::OutputDevice",
"Unknown primaries. Using bt_2020",
log::Type::Error,
kModule);
}
}

switch(hdrData->eotf)
{
case image::EOTFType::EOTF_BT601:
transferName = "bt_601";
matrixName = "bt_601";
break;
case image::EOTFType::EOTF_BT709:
transferName = "bt_709";
matrixName = "bt_709";
break;
case image::EOTFType::EOTF_BT2020:
transferName = "bt_2020";
matrixName = "bt_2020";
break;
case image::EOTFType::EOTF_BT2100_HLG:
transferName = "bt_2100_hlg";
matrixName = "bt_2100";
break;
case image::EOTFType::EOTF_BT2100_PQ:
transferName = "bt_2100_pq";
matrixName = "bt_2100";
break;
}

const std::string& metadata = string::Format("<ndi_color_info "
" transfer=\"{0}\" "
" matrix=\"{1}\" "
" primaries=\"{2}\" "
"/> ").
arg(transferName).
arg(matrixName).
arg(primariesName);
video_frame.p_metadata = metadata.c_str();
}

NDIlib_send_send_video(p.thread.NDI_send, &video_frame);

}
Expand Down
1 change: 1 addition & 0 deletions lib/tlDevice/NDI/NDIOutputDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ namespace tl
const otime::TimeRange&,
const otime::RationalTime&,
const std::vector<timeline::AudioData>&);
void _metadata();
math::Matrix4x4f _projectionMatrix() const noexcept;
void _render(
const device::DeviceConfig&,
Expand Down
1 change: 1 addition & 0 deletions lib/tlDevice/OutputData.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ namespace tl
int displayModeIndex = -1;
PixelType pixelType = PixelType::None;
BoolOptions boolOptions;
bool noAudio = false;

bool operator == (const DeviceConfig&) const;
bool operator != (const DeviceConfig&) const;
Expand Down

0 comments on commit 55eefb3

Please sign in to comment.