]> git.sesse.net Git - casparcg/blobdiff - modules/flash/producer/flash_producer.cpp
2.1.0: -data_frame: Added field_mode and frame_rate meta-data.
[casparcg] / modules / flash / producer / flash_producer.cpp
index 0c4a163a7c4bce93a837fe9469feabbec52925e6..c07cdbd79749ebb51d46a925dbcc5b2ef6da5866 100644 (file)
@@ -277,7 +277,7 @@ public:
        \r
        spl::shared_ptr<core::draw_frame> render()\r
        {                       \r
-               const float frame_time = 1.0f/ax_->GetFPS();\r
+               const float frame_time = 1.0f/fps();\r
 \r
                frame_timer_.restart();\r
 \r
@@ -288,7 +288,7 @@ public:
                \r
                        core::pixel_format_desc desc = core::pixel_format::bgra;\r
                        desc.planes.push_back(core::pixel_format_desc::plane(width_, height_, 4));\r
-                       auto frame = frame_factory_->create_frame(this, desc);\r
+                       auto frame = frame_factory_->create_frame(this, desc, fps(), core::field_mode::progressive);\r
 \r
                        A_memcpy(frame->image_data(0).begin(), bmp_.data(), width_*height_*4);\r
                        head_ = frame;  \r
@@ -332,20 +332,19 @@ 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
+       std::unique_ptr<flash_renderer>                                                                         renderer_;\r
 \r
        spl::shared_ptr<core::draw_frame>                                                                       last_frame_;\r
-       mutable tbb::spin_mutex                                                                                         last_frame_mutex_;\r
-                       \r
-       std::unique_ptr<flash_renderer>                                                                         renderer_;\r
 \r
        executor                                                                                                                        executor_;      \r
 public:\r
        flash_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, int width, int height) \r
                : filename_(filename)           \r
                , frame_factory_(frame_factory)\r
-               , width_(width > 0 ? width : frame_factory->get_video_format_desc().width)\r
-               , height_(height > 0 ? height : frame_factory->get_video_format_desc().height)\r
-               , buffer_size_(env::properties().get(L"configuration.flash.buffer-depth", frame_factory_->get_video_format_desc().fps > 30.0 ? 4 : 2))\r
+               , 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
@@ -377,19 +376,19 @@ public:
 \r
                if(output_buffer_.try_pop(frame))                       \r
                        executor_.begin_invoke(std::bind(&flash_producer::next, this));         \r
-               else\r
-                       graph_->set_tag("late-frame");\r
-                                               \r
+               else            \r
+                       graph_->set_tag("late-frame");          \r
+\r
+               if(frame != core::draw_frame::late())\r
+                       last_frame_ = frame;\r
+               \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
+               return core::draw_frame::still(last_frame_);\r
+       }\r
        \r
        virtual boost::unique_future<std::wstring> call(const std::wstring& param) override\r
        {       \r
@@ -422,23 +421,20 @@ public:
                return L"flash[" + boost::filesystem::path(filename_).wstring() + L"|" + boost::lexical_cast<std::wstring>(fps_) + L"]";                \r
        }       \r
 \r
+       virtual std::wstring name() const override\r
+       {\r
+               return L"flash";\r
+       }\r
+\r
        virtual boost::property_tree::wptree info() const override\r
        {\r
                boost::property_tree::wptree info;\r
-               info.add(L"type", L"flash-producer");\r
+               info.add(L"type", L"flash");\r
                return info;\r
        }\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
@@ -451,16 +447,16 @@ public:
 \r
                if(frame_buffer_.empty())\r
                {\r
-                       auto format_desc = frame_factory_->get_video_format_desc();\r
+                       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
@@ -488,14 +484,14 @@ public:
 \r
 spl::shared_ptr<core::frame_producer> create_producer(const spl::shared_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params)\r
 {\r
-       auto template_host = get_template_host(frame_factory->get_video_format_desc());\r
+       auto template_host = get_template_host(frame_factory->video_format_desc());\r
        \r
        auto filename = env::template_folder() + L"\\" + template_host.filename;\r
        \r
        if(!boost::filesystem::exists(filename))\r
                BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(u8(filename)));      \r
 \r
-       return spl::make_shared<flash_producer>(frame_factory, filename, template_host.width, template_host.height);\r
+       return core::wrap_producer(spl::make_shared<flash_producer>(frame_factory, filename, template_host.width, template_host.height));\r
 }\r
 \r
 std::wstring find_template(const std::wstring& template_name)\r