]> git.sesse.net Git - casparcg/blobdiff - core/producer/frame_producer.cpp
Simplified thumbnail creation, making it less intrusive in the frame_producer design.
[casparcg] / core / producer / frame_producer.cpp
index fa458be4450e2408fbfcdf149f1712383ce936fd..2b78c61778998ba10c57bf77552893eb2a830224 100644 (file)
@@ -43,7 +43,7 @@ namespace caspar { namespace core {
 struct frame_producer_registry::impl
 {
        std::vector<producer_factory_t>         producer_factories;
-       std::vector<producer_factory_t>         thumbnail_factories;
+       std::vector<thumbnail_producer_t>       thumbnail_producers;
        spl::shared_ptr<help_repository>        help_repo;
 
        impl(spl::shared_ptr<help_repository> help_repo)
@@ -63,9 +63,9 @@ void frame_producer_registry::register_producer_factory(std::wstring name, const
        impl_->help_repo->register_item({ L"producer" }, std::move(name), describer);
 }
 
-void frame_producer_registry::register_thumbnail_producer_factory(const producer_factory_t& factory)
+void frame_producer_registry::register_thumbnail_producer(const thumbnail_producer_t& thumbnail_producer)
 {
-       impl_->thumbnail_factories.push_back(factory);
+       impl_->thumbnail_producers.push_back(thumbnail_producer);
 }
 
 frame_producer_dependencies::frame_producer_dependencies(
@@ -127,10 +127,6 @@ struct frame_producer_base::impl
        {
                return draw_frame::still(last_frame_);
        }
-       draw_frame create_thumbnail_frame()
-       {
-               return draw_frame::empty();
-       }
 };
 
 frame_producer_base::frame_producer_base() : impl_(new impl(*this))
@@ -151,10 +147,6 @@ draw_frame frame_producer_base::last_frame()
 {
        return impl_->last_frame();
 }
-draw_frame frame_producer_base::create_thumbnail_frame()
-{
-       return impl_->create_thumbnail_frame();
-}
 
 std::future<std::wstring> frame_producer_base::call(const std::vector<std::wstring>&) 
 {
@@ -201,7 +193,6 @@ const spl::shared_ptr<frame_producer>& frame_producer::empty()
                variable& get_variable(const std::wstring& name) override { CASPAR_THROW_EXCEPTION(not_implemented()); }
                const std::vector<std::wstring>& get_variables() const override { static std::vector<std::wstring> empty; return empty; }
                draw_frame last_frame() {return draw_frame::empty();}
-               draw_frame create_thumbnail_frame() {return draw_frame::empty();}
                constraints& pixel_constraints() override { static constraints c; return c; }
        
                boost::property_tree::wptree info() const override
@@ -292,7 +283,6 @@ public:
        void                                                                                            leading_producer(const spl::shared_ptr<frame_producer>& producer) override              {return producer_->leading_producer(producer);}
        uint32_t                                                                                        nb_frames() const override                                                                                                              {return producer_->nb_frames();}
        draw_frame                                                                                      last_frame()                                                                                                                                    {return producer_->last_frame();}
-       draw_frame                                                                                      create_thumbnail_frame()                                                                                                                {return producer_->create_thumbnail_frame();}
        monitor::subject&                                                                       monitor_output() override                                                                                                               {return producer_->monitor_output();}                                                                           
        bool                                                                                            collides(double x, double y) const override                                                                             {return producer_->collides(x, y);}
        void                                                                                            on_interaction(const interaction_event::ptr& event)     override                                        {return producer_->on_interaction(event);}
@@ -339,35 +329,38 @@ spl::shared_ptr<core::frame_producer> do_create_producer(const frame_producer_de
        return producer;
 }
 
-spl::shared_ptr<core::frame_producer> frame_producer_registry::create_thumbnail_producer(const frame_producer_dependencies& dependencies, const std::wstring& media_file) const
+draw_frame do_create_thumbnail_frame(
+               const frame_producer_dependencies& dependencies,
+               const std::wstring& media_file,
+               const std::vector<thumbnail_producer_t>& thumbnail_producers)
+{
+       for (auto& thumbnail_producer : thumbnail_producers)
+       {
+               auto frame = thumbnail_producer(dependencies, media_file);
+
+               if (frame != draw_frame::empty())
+                       return frame;
+       }
+
+       return draw_frame::empty();
+}
+
+draw_frame frame_producer_registry::create_thumbnail(const frame_producer_dependencies& dependencies, const std::wstring& media_file) const
 {
-       auto& thumbnail_factories = impl_->thumbnail_factories;
+       auto& thumbnail_producers = impl_->thumbnail_producers;
        std::vector<std::wstring> params;
        params.push_back(media_file);
 
-       auto producer = do_create_producer(dependencies, params, thumbnail_factories, true);
-       auto key_producer = frame_producer::empty();
-  
-       try // to find a key file.
-       {
-               auto params_copy = params;
-               if (params_copy.size() > 0)
-               {
-                       params_copy[0] += L"_A";
-                       key_producer = do_create_producer(dependencies, params_copy, thumbnail_factories, true);
-                       if (key_producer == frame_producer::empty())
-                       {
-                               params_copy[0] += L"LPHA";
-                               key_producer = do_create_producer(dependencies, params_copy, thumbnail_factories, true);
-                       }
-               }
-       }
-       catch(...){}
+       auto fill_frame = do_create_thumbnail_frame(dependencies, media_file, thumbnail_producers);
+       auto key_frame = do_create_thumbnail_frame(dependencies, media_file + L"_A", thumbnail_producers);
 
-       if (producer != frame_producer::empty() && key_producer != frame_producer::empty())
-               return create_separated_producer(producer, key_producer);
+       if (key_frame == draw_frame::empty())
+               key_frame = do_create_thumbnail_frame(dependencies, media_file + L"_ALPHA", thumbnail_producers);
   
-       return producer;
+       if (fill_frame != draw_frame::empty() && key_frame != draw_frame::empty())
+               return draw_frame::mask(fill_frame, key_frame);
+  
+       return fill_frame;
 }
 
 spl::shared_ptr<core::frame_producer> frame_producer_registry::create_producer(const frame_producer_dependencies& dependencies, const std::vector<std::wstring>& params) const