2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Nicklas P Andersson
22 #include "../StdAfx.h"
25 #pragma warning (push, 1) // TODO: Legacy code, just disable warnings
28 #include "AMCPCommandsImpl.h"
29 #include "AMCPProtocolStrategy.h"
31 #include <common/env.h>
33 #include <common/log.h>
34 #include <common/diagnostics/graph.h>
35 #include <common/os/windows/current_version.h>
36 #include <common/os/windows/system_info.h>
38 #include <core/producer/frame_producer.h>
39 #include <core/video_format.h>
40 #include <core/producer/transition/transition_producer.h>
41 #include <core/frame/frame_transform.h>
42 #include <core/producer/stage.h>
43 #include <core/producer/layer.h>
44 #include <core/mixer/mixer.h>
45 #include <core/consumer/output.h>
47 #include <modules/reroute/producer/reroute_producer.h>
48 #include <modules/bluefish/bluefish.h>
49 #include <modules/decklink/decklink.h>
50 #include <modules/ffmpeg/ffmpeg.h>
51 #include <modules/flash/flash.h>
52 #include <modules/flash/util/swf.h>
53 #include <modules/flash/producer/flash_producer.h>
54 #include <modules/flash/producer/cg_proxy.h>
55 #include <modules/ffmpeg/producer/util/util.h>
56 #include <modules/image/image.h>
57 #include <modules/screen/screen.h>
58 #include <modules/reroute/producer/reroute_producer.h>
67 #include <boost/date_time/posix_time/posix_time.hpp>
68 #include <boost/lexical_cast.hpp>
69 #include <boost/algorithm/string.hpp>
70 #include <boost/filesystem.hpp>
71 #include <boost/filesystem/fstream.hpp>
72 #include <boost/regex.hpp>
73 #include <boost/property_tree/xml_parser.hpp>
74 #include <boost/locale.hpp>
75 #include <boost/range/adaptor/transformed.hpp>
76 #include <boost/range/algorithm/copy.hpp>
78 #include <tbb/concurrent_unordered_map.h>
82 100 [action] Information om att något har hänt
83 101 [action] Information om att något har hänt, en rad data skickas
85 202 [kommando] OK Kommandot har utförts
86 201 [kommando] OK Kommandot har utförts, och en rad data skickas tillbaka
87 200 [kommando] OK Kommandot har utförts, och flera rader data skickas tillbaka. Avslutas med tomrad
89 400 ERROR Kommandot kunde inte förstås
90 401 [kommando] ERROR Ogiltig kanal
91 402 [kommando] ERROR Parameter saknas
92 403 [kommando] ERROR Ogiltig parameter
93 404 [kommando] ERROR Mediafilen hittades inte
95 500 FAILED Internt configurationfel
96 501 [kommando] FAILED Internt configurationfel
97 502 [kommando] FAILED Oläslig mediafil
99 600 [kommando] FAILED funktion ej implementerad
102 namespace caspar { namespace protocol {
104 using namespace core;
106 std::wstring read_utf8_file(const boost::filesystem::wpath& file)
108 std::wstringstream result;
109 boost::filesystem::wifstream filestream(file);
116 result << filestream.rdbuf();
122 std::wstring read_latin1_file(const boost::filesystem::wpath& file)
124 boost::locale::generator gen;
125 gen.locale_cache_enabled(true);
126 gen.categories(boost::locale::codepage_facet);
128 std::stringstream result_stream;
129 boost::filesystem::ifstream filestream(file);
130 filestream.imbue(gen("en_US.ISO8859-1"));
135 result_stream << filestream.rdbuf();
138 std::string result = result_stream.str();
139 std::wstring widened_result;
141 // The first 255 codepoints in unicode is the same as in latin1
142 auto from_signed_to_signed = std::function<unsigned char(char)>(
143 [] (char c) { return static_cast<unsigned char>(c); }
146 result | boost::adaptors::transformed(from_signed_to_signed),
147 std::back_inserter(widened_result));
149 return widened_result;
152 std::wstring read_file(const boost::filesystem::wpath& file)
154 static const uint8_t BOM[] = {0xef, 0xbb, 0xbf};
156 if (!boost::filesystem::exists(file))
161 if (boost::filesystem::file_size(file) >= 3)
163 boost::filesystem::ifstream bom_stream(file);
166 bom_stream.read(header, 3);
169 if (std::memcmp(BOM, header, 3) == 0)
170 return read_utf8_file(file);
173 return read_latin1_file(file);
176 std::wstring MediaInfo(const boost::filesystem::path& path)
178 if(boost::filesystem::is_regular_file(path))
180 std::wstring clipttype = TEXT("N/A");
181 std::wstring extension = boost::to_upper_copy(path.extension().wstring());
182 if(extension == TEXT(".TGA") || extension == TEXT(".COL") || extension == L".PNG" || extension == L".JPEG" || extension == L".JPG" ||
183 extension == L"GIF" || extension == L"BMP")
184 clipttype = TEXT("STILL");
185 else if(extension == TEXT(".WAV") || extension == TEXT(".MP3"))
186 clipttype = TEXT("AUDIO");
187 else if(extension == TEXT("SWF") || extension == TEXT("CT") || extension == TEXT("DV") || extension == TEXT("MOV") || extension == TEXT("MPG") || extension == TEXT("AVI") || caspar::ffmpeg::is_valid_file(path.wstring()))
188 clipttype = TEXT("MOVIE");
190 if(clipttype != TEXT("N/A"))
192 auto is_not_digit = [](char c){ return std::isdigit(c) == 0; };
194 auto relativePath = boost::filesystem::path(path.wstring().substr(env::media_folder().size()-1, path.wstring().size()));
196 auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(path)));
197 writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), is_not_digit), writeTimeStr.end());
198 auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end());
200 auto sizeStr = boost::lexical_cast<std::wstring>(boost::filesystem::file_size(path));
201 sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), is_not_digit), sizeStr.end());
202 auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end());
204 auto str = relativePath.replace_extension(TEXT("")).native();
205 while(str.size() > 0 && (str[0] == '\\' || str[0] == '/'))
206 str = std::wstring(str.begin() + 1, str.end());
208 return std::wstring() + TEXT("\"") + str +
209 + TEXT("\" ") + clipttype +
210 + TEXT(" ") + sizeStr +
211 + TEXT(" ") + writeTimeWStr +
218 std::wstring ListMedia()
220 std::wstringstream replyString;
221 for (boost::filesystem::recursive_directory_iterator itr(env::media_folder()), end; itr != end; ++itr)
222 replyString << MediaInfo(itr->path());
224 return boost::to_upper_copy(replyString.str());
227 std::wstring ListTemplates()
229 std::wstringstream replyString;
231 for (boost::filesystem::recursive_directory_iterator itr(env::template_folder()), end; itr != end; ++itr)
233 if(boost::filesystem::is_regular_file(itr->path()) && (itr->path().extension() == L".ft" || itr->path().extension() == L".ct"))
235 auto relativePath = boost::filesystem::wpath(itr->path().wstring().substr(env::template_folder().size()-1, itr->path().wstring().size()));
237 auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(itr->path())));
238 writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), [](char c){ return std::isdigit(c) == 0;}), writeTimeStr.end());
239 auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end());
241 auto sizeStr = boost::lexical_cast<std::string>(boost::filesystem::file_size(itr->path()));
242 sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), [](char c){ return std::isdigit(c) == 0;}), sizeStr.end());
244 auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end());
246 std::wstring dir = relativePath.parent_path().native();
247 std::wstring file = boost::to_upper_copy(relativePath.filename().wstring());
248 relativePath = boost::filesystem::wpath(dir + L"/" + file);
250 auto str = relativePath.replace_extension(TEXT("")).native();
251 boost::trim_if(str, boost::is_any_of("\\/"));
253 replyString << TEXT("\"") << str
254 << TEXT("\" ") << sizeWStr
255 << TEXT(" ") << writeTimeWStr
259 return replyString.str();
264 AMCPCommand::AMCPCommand() : channelIndex_(0), layerIndex_(-1)
267 void AMCPCommand::SendReply()
272 if(replyString_.empty())
275 pClientInfo_->Send(replyString_);
278 void AMCPCommand::Clear()
280 pChannel_->stage().clear();
281 pClientInfo_.reset();
286 bool DiagnosticsCommand::DoExecute()
290 diagnostics::show_graphs(true);
292 SetReplyString(TEXT("202 DIAG OK\r\n"));
298 CASPAR_LOG_CURRENT_EXCEPTION();
299 SetReplyString(TEXT("502 DIAG FAILED\r\n"));
304 bool ChannelGridCommand::DoExecute()
306 CASPAR_THROW_EXCEPTION(not_implemented());
309 //auto self = GetChannels().back();
311 //std::vector<std::wstring> params;
312 //params.push_back(L"SCREEN");
313 //params.push_back(L"NAME");
314 //params.push_back(L"Channel Grid Window");
315 //auto screen = create_consumer(params);
317 //self->output().add(screen);
319 //BOOST_FOREACH(auto channel, GetChannels())
321 // if(channel != self)
323 // auto producer = reroute::create_producer(self->frame_factory(), *channel);
324 // self->stage().load(index, producer, false);
325 // self->stage().play(index);
330 //int n = GetChannels().size()-1;
331 //double delta = 1.0/static_cast<double>(n);
332 //for(int x = 0; x < n; ++x)
334 // for(int y = 0; y < n; ++y)
336 // int index = x+y*n+1;
337 // auto transform = [=](frame_transform transform) -> frame_transform
339 // transform.image_transform.fill_translation[0] = x*delta;
340 // transform.image_transform.fill_translation[1] = y*delta;
341 // transform.image_transform.fill_scale[0] = delta;
342 // transform.image_transform.fill_scale[1] = delta;
343 // transform.image_transform.clip_translation[0] = x*delta;
344 // transform.image_transform.clip_translation[1] = y*delta;
345 // transform.image_transform.clip_scale[0] = delta;
346 // transform.image_transform.clip_scale[1] = delta;
349 // self->stage().apply_transform(index, transform);
356 bool CallCommand::DoExecute()
358 //Perform loading of the clip
361 //auto what = _parameters.at(0);
362 auto result = GetChannel()->stage().call(GetLayerIndex(), parameters());
364 if(!result.timed_wait(boost::posix_time::seconds(2)))
365 CASPAR_THROW_EXCEPTION(timed_out());
367 std::wstringstream replyString;
368 if(result.get().empty())
369 replyString << TEXT("202 CALL OK\r\n");
371 replyString << TEXT("201 CALL OK\r\n") << result.get() << L"\r\n";
373 SetReplyString(replyString.str());
379 CASPAR_LOG_CURRENT_EXCEPTION();
380 SetReplyString(TEXT("502 CALL FAILED\r\n"));
385 tbb::concurrent_unordered_map<int, std::vector<stage::transform_tuple_t>> deferred_transforms;
387 bool MixerCommand::DoExecute()
389 //Perform loading of the clip
392 bool defer = boost::iequals(parameters().back(), L"DEFER");
394 parameters().pop_back();
396 std::vector<stage::transform_tuple_t> transforms;
398 if(boost::iequals(parameters()[0], L"KEYER") || boost::iequals(parameters()[0], L"IS_KEY"))
400 bool value = boost::lexical_cast<int>(parameters().at(1));
401 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
403 transform.image_transform.is_key = value;
407 else if(boost::iequals(parameters()[0], L"OPACITY"))
409 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
410 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
412 double value = boost::lexical_cast<double>(parameters().at(1));
414 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
416 transform.image_transform.opacity = value;
418 }, duration, tween));
420 else if(boost::iequals(parameters()[0], L"FILL") || boost::iequals(parameters()[0], L"FILL_RECT"))
422 int duration = parameters().size() > 5 ? boost::lexical_cast<int>(parameters()[5]) : 0;
423 std::wstring tween = parameters().size() > 6 ? parameters()[6] : L"linear";
424 double x = boost::lexical_cast<double>(parameters().at(1));
425 double y = boost::lexical_cast<double>(parameters().at(2));
426 double x_s = boost::lexical_cast<double>(parameters().at(3));
427 double y_s = boost::lexical_cast<double>(parameters().at(4));
429 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) mutable -> frame_transform
431 transform.image_transform.fill_translation[0] = x;
432 transform.image_transform.fill_translation[1] = y;
433 transform.image_transform.fill_scale[0] = x_s;
434 transform.image_transform.fill_scale[1] = y_s;
436 }, duration, tween));
438 else if(boost::iequals(parameters()[0], L"CLIP") || boost::iequals(parameters()[0], L"CLIP_RECT"))
440 int duration = parameters().size() > 5 ? boost::lexical_cast<int>(parameters()[5]) : 0;
441 std::wstring tween = parameters().size() > 6 ? parameters()[6] : L"linear";
442 double x = boost::lexical_cast<double>(parameters().at(1));
443 double y = boost::lexical_cast<double>(parameters().at(2));
444 double x_s = boost::lexical_cast<double>(parameters().at(3));
445 double y_s = boost::lexical_cast<double>(parameters().at(4));
447 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
449 transform.image_transform.clip_translation[0] = x;
450 transform.image_transform.clip_translation[1] = y;
451 transform.image_transform.clip_scale[0] = x_s;
452 transform.image_transform.clip_scale[1] = y_s;
454 }, duration, tween));
456 else if(boost::iequals(parameters()[0], L"GRID"))
458 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
459 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
460 int n = boost::lexical_cast<int>(parameters().at(1));
461 double delta = 1.0/static_cast<double>(n);
462 for(int x = 0; x < n; ++x)
464 for(int y = 0; y < n; ++y)
467 transforms.push_back(stage::transform_tuple_t(index, [=](frame_transform transform) -> frame_transform
469 transform.image_transform.fill_translation[0] = x*delta;
470 transform.image_transform.fill_translation[1] = y*delta;
471 transform.image_transform.fill_scale[0] = delta;
472 transform.image_transform.fill_scale[1] = delta;
473 transform.image_transform.clip_translation[0] = x*delta;
474 transform.image_transform.clip_translation[1] = y*delta;
475 transform.image_transform.clip_scale[0] = delta;
476 transform.image_transform.clip_scale[1] = delta;
478 }, duration, tween));
482 else if(boost::iequals(parameters()[0], L"BLEND"))
484 auto blend_str = parameters().at(1);
485 int layer = GetLayerIndex();
486 GetChannel()->mixer().set_blend_mode(GetLayerIndex(), get_blend_mode(blend_str));
488 else if(boost::iequals(parameters()[0], L"MASTERVOLUME"))
490 float master_volume = boost::lexical_cast<float>(parameters().at(1));
491 GetChannel()->mixer().set_master_volume(master_volume);
493 else if(boost::iequals(parameters()[0], L"BRIGHTNESS"))
495 auto value = boost::lexical_cast<double>(parameters().at(1));
496 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
497 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
498 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
500 transform.image_transform.brightness = value;
502 }, duration, tween));
504 else if(boost::iequals(parameters()[0], L"SATURATION"))
506 auto value = boost::lexical_cast<double>(parameters().at(1));
507 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
508 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
509 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
511 transform.image_transform.saturation = value;
513 }, duration, tween));
515 else if(parameters()[0] == L"CONTRAST")
517 auto value = boost::lexical_cast<double>(parameters().at(1));
518 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
519 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
520 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
522 transform.image_transform.contrast = value;
524 }, duration, tween));
526 else if(boost::iequals(parameters()[0], L"LEVELS"))
529 value.min_input = boost::lexical_cast<double>(parameters().at(1));
530 value.max_input = boost::lexical_cast<double>(parameters().at(2));
531 value.gamma = boost::lexical_cast<double>(parameters().at(3));
532 value.min_output = boost::lexical_cast<double>(parameters().at(4));
533 value.max_output = boost::lexical_cast<double>(parameters().at(5));
534 int duration = parameters().size() > 6 ? boost::lexical_cast<int>(parameters()[6]) : 0;
535 std::wstring tween = parameters().size() > 7 ? parameters()[7] : L"linear";
537 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
539 transform.image_transform.levels = value;
541 }, duration, tween));
543 else if(boost::iequals(parameters()[0], L"VOLUME"))
545 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
546 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
547 double value = boost::lexical_cast<double>(parameters()[1]);
549 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
551 transform.audio_transform.volume = value;
553 }, duration, tween));
555 else if(boost::iequals(parameters()[0], L"CLEAR"))
557 int layer = GetLayerIndex(std::numeric_limits<int>::max());
559 if (layer == std::numeric_limits<int>::max())
561 GetChannel()->stage().clear_transforms();
562 GetChannel()->mixer().clear_blend_modes();
566 GetChannel()->stage().clear_transforms(layer);
567 GetChannel()->mixer().clear_blend_mode(layer);
570 else if(boost::iequals(parameters()[0], L"COMMIT"))
572 transforms = std::move(deferred_transforms[GetChannelIndex()]);
576 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
582 auto& defer_tranforms = deferred_transforms[GetChannelIndex()];
583 defer_tranforms.insert(defer_tranforms.end(), transforms.begin(), transforms.end());
586 GetChannel()->stage().apply_transforms(transforms);
588 SetReplyString(TEXT("202 MIXER OK\r\n"));
592 catch(file_not_found&)
594 CASPAR_LOG_CURRENT_EXCEPTION();
595 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
600 CASPAR_LOG_CURRENT_EXCEPTION();
601 SetReplyString(TEXT("502 MIXER FAILED\r\n"));
606 bool SwapCommand::DoExecute()
608 //Perform loading of the clip
611 if(GetLayerIndex(-1) != -1)
613 std::vector<std::string> strs;
614 boost::split(strs, parameters()[0], boost::is_any_of("-"));
616 auto ch1 = GetChannel();
617 auto ch2 = GetChannels().at(boost::lexical_cast<int>(strs.at(0))-1);
619 int l1 = GetLayerIndex();
620 int l2 = boost::lexical_cast<int>(strs.at(1));
622 ch1->stage().swap_layer(l1, l2, ch2->stage());
626 auto ch1 = GetChannel();
627 auto ch2 = GetChannels().at(boost::lexical_cast<int>(parameters()[0])-1);
628 ch1->stage().swap_layers(ch2->stage());
631 SetReplyString(TEXT("202 SWAP OK\r\n"));
635 catch(file_not_found&)
637 CASPAR_LOG_CURRENT_EXCEPTION();
638 SetReplyString(TEXT("404 SWAP ERROR\r\n"));
643 CASPAR_LOG_CURRENT_EXCEPTION();
644 SetReplyString(TEXT("502 SWAP FAILED\r\n"));
649 bool AddCommand::DoExecute()
651 //Perform loading of the clip
654 //create_consumer still expects all parameters to be uppercase
655 BOOST_FOREACH(std::wstring& str, parameters())
657 boost::to_upper(str);
660 auto consumer = create_consumer(parameters());
661 GetChannel()->output().add(GetLayerIndex(consumer->index()), consumer);
663 SetReplyString(TEXT("202 ADD OK\r\n"));
667 catch(file_not_found&)
669 CASPAR_LOG_CURRENT_EXCEPTION();
670 SetReplyString(TEXT("404 ADD ERROR\r\n"));
675 CASPAR_LOG_CURRENT_EXCEPTION();
676 SetReplyString(TEXT("502 ADD FAILED\r\n"));
681 bool RemoveCommand::DoExecute()
683 //Perform loading of the clip
686 auto index = GetLayerIndex(std::numeric_limits<int>::min());
687 if(index == std::numeric_limits<int>::min())
689 //create_consumer still expects all parameters to be uppercase
690 BOOST_FOREACH(std::wstring& str, parameters())
692 boost::to_upper(str);
695 index = create_consumer(parameters())->index();
698 GetChannel()->output().remove(index);
700 SetReplyString(TEXT("202 REMOVE OK\r\n"));
704 catch(file_not_found&)
706 CASPAR_LOG_CURRENT_EXCEPTION();
707 SetReplyString(TEXT("404 REMOVE ERROR\r\n"));
712 CASPAR_LOG_CURRENT_EXCEPTION();
713 SetReplyString(TEXT("502 REMOVE FAILED\r\n"));
718 bool LoadCommand::DoExecute()
720 //Perform loading of the clip
723 //create_producer still expects all parameters to be uppercase
724 BOOST_FOREACH(std::wstring& str, parameters())
726 boost::to_upper(str);
729 auto pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), parameters());
730 GetChannel()->stage().load(GetLayerIndex(), pFP, true);
732 SetReplyString(TEXT("202 LOAD OK\r\n"));
736 catch(file_not_found&)
738 CASPAR_LOG_CURRENT_EXCEPTION();
739 SetReplyString(TEXT("404 LOAD ERROR\r\n"));
744 CASPAR_LOG_CURRENT_EXCEPTION();
745 SetReplyString(TEXT("502 LOAD FAILED\r\n"));
752 //std::function<std::wstring()> channel_cg_add_command::parse(const std::wstring& message, const std::vector<renderer::render_device_ptr>& channels)
754 // static boost::wregex expr(L"^CG\\s(?<video_channel>\\d+)-?(?<LAYER>\\d+)?\\sADD\\s(?<FLASH_LAYER>\\d+)\\s(?<TEMPLATE>\\S+)\\s?(?<START_LABEL>\\S\\S+)?\\s?(?<PLAY_ON_LOAD>\\d)?\\s?(?<DATA>.*)?");
756 // boost::wsmatch what;
757 // if(!boost::regex_match(message, what, expr))
760 // auto info = channel_info::parse(what, channels);
762 // int flash_layer_index = boost::lexical_cast<int>(what["FLASH_LAYER"].str());
764 // std::wstring templatename = what["TEMPLATE"].str();
765 // bool play_on_load = what["PLAY_ON_LOAD"].matched ? what["PLAY_ON_LOAD"].str() != L"0" : 0;
766 // std::wstring start_label = what["START_LABEL"].str();
767 // std::wstring data = get_data(what["DATA"].str());
769 // boost::replace_all(templatename, "\"", "");
771 // return [=]() -> std::wstring
773 // std::wstring fullFilename = flash::flash_producer::find_template(server::template_folder() + templatename);
774 // if(fullFilename.empty())
775 // CASPAR_THROW_EXCEPTION(file_not_found());
777 // std::wstring extension = boost::filesystem::wpath(fullFilename).extension();
778 // std::wstring filename = templatename;
779 // filename.append(extension);
781 // flash::flash::create_cg_proxy(info.video_channel, std::max<int>(DEFAULT_CHANNEL_LAYER+1, info.layer_index))
782 // ->add(flash_layer_index, filename, play_on_load, start_label, data);
784 // CASPAR_LOG(info) << L"Executed [amcp_channel_cg_add]";
788 bool LoadbgCommand::DoExecute()
790 transition_info transitionInfo;
796 std::wstring message;
797 for(size_t n = 0; n < parameters().size(); ++n)
798 message += boost::to_upper_copy(parameters()[n]) + L" ";
800 static const boost::wregex expr(L".*(?<TRANSITION>CUT|PUSH|SLIDE|WIPE|MIX)\\s*(?<DURATION>\\d+)\\s*(?<TWEEN>(LINEAR)|(EASE[^\\s]*))?\\s*(?<DIRECTION>FROMLEFT|FROMRIGHT|LEFT|RIGHT)?.*");
802 if(boost::regex_match(message, what, expr))
804 auto transition = what["TRANSITION"].str();
805 transitionInfo.duration = boost::lexical_cast<size_t>(what["DURATION"].str());
806 auto direction = what["DIRECTION"].matched ? what["DIRECTION"].str() : L"";
807 auto tween = what["TWEEN"].matched ? what["TWEEN"].str() : L"";
808 transitionInfo.tweener = tween;
810 if(transition == TEXT("CUT"))
811 transitionInfo.type = transition_type::cut;
812 else if(transition == TEXT("MIX"))
813 transitionInfo.type = transition_type::mix;
814 else if(transition == TEXT("PUSH"))
815 transitionInfo.type = transition_type::push;
816 else if(transition == TEXT("SLIDE"))
817 transitionInfo.type = transition_type::slide;
818 else if(transition == TEXT("WIPE"))
819 transitionInfo.type = transition_type::wipe;
821 if(direction == TEXT("FROMLEFT"))
822 transitionInfo.direction = transition_direction::from_left;
823 else if(direction == TEXT("FROMRIGHT"))
824 transitionInfo.direction = transition_direction::from_right;
825 else if(direction == TEXT("LEFT"))
826 transitionInfo.direction = transition_direction::from_right;
827 else if(direction == TEXT("RIGHT"))
828 transitionInfo.direction = transition_direction::from_left;
831 //Perform loading of the clip
834 std::shared_ptr<core::frame_producer> pFP;
836 static boost::wregex expr(L"\\[(?<CHANNEL>\\d+)\\]", boost::regex::icase);
839 if(boost::regex_match(parameters().at(0), what, expr))
841 auto channel_index = boost::lexical_cast<int>(what["CHANNEL"].str());
842 pFP = reroute::create_producer(*GetChannels().at(channel_index-1));
846 //create_producer still expects all parameters to be uppercase
847 BOOST_FOREACH(std::wstring& str, parameters())
849 boost::to_upper(str);
851 pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), parameters());
854 if(pFP == frame_producer::empty())
855 CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(parameters().size() > 0 ? parameters()[0] : L""));
857 bool auto_play = std::find_if(parameters().begin(), parameters().end(), [](const std::wstring& p) { return boost::iequals(p, L"AUTO"); }) != parameters().end();
859 auto pFP2 = create_transition_producer(GetChannel()->video_format_desc().field_mode, spl::make_shared_ptr(pFP), transitionInfo);
861 GetChannel()->stage().load(GetLayerIndex(), pFP2, false, transitionInfo.duration); // TODO: LOOP
863 GetChannel()->stage().load(GetLayerIndex(), pFP2, false); // TODO: LOOP
866 SetReplyString(TEXT("202 LOADBG OK\r\n"));
870 catch(file_not_found&)
872 CASPAR_LOG(error) << L"File not found. No match found for parameters. Check syntax.";
873 SetReplyString(TEXT("404 LOADBG ERROR\r\n"));
878 CASPAR_LOG_CURRENT_EXCEPTION();
879 SetReplyString(TEXT("502 LOADBG FAILED\r\n"));
884 bool PauseCommand::DoExecute()
888 GetChannel()->stage().pause(GetLayerIndex());
889 SetReplyString(TEXT("202 PAUSE OK\r\n"));
894 SetReplyString(TEXT("501 PAUSE FAILED\r\n"));
900 bool PlayCommand::DoExecute()
904 if(!parameters().empty())
907 lbg.SetChannel(GetChannel());
908 lbg.SetChannels(GetChannels());
909 lbg.SetChannelIndex(GetChannelIndex());
910 lbg.SetLayerIntex(GetLayerIndex());
911 lbg.SetClientInfo(GetClientInfo());
912 for(auto it = parameters().begin(); it != parameters().end(); ++it)
913 lbg.AddParameter(*it);
915 throw std::exception();
918 GetChannel()->stage().play(GetLayerIndex());
920 SetReplyString(TEXT("202 PLAY OK\r\n"));
925 SetReplyString(TEXT("501 PLAY FAILED\r\n"));
931 bool StopCommand::DoExecute()
935 GetChannel()->stage().stop(GetLayerIndex());
936 SetReplyString(TEXT("202 STOP OK\r\n"));
941 SetReplyString(TEXT("501 STOP FAILED\r\n"));
947 bool ClearCommand::DoExecute()
949 int index = GetLayerIndex(std::numeric_limits<int>::min());
950 if(index != std::numeric_limits<int>::min())
951 GetChannel()->stage().clear(index);
953 GetChannel()->stage().clear();
955 SetReplyString(TEXT("202 CLEAR OK\r\n"));
960 bool PrintCommand::DoExecute()
962 GetChannel()->output().add(create_consumer(boost::assign::list_of(L"IMAGE")));
964 SetReplyString(TEXT("202 PRINT OK\r\n"));
969 bool LogCommand::DoExecute()
971 if(boost::iequals(parameters().at(0), L"LEVEL"))
972 log::set_log_level(parameters().at(1));
974 SetReplyString(TEXT("202 LOG OK\r\n"));
979 bool CGCommand::DoExecute()
983 std::wstring command = boost::to_upper_copy(parameters()[0]);
984 if(command == TEXT("ADD"))
985 return DoExecuteAdd();
986 else if(command == TEXT("PLAY"))
987 return DoExecutePlay();
988 else if(command == TEXT("STOP"))
989 return DoExecuteStop();
990 else if(command == TEXT("NEXT"))
991 return DoExecuteNext();
992 else if(command == TEXT("REMOVE"))
993 return DoExecuteRemove();
994 else if(command == TEXT("CLEAR"))
995 return DoExecuteClear();
996 else if(command == TEXT("UPDATE"))
997 return DoExecuteUpdate();
998 else if(command == TEXT("INVOKE"))
999 return DoExecuteInvoke();
1000 else if(command == TEXT("INFO"))
1001 return DoExecuteInfo();
1005 CASPAR_LOG_CURRENT_EXCEPTION();
1008 SetReplyString(TEXT("403 CG ERROR\r\n"));
1012 bool CGCommand::ValidateLayer(const std::wstring& layerstring) {
1013 int length = layerstring.length();
1014 for(int i = 0; i < length; ++i) {
1015 if(!_istdigit(layerstring[i])) {
1023 bool CGCommand::DoExecuteAdd() {
1024 //CG 1 ADD 0 "template_folder/templatename" [STARTLABEL] 0/1 [DATA]
1026 int layer = 0; //_parameters[1]
1027 // std::wstring templateName; //_parameters[2]
1028 std::wstring label; //_parameters[3]
1029 bool bDoStart = false; //_parameters[3] alt. _parameters[4]
1030 // std::wstring data; //_parameters[4] alt. _parameters[5]
1032 if(parameters().size() < 4)
1034 SetReplyString(TEXT("402 CG ERROR\r\n"));
1037 unsigned int dataIndex = 4;
1039 if(!ValidateLayer(parameters()[1]))
1041 SetReplyString(TEXT("403 CG ERROR\r\n"));
1045 layer = boost::lexical_cast<int>(parameters()[1]);
1047 if(parameters()[3].length() > 1)
1049 label = parameters()[3];
1052 if(parameters().size() > 4 && parameters()[4].length() > 0) //read play-on-load-flag
1053 bDoStart = (parameters()[4][0]==TEXT('1')) ? true : false;
1056 SetReplyString(TEXT("402 CG ERROR\r\n"));
1060 else if(parameters()[3].length() > 0) { //read play-on-load-flag
1061 bDoStart = (parameters()[3][0]==TEXT('1')) ? true : false;
1065 SetReplyString(TEXT("403 CG ERROR\r\n"));
1069 const TCHAR* pDataString = 0;
1070 std::wstringstream data;
1071 std::wstring dataFromFile;
1072 if(parameters().size() > dataIndex)
1074 const std::wstring& dataString = parameters()[dataIndex];
1076 if(dataString[0] == TEXT('<')) //the data is an XML-string
1077 pDataString = dataString.c_str();
1080 //The data is not an XML-string, it must be a filename
1081 std::wstring filename = env::data_folder();
1082 filename.append(dataString);
1083 filename.append(TEXT(".ftd"));
1085 dataFromFile = read_file(boost::filesystem::wpath(filename));
1086 pDataString = dataFromFile.c_str();
1090 std::wstring fullFilename = flash::find_template(env::template_folder() + parameters()[2]);
1091 if(!fullFilename.empty())
1093 std::wstring extension = boost::filesystem::path(fullFilename).extension().wstring();
1094 std::wstring filename = parameters()[2];
1095 filename.append(extension);
1097 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).add(layer, filename, bDoStart, label, (pDataString!=0) ? pDataString : TEXT(""));
1098 SetReplyString(TEXT("202 CG OK\r\n"));
1102 CASPAR_LOG(warning) << "Could not find template " << parameters()[2];
1103 SetReplyString(TEXT("404 CG ERROR\r\n"));
1108 bool CGCommand::DoExecutePlay()
1110 if(parameters().size() > 1)
1112 if(!ValidateLayer(parameters()[1]))
1114 SetReplyString(TEXT("403 CG ERROR\r\n"));
1117 int layer = boost::lexical_cast<int>(parameters()[1]);
1118 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).play(layer);
1122 SetReplyString(TEXT("402 CG ERROR\r\n"));
1126 SetReplyString(TEXT("202 CG OK\r\n"));
1130 bool CGCommand::DoExecuteStop()
1132 if(parameters().size() > 1)
1134 if(!ValidateLayer(parameters()[1]))
1136 SetReplyString(TEXT("403 CG ERROR\r\n"));
1139 int layer = boost::lexical_cast<int>(parameters()[1]);
1140 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).stop(layer, 0);
1144 SetReplyString(TEXT("402 CG ERROR\r\n"));
1148 SetReplyString(TEXT("202 CG OK\r\n"));
1152 bool CGCommand::DoExecuteNext()
1154 if(parameters().size() > 1)
1156 if(!ValidateLayer(parameters()[1]))
1158 SetReplyString(TEXT("403 CG ERROR\r\n"));
1162 int layer = boost::lexical_cast<int>(parameters()[1]);
1163 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).next(layer);
1167 SetReplyString(TEXT("402 CG ERROR\r\n"));
1171 SetReplyString(TEXT("202 CG OK\r\n"));
1175 bool CGCommand::DoExecuteRemove()
1177 if(parameters().size() > 1)
1179 if(!ValidateLayer(parameters()[1]))
1181 SetReplyString(TEXT("403 CG ERROR\r\n"));
1185 int layer = boost::lexical_cast<int>(parameters()[1]);
1186 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).remove(layer);
1190 SetReplyString(TEXT("402 CG ERROR\r\n"));
1194 SetReplyString(TEXT("202 CG OK\r\n"));
1198 bool CGCommand::DoExecuteClear()
1200 GetChannel()->stage().clear(GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER));
1201 SetReplyString(TEXT("202 CG OK\r\n"));
1205 bool CGCommand::DoExecuteUpdate()
1209 if(!ValidateLayer(parameters().at(1)))
1211 SetReplyString(TEXT("403 CG ERROR\r\n"));
1215 std::wstring dataString = parameters().at(2);
1216 if(dataString.at(0) != TEXT('<'))
1218 //The data is not an XML-string, it must be a filename
1219 std::wstring filename = env::data_folder();
1220 filename.append(dataString);
1221 filename.append(TEXT(".ftd"));
1223 dataString = read_file(boost::filesystem::wpath(filename));
1226 int layer = boost::lexical_cast<int>(parameters()[1]);
1227 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).update(layer, dataString);
1231 SetReplyString(TEXT("402 CG ERROR\r\n"));
1235 SetReplyString(TEXT("202 CG OK\r\n"));
1239 bool CGCommand::DoExecuteInvoke()
1241 std::wstringstream replyString;
1242 replyString << TEXT("201 CG OK\r\n");
1244 if(parameters().size() > 2)
1246 if(!ValidateLayer(parameters()[1]))
1248 SetReplyString(TEXT("403 CG ERROR\r\n"));
1251 int layer = boost::lexical_cast<int>(parameters()[1]);
1252 auto result = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).invoke(layer, parameters()[2]);
1253 replyString << result << TEXT("\r\n");
1257 SetReplyString(TEXT("402 CG ERROR\r\n"));
1261 SetReplyString(replyString.str());
1265 bool CGCommand::DoExecuteInfo()
1267 std::wstringstream replyString;
1268 replyString << TEXT("201 CG OK\r\n");
1270 if(parameters().size() > 1)
1272 if(!ValidateLayer(parameters()[1]))
1274 SetReplyString(TEXT("403 CG ERROR\r\n"));
1278 int layer = boost::lexical_cast<int>(parameters()[1]);
1279 auto desc = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).description(layer);
1281 replyString << desc << TEXT("\r\n");
1285 auto info = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).template_host_info();
1286 replyString << info << TEXT("\r\n");
1289 SetReplyString(replyString.str());
1293 bool DataCommand::DoExecute()
1295 std::wstring command = boost::to_upper_copy(parameters()[0]);
1296 if(command == TEXT("STORE"))
1297 return DoExecuteStore();
1298 else if(command == TEXT("RETRIEVE"))
1299 return DoExecuteRetrieve();
1300 else if(command == TEXT("REMOVE"))
1301 return DoExecuteRemove();
1302 else if(command == TEXT("LIST"))
1303 return DoExecuteList();
1305 SetReplyString(TEXT("403 DATA ERROR\r\n"));
1309 bool DataCommand::DoExecuteStore()
1311 if(parameters().size() < 3)
1313 SetReplyString(TEXT("402 DATA STORE ERROR\r\n"));
1317 std::wstring filename = env::data_folder();
1318 filename.append(parameters()[1]);
1319 filename.append(TEXT(".ftd"));
1321 auto data_path = boost::filesystem::wpath(
1322 boost::filesystem::wpath(filename).parent_path());
1324 if(!boost::filesystem::exists(data_path))
1325 boost::filesystem::create_directories(data_path);
1327 std::wofstream datafile(filename.c_str());
1330 SetReplyString(TEXT("501 DATA STORE FAILED\r\n"));
1334 datafile << static_cast<wchar_t>(65279); // UTF-8 BOM character
1335 datafile << parameters()[2] << std::flush;
1338 std::wstring replyString = TEXT("202 DATA STORE OK\r\n");
1339 SetReplyString(replyString);
1343 bool DataCommand::DoExecuteRetrieve()
1345 if(parameters().size() < 2)
1347 SetReplyString(TEXT("402 DATA RETRIEVE ERROR\r\n"));
1351 std::wstring filename = env::data_folder();
1352 filename.append(parameters()[1]);
1353 filename.append(TEXT(".ftd"));
1355 std::wstring file_contents = read_file(boost::filesystem::wpath(filename));
1357 if (file_contents.empty())
1359 SetReplyString(TEXT("404 DATA RETRIEVE ERROR\r\n"));
1363 std::wstringstream reply(TEXT("201 DATA RETRIEVE OK\r\n"));
1365 reply << file_contents;
1367 SetReplyString(reply.str());
1371 bool DataCommand::DoExecuteRemove()
1373 if (parameters().size() < 2)
1375 SetReplyString(TEXT("402 DATA REMOVE ERROR\r\n"));
1379 std::wstring filename = env::data_folder();
1380 filename.append(parameters()[1]);
1381 filename.append(TEXT(".ftd"));
1383 if (!boost::filesystem::exists(filename))
1385 SetReplyString(TEXT("404 DATA REMOVE ERROR\r\n"));
1389 if (!boost::filesystem::remove(filename))
1391 SetReplyString(TEXT("403 DATA REMOVE ERROR\r\n"));
1395 SetReplyString(TEXT("201 DATA REMOVE OK\r\n"));
1400 bool DataCommand::DoExecuteList()
1402 std::wstringstream replyString;
1403 replyString << TEXT("200 DATA LIST OK\r\n");
1405 for (boost::filesystem::recursive_directory_iterator itr(env::data_folder()), end; itr != end; ++itr)
1407 if(boost::filesystem::is_regular_file(itr->path()))
1409 if(!boost::iequals(itr->path().extension().wstring(), L".ftd"))
1412 auto relativePath = boost::filesystem::wpath(itr->path().wstring().substr(env::data_folder().size()-1, itr->path().wstring().size()));
1414 auto str = relativePath.replace_extension(TEXT("")).native();
1415 if(str[0] == '\\' || str[0] == '/')
1416 str = std::wstring(str.begin() + 1, str.end());
1418 replyString << str << TEXT("\r\n");
1422 replyString << TEXT("\r\n");
1424 SetReplyString(boost::to_upper_copy(replyString.str()));
1428 bool CinfCommand::DoExecute()
1430 std::wstringstream replyString;
1435 for (boost::filesystem::recursive_directory_iterator itr(env::media_folder()), end; itr != end && info.empty(); ++itr)
1437 auto path = itr->path();
1438 auto file = path.replace_extension(L"").filename();
1439 if(boost::iequals(file.wstring(), parameters().at(0)))
1440 info += MediaInfo(itr->path()) + L"\r\n";
1445 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1448 replyString << TEXT("200 CINF OK\r\n");
1449 replyString << info << "\r\n";
1453 CASPAR_LOG_CURRENT_EXCEPTION();
1454 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1458 SetReplyString(replyString.str());
1462 void GenerateChannelInfo(int index, const spl::shared_ptr<core::video_channel>& pChannel, std::wstringstream& replyString)
1464 replyString << index+1 << TEXT(" ") << pChannel->video_format_desc().name << TEXT(" PLAYING") << TEXT("\r\n");
1467 bool InfoCommand::DoExecute()
1469 std::wstringstream replyString;
1471 boost::property_tree::xml_writer_settings<wchar_t> w(' ', 3);
1475 if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"TEMPLATE"))
1477 replyString << L"201 INFO TEMPLATE OK\r\n";
1479 // Needs to be extended for any file, not just flash.
1481 auto filename = flash::find_template(env::template_folder() + parameters().at(1));
1483 std::wstringstream str;
1484 str << u16(flash::read_template_meta_info(filename));
1485 boost::property_tree::wptree info;
1486 boost::property_tree::xml_parser::read_xml(str, info, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
1488 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1490 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"CONFIG"))
1492 replyString << L"201 INFO CONFIG OK\r\n";
1494 boost::property_tree::write_xml(replyString, caspar::env::properties(), w);
1496 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"PATHS"))
1498 replyString << L"201 INFO PATHS OK\r\n";
1500 boost::property_tree::wptree info;
1501 info.add_child(L"paths", caspar::env::properties().get_child(L"configuration.paths"));
1502 info.add(L"paths.initial-path", boost::filesystem3::initial_path().wstring() + L"\\");
1504 boost::property_tree::write_xml(replyString, info, w);
1506 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"SYSTEM"))
1508 replyString << L"201 INFO SYSTEM OK\r\n";
1510 boost::property_tree::wptree info;
1512 info.add(L"system.name", caspar::system_product_name());
1513 info.add(L"system.windows.name", caspar::win_product_name());
1514 info.add(L"system.windows.service-pack", caspar::win_sp_version());
1515 info.add(L"system.cpu", caspar::cpu_info());
1517 BOOST_FOREACH(auto device, caspar::decklink::device_list())
1518 info.add(L"system.decklink.device", device);
1520 BOOST_FOREACH(auto device, caspar::bluefish::device_list())
1521 info.add(L"system.bluefish.device", device);
1523 info.add(L"system.flash", caspar::flash::version());
1524 //info.add(L"system.free-image", caspar::image::version());
1525 info.add(L"system.ffmpeg.avcodec", caspar::ffmpeg::avcodec_version());
1526 info.add(L"system.ffmpeg.avformat", caspar::ffmpeg::avformat_version());
1527 info.add(L"system.ffmpeg.avfilter", caspar::ffmpeg::avfilter_version());
1528 info.add(L"system.ffmpeg.avutil", caspar::ffmpeg::avutil_version());
1529 info.add(L"system.ffmpeg.swscale", caspar::ffmpeg::swscale_version());
1531 boost::property_tree::write_xml(replyString, info, w);
1533 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"SERVER"))
1535 replyString << L"201 INFO SERVER OK\r\n";
1537 boost::property_tree::wptree info;
1540 BOOST_FOREACH(auto channel, channels_)
1541 info.add_child(L"channels.channel", channel->info())
1542 .add(L"index", ++index);
1544 boost::property_tree::write_xml(replyString, info, w);
1548 if(parameters().size() >= 1)
1550 replyString << TEXT("201 INFO OK\r\n");
1551 boost::property_tree::wptree info;
1553 std::vector<std::wstring> split;
1554 boost::split(split, parameters()[0], boost::is_any_of("-"));
1556 int layer = std::numeric_limits<int>::min();
1557 int channel = boost::lexical_cast<int>(split[0]) - 1;
1559 if(split.size() > 1)
1560 layer = boost::lexical_cast<int>(split[1]);
1562 if(layer == std::numeric_limits<int>::min())
1564 info.add_child(L"channel", channels_.at(channel)->info())
1565 .add(L"index", channel);
1569 if(parameters().size() >= 2)
1571 if(boost::iequals(parameters()[1], L"B"))
1572 info.add_child(L"producer", channels_.at(channel)->stage().background(layer).get()->info());
1574 info.add_child(L"producer", channels_.at(channel)->stage().foreground(layer).get()->info());
1578 info.add_child(L"layer", channels_.at(channel)->stage().info(layer).get())
1579 .add(L"index", layer);
1582 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1586 // This is needed for backwards compatibility with old clients
1587 replyString << TEXT("200 INFO OK\r\n");
1588 for(size_t n = 0; n < channels_.size(); ++n)
1589 GenerateChannelInfo(n, channels_[n], replyString);
1596 CASPAR_LOG_CURRENT_EXCEPTION();
1597 SetReplyString(TEXT("403 INFO ERROR\r\n"));
1601 replyString << TEXT("\r\n");
1602 SetReplyString(replyString.str());
1606 bool ClsCommand::DoExecute()
1618 std::wstringstream replyString;
1619 replyString << TEXT("200 CLS OK\r\n");
1620 replyString << ListMedia();
1621 replyString << TEXT("\r\n");
1622 SetReplyString(boost::to_upper_copy(replyString.str()));
1626 CASPAR_LOG_CURRENT_EXCEPTION();
1627 SetReplyString(TEXT("501 CLS FAILED\r\n"));
1634 bool TlsCommand::DoExecute()
1638 std::wstringstream replyString;
1639 replyString << TEXT("200 TLS OK\r\n");
1641 replyString << ListTemplates();
1642 replyString << TEXT("\r\n");
1644 SetReplyString(replyString.str());
1648 CASPAR_LOG_CURRENT_EXCEPTION();
1649 SetReplyString(TEXT("501 TLS FAILED\r\n"));
1655 bool VersionCommand::DoExecute()
1657 std::wstring replyString = TEXT("201 VERSION OK\r\n") + env::version() + TEXT("\r\n");
1659 if(parameters().size() > 0)
1661 if(boost::iequals(parameters()[0], L"FLASH"))
1662 replyString = TEXT("201 VERSION OK\r\n") + flash::version() + TEXT("\r\n");
1663 else if(boost::iequals(parameters()[0], L"TEMPLATEHOST"))
1664 replyString = TEXT("201 VERSION OK\r\n") + flash::cg_version() + TEXT("\r\n");
1665 else if(!boost::iequals(parameters()[0], L"SERVER"))
1666 replyString = TEXT("403 VERSION ERROR\r\n");
1669 SetReplyString(replyString);
1673 bool ByeCommand::DoExecute()
1675 GetClientInfo()->Disconnect();
1679 bool SetCommand::DoExecute()
1683 std::wstring name = boost::to_upper_copy(parameters()[0]);
1684 std::wstring value = boost::to_upper_copy(parameters()[1]);
1686 if(name == TEXT("MODE"))
1688 auto format_desc = core::video_format_desc(value);
1689 if(format_desc.format != core::video_format::invalid)
1691 GetChannel()->video_format_desc(format_desc);
1692 SetReplyString(TEXT("202 SET MODE OK\r\n"));
1695 SetReplyString(TEXT("501 SET MODE FAILED\r\n"));
1699 this->SetReplyString(TEXT("403 SET ERROR\r\n"));
1704 CASPAR_LOG_CURRENT_EXCEPTION();
1705 SetReplyString(TEXT("501 SET FAILED\r\n"));
1714 }} //namespace caspar