]> git.sesse.net Git - casparcg/commitdiff
flash_producer: Added smarter skip sync with exp sync ratio, instead of discrete...
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 15 Feb 2012 19:57:05 +0000 (19:57 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 15 Feb 2012 19:57:05 +0000 (19:57 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/trunk@2418 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

modules/flash/producer/flash_producer.cpp

index 058237b4b008af4b185f9c66a30929e664dd9ddc..d0a4c1592d62473d2de94da9b881671f987e5093 100644 (file)
@@ -191,7 +191,7 @@ public:
                graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));\r
                graph_->set_color("tick-time", diagnostics::color(0.0f, 0.6f, 0.9f));\r
                graph_->set_color("param", diagnostics::color(1.0f, 0.5f, 0.0f));       \r
-               graph_->set_color("skip-sync", diagnostics::color(0.8f, 0.3f, 0.2f));                   \r
+               graph_->set_color("sync", diagnostics::color(0.8f, 0.3f, 0.2f));                        \r
                \r
                if(FAILED(CComObject<caspar::flash::FlashAxContainer>::CreateInstance(&ax_)))\r
                        BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Failed to create FlashAxContainer"));\r
@@ -245,7 +245,7 @@ public:
                return result;\r
        }\r
        \r
-       safe_ptr<core::basic_frame> render_frame(bool sync)\r
+       safe_ptr<core::basic_frame> render_frame(double sync)\r
        {\r
                float frame_time = 1.0f/ax_->GetFPS();\r
 \r
@@ -255,10 +255,12 @@ public:
                if(ax_->IsEmpty())\r
                        return core::basic_frame::empty();              \r
                \r
-               if(sync)                        \r
-                       timer_.tick(frame_time); // This will block the thread.\r
+               if(sync > 0.00001)                      \r
+                       timer_.tick(frame_time*sync); // This will block the thread.\r
                else\r
-                       graph_->set_tag("skip-sync");\r
+                       graph_->set_tag("sync");\r
+\r
+               graph_->set_value("sync", sync);\r
                        \r
                frame_timer_.restart();\r
 \r
@@ -320,7 +322,6 @@ struct flash_producer : public core::frame_producer
        const int                                                                                                       buffer_size_;\r
 \r
        tbb::atomic<int>                                                                                        fps_;\r
-       tbb::atomic<bool>                                                                                       sync_;\r
 \r
        safe_ptr<diagnostics::graph>                                                            graph_;\r
 \r
@@ -343,10 +344,8 @@ public:
                , buffer_size_(env::properties().get(L"configuration.flash.buffer-depth", frame_factory_->get_video_format_desc().fps > 30.0 ? 4 : 2))\r
                , executor_(L"flash_producer")\r
        {       \r
-               sync_ = true;\r
                fps_ = 0;\r
         \r
-               graph_->set_color("buffer-size", diagnostics::color(1.0f, 1.0f, 0.0f));\r
                graph_->set_color("late-frame", diagnostics::color(0.6f, 0.3f, 0.9f));\r
                graph_->set_text(print());\r
                diagnostics::register_graph(graph_);\r
@@ -366,9 +365,6 @@ public:
        {                                       \r
                auto frame = core::basic_frame::late();\r
                \r
-               graph_->set_value("buffer-size", static_cast<float>(output_buffer_.size())/static_cast<float>(buffer_size_));\r
-               sync_ = output_buffer_.size() == buffer_size_;\r
-\r
                if(output_buffer_.try_pop(frame))       \r
                        next();\r
                else\r
@@ -472,7 +468,10 @@ public:
 \r
        safe_ptr<core::basic_frame> render_frame()\r
        {       \r
-               auto frame = renderer_->render_frame(sync_);\r
+               double ratio = std::min(1.0, static_cast<double>(output_buffer_.size())/static_cast<double>(std::max(1, buffer_size_ - 1)));\r
+               double sync  = 2*ratio - ratio*ratio;\r
+\r
+               auto frame = renderer_->render_frame(sync);\r
                lock(last_frame_mutex_, [&]\r
                {\r
                        last_frame_ = frame;\r