Skip to content

Commit 3ab9afc

Browse files
authored
fix: pass channel_info object to consumer factory methods (#1614)
1 parent 8eb9916 commit 3ab9afc

38 files changed

+1259
-1201
lines changed

src/accelerator/accelerator.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@ struct accelerator::impl
2525
{
2626
}
2727

28-
std::unique_ptr<core::image_mixer>
29-
create_image_mixer(int channel_id, common::bit_depth depth, core::color_space color_space)
28+
std::unique_ptr<core::image_mixer> create_image_mixer(int channel_id, common::bit_depth depth)
3029
{
31-
return std::make_unique<ogl::image_mixer>(spl::make_shared_ptr(get_device()),
32-
channel_id,
33-
format_repository_.get_max_video_format_size(),
34-
depth,
35-
color_space);
30+
return std::make_unique<ogl::image_mixer>(
31+
spl::make_shared_ptr(get_device()), channel_id, format_repository_.get_max_video_format_size(), depth);
3632
}
3733

3834
std::shared_ptr<ogl::device> get_device()
@@ -52,10 +48,9 @@ accelerator::accelerator(const core::video_format_repository format_repository)
5248

5349
accelerator::~accelerator() {}
5450

55-
std::unique_ptr<core::image_mixer>
56-
accelerator::create_image_mixer(const int channel_id, common::bit_depth depth, core::color_space color_space)
51+
std::unique_ptr<core::image_mixer> accelerator::create_image_mixer(const int channel_id, common::bit_depth depth)
5752
{
58-
return impl_->create_image_mixer(channel_id, depth, color_space);
53+
return impl_->create_image_mixer(channel_id, depth);
5954
}
6055

6156
std::shared_ptr<accelerator_device> accelerator::get_device() const

src/accelerator/accelerator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ class accelerator
3030

3131
accelerator& operator=(accelerator&) = delete;
3232

33-
std::unique_ptr<caspar::core::image_mixer>
34-
create_image_mixer(int channel_id, common::bit_depth depth, core::color_space color_space);
33+
std::unique_ptr<caspar::core::image_mixer> create_image_mixer(int channel_id, common::bit_depth depth);
3534

3635
std::shared_ptr<accelerator_device> get_device() const;
3736

src/accelerator/ogl/image/image_mixer.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,13 @@ class image_renderer
7272
image_kernel kernel_;
7373
const size_t max_frame_size_;
7474
common::bit_depth depth_;
75-
core::color_space color_space_;
7675

7776
public:
78-
explicit image_renderer(const spl::shared_ptr<device>& ogl,
79-
const size_t max_frame_size,
80-
common::bit_depth depth,
81-
core::color_space color_space)
77+
explicit image_renderer(const spl::shared_ptr<device>& ogl, const size_t max_frame_size, common::bit_depth depth)
8278
: ogl_(ogl)
8379
, kernel_(ogl_)
8480
, max_frame_size_(max_frame_size)
8581
, depth_(depth)
86-
, color_space_(color_space)
8782
{
8883
}
8984

@@ -106,7 +101,6 @@ class image_renderer
106101
}
107102

108103
common::bit_depth depth() const { return depth_; }
109-
core::color_space color_space() const { return color_space_; }
110104

111105
private:
112106
void draw(std::shared_ptr<texture>& target_texture,
@@ -255,13 +249,9 @@ struct image_mixer::impl
255249
double aspect_ratio_ = 1.0;
256250

257251
public:
258-
impl(const spl::shared_ptr<device>& ogl,
259-
const int channel_id,
260-
const size_t max_frame_size,
261-
common::bit_depth depth,
262-
core::color_space color_space)
252+
impl(const spl::shared_ptr<device>& ogl, const int channel_id, const size_t max_frame_size, common::bit_depth depth)
263253
: ogl_(ogl)
264-
, renderer_(ogl, max_frame_size, depth, color_space)
254+
, renderer_(ogl, max_frame_size, depth)
265255
, transform_stack_(1)
266256
{
267257
CASPAR_LOG(info) << L"Initialized OpenGL Accelerated GPU Image Mixer for channel " << channel_id;
@@ -368,15 +358,13 @@ struct image_mixer::impl
368358
}
369359

370360
common::bit_depth depth() const { return renderer_.depth(); }
371-
core::color_space color_space() const { return renderer_.color_space(); }
372361
};
373362

374363
image_mixer::image_mixer(const spl::shared_ptr<device>& ogl,
375364
const int channel_id,
376365
const size_t max_frame_size,
377-
common::bit_depth depth,
378-
core::color_space color_space)
379-
: impl_(std::make_unique<impl>(ogl, channel_id, max_frame_size, depth, color_space))
366+
common::bit_depth depth)
367+
: impl_(std::make_unique<impl>(ogl, channel_id, max_frame_size, depth))
380368
{
381369
}
382370
image_mixer::~image_mixer() {}
@@ -399,6 +387,5 @@ image_mixer::create_frame(const void* tag, const core::pixel_format_desc& desc,
399387
}
400388

401389
common::bit_depth image_mixer::depth() const { return impl_->depth(); }
402-
core::color_space image_mixer::color_space() const { return impl_->color_space(); }
403390

404391
}}} // namespace caspar::accelerator::ogl

src/accelerator/ogl/image/image_mixer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class image_mixer final : public core::image_mixer
4040
image_mixer(const spl::shared_ptr<class device>& ogl,
4141
int channel_id,
4242
const size_t max_frame_size,
43-
common::bit_depth depth,
44-
core::color_space color_space);
43+
common::bit_depth depth);
4544
image_mixer(const image_mixer&) = delete;
4645

4746
~image_mixer();
@@ -61,7 +60,6 @@ class image_mixer final : public core::image_mixer
6160
void visit(const core::const_frame& frame) override;
6261
void pop() override;
6362
common::bit_depth depth() const override;
64-
core::color_space color_space() const override;
6563

6664
private:
6765
struct impl;

src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ set(HEADERS
7575
StdAfx.h
7676
video_channel.h
7777
video_format.h
78+
consumer/channel_info.h
7879
)
7980

8081
casparcg_add_library(core SOURCES ${SOURCES} ${HEADERS})

src/core/consumer/channel_info.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2011 Sveriges Television AB <[email protected]>
3+
*
4+
* This file is part of CasparCG (www.casparcg.com).
5+
*
6+
* CasparCG is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* CasparCG is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* Author: Julian Waller, [email protected]
20+
*/
21+
22+
#pragma once
23+
24+
#include "../frame/pixel_format.h"
25+
#include "common/bit_depth.h"
26+
27+
namespace caspar::core {
28+
29+
struct channel_info
30+
{
31+
channel_info(int channel_index, common::bit_depth depth, color_space color_space)
32+
: index(channel_index)
33+
, depth(depth)
34+
, default_color_space(color_space)
35+
{}
36+
37+
int index;
38+
common::bit_depth depth;
39+
color_space default_color_space;
40+
};
41+
42+
} // namespace caspar::core

src/core/consumer/frame_consumer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const spl::shared_ptr<frame_consumer>& frame_consumer::empty()
3838
{
3939
public:
4040
std::future<bool> send(const core::video_field field, const_frame) override { return make_ready_future(false); }
41-
void initialize(const video_format_desc&, int) override {}
41+
void initialize(const video_format_desc&, const core::channel_info&, int port_index) override {}
4242
std::wstring print() const override { return L"empty"; }
4343
std::wstring name() const override { return L"empty"; }
4444
bool has_synchronization_clock() const override { return false; }

src/core/consumer/frame_consumer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class frame_consumer
5050
virtual ~frame_consumer() {}
5151

5252
virtual std::future<bool> send(const core::video_field field, const_frame frame) = 0;
53-
virtual void initialize(const video_format_desc& format_desc, int channel_index) = 0;
53+
virtual void initialize(const video_format_desc& format_desc, const core::channel_info& channel_info, int port_index) = 0;
5454

5555
virtual core::monitor::state state() const = 0;
5656

src/core/consumer/frame_consumer_registry.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ class destroy_consumer_proxy : public frame_consumer
9090
{
9191
return consumer_->send(field, std::move(frame));
9292
}
93-
void initialize(const video_format_desc& format_desc, int channel_index) override
93+
void initialize(const video_format_desc& format_desc, const core::channel_info& channel_info, int port_index) override
9494
{
95-
return consumer_->initialize(format_desc, channel_index);
95+
return consumer_->initialize(format_desc, channel_info, port_index);
9696
}
9797
std::wstring print() const override { return consumer_->print(); }
9898
std::wstring name() const override { return consumer_->name(); }
@@ -123,9 +123,9 @@ class print_consumer_proxy : public frame_consumer
123123
{
124124
return consumer_->send(field, std::move(frame));
125125
}
126-
void initialize(const video_format_desc& format_desc, int channel_index) override
126+
void initialize(const video_format_desc& format_desc, const core::channel_info& channel_info, int port_index) override
127127
{
128-
consumer_->initialize(format_desc, channel_index);
128+
consumer_->initialize(format_desc, channel_info, port_index);
129129
CASPAR_LOG(info) << consumer_->print() << L" Initialized.";
130130
}
131131
std::wstring print() const override { return consumer_->print(); }
@@ -152,7 +152,7 @@ spl::shared_ptr<core::frame_consumer>
152152
frame_consumer_registry::create_consumer(const std::vector<std::wstring>& params,
153153
const core::video_format_repository& format_repository,
154154
const std::vector<spl::shared_ptr<core::video_channel>>& channels,
155-
common::bit_depth depth) const
155+
const core::channel_info& channel_info) const
156156
{
157157
if (params.empty())
158158
CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("params cannot be empty"));
@@ -162,7 +162,7 @@ frame_consumer_registry::create_consumer(const std::vector<std::wstring>&
162162
if (!std::any_of(
163163
consumer_factories.begin(), consumer_factories.end(), [&](const consumer_factory_t& factory) -> bool {
164164
try {
165-
consumer = factory(params, format_repository, channels, depth);
165+
consumer = factory(params, format_repository, channels, channel_info);
166166
} catch (...) {
167167
CASPAR_LOG_CURRENT_EXCEPTION();
168168
}
@@ -179,7 +179,7 @@ frame_consumer_registry::create_consumer(const std::wstring&
179179
const boost::property_tree::wptree& element,
180180
const core::video_format_repository& format_repository,
181181
const std::vector<spl::shared_ptr<core::video_channel>>& channels,
182-
common::bit_depth depth) const
182+
const core::channel_info& channel_info) const
183183
{
184184
auto& preconfigured_consumer_factories = preconfigured_consumer_factories_;
185185
auto found = preconfigured_consumer_factories.find(element_name);
@@ -189,7 +189,7 @@ frame_consumer_registry::create_consumer(const std::wstring&
189189
<< msg_info(L"No consumer factory registered for element name " + element_name));
190190

191191
return spl::make_shared<destroy_consumer_proxy>(
192-
spl::make_shared<print_consumer_proxy>(found->second(element, format_repository, channels, depth)));
192+
spl::make_shared<print_consumer_proxy>(found->second(element, format_repository, channels, channel_info)));
193193
}
194194

195195
}} // namespace caspar::core

src/core/consumer/frame_consumer_registry.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "../fwd.h"
2525
#include "../monitor/monitor.h"
26+
#include "channel_info.h"
2627

2728
#include <common/bit_depth.h>
2829
#include <common/memory.h>
@@ -45,12 +46,12 @@ using consumer_factory_t =
4546
std::function<spl::shared_ptr<frame_consumer>(const std::vector<std::wstring>& params,
4647
const core::video_format_repository& format_repository,
4748
const std::vector<spl::shared_ptr<core::video_channel>>& channels,
48-
common::bit_depth depth)>;
49+
const core::channel_info& channel_info)>;
4950
using preconfigured_consumer_factory_t =
5051
std::function<spl::shared_ptr<frame_consumer>(const boost::property_tree::wptree& element,
5152
const core::video_format_repository& format_repository,
5253
const std::vector<spl::shared_ptr<core::video_channel>>& channels,
53-
common::bit_depth depth)>;
54+
const core::channel_info& channel_info)>;
5455

5556
class frame_consumer_registry
5657
{
@@ -62,12 +63,12 @@ class frame_consumer_registry
6263
spl::shared_ptr<frame_consumer> create_consumer(const std::vector<std::wstring>& params,
6364
const core::video_format_repository& format_repository,
6465
const std::vector<spl::shared_ptr<core::video_channel>>& channels,
65-
common::bit_depth depth) const;
66+
const core::channel_info& channel_info) const;
6667
spl::shared_ptr<frame_consumer> create_consumer(const std::wstring& element_name,
6768
const boost::property_tree::wptree& element,
6869
const core::video_format_repository& format_repository,
6970
const std::vector<spl::shared_ptr<core::video_channel>>& channels,
70-
common::bit_depth depth) const;
71+
const core::channel_info& channel_info) const;
7172

7273
private:
7374
std::vector<consumer_factory_t> consumer_factories_;

0 commit comments

Comments
 (0)