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 what = _parameters.at(0);
363 auto result = GetChannel()->stage().call(GetLayerIndex(), parameters());
365 if(!result.timed_wait(boost::posix_time::seconds(2)))
366 CASPAR_THROW_EXCEPTION(timed_out());
368 std::wstringstream replyString;
369 if(result.get().empty())
370 replyString << TEXT("202 CALL OK\r\n");
372 replyString << TEXT("201 CALL OK\r\n") << result.get() << L"\r\n";
374 SetReplyString(replyString.str());
380 CASPAR_LOG_CURRENT_EXCEPTION();
381 SetReplyString(TEXT("502 CALL FAILED\r\n"));
386 tbb::concurrent_unordered_map<int, std::vector<stage::transform_tuple_t>> deferred_transforms;
388 bool MixerCommand::DoExecute()
390 //Perform loading of the clip
393 bool defer = boost::iequals(parameters().back(), L"DEFER");
395 parameters().pop_back();
397 std::vector<stage::transform_tuple_t> transforms;
399 if(boost::iequals(parameters()[0], L"KEYER") || boost::iequals(parameters()[0], L"IS_KEY"))
401 bool value = boost::lexical_cast<int>(parameters().at(1));
402 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
404 transform.image_transform.is_key = value;
408 else if(boost::iequals(parameters()[0], L"OPACITY"))
410 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
411 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
413 double value = boost::lexical_cast<double>(parameters().at(1));
415 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
417 transform.image_transform.opacity = value;
419 }, duration, tween));
421 else if(boost::iequals(parameters()[0], L"FILL") || boost::iequals(parameters()[0], L"FILL_RECT"))
423 int duration = parameters().size() > 5 ? boost::lexical_cast<int>(parameters()[5]) : 0;
424 std::wstring tween = parameters().size() > 6 ? parameters()[6] : L"linear";
425 double x = boost::lexical_cast<double>(parameters().at(1));
426 double y = boost::lexical_cast<double>(parameters().at(2));
427 double x_s = boost::lexical_cast<double>(parameters().at(3));
428 double y_s = boost::lexical_cast<double>(parameters().at(4));
430 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) mutable -> frame_transform
432 transform.image_transform.fill_translation[0] = x;
433 transform.image_transform.fill_translation[1] = y;
434 transform.image_transform.fill_scale[0] = x_s;
435 transform.image_transform.fill_scale[1] = y_s;
437 }, duration, tween));
439 else if(boost::iequals(parameters()[0], L"CLIP") || boost::iequals(parameters()[0], L"CLIP_RECT"))
441 int duration = parameters().size() > 5 ? boost::lexical_cast<int>(parameters()[5]) : 0;
442 std::wstring tween = parameters().size() > 6 ? parameters()[6] : L"linear";
443 double x = boost::lexical_cast<double>(parameters().at(1));
444 double y = boost::lexical_cast<double>(parameters().at(2));
445 double x_s = boost::lexical_cast<double>(parameters().at(3));
446 double y_s = boost::lexical_cast<double>(parameters().at(4));
448 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
450 transform.image_transform.clip_translation[0] = x;
451 transform.image_transform.clip_translation[1] = y;
452 transform.image_transform.clip_scale[0] = x_s;
453 transform.image_transform.clip_scale[1] = y_s;
455 }, duration, tween));
457 else if(boost::iequals(parameters()[0], L"GRID"))
459 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
460 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
461 int n = boost::lexical_cast<int>(parameters().at(1));
462 double delta = 1.0/static_cast<double>(n);
463 for(int x = 0; x < n; ++x)
465 for(int y = 0; y < n; ++y)
468 transforms.push_back(stage::transform_tuple_t(index, [=](frame_transform transform) -> frame_transform
470 transform.image_transform.fill_translation[0] = x*delta;
471 transform.image_transform.fill_translation[1] = y*delta;
472 transform.image_transform.fill_scale[0] = delta;
473 transform.image_transform.fill_scale[1] = delta;
474 transform.image_transform.clip_translation[0] = x*delta;
475 transform.image_transform.clip_translation[1] = y*delta;
476 transform.image_transform.clip_scale[0] = delta;
477 transform.image_transform.clip_scale[1] = delta;
479 }, duration, tween));
483 else if(boost::iequals(parameters()[0], L"BLEND"))
485 auto blend_str = parameters().at(1);
486 int layer = GetLayerIndex();
487 GetChannel()->mixer().set_blend_mode(GetLayerIndex(), get_blend_mode(blend_str));
489 else if(boost::iequals(parameters()[0], L"MASTERVOLUME"))
491 float master_volume = boost::lexical_cast<float>(parameters().at(1));
492 GetChannel()->mixer().set_master_volume(master_volume);
494 else if(boost::iequals(parameters()[0], L"BRIGHTNESS"))
496 auto value = boost::lexical_cast<double>(parameters().at(1));
497 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
498 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
499 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
501 transform.image_transform.brightness = value;
503 }, duration, tween));
505 else if(boost::iequals(parameters()[0], L"SATURATION"))
507 auto value = boost::lexical_cast<double>(parameters().at(1));
508 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
509 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
510 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
512 transform.image_transform.saturation = value;
514 }, duration, tween));
516 else if(parameters()[0] == L"CONTRAST")
518 auto value = boost::lexical_cast<double>(parameters().at(1));
519 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
520 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
521 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
523 transform.image_transform.contrast = value;
525 }, duration, tween));
527 else if(boost::iequals(parameters()[0], L"LEVELS"))
530 value.min_input = boost::lexical_cast<double>(parameters().at(1));
531 value.max_input = boost::lexical_cast<double>(parameters().at(2));
532 value.gamma = boost::lexical_cast<double>(parameters().at(3));
533 value.min_output = boost::lexical_cast<double>(parameters().at(4));
534 value.max_output = boost::lexical_cast<double>(parameters().at(5));
535 int duration = parameters().size() > 6 ? boost::lexical_cast<int>(parameters()[6]) : 0;
536 std::wstring tween = parameters().size() > 7 ? parameters()[7] : L"linear";
538 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
540 transform.image_transform.levels = value;
542 }, duration, tween));
544 else if(boost::iequals(parameters()[0], L"VOLUME"))
546 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
547 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
548 double value = boost::lexical_cast<double>(parameters()[1]);
550 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
552 transform.audio_transform.volume = value;
554 }, duration, tween));
556 else if(boost::iequals(parameters()[0], L"CLEAR"))
558 int layer = GetLayerIndex(std::numeric_limits<int>::max());
560 if (layer == std::numeric_limits<int>::max())
562 GetChannel()->stage().clear_transforms();
563 GetChannel()->mixer().clear_blend_modes();
567 GetChannel()->stage().clear_transforms(layer);
568 GetChannel()->mixer().clear_blend_mode(layer);
571 else if(boost::iequals(parameters()[0], L"COMMIT"))
573 transforms = std::move(deferred_transforms[GetChannelIndex()]);
577 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
583 auto& defer_tranforms = deferred_transforms[GetChannelIndex()];
584 defer_tranforms.insert(defer_tranforms.end(), transforms.begin(), transforms.end());
587 GetChannel()->stage().apply_transforms(transforms);
589 SetReplyString(TEXT("202 MIXER OK\r\n"));
593 catch(file_not_found&)
595 CASPAR_LOG_CURRENT_EXCEPTION();
596 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
601 CASPAR_LOG_CURRENT_EXCEPTION();
602 SetReplyString(TEXT("502 MIXER FAILED\r\n"));
607 bool SwapCommand::DoExecute()
609 //Perform loading of the clip
612 if(GetLayerIndex(-1) != -1)
614 std::vector<std::string> strs;
615 boost::split(strs, parameters()[0], boost::is_any_of("-"));
617 auto ch1 = GetChannel();
618 auto ch2 = GetChannels().at(boost::lexical_cast<int>(strs.at(0))-1);
620 int l1 = GetLayerIndex();
621 int l2 = boost::lexical_cast<int>(strs.at(1));
623 ch1->stage().swap_layer(l1, l2, ch2->stage());
627 auto ch1 = GetChannel();
628 auto ch2 = GetChannels().at(boost::lexical_cast<int>(parameters()[0])-1);
629 ch1->stage().swap_layers(ch2->stage());
632 SetReplyString(TEXT("202 SWAP OK\r\n"));
636 catch(file_not_found&)
638 CASPAR_LOG_CURRENT_EXCEPTION();
639 SetReplyString(TEXT("404 SWAP ERROR\r\n"));
644 CASPAR_LOG_CURRENT_EXCEPTION();
645 SetReplyString(TEXT("502 SWAP FAILED\r\n"));
650 bool AddCommand::DoExecute()
652 //Perform loading of the clip
655 //create_consumer still expects all parameters to be uppercase
656 BOOST_FOREACH(std::wstring& str, parameters())
658 boost::to_upper(str);
661 auto consumer = create_consumer(parameters());
662 GetChannel()->output().add(GetLayerIndex(consumer->index()), consumer);
664 SetReplyString(TEXT("202 ADD OK\r\n"));
668 catch(file_not_found&)
670 CASPAR_LOG_CURRENT_EXCEPTION();
671 SetReplyString(TEXT("404 ADD ERROR\r\n"));
676 CASPAR_LOG_CURRENT_EXCEPTION();
677 SetReplyString(TEXT("502 ADD FAILED\r\n"));
682 bool RemoveCommand::DoExecute()
684 //Perform loading of the clip
687 auto index = GetLayerIndex(std::numeric_limits<int>::min());
688 if(index == std::numeric_limits<int>::min())
690 //create_consumer still expects all parameters to be uppercase
691 BOOST_FOREACH(std::wstring& str, parameters())
693 boost::to_upper(str);
696 index = create_consumer(parameters())->index();
699 GetChannel()->output().remove(index);
701 SetReplyString(TEXT("202 REMOVE OK\r\n"));
705 catch(file_not_found&)
707 CASPAR_LOG_CURRENT_EXCEPTION();
708 SetReplyString(TEXT("404 REMOVE ERROR\r\n"));
713 CASPAR_LOG_CURRENT_EXCEPTION();
714 SetReplyString(TEXT("502 REMOVE FAILED\r\n"));
719 bool LoadCommand::DoExecute()
721 //Perform loading of the clip
724 auto pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), parameters());
725 GetChannel()->stage().load(GetLayerIndex(), pFP, true);
727 SetReplyString(TEXT("202 LOAD OK\r\n"));
731 catch(file_not_found&)
733 CASPAR_LOG_CURRENT_EXCEPTION();
734 SetReplyString(TEXT("404 LOAD ERROR\r\n"));
739 CASPAR_LOG_CURRENT_EXCEPTION();
740 SetReplyString(TEXT("502 LOAD FAILED\r\n"));
747 //std::function<std::wstring()> channel_cg_add_command::parse(const std::wstring& message, const std::vector<renderer::render_device_ptr>& channels)
749 // 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>.*)?");
751 // boost::wsmatch what;
752 // if(!boost::regex_match(message, what, expr))
755 // auto info = channel_info::parse(what, channels);
757 // int flash_layer_index = boost::lexical_cast<int>(what["FLASH_LAYER"].str());
759 // std::wstring templatename = what["TEMPLATE"].str();
760 // bool play_on_load = what["PLAY_ON_LOAD"].matched ? what["PLAY_ON_LOAD"].str() != L"0" : 0;
761 // std::wstring start_label = what["START_LABEL"].str();
762 // std::wstring data = get_data(what["DATA"].str());
764 // boost::replace_all(templatename, "\"", "");
766 // return [=]() -> std::wstring
768 // std::wstring fullFilename = flash::flash_producer::find_template(server::template_folder() + templatename);
769 // if(fullFilename.empty())
770 // CASPAR_THROW_EXCEPTION(file_not_found());
772 // std::wstring extension = boost::filesystem::wpath(fullFilename).extension();
773 // std::wstring filename = templatename;
774 // filename.append(extension);
776 // flash::flash::create_cg_proxy(info.video_channel, std::max<int>(DEFAULT_CHANNEL_LAYER+1, info.layer_index))
777 // ->add(flash_layer_index, filename, play_on_load, start_label, data);
779 // CASPAR_LOG(info) << L"Executed [amcp_channel_cg_add]";
783 bool LoadbgCommand::DoExecute()
785 transition_info transitionInfo;
791 std::wstring message;
792 for(size_t n = 0; n < parameters().size(); ++n)
793 message += boost::to_upper_copy(parameters()[n]) + L" ";
795 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)?.*");
797 if(boost::regex_match(message, what, expr))
799 auto transition = what["TRANSITION"].str();
800 transitionInfo.duration = boost::lexical_cast<size_t>(what["DURATION"].str());
801 auto direction = what["DIRECTION"].matched ? what["DIRECTION"].str() : L"";
802 auto tween = what["TWEEN"].matched ? what["TWEEN"].str() : L"";
803 transitionInfo.tweener = tween;
805 if(transition == TEXT("CUT"))
806 transitionInfo.type = transition_type::cut;
807 else if(transition == TEXT("MIX"))
808 transitionInfo.type = transition_type::mix;
809 else if(transition == TEXT("PUSH"))
810 transitionInfo.type = transition_type::push;
811 else if(transition == TEXT("SLIDE"))
812 transitionInfo.type = transition_type::slide;
813 else if(transition == TEXT("WIPE"))
814 transitionInfo.type = transition_type::wipe;
816 if(direction == TEXT("FROMLEFT"))
817 transitionInfo.direction = transition_direction::from_left;
818 else if(direction == TEXT("FROMRIGHT"))
819 transitionInfo.direction = transition_direction::from_right;
820 else if(direction == TEXT("LEFT"))
821 transitionInfo.direction = transition_direction::from_right;
822 else if(direction == TEXT("RIGHT"))
823 transitionInfo.direction = transition_direction::from_left;
826 //Perform loading of the clip
829 std::shared_ptr<core::frame_producer> pFP;
831 static boost::wregex expr(L"\\[(?<CHANNEL>\\d+)\\]", boost::regex::icase);
834 if(boost::regex_match(parameters().at(0), what, expr))
836 auto channel_index = boost::lexical_cast<int>(what["CHANNEL"].str());
837 pFP = reroute::create_producer(*GetChannels().at(channel_index-1));
841 pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), parameters());
844 if(pFP == frame_producer::empty())
845 CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(parameters().size() > 0 ? parameters()[0] : L""));
847 bool auto_play = contains_param(L"AUTO", parameters());
849 auto pFP2 = create_transition_producer(GetChannel()->video_format_desc().field_mode, spl::make_shared_ptr(pFP), transitionInfo);
851 GetChannel()->stage().load(GetLayerIndex(), pFP2, false, transitionInfo.duration); // TODO: LOOP
853 GetChannel()->stage().load(GetLayerIndex(), pFP2, false); // TODO: LOOP
856 SetReplyString(TEXT("202 LOADBG OK\r\n"));
860 catch(file_not_found&)
862 CASPAR_LOG(error) << L"File not found. No match found for parameters. Check syntax.";
863 SetReplyString(TEXT("404 LOADBG ERROR\r\n"));
868 CASPAR_LOG_CURRENT_EXCEPTION();
869 SetReplyString(TEXT("502 LOADBG FAILED\r\n"));
874 bool PauseCommand::DoExecute()
878 GetChannel()->stage().pause(GetLayerIndex());
879 SetReplyString(TEXT("202 PAUSE OK\r\n"));
884 SetReplyString(TEXT("501 PAUSE FAILED\r\n"));
890 bool PlayCommand::DoExecute()
894 if(!parameters().empty())
897 lbg.SetChannel(GetChannel());
898 lbg.SetChannels(GetChannels());
899 lbg.SetChannelIndex(GetChannelIndex());
900 lbg.SetLayerIntex(GetLayerIndex());
901 lbg.SetClientInfo(GetClientInfo());
902 for(auto it = parameters().begin(); it != parameters().end(); ++it)
903 lbg.AddParameter(*it);
905 throw std::exception();
908 GetChannel()->stage().play(GetLayerIndex());
910 SetReplyString(TEXT("202 PLAY OK\r\n"));
915 SetReplyString(TEXT("501 PLAY FAILED\r\n"));
921 bool StopCommand::DoExecute()
925 GetChannel()->stage().stop(GetLayerIndex());
926 SetReplyString(TEXT("202 STOP OK\r\n"));
931 SetReplyString(TEXT("501 STOP FAILED\r\n"));
937 bool ClearCommand::DoExecute()
939 int index = GetLayerIndex(std::numeric_limits<int>::min());
940 if(index != std::numeric_limits<int>::min())
941 GetChannel()->stage().clear(index);
943 GetChannel()->stage().clear();
945 SetReplyString(TEXT("202 CLEAR OK\r\n"));
950 bool PrintCommand::DoExecute()
952 GetChannel()->output().add(create_consumer(boost::assign::list_of(L"IMAGE")));
954 SetReplyString(TEXT("202 PRINT OK\r\n"));
959 bool LogCommand::DoExecute()
961 if(boost::iequals(parameters().at(0), L"LEVEL"))
962 log::set_log_level(parameters().at(1));
964 SetReplyString(TEXT("202 LOG OK\r\n"));
969 bool CGCommand::DoExecute()
973 std::wstring command = boost::to_upper_copy(parameters()[0]);
974 if(command == TEXT("ADD"))
975 return DoExecuteAdd();
976 else if(command == TEXT("PLAY"))
977 return DoExecutePlay();
978 else if(command == TEXT("STOP"))
979 return DoExecuteStop();
980 else if(command == TEXT("NEXT"))
981 return DoExecuteNext();
982 else if(command == TEXT("REMOVE"))
983 return DoExecuteRemove();
984 else if(command == TEXT("CLEAR"))
985 return DoExecuteClear();
986 else if(command == TEXT("UPDATE"))
987 return DoExecuteUpdate();
988 else if(command == TEXT("INVOKE"))
989 return DoExecuteInvoke();
990 else if(command == TEXT("INFO"))
991 return DoExecuteInfo();
995 CASPAR_LOG_CURRENT_EXCEPTION();
998 SetReplyString(TEXT("403 CG ERROR\r\n"));
1002 bool CGCommand::ValidateLayer(const std::wstring& layerstring) {
1003 int length = layerstring.length();
1004 for(int i = 0; i < length; ++i) {
1005 if(!_istdigit(layerstring[i])) {
1013 bool CGCommand::DoExecuteAdd() {
1014 //CG 1 ADD 0 "template_folder/templatename" [STARTLABEL] 0/1 [DATA]
1016 int layer = 0; //_parameters[1]
1017 // std::wstring templateName; //_parameters[2]
1018 std::wstring label; //_parameters[3]
1019 bool bDoStart = false; //_parameters[3] alt. _parameters[4]
1020 // std::wstring data; //_parameters[4] alt. _parameters[5]
1022 if(parameters().size() < 4)
1024 SetReplyString(TEXT("402 CG ERROR\r\n"));
1027 unsigned int dataIndex = 4;
1029 if(!ValidateLayer(parameters()[1]))
1031 SetReplyString(TEXT("403 CG ERROR\r\n"));
1035 layer = boost::lexical_cast<int>(parameters()[1]);
1037 if(parameters()[3].length() > 1)
1039 label = parameters()[3];
1042 if(parameters().size() > 4 && parameters()[4].length() > 0) //read play-on-load-flag
1043 bDoStart = (parameters()[4][0]==TEXT('1')) ? true : false;
1046 SetReplyString(TEXT("402 CG ERROR\r\n"));
1050 else if(parameters()[3].length() > 0) { //read play-on-load-flag
1051 bDoStart = (parameters()[3][0]==TEXT('1')) ? true : false;
1055 SetReplyString(TEXT("403 CG ERROR\r\n"));
1059 const TCHAR* pDataString = 0;
1060 std::wstringstream data;
1061 std::wstring dataFromFile;
1062 if(parameters().size() > dataIndex)
1064 const std::wstring& dataString = parameters()[dataIndex];
1066 if(dataString[0] == TEXT('<')) //the data is an XML-string
1067 pDataString = dataString.c_str();
1070 //The data is not an XML-string, it must be a filename
1071 std::wstring filename = env::data_folder();
1072 filename.append(dataString);
1073 filename.append(TEXT(".ftd"));
1075 dataFromFile = read_file(boost::filesystem::wpath(filename));
1076 pDataString = dataFromFile.c_str();
1080 std::wstring fullFilename = flash::find_template(env::template_folder() + parameters()[2]);
1081 if(!fullFilename.empty())
1083 std::wstring extension = boost::filesystem::path(fullFilename).extension().wstring();
1084 std::wstring filename = parameters()[2];
1085 filename.append(extension);
1087 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(""));
1088 SetReplyString(TEXT("202 CG OK\r\n"));
1092 CASPAR_LOG(warning) << "Could not find template " << parameters()[2];
1093 SetReplyString(TEXT("404 CG ERROR\r\n"));
1098 bool CGCommand::DoExecutePlay()
1100 if(parameters().size() > 1)
1102 if(!ValidateLayer(parameters()[1]))
1104 SetReplyString(TEXT("403 CG ERROR\r\n"));
1107 int layer = boost::lexical_cast<int>(parameters()[1]);
1108 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).play(layer);
1112 SetReplyString(TEXT("402 CG ERROR\r\n"));
1116 SetReplyString(TEXT("202 CG OK\r\n"));
1120 bool CGCommand::DoExecuteStop()
1122 if(parameters().size() > 1)
1124 if(!ValidateLayer(parameters()[1]))
1126 SetReplyString(TEXT("403 CG ERROR\r\n"));
1129 int layer = boost::lexical_cast<int>(parameters()[1]);
1130 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).stop(layer, 0);
1134 SetReplyString(TEXT("402 CG ERROR\r\n"));
1138 SetReplyString(TEXT("202 CG OK\r\n"));
1142 bool CGCommand::DoExecuteNext()
1144 if(parameters().size() > 1)
1146 if(!ValidateLayer(parameters()[1]))
1148 SetReplyString(TEXT("403 CG ERROR\r\n"));
1152 int layer = boost::lexical_cast<int>(parameters()[1]);
1153 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).next(layer);
1157 SetReplyString(TEXT("402 CG ERROR\r\n"));
1161 SetReplyString(TEXT("202 CG OK\r\n"));
1165 bool CGCommand::DoExecuteRemove()
1167 if(parameters().size() > 1)
1169 if(!ValidateLayer(parameters()[1]))
1171 SetReplyString(TEXT("403 CG ERROR\r\n"));
1175 int layer = boost::lexical_cast<int>(parameters()[1]);
1176 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).remove(layer);
1180 SetReplyString(TEXT("402 CG ERROR\r\n"));
1184 SetReplyString(TEXT("202 CG OK\r\n"));
1188 bool CGCommand::DoExecuteClear()
1190 GetChannel()->stage().clear(GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER));
1191 SetReplyString(TEXT("202 CG OK\r\n"));
1195 bool CGCommand::DoExecuteUpdate()
1199 if(!ValidateLayer(parameters().at(1)))
1201 SetReplyString(TEXT("403 CG ERROR\r\n"));
1205 std::wstring dataString = parameters().at(2);
1206 if(dataString.at(0) != TEXT('<'))
1208 //The data is not an XML-string, it must be a filename
1209 std::wstring filename = env::data_folder();
1210 filename.append(dataString);
1211 filename.append(TEXT(".ftd"));
1213 dataString = read_file(boost::filesystem::wpath(filename));
1216 int layer = boost::lexical_cast<int>(parameters()[1]);
1217 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).update(layer, dataString);
1221 SetReplyString(TEXT("402 CG ERROR\r\n"));
1225 SetReplyString(TEXT("202 CG OK\r\n"));
1229 bool CGCommand::DoExecuteInvoke()
1231 std::wstringstream replyString;
1232 replyString << TEXT("201 CG OK\r\n");
1234 if(parameters().size() > 2)
1236 if(!ValidateLayer(parameters()[1]))
1238 SetReplyString(TEXT("403 CG ERROR\r\n"));
1241 int layer = boost::lexical_cast<int>(parameters()[1]);
1242 auto result = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).invoke(layer, parameters()[2]);
1243 replyString << result << TEXT("\r\n");
1247 SetReplyString(TEXT("402 CG ERROR\r\n"));
1251 SetReplyString(replyString.str());
1255 bool CGCommand::DoExecuteInfo()
1257 std::wstringstream replyString;
1258 replyString << TEXT("201 CG OK\r\n");
1260 if(parameters().size() > 1)
1262 if(!ValidateLayer(parameters()[1]))
1264 SetReplyString(TEXT("403 CG ERROR\r\n"));
1268 int layer = boost::lexical_cast<int>(parameters()[1]);
1269 auto desc = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).description(layer);
1271 replyString << desc << TEXT("\r\n");
1275 auto info = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).template_host_info();
1276 replyString << info << TEXT("\r\n");
1279 SetReplyString(replyString.str());
1283 bool DataCommand::DoExecute()
1285 std::wstring command = boost::to_upper_copy(parameters()[0]);
1286 if(command == TEXT("STORE"))
1287 return DoExecuteStore();
1288 else if(command == TEXT("RETRIEVE"))
1289 return DoExecuteRetrieve();
1290 else if(command == TEXT("REMOVE"))
1291 return DoExecuteRemove();
1292 else if(command == TEXT("LIST"))
1293 return DoExecuteList();
1295 SetReplyString(TEXT("403 DATA ERROR\r\n"));
1299 bool DataCommand::DoExecuteStore()
1301 if(parameters().size() < 3)
1303 SetReplyString(TEXT("402 DATA STORE ERROR\r\n"));
1307 std::wstring filename = env::data_folder();
1308 filename.append(parameters()[1]);
1309 filename.append(TEXT(".ftd"));
1311 auto data_path = boost::filesystem::wpath(
1312 boost::filesystem::wpath(filename).parent_path());
1314 if(!boost::filesystem::exists(data_path))
1315 boost::filesystem::create_directories(data_path);
1317 std::wofstream datafile(filename.c_str());
1320 SetReplyString(TEXT("501 DATA STORE FAILED\r\n"));
1324 datafile << static_cast<wchar_t>(65279); // UTF-8 BOM character
1325 datafile << parameters()[2] << std::flush;
1328 std::wstring replyString = TEXT("202 DATA STORE OK\r\n");
1329 SetReplyString(replyString);
1333 bool DataCommand::DoExecuteRetrieve()
1335 if(parameters().size() < 2)
1337 SetReplyString(TEXT("402 DATA RETRIEVE ERROR\r\n"));
1341 std::wstring filename = env::data_folder();
1342 filename.append(parameters()[1]);
1343 filename.append(TEXT(".ftd"));
1345 std::wstring file_contents = read_file(boost::filesystem::wpath(filename));
1347 if (file_contents.empty())
1349 SetReplyString(TEXT("404 DATA RETRIEVE ERROR\r\n"));
1353 std::wstringstream reply(TEXT("201 DATA RETRIEVE OK\r\n"));
1355 reply << file_contents;
1357 SetReplyString(reply.str());
1361 bool DataCommand::DoExecuteRemove()
1363 if (parameters().size() < 2)
1365 SetReplyString(TEXT("402 DATA REMOVE ERROR\r\n"));
1369 std::wstring filename = env::data_folder();
1370 filename.append(parameters()[1]);
1371 filename.append(TEXT(".ftd"));
1373 if (!boost::filesystem::exists(filename))
1375 SetReplyString(TEXT("404 DATA REMOVE ERROR\r\n"));
1379 if (!boost::filesystem::remove(filename))
1381 SetReplyString(TEXT("403 DATA REMOVE ERROR\r\n"));
1385 SetReplyString(TEXT("201 DATA REMOVE OK\r\n"));
1390 bool DataCommand::DoExecuteList()
1392 std::wstringstream replyString;
1393 replyString << TEXT("200 DATA LIST OK\r\n");
1395 for (boost::filesystem::recursive_directory_iterator itr(env::data_folder()), end; itr != end; ++itr)
1397 if(boost::filesystem::is_regular_file(itr->path()))
1399 if(!boost::iequals(itr->path().extension().wstring(), L".ftd"))
1402 auto relativePath = boost::filesystem::wpath(itr->path().wstring().substr(env::data_folder().size()-1, itr->path().wstring().size()));
1404 auto str = relativePath.replace_extension(TEXT("")).native();
1405 if(str[0] == '\\' || str[0] == '/')
1406 str = std::wstring(str.begin() + 1, str.end());
1408 replyString << str << TEXT("\r\n");
1412 replyString << TEXT("\r\n");
1414 SetReplyString(boost::to_upper_copy(replyString.str()));
1418 bool CinfCommand::DoExecute()
1420 std::wstringstream replyString;
1425 for (boost::filesystem::recursive_directory_iterator itr(env::media_folder()), end; itr != end && info.empty(); ++itr)
1427 auto path = itr->path();
1428 auto file = path.replace_extension(L"").filename();
1429 if(boost::iequals(file.wstring(), parameters().at(0)))
1430 info += MediaInfo(itr->path()) + L"\r\n";
1435 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1438 replyString << TEXT("200 CINF OK\r\n");
1439 replyString << info << "\r\n";
1443 CASPAR_LOG_CURRENT_EXCEPTION();
1444 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1448 SetReplyString(replyString.str());
1452 void GenerateChannelInfo(int index, const spl::shared_ptr<core::video_channel>& pChannel, std::wstringstream& replyString)
1454 replyString << index+1 << TEXT(" ") << pChannel->video_format_desc().name << TEXT(" PLAYING") << TEXT("\r\n");
1457 bool InfoCommand::DoExecute()
1459 std::wstringstream replyString;
1461 boost::property_tree::xml_writer_settings<wchar_t> w(' ', 3);
1465 if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"TEMPLATE"))
1467 replyString << L"201 INFO TEMPLATE OK\r\n";
1469 // Needs to be extended for any file, not just flash.
1471 auto filename = flash::find_template(env::template_folder() + parameters().at(1));
1473 std::wstringstream str;
1474 str << u16(flash::read_template_meta_info(filename));
1475 boost::property_tree::wptree info;
1476 boost::property_tree::xml_parser::read_xml(str, info, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
1478 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1480 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"CONFIG"))
1482 replyString << L"201 INFO CONFIG OK\r\n";
1484 boost::property_tree::write_xml(replyString, caspar::env::properties(), w);
1486 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"PATHS"))
1488 replyString << L"201 INFO PATHS OK\r\n";
1490 boost::property_tree::wptree info;
1491 info.add_child(L"paths", caspar::env::properties().get_child(L"configuration.paths"));
1492 info.add(L"paths.initial-path", boost::filesystem3::initial_path().wstring() + L"\\");
1494 boost::property_tree::write_xml(replyString, info, w);
1496 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"SYSTEM"))
1498 replyString << L"201 INFO SYSTEM OK\r\n";
1500 boost::property_tree::wptree info;
1502 info.add(L"system.name", caspar::system_product_name());
1503 info.add(L"system.windows.name", caspar::win_product_name());
1504 info.add(L"system.windows.service-pack", caspar::win_sp_version());
1505 info.add(L"system.cpu", caspar::cpu_info());
1507 BOOST_FOREACH(auto device, caspar::decklink::device_list())
1508 info.add(L"system.decklink.device", device);
1510 BOOST_FOREACH(auto device, caspar::bluefish::device_list())
1511 info.add(L"system.bluefish.device", device);
1513 info.add(L"system.flash", caspar::flash::version());
1514 //info.add(L"system.free-image", caspar::image::version());
1515 info.add(L"system.ffmpeg.avcodec", caspar::ffmpeg::avcodec_version());
1516 info.add(L"system.ffmpeg.avformat", caspar::ffmpeg::avformat_version());
1517 info.add(L"system.ffmpeg.avfilter", caspar::ffmpeg::avfilter_version());
1518 info.add(L"system.ffmpeg.avutil", caspar::ffmpeg::avutil_version());
1519 info.add(L"system.ffmpeg.swscale", caspar::ffmpeg::swscale_version());
1521 boost::property_tree::write_xml(replyString, info, w);
1523 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"SERVER"))
1525 replyString << L"201 INFO SERVER OK\r\n";
1527 boost::property_tree::wptree info;
1530 BOOST_FOREACH(auto channel, channels_)
1531 info.add_child(L"channels.channel", channel->info())
1532 .add(L"index", ++index);
1534 boost::property_tree::write_xml(replyString, info, w);
1538 if(parameters().size() >= 1)
1540 replyString << TEXT("201 INFO OK\r\n");
1541 boost::property_tree::wptree info;
1543 std::vector<std::wstring> split;
1544 boost::split(split, parameters()[0], boost::is_any_of("-"));
1546 int layer = std::numeric_limits<int>::min();
1547 int channel = boost::lexical_cast<int>(split[0]) - 1;
1549 if(split.size() > 1)
1550 layer = boost::lexical_cast<int>(split[1]);
1552 if(layer == std::numeric_limits<int>::min())
1554 info.add_child(L"channel", channels_.at(channel)->info())
1555 .add(L"index", channel);
1559 if(parameters().size() >= 2)
1561 if(boost::iequals(parameters()[1], L"B"))
1562 info.add_child(L"producer", channels_.at(channel)->stage().background(layer).get()->info());
1564 info.add_child(L"producer", channels_.at(channel)->stage().foreground(layer).get()->info());
1568 info.add_child(L"layer", channels_.at(channel)->stage().info(layer).get())
1569 .add(L"index", layer);
1572 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1576 // This is needed for backwards compatibility with old clients
1577 replyString << TEXT("200 INFO OK\r\n");
1578 for(size_t n = 0; n < channels_.size(); ++n)
1579 GenerateChannelInfo(n, channels_[n], replyString);
1586 CASPAR_LOG_CURRENT_EXCEPTION();
1587 SetReplyString(TEXT("403 INFO ERROR\r\n"));
1591 replyString << TEXT("\r\n");
1592 SetReplyString(replyString.str());
1596 bool ClsCommand::DoExecute()
1608 std::wstringstream replyString;
1609 replyString << TEXT("200 CLS OK\r\n");
1610 replyString << ListMedia();
1611 replyString << TEXT("\r\n");
1612 SetReplyString(boost::to_upper_copy(replyString.str()));
1616 CASPAR_LOG_CURRENT_EXCEPTION();
1617 SetReplyString(TEXT("501 CLS FAILED\r\n"));
1624 bool TlsCommand::DoExecute()
1628 std::wstringstream replyString;
1629 replyString << TEXT("200 TLS OK\r\n");
1631 replyString << ListTemplates();
1632 replyString << TEXT("\r\n");
1634 SetReplyString(replyString.str());
1638 CASPAR_LOG_CURRENT_EXCEPTION();
1639 SetReplyString(TEXT("501 TLS FAILED\r\n"));
1645 bool VersionCommand::DoExecute()
1647 std::wstring replyString = TEXT("201 VERSION OK\r\n") + env::version() + TEXT("\r\n");
1649 if(parameters().size() > 0)
1651 if(boost::iequals(parameters()[0], L"FLASH"))
1652 replyString = TEXT("201 VERSION OK\r\n") + flash::version() + TEXT("\r\n");
1653 else if(boost::iequals(parameters()[0], L"TEMPLATEHOST"))
1654 replyString = TEXT("201 VERSION OK\r\n") + flash::cg_version() + TEXT("\r\n");
1655 else if(!boost::iequals(parameters()[0], L"SERVER"))
1656 replyString = TEXT("403 VERSION ERROR\r\n");
1659 SetReplyString(replyString);
1663 bool ByeCommand::DoExecute()
1665 GetClientInfo()->Disconnect();
1669 bool SetCommand::DoExecute()
1673 std::wstring name = boost::to_upper_copy(parameters()[0]);
1674 std::wstring value = boost::to_upper_copy(parameters()[1]);
1676 if(name == TEXT("MODE"))
1678 auto format_desc = core::video_format_desc(value);
1679 if(format_desc.format != core::video_format::invalid)
1681 GetChannel()->video_format_desc(format_desc);
1682 SetReplyString(TEXT("202 SET MODE OK\r\n"));
1685 SetReplyString(TEXT("501 SET MODE FAILED\r\n"));
1689 this->SetReplyString(TEXT("403 SET ERROR\r\n"));
1694 CASPAR_LOG_CURRENT_EXCEPTION();
1695 SetReplyString(TEXT("501 SET FAILED\r\n"));
1704 }} //namespace caspar