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/param.h>
35 #include <common/diagnostics/graph.h>
36 #include <common/os/windows/current_version.h>
37 #include <common/os/windows/system_info.h>
39 #include <core/producer/frame_producer.h>
40 #include <core/video_format.h>
41 #include <core/producer/transition/transition_producer.h>
42 #include <core/frame/frame_transform.h>
43 #include <core/producer/stage.h>
44 #include <core/producer/layer.h>
45 #include <core/mixer/mixer.h>
46 #include <core/consumer/output.h>
48 #include <modules/reroute/producer/reroute_producer.h>
49 #include <modules/bluefish/bluefish.h>
50 #include <modules/decklink/decklink.h>
51 #include <modules/ffmpeg/ffmpeg.h>
52 #include <modules/flash/flash.h>
53 #include <modules/flash/util/swf.h>
54 #include <modules/flash/producer/flash_producer.h>
55 #include <modules/flash/producer/cg_proxy.h>
56 #include <modules/ffmpeg/producer/util/util.h>
57 #include <modules/image/image.h>
58 #include <modules/screen/screen.h>
59 #include <modules/reroute/producer/reroute_producer.h>
68 #include <boost/date_time/posix_time/posix_time.hpp>
69 #include <boost/lexical_cast.hpp>
70 #include <boost/algorithm/string.hpp>
71 #include <boost/filesystem.hpp>
72 #include <boost/filesystem/fstream.hpp>
73 #include <boost/regex.hpp>
74 #include <boost/property_tree/xml_parser.hpp>
75 #include <boost/locale.hpp>
76 #include <boost/range/adaptor/transformed.hpp>
77 #include <boost/range/algorithm/copy.hpp>
79 #include <tbb/concurrent_unordered_map.h>
83 100 [action] Information om att något har hänt
84 101 [action] Information om att något har hänt, en rad data skickas
86 202 [kommando] OK Kommandot har utförts
87 201 [kommando] OK Kommandot har utförts, och en rad data skickas tillbaka
88 200 [kommando] OK Kommandot har utförts, och flera rader data skickas tillbaka. Avslutas med tomrad
90 400 ERROR Kommandot kunde inte förstås
91 401 [kommando] ERROR Ogiltig kanal
92 402 [kommando] ERROR Parameter saknas
93 403 [kommando] ERROR Ogiltig parameter
94 404 [kommando] ERROR Mediafilen hittades inte
96 500 FAILED Internt configurationfel
97 501 [kommando] FAILED Internt configurationfel
98 502 [kommando] FAILED Oläslig mediafil
100 600 [kommando] FAILED funktion ej implementerad
103 namespace caspar { namespace protocol {
105 using namespace core;
107 std::wstring read_utf8_file(const boost::filesystem::wpath& file)
109 std::wstringstream result;
110 boost::filesystem::wifstream filestream(file);
117 result << filestream.rdbuf();
123 std::wstring read_latin1_file(const boost::filesystem::wpath& file)
125 boost::locale::generator gen;
126 gen.locale_cache_enabled(true);
127 gen.categories(boost::locale::codepage_facet);
129 std::stringstream result_stream;
130 boost::filesystem::ifstream filestream(file);
131 filestream.imbue(gen("en_US.ISO8859-1"));
136 result_stream << filestream.rdbuf();
139 std::string result = result_stream.str();
140 std::wstring widened_result;
142 // The first 255 codepoints in unicode is the same as in latin1
143 auto from_signed_to_signed = std::function<unsigned char(char)>(
144 [] (char c) { return static_cast<unsigned char>(c); }
147 result | boost::adaptors::transformed(from_signed_to_signed),
148 std::back_inserter(widened_result));
150 return widened_result;
153 std::wstring read_file(const boost::filesystem::wpath& file)
155 static const uint8_t BOM[] = {0xef, 0xbb, 0xbf};
157 if (!boost::filesystem::exists(file))
162 if (boost::filesystem::file_size(file) >= 3)
164 boost::filesystem::ifstream bom_stream(file);
167 bom_stream.read(header, 3);
170 if (std::memcmp(BOM, header, 3) == 0)
171 return read_utf8_file(file);
174 return read_latin1_file(file);
177 std::wstring MediaInfo(const boost::filesystem::path& path)
179 if(boost::filesystem::is_regular_file(path))
181 std::wstring clipttype = TEXT("N/A");
182 std::wstring extension = boost::to_upper_copy(path.extension().wstring());
183 if(extension == TEXT(".TGA") || extension == TEXT(".COL") || extension == L".PNG" || extension == L".JPEG" || extension == L".JPG" ||
184 extension == L"GIF" || extension == L"BMP")
185 clipttype = TEXT("STILL");
186 else if(extension == TEXT(".WAV") || extension == TEXT(".MP3"))
187 clipttype = TEXT("AUDIO");
188 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()))
189 clipttype = TEXT("MOVIE");
191 if(clipttype != TEXT("N/A"))
193 auto is_not_digit = [](char c){ return std::isdigit(c) == 0; };
195 auto relativePath = boost::filesystem::path(path.wstring().substr(env::media_folder().size()-1, path.wstring().size()));
197 auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(path)));
198 writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), is_not_digit), writeTimeStr.end());
199 auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end());
201 auto sizeStr = boost::lexical_cast<std::wstring>(boost::filesystem::file_size(path));
202 sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), is_not_digit), sizeStr.end());
203 auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end());
205 auto str = relativePath.replace_extension(TEXT("")).native();
206 while(str.size() > 0 && (str[0] == '\\' || str[0] == '/'))
207 str = std::wstring(str.begin() + 1, str.end());
209 return std::wstring() + TEXT("\"") + str +
210 + TEXT("\" ") + clipttype +
211 + TEXT(" ") + sizeStr +
212 + TEXT(" ") + writeTimeWStr +
219 std::wstring ListMedia()
221 std::wstringstream replyString;
222 for (boost::filesystem::recursive_directory_iterator itr(env::media_folder()), end; itr != end; ++itr)
223 replyString << MediaInfo(itr->path());
225 return boost::to_upper_copy(replyString.str());
228 std::wstring ListTemplates()
230 std::wstringstream replyString;
232 for (boost::filesystem::recursive_directory_iterator itr(env::template_folder()), end; itr != end; ++itr)
234 if(boost::filesystem::is_regular_file(itr->path()) && (itr->path().extension() == L".ft" || itr->path().extension() == L".ct"))
236 auto relativePath = boost::filesystem::wpath(itr->path().wstring().substr(env::template_folder().size()-1, itr->path().wstring().size()));
238 auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(itr->path())));
239 writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), [](char c){ return std::isdigit(c) == 0;}), writeTimeStr.end());
240 auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end());
242 auto sizeStr = boost::lexical_cast<std::string>(boost::filesystem::file_size(itr->path()));
243 sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), [](char c){ return std::isdigit(c) == 0;}), sizeStr.end());
245 auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end());
247 std::wstring dir = relativePath.parent_path().native();
248 std::wstring file = boost::to_upper_copy(relativePath.filename().wstring());
249 relativePath = boost::filesystem::wpath(dir + L"/" + file);
251 auto str = relativePath.replace_extension(TEXT("")).native();
252 boost::trim_if(str, boost::is_any_of("\\/"));
254 replyString << TEXT("\"") << str
255 << TEXT("\" ") << sizeWStr
256 << TEXT(" ") << writeTimeWStr
260 return replyString.str();
265 AMCPCommand::AMCPCommand() : channelIndex_(0), layerIndex_(-1)
268 void AMCPCommand::SendReply()
273 if(replyString_.empty())
276 pClientInfo_->Send(replyString_);
279 void AMCPCommand::Clear()
281 pChannel_->stage().clear();
282 pClientInfo_.reset();
287 bool DiagnosticsCommand::DoExecute()
291 diagnostics::show_graphs(true);
293 SetReplyString(TEXT("202 DIAG OK\r\n"));
299 CASPAR_LOG_CURRENT_EXCEPTION();
300 SetReplyString(TEXT("502 DIAG FAILED\r\n"));
305 bool ChannelGridCommand::DoExecute()
307 CASPAR_THROW_EXCEPTION(not_implemented());
310 //auto self = GetChannels().back();
312 //std::vector<std::wstring> params;
313 //params.push_back(L"SCREEN");
314 //params.push_back(L"NAME");
315 //params.push_back(L"Channel Grid Window");
316 //auto screen = create_consumer(params);
318 //self->output().add(screen);
320 //BOOST_FOREACH(auto channel, GetChannels())
322 // if(channel != self)
324 // auto producer = reroute::create_producer(self->frame_factory(), *channel);
325 // self->stage().load(index, producer, false);
326 // self->stage().play(index);
331 //int n = GetChannels().size()-1;
332 //double delta = 1.0/static_cast<double>(n);
333 //for(int x = 0; x < n; ++x)
335 // for(int y = 0; y < n; ++y)
337 // int index = x+y*n+1;
338 // auto transform = [=](frame_transform transform) -> frame_transform
340 // transform.image_transform.fill_translation[0] = x*delta;
341 // transform.image_transform.fill_translation[1] = y*delta;
342 // transform.image_transform.fill_scale[0] = delta;
343 // transform.image_transform.fill_scale[1] = delta;
344 // transform.image_transform.clip_translation[0] = x*delta;
345 // transform.image_transform.clip_translation[1] = y*delta;
346 // transform.image_transform.clip_scale[0] = delta;
347 // transform.image_transform.clip_scale[1] = delta;
350 // self->stage().apply_transform(index, transform);
357 bool CallCommand::DoExecute()
359 //Perform loading of the clip
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 auto pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), parameters());
724 GetChannel()->stage().load(GetLayerIndex(), pFP, true);
726 SetReplyString(TEXT("202 LOAD OK\r\n"));
730 catch(file_not_found&)
732 CASPAR_LOG_CURRENT_EXCEPTION();
733 SetReplyString(TEXT("404 LOAD ERROR\r\n"));
738 CASPAR_LOG_CURRENT_EXCEPTION();
739 SetReplyString(TEXT("502 LOAD FAILED\r\n"));
746 //std::function<std::wstring()> channel_cg_add_command::parse(const std::wstring& message, const std::vector<renderer::render_device_ptr>& channels)
748 // 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>.*)?");
750 // boost::wsmatch what;
751 // if(!boost::regex_match(message, what, expr))
754 // auto info = channel_info::parse(what, channels);
756 // int flash_layer_index = boost::lexical_cast<int>(what["FLASH_LAYER"].str());
758 // std::wstring templatename = what["TEMPLATE"].str();
759 // bool play_on_load = what["PLAY_ON_LOAD"].matched ? what["PLAY_ON_LOAD"].str() != L"0" : 0;
760 // std::wstring start_label = what["START_LABEL"].str();
761 // std::wstring data = get_data(what["DATA"].str());
763 // boost::replace_all(templatename, "\"", "");
765 // return [=]() -> std::wstring
767 // std::wstring fullFilename = flash::flash_producer::find_template(server::template_folder() + templatename);
768 // if(fullFilename.empty())
769 // CASPAR_THROW_EXCEPTION(file_not_found());
771 // std::wstring extension = boost::filesystem::wpath(fullFilename).extension();
772 // std::wstring filename = templatename;
773 // filename.append(extension);
775 // flash::flash::create_cg_proxy(info.video_channel, std::max<int>(DEFAULT_CHANNEL_LAYER+1, info.layer_index))
776 // ->add(flash_layer_index, filename, play_on_load, start_label, data);
778 // CASPAR_LOG(info) << L"Executed [amcp_channel_cg_add]";
782 bool LoadbgCommand::DoExecute()
784 transition_info transitionInfo;
790 std::wstring message;
791 for(size_t n = 0; n < parameters().size(); ++n)
792 message += boost::to_upper_copy(parameters()[n]) + L" ";
794 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)?.*");
796 if(boost::regex_match(message, what, expr))
798 auto transition = what["TRANSITION"].str();
799 transitionInfo.duration = boost::lexical_cast<size_t>(what["DURATION"].str());
800 auto direction = what["DIRECTION"].matched ? what["DIRECTION"].str() : L"";
801 auto tween = what["TWEEN"].matched ? what["TWEEN"].str() : L"";
802 transitionInfo.tweener = tween;
804 if(transition == TEXT("CUT"))
805 transitionInfo.type = transition_type::cut;
806 else if(transition == TEXT("MIX"))
807 transitionInfo.type = transition_type::mix;
808 else if(transition == TEXT("PUSH"))
809 transitionInfo.type = transition_type::push;
810 else if(transition == TEXT("SLIDE"))
811 transitionInfo.type = transition_type::slide;
812 else if(transition == TEXT("WIPE"))
813 transitionInfo.type = transition_type::wipe;
815 if(direction == TEXT("FROMLEFT"))
816 transitionInfo.direction = transition_direction::from_left;
817 else if(direction == TEXT("FROMRIGHT"))
818 transitionInfo.direction = transition_direction::from_right;
819 else if(direction == TEXT("LEFT"))
820 transitionInfo.direction = transition_direction::from_right;
821 else if(direction == TEXT("RIGHT"))
822 transitionInfo.direction = transition_direction::from_left;
825 //Perform loading of the clip
828 std::shared_ptr<core::frame_producer> pFP;
830 static boost::wregex expr(L"\\[(?<CHANNEL>\\d+)\\]", boost::regex::icase);
833 if(boost::regex_match(parameters().at(0), what, expr))
835 auto channel_index = boost::lexical_cast<int>(what["CHANNEL"].str());
836 pFP = reroute::create_producer(*GetChannels().at(channel_index-1));
840 pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), parameters());
843 if(pFP == frame_producer::empty())
844 CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(parameters().size() > 0 ? parameters()[0] : L""));
846 bool auto_play = contains_param(L"AUTO", parameters());
848 auto pFP2 = create_transition_producer(GetChannel()->video_format_desc().field_mode, spl::make_shared_ptr(pFP), transitionInfo);
850 GetChannel()->stage().load(GetLayerIndex(), pFP2, false, transitionInfo.duration); // TODO: LOOP
852 GetChannel()->stage().load(GetLayerIndex(), pFP2, false); // TODO: LOOP
855 SetReplyString(TEXT("202 LOADBG OK\r\n"));
859 catch(file_not_found&)
861 CASPAR_LOG(error) << L"File not found. No match found for parameters. Check syntax.";
862 SetReplyString(TEXT("404 LOADBG ERROR\r\n"));
867 CASPAR_LOG_CURRENT_EXCEPTION();
868 SetReplyString(TEXT("502 LOADBG FAILED\r\n"));
873 bool PauseCommand::DoExecute()
877 GetChannel()->stage().pause(GetLayerIndex());
878 SetReplyString(TEXT("202 PAUSE OK\r\n"));
883 SetReplyString(TEXT("501 PAUSE FAILED\r\n"));
889 bool PlayCommand::DoExecute()
893 if(!parameters().empty())
896 lbg.SetChannel(GetChannel());
897 lbg.SetChannels(GetChannels());
898 lbg.SetChannelIndex(GetChannelIndex());
899 lbg.SetLayerIntex(GetLayerIndex());
900 lbg.SetClientInfo(GetClientInfo());
901 for(auto it = parameters().begin(); it != parameters().end(); ++it)
902 lbg.AddParameter(*it);
904 throw std::exception();
907 GetChannel()->stage().play(GetLayerIndex());
909 SetReplyString(TEXT("202 PLAY OK\r\n"));
914 SetReplyString(TEXT("501 PLAY FAILED\r\n"));
920 bool StopCommand::DoExecute()
924 GetChannel()->stage().stop(GetLayerIndex());
925 SetReplyString(TEXT("202 STOP OK\r\n"));
930 SetReplyString(TEXT("501 STOP FAILED\r\n"));
936 bool ClearCommand::DoExecute()
938 int index = GetLayerIndex(std::numeric_limits<int>::min());
939 if(index != std::numeric_limits<int>::min())
940 GetChannel()->stage().clear(index);
942 GetChannel()->stage().clear();
944 SetReplyString(TEXT("202 CLEAR OK\r\n"));
949 bool PrintCommand::DoExecute()
951 GetChannel()->output().add(create_consumer(boost::assign::list_of(L"IMAGE")));
953 SetReplyString(TEXT("202 PRINT OK\r\n"));
958 bool LogCommand::DoExecute()
960 if(boost::iequals(parameters().at(0), L"LEVEL"))
961 log::set_log_level(parameters().at(1));
963 SetReplyString(TEXT("202 LOG OK\r\n"));
968 bool CGCommand::DoExecute()
972 std::wstring command = boost::to_upper_copy(parameters()[0]);
973 if(command == TEXT("ADD"))
974 return DoExecuteAdd();
975 else if(command == TEXT("PLAY"))
976 return DoExecutePlay();
977 else if(command == TEXT("STOP"))
978 return DoExecuteStop();
979 else if(command == TEXT("NEXT"))
980 return DoExecuteNext();
981 else if(command == TEXT("REMOVE"))
982 return DoExecuteRemove();
983 else if(command == TEXT("CLEAR"))
984 return DoExecuteClear();
985 else if(command == TEXT("UPDATE"))
986 return DoExecuteUpdate();
987 else if(command == TEXT("INVOKE"))
988 return DoExecuteInvoke();
989 else if(command == TEXT("INFO"))
990 return DoExecuteInfo();
994 CASPAR_LOG_CURRENT_EXCEPTION();
997 SetReplyString(TEXT("403 CG ERROR\r\n"));
1001 bool CGCommand::ValidateLayer(const std::wstring& layerstring) {
1002 int length = layerstring.length();
1003 for(int i = 0; i < length; ++i) {
1004 if(!_istdigit(layerstring[i])) {
1012 bool CGCommand::DoExecuteAdd() {
1013 //CG 1 ADD 0 "template_folder/templatename" [STARTLABEL] 0/1 [DATA]
1015 int layer = 0; //_parameters[1]
1016 // std::wstring templateName; //_parameters[2]
1017 std::wstring label; //_parameters[3]
1018 bool bDoStart = false; //_parameters[3] alt. _parameters[4]
1019 // std::wstring data; //_parameters[4] alt. _parameters[5]
1021 if(parameters().size() < 4)
1023 SetReplyString(TEXT("402 CG ERROR\r\n"));
1026 unsigned int dataIndex = 4;
1028 if(!ValidateLayer(parameters()[1]))
1030 SetReplyString(TEXT("403 CG ERROR\r\n"));
1034 layer = boost::lexical_cast<int>(parameters()[1]);
1036 if(parameters()[3].length() > 1)
1038 label = parameters()[3];
1041 if(parameters().size() > 4 && parameters()[4].length() > 0) //read play-on-load-flag
1042 bDoStart = (parameters()[4][0]==TEXT('1')) ? true : false;
1045 SetReplyString(TEXT("402 CG ERROR\r\n"));
1049 else if(parameters()[3].length() > 0) { //read play-on-load-flag
1050 bDoStart = (parameters()[3][0]==TEXT('1')) ? true : false;
1054 SetReplyString(TEXT("403 CG ERROR\r\n"));
1058 const TCHAR* pDataString = 0;
1059 std::wstringstream data;
1060 std::wstring dataFromFile;
1061 if(parameters().size() > dataIndex)
1063 const std::wstring& dataString = parameters()[dataIndex];
1065 if(dataString[0] == TEXT('<')) //the data is an XML-string
1066 pDataString = dataString.c_str();
1069 //The data is not an XML-string, it must be a filename
1070 std::wstring filename = env::data_folder();
1071 filename.append(dataString);
1072 filename.append(TEXT(".ftd"));
1074 dataFromFile = read_file(boost::filesystem::wpath(filename));
1075 pDataString = dataFromFile.c_str();
1079 std::wstring fullFilename = flash::find_template(env::template_folder() + parameters()[2]);
1080 if(!fullFilename.empty())
1082 std::wstring extension = boost::filesystem::path(fullFilename).extension().wstring();
1083 std::wstring filename = parameters()[2];
1084 filename.append(extension);
1086 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(""));
1087 SetReplyString(TEXT("202 CG OK\r\n"));
1091 CASPAR_LOG(warning) << "Could not find template " << parameters()[2];
1092 SetReplyString(TEXT("404 CG ERROR\r\n"));
1097 bool CGCommand::DoExecutePlay()
1099 if(parameters().size() > 1)
1101 if(!ValidateLayer(parameters()[1]))
1103 SetReplyString(TEXT("403 CG ERROR\r\n"));
1106 int layer = boost::lexical_cast<int>(parameters()[1]);
1107 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).play(layer);
1111 SetReplyString(TEXT("402 CG ERROR\r\n"));
1115 SetReplyString(TEXT("202 CG OK\r\n"));
1119 bool CGCommand::DoExecuteStop()
1121 if(parameters().size() > 1)
1123 if(!ValidateLayer(parameters()[1]))
1125 SetReplyString(TEXT("403 CG ERROR\r\n"));
1128 int layer = boost::lexical_cast<int>(parameters()[1]);
1129 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).stop(layer, 0);
1133 SetReplyString(TEXT("402 CG ERROR\r\n"));
1137 SetReplyString(TEXT("202 CG OK\r\n"));
1141 bool CGCommand::DoExecuteNext()
1143 if(parameters().size() > 1)
1145 if(!ValidateLayer(parameters()[1]))
1147 SetReplyString(TEXT("403 CG ERROR\r\n"));
1151 int layer = boost::lexical_cast<int>(parameters()[1]);
1152 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).next(layer);
1156 SetReplyString(TEXT("402 CG ERROR\r\n"));
1160 SetReplyString(TEXT("202 CG OK\r\n"));
1164 bool CGCommand::DoExecuteRemove()
1166 if(parameters().size() > 1)
1168 if(!ValidateLayer(parameters()[1]))
1170 SetReplyString(TEXT("403 CG ERROR\r\n"));
1174 int layer = boost::lexical_cast<int>(parameters()[1]);
1175 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).remove(layer);
1179 SetReplyString(TEXT("402 CG ERROR\r\n"));
1183 SetReplyString(TEXT("202 CG OK\r\n"));
1187 bool CGCommand::DoExecuteClear()
1189 GetChannel()->stage().clear(GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER));
1190 SetReplyString(TEXT("202 CG OK\r\n"));
1194 bool CGCommand::DoExecuteUpdate()
1198 if(!ValidateLayer(parameters().at(1)))
1200 SetReplyString(TEXT("403 CG ERROR\r\n"));
1204 std::wstring dataString = parameters().at(2);
1205 if(dataString.at(0) != TEXT('<'))
1207 //The data is not an XML-string, it must be a filename
1208 std::wstring filename = env::data_folder();
1209 filename.append(dataString);
1210 filename.append(TEXT(".ftd"));
1212 dataString = read_file(boost::filesystem::wpath(filename));
1215 int layer = boost::lexical_cast<int>(parameters()[1]);
1216 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).update(layer, dataString);
1220 SetReplyString(TEXT("402 CG ERROR\r\n"));
1224 SetReplyString(TEXT("202 CG OK\r\n"));
1228 bool CGCommand::DoExecuteInvoke()
1230 std::wstringstream replyString;
1231 replyString << TEXT("201 CG OK\r\n");
1233 if(parameters().size() > 2)
1235 if(!ValidateLayer(parameters()[1]))
1237 SetReplyString(TEXT("403 CG ERROR\r\n"));
1240 int layer = boost::lexical_cast<int>(parameters()[1]);
1241 auto result = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).invoke(layer, parameters()[2]);
1242 replyString << result << TEXT("\r\n");
1246 SetReplyString(TEXT("402 CG ERROR\r\n"));
1250 SetReplyString(replyString.str());
1254 bool CGCommand::DoExecuteInfo()
1256 std::wstringstream replyString;
1257 replyString << TEXT("201 CG OK\r\n");
1259 if(parameters().size() > 1)
1261 if(!ValidateLayer(parameters()[1]))
1263 SetReplyString(TEXT("403 CG ERROR\r\n"));
1267 int layer = boost::lexical_cast<int>(parameters()[1]);
1268 auto desc = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).description(layer);
1270 replyString << desc << TEXT("\r\n");
1274 auto info = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).template_host_info();
1275 replyString << info << TEXT("\r\n");
1278 SetReplyString(replyString.str());
1282 bool DataCommand::DoExecute()
1284 std::wstring command = boost::to_upper_copy(parameters()[0]);
1285 if(command == TEXT("STORE"))
1286 return DoExecuteStore();
1287 else if(command == TEXT("RETRIEVE"))
1288 return DoExecuteRetrieve();
1289 else if(command == TEXT("REMOVE"))
1290 return DoExecuteRemove();
1291 else if(command == TEXT("LIST"))
1292 return DoExecuteList();
1294 SetReplyString(TEXT("403 DATA ERROR\r\n"));
1298 bool DataCommand::DoExecuteStore()
1300 if(parameters().size() < 3)
1302 SetReplyString(TEXT("402 DATA STORE ERROR\r\n"));
1306 std::wstring filename = env::data_folder();
1307 filename.append(parameters()[1]);
1308 filename.append(TEXT(".ftd"));
1310 auto data_path = boost::filesystem::wpath(
1311 boost::filesystem::wpath(filename).parent_path());
1313 if(!boost::filesystem::exists(data_path))
1314 boost::filesystem::create_directories(data_path);
1316 std::wofstream datafile(filename.c_str());
1319 SetReplyString(TEXT("501 DATA STORE FAILED\r\n"));
1323 datafile << static_cast<wchar_t>(65279); // UTF-8 BOM character
1324 datafile << parameters()[2] << std::flush;
1327 std::wstring replyString = TEXT("202 DATA STORE OK\r\n");
1328 SetReplyString(replyString);
1332 bool DataCommand::DoExecuteRetrieve()
1334 if(parameters().size() < 2)
1336 SetReplyString(TEXT("402 DATA RETRIEVE ERROR\r\n"));
1340 std::wstring filename = env::data_folder();
1341 filename.append(parameters()[1]);
1342 filename.append(TEXT(".ftd"));
1344 std::wstring file_contents = read_file(boost::filesystem::wpath(filename));
1346 if (file_contents.empty())
1348 SetReplyString(TEXT("404 DATA RETRIEVE ERROR\r\n"));
1352 std::wstringstream reply(TEXT("201 DATA RETRIEVE OK\r\n"));
1354 reply << file_contents;
1356 SetReplyString(reply.str());
1360 bool DataCommand::DoExecuteRemove()
1362 if (parameters().size() < 2)
1364 SetReplyString(TEXT("402 DATA REMOVE ERROR\r\n"));
1368 std::wstring filename = env::data_folder();
1369 filename.append(parameters()[1]);
1370 filename.append(TEXT(".ftd"));
1372 if (!boost::filesystem::exists(filename))
1374 SetReplyString(TEXT("404 DATA REMOVE ERROR\r\n"));
1378 if (!boost::filesystem::remove(filename))
1380 SetReplyString(TEXT("403 DATA REMOVE ERROR\r\n"));
1384 SetReplyString(TEXT("201 DATA REMOVE OK\r\n"));
1389 bool DataCommand::DoExecuteList()
1391 std::wstringstream replyString;
1392 replyString << TEXT("200 DATA LIST OK\r\n");
1394 for (boost::filesystem::recursive_directory_iterator itr(env::data_folder()), end; itr != end; ++itr)
1396 if(boost::filesystem::is_regular_file(itr->path()))
1398 if(!boost::iequals(itr->path().extension().wstring(), L".ftd"))
1401 auto relativePath = boost::filesystem::wpath(itr->path().wstring().substr(env::data_folder().size()-1, itr->path().wstring().size()));
1403 auto str = relativePath.replace_extension(TEXT("")).native();
1404 if(str[0] == '\\' || str[0] == '/')
1405 str = std::wstring(str.begin() + 1, str.end());
1407 replyString << str << TEXT("\r\n");
1411 replyString << TEXT("\r\n");
1413 SetReplyString(boost::to_upper_copy(replyString.str()));
1417 bool CinfCommand::DoExecute()
1419 std::wstringstream replyString;
1424 for (boost::filesystem::recursive_directory_iterator itr(env::media_folder()), end; itr != end && info.empty(); ++itr)
1426 auto path = itr->path();
1427 auto file = path.replace_extension(L"").filename();
1428 if(boost::iequals(file.wstring(), parameters().at(0)))
1429 info += MediaInfo(itr->path()) + L"\r\n";
1434 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1437 replyString << TEXT("200 CINF OK\r\n");
1438 replyString << info << "\r\n";
1442 CASPAR_LOG_CURRENT_EXCEPTION();
1443 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1447 SetReplyString(replyString.str());
1451 void GenerateChannelInfo(int index, const spl::shared_ptr<core::video_channel>& pChannel, std::wstringstream& replyString)
1453 replyString << index+1 << TEXT(" ") << pChannel->video_format_desc().name << TEXT(" PLAYING") << TEXT("\r\n");
1456 bool InfoCommand::DoExecute()
1458 std::wstringstream replyString;
1460 boost::property_tree::xml_writer_settings<wchar_t> w(' ', 3);
1464 if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"TEMPLATE"))
1466 replyString << L"201 INFO TEMPLATE OK\r\n";
1468 // Needs to be extended for any file, not just flash.
1470 auto filename = flash::find_template(env::template_folder() + parameters().at(1));
1472 std::wstringstream str;
1473 str << u16(flash::read_template_meta_info(filename));
1474 boost::property_tree::wptree info;
1475 boost::property_tree::xml_parser::read_xml(str, info, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
1477 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1479 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"CONFIG"))
1481 replyString << L"201 INFO CONFIG OK\r\n";
1483 boost::property_tree::write_xml(replyString, caspar::env::properties(), w);
1485 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"PATHS"))
1487 replyString << L"201 INFO PATHS OK\r\n";
1489 boost::property_tree::wptree info;
1490 info.add_child(L"paths", caspar::env::properties().get_child(L"configuration.paths"));
1491 info.add(L"paths.initial-path", boost::filesystem3::initial_path().wstring() + L"\\");
1493 boost::property_tree::write_xml(replyString, info, w);
1495 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"SYSTEM"))
1497 replyString << L"201 INFO SYSTEM OK\r\n";
1499 boost::property_tree::wptree info;
1501 info.add(L"system.name", caspar::system_product_name());
1502 info.add(L"system.windows.name", caspar::win_product_name());
1503 info.add(L"system.windows.service-pack", caspar::win_sp_version());
1504 info.add(L"system.cpu", caspar::cpu_info());
1506 BOOST_FOREACH(auto device, caspar::decklink::device_list())
1507 info.add(L"system.decklink.device", device);
1509 BOOST_FOREACH(auto device, caspar::bluefish::device_list())
1510 info.add(L"system.bluefish.device", device);
1512 info.add(L"system.flash", caspar::flash::version());
1513 //info.add(L"system.free-image", caspar::image::version());
1514 info.add(L"system.ffmpeg.avcodec", caspar::ffmpeg::avcodec_version());
1515 info.add(L"system.ffmpeg.avformat", caspar::ffmpeg::avformat_version());
1516 info.add(L"system.ffmpeg.avfilter", caspar::ffmpeg::avfilter_version());
1517 info.add(L"system.ffmpeg.avutil", caspar::ffmpeg::avutil_version());
1518 info.add(L"system.ffmpeg.swscale", caspar::ffmpeg::swscale_version());
1520 boost::property_tree::write_xml(replyString, info, w);
1522 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"SERVER"))
1524 replyString << L"201 INFO SERVER OK\r\n";
1526 boost::property_tree::wptree info;
1529 BOOST_FOREACH(auto channel, channels_)
1530 info.add_child(L"channels.channel", channel->info())
1531 .add(L"index", ++index);
1533 boost::property_tree::write_xml(replyString, info, w);
1537 if(parameters().size() >= 1)
1539 replyString << TEXT("201 INFO OK\r\n");
1540 boost::property_tree::wptree info;
1542 std::vector<std::wstring> split;
1543 boost::split(split, parameters()[0], boost::is_any_of("-"));
1545 int layer = std::numeric_limits<int>::min();
1546 int channel = boost::lexical_cast<int>(split[0]) - 1;
1548 if(split.size() > 1)
1549 layer = boost::lexical_cast<int>(split[1]);
1551 if(layer == std::numeric_limits<int>::min())
1553 info.add_child(L"channel", channels_.at(channel)->info())
1554 .add(L"index", channel);
1558 if(parameters().size() >= 2)
1560 if(boost::iequals(parameters()[1], L"B"))
1561 info.add_child(L"producer", channels_.at(channel)->stage().background(layer).get()->info());
1563 info.add_child(L"producer", channels_.at(channel)->stage().foreground(layer).get()->info());
1567 info.add_child(L"layer", channels_.at(channel)->stage().info(layer).get())
1568 .add(L"index", layer);
1571 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1575 // This is needed for backwards compatibility with old clients
1576 replyString << TEXT("200 INFO OK\r\n");
1577 for(size_t n = 0; n < channels_.size(); ++n)
1578 GenerateChannelInfo(n, channels_[n], replyString);
1585 CASPAR_LOG_CURRENT_EXCEPTION();
1586 SetReplyString(TEXT("403 INFO ERROR\r\n"));
1590 replyString << TEXT("\r\n");
1591 SetReplyString(replyString.str());
1595 bool ClsCommand::DoExecute()
1607 std::wstringstream replyString;
1608 replyString << TEXT("200 CLS OK\r\n");
1609 replyString << ListMedia();
1610 replyString << TEXT("\r\n");
1611 SetReplyString(boost::to_upper_copy(replyString.str()));
1615 CASPAR_LOG_CURRENT_EXCEPTION();
1616 SetReplyString(TEXT("501 CLS FAILED\r\n"));
1623 bool TlsCommand::DoExecute()
1627 std::wstringstream replyString;
1628 replyString << TEXT("200 TLS OK\r\n");
1630 replyString << ListTemplates();
1631 replyString << TEXT("\r\n");
1633 SetReplyString(replyString.str());
1637 CASPAR_LOG_CURRENT_EXCEPTION();
1638 SetReplyString(TEXT("501 TLS FAILED\r\n"));
1644 bool VersionCommand::DoExecute()
1646 std::wstring replyString = TEXT("201 VERSION OK\r\n") + env::version() + TEXT("\r\n");
1648 if(parameters().size() > 0)
1650 if(boost::iequals(parameters()[0], L"FLASH"))
1651 replyString = TEXT("201 VERSION OK\r\n") + flash::version() + TEXT("\r\n");
1652 else if(boost::iequals(parameters()[0], L"TEMPLATEHOST"))
1653 replyString = TEXT("201 VERSION OK\r\n") + flash::cg_version() + TEXT("\r\n");
1654 else if(!boost::iequals(parameters()[0], L"SERVER"))
1655 replyString = TEXT("403 VERSION ERROR\r\n");
1658 SetReplyString(replyString);
1662 bool ByeCommand::DoExecute()
1664 GetClientInfo()->Disconnect();
1668 bool SetCommand::DoExecute()
1672 std::wstring name = boost::to_upper_copy(parameters()[0]);
1673 std::wstring value = boost::to_upper_copy(parameters()[1]);
1675 if(name == TEXT("MODE"))
1677 auto format_desc = core::video_format_desc(value);
1678 if(format_desc.format != core::video_format::invalid)
1680 GetChannel()->video_format_desc(format_desc);
1681 SetReplyString(TEXT("202 SET MODE OK\r\n"));
1684 SetReplyString(TEXT("501 SET MODE FAILED\r\n"));
1688 this->SetReplyString(TEXT("403 SET ERROR\r\n"));
1693 CASPAR_LOG_CURRENT_EXCEPTION();
1694 SetReplyString(TEXT("501 SET FAILED\r\n"));
1703 }} //namespace caspar