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())
274 pClientInfo_->Send(replyString_);
277 void AMCPCommand::Clear()
279 pChannel_->stage().clear();
280 pClientInfo_.reset();
285 bool DiagnosticsCommand::DoExecute()
289 diagnostics::show_graphs(true);
291 SetReplyString(TEXT("202 DIAG OK\r\n"));
297 CASPAR_LOG_CURRENT_EXCEPTION();
298 SetReplyString(TEXT("502 DIAG FAILED\r\n"));
303 bool ChannelGridCommand::DoExecute()
305 CASPAR_THROW_EXCEPTION(not_implemented());
308 //auto self = GetChannels().back();
310 //std::vector<std::wstring> params;
311 //params.push_back(L"SCREEN");
312 //params.push_back(L"NAME");
313 //params.push_back(L"Channel Grid Window");
314 //auto screen = create_consumer(params);
316 //self->output().add(screen);
318 //BOOST_FOREACH(auto channel, GetChannels())
320 // if(channel != self)
322 // auto producer = reroute::create_producer(self->frame_factory(), *channel);
323 // self->stage().load(index, producer, false);
324 // self->stage().play(index);
329 //int n = GetChannels().size()-1;
330 //double delta = 1.0/static_cast<double>(n);
331 //for(int x = 0; x < n; ++x)
333 // for(int y = 0; y < n; ++y)
335 // int index = x+y*n+1;
336 // auto transform = [=](frame_transform transform) -> frame_transform
338 // transform.image_transform.fill_translation[0] = x*delta;
339 // transform.image_transform.fill_translation[1] = y*delta;
340 // transform.image_transform.fill_scale[0] = delta;
341 // transform.image_transform.fill_scale[1] = delta;
342 // transform.image_transform.clip_translation[0] = x*delta;
343 // transform.image_transform.clip_translation[1] = y*delta;
344 // transform.image_transform.clip_scale[0] = delta;
345 // transform.image_transform.clip_scale[1] = delta;
348 // self->stage().apply_transform(index, transform);
355 bool CallCommand::DoExecute()
357 //Perform loading of the clip
360 auto what = _parameters.at(0);
363 for(auto it = std::begin(_parameters2); it != std::end(_parameters2); ++it, param += L" ")
366 auto result = GetChannel()->stage().call(GetLayerIndex(), boost::trim_copy(param));
368 if(!result.timed_wait(boost::posix_time::seconds(2)))
369 CASPAR_THROW_EXCEPTION(timed_out());
371 std::wstringstream replyString;
372 if(result.get().empty())
373 replyString << TEXT("202 CALL OK\r\n");
375 replyString << TEXT("201 CALL OK\r\n") << result.get() << L"\r\n";
377 SetReplyString(replyString.str());
383 CASPAR_LOG_CURRENT_EXCEPTION();
384 SetReplyString(TEXT("502 CALL FAILED\r\n"));
389 tbb::concurrent_unordered_map<int, std::vector<stage::transform_tuple_t>> deferred_transforms;
391 bool MixerCommand::DoExecute()
393 //Perform loading of the clip
396 bool defer = _parameters.back() == L"DEFER";
398 _parameters.pop_back();
400 std::vector<stage::transform_tuple_t> transforms;
402 if(_parameters[0] == L"KEYER" || _parameters[0] == L"IS_KEY")
404 bool value = boost::lexical_cast<int>(_parameters.at(1));
405 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
407 transform.image_transform.is_key = value;
411 else if(_parameters[0] == L"OPACITY")
413 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
414 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
416 double value = boost::lexical_cast<double>(_parameters.at(1));
418 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
420 transform.image_transform.opacity = value;
422 }, duration, tween));
424 else if(_parameters[0] == L"FILL" || _parameters[0] == L"FILL_RECT")
426 int duration = _parameters.size() > 5 ? boost::lexical_cast<int>(_parameters[5]) : 0;
427 std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear";
428 double x = boost::lexical_cast<double>(_parameters.at(1));
429 double y = boost::lexical_cast<double>(_parameters.at(2));
430 double x_s = boost::lexical_cast<double>(_parameters.at(3));
431 double y_s = boost::lexical_cast<double>(_parameters.at(4));
433 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) mutable -> frame_transform
435 transform.image_transform.fill_translation[0] = x;
436 transform.image_transform.fill_translation[1] = y;
437 transform.image_transform.fill_scale[0] = x_s;
438 transform.image_transform.fill_scale[1] = y_s;
439 transform.image_transform.clip_translation[0] = x;
440 transform.image_transform.clip_translation[1] = y;
441 transform.image_transform.clip_scale[0] = x_s;
442 transform.image_transform.clip_scale[1] = y_s;
444 }, duration, tween));
446 else if(_parameters[0] == L"CLIP" || _parameters[0] == L"CLIP_RECT")
448 int duration = _parameters.size() > 5 ? boost::lexical_cast<int>(_parameters[5]) : 0;
449 std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear";
450 double x = boost::lexical_cast<double>(_parameters.at(1));
451 double y = boost::lexical_cast<double>(_parameters.at(2));
452 double x_s = boost::lexical_cast<double>(_parameters.at(3));
453 double y_s = boost::lexical_cast<double>(_parameters.at(4));
455 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
457 transform.image_transform.clip_translation[0] = x;
458 transform.image_transform.clip_translation[1] = y;
459 transform.image_transform.clip_scale[0] = x_s;
460 transform.image_transform.clip_scale[1] = y_s;
462 }, duration, tween));
464 else if(_parameters[0] == L"GRID")
466 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
467 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
468 int n = boost::lexical_cast<int>(_parameters.at(1));
469 double delta = 1.0/static_cast<double>(n);
470 for(int x = 0; x < n; ++x)
472 for(int y = 0; y < n; ++y)
475 transforms.push_back(stage::transform_tuple_t(index, [=](frame_transform transform) -> frame_transform
477 transform.image_transform.fill_translation[0] = x*delta;
478 transform.image_transform.fill_translation[1] = y*delta;
479 transform.image_transform.fill_scale[0] = delta;
480 transform.image_transform.fill_scale[1] = delta;
481 transform.image_transform.clip_translation[0] = x*delta;
482 transform.image_transform.clip_translation[1] = y*delta;
483 transform.image_transform.clip_scale[0] = delta;
484 transform.image_transform.clip_scale[1] = delta;
486 }, duration, tween));
490 else if(_parameters[0] == L"BLEND")
492 auto blend_str = _parameters.at(1);
493 int layer = GetLayerIndex();
494 GetChannel()->mixer().set_blend_mode(GetLayerIndex(), get_blend_mode(blend_str));
496 else if(_parameters[0] == L"BRIGHTNESS")
498 auto value = boost::lexical_cast<double>(_parameters.at(1));
499 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
500 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
501 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
503 transform.image_transform.brightness = value;
505 }, duration, tween));
507 else if(_parameters[0] == L"SATURATION")
509 auto value = boost::lexical_cast<double>(_parameters.at(1));
510 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
511 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
512 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
514 transform.image_transform.saturation = value;
516 }, duration, tween));
518 else if(_parameters[0] == L"CONTRAST")
520 auto value = boost::lexical_cast<double>(_parameters.at(1));
521 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
522 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
523 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
525 transform.image_transform.contrast = value;
527 }, duration, tween));
529 else if(_parameters[0] == L"LEVELS")
532 value.min_input = boost::lexical_cast<double>(_parameters.at(1));
533 value.max_input = boost::lexical_cast<double>(_parameters.at(2));
534 value.gamma = boost::lexical_cast<double>(_parameters.at(3));
535 value.min_output = boost::lexical_cast<double>(_parameters.at(4));
536 value.max_output = boost::lexical_cast<double>(_parameters.at(5));
537 int duration = _parameters.size() > 6 ? boost::lexical_cast<int>(_parameters[6]) : 0;
538 std::wstring tween = _parameters.size() > 7 ? _parameters[7] : L"linear";
540 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
542 transform.image_transform.levels = value;
544 }, duration, tween));
546 else if(_parameters[0] == L"VOLUME")
548 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
549 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
550 double value = boost::lexical_cast<double>(_parameters[1]);
552 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
554 transform.audio_transform.volume = value;
556 }, duration, tween));
558 else if(_parameters[0] == L"CLEAR")
560 int layer = GetLayerIndex(std::numeric_limits<int>::max());
562 if (layer == std::numeric_limits<int>::max())
564 GetChannel()->stage().clear_transforms();
565 GetChannel()->mixer().clear_blend_modes();
569 GetChannel()->stage().clear_transforms(layer);
570 GetChannel()->mixer().clear_blend_mode(layer);
573 else if(_parameters[0] == L"COMMIT")
575 transforms = std::move(deferred_transforms[GetChannelIndex()]);
579 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
585 auto& defer_tranforms = deferred_transforms[GetChannelIndex()];
586 defer_tranforms.insert(defer_tranforms.end(), transforms.begin(), transforms.end());
589 GetChannel()->stage().apply_transforms(transforms);
591 SetReplyString(TEXT("202 MIXER OK\r\n"));
595 catch(file_not_found&)
597 CASPAR_LOG_CURRENT_EXCEPTION();
598 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
603 CASPAR_LOG_CURRENT_EXCEPTION();
604 SetReplyString(TEXT("502 MIXER FAILED\r\n"));
609 bool SwapCommand::DoExecute()
611 //Perform loading of the clip
614 if(GetLayerIndex(-1) != -1)
616 std::vector<std::string> strs;
617 boost::split(strs, _parameters[0], boost::is_any_of("-"));
619 auto ch1 = GetChannel();
620 auto ch2 = GetChannels().at(boost::lexical_cast<int>(strs.at(0))-1);
622 int l1 = GetLayerIndex();
623 int l2 = boost::lexical_cast<int>(strs.at(1));
625 ch1->stage().swap_layer(l1, l2, ch2->stage());
629 auto ch1 = GetChannel();
630 auto ch2 = GetChannels().at(boost::lexical_cast<int>(_parameters[0])-1);
631 ch1->stage().swap_layers(ch2->stage());
634 SetReplyString(TEXT("202 SWAP OK\r\n"));
638 catch(file_not_found&)
640 CASPAR_LOG_CURRENT_EXCEPTION();
641 SetReplyString(TEXT("404 SWAP ERROR\r\n"));
646 CASPAR_LOG_CURRENT_EXCEPTION();
647 SetReplyString(TEXT("502 SWAP FAILED\r\n"));
652 bool AddCommand::DoExecute()
654 //Perform loading of the clip
657 auto consumer = create_consumer(_parameters);
658 GetChannel()->output().add(GetLayerIndex(consumer->index()), consumer);
660 SetReplyString(TEXT("202 ADD OK\r\n"));
664 catch(file_not_found&)
666 CASPAR_LOG_CURRENT_EXCEPTION();
667 SetReplyString(TEXT("404 ADD ERROR\r\n"));
672 CASPAR_LOG_CURRENT_EXCEPTION();
673 SetReplyString(TEXT("502 ADD FAILED\r\n"));
678 bool RemoveCommand::DoExecute()
680 //Perform loading of the clip
683 auto index = GetLayerIndex(std::numeric_limits<int>::min());
684 if(index == std::numeric_limits<int>::min())
685 index = create_consumer(_parameters)->index();
687 GetChannel()->output().remove(index);
689 SetReplyString(TEXT("202 REMOVE OK\r\n"));
693 catch(file_not_found&)
695 CASPAR_LOG_CURRENT_EXCEPTION();
696 SetReplyString(TEXT("404 REMOVE ERROR\r\n"));
701 CASPAR_LOG_CURRENT_EXCEPTION();
702 SetReplyString(TEXT("502 REMOVE FAILED\r\n"));
707 bool LoadCommand::DoExecute()
709 //Perform loading of the clip
712 _parameters[0] = _parameters[0];
713 auto pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), _parameters);
714 GetChannel()->stage().load(GetLayerIndex(), pFP, true);
716 SetReplyString(TEXT("202 LOAD OK\r\n"));
720 catch(file_not_found&)
722 CASPAR_LOG_CURRENT_EXCEPTION();
723 SetReplyString(TEXT("404 LOAD ERROR\r\n"));
728 CASPAR_LOG_CURRENT_EXCEPTION();
729 SetReplyString(TEXT("502 LOAD FAILED\r\n"));
736 //std::function<std::wstring()> channel_cg_add_command::parse(const std::wstring& message, const std::vector<renderer::render_device_ptr>& channels)
738 // 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>.*)?");
740 // boost::wsmatch what;
741 // if(!boost::regex_match(message, what, expr))
744 // auto info = channel_info::parse(what, channels);
746 // int flash_layer_index = boost::lexical_cast<int>(what["FLASH_LAYER"].str());
748 // std::wstring templatename = what["TEMPLATE"].str();
749 // bool play_on_load = what["PLAY_ON_LOAD"].matched ? what["PLAY_ON_LOAD"].str() != L"0" : 0;
750 // std::wstring start_label = what["START_LABEL"].str();
751 // std::wstring data = get_data(what["DATA"].str());
753 // boost::replace_all(templatename, "\"", "");
755 // return [=]() -> std::wstring
757 // std::wstring fullFilename = flash::flash_producer::find_template(server::template_folder() + templatename);
758 // if(fullFilename.empty())
759 // CASPAR_THROW_EXCEPTION(file_not_found());
761 // std::wstring extension = boost::filesystem::wpath(fullFilename).extension();
762 // std::wstring filename = templatename;
763 // filename.append(extension);
765 // flash::flash::create_cg_proxy(info.video_channel, std::max<int>(DEFAULT_CHANNEL_LAYER+1, info.layer_index))
766 // ->add(flash_layer_index, filename, play_on_load, start_label, data);
768 // CASPAR_LOG(info) << L"Executed [amcp_channel_cg_add]";
772 bool LoadbgCommand::DoExecute()
774 transition_info transitionInfo;
780 std::wstring message;
781 for(size_t n = 0; n < _parameters.size(); ++n)
782 message += _parameters[n] + L" ";
784 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)?.*");
786 if(boost::regex_match(message, what, expr))
788 auto transition = what["TRANSITION"].str();
789 transitionInfo.duration = boost::lexical_cast<size_t>(what["DURATION"].str());
790 auto direction = what["DIRECTION"].matched ? what["DIRECTION"].str() : L"";
791 auto tween = what["TWEEN"].matched ? what["TWEEN"].str() : L"";
792 transitionInfo.tweener = tween;
794 if(transition == TEXT("CUT"))
795 transitionInfo.type = transition_type::cut;
796 else if(transition == TEXT("MIX"))
797 transitionInfo.type = transition_type::mix;
798 else if(transition == TEXT("PUSH"))
799 transitionInfo.type = transition_type::push;
800 else if(transition == TEXT("SLIDE"))
801 transitionInfo.type = transition_type::slide;
802 else if(transition == TEXT("WIPE"))
803 transitionInfo.type = transition_type::wipe;
805 if(direction == TEXT("FROMLEFT"))
806 transitionInfo.direction = transition_direction::from_left;
807 else if(direction == TEXT("FROMRIGHT"))
808 transitionInfo.direction = transition_direction::from_right;
809 else if(direction == TEXT("LEFT"))
810 transitionInfo.direction = transition_direction::from_right;
811 else if(direction == TEXT("RIGHT"))
812 transitionInfo.direction = transition_direction::from_left;
815 //Perform loading of the clip
818 std::shared_ptr<core::frame_producer> pFP;
820 static boost::wregex expr(L"\\[(?<CHANNEL>\\d+)\\]", boost::regex::icase);
823 if(boost::regex_match(_parameters.at(0), what, expr))
825 auto channel_index = boost::lexical_cast<int>(what["CHANNEL"].str());
826 pFP = reroute::create_producer(*GetChannels().at(channel_index-1));
829 pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), _parameters);
831 if(pFP == frame_producer::empty())
832 CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(_parameters.size() > 0 ? _parameters[0] : L""));
834 bool auto_play = std::find(_parameters.begin(), _parameters.end(), L"AUTO") != _parameters.end();
836 auto pFP2 = create_transition_producer(GetChannel()->video_format_desc().field_mode, spl::make_shared_ptr(pFP), transitionInfo);
838 GetChannel()->stage().load(GetLayerIndex(), pFP2, false, transitionInfo.duration); // TODO: LOOP
840 GetChannel()->stage().load(GetLayerIndex(), pFP2, false); // TODO: LOOP
843 SetReplyString(TEXT("202 LOADBG OK\r\n"));
847 catch(file_not_found&)
849 std::wstring params2;
850 for(auto it = _parameters.begin(); it != _parameters.end(); ++it)
851 params2 += L" " + *it;
852 CASPAR_LOG(error) << L"File not found. No match found for parameters. Check syntax:" << params2;
853 SetReplyString(TEXT("404 LOADBG ERROR\r\n"));
858 CASPAR_LOG_CURRENT_EXCEPTION();
859 SetReplyString(TEXT("502 LOADBG FAILED\r\n"));
864 bool PauseCommand::DoExecute()
868 GetChannel()->stage().pause(GetLayerIndex());
869 SetReplyString(TEXT("202 PAUSE OK\r\n"));
874 SetReplyString(TEXT("501 PAUSE FAILED\r\n"));
880 bool PlayCommand::DoExecute()
884 if(!_parameters.empty())
887 lbg.SetChannel(GetChannel());
888 lbg.SetChannels(GetChannels());
889 lbg.SetChannelIndex(GetChannelIndex());
890 lbg.SetLayerIntex(GetLayerIndex());
891 lbg.SetClientInfo(GetClientInfo());
892 for(auto it = _parameters.begin(); it != _parameters.end(); ++it)
893 lbg.AddParameter(*it);
895 throw std::exception();
898 GetChannel()->stage().play(GetLayerIndex());
900 SetReplyString(TEXT("202 PLAY OK\r\n"));
905 SetReplyString(TEXT("501 PLAY FAILED\r\n"));
911 bool StopCommand::DoExecute()
915 GetChannel()->stage().stop(GetLayerIndex());
916 SetReplyString(TEXT("202 STOP OK\r\n"));
921 SetReplyString(TEXT("501 STOP FAILED\r\n"));
927 bool ClearCommand::DoExecute()
929 int index = GetLayerIndex(std::numeric_limits<int>::min());
930 if(index != std::numeric_limits<int>::min())
931 GetChannel()->stage().clear(index);
933 GetChannel()->stage().clear();
935 SetReplyString(TEXT("202 CLEAR OK\r\n"));
940 bool PrintCommand::DoExecute()
942 GetChannel()->output().add(create_consumer(boost::assign::list_of(L"IMAGE")));
944 SetReplyString(TEXT("202 PRINT OK\r\n"));
949 bool LogCommand::DoExecute()
951 if(_parameters.at(0) == L"LEVEL")
952 log::set_log_level(_parameters.at(1));
954 SetReplyString(TEXT("202 LOG OK\r\n"));
959 bool CGCommand::DoExecute()
963 std::wstring command = _parameters[0];
964 if(command == TEXT("ADD"))
965 return DoExecuteAdd();
966 else if(command == TEXT("PLAY"))
967 return DoExecutePlay();
968 else if(command == TEXT("STOP"))
969 return DoExecuteStop();
970 else if(command == TEXT("NEXT"))
971 return DoExecuteNext();
972 else if(command == TEXT("REMOVE"))
973 return DoExecuteRemove();
974 else if(command == TEXT("CLEAR"))
975 return DoExecuteClear();
976 else if(command == TEXT("UPDATE"))
977 return DoExecuteUpdate();
978 else if(command == TEXT("INVOKE"))
979 return DoExecuteInvoke();
980 else if(command == TEXT("INFO"))
981 return DoExecuteInfo();
985 CASPAR_LOG_CURRENT_EXCEPTION();
988 SetReplyString(TEXT("403 CG ERROR\r\n"));
992 bool CGCommand::ValidateLayer(const std::wstring& layerstring) {
993 int length = layerstring.length();
994 for(int i = 0; i < length; ++i) {
995 if(!_istdigit(layerstring[i])) {
1003 bool CGCommand::DoExecuteAdd() {
1004 //CG 1 ADD 0 "template_folder/templatename" [STARTLABEL] 0/1 [DATA]
1006 int layer = 0; //_parameters[1]
1007 // std::wstring templateName; //_parameters[2]
1008 std::wstring label; //_parameters[3]
1009 bool bDoStart = false; //_parameters[3] alt. _parameters[4]
1010 // std::wstring data; //_parameters[4] alt. _parameters[5]
1012 if(_parameters.size() < 4)
1014 SetReplyString(TEXT("402 CG ERROR\r\n"));
1017 unsigned int dataIndex = 4;
1019 if(!ValidateLayer(_parameters[1]))
1021 SetReplyString(TEXT("403 CG ERROR\r\n"));
1025 layer = _ttoi(_parameters[1].c_str());
1027 if(_parameters[3].length() > 1)
1029 label = _parameters2[3];
1032 if(_parameters.size() > 4 && _parameters[4].length() > 0) //read play-on-load-flag
1033 bDoStart = (_parameters[4][0]==TEXT('1')) ? true : false;
1036 SetReplyString(TEXT("402 CG ERROR\r\n"));
1040 else if(_parameters[3].length() > 0) { //read play-on-load-flag
1041 bDoStart = (_parameters[3][0]==TEXT('1')) ? true : false;
1045 SetReplyString(TEXT("403 CG ERROR\r\n"));
1049 const TCHAR* pDataString = 0;
1050 std::wstringstream data;
1051 std::wstring dataFromFile;
1052 if(_parameters.size() > dataIndex)
1054 const std::wstring& dataString = _parameters2[dataIndex];
1056 if(dataString[0] == TEXT('<')) //the data is an XML-string
1057 pDataString = dataString.c_str();
1060 //The data is not an XML-string, it must be a filename
1061 std::wstring filename = env::data_folder();
1062 filename.append(dataString);
1063 filename.append(TEXT(".ftd"));
1065 dataFromFile = read_file(boost::filesystem::wpath(filename));
1066 pDataString = dataFromFile.c_str();
1070 std::wstring fullFilename = flash::find_template(env::template_folder() + _parameters[2]);
1071 if(!fullFilename.empty())
1073 std::wstring extension = boost::filesystem::path(fullFilename).extension().wstring();
1074 std::wstring filename = _parameters[2];
1075 filename.append(extension);
1077 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(""));
1078 SetReplyString(TEXT("202 CG OK\r\n"));
1082 CASPAR_LOG(warning) << "Could not find template " << _parameters[2];
1083 SetReplyString(TEXT("404 CG ERROR\r\n"));
1088 bool CGCommand::DoExecutePlay()
1090 if(_parameters.size() > 1)
1092 if(!ValidateLayer(_parameters[1]))
1094 SetReplyString(TEXT("403 CG ERROR\r\n"));
1097 int layer = _ttoi(_parameters[1].c_str());
1098 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).play(layer);
1102 SetReplyString(TEXT("402 CG ERROR\r\n"));
1106 SetReplyString(TEXT("202 CG OK\r\n"));
1110 bool CGCommand::DoExecuteStop()
1112 if(_parameters.size() > 1)
1114 if(!ValidateLayer(_parameters[1]))
1116 SetReplyString(TEXT("403 CG ERROR\r\n"));
1119 int layer = _ttoi(_parameters[1].c_str());
1120 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).stop(layer, 0);
1124 SetReplyString(TEXT("402 CG ERROR\r\n"));
1128 SetReplyString(TEXT("202 CG OK\r\n"));
1132 bool CGCommand::DoExecuteNext()
1134 if(_parameters.size() > 1)
1136 if(!ValidateLayer(_parameters[1]))
1138 SetReplyString(TEXT("403 CG ERROR\r\n"));
1142 int layer = _ttoi(_parameters[1].c_str());
1143 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).next(layer);
1147 SetReplyString(TEXT("402 CG ERROR\r\n"));
1151 SetReplyString(TEXT("202 CG OK\r\n"));
1155 bool CGCommand::DoExecuteRemove()
1157 if(_parameters.size() > 1)
1159 if(!ValidateLayer(_parameters[1]))
1161 SetReplyString(TEXT("403 CG ERROR\r\n"));
1165 int layer = _ttoi(_parameters[1].c_str());
1166 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).remove(layer);
1170 SetReplyString(TEXT("402 CG ERROR\r\n"));
1174 SetReplyString(TEXT("202 CG OK\r\n"));
1178 bool CGCommand::DoExecuteClear()
1180 GetChannel()->stage().clear(GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER));
1181 SetReplyString(TEXT("202 CG OK\r\n"));
1185 bool CGCommand::DoExecuteUpdate()
1189 if(!ValidateLayer(_parameters.at(1)))
1191 SetReplyString(TEXT("403 CG ERROR\r\n"));
1195 std::wstring dataString = _parameters2.at(2);
1196 if(dataString.at(0) != TEXT('<'))
1198 //The data is not an XML-string, it must be a filename
1199 std::wstring filename = env::data_folder();
1200 filename.append(dataString);
1201 filename.append(TEXT(".ftd"));
1203 dataString = read_file(boost::filesystem::wpath(filename));
1206 int layer = _ttoi(_parameters.at(1).c_str());
1207 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).update(layer, dataString);
1211 SetReplyString(TEXT("402 CG ERROR\r\n"));
1215 SetReplyString(TEXT("202 CG OK\r\n"));
1219 bool CGCommand::DoExecuteInvoke()
1221 std::wstringstream replyString;
1222 replyString << TEXT("201 CG OK\r\n");
1224 if(_parameters.size() > 2)
1226 if(!ValidateLayer(_parameters[1]))
1228 SetReplyString(TEXT("403 CG ERROR\r\n"));
1231 int layer = _ttoi(_parameters[1].c_str());
1232 auto result = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).invoke(layer, _parameters2[2]);
1233 replyString << result << TEXT("\r\n");
1237 SetReplyString(TEXT("402 CG ERROR\r\n"));
1241 SetReplyString(replyString.str());
1245 bool CGCommand::DoExecuteInfo()
1247 std::wstringstream replyString;
1248 replyString << TEXT("201 CG OK\r\n");
1250 if(_parameters.size() > 1)
1252 if(!ValidateLayer(_parameters[1]))
1254 SetReplyString(TEXT("403 CG ERROR\r\n"));
1258 int layer = _ttoi(_parameters[1].c_str());
1259 auto desc = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).description(layer);
1261 replyString << desc << TEXT("\r\n");
1265 auto info = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).template_host_info();
1266 replyString << info << TEXT("\r\n");
1269 SetReplyString(replyString.str());
1273 bool DataCommand::DoExecute()
1275 std::wstring command = _parameters[0];
1276 if(command == TEXT("STORE"))
1277 return DoExecuteStore();
1278 else if(command == TEXT("RETRIEVE"))
1279 return DoExecuteRetrieve();
1280 else if(command == TEXT("REMOVE"))
1281 return DoExecuteRemove();
1282 else if(command == TEXT("LIST"))
1283 return DoExecuteList();
1285 SetReplyString(TEXT("403 DATA ERROR\r\n"));
1289 bool DataCommand::DoExecuteStore()
1291 if(_parameters.size() < 3)
1293 SetReplyString(TEXT("402 DATA STORE ERROR\r\n"));
1297 std::wstring filename = env::data_folder();
1298 filename.append(_parameters[1]);
1299 filename.append(TEXT(".ftd"));
1301 auto data_path = boost::filesystem::wpath(
1302 boost::filesystem::wpath(filename).parent_path());
1304 if(!boost::filesystem::exists(data_path))
1305 boost::filesystem::create_directories(data_path);
1307 std::wofstream datafile(filename.c_str());
1310 SetReplyString(TEXT("501 DATA STORE FAILED\r\n"));
1314 datafile << static_cast<wchar_t>(65279); // UTF-8 BOM character
1315 datafile << _parameters2[2] << std::flush;
1318 std::wstring replyString = TEXT("202 DATA STORE OK\r\n");
1319 SetReplyString(replyString);
1323 bool DataCommand::DoExecuteRetrieve()
1325 if(_parameters.size() < 2)
1327 SetReplyString(TEXT("402 DATA RETRIEVE ERROR\r\n"));
1331 std::wstring filename = env::data_folder();
1332 filename.append(_parameters[1]);
1333 filename.append(TEXT(".ftd"));
1335 std::wstring file_contents = read_file(boost::filesystem::wpath(filename));
1337 if (file_contents.empty())
1339 SetReplyString(TEXT("404 DATA RETRIEVE ERROR\r\n"));
1343 std::wstringstream reply(TEXT("201 DATA RETRIEVE OK\r\n"));
1345 reply << file_contents;
1347 SetReplyString(reply.str());
1351 bool DataCommand::DoExecuteRemove()
1353 if (_parameters.size() < 2)
1355 SetReplyString(TEXT("402 DATA REMOVE ERROR\r\n"));
1359 std::wstring filename = env::data_folder();
1360 filename.append(_parameters[1]);
1361 filename.append(TEXT(".ftd"));
1363 if (!boost::filesystem::exists(filename))
1365 SetReplyString(TEXT("404 DATA REMOVE ERROR\r\n"));
1369 if (!boost::filesystem::remove(filename))
1371 SetReplyString(TEXT("403 DATA REMOVE ERROR\r\n"));
1375 SetReplyString(TEXT("201 DATA REMOVE OK\r\n"));
1380 bool DataCommand::DoExecuteList()
1382 std::wstringstream replyString;
1383 replyString << TEXT("200 DATA LIST OK\r\n");
1385 for (boost::filesystem::recursive_directory_iterator itr(env::data_folder()), end; itr != end; ++itr)
1387 if(boost::filesystem::is_regular_file(itr->path()))
1389 if(!boost::iequals(itr->path().extension().wstring(), L".ftd"))
1392 auto relativePath = boost::filesystem::wpath(itr->path().wstring().substr(env::data_folder().size()-1, itr->path().wstring().size()));
1394 auto str = relativePath.replace_extension(TEXT("")).native();
1395 if(str[0] == '\\' || str[0] == '/')
1396 str = std::wstring(str.begin() + 1, str.end());
1398 replyString << str << TEXT("\r\n");
1402 replyString << TEXT("\r\n");
1404 SetReplyString(boost::to_upper_copy(replyString.str()));
1408 bool CinfCommand::DoExecute()
1410 std::wstringstream replyString;
1415 for (boost::filesystem::recursive_directory_iterator itr(env::media_folder()), end; itr != end && info.empty(); ++itr)
1417 auto path = itr->path();
1418 auto file = path.replace_extension(L"").filename();
1419 if(boost::iequals(file.wstring(), _parameters.at(0)))
1420 info += MediaInfo(itr->path()) + L"\r\n";
1425 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1428 replyString << TEXT("200 CINF OK\r\n");
1429 replyString << info << "\r\n";
1433 CASPAR_LOG_CURRENT_EXCEPTION();
1434 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1438 SetReplyString(replyString.str());
1442 void GenerateChannelInfo(int index, const spl::shared_ptr<core::video_channel>& pChannel, std::wstringstream& replyString)
1444 replyString << index+1 << TEXT(" ") << pChannel->video_format_desc().name << TEXT(" PLAYING") << TEXT("\r\n");
1447 bool InfoCommand::DoExecute()
1449 std::wstringstream replyString;
1451 boost::property_tree::xml_writer_settings<wchar_t> w(' ', 3);
1455 if(_parameters.size() >= 1 && _parameters[0] == L"TEMPLATE")
1457 replyString << L"201 INFO TEMPLATE OK\r\n";
1459 // Needs to be extended for any file, not just flash.
1461 auto filename = flash::find_template(env::template_folder() + _parameters.at(1));
1463 std::wstringstream str;
1464 str << u16(flash::read_template_meta_info(filename));
1465 boost::property_tree::wptree info;
1466 boost::property_tree::xml_parser::read_xml(str, info, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
1468 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1470 else if(_parameters.size() >= 1 && _parameters[0] == L"CONFIG")
1472 replyString << L"201 INFO CONFIG OK\r\n";
1474 boost::property_tree::write_xml(replyString, caspar::env::properties(), w);
1476 else if(_parameters.size() >= 1 && _parameters[0] == L"PATHS")
1478 replyString << L"201 INFO PATHS OK\r\n";
1480 boost::property_tree::wptree info;
1481 info.add_child(L"paths", caspar::env::properties().get_child(L"configuration.paths"));
1482 info.add(L"paths.initial-path", boost::filesystem3::initial_path().wstring() + L"\\");
1484 boost::property_tree::write_xml(replyString, info, w);
1486 else if(_parameters.size() >= 1 && _parameters[0] == L"SYSTEM")
1488 replyString << L"201 INFO SYSTEM OK\r\n";
1490 boost::property_tree::wptree info;
1492 info.add(L"system.name", caspar::system_product_name());
1493 info.add(L"system.windows.name", caspar::win_product_name());
1494 info.add(L"system.windows.service-pack", caspar::win_sp_version());
1495 info.add(L"system.cpu", caspar::cpu_info());
1497 BOOST_FOREACH(auto device, caspar::decklink::device_list())
1498 info.add(L"system.decklink.device", device);
1500 BOOST_FOREACH(auto device, caspar::bluefish::device_list())
1501 info.add(L"system.bluefish.device", device);
1503 info.add(L"system.flash", caspar::flash::version());
1504 //info.add(L"system.free-image", caspar::image::version());
1505 info.add(L"system.ffmpeg.avcodec", caspar::ffmpeg::avcodec_version());
1506 info.add(L"system.ffmpeg.avformat", caspar::ffmpeg::avformat_version());
1507 info.add(L"system.ffmpeg.avfilter", caspar::ffmpeg::avfilter_version());
1508 info.add(L"system.ffmpeg.avutil", caspar::ffmpeg::avutil_version());
1509 info.add(L"system.ffmpeg.swscale", caspar::ffmpeg::swscale_version());
1511 boost::property_tree::write_xml(replyString, info, w);
1513 else if(_parameters.size() >= 1 && _parameters[0] == L"SERVER")
1515 replyString << L"201 INFO SERVER OK\r\n";
1517 boost::property_tree::wptree info;
1520 BOOST_FOREACH(auto channel, channels_)
1521 info.add_child(L"channels.channel", channel->info())
1522 .add(L"index", ++index);
1524 boost::property_tree::write_xml(replyString, info, w);
1528 if(_parameters.size() >= 1)
1530 replyString << TEXT("201 INFO OK\r\n");
1531 boost::property_tree::wptree info;
1533 std::vector<std::wstring> split;
1534 boost::split(split, _parameters[0], boost::is_any_of("-"));
1536 int layer = std::numeric_limits<int>::min();
1537 int channel = boost::lexical_cast<int>(split[0]) - 1;
1539 if(split.size() > 1)
1540 layer = boost::lexical_cast<int>(split[1]);
1542 if(layer == std::numeric_limits<int>::min())
1544 info.add_child(L"channel", channels_.at(channel)->info())
1545 .add(L"index", channel);
1549 if(_parameters.size() >= 2)
1551 if(_parameters[1] == L"B")
1552 info.add_child(L"producer", channels_.at(channel)->stage().background(layer).get()->info());
1554 info.add_child(L"producer", channels_.at(channel)->stage().foreground(layer).get()->info());
1558 info.add_child(L"layer", channels_.at(channel)->stage().info(layer).get())
1559 .add(L"index", layer);
1562 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1566 // This is needed for backwards compatibility with old clients
1567 replyString << TEXT("200 INFO OK\r\n");
1568 for(size_t n = 0; n < channels_.size(); ++n)
1569 GenerateChannelInfo(n, channels_[n], replyString);
1576 CASPAR_LOG_CURRENT_EXCEPTION();
1577 SetReplyString(TEXT("403 INFO ERROR\r\n"));
1581 replyString << TEXT("\r\n");
1582 SetReplyString(replyString.str());
1586 bool ClsCommand::DoExecute()
1598 std::wstringstream replyString;
1599 replyString << TEXT("200 CLS OK\r\n");
1600 replyString << ListMedia();
1601 replyString << TEXT("\r\n");
1602 SetReplyString(boost::to_upper_copy(replyString.str()));
1606 CASPAR_LOG_CURRENT_EXCEPTION();
1607 SetReplyString(TEXT("501 CLS FAILED\r\n"));
1614 bool TlsCommand::DoExecute()
1618 std::wstringstream replyString;
1619 replyString << TEXT("200 TLS OK\r\n");
1621 replyString << ListTemplates();
1622 replyString << TEXT("\r\n");
1624 SetReplyString(replyString.str());
1628 CASPAR_LOG_CURRENT_EXCEPTION();
1629 SetReplyString(TEXT("501 TLS FAILED\r\n"));
1635 bool VersionCommand::DoExecute()
1637 std::wstring replyString = TEXT("201 VERSION OK\r\n") + env::version() + TEXT("\r\n");
1639 if(_parameters.size() > 0)
1641 if(_parameters[0] == L"FLASH")
1642 replyString = TEXT("201 VERSION OK\r\n") + flash::version() + TEXT("\r\n");
1643 else if(_parameters[0] == L"TEMPLATEHOST")
1644 replyString = TEXT("201 VERSION OK\r\n") + flash::cg_version() + TEXT("\r\n");
1645 else if(_parameters[0] != L"SERVER")
1646 replyString = TEXT("403 VERSION ERROR\r\n");
1649 SetReplyString(replyString);
1653 bool ByeCommand::DoExecute()
1655 GetClientInfo()->Disconnect();
1659 bool SetCommand::DoExecute()
1663 std::wstring name = _parameters[0];
1664 std::transform(name.begin(), name.end(), name.begin(), toupper);
1666 std::wstring value = _parameters[1];
1667 std::transform(value.begin(), value.end(), value.begin(), toupper);
1669 if(name == TEXT("MODE"))
1671 auto format_desc = core::video_format_desc(value);
1672 if(format_desc.format != core::video_format::invalid)
1674 GetChannel()->video_format_desc(format_desc);
1675 SetReplyString(TEXT("202 SET MODE OK\r\n"));
1678 SetReplyString(TEXT("501 SET MODE FAILED\r\n"));
1682 this->SetReplyString(TEXT("403 SET ERROR\r\n"));
1687 CASPAR_LOG_CURRENT_EXCEPTION();
1688 SetReplyString(TEXT("501 SET FAILED\r\n"));
1697 }} //namespace caspar