]> git.sesse.net Git - casparcg/blobdiff - core/producer/stage.cpp
[scene] Fixed infinite loop in expression parsing.
[casparcg] / core / producer / stage.cpp
index 992554ef4f0e153f986c54e7c65f00f1c0419def..54f30ff59542ba109eb8f24c904e2906ed846523 100644 (file)
 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));
        }
@@ -165,8 +164,9 @@ public:
                {
                        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);
@@ -222,6 +222,14 @@ public:
                }, task_priority::high_priority);
        }
 
+       std::future<void> resume(int index)
+       {
+               return executor_.begin_invoke([=]
+               {
+                       get_layer(index).resume();
+               }, task_priority::high_priority);
+       }
+
        std::future<void> play(int index)
        {               
                return executor_.begin_invoke([=]
@@ -254,7 +262,7 @@ public:
                }, task_priority::high_priority);
        }       
                
-       std::future<void> swap_layers(stage& other)
+       std::future<void> swap_layers(stage& other, bool swap_transforms)
        {
                auto other_impl = other.impl_;
 
@@ -281,7 +289,10 @@ public:
                        
                        for (auto& layer : other_layers)
                                layer.monitor_output().attach_parent(monitor_subject_);
-               };              
+
+                       if (swap_transforms)
+                               std::swap(tweens_, other_impl->tweens_);
+               };
 
                return executor_.begin_invoke([=]
                {
@@ -289,20 +300,23 @@ public:
                }, task_priority::high_priority);
        }
 
-       std::future<void> swap_layer(int index, int other_index)
+       std::future<void> swap_layer(int index, int other_index, bool swap_transforms)
        {
                return executor_.begin_invoke([=]
                {
                        std::swap(get_layer(index), get_layer(other_index));
+
+                       if (swap_transforms)
+                               std::swap(tweens_[index], tweens_[other_index]);
                }, task_priority::high_priority);
        }
 
-       std::future<void> swap_layer(int index, int other_index, stage& other)
+       std::future<void> swap_layer(int index, int other_index, stage& other, bool swap_transforms)
        {
                auto other_impl = other.impl_;
 
                if(other_impl.get() == this)
-                       return swap_layer(index, other_index);
+                       return swap_layer(index, other_index, swap_transforms);
                else
                {
                        auto func = [=]
@@ -317,6 +331,13 @@ public:
 
                                my_layer.monitor_output().attach_parent(monitor_subject_);
                                other_layer.monitor_output().attach_parent(other_impl->monitor_subject_);
+
+                               if (swap_transforms)
+                               {
+                                       auto& my_tween          = tweens_[index];
+                                       auto& other_tween       = other_impl->tweens_[other_index];
+                                       std::swap(my_tween, other_tween);
+                               }
                        };              
 
                        return executor_.begin_invoke([=]
@@ -381,7 +402,28 @@ public:
                {
                        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)
        {
@@ -420,7 +462,7 @@ public:
        }
 };
 
-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); }
@@ -429,21 +471,22 @@ std::future<void> stage::clear_transforms(){ return impl_->clear_transforms(); }
 std::future<frame_transform> stage::get_current_transform(int index){ return impl_->get_current_transform(index); }
 std::future<void> stage::load(int index, const spl::shared_ptr<frame_producer>& producer, bool preview, const boost::optional<int32_t>& auto_play_delta){ return impl_->load(index, producer, preview, auto_play_delta); }
 std::future<void> stage::pause(int index){ return impl_->pause(index); }
+std::future<void> stage::resume(int index){ return impl_->resume(index); }
 std::future<void> stage::play(int index){ return impl_->play(index); }
 std::future<void> stage::stop(int index){ return impl_->stop(index); }
 std::future<void> stage::clear(int index){ return impl_->clear(index); }
 std::future<void> stage::clear(){ return impl_->clear(); }
-std::future<void> stage::swap_layers(stage& other){ return impl_->swap_layers(other); }
-std::future<void> stage::swap_layer(int index, int other_index){ return impl_->swap_layer(index, other_index); }
-std::future<void> stage::swap_layer(int index, int other_index, stage& other){ return impl_->swap_layer(index, other_index, other); }
+std::future<void> stage::swap_layers(stage& other, bool swap_transforms){ return impl_->swap_layers(other, swap_transforms); }
+std::future<void> stage::swap_layer(int index, int other_index, bool swap_transforms){ return impl_->swap_layer(index, other_index, swap_transforms); }
+std::future<void> stage::swap_layer(int index, int other_index, stage& other, bool swap_transforms){ return impl_->swap_layer(index, other_index, other, swap_transforms); }
 void stage::add_layer_consumer(void* token, int layer, const spl::shared_ptr<write_frame_consumer>& layer_consumer){ impl_->add_layer_consumer(token, layer, layer_consumer); }
 void stage::remove_layer_consumer(void* token, int layer){ impl_->remove_layer_consumer(token, layer); }std::future<std::shared_ptr<frame_producer>> stage::foreground(int index) { return impl_->foreground(index); }
 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); }
 }}