]> git.sesse.net Git - casparcg/commitdiff
2.0. flash_producer: Now possible to set static template-host size. Useful for e...
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 11 Aug 2011 08:14:02 +0000 (08:14 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 11 Aug 2011 08:14:02 +0000 (08:14 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1135 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

common/env.cpp
common/env.h
modules/flash/producer/FlashAxContainer.cpp
modules/flash/producer/FlashAxContainer.h
modules/flash/producer/cg_producer.cpp
modules/flash/producer/flash_producer.cpp

index 209e530c77408f9f6da3b18d1df7fb0b92d57cfe..99cf775bb9571fd6a65baeb117a6136ee8dd8ac4 100644 (file)
@@ -41,7 +41,6 @@ using namespace boost::filesystem2;
 std::wstring media;\r
 std::wstring log;\r
 std::wstring ftemplate;\r
-std::wstring ftemplate_host;\r
 std::wstring data;\r
 boost::property_tree::ptree pt;\r
 \r
@@ -62,10 +61,7 @@ void configure(const std::string& filename)
                auto paths = pt.get_child("configuration.paths");\r
                media = widen(paths.get("media-path", initialPath + "\\media\\"));\r
                log = widen(paths.get("log-path", initialPath + "\\log\\"));\r
-               ftemplate = complete(wpath(widen(paths.get("template-path", initialPath + "\\template\\")))).string();\r
-\r
-               ftemplate_host = widen(paths.get("template-host", "cg.fth"));\r
-\r
+               ftemplate = complete(wpath(widen(paths.get("template-path", initialPath + "\\template\\")))).string();          \r
                data = widen(paths.get("data-path", initialPath + "\\data\\"));\r
        }\r
        catch(...)\r
@@ -93,12 +89,6 @@ const std::wstring& template_folder()
        return ftemplate;\r
 }\r
 \r
-const std::wstring& template_host()\r
-{\r
-       check_is_configured();\r
-       return ftemplate_host;\r
-}\r
-\r
 const std::wstring& data_folder()\r
 {\r
        check_is_configured();\r
index 7b4ee55a9da743dfc0571db930a5aabd7babd460..bfd8d9907e4c578b7e49bc5f66d5f2163deffa86 100644 (file)
@@ -30,7 +30,6 @@ void configure(const std::string& filename);
 const std::wstring& media_folder();\r
 const std::wstring& log_folder();\r
 const std::wstring& template_folder();\r
-const std::wstring& template_host();\r
 const std::wstring& data_folder();\r
 const std::wstring& version();\r
 \r
index 48239fe94041ac6f0c3ddbebb7b96df3d672efef..c4386b4fe04af33530a1a1a0fe5cda8161a8c94c 100644 (file)
@@ -810,13 +810,13 @@ HRESULT FlashAxContainer::CreateAxControl()
        return S_OK;\r
 }\r
 \r
-void FlashAxContainer::SetFormat(const core::video_format_desc& fmtDesc) {\r
+void FlashAxContainer::SetSize(size_t width, size_t height) {\r
        if(m_spInPlaceObjectWindowless != 0)\r
        {\r
                m_rcPos.top = 0;\r
                m_rcPos.left = 0;\r
-               m_rcPos.right = fmtDesc.width;\r
-               m_rcPos.bottom = fmtDesc.height;\r
+               m_rcPos.right = width;\r
+               m_rcPos.bottom = height;\r
 \r
                m_pxSize.cx = m_rcPos.right - m_rcPos.left;\r
                m_pxSize.cy = m_rcPos.bottom - m_rcPos.top;\r
index 7f88b5fa886fa89a2e093c7313b2d3cb625ddc40..4156ac622149aa63a12aba302703419adc79da13 100644 (file)
@@ -256,7 +256,7 @@ public:
        bool InvalidRect() const { return bInvalidRect_; } \r
        bool IsEmpty() const { return bIsEmpty_; }\r
 \r
-       void SetFormat(const core::video_format_desc&);\r
+       void SetSize(size_t width, size_t height);\r
        bool IsReadyToRender() const;\r
        void EnterFullscreen();\r
 \r
index eec109005e81ab2cd3b3f54f2ec5eb579b241853..14932d56e89486ea23583b959f578060577d2ec7 100644 (file)
@@ -108,6 +108,24 @@ public:
                return flash_producer_->print();\r
        }\r
 };\r
+\r
+std::vector<std::wstring> template_host_params()\r
+{\r
+       std::vector<std::wstring> params;\r
+       params.push_back(widen(env::properties().get("configuration.template-host.filename", "cg.fth")));\r
+       \r
+       try\r
+       {\r
+               params.push_back(widen(env::properties().get<std::string>("configuration.template-host.width")));\r
+               params.push_back(widen(env::properties().get<std::string>("configuration.template-host.height")));\r
+       }\r
+       catch(...)\r
+       {\r
+               params.clear();\r
+               params.push_back(widen(env::properties().get("configuration.template-host.filename", "cg.fth")));\r
+       }\r
+       return params;\r
+}\r
        \r
 safe_ptr<cg_producer> get_default_cg_producer(const safe_ptr<core::video_channel>& video_channel, int render_layer)\r
 {      \r
@@ -115,7 +133,7 @@ safe_ptr<cg_producer> get_default_cg_producer(const safe_ptr<core::video_channel
 \r
        if(flash_producer->print().find(L"flash[") == std::string::npos) // UGLY hack\r
        {\r
-               flash_producer = create_flash_producer(video_channel->mixer(), boost::assign::list_of(env::template_host()));   \r
+               flash_producer = create_flash_producer(video_channel->mixer(), template_host_params()); \r
                video_channel->stage()->load(render_layer, flash_producer); \r
                video_channel->stage()->play(render_layer);\r
        }\r
@@ -129,7 +147,7 @@ safe_ptr<core::frame_producer> create_ct_producer(const safe_ptr<core::frame_fac
        if(!boost::filesystem::exists(filename))\r
                return core::frame_producer::empty();\r
        \r
-       auto flash_producer = create_flash_producer(frame_factory, boost::assign::list_of(env::template_host()));       \r
+       auto flash_producer = create_flash_producer(frame_factory, template_host_params());     \r
        auto producer = make_safe<cg_producer>(flash_producer);\r
        producer->add(0, filename, 1);\r
 \r
index 4b71ef62217b38c819934c4df00cf3fa12427c5b..2afaf13c5627910faf41d18c9a058f42b356a9d8 100644 (file)
@@ -86,7 +86,6 @@ private:
 class flash_renderer\r
 {      \r
        const std::wstring filename_;\r
-       core::video_format_desc format_desc_;\r
 \r
        const std::shared_ptr<core::frame_factory> frame_factory_;\r
        \r
@@ -99,16 +98,20 @@ class flash_renderer
        boost::timer tick_timer_;\r
 \r
        high_prec_timer timer_;\r
+\r
+       const size_t width_;\r
+       const size_t height_;\r
        \r
 public:\r
-       flash_renderer(const safe_ptr<diagnostics::graph>& graph, const std::shared_ptr<core::frame_factory>& frame_factory, const std::wstring& filename) \r
+       flash_renderer(const safe_ptr<diagnostics::graph>& graph, const std::shared_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, int width, int height\r
                : graph_(graph)\r
                , filename_(filename)\r
-               , format_desc_(frame_factory->get_video_format_desc())\r
                , frame_factory_(frame_factory)\r
                , ax_(nullptr)\r
                , head_(core::basic_frame::empty())\r
-               , bmp_(format_desc_.width, format_desc_.height)\r
+               , bmp_(width, height)\r
+               , width_(width)\r
+               , height_(height)\r
        {\r
                graph_->add_guide("frame-time", 0.5f);\r
                graph_->set_color("frame-time", diagnostics::color(0.8f, 0.3f, 0.4f));  \r
@@ -138,9 +141,10 @@ public:
                if(FAILED(spFlash->put_ScaleMode(2)))  //Exact fit. Scale without respect to the aspect ratio.\r
                        BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Failed to Set Scale Mode"));\r
                                                \r
-               ax_->SetFormat(format_desc_);           \r
+               ax_->SetSize(width_, height_);          \r
        \r
                CASPAR_LOG(info) << print() << L" Thread started.";\r
+               CASPAR_LOG(info) << print() << L" Successfully initialized to, width: " << width_ << L" height: " << height_ << L".";\r
        }\r
 \r
        ~flash_renderer()\r
@@ -158,19 +162,16 @@ public:
                if(!ax_->FlashCall(param))\r
                        CASPAR_LOG(warning) << print() << " Flash function call failed. Param: " << param << ".";\r
                graph_->add_tag("param");\r
-\r
-               if(abs(ax_->GetFPS() - format_desc_.fps) > 0.01 && abs(ax_->GetFPS()/2.0 - format_desc_.fps) > 0.01)\r
-                       CASPAR_LOG(warning) << print() << " Invalid frame-rate: " << ax_->GetFPS() << L". Should be either " << format_desc_.fps << L" or " << format_desc_.fps*2.0 << L".";\r
        }\r
        \r
        safe_ptr<core::basic_frame> render_frame(bool has_underflow)\r
        {\r
-               if(format_desc_ != frame_factory_->get_video_format_desc())\r
-               {\r
-                       format_desc_ = frame_factory_->get_video_format_desc();\r
-                       bmp_ = bitmap(format_desc_.width, format_desc_.height);\r
-                       ax_->SetFormat(format_desc_);\r
-               }\r
+               //if(format_desc_ != frame_factory_->get_video_format_desc())\r
+               //{\r
+               //      format_desc_ = frame_factory_->get_video_format_desc();\r
+               //      bmp_ = bitmap(format_desc_.width, format_desc_.height);\r
+               //      ax_->SetFormat(format_desc_);\r
+               //}\r
 \r
                float frame_time = 1.0f/ax_->GetFPS();\r
 \r
@@ -190,11 +191,11 @@ public:
                ax_->Tick();\r
                if(ax_->InvalidRect())\r
                {                       \r
-                       fast_memclr(bmp_.data(),  format_desc_.size);\r
+                       fast_memclr(bmp_.data(), width_*height_*4);\r
                        ax_->DrawControl(bmp_);\r
                \r
-                       auto frame = frame_factory_->create_frame(this, format_desc_.width, format_desc_.height);\r
-                       fast_memcpy(frame->image_data().begin(), bmp_.data(), format_desc_.size);\r
+                       auto frame = frame_factory_->create_frame(this, width_, height_);\r
+                       fast_memcpy(frame->image_data().begin(), bmp_.data(), width_*height_*4);\r
                        frame->commit();\r
                        head_ = frame;\r
                }               \r
@@ -227,13 +228,18 @@ struct flash_producer : public core::frame_producer
 \r
        safe_ptr<core::basic_frame>     last_frame_;\r
                                \r
-       com_context<flash_renderer> context_;           \r
+       com_context<flash_renderer> context_;   \r
+\r
+       int width_;\r
+       int height_;\r
 public:\r
-       flash_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename) \r
+       flash_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, size_t width, size_t height\r
                : filename_(filename)           \r
                , frame_factory_(frame_factory)\r
                , context_(L"flash_producer")\r
                , last_frame_(core::basic_frame::empty())\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
        {       \r
                if(!boost::filesystem::exists(filename))\r
                        BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(narrow(filename)));  \r
@@ -281,6 +287,10 @@ public:
                        try\r
                        {\r
                                context_->param(param); \r
+\r
+                               const auto& format_desc = frame_factory_->get_video_format_desc();\r
+                               if(abs(context_->fps() - format_desc.fps) > 0.01 && abs(context_->fps()/2.0 - format_desc.fps) > 0.01)\r
+                                       CASPAR_LOG(warning) << print() << " Invalid frame-rate: " << context_->fps() << L". Should be either " << format_desc.fps << L" or " << format_desc.fps*2.0 << L".";\r
                        }\r
                        catch(...)\r
                        {\r
@@ -301,7 +311,7 @@ public:
 \r
        void initialize()\r
        {\r
-               context_.reset([&]{return new flash_renderer(safe_ptr<diagnostics::graph>(graph_), frame_factory_, filename_);});\r
+               context_.reset([&]{return new flash_renderer(safe_ptr<diagnostics::graph>(graph_), frame_factory_, filename_, width_, height_);});\r
                while(frame_buffer_.try_push(core::basic_frame::empty())){}             \r
                render(context_.get());\r
        }\r
@@ -353,8 +363,17 @@ public:
 safe_ptr<core::frame_producer> create_flash_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params)\r
 {\r
        std::wstring filename = env::template_folder() + L"\\" + params[0];\r
+\r
+       size_t width = frame_factory->get_video_format_desc().width;\r
+       size_t height = frame_factory->get_video_format_desc().height;\r
+\r
+       if(params.size() >= 3)\r
+       {\r
+               width = boost::lexical_cast<size_t>(params[1]);\r
+               height = boost::lexical_cast<size_t>(params[2]);\r
+       }\r
        \r
-       return make_safe<flash_producer>(frame_factory, filename);\r
+       return make_safe<flash_producer>(frame_factory, filename, width, height);\r
 }\r
 \r
 std::wstring find_flash_template(const std::wstring& template_name)\r