]> git.sesse.net Git - casparcg/commitdiff
made all producers-factories able to handle non-uppercased params
authorniklaspandersson <niklas.p.andersson@svt.se>
Wed, 7 Aug 2013 12:28:27 +0000 (14:28 +0200)
committerniklaspandersson <niklas.p.andersson@svt.se>
Wed, 7 Aug 2013 12:28:27 +0000 (14:28 +0200)
common/param.h
core/StdAfx.h
core/producer/draw/freehand_producer.cpp
core/producer/scene/scene_producer.cpp
core/producer/text/text_producer.cpp
modules/ffmpeg/producer/ffmpeg_producer.cpp
modules/image/producer/image_scroll_producer.cpp
protocol/amcp/AMCPCommandsImpl.cpp
shell/main.cpp

index 9429536cf1bf06375d38d4b01f210c775928f40d..87a08a084ed8c01e3c9ba98289cf7b68f21f4912 100644 (file)
@@ -3,16 +3,31 @@
 #include "except.h"
 
 #include <boost/lexical_cast.hpp>
+#include <boost/algorithm/string.hpp>
 
 #include <type_traits>
 #include <string>
 
 namespace caspar {
-               
+
+class param_comparer {
+               const std::wstring& lhs;
+       public:
+               explicit param_comparer(const std::wstring& p) : lhs(p) {}
+               bool operator()(const std::wstring& rhs) { return boost::iequals(lhs, rhs); }
+       };
+
+template<typename C>
+bool contains_param(const std::wstring& name, C&& params)
+{
+       return std::find_if(params.begin(), params.end(), param_comparer(name)) != params.end();
+}
+
 template<typename T, typename C>
 typename std::enable_if<!std::is_convertible<T, std::wstring>::value, typename std::decay<T>::type>::type get_param(const std::wstring& name, C&& params, T fail_value = T())
 {      
-       auto it = std::find(std::begin(params), std::end(params), name);
+       auto it = std::find_if(std::begin(params), std::end(params), param_comparer(name));
+       //auto it = std::find(std::begin(params), std::end(params), name);
        if(it == params.end())  
                return fail_value;
        
@@ -32,7 +47,8 @@ typename std::enable_if<!std::is_convertible<T, std::wstring>::value, typename s
 template<typename C>
 std::wstring get_param(const std::wstring& name, C&& params, const std::wstring& fail_value = L"")
 {      
-       auto it = std::find(std::begin(params), std::end(params), name);
+       auto it = std::find_if(std::begin(params), std::end(params), param_comparer(name));
+       //auto it = std::find(std::begin(params), std::end(params), name);
        if(it == params.end())  
                return fail_value;
        
index 31ea7b85850a7217a9f1c3d1038f4aa4287e0563..2eb6f3dcc7e5f95786356e55688cfd325aef7657 100644 (file)
@@ -52,6 +52,7 @@
 #include <boost/range.hpp>
 #include <boost/range/adaptors.hpp>
 #include <boost/range/algorithm.hpp>
+#include <boost/algorithm/string.hpp>
 #include <boost/thread.hpp>
 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/xml_parser.hpp>
index bd3785da19e12ae0a7f94d7148c9c7ed496463bb..f426802affc65386d7a18fbad0c8e1e7da3a1781 100644 (file)
@@ -172,7 +172,7 @@ public:
 
 spl::shared_ptr<frame_producer> create_freehand_producer(const spl::shared_ptr<frame_factory>& frame_factory, const std::vector<std::wstring>& params)
 {
-       if(params.size() < 3 || params.at(0) != L"[FREEHAND]")
+       if(params.size() < 3 || !boost::iequals(params.at(0), L"[FREEHAND]"))
                return core::frame_producer::empty();
 
        int width = boost::lexical_cast<int>(params.at(1));
index 45ca4858a98b7aa6ad5ae3415ef1eefa0072413a..708fd1428e8e1843ca1567c59cad60447c29644c 100644 (file)
@@ -297,7 +297,7 @@ void scene_producer::unsubscribe(const monitor::observable::observer_ptr& o)
 
 spl::shared_ptr<frame_producer> create_dummy_scene_producer(const spl::shared_ptr<class frame_factory>& frame_factory, const video_format_desc& format_desc, const std::vector<std::wstring>& params)
 {
-       if (params.size() < 1 || params.at(0) != L"[SCENE]")
+       if (params.size() < 1 || !boost::iequals(params.at(0), L"[SCENE]"))
                return core::frame_producer::empty();
 
        auto scene = spl::make_shared<scene_producer>(format_desc.width, format_desc.height);
index 6c69903d8427f89f8e2f3f82c8e84da1dd8f3b28..575127f236f4b8003234cf3e35939232f2deac17 100644 (file)
@@ -178,7 +178,7 @@ spl::shared_ptr<text_producer> text_producer::create(const spl::shared_ptr<frame
 
 spl::shared_ptr<frame_producer> create_text_producer(const spl::shared_ptr<frame_factory>& frame_factory, const video_format_desc& format_desc, const std::vector<std::wstring>& params)
 {
-       if(params.size() < 2 || params.at(0) != L"[TEXT]")
+       if(params.size() < 2 || !boost::iequals(params.at(0), L"[TEXT]"))
                return core::frame_producer::empty();
 
        int x = 0, y = 0;
index 27c2f0f334fe68d702d69b0ac794c975fdcb413d..8a8afcad12de4edfd2c57099c12ad4cd44fa2e7f 100644 (file)
@@ -387,7 +387,7 @@ spl::shared_ptr<core::frame_producer> create_producer(const spl::shared_ptr<core
        if(filename.empty())
                return core::frame_producer::empty();
        
-       auto loop               = boost::range::find(params, L"LOOP") != params.end();
+       bool loop               = contains_param(L"LOOP", params);
        auto start              = get_param(L"START", params, get_param(L"SEEK", params, static_cast<uint32_t>(0)));
        auto length             = get_param(L"LENGTH", params, std::numeric_limits<uint32_t>::max());
        auto filter_str = get_param(L"FILTER", params, L"");    
index 5d10afc5aa0fd64dad54b63bace5a5aad8893d07..f75297ddf2e962b06dfdca929e21e09c385d6f3d 100644 (file)
@@ -40,6 +40,7 @@
 #include <common/except.h>
 #include <common/array.h>
 #include <common/tweener.h>
+#include <common/param.h>
 
 #include <boost/assign.hpp>
 #include <boost/filesystem.hpp>
@@ -417,37 +418,19 @@ spl::shared_ptr<core::frame_producer> create_scroll_producer(const spl::shared_p
        if(ext == extensions.end())
                return core::frame_producer::empty();
        
-       double speed = 0.0;
        double duration = 0.0;
-       auto speed_it = std::find(params.begin(), params.end(), L"SPEED");
-       if(speed_it != params.end())
-       {
-               if(++speed_it != params.end())
-                       speed = boost::lexical_cast<double>(*speed_it);
-       }
+       double speed = get_param(L"SPEED", params, 0.0);
 
        if (speed == 0)
-       {
-               auto duration_it = std::find(params.begin(), params.end(), L"DURATION");
-
-               if (duration_it != params.end() && ++duration_it != params.end())
-               {
-                       duration = boost::lexical_cast<double>(*duration_it);
-               }
-       }
+               duration = get_param(L"DURATION", params, 0.0);
 
        if(speed == 0 && duration == 0)
                return core::frame_producer::empty();
 
-       int motion_blur_px = 0;
-       auto blur_it = std::find(params.begin(), params.end(), L"BLUR");
-       if (blur_it != params.end() && ++blur_it != params.end())
-       {
-               motion_blur_px = boost::lexical_cast<int>(*blur_it);
-       }
+       int motion_blur_px = get_param(L"BLUR", params, 0);
 
-       bool premultiply_with_alpha = std::find(params.begin(), params.end(), L"PREMULTIPLY") != params.end();
-       bool progressive = std::find(params.begin(), params.end(), L"PROGRESSIVE") != params.end();
+       bool premultiply_with_alpha = contains_param(L"PREMULTIPLY", params);
+       bool progressive = contains_param(L"PROGRESSIVE", params);
 
        return core::create_destroy_proxy(spl::make_shared<image_scroll_producer>(
                frame_factory, 
index 6adf422fd91c28468127efc5d9acd4cb065e41a3..c2c22ed44ad972fa3f475354168ff618a07d4369 100644 (file)
@@ -31,6 +31,7 @@
 #include <common/env.h>
 
 #include <common/log.h>
+#include <common/param.h>
 #include <common/diagnostics/graph.h>
 #include <common/os/windows/current_version.h>
 #include <common/os/windows/system_info.h>
@@ -720,12 +721,6 @@ bool LoadCommand::DoExecute()
        //Perform loading of the clip
        try
        {
-               //create_producer still expects all parameters to be uppercase
-               BOOST_FOREACH(std::wstring& str, parameters())
-               {
-                       boost::to_upper(str);
-               }
-
                auto pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), parameters());             
                GetChannel()->stage().load(GetLayerIndex(), pFP, true);
        
@@ -843,18 +838,13 @@ bool LoadbgCommand::DoExecute()
                }
                else
                {
-                       //create_producer still expects all parameters to be uppercase
-                       BOOST_FOREACH(std::wstring& str, parameters())
-                       {
-                               boost::to_upper(str);
-                       }
                        pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), parameters());
                }
                
                if(pFP == frame_producer::empty())
                        CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(parameters().size() > 0 ? parameters()[0] : L""));
 
-               bool auto_play = std::find_if(parameters().begin(), parameters().end(), [](const std::wstring& p) { return boost::iequals(p, L"AUTO"); }) != parameters().end();
+               bool auto_play = contains_param(L"AUTO", parameters());
 
                auto pFP2 = create_transition_producer(GetChannel()->video_format_desc().field_mode, spl::make_shared_ptr(pFP), transitionInfo);
                if(auto_play)
index 47739e9dcea6fd53262c7e669af6799772072a5c..1c0ede785ce1d1871698bdbe7a39feeaebb55b1d 100644 (file)
@@ -205,9 +205,9 @@ void run()
        {
                std::getline(std::wcin, wcmd); // TODO: It's blocking...
                                
-               boost::to_upper(wcmd);
+               //boost::to_upper(wcmd);
 
-               if(wcmd == L"EXIT" || wcmd == L"Q" || wcmd == L"QUIT" || wcmd == L"BYE")
+               if(boost::iequals(wcmd, L"EXIT") || boost::iequals(wcmd, L"Q") || boost::iequals(wcmd, L"QUIT") || boost::iequals(wcmd, L"BYE"))
                        break;
 
                try