#include <future>
namespace caspar { namespace core {
-
+
struct stage::impl : public std::enable_shared_from_this<impl>
-{
+{
+ int channel_index_;
spl::shared_ptr<diagnostics::graph> graph_;
- spl::shared_ptr<monitor::subject> monitor_subject_;
- //reactive::basic_subject<std::map<int, draw_frame>> frames_subject_;
- std::map<int, layer> layers_;
+ spl::shared_ptr<monitor::subject> monitor_subject_ = spl::make_shared<monitor::subject>("/stage");
+ std::map<int, layer> layers_;
std::map<int, tweened_transform> tweens_;
interaction_aggregator aggregator_;
// map of layer -> map of tokens (src ref) -> layer_consumer
std::map<int, std::map<void*, spl::shared_ptr<write_frame_consumer>>> layer_consumers_;
- executor executor_;
+ executor executor_ { L"stage " + boost::lexical_cast<std::wstring>(channel_index_) };
public:
- impl(spl::shared_ptr<diagnostics::graph> graph)
- : graph_(std::move(graph))
- , monitor_subject_(spl::make_shared<monitor::subject>("/stage"))
+ impl(int channel_index, spl::shared_ptr<diagnostics::graph> graph)
+ : channel_index_(channel_index)
+ , graph_(std::move(graph))
, aggregator_([=] (double x, double y) { return collission_detect(x, y); })
- , executor_(L"stage")
{
graph_->set_color("produce-time", diagnostics::color(0.0f, 1.0f, 0.0f));
}
-
+
std::map<int, draw_frame> operator()(const video_format_desc& format_desc)
- {
+ {
caspar::timer frame_timer;
auto frames = executor_.invoke([=]() -> std::map<int, draw_frame>
{
std::map<int, draw_frame> frames;
-
+
try
- {
+ {
std::vector<int> indices;
- for (auto& layer : layers_)
+ for (auto& layer : layers_)
{
// Prevent race conditions in parallel for each later
frames[layer.first] = draw_frame::empty();
{
layers_.clear();
CASPAR_LOG_CURRENT_EXCEPTION();
- }
-
+ }
+
return frames;
});
-
+
//frames_subject_ << frames;
-
+
graph_->set_value("produce-time", frame_timer.elapsed()*format_desc.fps*0.5);
*monitor_subject_ << monitor::message("/profiler/time") % frame_timer.elapsed() % (1.0/format_desc.fps);
auto& tween = tweens_[index];
auto& consumers = layer_consumers_[index];
- auto frame = layer.receive(format_desc);
-
+ auto frame = layer.receive(format_desc);
+
if (!consumers.empty())
{
auto consumer_it = consumers | boost::adaptors::map_values;
}
auto frame1 = frame;
-
+
frame1.transform() *= tween.fetch_and_tick(1);
if(format_desc.field_mode != core::field_mode::progressive)
- {
+ {
auto frame2 = frame;
frame2.transform() *= tween.fetch_and_tick(1);
+ frame2.transform().audio_transform.volume = 0.0;
frame1 = core::draw_frame::interlace(frame1, frame2, format_desc.field_mode);
}
}
return it->second;
}
-
+
std::future<void> apply_transforms(const std::vector<std::tuple<int, stage::transform_func_t, unsigned int, tweener>>& transforms)
{
return executor_.begin_invoke([=]
{
for (auto& transform : transforms)
{
- auto src = tweens_[std::get<0>(transform)].fetch();
- auto dst = std::get<1>(transform)(src);
+ auto& tween = tweens_[std::get<0>(transform)];
+ auto src = tween.fetch();
+ auto dst = std::get<1>(transform)(tween.dest());
tweens_[std::get<0>(transform)] = tweened_transform(src, dst, std::get<2>(transform), std::get<3>(transform));
}
}, task_priority::high_priority);
}
-
+
std::future<void> apply_transform(int index, const stage::transform_func_t& transform, unsigned int mix_duration, const tweener& tween)
{
return executor_.begin_invoke([=]
{
return executor_.begin_invoke([=]
{
- get_layer(index).load(producer, preview, auto_play_delta);
+ get_layer(index).load(producer, preview, auto_play_delta);
}, task_priority::high_priority);
}
std::future<void> pause(int index)
- {
+ {
return executor_.begin_invoke([=]
{
get_layer(index).pause();
}
std::future<void> play(int index)
- {
+ {
return executor_.begin_invoke([=]
{
get_layer(index).play();
}
std::future<void> stop(int index)
- {
+ {
return executor_.begin_invoke([=]
{
get_layer(index).stop();
layers_.erase(index);
}, task_priority::high_priority);
}
-
+
std::future<void> clear()
{
return executor_.begin_invoke([=]
{
layers_.clear();
}, task_priority::high_priority);
- }
-
+ }
+
std::future<void> swap_layers(stage& other, bool swap_transforms)
{
auto other_impl = other.impl_;
{
return make_ready_future();
}
-
+
auto func = [=]
{
auto layers = layers_ | boost::adaptors::map_values;
for (auto& layer : layers)
layer.monitor_output().detach_parent();
-
+
for (auto& layer : other_layers)
layer.monitor_output().detach_parent();
-
+
std::swap(layers_, other_impl->layers_);
-
+
for (auto& layer : layers)
layer.monitor_output().attach_parent(monitor_subject_);
-
+
for (auto& layer : other_layers)
layer.monitor_output().attach_parent(monitor_subject_);
auto& other_tween = other_impl->tweens_[other_index];
std::swap(my_tween, other_tween);
}
- };
+ };
return executor_.begin_invoke([=]
{
return get_layer(index).foreground();
}, task_priority::high_priority);
}
-
+
std::future<std::shared_ptr<frame_producer>> background(int index)
{
return executor_.begin_invoke([=]() -> std::shared_ptr<frame_producer>
return executor_.begin_invoke([this]() -> boost::property_tree::wptree
{
boost::property_tree::wptree info;
- for (auto& layer : layers_)
+ for (auto& layer : layers_)
info.add_child(L"layers.layer", layer.second.info())
- .add(L"index", layer.first);
+ .add(L"index", layer.first);
return info;
}, task_priority::high_priority);
}
{
return get_layer(index).info();
}, task_priority::high_priority);
- }
-
+ }
+
+ std::future<boost::property_tree::wptree> delay_info()
+ {
+ return std::move(executor_.begin_invoke([this]() -> boost::property_tree::wptree
+ {
+ boost::property_tree::wptree info;
+
+ for (auto& layer : layers_)
+ info.add_child(L"layer", layer.second.delay_info()).add(L"index", layer.first);
+
+ return info;
+ }, task_priority::high_priority));
+ }
+
+ std::future<boost::property_tree::wptree> delay_info(int index)
+ {
+ return std::move(executor_.begin_invoke([=]() -> boost::property_tree::wptree
+ {
+ return get_layer(index).delay_info();
+ }, task_priority::high_priority));
+ }
+
std::future<std::wstring> call(int index, const std::vector<std::wstring>& params)
{
return flatten(executor_.begin_invoke([=]
}
};
-stage::stage(spl::shared_ptr<diagnostics::graph> graph) : impl_(new impl(std::move(graph))){}
+stage::stage(int channel_index, spl::shared_ptr<diagnostics::graph> graph) : impl_(new impl(channel_index, std::move(graph))){}
std::future<std::wstring> stage::call(int index, const std::vector<std::wstring>& params){return impl_->call(index, params);}
std::future<void> stage::apply_transforms(const std::vector<stage::transform_tuple_t>& transforms){ return impl_->apply_transforms(transforms); }
std::future<void> stage::apply_transform(int index, const std::function<core::frame_transform(core::frame_transform)>& transform, unsigned int mix_duration, const tweener& tween){ return impl_->apply_transform(index, transform, mix_duration, tween); }
std::future<std::shared_ptr<frame_producer>> stage::background(int index) { return impl_->background(index); }
std::future<boost::property_tree::wptree> stage::info() const{ return impl_->info(); }
std::future<boost::property_tree::wptree> stage::info(int index) const{ return impl_->info(index); }
-std::map<int, draw_frame> stage::operator()(const video_format_desc& format_desc){return (*impl_)(format_desc);}
+std::future<boost::property_tree::wptree> stage::delay_info() const{ return impl_->delay_info(); }
+std::future<boost::property_tree::wptree> stage::delay_info(int index) const{ return impl_->delay_info(index); }
+std::map<int, draw_frame> stage::operator()(const video_format_desc& format_desc){ return (*impl_)(format_desc); }
monitor::subject& stage::monitor_output(){return *impl_->monitor_subject_;}
-//void stage::subscribe(const frame_observable::observer_ptr& o) {impl_->frames_subject_.subscribe(o);}
-//void stage::unsubscribe(const frame_observable::observer_ptr& o) {impl_->frames_subject_.unsubscribe(o);}
void stage::on_interaction(const interaction_event::ptr& event) { impl_->on_interaction(event); }
}}