Skip to content

Commit

Permalink
decklink: better name for format strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
niklaspandersson committed Sep 23, 2024
1 parent 91831c1 commit e6fcc58
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 62 deletions.
10 changes: 5 additions & 5 deletions src/modules/decklink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ project (decklink)

set(SOURCES
consumer/decklink_consumer.cpp
consumer/frame_factory_hdr_v210.cpp
consumer/frame_factory_sdr_bgra.cpp
consumer/hdr_v210_strategy.cpp
consumer/sdr_bgra_strategy.cpp
consumer/config.cpp
consumer/monitor.cpp

Expand All @@ -14,9 +14,9 @@ set(SOURCES
)
set(HEADERS
consumer/decklink_consumer.h
consumer/frame_factory_hdr_v210.h
consumer/frame_factory_sdr_bgra.h
consumer/frame_factory.h
consumer/hdr_v210_strategy.h
consumer/sdr_bgra_strategy.h
consumer/format_strategy.h
consumer/config.h
consumer/monitor.h

Expand Down
40 changes: 20 additions & 20 deletions src/modules/decklink/consumer/decklink_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include "common/os/thread.h"
#include "config.h"
#include "decklink_consumer.h"
#include "frame_factory_hdr_v210.h"
#include "frame_factory_sdr_bgra.h"
#include "hdr_v210_strategy.h"
#include "sdr_bgra_strategy.h"
#include "monitor.h"

#include "../decklink.h"
Expand Down Expand Up @@ -194,10 +194,10 @@ core::video_format_desc get_decklink_format(const port_configuration& confi
return fallback_format_desc;
}

spl::shared_ptr<frame_factory> create_frame_factory(bool hdr)
spl::shared_ptr<format_strategy> create_format_strategy(bool hdr)
{
return hdr ? spl::make_shared<frame_factory, frame_factory_hdr_v210>()
: spl::make_shared<frame_factory, frame_factory_sdr_bgra>();
return hdr ? spl::make_shared<format_strategy, hdr_v210_strategy>()
: spl::make_shared<format_strategy, sdr_bgra_strategy>();
}

enum EOTF
Expand Down Expand Up @@ -437,7 +437,7 @@ struct decklink_secondary_port final : public IDeckLinkVideoOutputCallback
{
const configuration config_;
const port_configuration output_config_;
spl::shared_ptr<frame_factory> frame_factory_;
spl::shared_ptr<format_strategy> format_strategy_;
com_ptr<IDeckLink> decklink_ = get_device(output_config_.device_index);
com_iface_ptr<IDeckLinkOutput> output_ = iface_cast<IDeckLinkOutput>(decklink_);
com_iface_ptr<IDeckLinkKeyer> keyer_ = iface_cast<IDeckLinkKeyer>(decklink_, true);
Expand All @@ -454,7 +454,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,
frame_factory_->get_pixel_format(),
format_strategy_->get_pixel_format(),
bmdSupportedVideoModeDefault);

decklink_secondary_port(const configuration& config,
Expand All @@ -465,7 +465,7 @@ struct decklink_secondary_port final : public IDeckLinkVideoOutputCallback
int device_sync_group)
: config_(config)
, output_config_(std::move(output_config))
, frame_factory_(new frame_factory_sdr_bgra())
, format_strategy_(new sdr_bgra_strategy())
, device_sync_group_(device_sync_group)
, channel_format_desc_(std::move(channel_format_desc))
, decklink_format_desc_(get_decklink_format(output_config_, main_decklink_format_desc))
Expand Down Expand Up @@ -557,7 +557,7 @@ struct decklink_secondary_port final : public IDeckLinkVideoOutputCallback
frame1 = frame;
}

auto image_data = frame_factory_->convert_frame_for_port(
auto image_data = format_strategy_->convert_frame_for_port(
channel_format_desc_, decklink_format_desc_, output_config_, frame1, frame2, mode_->GetFieldDominance());

schedule_next_video(image_data, 0, display_time);
Expand All @@ -569,8 +569,8 @@ struct decklink_secondary_port final : public IDeckLinkVideoOutputCallback
decklink_format_desc_,
nb_samples,
config_.hdr,
frame_factory_->get_pixel_format(),
frame_factory_->get_row_bytes(decklink_format_desc_.width),
format_strategy_->get_pixel_format(),
format_strategy_->get_row_bytes(decklink_format_desc_.width),
core::color_space::bt709,
config_.hdr_meta));
if (FAILED(output_->ScheduleVideoFrame(get_raw(packed_frame),
Expand Down Expand Up @@ -600,9 +600,9 @@ struct decklink_secondary_port final : public IDeckLinkVideoOutputCallback

struct decklink_consumer final : public IDeckLinkVideoOutputCallback
{
const int channel_index_;
const configuration config_;
spl::shared_ptr<frame_factory> frame_factory_;
const int channel_index_;
const configuration config_;
spl::shared_ptr<format_strategy> format_strategy_;

com_ptr<IDeckLink> decklink_ = get_device(config_.primary.device_index);
com_iface_ptr<IDeckLinkOutput> output_ = iface_cast<IDeckLinkOutput>(decklink_);
Expand Down Expand Up @@ -638,7 +638,7 @@ struct decklink_consumer final : public IDeckLinkVideoOutputCallback

com_ptr<IDeckLinkDisplayMode> mode_ = get_display_mode(output_,
decklink_format_desc_.format,
frame_factory_->get_pixel_format(),
format_strategy_->get_pixel_format(),
bmdSupportedVideoModeDefault);

std::atomic<bool> abort_request_{false};
Expand All @@ -647,7 +647,7 @@ struct decklink_consumer final : public IDeckLinkVideoOutputCallback
decklink_consumer(const configuration& config, core::video_format_desc channel_format_desc, int channel_index)
: channel_index_(channel_index)
, config_(config)
, frame_factory_(create_frame_factory(config.hdr))
, format_strategy_(create_format_strategy(config.hdr))
, channel_format_desc_(std::move(channel_format_desc))
, decklink_format_desc_(get_decklink_format(config.primary, channel_format_desc_))
{
Expand Down Expand Up @@ -726,7 +726,7 @@ struct decklink_consumer final : public IDeckLinkVideoOutputCallback
nb_samples);
}

std::shared_ptr<void> image_data = frame_factory_->allocate_frame_data(decklink_format_desc_);
std::shared_ptr<void> image_data = format_strategy_->allocate_frame_data(decklink_format_desc_);

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 @@ -943,7 +943,7 @@ struct decklink_consumer final : public IDeckLinkVideoOutputCallback
if (i == -1) {
// Primary port
std::shared_ptr<void> image_data =
frame_factory_->convert_frame_for_port(channel_format_desc_,
format_strategy_->convert_frame_for_port(channel_format_desc_,
decklink_format_desc_,
config_.primary,
frame1,
Expand Down Expand Up @@ -1016,8 +1016,8 @@ struct decklink_consumer final : public IDeckLinkVideoOutputCallback
BMDTimeValue display_time,
core::color_space color_space)
{
auto fmt = frame_factory_->get_pixel_format();
auto row_bytes = frame_factory_->get_row_bytes(decklink_format_desc_.width);
auto fmt = format_strategy_->get_pixel_format();
auto row_bytes = format_strategy_->get_row_bytes(decklink_format_desc_.width);
auto fill_frame = wrap_raw<com_ptr, IDeckLinkVideoFrame>(new decklink_frame(
std::move(image_data), decklink_format_desc_, nb_samples, config_.hdr, fmt, row_bytes, color_space, config_.hdr_meta));
if (FAILED(output_->ScheduleVideoFrame(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@

namespace caspar { namespace decklink {

class frame_factory
class format_strategy
{
protected:
frame_factory() = default;
format_strategy() = default;

public:
frame_factory& operator=(const frame_factory&) = delete;
virtual ~frame_factory() = default;
format_strategy& operator=(const format_strategy&) = delete;
virtual ~format_strategy() = default;

frame_factory(const frame_factory&) = delete;
format_strategy(const format_strategy&) = delete;

virtual BMDPixelFormat get_pixel_format() = 0;
virtual int get_row_bytes(int width) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "../StdAfx.h"

#include "frame_factory_hdr_v210.h"
#include "hdr_v210_strategy.h"

#include <common/memshfl.h>

Expand Down Expand Up @@ -198,7 +198,7 @@ void pack_v210(const ARGBPixel* src, const std::vector<int32_t>& color_matrix, u
}


struct frame_factory_hdr_v210::impl final
struct hdr_v210_strategy::impl final
{
std::vector<float> bt709{0.2126, 0.7152, 0.0722, -0.1146, -0.3854, 0.5, 0.5, -0.4542, -0.0458};

Expand Down Expand Up @@ -338,22 +338,22 @@ struct frame_factory_hdr_v210::impl final
}
};

frame_factory_hdr_v210::frame_factory_hdr_v210()
hdr_v210_strategy::hdr_v210_strategy()
: impl_(new impl())
{
}

frame_factory_hdr_v210::~frame_factory_hdr_v210() {}
hdr_v210_strategy::~hdr_v210_strategy() {}

BMDPixelFormat frame_factory_hdr_v210::get_pixel_format() { return impl_->get_pixel_format(); }
int frame_factory_hdr_v210::get_row_bytes(int width) { return impl_->get_row_bytes(width); }
BMDPixelFormat hdr_v210_strategy::get_pixel_format() { return impl_->get_pixel_format(); }
int hdr_v210_strategy::get_row_bytes(int width) { return impl_->get_row_bytes(width); }

std::shared_ptr<void> frame_factory_hdr_v210::allocate_frame_data(const core::video_format_desc& format_desc)
std::shared_ptr<void> hdr_v210_strategy::allocate_frame_data(const core::video_format_desc& format_desc)
{
return impl_->allocate_frame_data(format_desc);
}
std::shared_ptr<void>
frame_factory_hdr_v210::convert_frame_for_port(const core::video_format_desc& channel_format_desc,
hdr_v210_strategy::convert_frame_for_port(const core::video_format_desc& channel_format_desc,
const core::video_format_desc& decklink_format_desc,
const port_configuration& config,
const core::const_frame& frame1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "../StdAfx.h"

#include "config.h"
#include "frame_factory.h"
#include "format_strategy.h"

#include "../decklink_api.h"

Expand All @@ -35,13 +35,13 @@

namespace caspar { namespace decklink {

class frame_factory_sdr_bgra
: public frame_factory
, std::enable_shared_from_this<frame_factory_sdr_bgra>
class hdr_v210_strategy
: public format_strategy
, std::enable_shared_from_this<hdr_v210_strategy>
{
public:
explicit frame_factory_sdr_bgra();
virtual ~frame_factory_sdr_bgra();
explicit hdr_v210_strategy();
virtual ~hdr_v210_strategy();

virtual BMDPixelFormat get_pixel_format();
virtual int get_row_bytes(int width);
Expand All @@ -56,8 +56,8 @@ class frame_factory_sdr_bgra
private:
struct impl;
std::unique_ptr<impl> impl_;
frame_factory_sdr_bgra(const frame_factory_sdr_bgra&) = delete;
frame_factory_sdr_bgra& operator=(const frame_factory_sdr_bgra&) = delete;
hdr_v210_strategy(const hdr_v210_strategy&) = delete;
hdr_v210_strategy& operator=(const hdr_v210_strategy&) = delete;
};

}} // namespace caspar::decklink
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "../StdAfx.h"

#include "frame_factory_sdr_bgra.h"
#include "sdr_bgra_strategy.h"

#include <common/memshfl.h>

Expand All @@ -40,7 +40,7 @@ std::shared_ptr<void> convert_to_key_only(const std::shared_ptr<void>& image_dat
return key_data;
}

struct frame_factory_sdr_bgra::impl final
struct sdr_bgra_strategy::impl final
{
public:
impl() = default;
Expand Down Expand Up @@ -181,22 +181,22 @@ struct frame_factory_sdr_bgra::impl final
}
};

frame_factory_sdr_bgra::frame_factory_sdr_bgra()
sdr_bgra_strategy::sdr_bgra_strategy()
: impl_(new impl())
{
}

frame_factory_sdr_bgra::~frame_factory_sdr_bgra() {}
sdr_bgra_strategy::~sdr_bgra_strategy() {}

BMDPixelFormat frame_factory_sdr_bgra::get_pixel_format() { return impl_->get_pixel_format(); }
int frame_factory_sdr_bgra::get_row_bytes(int width) { return impl_->get_row_bytes(width); }
BMDPixelFormat sdr_bgra_strategy::get_pixel_format() { return impl_->get_pixel_format(); }
int sdr_bgra_strategy::get_row_bytes(int width) { return impl_->get_row_bytes(width); }

std::shared_ptr<void> frame_factory_sdr_bgra::allocate_frame_data(const core::video_format_desc& format_desc)
std::shared_ptr<void> sdr_bgra_strategy::allocate_frame_data(const core::video_format_desc& format_desc)
{
return impl_->allocate_frame_data(format_desc);
}
std::shared_ptr<void>
frame_factory_sdr_bgra::convert_frame_for_port(const core::video_format_desc& channel_format_desc,
sdr_bgra_strategy::convert_frame_for_port(const core::video_format_desc& channel_format_desc,
const core::video_format_desc& decklink_format_desc,
const port_configuration& config,
const core::const_frame& frame1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "../StdAfx.h"

#include "config.h"
#include "frame_factory.h"
#include "format_strategy.h"

#include "../decklink_api.h"

Expand All @@ -35,13 +35,13 @@

namespace caspar { namespace decklink {

class frame_factory_hdr_v210
: public frame_factory
, std::enable_shared_from_this<frame_factory_hdr_v210>
class sdr_bgra_strategy
: public format_strategy
, std::enable_shared_from_this<sdr_bgra_strategy>
{
public:
explicit frame_factory_hdr_v210();
virtual ~frame_factory_hdr_v210();
explicit sdr_bgra_strategy();
virtual ~sdr_bgra_strategy();

virtual BMDPixelFormat get_pixel_format();
virtual int get_row_bytes(int width);
Expand All @@ -56,8 +56,8 @@ class frame_factory_hdr_v210
private:
struct impl;
std::unique_ptr<impl> impl_;
frame_factory_hdr_v210(const frame_factory_hdr_v210&) = delete;
frame_factory_hdr_v210& operator=(const frame_factory_hdr_v210&) = delete;
sdr_bgra_strategy(const sdr_bgra_strategy&) = delete;
sdr_bgra_strategy& operator=(const sdr_bgra_strategy&) = delete;
};

}} // namespace caspar::decklink

0 comments on commit e6fcc58

Please sign in to comment.