]> git.sesse.net Git - casparcg/commitdiff
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 23 Oct 2011 10:37:47 +0000 (10:37 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 23 Oct 2011 10:37:47 +0000 (10:37 +0000)
modules/flash/producer/flash_producer.cpp

index 6652165e472d0649e9c72a5e82cf594f451bc09c..e0529031dc7a08856eb6259575171f5ea2da7439 100644 (file)
@@ -50,6 +50,8 @@
 #include <agents_extras.h>\r
 #include <concrt_extras.h>\r
 \r
+using namespace Concurrency;\r
+\r
 namespace caspar { namespace flash {\r
                \r
 class bitmap\r
@@ -127,22 +129,22 @@ template_host get_template_host(const core::video_format_desc& desc)
 \r
 class flash_renderer\r
 {      \r
-       const std::wstring filename_;\r
+       const std::wstring                                                              filename_;\r
 \r
-       const safe_ptr<core::frame_factory> frame_factory_;\r
-       \r
-       CComObject<caspar::flash::FlashAxContainer>* ax_;\r
-       safe_ptr<core::basic_frame> head_;\r
-       bitmap bmp_;\r
-       \r
-       safe_ptr<diagnostics::graph> graph_;\r
-       boost::timer frame_timer_;\r
-       boost::timer tick_timer_;\r
+       const safe_ptr<core::frame_factory>                             frame_factory_;\r
+       safe_ptr<diagnostics::graph>                                    graph_;\r
 \r
-       high_prec_timer timer_;\r
+       high_prec_timer                                                                 timer_;\r
+       safe_ptr<core::basic_frame>                                             head_;\r
+       bitmap                                                                                  bmp_;\r
 \r
-       const size_t width_;\r
-       const size_t height_;\r
+       const size_t                                                                    width_;\r
+       const size_t                                                                    height_;\r
+                       \r
+       boost::timer                                                                    frame_timer_;\r
+       boost::timer                                                                    tick_timer_;\r
+\r
+       CComObject<caspar::flash::FlashAxContainer>*    ax_;\r
        \r
 public:\r
        flash_renderer(const safe_ptr<diagnostics::graph>& graph, const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, int width, int height) \r
@@ -159,8 +161,7 @@ public:
                graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f));\r
                graph_->add_guide("tick-time", 0.5);\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("param", diagnostics::color(1.0f, 0.5f, 0.0f));               \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
@@ -206,7 +207,7 @@ public:
                graph_->add_tag("param");\r
        }\r
        \r
-       safe_ptr<core::basic_frame> render_frame(bool has_underflow)\r
+       safe_ptr<core::basic_frame> operator()()\r
        {\r
                const float frame_time = 1.0f/ax_->GetFPS();\r
 \r
@@ -216,14 +217,9 @@ public:
                if(ax_->IsEmpty())\r
                        return core::basic_frame::empty();              \r
                \r
-               if(!has_underflow)              \r
-               {\r
-                       Concurrency::scoped_oversubcription_token oversubscribe;\r
-                       timer_.tick(frame_time); // This will block the thread.\r
-                       //Concurrency::wait(std::max<int>(0, frame_time-3));\r
-               }\r
-               else\r
-                       graph_->add_tag("skip-sync");\r
+               Concurrency::scoped_oversubcription_token oversubscribe;\r
+               timer_.tick(frame_time); // This will block the thread.\r
+               //Concurrency::wait(std::max<int>(0, frame_time-3));\r
                        \r
                frame_timer_.restart();\r
 \r
@@ -256,8 +252,8 @@ public:
 \r
 struct flash_producer : public Concurrency::agent, public core::frame_producer\r
 {      \r
-       Concurrency::unbounded_buffer<std::wstring>                                     params_;\r
-       Concurrency::bounded_buffer<safe_ptr<core::basic_frame>>        frames_;\r
+       unbounded_buffer<std::wstring>                                                          params_;\r
+       bounded_buffer<safe_ptr<core::basic_frame>>                                     frames_;\r
 \r
        tbb::atomic<bool>                                                                                       is_running_;\r
                \r
@@ -267,7 +263,7 @@ struct flash_producer : public Concurrency::agent, public core::frame_producer
        const int                                                                                                       width_;\r
        const int                                                                                                       height_;\r
                \r
-       mutable Concurrency::overwrite_buffer<safe_ptr<core::basic_frame>> last_frame_;\r
+       mutable overwrite_buffer<safe_ptr<core::basic_frame>>           last_frame_;\r
 \r
        safe_ptr<diagnostics::graph>                                                            graph_;\r
                                \r
@@ -278,7 +274,7 @@ public:
                , filename_(filename)           \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
-               , graph_(diagnostics::create_graph("", false))\r
+               , graph_(diagnostics::create_graph("flash", false))\r
        {       \r
                if(!boost::filesystem::exists(filename))\r
                        BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(narrow(filename)));  \r
@@ -298,7 +294,7 @@ public:
        {\r
                is_running_ = false;\r
                auto frame = core::basic_frame::empty();\r
-               while(Concurrency::try_receive(frames_, frame)){}\r
+               while(try_receive(frames_, frame)){}\r
                agent::wait(this);\r
        }\r
        \r
@@ -325,23 +321,23 @@ public:
 \r
                                if(abs(renderer.fps()/2.0 - format_desc.fps) < 2.0) // flash == 2 * format -> interlace\r
                                {\r
-                                       auto frame1 = renderer.render_frame(false);\r
-                                       auto frame2 = renderer.render_frame(false);\r
-                                       Concurrency::send(last_frame_, frame2);\r
-                                       Concurrency::send(frames_, core::basic_frame::interlace(frame1, frame2, format_desc.field_mode));\r
+                                       auto frame1 = renderer();\r
+                                       auto frame2 = renderer();\r
+                                       send(last_frame_, frame2);\r
+                                       send(frames_, core::basic_frame::interlace(frame1, frame2, format_desc.field_mode));\r
                                }\r
                                else if(abs(renderer.fps()- format_desc.fps/2.0) < 2.0) // format == 2 * flash -> duplicate\r
                                {\r
-                                       auto frame = renderer.render_frame(false);\r
-                                       Concurrency::send(last_frame_, frame);\r
-                                       Concurrency::send(frames_, frame);\r
-                                       Concurrency::send(frames_, frame);\r
+                                       auto frame = renderer();\r
+                                       send(last_frame_, frame);\r
+                                       send(frames_, frame);\r
+                                       send(frames_, frame);\r
                                }\r
                                else //if(abs(renderer_->fps() - format_desc_.fps) < 0.1) // format == flash -> simple\r
                                {\r
-                                       auto frame = renderer.render_frame(false);\r
-                                       Concurrency::send(last_frame_, frame);\r
-                                       Concurrency::send(frames_, frame);\r
+                                       auto frame = renderer();\r
+                                       send(last_frame_, frame);\r
+                                       send(frames_, frame);\r
                                }\r
 \r
                                fps_ = static_cast<int>(renderer.fps()*100.0);\r
@@ -365,9 +361,9 @@ public:
 \r
                try\r
                {\r
-                       frame = Concurrency::receive(frames_, 5);\r
+                       frame = Concurrency::receive(frames_, 10);\r
                }\r
-               catch(Concurrency::operation_timed_out&)\r
+               catch(operation_timed_out&)\r
                {                       \r
                        graph_->add_tag("underflow");\r
                }\r
@@ -387,7 +383,7 @@ public:
                        agent::wait(this);\r
                        start();\r
                }\r
-               Concurrency::asend(params_, param);\r
+               asend(params_, param);\r
        }\r
                \r
        virtual std::wstring print() const\r