]> git.sesse.net Git - casparcg/commitdiff
Improved hotswap_producer
authorHelge Norberg <helge.norberg@svt.se>
Wed, 9 Dec 2015 16:21:36 +0000 (17:21 +0100)
committerHelge Norberg <helge.norberg@svt.se>
Wed, 9 Dec 2015 16:21:36 +0000 (17:21 +0100)
core/producer/scene/hotswap_producer.cpp
core/producer/scene/hotswap_producer.h

index 3afc93a61f6fb2a632eb42bcb8392e2a95aeeffd..60d807b00ad18abd2a659f69bf48705e31f85208 100644 (file)
@@ -30,18 +30,28 @@ namespace caspar { namespace core {
 
 struct hotswap_producer::impl
 {
-       monitor::subject monitor_subject;
-       binding<std::shared_ptr<frame_producer>> producer;
-       constraints size;
+       spl::shared_ptr<monitor::subject>                       monitor_subject;
+       binding<std::shared_ptr<frame_producer>>        producer;
+       constraints                                                                     size;
 
-       impl(int width, int height)
+       impl(int width, int height, bool auto_size)
                : size(width, height)
        {
+               producer.on_change([=]
+               {
+                       if (auto_size)
+                       {
+                               size.width.bind(producer.get()->pixel_constraints().width);
+                               size.height.bind(producer.get()->pixel_constraints().height);
+                       }
+
+                       producer.get()->monitor_output().attach_parent(monitor_subject);
+               });
        }
 };
 
-hotswap_producer::hotswap_producer(int width, int height)
-       : impl_(new impl(width, height))
+hotswap_producer::hotswap_producer(int width, int height, bool auto_size)
+       : impl_(new impl(width, height, auto_size))
 {
 }
 
@@ -90,7 +100,27 @@ boost::property_tree::wptree hotswap_producer::info() const
 
 monitor::subject& hotswap_producer::monitor_output()
 {
-       return impl_->monitor_subject;
+       return *impl_->monitor_subject;
+}
+
+variable& hotswap_producer::get_variable(const std::wstring& name)
+{
+       auto producer = impl_->producer.get();
+
+       if (producer)
+               return producer->get_variable(name);
+       else
+               return frame_producer_base::get_variable(name);
+}
+
+const std::vector<std::wstring>& hotswap_producer::get_variables() const
+{
+       auto producer = impl_->producer.get();
+
+       if (producer)
+               return producer->get_variables();
+       else
+               return frame_producer_base::get_variables();
 }
 
 binding<std::shared_ptr<frame_producer>>& hotswap_producer::producer()
index d148b9258ced4c116e9a38f6dc5438195cac2787..3fe88ba1b1829b6feb814b5c59d616860776fac2 100644 (file)
@@ -33,15 +33,17 @@ namespace caspar { namespace core {
 class hotswap_producer : public frame_producer_base
 {
 public:
-       hotswap_producer(int width, int height);
+       hotswap_producer(int width, int height, bool auto_size = false);
        ~hotswap_producer();
 
-       draw_frame receive_impl() override;
-       constraints& pixel_constraints() override;
-       std::wstring print() const override;
-       std::wstring name() const override;
-       boost::property_tree::wptree info() const override;
-       monitor::subject& monitor_output();
+       draw_frame                                                      receive_impl() override;
+       constraints&                                            pixel_constraints() override;
+       std::wstring                                            print() const override;
+       std::wstring                                            name() const override;
+       boost::property_tree::wptree            info() const override;
+       monitor::subject&                                       monitor_output() override;
+       variable&                                                       get_variable(const std::wstring& name) override;
+       const std::vector<std::wstring>&        get_variables() const override;
 
        binding<std::shared_ptr<frame_producer>>& producer();
 private: