]> git.sesse.net Git - casparcg/commitdiff
2.1.0: -frame_producer: Refactored last_frame.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 12 Feb 2012 14:33:41 +0000 (14:33 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 12 Feb 2012 14:33:41 +0000 (14:33 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.1.0@2372 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

13 files changed:
core/producer/color/color_producer.cpp
core/producer/frame_producer.cpp
core/producer/frame_producer.h
core/producer/layer.cpp
core/producer/separated/separated_producer.cpp
core/producer/transition/transition_producer.cpp
modules/decklink/producer/decklink_producer.cpp
modules/ffmpeg/producer/ffmpeg_producer.cpp
modules/flash/producer/flash_producer.cpp
modules/image/producer/image_producer.cpp
modules/image/producer/image_scroll_producer.cpp
modules/reroute/producer/reroute_producer.cpp
shell/casparcg.config

index 6b6c2188fd1717ac99da142bfeec670f7e5c81b8..26b9d35d50cd7b8cf1a5cc876ff534a3f6b83b86 100644 (file)
@@ -54,12 +54,7 @@ public:
        {\r
                return frame_;\r
        }       \r
-\r
-       virtual spl::shared_ptr<draw_frame> last_frame() const override\r
-       {\r
-               return frame_; \r
-       }       \r
-\r
+       \r
        virtual std::wstring print() const override\r
        {\r
                return L"color[" + color_str_ + L"]";\r
index 0557e2e7432aace16e09b65d2c9b76179283e825..2b0a295fba242cfec7c59ed3a4c094f84dddd654 100644 (file)
@@ -44,6 +44,11 @@ void register_producer_factory(const producer_factory_t& factory)
        g_factories.push_back(factory);\r
 }\r
 \r
+spl::shared_ptr<class draw_frame> frame_producer::last_frame() const\r
+{\r
+       BOOST_THROW_EXCEPTION(not_implemented());\r
+}\r
+\r
 boost::unique_future<std::wstring> frame_producer::call(const std::wstring&) \r
 {\r
        BOOST_THROW_EXCEPTION(not_supported());\r
@@ -90,60 +95,12 @@ public:
        virtual std::wstring                                                                            name() const override                                                                                                                   {return producer_->name();}\r
        virtual boost::property_tree::wptree                                            info() const override                                                                                                                   {return producer_->info();}\r
        virtual boost::unique_future<std::wstring>                                      call(const std::wstring& str) override                                                                                  {return producer_->call(str);}\r
-       virtual spl::shared_ptr<frame_producer>                                         following_producer() const override                                                                                     {return producer_->following_producer();}\r
-       virtual void                                                                                            leading_producer(const spl::shared_ptr<frame_producer>& producer) override      {return producer_->leading_producer(producer);}\r
+       virtual void                                                                                            leading_producer(const spl::shared_ptr<frame_producer>& producer) override              {return producer_->leading_producer(producer);}\r
        virtual uint32_t                                                                                        nb_frames() const override                                                                                                              {return producer_->nb_frames();}\r
        virtual void subscribe(const monitor::observable::observer_ptr& o)                                                                                                                                                      {return producer_->subscribe(o);}\r
        virtual void unsubscribe(const monitor::observable::observer_ptr& o)                                                                                                                                            {return producer_->unsubscribe(o);}\r
 };\r
 \r
-class follow_producer_proxy : public producer_proxy_base\r
-{      \r
-       monitor::basic_subject event_subject_;\r
-public:\r
-       follow_producer_proxy(spl::shared_ptr<frame_producer>&& producer) \r
-               : producer_proxy_base(std::move(producer))\r
-       {\r
-               producer->subscribe(event_subject_);\r
-       }\r
-\r
-       virtual spl::shared_ptr<draw_frame>     receive(int hints) override                                                                                                             \r
-       {\r
-               auto frame = producer_->receive(hints);\r
-               if(frame == draw_frame::eof())\r
-               {\r
-                       CASPAR_LOG(info) << producer_->print() << " End Of File.";\r
-                       auto following = producer_->following_producer();\r
-                       if(following != frame_producer::empty())\r
-                       {\r
-                               following->leading_producer(spl::make_shared_ptr(producer_));\r
-\r
-                               producer_->unsubscribe(event_subject_);\r
-                               producer_ = std::move(following);\r
-                               producer_->subscribe(event_subject_);\r
-                       }\r
-\r
-                       return receive(hints);\r
-               }\r
-               return frame;\r
-       }\r
-\r
-       virtual spl::shared_ptr<draw_frame> last_frame() const override \r
-       {\r
-               return draw_frame::mute(producer_->last_frame());\r
-       }\r
-\r
-       virtual void subscribe(const monitor::observable::observer_ptr& o) override                                                                                                                     \r
-       {\r
-               event_subject_.subscribe(o);\r
-       }\r
-\r
-       virtual void unsubscribe(const monitor::observable::observer_ptr& o) override           \r
-       {\r
-               event_subject_.unsubscribe(o);\r
-       }\r
-};\r
-\r
 class destroy_producer_proxy : public producer_proxy_base\r
 {      \r
 public:\r
@@ -198,12 +155,32 @@ public:
        }\r
 };\r
 \r
+class last_frame_producer_proxy : public producer_proxy_base\r
+{      \r
+public:\r
+       last_frame_producer_proxy(spl::shared_ptr<frame_producer>&& producer) \r
+               : producer_proxy_base(std::move(producer))\r
+               , last_frame_(draw_frame::empty())\r
+       {\r
+               CASPAR_LOG(info) << producer_->print() << L" Initialized.";\r
+       }\r
+       \r
+       virtual spl::shared_ptr<draw_frame>     receive(int hints) override                                     \r
+       {\r
+               return last_frame_ = producer_->receive(hints);\r
+       }\r
+\r
+       virtual spl::shared_ptr<draw_frame>     last_frame() const override                                                                                                             \r
+       {\r
+               return last_frame_;\r
+       }\r
+};\r
+\r
 spl::shared_ptr<core::frame_producer> wrap_producer(spl::shared_ptr<core::frame_producer> producer)\r
 {\r
-       return spl::make_shared<follow_producer_proxy>(\r
-                       spl::make_shared<destroy_producer_proxy>(\r
+       return spl::make_shared<destroy_producer_proxy>(\r
                         spl::make_shared<print_producer_proxy>(\r
-                         std::move(producer))));\r
+                         std::move(producer)));\r
 }\r
 \r
 spl::shared_ptr<core::frame_producer> do_create_producer(const spl::shared_ptr<frame_factory>& my_frame_factory, const std::vector<std::wstring>& params)\r
index ab3d24a267b7a9ca3026836d78ec0a4d838f5511..a89bbd3013152e40b148265426761b7ccaac3c59 100644 (file)
@@ -64,13 +64,12 @@ struct frame_producer : public monitor::observable
 \r
        virtual boost::unique_future<std::wstring> call(const std::wstring&);\r
 \r
-       virtual spl::shared_ptr<frame_producer> following_producer() const {return frame_producer::empty();}  // nothrow\r
        virtual void leading_producer(const spl::shared_ptr<frame_producer>&) {}  // nothrow\r
                \r
        virtual uint32_t nb_frames() const {return std::numeric_limits<uint32_t>::max();}\r
        \r
        virtual spl::shared_ptr<class draw_frame> receive(int fBlags) = 0;\r
-       virtual spl::shared_ptr<class draw_frame> last_frame() const = 0;\r
+       virtual spl::shared_ptr<class draw_frame> last_frame() const;\r
        \r
        static const spl::shared_ptr<frame_producer>& empty(); // nothrow\r
 \r
index 55bd73230d40b5061e9b6507be422865b16da1eb..9c79e66615e0ed02db34de1f0aa9bdb9193499c7 100644 (file)
@@ -119,12 +119,19 @@ public:
                try\r
                {\r
                        if(is_paused_)\r
-                               return draw_frame::mute(foreground_->last_frame());\r
+                               return foreground_->last_frame();\r
                \r
                        auto frame = foreground_->receive(flags.value());\r
+\r
                        if(frame == core::draw_frame::late())\r
                                return foreground_->last_frame();\r
                        \r
+                       if(frame == core::draw_frame::eof())\r
+                       {       \r
+                               stop();\r
+                               return core::draw_frame::empty();\r
+                       }\r
+                       \r
                        ++frame_number_;\r
 \r
                        if(auto_play_delta_)\r
index 5774fd43ef838921d91567e6f16592f6a6eaca79..ee845c74d771d61bfa3bcbb50cc2c36d3c937ae0 100644 (file)
@@ -36,14 +36,12 @@ struct separated_producer : public frame_producer
        spl::shared_ptr<frame_producer> key_producer_;\r
        spl::shared_ptr<draw_frame>             fill_;\r
        spl::shared_ptr<draw_frame>             key_;\r
-       spl::shared_ptr<draw_frame>             last_frame_;\r
                \r
        explicit separated_producer(const spl::shared_ptr<frame_producer>& fill, const spl::shared_ptr<frame_producer>& key) \r
                : fill_producer_(fill)\r
                , key_producer_(key)\r
                , fill_(core::draw_frame::late())\r
                , key_(core::draw_frame::late())\r
-               , last_frame_(core::draw_frame::empty())\r
        {\r
        }\r
 \r
@@ -74,14 +72,9 @@ struct separated_producer : public frame_producer
                fill_ = draw_frame::late();\r
                key_  = draw_frame::late();\r
 \r
-               return last_frame_ = frame;\r
+               return frame;\r
        }\r
-\r
-       virtual spl::shared_ptr<core::draw_frame> last_frame() const override\r
-       {\r
-               return last_frame_;\r
-       }\r
-\r
+       \r
        virtual uint32_t nb_frames() const override\r
        {\r
                return std::min(fill_producer_->nb_frames(), key_producer_->nb_frames());\r
index 9d6176f54688a7d9b174761008c8b7afc82779bc..eaac208da91f0484f49de773c55843f30d0704b2 100644 (file)
@@ -42,8 +42,6 @@ struct transition_producer : public frame_producer
        \r
        spl::shared_ptr<frame_producer>         dest_producer_;\r
        spl::shared_ptr<frame_producer>         source_producer_;\r
-\r
-       spl::shared_ptr<draw_frame>                     last_frame_;\r
                \r
        explicit transition_producer(const field_mode& mode, const spl::shared_ptr<frame_producer>& dest, const transition_info& info) \r
                : mode_(mode)\r
@@ -51,18 +49,12 @@ struct transition_producer : public frame_producer
                , info_(info)\r
                , dest_producer_(dest)\r
                , source_producer_(frame_producer::empty())\r
-               , last_frame_(draw_frame::empty())\r
        {\r
                dest->subscribe(event_subject_);\r
        }\r
        \r
        // frame_producer\r
-\r
-       virtual spl::shared_ptr<frame_producer> following_producer() const override\r
-       {\r
-               return dest_producer_;\r
-       }\r
-       \r
+               \r
        virtual void leading_producer(const spl::shared_ptr<frame_producer>& producer) override\r
        {\r
                source_producer_ = producer;\r
@@ -70,9 +62,11 @@ struct transition_producer : public frame_producer
 \r
        virtual spl::shared_ptr<draw_frame> receive(int flags) override\r
        {\r
-               if(++current_frame_ >= info_.duration)\r
-                       return draw_frame::eof();\r
+               if(current_frame_ >= info_.duration)\r
+                       return dest_producer_->receive(flags);\r
                \r
+               ++current_frame_;\r
+\r
                event_subject_  << monitor::event("transition/frame") % current_frame_ % info_.duration\r
                                                << monitor::event("transition/type") % [&]() -> std::string\r
                                                                                                                                {\r
@@ -106,15 +100,10 @@ struct transition_producer : public frame_producer
 \r
                return compose(dest, source);\r
        }\r
-\r
-       virtual spl::shared_ptr<core::draw_frame> last_frame() const override\r
-       {\r
-               return last_frame_;\r
-       }\r
-\r
+       \r
        virtual uint32_t nb_frames() const override\r
        {\r
-               return following_producer()->nb_frames();\r
+               return dest_producer_->nb_frames();\r
        }\r
 \r
        virtual std::wstring print() const override\r
@@ -188,8 +177,6 @@ struct transition_producer : public frame_producer
                const auto s_frame = s_frame1->get_frame_transform() == s_frame2->get_frame_transform() ? s_frame2 : draw_frame::interlace(s_frame1, s_frame2, mode_);\r
                const auto d_frame = d_frame1->get_frame_transform() == d_frame2->get_frame_transform() ? d_frame2 : draw_frame::interlace(d_frame1, d_frame2, mode_);\r
                \r
-               last_frame_ = draw_frame::over(s_frame2, d_frame2);\r
-\r
                return draw_frame::over(s_frame, d_frame);\r
        }\r
 \r
index bf30599ed8828a0d6e6e82bb8019e4cfa2086547..e634ee57e12200fdb1ffa790fa517e6f3fd46e9e 100644 (file)
@@ -269,14 +269,12 @@ public:
        \r
 class decklink_producer_proxy : public core::frame_producer\r
 {              \r
-       spl::shared_ptr<core::draw_frame>                       last_frame_;\r
        std::unique_ptr<decklink_producer>      producer_;\r
        const uint32_t                                          length_;\r
        executor                                                        executor_;\r
 public:\r
        explicit decklink_producer_proxy(const spl::shared_ptr<core::frame_factory>& frame_factory, const core::video_format_desc& format_desc, size_t device_index, const std::wstring& filter_str, uint32_t length)\r
                : executor_(L"decklink_producer[" + boost::lexical_cast<std::wstring>(device_index) + L"]")\r
-               , last_frame_(core::draw_frame::empty())\r
                , length_(length)\r
        {\r
                executor_.invoke([=]\r
@@ -299,17 +297,9 @@ public:
                                \r
        virtual spl::shared_ptr<core::draw_frame> receive(int flags) override\r
        {\r
-               auto frame = producer_->get_frame(flags);\r
-               if(frame != core::draw_frame::late())\r
-                       last_frame_ = frame;\r
-               return frame;\r
-       }\r
-\r
-       virtual spl::shared_ptr<core::draw_frame> last_frame() const override\r
-       {\r
-               return last_frame_;\r
+               return producer_->get_frame(flags);\r
        }\r
-       \r
+               \r
        virtual uint32_t nb_frames() const override\r
        {\r
                return length_;\r
index 2e32a1ae8057966eb1df1d1fe97d454abf48d881..919011fc208e9eb5bfb4f9a0a4cec86a188a0e0c 100644 (file)
@@ -81,9 +81,7 @@ struct ffmpeg_producer : public core::frame_producer
        const double                                                                                            fps_;\r
        const uint32_t                                                                                          start_;\r
        const uint32_t                                                                                          length_;\r
-\r
-       spl::shared_ptr<core::draw_frame>                                                       last_frame_;\r
-       \r
+               \r
        int64_t                                                                                                         frame_number_;\r
        \r
 public:\r
@@ -95,7 +93,6 @@ public:
                , fps_(read_fps(*input_.context(), format_desc_.fps))\r
                , start_(start)\r
                , length_(length)\r
-               , last_frame_(core::draw_frame::empty())\r
                , frame_number_(0)\r
        {\r
                graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));\r
@@ -163,21 +160,16 @@ public:
                {\r
                        if(!input_.eof())               \r
                                graph_->set_tag("underflow");   \r
-                       return last_frame();\r
+                       return core::draw_frame::late();\r
                }\r
                                \r
                ++frame_number_;\r
 \r
                graph_->set_text(print());\r
 \r
-               return last_frame_ = spl::make_shared_ptr(frame);\r
-       }\r
-\r
-       virtual spl::shared_ptr<core::draw_frame> last_frame() const override\r
-       {\r
-               return core::draw_frame::mute(last_frame_);\r
+               return spl::make_shared_ptr(frame);\r
        }\r
-\r
+       \r
        virtual uint32_t nb_frames() const override\r
        {\r
                if(input_.loop())\r
index a1ba140c04d42a4110371a1cc84c9a7915c33fea..26b95aae361734c7cb770259cbd127c3c724f5fe 100644 (file)
@@ -332,10 +332,7 @@ struct flash_producer : public core::frame_producer
 \r
        std::queue<spl::shared_ptr<core::draw_frame>>                                           frame_buffer_;\r
        tbb::concurrent_bounded_queue<spl::shared_ptr<core::draw_frame>>        output_buffer_;\r
-\r
-       spl::shared_ptr<core::draw_frame>                                                                       last_frame_;\r
-       mutable tbb::spin_mutex                                                                                         last_frame_mutex_;\r
-                       \r
+                               \r
        std::unique_ptr<flash_renderer>                                                                         renderer_;\r
 \r
        executor                                                                                                                        executor_;      \r
@@ -346,7 +343,6 @@ public:
                , width_(width > 0 ? width : frame_factory->video_format_desc().width)\r
                , height_(height > 0 ? height : frame_factory->video_format_desc().height)\r
                , buffer_size_(env::properties().get(L"configuration.flash.buffer-depth", frame_factory_->video_format_desc().fps > 30.0 ? 4 : 2))\r
-               , last_frame_(core::draw_frame::empty())\r
                , executor_(L"flash_producer")\r
        {       \r
                sync_ = true;\r
@@ -382,14 +378,6 @@ public:
                                                \r
                return frame;\r
        }\r
-\r
-       virtual spl::shared_ptr<core::draw_frame> last_frame() const override\r
-       {\r
-               return lock(last_frame_mutex_, [this]\r
-               {\r
-                       return last_frame_;\r
-               });\r
-       }               \r
        \r
        virtual boost::unique_future<std::wstring> call(const std::wstring& param) override\r
        {       \r
@@ -435,15 +423,7 @@ public:
        }\r
 \r
        // flash_producer\r
-\r
-       spl::shared_ptr<core::draw_frame> render()\r
-       {\r
-               return lock(last_frame_mutex_, [this]\r
-               {\r
-                       return last_frame_ = renderer_->render();\r
-               });\r
-       }\r
-\r
+       \r
        void tick()\r
        {\r
                renderer_->tick(sync_);\r
@@ -459,13 +439,13 @@ public:
                        auto format_desc = frame_factory_->video_format_desc();\r
                                        \r
                        tick();\r
-                       auto frame = render();\r
+                       auto frame = renderer_->render();\r
 \r
                        if(abs(renderer_->fps()/2.0 - format_desc.fps) < 2.0) // flash == 2 * format -> interlace\r
                        {                                       \r
                                tick();\r
                                if(format_desc.field_mode != core::field_mode::progressive)\r
-                                       frame = core::draw_frame::interlace(frame, render(), format_desc.field_mode);\r
+                                       frame = core::draw_frame::interlace(frame, renderer_->render(), format_desc.field_mode);\r
                                \r
                                frame_buffer_.push(frame);\r
                        }\r
index 09068e0f5257044f5bf3a6a01eed8e96c9bb854e..fa5b516d887137f96783fe5e1cdefb8e8a4d16b0 100644 (file)
@@ -70,11 +70,6 @@ struct image_producer : public core::frame_producer
                return frame_;\r
        }\r
                \r
-       virtual spl::shared_ptr<core::draw_frame> last_frame() const override\r
-       {\r
-               return frame_;\r
-       }\r
-\r
        virtual std::wstring print() const override\r
        {\r
                return L"image_producer[" + filename_ + L"]";\r
index 8f9869e038aa7ef2bb77405e3bb2cf077be90231..aa297c32f62b172f0675a4b09d0b245826ad306c 100644 (file)
@@ -50,25 +50,22 @@ namespace caspar { namespace image {
                \r
 struct image_scroll_producer : public core::frame_producer\r
 {      \r
-       const std::wstring                                                      filename_;\r
+       const std::wstring                                                              filename_;\r
        std::vector<spl::shared_ptr<core::draw_frame>>  frames_;\r
-       core::video_format_desc                                         format_desc_;\r
-       int                                                                             width_;\r
-       int                                                                             height_;\r
+       core::video_format_desc                                                 format_desc_;\r
+       int                                                                                             width_;\r
+       int                                                                                             height_;\r
 \r
-       int                                                                                     delta_;\r
-       int                                                                                     speed_;\r
+       int                                                                                             delta_;\r
+       int                                                                                             speed_;\r
 \r
-       std::array<double, 2>                                           start_offset_;\r
+       std::array<double, 2>                                                   start_offset_;\r
 \r
-       spl::shared_ptr<core::draw_frame>                                       last_frame_;\r
-       \r
        explicit image_scroll_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, int speed) \r
                : filename_(filename)\r
                , delta_(0)\r
                , format_desc_(frame_factory->video_format_desc())\r
                , speed_(speed)\r
-               , last_frame_(core::draw_frame::empty())\r
        {\r
                start_offset_.assign(0.0);\r
 \r
@@ -188,14 +185,9 @@ struct image_scroll_producer : public core::frame_producer
                        }\r
                }\r
 \r
-               return last_frame_ = spl::make_shared<core::draw_frame>(frames_);\r
-       }\r
-\r
-       virtual spl::shared_ptr<core::draw_frame> last_frame() const override\r
-       {\r
-               return last_frame_;\r
+               return spl::make_shared<core::draw_frame>(frames_);\r
        }\r
-               \r
+                       \r
        virtual std::wstring print() const override\r
        {\r
                return L"image_scroll_producer[" + filename_ + L"]";\r
index b821181e08b7642f2654f89ec2eba51c31d107d9..d2a7823c6c058df0bd26edf05851bf95ba4063eb 100644 (file)
@@ -52,15 +52,13 @@ class reroute_producer : public reactive::observer<spl::shared_ptr<const core::d
        const spl::shared_ptr<diagnostics::graph>                                                                       graph_;\r
        const spl::shared_ptr<core::frame_factory>                                                                      frame_factory_;\r
        \r
-       tbb::concurrent_bounded_queue<std::shared_ptr<const core::data_frame>>  input_buffer_;\r
+       tbb::concurrent_bounded_queue<std::shared_ptr<const core::data_frame>>          input_buffer_;\r
        std::queue<spl::shared_ptr<core::draw_frame>>                                                           frame_buffer_;\r
-       spl::shared_ptr<core::draw_frame>                                                                                       last_frame_;\r
-       uint64_t                                                                                                                        frame_number_;\r
+       uint64_t                                                                                                                                        frame_number_;\r
 \r
 public:\r
        explicit reroute_producer(const spl::shared_ptr<core::frame_factory>& frame_factory) \r
                : frame_factory_(frame_factory)\r
-               , last_frame_(core::draw_frame::empty())\r
                , frame_number_(0)\r
        {\r
                graph_->set_color("late-frame", diagnostics::color(0.6f, 0.3f, 0.3f));\r
@@ -87,7 +85,7 @@ public:
                {\r
                        auto frame = frame_buffer_.front();\r
                        frame_buffer_.pop();\r
-                       return last_frame_ = frame;\r
+                       return frame;\r
                }\r
                \r
                std::shared_ptr<const core::data_frame> read_frame;\r
@@ -117,12 +115,7 @@ public:
 \r
                return receive(0);\r
        }       \r
-\r
-       virtual spl::shared_ptr<core::draw_frame> last_frame() const override\r
-       {\r
-               return last_frame_; \r
-       }       \r
-\r
+       \r
        virtual std::wstring print() const override\r
        {\r
                return L"reroute[]";\r
index e49f87cc98b4e8690acfd3e69d68fa1f96bc65a2..823e3884c1e085700d9c13148dbf4702b6da86b4 100644 (file)
@@ -7,7 +7,7 @@
     <template-path>D:\casparcg\_templates\</template-path>\r
   </paths>\r
   <log-level>trace</log-level>\r
-  <accelerator>cpu</accelerator>\r
+  <accelerator>auto</accelerator>\r
   <channels>\r
     <channel>\r
       <video-mode>PAL</video-mode>\r