]> git.sesse.net Git - casparcg/blobdiff - protocol/amcp/AMCPCommandsImpl.cpp
2.0.2: INFO, removed extra \r\n.
[casparcg] / protocol / amcp / AMCPCommandsImpl.cpp
index 9d69c22ee641c2ac08ee1c4f0971f3d45877f16d..c16087b205039d95e209be068e4c386b939479b9 100644 (file)
@@ -1,21 +1,22 @@
 /*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
 *\r
-*  This file is part of CasparCG.\r
+* This file is part of CasparCG (www.casparcg.com).\r
 *\r
-*    CasparCG is free software: you can redistribute it and/or modify\r
-*    it under the terms of the GNU General Public License as published by\r
-*    the Free Software Foundation, either version 3 of the License, or\r
-*    (at your option) any later version.\r
+* CasparCG is free software: you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation, either version 3 of the License, or\r
+* (at your option) any later version.\r
 *\r
-*    CasparCG is distributed in the hope that it will be useful,\r
-*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-*    GNU General Public License for more details.\r
-\r
-*    You should have received a copy of the GNU General Public License\r
-*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+* CasparCG is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
 *\r
+* Author: Nicklas P Andersson\r
 */\r
 \r
 #include "../StdAfx.h"\r
 #include <common/env.h>\r
 \r
 #include <common/log/log.h>\r
+#include <common/diagnostics/graph.h>\r
+#include <common/os/windows/current_version.h>\r
+#include <common/os/windows/system_info.h>\r
 \r
 #include <core/producer/frame_producer.h>\r
 #include <core/video_format.h>\r
-#include <core/video_channel_context.h>\r
 #include <core/producer/transition/transition_producer.h>\r
 #include <core/producer/frame/frame_transform.h>\r
 #include <core/producer/stage.h>\r
 #include <core/mixer/mixer.h>\r
 #include <core/consumer/output.h>\r
 \r
+#include <modules/bluefish/bluefish.h>\r
+#include <modules/decklink/decklink.h>\r
+#include <modules/ffmpeg/ffmpeg.h>\r
 #include <modules/flash/flash.h>\r
+#include <modules/flash/util/swf.h>\r
 #include <modules/flash/producer/flash_producer.h>\r
 #include <modules/flash/producer/cg_producer.h>\r
+#include <modules/ffmpeg/producer/util/util.h>\r
+#include <modules/image/image.h>\r
 \r
 #include <algorithm>\r
 #include <locale>\r
@@ -56,6 +65,7 @@
 #include <boost/algorithm/string.hpp>\r
 #include <boost/filesystem.hpp>\r
 #include <boost/regex.hpp>\r
+#include <boost/property_tree/xml_parser.hpp>\r
 \r
 /* Return codes\r
 \r
@@ -83,52 +93,54 @@ namespace caspar { namespace protocol {
 \r
 using namespace core;\r
 \r
+std::wstring MediaInfo(const boost::filesystem::wpath& path)\r
+{\r
+       if(boost::filesystem::is_regular_file(path))\r
+       {\r
+               std::wstring clipttype = TEXT(" N/A ");\r
+               std::wstring extension = boost::to_upper_copy(path.extension());\r
+               if(extension == TEXT(".TGA") || extension == TEXT(".COL") || extension == L".PNG" || extension == L".JPEG" || extension == L".JPG" ||\r
+                       extension == L"GIF" || extension == L"BMP")\r
+                       clipttype = TEXT(" STILL ");\r
+               else if(extension == TEXT(".WAV") || extension == TEXT(".MP3"))\r
+                       clipttype = TEXT(" STILL ");\r
+               else if(caspar::ffmpeg::is_valid_file(path.file_string()) || extension == L".CT")\r
+                       clipttype = TEXT(" MOVIE ");\r
+\r
+               if(clipttype != TEXT(" N/A "))\r
+               {               \r
+                       auto is_not_digit = [](char c){ return std::isdigit(c) == 0; };\r
+\r
+                       auto relativePath = boost::filesystem::wpath(path.file_string().substr(env::media_folder().size()-1, path.file_string().size()));\r
+\r
+                       auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(path)));\r
+                       writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), is_not_digit), writeTimeStr.end());\r
+                       auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end());\r
+\r
+                       auto sizeStr = boost::lexical_cast<std::wstring>(boost::filesystem::file_size(path));\r
+                       sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), is_not_digit), sizeStr.end());\r
+                       auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end());\r
+                               \r
+                       auto str = relativePath.replace_extension(TEXT("")).external_file_string();\r
+                       if(str[0] == '\\' || str[0] == '/')\r
+                               str = std::wstring(str.begin() + 1, str.end());\r
+\r
+                       return std::wstring() + TEXT("\"") + str +\r
+                                       + TEXT("\" ") + clipttype +\r
+                                       + TEXT(" ") + sizeStr +\r
+                                       + TEXT(" ") + writeTimeWStr +\r
+                                       + TEXT("\r\n");         \r
+               }       \r
+       }\r
+       return L"";\r
+}\r
+\r
 std::wstring ListMedia()\r
 {      \r
        std::wstringstream replyString;\r
-       for (boost::filesystem::wrecursive_directory_iterator itr(env::media_folder()), end; itr != end; ++itr)\r
-       {                       \r
-               if(boost::filesystem::is_regular_file(itr->path()))\r
-               {\r
-                       std::wstring clipttype = TEXT(" N/A ");\r
-                       std::wstring extension = boost::to_upper_copy(itr->path().extension());\r
-                       if(extension == TEXT(".TGA") || extension == TEXT(".COL") || extension == L".PNG" || extension == L".JPEG" || extension == L".JPG" ||\r
-                               extension == L"GIF" || extension == L"BMP")\r
-                               clipttype = TEXT(" STILL ");\r
-                       else if(extension == TEXT(".SWF") || extension == TEXT(".DV") || extension == TEXT(".MOV") || extension == TEXT(".MPG") || \r
-                                       extension == TEXT(".AVI") || extension == TEXT(".FLV") || extension == TEXT(".F4V") || extension == TEXT(".MP4") ||\r
-                                       extension == L".M2V" || extension == L".H264" || extension == L".MKV" || extension == L".WMV" || extension == L".DIVX" || \r
-                                       extension == L".XVID" || extension == L".OGG")\r
-                               clipttype = TEXT(" MOVIE ");\r
-                       else if(extension == TEXT(".WAV") || extension == TEXT(".MP3"))\r
-                               clipttype = TEXT(" STILL ");\r
-\r
-                       if(clipttype != TEXT(" N/A "))\r
-                       {               \r
-                               auto is_not_digit = [](char c){ return std::isdigit(c) == 0; };\r
-\r
-                               auto relativePath = boost::filesystem::wpath(itr->path().file_string().substr(env::media_folder().size()-1, itr->path().file_string().size()));\r
-\r
-                               auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(itr->path())));\r
-                               writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), is_not_digit), writeTimeStr.end());\r
-                               auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end());\r
-\r
-                               auto sizeStr = boost::lexical_cast<std::wstring>(boost::filesystem::file_size(itr->path()));\r
-                               sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), is_not_digit), sizeStr.end());\r
-                               auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end());\r
-                               \r
-                               auto str = relativePath.replace_extension(TEXT("")).external_file_string();\r
-                               if(str[0] == '\\' || str[0] == '/')\r
-                                       str = std::wstring(str.begin() + 1, str.end());\r
-\r
-                               replyString << TEXT("\"") << str\r
-                                                       << TEXT("\" ") << clipttype \r
-                                                       << TEXT(" ") << sizeStr\r
-                                                       << TEXT(" ") << writeTimeWStr\r
-                                                       << TEXT("\r\n");        \r
-                       }       \r
-               }\r
-       }\r
+       for (boost::filesystem::wrecursive_directory_iterator itr(env::media_folder()), end; itr != end; ++itr) \r
+               replyString << MediaInfo(itr->path());\r
+       \r
        return boost::to_upper_copy(replyString.str());\r
 }\r
 \r
@@ -138,7 +150,7 @@ std::wstring ListTemplates()
 \r
        for (boost::filesystem::wrecursive_directory_iterator itr(env::template_folder()), end; itr != end; ++itr)\r
        {               \r
-               if(boost::filesystem::is_regular_file(itr->path()) && itr->path().extension() == L".ft")\r
+               if(boost::filesystem::is_regular_file(itr->path()) && (itr->path().extension() == L".ft" || itr->path().extension() == L".ct"))\r
                {\r
                        auto relativePath = boost::filesystem::wpath(itr->path().file_string().substr(env::template_folder().size()-1, itr->path().file_string().size()));\r
 \r
@@ -191,27 +203,62 @@ void AMCPCommand::Clear()
        _parameters.clear();\r
 }\r
 \r
-bool ParamCommand::DoExecute()\r
+bool DiagnosticsCommand::DoExecute()\r
+{      \r
+       try\r
+       {\r
+               diagnostics::show_graphs(true);\r
+\r
+               SetReplyString(TEXT("202 DIAG OK\r\n"));\r
+\r
+               return true;\r
+       }\r
+       catch(...)\r
+       {\r
+               CASPAR_LOG_CURRENT_EXCEPTION();\r
+               SetReplyString(TEXT("502 DIAG FAILED\r\n"));\r
+               return false;\r
+       }\r
+}\r
+\r
+bool CallCommand::DoExecute()\r
 {      \r
        //Perform loading of the clip\r
        try\r
        {\r
-               auto what = _parameters.at(2);\r
+               auto what = _parameters.at(0);\r
+\r
+               std::wstring param = _parameters2.at(1);\r
+               for(auto it = std::begin(_parameters2)+2; it != std::end(_parameters2); ++it)\r
+                       param += L" " + *it;\r
+               \r
+               boost::unique_future<std::wstring> result;\r
                if(what == L"B")\r
-                       GetChannel()->stage()->background(GetLayerIndex()).get()->param(_parameters.at(3));\r
+                       result = GetChannel()->stage()->call(GetLayerIndex(), false, param);\r
                else if(what == L"F")\r
-                       GetChannel()->stage()->foreground(GetLayerIndex()).get()->param(_parameters.at(3));\r
+                       result = GetChannel()->stage()->call(GetLayerIndex(), true, param);\r
+               else\r
+                       result = GetChannel()->stage()->call(GetLayerIndex(), true, _parameters.at(0) + L" " + param);\r
        \r
-               CASPAR_LOG(info) << "Executed param: " <<  _parameters[0] << TEXT(" successfully");\r
+               if(!result.timed_wait(boost::posix_time::seconds(2)))\r
+                       BOOST_THROW_EXCEPTION(timed_out());\r
 \r
-               SetReplyString(TEXT("202 PARAM OK\r\n"));\r
+               CASPAR_LOG(info) << "Executed call: " <<  _parameters[0] << TEXT(" successfully");\r
+               \r
+               std::wstringstream replyString;\r
+               if(result.get().empty())\r
+                       replyString << TEXT("202 CALL OK\r\n");\r
+               else\r
+                       replyString << TEXT("201 CALL OK\r\n") << result.get() << L"\r\n";\r
+               \r
+               SetReplyString(replyString.str());\r
 \r
                return true;\r
        }\r
        catch(...)\r
        {\r
                CASPAR_LOG_CURRENT_EXCEPTION();\r
-               SetReplyString(TEXT("502 PARAM FAILED\r\n"));\r
+               SetReplyString(TEXT("502 CALL FAILED\r\n"));\r
                return false;\r
        }\r
 }\r
@@ -221,7 +268,7 @@ bool MixerCommand::DoExecute()
        //Perform loading of the clip\r
        try\r
        {       \r
-               if(_parameters[0] == L"KEYER")\r
+               if(_parameters[0] == L"KEYER" || _parameters[0] == L"IS_KEY")\r
                {\r
                        bool value = lexical_cast_or_default(_parameters.at(1), false);\r
                        auto transform = [=](frame_transform transform) -> frame_transform\r
@@ -231,7 +278,7 @@ bool MixerCommand::DoExecute()
                        };\r
 \r
                        int layer = GetLayerIndex();\r
-                       GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform);\r
+                       GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform);\r
                }\r
                else if(_parameters[0] == L"OPACITY")\r
                {\r
@@ -247,9 +294,9 @@ bool MixerCommand::DoExecute()
                        };\r
 \r
                        int layer = GetLayerIndex();\r
-                       GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);\r
+                       GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);\r
                }\r
-               else if(_parameters[0] == L"FILL")\r
+               else if(_parameters[0] == L"FILL" || _parameters[0] == L"FILL_RECT")\r
                {\r
                        int duration = _parameters.size() > 5 ? lexical_cast_or_default(_parameters[5], 0) : 0;\r
                        std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear";\r
@@ -272,9 +319,9 @@ bool MixerCommand::DoExecute()
                        };\r
                                \r
                        int layer = GetLayerIndex();\r
-                       GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);\r
+                       GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);\r
                }\r
-               else if(_parameters[0] == L"CLIP")\r
+               else if(_parameters[0] == L"CLIP" || _parameters[0] == L"CLIP_RECT")\r
                {\r
                        int duration = _parameters.size() > 5 ? lexical_cast_or_default(_parameters[5], 0) : 0;\r
                        std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear";\r
@@ -293,7 +340,7 @@ bool MixerCommand::DoExecute()
                        };\r
                                \r
                        int layer = GetLayerIndex();\r
-                       GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);\r
+                       GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);\r
                }\r
                else if(_parameters[0] == L"GRID")\r
                {\r
@@ -318,7 +365,7 @@ bool MixerCommand::DoExecute()
                                                transform.clip_scale[1]                 = delta;                        \r
                                                return transform;\r
                                        };\r
-                                       GetChannel()->mixer()->apply_frame_transform(index, transform, duration, tween);\r
+                                       GetChannel()->stage()->apply_frame_transform(index, transform, duration, tween);\r
                                }\r
                        }\r
                }\r
@@ -340,7 +387,7 @@ bool MixerCommand::DoExecute()
                        };\r
                                \r
                        int layer = GetLayerIndex();\r
-                       GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);      \r
+                       GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);      \r
                }\r
                else if(_parameters[0] == L"SATURATION")\r
                {\r
@@ -354,7 +401,7 @@ bool MixerCommand::DoExecute()
                        };\r
                                \r
                        int layer = GetLayerIndex();\r
-                       GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);      \r
+                       GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);      \r
                }\r
                else if(_parameters[0] == L"CONTRAST")\r
                {\r
@@ -368,7 +415,7 @@ bool MixerCommand::DoExecute()
                        };\r
                                \r
                        int layer = GetLayerIndex();\r
-                       GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);      \r
+                       GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);      \r
                }\r
                else if(_parameters[0] == L"LEVELS")\r
                {\r
@@ -388,7 +435,7 @@ bool MixerCommand::DoExecute()
                        };\r
                                \r
                        int layer = GetLayerIndex();\r
-                       GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);      \r
+                       GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);      \r
                }\r
                else if(_parameters[0] == L"VOLUME")\r
                {\r
@@ -403,11 +450,15 @@ bool MixerCommand::DoExecute()
                        };\r
                                \r
                        int layer = GetLayerIndex();\r
-                       GetChannel()->mixer()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);\r
+                       GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);\r
                }\r
                else if(_parameters[0] == L"CLEAR")\r
                {\r
-                       GetChannel()->mixer()->clear_transforms();\r
+                       int layer = GetLayerIndex(std::numeric_limits<int>::max());\r
+                       if(layer ==     std::numeric_limits<int>::max())\r
+                               GetChannel()->stage()->clear_transforms();\r
+                       else\r
+                               GetChannel()->stage()->clear_transforms(layer);\r
                }\r
                else\r
                {\r
@@ -449,13 +500,13 @@ bool SwapCommand::DoExecute()
                        int l1 = GetLayerIndex();\r
                        int l2 = boost::lexical_cast<int>(strs.at(1));\r
 \r
-                       ch1->stage()->swap_layer(l1, l2, *ch2->stage());\r
+                       ch1->stage()->swap_layer(l1, l2, ch2->stage());\r
                }\r
                else\r
                {\r
                        auto ch1 = GetChannel();\r
                        auto ch2 = GetChannels().at(boost::lexical_cast<int>(_parameters[0])-1);\r
-                       ch1->stage()->swap(*ch2->stage());\r
+                       ch1->stage()->swap_layers(ch2->stage());\r
                }\r
 \r
                CASPAR_LOG(info) << "Swapped successfully";\r
@@ -483,7 +534,8 @@ bool AddCommand::DoExecute()
        //Perform loading of the clip\r
        try\r
        {\r
-               GetChannel()->output()->add(GetLayerIndex(), create_consumer(_parameters));\r
+               auto consumer = create_consumer(_parameters);\r
+               GetChannel()->output()->add(GetLayerIndex(consumer->index()), consumer);\r
        \r
                CASPAR_LOG(info) << "Added " <<  _parameters[0] << TEXT(" successfully");\r
 \r
@@ -510,7 +562,11 @@ bool RemoveCommand::DoExecute()
        //Perform loading of the clip\r
        try\r
        {\r
-               GetChannel()->output()->remove(GetLayerIndex());\r
+               auto index = GetLayerIndex(std::numeric_limits<int>::min());\r
+               if(index == std::numeric_limits<int>::min())\r
+                       index = create_consumer(_parameters)->index();\r
+\r
+               GetChannel()->output()->remove(index);\r
 \r
                SetReplyString(TEXT("202 REMOVE OK\r\n"));\r
 \r
@@ -650,7 +706,7 @@ bool LoadbgCommand::DoExecute()
 \r
                bool auto_play = std::find(_parameters.begin(), _parameters.end(), L"AUTO") != _parameters.end();\r
 \r
-               auto pFP2 = create_transition_producer(GetChannel()->get_video_format_desc().field_mode, create_destroy_producer_proxy(GetChannel()->context().destruction(), pFP), transitionInfo);\r
+               auto pFP2 = create_transition_producer(GetChannel()->get_video_format_desc().field_mode, pFP, transitionInfo);\r
                GetChannel()->stage()->load(GetLayerIndex(), pFP2, false, auto_play ? transitionInfo.duration : -1); // TODO: LOOP\r
        \r
                CASPAR_LOG(info) << "Loaded " << _parameters[0] << TEXT(" successfully to background");\r
@@ -751,39 +807,13 @@ bool ClearCommand::DoExecute()
 \r
 bool PrintCommand::DoExecute()\r
 {\r
-       GetChannel()->output()->add(99978, create_consumer(boost::assign::list_of(L"IMAGE")));\r
+       GetChannel()->output()->add(create_consumer(boost::assign::list_of(L"IMAGE")));\r
                \r
        SetReplyString(TEXT("202 PRINT OK\r\n"));\r
 \r
        return true;\r
 }\r
 \r
-bool StatusCommand::DoExecute()\r
-{                              \r
-       if (GetLayerIndex() > -1)\r
-       {\r
-               auto status = GetChannel()->stage()->get_status(GetLayerIndex());\r
-               std::wstringstream status_text;\r
-               status_text\r
-                       << L"202 STATUS OK\r\n"\r
-                       << L"FOREGROUND:"               << status.foreground << L"\r\n"\r
-                       << L"BACKGROUND:"               << status.background << L"\r\n"\r
-                       << L"STATUS:"                   << (status.is_paused ? L"PAUSED" : L"PLAYING") << L"\r\n"\r
-                       << L"TOTAL FRAMES:"             << (status.total_frames == std::numeric_limits<int64_t>::max() ? 0 : status.total_frames) << L"\r\n"\r
-                       << L"CURRENT FRAME:"    << status.current_frame << L"\r\n";\r
-\r
-               SetReplyString(status_text.str());\r
-               return true;\r
-       }\r
-       else\r
-       {\r
-               //NOTE: Possible to extend soo that "channel" status is returned when no layer is specified.\r
-\r
-               SetReplyString(TEXT("403 LAYER MUST BE SPECIFIED\r\n"));\r
-               return false;\r
-       }\r
-}\r
-\r
 bool LogCommand::DoExecute()\r
 {\r
        if(_parameters.at(0) == L"LEVEL")\r
@@ -1070,6 +1100,9 @@ bool CGCommand::DoExecuteUpdate()
 \r
 bool CGCommand::DoExecuteInvoke() \r
 {\r
+       std::wstringstream replyString;\r
+       replyString << TEXT("201 CG OK\r\n");\r
+\r
        if(_parameters.size() > 2)\r
        {\r
                if(!ValidateLayer(_parameters[1]))\r
@@ -1078,23 +1111,44 @@ bool CGCommand::DoExecuteInvoke()
                        return false;\r
                }\r
                int layer = _ttoi(_parameters[1].c_str());\r
-               flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->invoke(layer, _parameters2[2]);\r
+               auto result = flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->invoke(layer, _parameters2[2]);\r
+               replyString << result << TEXT("\r\n"); \r
        }\r
        else \r
        {\r
                SetReplyString(TEXT("402 CG ERROR\r\n"));\r
                return true;\r
        }\r
-\r
-       SetReplyString(TEXT("202 CG OK\r\n"));\r
+       \r
+       SetReplyString(replyString.str());\r
        return true;\r
 }\r
 \r
 bool CGCommand::DoExecuteInfo() \r
 {\r
-       // TODO\r
-       //flash::get_default_cg_producer(GetChannel())->Info();\r
-       SetReplyString(TEXT("600 CG FAILED\r\n"));\r
+       std::wstringstream replyString;\r
+       replyString << TEXT("201 CG OK\r\n");\r
+\r
+       if(_parameters.size() > 1)\r
+       {\r
+               if(!ValidateLayer(_parameters[1]))\r
+               {\r
+                       SetReplyString(TEXT("403 CG ERROR\r\n"));\r
+                       return false;\r
+               }\r
+\r
+               int layer = _ttoi(_parameters[1].c_str());\r
+               auto desc = flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->description(layer);\r
+               \r
+               replyString << desc << TEXT("\r\n"); \r
+       }\r
+       else \r
+       {\r
+               auto info = flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->template_host_info();\r
+               replyString << info << TEXT("\r\n"); \r
+       }       \r
+\r
+       SetReplyString(replyString.str());\r
        return true;\r
 }\r
 \r
@@ -1208,30 +1262,34 @@ bool DataCommand::DoExecuteList()
 bool CinfCommand::DoExecute()\r
 {\r
        std::wstringstream replyString;\r
+       \r
+       try\r
+       {\r
+               std::wstring info;\r
+               for (boost::filesystem::wrecursive_directory_iterator itr(env::media_folder()), end; itr != end; ++itr)\r
+               {\r
+                       auto path = itr->path();\r
+                       auto file = path.replace_extension(L"").filename();\r
+                       if(boost::iequals(file, _parameters.at(0)))\r
+                               info += MediaInfo(itr->path()) + L"\r\n";\r
+               }\r
 \r
-       std::wstring filename = _parameters[0];\r
-\r
-       // TODO:\r
-\r
-       //FileInfo fileInfo;\r
-\r
-       //MediaManagerPtr pMediaManager = GetApplication()->FindMediaFile(filename, &fileInfo);\r
-       //if(pMediaManager != 0 && fileInfo.filetype.length() >0)       //File was found\r
-       //{\r
-       //      if(pMediaManager->getFileInfo(&fileInfo))\r
-       //      {\r
-       //              TCHAR numBuffer[32];\r
-       //              _ui64tot_s(fileInfo.size, numBuffer, 32, 10);\r
-\r
-       //              replyString << TEXT("201 CINF OK\r\n\"") << fileInfo.filename << TEXT("\" ") << fileInfo.type << TEXT("/") << fileInfo.filetype << TEXT("/") << fileInfo.encoding << TEXT(" ") << numBuffer << TEXT("\r\n");\r
-\r
-       //              SetReplyString(replyString.str());\r
-       //              return true;\r
-       //      }\r
-       //}\r
-\r
-       SetReplyString(TEXT("404 CINF ERROR\r\n"));\r
-       return false;\r
+               if(info.empty())\r
+               {\r
+                       SetReplyString(TEXT("404 CINF ERROR\r\n"));\r
+                       return false;\r
+               }\r
+               replyString << TEXT("200 CINF OK\r\n");\r
+               replyString << info << "\r\n";\r
+       }\r
+       catch(...)\r
+       {\r
+               SetReplyString(TEXT("404 CINF ERROR\r\n"));\r
+               return false;\r
+       }\r
+       \r
+       SetReplyString(replyString.str());\r
+       return true;\r
 }\r
 \r
 void GenerateChannelInfo(int index, const safe_ptr<core::video_channel>& pChannel, std::wstringstream& replyString)\r
@@ -1242,30 +1300,137 @@ void GenerateChannelInfo(int index, const safe_ptr<core::video_channel>& pChanne
 bool InfoCommand::DoExecute()\r
 {\r
        std::wstringstream replyString;\r
+       \r
+       boost::property_tree::xml_writer_settings<wchar_t> w(' ', 3);\r
 \r
-       if(_parameters.size() >= 1)\r
+       try\r
        {\r
-               int channelIndex = _ttoi(_parameters[0].c_str())-1;\r
+               if(_parameters.size() >= 1 && _parameters[0] == L"TEMPLATE")\r
+               {               \r
+                       replyString << L"201 INFO TEMPLATE OK\r\n";\r
+\r
+                       // Needs to be extended for any file, not just flash.\r
+\r
+                       auto filename = flash::find_template(env::template_folder() + _parameters.at(1));\r
+                                               \r
+                       std::wstringstream str;\r
+                       str << widen(flash::read_template_meta_info(filename));\r
+                       boost::property_tree::wptree info;\r
+                       boost::property_tree::xml_parser::read_xml(str, info, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);\r
 \r
-               if(channelIndex < channels_.size())\r
+                       boost::property_tree::xml_parser::write_xml(replyString, info, w);\r
+               }\r
+               else if(_parameters.size() >= 1 && _parameters[0] == L"CONFIG")\r
+               {               \r
+                       replyString << L"201 INFO CONFIG OK\r\n";\r
+\r
+                       boost::property_tree::write_xml(replyString, caspar::env::properties(), w);\r
+               }\r
+               else if(_parameters.size() >= 1 && _parameters[0] == L"PATHS")\r
                {\r
-                       replyString << TEXT("201 INFO OK\r\n");\r
-                       GenerateChannelInfo(channelIndex, channels_[channelIndex], replyString);\r
+                       replyString << L"201 INFO PATHS OK\r\n";\r
+\r
+                       boost::property_tree::wptree info;\r
+                       info.add_child(L"paths", caspar::env::properties().get_child(L"configuration.paths"));\r
+                       info.add(L"paths.initial-path", boost::filesystem2::initial_path<boost::filesystem2::wpath>().directory_string() + L"\\");\r
+\r
+                       boost::property_tree::write_xml(replyString, info, w);\r
                }\r
-               else\r
+               else if(_parameters.size() >= 1 && _parameters[0] == L"SYSTEM")\r
                {\r
-                       SetReplyString(TEXT("401 INFO ERROR\r\n"));\r
-                       return false;\r
+                       replyString << L"201 INFO SYSTEM OK\r\n";\r
+                       \r
+                       boost::property_tree::wptree info;\r
+                       \r
+                       info.add(L"system.name",                                        caspar::get_system_product_name());\r
+                       info.add(L"system.windows.name",                        caspar::get_win_product_name());\r
+                       info.add(L"system.windows.service-pack",        caspar::get_win_sp_version());\r
+                       info.add(L"system.cpu",                                         caspar::get_cpu_info());\r
+       \r
+                       BOOST_FOREACH(auto device, caspar::decklink::get_device_list())\r
+                               info.add(L"system.decklink.device", device);\r
+\r
+                       BOOST_FOREACH(auto device, caspar::bluefish::get_device_list())\r
+                               info.add(L"system.bluefish.device", device);\r
+                               \r
+                       info.add(L"system.flash",                                       caspar::flash::get_version());\r
+                       info.add(L"system.free-image",                          caspar::image::get_version());\r
+                       info.add(L"system.ffmpeg.avcodec",                      caspar::ffmpeg::get_avcodec_version());\r
+                       info.add(L"system.ffmpeg.avformat",                     caspar::ffmpeg::get_avformat_version());\r
+                       info.add(L"system.ffmpeg.avfilter",                     caspar::ffmpeg::get_avfilter_version());\r
+                       info.add(L"system.ffmpeg.avutil",                       caspar::ffmpeg::get_avutil_version());\r
+                       info.add(L"system.ffmpeg.swscale",                      caspar::ffmpeg::get_swscale_version());\r
+                                               \r
+                       boost::property_tree::write_xml(replyString, info, w);\r
+               }\r
+               else if(_parameters.size() >= 1 && _parameters[0] == L"SERVER")\r
+               {\r
+                       replyString << L"201 INFO SYSTEM OK\r\n";\r
+                       \r
+                       boost::property_tree::wptree info;\r
+\r
+                       int index = 0;\r
+                       BOOST_FOREACH(auto channel, channels_)\r
+                               info.add_child(L"channels.channel", channel->info())\r
+                                       .add(L"index", ++index);\r
+                       \r
+                       boost::property_tree::write_xml(replyString, info, w);\r
+               }\r
+               else // channel\r
+               {                       \r
+                       if(_parameters.size() >= 1)\r
+                       {\r
+                               replyString << TEXT("201 INFO OK\r\n");\r
+                               boost::property_tree::wptree info;\r
+\r
+                               std::vector<std::wstring> split;\r
+                               boost::split(split, _parameters[0], boost::is_any_of("-"));\r
+                                       \r
+                               int layer = std::numeric_limits<int>::min();\r
+                               int channel = boost::lexical_cast<int>(split[0]) - 1;\r
+\r
+                               if(split.size() > 1)\r
+                                       layer = boost::lexical_cast<int>(split[1]);\r
+                               \r
+                               if(layer == std::numeric_limits<int>::min())\r
+                               {       \r
+                                       info.add_child(L"channel", channels_.at(channel)->info())\r
+                                                       .add(L"index", channel);\r
+                               }\r
+                               else\r
+                               {\r
+                                       if(_parameters.size() >= 2)\r
+                                       {\r
+                                               if(_parameters[1] == L"B")\r
+                                                       info.add_child(L"producer", channels_.at(channel)->stage()->background(layer).get()->info());\r
+                                               else\r
+                                                       info.add_child(L"producer", channels_.at(channel)->stage()->foreground(layer).get()->info());\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               info.add_child(L"layer", channels_.at(channel)->stage()->info(layer).get())\r
+                                                       .add(L"index", layer);\r
+                                       }\r
+                               }\r
+                               boost::property_tree::xml_parser::write_xml(replyString, info, w);\r
+                       }\r
+                       else\r
+                       {\r
+                               // This is needed for backwards compatibility with old clients\r
+                               replyString << TEXT("200 INFO OK\r\n");\r
+                               for(size_t n = 0; n < channels_.size(); ++n)\r
+                                       GenerateChannelInfo(n, channels_[n], replyString);\r
+                       }\r
+\r
                }\r
        }\r
-       else\r
+       catch(...)\r
        {\r
-               replyString << TEXT("200 INFO OK\r\n");\r
-               for(size_t n = 0; n < channels_.size(); ++n)\r
-                       GenerateChannelInfo(n, channels_[n], replyString);\r
-               replyString << TEXT("\r\n");\r
+               SetReplyString(TEXT("403 INFO ERROR\r\n"));\r
+               return false;\r
        }\r
 \r
+       replyString << TEXT("\r\n");\r
        SetReplyString(replyString.str());\r
        return true;\r
 }\r
@@ -1302,14 +1467,14 @@ bool TlsCommand::DoExecute()
 \r
 bool VersionCommand::DoExecute()\r
 {\r
-       std::wstring replyString = TEXT("201 VERSION OK\r\n SERVER: ") + env::version() + TEXT("\r\n");\r
+       std::wstring replyString = TEXT("201 VERSION OK\r\n") + env::version() + TEXT("\r\n");\r
 \r
        if(_parameters.size() > 0)\r
        {\r
                if(_parameters[0] == L"FLASH")\r
-                       replyString = TEXT("201 VERSION OK\r\n FLASH: ") + flash::get_version() + TEXT("\r\n");\r
+                       replyString = TEXT("201 VERSION OK\r\n") + flash::get_version() + TEXT("\r\n");\r
                else if(_parameters[0] == L"TEMPLATEHOST")\r
-                       replyString = TEXT("201 VERSION OK\r\n TEMPLATEHOST: ") + flash::get_cg_version() + TEXT("\r\n");\r
+                       replyString = TEXT("201 VERSION OK\r\n") + flash::get_cg_version() + TEXT("\r\n");\r
                else if(_parameters[0] != L"SERVER")\r
                        replyString = TEXT("403 VERSION ERROR\r\n");\r
        }\r