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;
440 }, duration, tween));
442 else if(_parameters[0] == L"CLIP" || _parameters[0] == L"CLIP_RECT")
444 int duration = _parameters.size() > 5 ? boost::lexical_cast<int>(_parameters[5]) : 0;
445 std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear";
446 double x = boost::lexical_cast<double>(_parameters.at(1));
447 double y = boost::lexical_cast<double>(_parameters.at(2));
448 double x_s = boost::lexical_cast<double>(_parameters.at(3));
449 double y_s = boost::lexical_cast<double>(_parameters.at(4));
451 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
453 transform.image_transform.clip_translation[0] = x;
454 transform.image_transform.clip_translation[1] = y;
455 transform.image_transform.clip_scale[0] = x_s;
456 transform.image_transform.clip_scale[1] = y_s;
458 }, duration, tween));
460 else if(_parameters[0] == L"GRID")
462 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
463 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
464 int n = boost::lexical_cast<int>(_parameters.at(1));
465 double delta = 1.0/static_cast<double>(n);
466 for(int x = 0; x < n; ++x)
468 for(int y = 0; y < n; ++y)
471 transforms.push_back(stage::transform_tuple_t(index, [=](frame_transform transform) -> frame_transform
473 transform.image_transform.fill_translation[0] = x*delta;
474 transform.image_transform.fill_translation[1] = y*delta;
475 transform.image_transform.fill_scale[0] = delta;
476 transform.image_transform.fill_scale[1] = delta;
477 transform.image_transform.clip_translation[0] = x*delta;
478 transform.image_transform.clip_translation[1] = y*delta;
479 transform.image_transform.clip_scale[0] = delta;
480 transform.image_transform.clip_scale[1] = delta;
482 }, duration, tween));
486 else if(_parameters[0] == L"BLEND")
488 auto blend_str = _parameters.at(1);
489 int layer = GetLayerIndex();
490 GetChannel()->mixer().set_blend_mode(GetLayerIndex(), get_blend_mode(blend_str));
492 else if(_parameters[0] == L"MASTERVOLUME")
494 float master_volume = boost::lexical_cast<float>(_parameters.at(1));
495 GetChannel()->mixer().set_master_volume(master_volume);
497 else if(_parameters[0] == L"BRIGHTNESS")
499 auto value = boost::lexical_cast<double>(_parameters.at(1));
500 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
501 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
502 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
504 transform.image_transform.brightness = value;
506 }, duration, tween));
508 else if(_parameters[0] == L"SATURATION")
510 auto value = boost::lexical_cast<double>(_parameters.at(1));
511 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
512 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
513 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
515 transform.image_transform.saturation = value;
517 }, duration, tween));
519 else if(_parameters[0] == L"CONTRAST")
521 auto value = boost::lexical_cast<double>(_parameters.at(1));
522 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
523 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
524 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
526 transform.image_transform.contrast = value;
528 }, duration, tween));
530 else if(_parameters[0] == L"LEVELS")
533 value.min_input = boost::lexical_cast<double>(_parameters.at(1));
534 value.max_input = boost::lexical_cast<double>(_parameters.at(2));
535 value.gamma = boost::lexical_cast<double>(_parameters.at(3));
536 value.min_output = boost::lexical_cast<double>(_parameters.at(4));
537 value.max_output = boost::lexical_cast<double>(_parameters.at(5));
538 int duration = _parameters.size() > 6 ? boost::lexical_cast<int>(_parameters[6]) : 0;
539 std::wstring tween = _parameters.size() > 7 ? _parameters[7] : L"linear";
541 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
543 transform.image_transform.levels = value;
545 }, duration, tween));
547 else if(_parameters[0] == L"VOLUME")
549 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
550 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
551 double value = boost::lexical_cast<double>(_parameters[1]);
553 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
555 transform.audio_transform.volume = value;
557 }, duration, tween));
559 else if(_parameters[0] == L"CLEAR")
561 int layer = GetLayerIndex(std::numeric_limits<int>::max());
563 if (layer == std::numeric_limits<int>::max())
565 GetChannel()->stage().clear_transforms();
566 GetChannel()->mixer().clear_blend_modes();
570 GetChannel()->stage().clear_transforms(layer);
571 GetChannel()->mixer().clear_blend_mode(layer);
574 else if(_parameters[0] == L"COMMIT")
576 transforms = std::move(deferred_transforms[GetChannelIndex()]);
580 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
586 auto& defer_tranforms = deferred_transforms[GetChannelIndex()];
587 defer_tranforms.insert(defer_tranforms.end(), transforms.begin(), transforms.end());
590 GetChannel()->stage().apply_transforms(transforms);
592 SetReplyString(TEXT("202 MIXER OK\r\n"));
596 catch(file_not_found&)
598 CASPAR_LOG_CURRENT_EXCEPTION();
599 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
604 CASPAR_LOG_CURRENT_EXCEPTION();
605 SetReplyString(TEXT("502 MIXER FAILED\r\n"));
610 bool SwapCommand::DoExecute()
612 //Perform loading of the clip
615 if(GetLayerIndex(-1) != -1)
617 std::vector<std::string> strs;
618 boost::split(strs, _parameters[0], boost::is_any_of("-"));
620 auto ch1 = GetChannel();
621 auto ch2 = GetChannels().at(boost::lexical_cast<int>(strs.at(0))-1);
623 int l1 = GetLayerIndex();
624 int l2 = boost::lexical_cast<int>(strs.at(1));
626 ch1->stage().swap_layer(l1, l2, ch2->stage());
630 auto ch1 = GetChannel();
631 auto ch2 = GetChannels().at(boost::lexical_cast<int>(_parameters[0])-1);
632 ch1->stage().swap_layers(ch2->stage());
635 SetReplyString(TEXT("202 SWAP OK\r\n"));
639 catch(file_not_found&)
641 CASPAR_LOG_CURRENT_EXCEPTION();
642 SetReplyString(TEXT("404 SWAP ERROR\r\n"));
647 CASPAR_LOG_CURRENT_EXCEPTION();
648 SetReplyString(TEXT("502 SWAP FAILED\r\n"));
653 bool AddCommand::DoExecute()
655 //Perform loading of the clip
658 auto consumer = create_consumer(_parameters);
659 GetChannel()->output().add(GetLayerIndex(consumer->index()), consumer);
661 SetReplyString(TEXT("202 ADD OK\r\n"));
665 catch(file_not_found&)
667 CASPAR_LOG_CURRENT_EXCEPTION();
668 SetReplyString(TEXT("404 ADD ERROR\r\n"));
673 CASPAR_LOG_CURRENT_EXCEPTION();
674 SetReplyString(TEXT("502 ADD FAILED\r\n"));
679 bool RemoveCommand::DoExecute()
681 //Perform loading of the clip
684 auto index = GetLayerIndex(std::numeric_limits<int>::min());
685 if(index == std::numeric_limits<int>::min())
686 index = create_consumer(_parameters)->index();
688 GetChannel()->output().remove(index);
690 SetReplyString(TEXT("202 REMOVE OK\r\n"));
694 catch(file_not_found&)
696 CASPAR_LOG_CURRENT_EXCEPTION();
697 SetReplyString(TEXT("404 REMOVE ERROR\r\n"));
702 CASPAR_LOG_CURRENT_EXCEPTION();
703 SetReplyString(TEXT("502 REMOVE FAILED\r\n"));
708 bool LoadCommand::DoExecute()
710 //Perform loading of the clip
713 _parameters[0] = _parameters[0];
714 auto pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), _parameters);
715 GetChannel()->stage().load(GetLayerIndex(), pFP, true);
717 SetReplyString(TEXT("202 LOAD OK\r\n"));
721 catch(file_not_found&)
723 CASPAR_LOG_CURRENT_EXCEPTION();
724 SetReplyString(TEXT("404 LOAD ERROR\r\n"));
729 CASPAR_LOG_CURRENT_EXCEPTION();
730 SetReplyString(TEXT("502 LOAD FAILED\r\n"));
737 //std::function<std::wstring()> channel_cg_add_command::parse(const std::wstring& message, const std::vector<renderer::render_device_ptr>& channels)
739 // 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>.*)?");
741 // boost::wsmatch what;
742 // if(!boost::regex_match(message, what, expr))
745 // auto info = channel_info::parse(what, channels);
747 // int flash_layer_index = boost::lexical_cast<int>(what["FLASH_LAYER"].str());
749 // std::wstring templatename = what["TEMPLATE"].str();
750 // bool play_on_load = what["PLAY_ON_LOAD"].matched ? what["PLAY_ON_LOAD"].str() != L"0" : 0;
751 // std::wstring start_label = what["START_LABEL"].str();
752 // std::wstring data = get_data(what["DATA"].str());
754 // boost::replace_all(templatename, "\"", "");
756 // return [=]() -> std::wstring
758 // std::wstring fullFilename = flash::flash_producer::find_template(server::template_folder() + templatename);
759 // if(fullFilename.empty())
760 // CASPAR_THROW_EXCEPTION(file_not_found());
762 // std::wstring extension = boost::filesystem::wpath(fullFilename).extension();
763 // std::wstring filename = templatename;
764 // filename.append(extension);
766 // flash::flash::create_cg_proxy(info.video_channel, std::max<int>(DEFAULT_CHANNEL_LAYER+1, info.layer_index))
767 // ->add(flash_layer_index, filename, play_on_load, start_label, data);
769 // CASPAR_LOG(info) << L"Executed [amcp_channel_cg_add]";
773 bool LoadbgCommand::DoExecute()
775 transition_info transitionInfo;
781 std::wstring message;
782 for(size_t n = 0; n < _parameters.size(); ++n)
783 message += _parameters[n] + L" ";
785 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)?.*");
787 if(boost::regex_match(message, what, expr))
789 auto transition = what["TRANSITION"].str();
790 transitionInfo.duration = boost::lexical_cast<size_t>(what["DURATION"].str());
791 auto direction = what["DIRECTION"].matched ? what["DIRECTION"].str() : L"";
792 auto tween = what["TWEEN"].matched ? what["TWEEN"].str() : L"";
793 transitionInfo.tweener = tween;
795 if(transition == TEXT("CUT"))
796 transitionInfo.type = transition_type::cut;
797 else if(transition == TEXT("MIX"))
798 transitionInfo.type = transition_type::mix;
799 else if(transition == TEXT("PUSH"))
800 transitionInfo.type = transition_type::push;
801 else if(transition == TEXT("SLIDE"))
802 transitionInfo.type = transition_type::slide;
803 else if(transition == TEXT("WIPE"))
804 transitionInfo.type = transition_type::wipe;
806 if(direction == TEXT("FROMLEFT"))
807 transitionInfo.direction = transition_direction::from_left;
808 else if(direction == TEXT("FROMRIGHT"))
809 transitionInfo.direction = transition_direction::from_right;
810 else if(direction == TEXT("LEFT"))
811 transitionInfo.direction = transition_direction::from_right;
812 else if(direction == TEXT("RIGHT"))
813 transitionInfo.direction = transition_direction::from_left;
816 //Perform loading of the clip
819 std::shared_ptr<core::frame_producer> pFP;
821 static boost::wregex expr(L"\\[(?<CHANNEL>\\d+)\\]", boost::regex::icase);
824 if(boost::regex_match(_parameters.at(0), what, expr))
826 auto channel_index = boost::lexical_cast<int>(what["CHANNEL"].str());
827 pFP = reroute::create_producer(*GetChannels().at(channel_index-1));
830 pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), _parameters);
832 if(pFP == frame_producer::empty())
833 CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(_parameters.size() > 0 ? _parameters[0] : L""));
835 bool auto_play = std::find(_parameters.begin(), _parameters.end(), L"AUTO") != _parameters.end();
837 auto pFP2 = create_transition_producer(GetChannel()->video_format_desc().field_mode, spl::make_shared_ptr(pFP), transitionInfo);
839 GetChannel()->stage().load(GetLayerIndex(), pFP2, false, transitionInfo.duration); // TODO: LOOP
841 GetChannel()->stage().load(GetLayerIndex(), pFP2, false); // TODO: LOOP
844 SetReplyString(TEXT("202 LOADBG OK\r\n"));
848 catch(file_not_found&)
850 std::wstring params2;
851 for(auto it = _parameters.begin(); it != _parameters.end(); ++it)
852 params2 += L" " + *it;
853 CASPAR_LOG(error) << L"File not found. No match found for parameters. Check syntax:" << params2;
854 SetReplyString(TEXT("404 LOADBG ERROR\r\n"));
859 CASPAR_LOG_CURRENT_EXCEPTION();
860 SetReplyString(TEXT("502 LOADBG FAILED\r\n"));
865 bool PauseCommand::DoExecute()
869 GetChannel()->stage().pause(GetLayerIndex());
870 SetReplyString(TEXT("202 PAUSE OK\r\n"));
875 SetReplyString(TEXT("501 PAUSE FAILED\r\n"));
881 bool PlayCommand::DoExecute()
885 if(!_parameters.empty())
888 lbg.SetChannel(GetChannel());
889 lbg.SetChannels(GetChannels());
890 lbg.SetChannelIndex(GetChannelIndex());
891 lbg.SetLayerIntex(GetLayerIndex());
892 lbg.SetClientInfo(GetClientInfo());
893 for(auto it = _parameters.begin(); it != _parameters.end(); ++it)
894 lbg.AddParameter(*it);
896 throw std::exception();
899 GetChannel()->stage().play(GetLayerIndex());
901 SetReplyString(TEXT("202 PLAY OK\r\n"));
906 SetReplyString(TEXT("501 PLAY FAILED\r\n"));
912 bool StopCommand::DoExecute()
916 GetChannel()->stage().stop(GetLayerIndex());
917 SetReplyString(TEXT("202 STOP OK\r\n"));
922 SetReplyString(TEXT("501 STOP FAILED\r\n"));
928 bool ClearCommand::DoExecute()
930 int index = GetLayerIndex(std::numeric_limits<int>::min());
931 if(index != std::numeric_limits<int>::min())
932 GetChannel()->stage().clear(index);
934 GetChannel()->stage().clear();
936 SetReplyString(TEXT("202 CLEAR OK\r\n"));
941 bool PrintCommand::DoExecute()
943 GetChannel()->output().add(create_consumer(boost::assign::list_of(L"IMAGE")));
945 SetReplyString(TEXT("202 PRINT OK\r\n"));
950 bool LogCommand::DoExecute()
952 if(_parameters.at(0) == L"LEVEL")
953 log::set_log_level(_parameters.at(1));
955 SetReplyString(TEXT("202 LOG OK\r\n"));
960 bool CGCommand::DoExecute()
964 std::wstring command = _parameters[0];
965 if(command == TEXT("ADD"))
966 return DoExecuteAdd();
967 else if(command == TEXT("PLAY"))
968 return DoExecutePlay();
969 else if(command == TEXT("STOP"))
970 return DoExecuteStop();
971 else if(command == TEXT("NEXT"))
972 return DoExecuteNext();
973 else if(command == TEXT("REMOVE"))
974 return DoExecuteRemove();
975 else if(command == TEXT("CLEAR"))
976 return DoExecuteClear();
977 else if(command == TEXT("UPDATE"))
978 return DoExecuteUpdate();
979 else if(command == TEXT("INVOKE"))
980 return DoExecuteInvoke();
981 else if(command == TEXT("INFO"))
982 return DoExecuteInfo();
986 CASPAR_LOG_CURRENT_EXCEPTION();
989 SetReplyString(TEXT("403 CG ERROR\r\n"));
993 bool CGCommand::ValidateLayer(const std::wstring& layerstring) {
994 int length = layerstring.length();
995 for(int i = 0; i < length; ++i) {
996 if(!_istdigit(layerstring[i])) {
1004 bool CGCommand::DoExecuteAdd() {
1005 //CG 1 ADD 0 "template_folder/templatename" [STARTLABEL] 0/1 [DATA]
1007 int layer = 0; //_parameters[1]
1008 // std::wstring templateName; //_parameters[2]
1009 std::wstring label; //_parameters[3]
1010 bool bDoStart = false; //_parameters[3] alt. _parameters[4]
1011 // std::wstring data; //_parameters[4] alt. _parameters[5]
1013 if(_parameters.size() < 4)
1015 SetReplyString(TEXT("402 CG ERROR\r\n"));
1018 unsigned int dataIndex = 4;
1020 if(!ValidateLayer(_parameters[1]))
1022 SetReplyString(TEXT("403 CG ERROR\r\n"));
1026 layer = _ttoi(_parameters[1].c_str());
1028 if(_parameters[3].length() > 1)
1030 label = _parameters2[3];
1033 if(_parameters.size() > 4 && _parameters[4].length() > 0) //read play-on-load-flag
1034 bDoStart = (_parameters[4][0]==TEXT('1')) ? true : false;
1037 SetReplyString(TEXT("402 CG ERROR\r\n"));
1041 else if(_parameters[3].length() > 0) { //read play-on-load-flag
1042 bDoStart = (_parameters[3][0]==TEXT('1')) ? true : false;
1046 SetReplyString(TEXT("403 CG ERROR\r\n"));
1050 const TCHAR* pDataString = 0;
1051 std::wstringstream data;
1052 std::wstring dataFromFile;
1053 if(_parameters.size() > dataIndex)
1055 const std::wstring& dataString = _parameters2[dataIndex];
1057 if(dataString[0] == TEXT('<')) //the data is an XML-string
1058 pDataString = dataString.c_str();
1061 //The data is not an XML-string, it must be a filename
1062 std::wstring filename = env::data_folder();
1063 filename.append(dataString);
1064 filename.append(TEXT(".ftd"));
1066 dataFromFile = read_file(boost::filesystem::wpath(filename));
1067 pDataString = dataFromFile.c_str();
1071 std::wstring fullFilename = flash::find_template(env::template_folder() + _parameters[2]);
1072 if(!fullFilename.empty())
1074 std::wstring extension = boost::filesystem::path(fullFilename).extension().wstring();
1075 std::wstring filename = _parameters[2];
1076 filename.append(extension);
1078 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(""));
1079 SetReplyString(TEXT("202 CG OK\r\n"));
1083 CASPAR_LOG(warning) << "Could not find template " << _parameters[2];
1084 SetReplyString(TEXT("404 CG ERROR\r\n"));
1089 bool CGCommand::DoExecutePlay()
1091 if(_parameters.size() > 1)
1093 if(!ValidateLayer(_parameters[1]))
1095 SetReplyString(TEXT("403 CG ERROR\r\n"));
1098 int layer = _ttoi(_parameters[1].c_str());
1099 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).play(layer);
1103 SetReplyString(TEXT("402 CG ERROR\r\n"));
1107 SetReplyString(TEXT("202 CG OK\r\n"));
1111 bool CGCommand::DoExecuteStop()
1113 if(_parameters.size() > 1)
1115 if(!ValidateLayer(_parameters[1]))
1117 SetReplyString(TEXT("403 CG ERROR\r\n"));
1120 int layer = _ttoi(_parameters[1].c_str());
1121 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).stop(layer, 0);
1125 SetReplyString(TEXT("402 CG ERROR\r\n"));
1129 SetReplyString(TEXT("202 CG OK\r\n"));
1133 bool CGCommand::DoExecuteNext()
1135 if(_parameters.size() > 1)
1137 if(!ValidateLayer(_parameters[1]))
1139 SetReplyString(TEXT("403 CG ERROR\r\n"));
1143 int layer = _ttoi(_parameters[1].c_str());
1144 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).next(layer);
1148 SetReplyString(TEXT("402 CG ERROR\r\n"));
1152 SetReplyString(TEXT("202 CG OK\r\n"));
1156 bool CGCommand::DoExecuteRemove()
1158 if(_parameters.size() > 1)
1160 if(!ValidateLayer(_parameters[1]))
1162 SetReplyString(TEXT("403 CG ERROR\r\n"));
1166 int layer = _ttoi(_parameters[1].c_str());
1167 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).remove(layer);
1171 SetReplyString(TEXT("402 CG ERROR\r\n"));
1175 SetReplyString(TEXT("202 CG OK\r\n"));
1179 bool CGCommand::DoExecuteClear()
1181 GetChannel()->stage().clear(GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER));
1182 SetReplyString(TEXT("202 CG OK\r\n"));
1186 bool CGCommand::DoExecuteUpdate()
1190 if(!ValidateLayer(_parameters.at(1)))
1192 SetReplyString(TEXT("403 CG ERROR\r\n"));
1196 std::wstring dataString = _parameters2.at(2);
1197 if(dataString.at(0) != TEXT('<'))
1199 //The data is not an XML-string, it must be a filename
1200 std::wstring filename = env::data_folder();
1201 filename.append(dataString);
1202 filename.append(TEXT(".ftd"));
1204 dataString = read_file(boost::filesystem::wpath(filename));
1207 int layer = _ttoi(_parameters.at(1).c_str());
1208 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).update(layer, dataString);
1212 SetReplyString(TEXT("402 CG ERROR\r\n"));
1216 SetReplyString(TEXT("202 CG OK\r\n"));
1220 bool CGCommand::DoExecuteInvoke()
1222 std::wstringstream replyString;
1223 replyString << TEXT("201 CG OK\r\n");
1225 if(_parameters.size() > 2)
1227 if(!ValidateLayer(_parameters[1]))
1229 SetReplyString(TEXT("403 CG ERROR\r\n"));
1232 int layer = _ttoi(_parameters[1].c_str());
1233 auto result = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).invoke(layer, _parameters2[2]);
1234 replyString << result << TEXT("\r\n");
1238 SetReplyString(TEXT("402 CG ERROR\r\n"));
1242 SetReplyString(replyString.str());
1246 bool CGCommand::DoExecuteInfo()
1248 std::wstringstream replyString;
1249 replyString << TEXT("201 CG OK\r\n");
1251 if(_parameters.size() > 1)
1253 if(!ValidateLayer(_parameters[1]))
1255 SetReplyString(TEXT("403 CG ERROR\r\n"));
1259 int layer = _ttoi(_parameters[1].c_str());
1260 auto desc = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).description(layer);
1262 replyString << desc << TEXT("\r\n");
1266 auto info = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).template_host_info();
1267 replyString << info << TEXT("\r\n");
1270 SetReplyString(replyString.str());
1274 bool DataCommand::DoExecute()
1276 std::wstring command = _parameters[0];
1277 if(command == TEXT("STORE"))
1278 return DoExecuteStore();
1279 else if(command == TEXT("RETRIEVE"))
1280 return DoExecuteRetrieve();
1281 else if(command == TEXT("REMOVE"))
1282 return DoExecuteRemove();
1283 else if(command == TEXT("LIST"))
1284 return DoExecuteList();
1286 SetReplyString(TEXT("403 DATA ERROR\r\n"));
1290 bool DataCommand::DoExecuteStore()
1292 if(_parameters.size() < 3)
1294 SetReplyString(TEXT("402 DATA STORE ERROR\r\n"));
1298 std::wstring filename = env::data_folder();
1299 filename.append(_parameters[1]);
1300 filename.append(TEXT(".ftd"));
1302 auto data_path = boost::filesystem::wpath(
1303 boost::filesystem::wpath(filename).parent_path());
1305 if(!boost::filesystem::exists(data_path))
1306 boost::filesystem::create_directories(data_path);
1308 std::wofstream datafile(filename.c_str());
1311 SetReplyString(TEXT("501 DATA STORE FAILED\r\n"));
1315 datafile << static_cast<wchar_t>(65279); // UTF-8 BOM character
1316 datafile << _parameters2[2] << std::flush;
1319 std::wstring replyString = TEXT("202 DATA STORE OK\r\n");
1320 SetReplyString(replyString);
1324 bool DataCommand::DoExecuteRetrieve()
1326 if(_parameters.size() < 2)
1328 SetReplyString(TEXT("402 DATA RETRIEVE ERROR\r\n"));
1332 std::wstring filename = env::data_folder();
1333 filename.append(_parameters[1]);
1334 filename.append(TEXT(".ftd"));
1336 std::wstring file_contents = read_file(boost::filesystem::wpath(filename));
1338 if (file_contents.empty())
1340 SetReplyString(TEXT("404 DATA RETRIEVE ERROR\r\n"));
1344 std::wstringstream reply(TEXT("201 DATA RETRIEVE OK\r\n"));
1346 reply << file_contents;
1348 SetReplyString(reply.str());
1352 bool DataCommand::DoExecuteRemove()
1354 if (_parameters.size() < 2)
1356 SetReplyString(TEXT("402 DATA REMOVE ERROR\r\n"));
1360 std::wstring filename = env::data_folder();
1361 filename.append(_parameters[1]);
1362 filename.append(TEXT(".ftd"));
1364 if (!boost::filesystem::exists(filename))
1366 SetReplyString(TEXT("404 DATA REMOVE ERROR\r\n"));
1370 if (!boost::filesystem::remove(filename))
1372 SetReplyString(TEXT("403 DATA REMOVE ERROR\r\n"));
1376 SetReplyString(TEXT("201 DATA REMOVE OK\r\n"));
1381 bool DataCommand::DoExecuteList()
1383 std::wstringstream replyString;
1384 replyString << TEXT("200 DATA LIST OK\r\n");
1386 for (boost::filesystem::recursive_directory_iterator itr(env::data_folder()), end; itr != end; ++itr)
1388 if(boost::filesystem::is_regular_file(itr->path()))
1390 if(!boost::iequals(itr->path().extension().wstring(), L".ftd"))
1393 auto relativePath = boost::filesystem::wpath(itr->path().wstring().substr(env::data_folder().size()-1, itr->path().wstring().size()));
1395 auto str = relativePath.replace_extension(TEXT("")).native();
1396 if(str[0] == '\\' || str[0] == '/')
1397 str = std::wstring(str.begin() + 1, str.end());
1399 replyString << str << TEXT("\r\n");
1403 replyString << TEXT("\r\n");
1405 SetReplyString(boost::to_upper_copy(replyString.str()));
1409 bool CinfCommand::DoExecute()
1411 std::wstringstream replyString;
1416 for (boost::filesystem::recursive_directory_iterator itr(env::media_folder()), end; itr != end && info.empty(); ++itr)
1418 auto path = itr->path();
1419 auto file = path.replace_extension(L"").filename();
1420 if(boost::iequals(file.wstring(), _parameters.at(0)))
1421 info += MediaInfo(itr->path()) + L"\r\n";
1426 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1429 replyString << TEXT("200 CINF OK\r\n");
1430 replyString << info << "\r\n";
1434 CASPAR_LOG_CURRENT_EXCEPTION();
1435 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1439 SetReplyString(replyString.str());
1443 void GenerateChannelInfo(int index, const spl::shared_ptr<core::video_channel>& pChannel, std::wstringstream& replyString)
1445 replyString << index+1 << TEXT(" ") << pChannel->video_format_desc().name << TEXT(" PLAYING") << TEXT("\r\n");
1448 bool InfoCommand::DoExecute()
1450 std::wstringstream replyString;
1452 boost::property_tree::xml_writer_settings<wchar_t> w(' ', 3);
1456 if(_parameters.size() >= 1 && _parameters[0] == L"TEMPLATE")
1458 replyString << L"201 INFO TEMPLATE OK\r\n";
1460 // Needs to be extended for any file, not just flash.
1462 auto filename = flash::find_template(env::template_folder() + _parameters.at(1));
1464 std::wstringstream str;
1465 str << u16(flash::read_template_meta_info(filename));
1466 boost::property_tree::wptree info;
1467 boost::property_tree::xml_parser::read_xml(str, info, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
1469 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1471 else if(_parameters.size() >= 1 && _parameters[0] == L"CONFIG")
1473 replyString << L"201 INFO CONFIG OK\r\n";
1475 boost::property_tree::write_xml(replyString, caspar::env::properties(), w);
1477 else if(_parameters.size() >= 1 && _parameters[0] == L"PATHS")
1479 replyString << L"201 INFO PATHS OK\r\n";
1481 boost::property_tree::wptree info;
1482 info.add_child(L"paths", caspar::env::properties().get_child(L"configuration.paths"));
1483 info.add(L"paths.initial-path", boost::filesystem3::initial_path().wstring() + L"\\");
1485 boost::property_tree::write_xml(replyString, info, w);
1487 else if(_parameters.size() >= 1 && _parameters[0] == L"SYSTEM")
1489 replyString << L"201 INFO SYSTEM OK\r\n";
1491 boost::property_tree::wptree info;
1493 info.add(L"system.name", caspar::system_product_name());
1494 info.add(L"system.windows.name", caspar::win_product_name());
1495 info.add(L"system.windows.service-pack", caspar::win_sp_version());
1496 info.add(L"system.cpu", caspar::cpu_info());
1498 BOOST_FOREACH(auto device, caspar::decklink::device_list())
1499 info.add(L"system.decklink.device", device);
1501 BOOST_FOREACH(auto device, caspar::bluefish::device_list())
1502 info.add(L"system.bluefish.device", device);
1504 info.add(L"system.flash", caspar::flash::version());
1505 //info.add(L"system.free-image", caspar::image::version());
1506 info.add(L"system.ffmpeg.avcodec", caspar::ffmpeg::avcodec_version());
1507 info.add(L"system.ffmpeg.avformat", caspar::ffmpeg::avformat_version());
1508 info.add(L"system.ffmpeg.avfilter", caspar::ffmpeg::avfilter_version());
1509 info.add(L"system.ffmpeg.avutil", caspar::ffmpeg::avutil_version());
1510 info.add(L"system.ffmpeg.swscale", caspar::ffmpeg::swscale_version());
1512 boost::property_tree::write_xml(replyString, info, w);
1514 else if(_parameters.size() >= 1 && _parameters[0] == L"SERVER")
1516 replyString << L"201 INFO SERVER OK\r\n";
1518 boost::property_tree::wptree info;
1521 BOOST_FOREACH(auto channel, channels_)
1522 info.add_child(L"channels.channel", channel->info())
1523 .add(L"index", ++index);
1525 boost::property_tree::write_xml(replyString, info, w);
1529 if(_parameters.size() >= 1)
1531 replyString << TEXT("201 INFO OK\r\n");
1532 boost::property_tree::wptree info;
1534 std::vector<std::wstring> split;
1535 boost::split(split, _parameters[0], boost::is_any_of("-"));
1537 int layer = std::numeric_limits<int>::min();
1538 int channel = boost::lexical_cast<int>(split[0]) - 1;
1540 if(split.size() > 1)
1541 layer = boost::lexical_cast<int>(split[1]);
1543 if(layer == std::numeric_limits<int>::min())
1545 info.add_child(L"channel", channels_.at(channel)->info())
1546 .add(L"index", channel);
1550 if(_parameters.size() >= 2)
1552 if(_parameters[1] == L"B")
1553 info.add_child(L"producer", channels_.at(channel)->stage().background(layer).get()->info());
1555 info.add_child(L"producer", channels_.at(channel)->stage().foreground(layer).get()->info());
1559 info.add_child(L"layer", channels_.at(channel)->stage().info(layer).get())
1560 .add(L"index", layer);
1563 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1567 // This is needed for backwards compatibility with old clients
1568 replyString << TEXT("200 INFO OK\r\n");
1569 for(size_t n = 0; n < channels_.size(); ++n)
1570 GenerateChannelInfo(n, channels_[n], replyString);
1577 CASPAR_LOG_CURRENT_EXCEPTION();
1578 SetReplyString(TEXT("403 INFO ERROR\r\n"));
1582 replyString << TEXT("\r\n");
1583 SetReplyString(replyString.str());
1587 bool ClsCommand::DoExecute()
1599 std::wstringstream replyString;
1600 replyString << TEXT("200 CLS OK\r\n");
1601 replyString << ListMedia();
1602 replyString << TEXT("\r\n");
1603 SetReplyString(boost::to_upper_copy(replyString.str()));
1607 CASPAR_LOG_CURRENT_EXCEPTION();
1608 SetReplyString(TEXT("501 CLS FAILED\r\n"));
1615 bool TlsCommand::DoExecute()
1619 std::wstringstream replyString;
1620 replyString << TEXT("200 TLS OK\r\n");
1622 replyString << ListTemplates();
1623 replyString << TEXT("\r\n");
1625 SetReplyString(replyString.str());
1629 CASPAR_LOG_CURRENT_EXCEPTION();
1630 SetReplyString(TEXT("501 TLS FAILED\r\n"));
1636 bool VersionCommand::DoExecute()
1638 std::wstring replyString = TEXT("201 VERSION OK\r\n") + env::version() + TEXT("\r\n");
1640 if(_parameters.size() > 0)
1642 if(_parameters[0] == L"FLASH")
1643 replyString = TEXT("201 VERSION OK\r\n") + flash::version() + TEXT("\r\n");
1644 else if(_parameters[0] == L"TEMPLATEHOST")
1645 replyString = TEXT("201 VERSION OK\r\n") + flash::cg_version() + TEXT("\r\n");
1646 else if(_parameters[0] != L"SERVER")
1647 replyString = TEXT("403 VERSION ERROR\r\n");
1650 SetReplyString(replyString);
1654 bool ByeCommand::DoExecute()
1656 GetClientInfo()->Disconnect();
1660 bool SetCommand::DoExecute()
1664 std::wstring name = _parameters[0];
1665 std::transform(name.begin(), name.end(), name.begin(), toupper);
1667 std::wstring value = _parameters[1];
1668 std::transform(value.begin(), value.end(), value.begin(), toupper);
1670 if(name == TEXT("MODE"))
1672 auto format_desc = core::video_format_desc(value);
1673 if(format_desc.format != core::video_format::invalid)
1675 GetChannel()->video_format_desc(format_desc);
1676 SetReplyString(TEXT("202 SET MODE OK\r\n"));
1679 SetReplyString(TEXT("501 SET MODE FAILED\r\n"));
1683 this->SetReplyString(TEXT("403 SET ERROR\r\n"));
1688 CASPAR_LOG_CURRENT_EXCEPTION();
1689 SetReplyString(TEXT("501 SET FAILED\r\n"));
1698 }} //namespace caspar