2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Nicklas P Andersson
22 #include "../StdAfx.h"
25 #pragma warning (push, 1) // TODO: Legacy code, just disable warnings
28 #include "AMCPCommandsImpl.h"
29 #include "AMCPProtocolStrategy.h"
31 #include <common/env.h>
33 #include <common/log.h>
34 #include <common/diagnostics/graph.h>
35 #include <common/os/windows/current_version.h>
36 #include <common/os/windows/system_info.h>
38 #include <core/producer/frame_producer.h>
39 #include <core/video_format.h>
40 #include <core/producer/transition/transition_producer.h>
41 #include <core/frame/frame_transform.h>
42 #include <core/producer/stage.h>
43 #include <core/producer/layer.h>
44 #include <core/mixer/mixer.h>
45 #include <core/consumer/output.h>
47 #include <modules/reroute/producer/reroute_producer.h>
48 #include <modules/bluefish/bluefish.h>
49 #include <modules/decklink/decklink.h>
50 #include <modules/ffmpeg/ffmpeg.h>
51 #include <modules/flash/flash.h>
52 #include <modules/flash/util/swf.h>
53 #include <modules/flash/producer/flash_producer.h>
54 #include <modules/flash/producer/cg_proxy.h>
55 #include <modules/ffmpeg/producer/util/util.h>
56 #include <modules/image/image.h>
57 #include <modules/screen/screen.h>
58 #include <modules/reroute/producer/reroute_producer.h>
67 #include <boost/date_time/posix_time/posix_time.hpp>
68 #include <boost/lexical_cast.hpp>
69 #include <boost/algorithm/string.hpp>
70 #include <boost/filesystem.hpp>
71 #include <boost/filesystem/fstream.hpp>
72 #include <boost/regex.hpp>
73 #include <boost/property_tree/xml_parser.hpp>
74 #include <boost/locale.hpp>
75 #include <boost/range/adaptor/transformed.hpp>
76 #include <boost/range/algorithm/copy.hpp>
78 #include <tbb/concurrent_unordered_map.h>
82 100 [action] Information om att något har hänt
83 101 [action] Information om att något har hänt, en rad data skickas
85 202 [kommando] OK Kommandot har utförts
86 201 [kommando] OK Kommandot har utförts, och en rad data skickas tillbaka
87 200 [kommando] OK Kommandot har utförts, och flera rader data skickas tillbaka. Avslutas med tomrad
89 400 ERROR Kommandot kunde inte förstås
90 401 [kommando] ERROR Ogiltig kanal
91 402 [kommando] ERROR Parameter saknas
92 403 [kommando] ERROR Ogiltig parameter
93 404 [kommando] ERROR Mediafilen hittades inte
95 500 FAILED Internt configurationfel
96 501 [kommando] FAILED Internt configurationfel
97 502 [kommando] FAILED Oläslig mediafil
99 600 [kommando] FAILED funktion ej implementerad
102 namespace caspar { namespace protocol {
104 using namespace core;
106 std::wstring read_utf8_file(const boost::filesystem::wpath& file)
108 std::wstringstream result;
109 boost::filesystem::wifstream filestream(file);
116 result << filestream.rdbuf();
122 std::wstring read_latin1_file(const boost::filesystem::wpath& file)
124 boost::locale::generator gen;
125 gen.locale_cache_enabled(true);
126 gen.categories(boost::locale::codepage_facet);
128 std::stringstream result_stream;
129 boost::filesystem::ifstream filestream(file);
130 filestream.imbue(gen("en_US.ISO8859-1"));
135 result_stream << filestream.rdbuf();
138 std::string result = result_stream.str();
139 std::wstring widened_result;
141 // The first 255 codepoints in unicode is the same as in latin1
142 auto from_signed_to_signed = std::function<unsigned char(char)>(
143 [] (char c) { return static_cast<unsigned char>(c); }
146 result | boost::adaptors::transformed(from_signed_to_signed),
147 std::back_inserter(widened_result));
149 return widened_result;
152 std::wstring read_file(const boost::filesystem::wpath& file)
154 static const uint8_t BOM[] = {0xef, 0xbb, 0xbf};
156 if (!boost::filesystem::exists(file))
161 if (boost::filesystem::file_size(file) >= 3)
163 boost::filesystem::ifstream bom_stream(file);
166 bom_stream.read(header, 3);
169 if (std::memcmp(BOM, header, 3) == 0)
170 return read_utf8_file(file);
173 return read_latin1_file(file);
176 std::wstring MediaInfo(const boost::filesystem::path& path)
178 if(boost::filesystem::is_regular_file(path))
180 std::wstring clipttype = TEXT("N/A");
181 std::wstring extension = boost::to_upper_copy(path.extension().wstring());
182 if(extension == TEXT(".TGA") || extension == TEXT(".COL") || extension == L".PNG" || extension == L".JPEG" || extension == L".JPG" ||
183 extension == L"GIF" || extension == L"BMP")
184 clipttype = TEXT("STILL");
185 else if(extension == TEXT(".WAV") || extension == TEXT(".MP3"))
186 clipttype = TEXT("AUDIO");
187 else if(extension == TEXT("SWF") || extension == TEXT("CT") || extension == TEXT("DV") || extension == TEXT("MOV") || extension == TEXT("MPG") || extension == TEXT("AVI") || caspar::ffmpeg::is_valid_file(path.wstring()))
188 clipttype = TEXT("MOVIE");
190 if(clipttype != TEXT("N/A"))
192 auto is_not_digit = [](char c){ return std::isdigit(c) == 0; };
194 auto relativePath = boost::filesystem::path(path.wstring().substr(env::media_folder().size()-1, path.wstring().size()));
196 auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(path)));
197 writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), is_not_digit), writeTimeStr.end());
198 auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end());
200 auto sizeStr = boost::lexical_cast<std::wstring>(boost::filesystem::file_size(path));
201 sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), is_not_digit), sizeStr.end());
202 auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end());
204 auto str = relativePath.replace_extension(TEXT("")).native();
205 while(str.size() > 0 && (str[0] == '\\' || str[0] == '/'))
206 str = std::wstring(str.begin() + 1, str.end());
208 return std::wstring() + TEXT("\"") + str +
209 + TEXT("\" ") + clipttype +
210 + TEXT(" ") + sizeStr +
211 + TEXT(" ") + writeTimeWStr +
218 std::wstring ListMedia()
220 std::wstringstream replyString;
221 for (boost::filesystem::recursive_directory_iterator itr(env::media_folder()), end; itr != end; ++itr)
222 replyString << MediaInfo(itr->path());
224 return boost::to_upper_copy(replyString.str());
227 std::wstring ListTemplates()
229 std::wstringstream replyString;
231 for (boost::filesystem::recursive_directory_iterator itr(env::template_folder()), end; itr != end; ++itr)
233 if(boost::filesystem::is_regular_file(itr->path()) && (itr->path().extension() == L".ft" || itr->path().extension() == L".ct"))
235 auto relativePath = boost::filesystem::wpath(itr->path().wstring().substr(env::template_folder().size()-1, itr->path().wstring().size()));
237 auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(itr->path())));
238 writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), [](char c){ return std::isdigit(c) == 0;}), writeTimeStr.end());
239 auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end());
241 auto sizeStr = boost::lexical_cast<std::string>(boost::filesystem::file_size(itr->path()));
242 sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), [](char c){ return std::isdigit(c) == 0;}), sizeStr.end());
244 auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end());
246 std::wstring dir = relativePath.parent_path().native();
247 std::wstring file = boost::to_upper_copy(relativePath.filename().wstring());
248 relativePath = boost::filesystem::wpath(dir + L"/" + file);
250 auto str = relativePath.replace_extension(TEXT("")).native();
251 boost::trim_if(str, boost::is_any_of("\\/"));
253 replyString << TEXT("\"") << str
254 << TEXT("\" ") << sizeWStr
255 << TEXT(" ") << writeTimeWStr
259 return replyString.str();
264 AMCPCommand::AMCPCommand() : channelIndex_(0), layerIndex_(-1)
267 void AMCPCommand::SendReply()
272 if(replyString_.empty())
274 pClientInfo_->Send(replyString_);
277 void AMCPCommand::Clear()
279 pChannel_->stage().clear();
280 pClientInfo_.reset();
285 bool DiagnosticsCommand::DoExecute()
289 diagnostics::show_graphs(true);
291 SetReplyString(TEXT("202 DIAG OK\r\n"));
297 CASPAR_LOG_CURRENT_EXCEPTION();
298 SetReplyString(TEXT("502 DIAG FAILED\r\n"));
303 bool ChannelGridCommand::DoExecute()
305 CASPAR_THROW_EXCEPTION(not_implemented());
308 //auto self = GetChannels().back();
310 //std::vector<std::wstring> params;
311 //params.push_back(L"SCREEN");
312 //params.push_back(L"NAME");
313 //params.push_back(L"Channel Grid Window");
314 //auto screen = create_consumer(params);
316 //self->output().add(screen);
318 //BOOST_FOREACH(auto channel, GetChannels())
320 // if(channel != self)
322 // auto producer = reroute::create_producer(self->frame_factory(), *channel);
323 // self->stage().load(index, producer, false);
324 // self->stage().play(index);
329 //int n = GetChannels().size()-1;
330 //double delta = 1.0/static_cast<double>(n);
331 //for(int x = 0; x < n; ++x)
333 // for(int y = 0; y < n; ++y)
335 // int index = x+y*n+1;
336 // auto transform = [=](frame_transform transform) -> frame_transform
338 // transform.image_transform.fill_translation[0] = x*delta;
339 // transform.image_transform.fill_translation[1] = y*delta;
340 // transform.image_transform.fill_scale[0] = delta;
341 // transform.image_transform.fill_scale[1] = delta;
342 // transform.image_transform.clip_translation[0] = x*delta;
343 // transform.image_transform.clip_translation[1] = y*delta;
344 // transform.image_transform.clip_scale[0] = delta;
345 // transform.image_transform.clip_scale[1] = delta;
348 // self->stage().apply_transform(index, transform);
355 bool CallCommand::DoExecute()
357 //Perform loading of the clip
360 auto what = _parameters.at(0);
363 for(auto it = std::begin(_parameters2); it != std::end(_parameters2); ++it, param += L" ")
366 auto result = GetChannel()->stage().call(GetLayerIndex(), boost::trim_copy(param));
368 if(!result.timed_wait(boost::posix_time::seconds(2)))
369 CASPAR_THROW_EXCEPTION(timed_out());
371 std::wstringstream replyString;
372 if(result.get().empty())
373 replyString << TEXT("202 CALL OK\r\n");
375 replyString << TEXT("201 CALL OK\r\n") << result.get() << L"\r\n";
377 SetReplyString(replyString.str());
383 CASPAR_LOG_CURRENT_EXCEPTION();
384 SetReplyString(TEXT("502 CALL FAILED\r\n"));
389 tbb::concurrent_unordered_map<int, std::vector<stage::transform_tuple_t>> deferred_transforms;
391 bool MixerCommand::DoExecute()
393 //Perform loading of the clip
396 bool defer = _parameters.back() == L"DEFER";
398 _parameters.pop_back();
400 std::vector<stage::transform_tuple_t> transforms;
402 if(_parameters[0] == L"KEYER" || _parameters[0] == L"IS_KEY")
404 bool value = boost::lexical_cast<int>(_parameters.at(1));
405 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
407 transform.image_transform.is_key = value;
411 else if(_parameters[0] == L"OPACITY")
413 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
414 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
416 double value = boost::lexical_cast<double>(_parameters.at(1));
418 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
420 transform.image_transform.opacity = value;
422 }, duration, tween));
424 else if(_parameters[0] == L"FILL" || _parameters[0] == L"FILL_RECT")
426 int duration = _parameters.size() > 5 ? boost::lexical_cast<int>(_parameters[5]) : 0;
427 std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear";
428 double x = boost::lexical_cast<double>(_parameters.at(1));
429 double y = boost::lexical_cast<double>(_parameters.at(2));
430 double x_s = boost::lexical_cast<double>(_parameters.at(3));
431 double y_s = boost::lexical_cast<double>(_parameters.at(4));
433 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) mutable -> frame_transform
435 transform.image_transform.fill_translation[0] = x;
436 transform.image_transform.fill_translation[1] = y;
437 transform.image_transform.fill_scale[0] = x_s;
438 transform.image_transform.fill_scale[1] = y_s;
439 transform.image_transform.clip_translation[0] = x;
440 transform.image_transform.clip_translation[1] = y;
441 transform.image_transform.clip_scale[0] = x_s;
442 transform.image_transform.clip_scale[1] = y_s;
444 }, duration, tween));
446 else if(_parameters[0] == L"CLIP" || _parameters[0] == L"CLIP_RECT")
448 int duration = _parameters.size() > 5 ? boost::lexical_cast<int>(_parameters[5]) : 0;
449 std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear";
450 double x = boost::lexical_cast<double>(_parameters.at(1));
451 double y = boost::lexical_cast<double>(_parameters.at(2));
452 double x_s = boost::lexical_cast<double>(_parameters.at(3));
453 double y_s = boost::lexical_cast<double>(_parameters.at(4));
455 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
457 transform.image_transform.clip_translation[0] = x;
458 transform.image_transform.clip_translation[1] = y;
459 transform.image_transform.clip_scale[0] = x_s;
460 transform.image_transform.clip_scale[1] = y_s;
462 }, duration, tween));
464 else if(_parameters[0] == L"GRID")
466 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
467 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
468 int n = boost::lexical_cast<int>(_parameters.at(1));
469 double delta = 1.0/static_cast<double>(n);
470 for(int x = 0; x < n; ++x)
472 for(int y = 0; y < n; ++y)
475 transforms.push_back(stage::transform_tuple_t(index, [=](frame_transform transform) -> frame_transform
477 transform.image_transform.fill_translation[0] = x*delta;
478 transform.image_transform.fill_translation[1] = y*delta;
479 transform.image_transform.fill_scale[0] = delta;
480 transform.image_transform.fill_scale[1] = delta;
481 transform.image_transform.clip_translation[0] = x*delta;
482 transform.image_transform.clip_translation[1] = y*delta;
483 transform.image_transform.clip_scale[0] = delta;
484 transform.image_transform.clip_scale[1] = delta;
486 }, duration, tween));
490 else if(_parameters[0] == L"BLEND")
492 auto blend_str = _parameters.at(1);
493 int layer = GetLayerIndex();
494 GetChannel()->mixer().set_blend_mode(GetLayerIndex(), get_blend_mode(blend_str));
496 else if(_parameters[0] == L"BRIGHTNESS")
498 auto value = boost::lexical_cast<double>(_parameters.at(1));
499 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
500 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
501 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
503 transform.image_transform.brightness = value;
505 }, duration, tween));
507 else if(_parameters[0] == L"SATURATION")
509 auto value = boost::lexical_cast<double>(_parameters.at(1));
510 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
511 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
512 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
514 transform.image_transform.saturation = value;
516 }, duration, tween));
518 else if(_parameters[0] == L"CONTRAST")
520 auto value = boost::lexical_cast<double>(_parameters.at(1));
521 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
522 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
523 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
525 transform.image_transform.contrast = value;
527 }, duration, tween));
529 else if(_parameters[0] == L"LEVELS")
532 value.min_input = boost::lexical_cast<double>(_parameters.at(1));
533 value.max_input = boost::lexical_cast<double>(_parameters.at(2));
534 value.gamma = boost::lexical_cast<double>(_parameters.at(3));
535 value.min_output = boost::lexical_cast<double>(_parameters.at(4));
536 value.max_output = boost::lexical_cast<double>(_parameters.at(5));
537 int duration = _parameters.size() > 6 ? boost::lexical_cast<int>(_parameters[6]) : 0;
538 std::wstring tween = _parameters.size() > 7 ? _parameters[7] : L"linear";
540 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
542 transform.image_transform.levels = value;
544 }, duration, tween));
546 else if(_parameters[0] == L"VOLUME")
548 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
549 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
550 double value = boost::lexical_cast<double>(_parameters[1]);
552 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
554 transform.audio_transform.volume = value;
556 }, duration, tween));
558 else if(_parameters[0] == L"CLEAR")
560 int layer = GetLayerIndex(std::numeric_limits<int>::max());
561 if(layer == std::numeric_limits<int>::max())
562 GetChannel()->stage().clear_transforms();
564 GetChannel()->stage().clear_transforms(layer);
566 else if(_parameters[0] == L"COMMIT")
568 transforms = std::move(deferred_transforms[GetChannelIndex()]);
572 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
578 auto& defer_tranforms = deferred_transforms[GetChannelIndex()];
579 defer_tranforms.insert(defer_tranforms.end(), transforms.begin(), transforms.end());
582 GetChannel()->stage().apply_transforms(transforms);
584 SetReplyString(TEXT("202 MIXER OK\r\n"));
588 catch(file_not_found&)
590 CASPAR_LOG_CURRENT_EXCEPTION();
591 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
596 CASPAR_LOG_CURRENT_EXCEPTION();
597 SetReplyString(TEXT("502 MIXER FAILED\r\n"));
602 bool SwapCommand::DoExecute()
604 //Perform loading of the clip
607 if(GetLayerIndex(-1) != -1)
609 std::vector<std::string> strs;
610 boost::split(strs, _parameters[0], boost::is_any_of("-"));
612 auto ch1 = GetChannel();
613 auto ch2 = GetChannels().at(boost::lexical_cast<int>(strs.at(0))-1);
615 int l1 = GetLayerIndex();
616 int l2 = boost::lexical_cast<int>(strs.at(1));
618 ch1->stage().swap_layer(l1, l2, ch2->stage());
622 auto ch1 = GetChannel();
623 auto ch2 = GetChannels().at(boost::lexical_cast<int>(_parameters[0])-1);
624 ch1->stage().swap_layers(ch2->stage());
627 SetReplyString(TEXT("202 SWAP OK\r\n"));
631 catch(file_not_found&)
633 CASPAR_LOG_CURRENT_EXCEPTION();
634 SetReplyString(TEXT("404 SWAP ERROR\r\n"));
639 CASPAR_LOG_CURRENT_EXCEPTION();
640 SetReplyString(TEXT("502 SWAP FAILED\r\n"));
645 bool AddCommand::DoExecute()
647 //Perform loading of the clip
650 auto consumer = create_consumer(_parameters);
651 GetChannel()->output().add(GetLayerIndex(consumer->index()), consumer);
653 SetReplyString(TEXT("202 ADD OK\r\n"));
657 catch(file_not_found&)
659 CASPAR_LOG_CURRENT_EXCEPTION();
660 SetReplyString(TEXT("404 ADD ERROR\r\n"));
665 CASPAR_LOG_CURRENT_EXCEPTION();
666 SetReplyString(TEXT("502 ADD FAILED\r\n"));
671 bool RemoveCommand::DoExecute()
673 //Perform loading of the clip
676 auto index = GetLayerIndex(std::numeric_limits<int>::min());
677 if(index == std::numeric_limits<int>::min())
678 index = create_consumer(_parameters)->index();
680 GetChannel()->output().remove(index);
682 SetReplyString(TEXT("202 REMOVE OK\r\n"));
686 catch(file_not_found&)
688 CASPAR_LOG_CURRENT_EXCEPTION();
689 SetReplyString(TEXT("404 REMOVE ERROR\r\n"));
694 CASPAR_LOG_CURRENT_EXCEPTION();
695 SetReplyString(TEXT("502 REMOVE FAILED\r\n"));
700 bool LoadCommand::DoExecute()
702 //Perform loading of the clip
705 _parameters[0] = _parameters[0];
706 auto pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), _parameters);
707 GetChannel()->stage().load(GetLayerIndex(), pFP, true);
709 SetReplyString(TEXT("202 LOAD OK\r\n"));
713 catch(file_not_found&)
715 CASPAR_LOG_CURRENT_EXCEPTION();
716 SetReplyString(TEXT("404 LOAD ERROR\r\n"));
721 CASPAR_LOG_CURRENT_EXCEPTION();
722 SetReplyString(TEXT("502 LOAD FAILED\r\n"));
729 //std::function<std::wstring()> channel_cg_add_command::parse(const std::wstring& message, const std::vector<renderer::render_device_ptr>& channels)
731 // 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>.*)?");
733 // boost::wsmatch what;
734 // if(!boost::regex_match(message, what, expr))
737 // auto info = channel_info::parse(what, channels);
739 // int flash_layer_index = boost::lexical_cast<int>(what["FLASH_LAYER"].str());
741 // std::wstring templatename = what["TEMPLATE"].str();
742 // bool play_on_load = what["PLAY_ON_LOAD"].matched ? what["PLAY_ON_LOAD"].str() != L"0" : 0;
743 // std::wstring start_label = what["START_LABEL"].str();
744 // std::wstring data = get_data(what["DATA"].str());
746 // boost::replace_all(templatename, "\"", "");
748 // return [=]() -> std::wstring
750 // std::wstring fullFilename = flash::flash_producer::find_template(server::template_folder() + templatename);
751 // if(fullFilename.empty())
752 // CASPAR_THROW_EXCEPTION(file_not_found());
754 // std::wstring extension = boost::filesystem::wpath(fullFilename).extension();
755 // std::wstring filename = templatename;
756 // filename.append(extension);
758 // flash::flash::create_cg_proxy(info.video_channel, std::max<int>(DEFAULT_CHANNEL_LAYER+1, info.layer_index))
759 // ->add(flash_layer_index, filename, play_on_load, start_label, data);
761 // CASPAR_LOG(info) << L"Executed [amcp_channel_cg_add]";
765 bool LoadbgCommand::DoExecute()
767 transition_info transitionInfo;
773 std::wstring message;
774 for(size_t n = 0; n < _parameters.size(); ++n)
775 message += _parameters[n] + L" ";
777 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)?.*");
779 if(boost::regex_match(message, what, expr))
781 auto transition = what["TRANSITION"].str();
782 transitionInfo.duration = boost::lexical_cast<size_t>(what["DURATION"].str());
783 auto direction = what["DIRECTION"].matched ? what["DIRECTION"].str() : L"";
784 auto tween = what["TWEEN"].matched ? what["TWEEN"].str() : L"";
785 transitionInfo.tweener = tween;
787 if(transition == TEXT("CUT"))
788 transitionInfo.type = transition_type::cut;
789 else if(transition == TEXT("MIX"))
790 transitionInfo.type = transition_type::mix;
791 else if(transition == TEXT("PUSH"))
792 transitionInfo.type = transition_type::push;
793 else if(transition == TEXT("SLIDE"))
794 transitionInfo.type = transition_type::slide;
795 else if(transition == TEXT("WIPE"))
796 transitionInfo.type = transition_type::wipe;
798 if(direction == TEXT("FROMLEFT"))
799 transitionInfo.direction = transition_direction::from_left;
800 else if(direction == TEXT("FROMRIGHT"))
801 transitionInfo.direction = transition_direction::from_right;
802 else if(direction == TEXT("LEFT"))
803 transitionInfo.direction = transition_direction::from_right;
804 else if(direction == TEXT("RIGHT"))
805 transitionInfo.direction = transition_direction::from_left;
808 //Perform loading of the clip
811 std::shared_ptr<core::frame_producer> pFP;
813 static boost::wregex expr(L"\\[(?<CHANNEL>\\d+)\\]", boost::regex::icase);
816 if(boost::regex_match(_parameters.at(0), what, expr))
818 auto channel_index = boost::lexical_cast<int>(what["CHANNEL"].str());
819 pFP = reroute::create_producer(*GetChannels().at(channel_index-1));
822 pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), _parameters);
824 if(pFP == frame_producer::empty())
825 CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(_parameters.size() > 0 ? _parameters[0] : L""));
827 bool auto_play = std::find(_parameters.begin(), _parameters.end(), L"AUTO") != _parameters.end();
829 auto pFP2 = create_transition_producer(GetChannel()->video_format_desc().field_mode, spl::make_shared_ptr(pFP), transitionInfo);
831 GetChannel()->stage().load(GetLayerIndex(), pFP2, false, transitionInfo.duration); // TODO: LOOP
833 GetChannel()->stage().load(GetLayerIndex(), pFP2, false); // TODO: LOOP
836 SetReplyString(TEXT("202 LOADBG OK\r\n"));
840 catch(file_not_found&)
842 std::wstring params2;
843 for(auto it = _parameters.begin(); it != _parameters.end(); ++it)
844 params2 += L" " + *it;
845 CASPAR_LOG(error) << L"File not found. No match found for parameters. Check syntax:" << params2;
846 SetReplyString(TEXT("404 LOADBG ERROR\r\n"));
851 CASPAR_LOG_CURRENT_EXCEPTION();
852 SetReplyString(TEXT("502 LOADBG FAILED\r\n"));
857 bool PauseCommand::DoExecute()
861 GetChannel()->stage().pause(GetLayerIndex());
862 SetReplyString(TEXT("202 PAUSE OK\r\n"));
867 SetReplyString(TEXT("501 PAUSE FAILED\r\n"));
873 bool PlayCommand::DoExecute()
877 if(!_parameters.empty())
880 lbg.SetChannel(GetChannel());
881 lbg.SetChannels(GetChannels());
882 lbg.SetChannelIndex(GetChannelIndex());
883 lbg.SetLayerIntex(GetLayerIndex());
884 lbg.SetClientInfo(GetClientInfo());
885 for(auto it = _parameters.begin(); it != _parameters.end(); ++it)
886 lbg.AddParameter(*it);
888 throw std::exception();
891 GetChannel()->stage().play(GetLayerIndex());
893 SetReplyString(TEXT("202 PLAY OK\r\n"));
898 SetReplyString(TEXT("501 PLAY FAILED\r\n"));
904 bool StopCommand::DoExecute()
908 GetChannel()->stage().stop(GetLayerIndex());
909 SetReplyString(TEXT("202 STOP OK\r\n"));
914 SetReplyString(TEXT("501 STOP FAILED\r\n"));
920 bool ClearCommand::DoExecute()
922 int index = GetLayerIndex(std::numeric_limits<int>::min());
923 if(index != std::numeric_limits<int>::min())
924 GetChannel()->stage().clear(index);
926 GetChannel()->stage().clear();
928 SetReplyString(TEXT("202 CLEAR OK\r\n"));
933 bool PrintCommand::DoExecute()
935 GetChannel()->output().add(create_consumer(boost::assign::list_of(L"IMAGE")));
937 SetReplyString(TEXT("202 PRINT OK\r\n"));
942 bool LogCommand::DoExecute()
944 if(_parameters.at(0) == L"LEVEL")
945 log::set_log_level(_parameters.at(1));
947 SetReplyString(TEXT("202 LOG OK\r\n"));
952 bool CGCommand::DoExecute()
956 std::wstring command = _parameters[0];
957 if(command == TEXT("ADD"))
958 return DoExecuteAdd();
959 else if(command == TEXT("PLAY"))
960 return DoExecutePlay();
961 else if(command == TEXT("STOP"))
962 return DoExecuteStop();
963 else if(command == TEXT("NEXT"))
964 return DoExecuteNext();
965 else if(command == TEXT("REMOVE"))
966 return DoExecuteRemove();
967 else if(command == TEXT("CLEAR"))
968 return DoExecuteClear();
969 else if(command == TEXT("UPDATE"))
970 return DoExecuteUpdate();
971 else if(command == TEXT("INVOKE"))
972 return DoExecuteInvoke();
973 else if(command == TEXT("INFO"))
974 return DoExecuteInfo();
978 CASPAR_LOG_CURRENT_EXCEPTION();
981 SetReplyString(TEXT("403 CG ERROR\r\n"));
985 bool CGCommand::ValidateLayer(const std::wstring& layerstring) {
986 int length = layerstring.length();
987 for(int i = 0; i < length; ++i) {
988 if(!_istdigit(layerstring[i])) {
996 bool CGCommand::DoExecuteAdd() {
997 //CG 1 ADD 0 "template_folder/templatename" [STARTLABEL] 0/1 [DATA]
999 int layer = 0; //_parameters[1]
1000 // std::wstring templateName; //_parameters[2]
1001 std::wstring label; //_parameters[3]
1002 bool bDoStart = false; //_parameters[3] alt. _parameters[4]
1003 // std::wstring data; //_parameters[4] alt. _parameters[5]
1005 if(_parameters.size() < 4)
1007 SetReplyString(TEXT("402 CG ERROR\r\n"));
1010 unsigned int dataIndex = 4;
1012 if(!ValidateLayer(_parameters[1]))
1014 SetReplyString(TEXT("403 CG ERROR\r\n"));
1018 layer = _ttoi(_parameters[1].c_str());
1020 if(_parameters[3].length() > 1)
1022 label = _parameters2[3];
1025 if(_parameters.size() > 4 && _parameters[4].length() > 0) //read play-on-load-flag
1026 bDoStart = (_parameters[4][0]==TEXT('1')) ? true : false;
1029 SetReplyString(TEXT("402 CG ERROR\r\n"));
1033 else if(_parameters[3].length() > 0) { //read play-on-load-flag
1034 bDoStart = (_parameters[3][0]==TEXT('1')) ? true : false;
1038 SetReplyString(TEXT("403 CG ERROR\r\n"));
1042 const TCHAR* pDataString = 0;
1043 std::wstringstream data;
1044 std::wstring dataFromFile;
1045 if(_parameters.size() > dataIndex)
1047 const std::wstring& dataString = _parameters2[dataIndex];
1049 if(dataString[0] == TEXT('<')) //the data is an XML-string
1050 pDataString = dataString.c_str();
1053 //The data is not an XML-string, it must be a filename
1054 std::wstring filename = env::data_folder();
1055 filename.append(dataString);
1056 filename.append(TEXT(".ftd"));
1058 dataFromFile = read_file(boost::filesystem::wpath(filename));
1059 pDataString = dataFromFile.c_str();
1063 std::wstring fullFilename = flash::find_template(env::template_folder() + _parameters[2]);
1064 if(!fullFilename.empty())
1066 std::wstring extension = boost::filesystem::path(fullFilename).extension().wstring();
1067 std::wstring filename = _parameters[2];
1068 filename.append(extension);
1070 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(""));
1071 SetReplyString(TEXT("202 CG OK\r\n"));
1075 CASPAR_LOG(warning) << "Could not find template " << _parameters[2];
1076 SetReplyString(TEXT("404 CG ERROR\r\n"));
1081 bool CGCommand::DoExecutePlay()
1083 if(_parameters.size() > 1)
1085 if(!ValidateLayer(_parameters[1]))
1087 SetReplyString(TEXT("403 CG ERROR\r\n"));
1090 int layer = _ttoi(_parameters[1].c_str());
1091 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).play(layer);
1095 SetReplyString(TEXT("402 CG ERROR\r\n"));
1099 SetReplyString(TEXT("202 CG OK\r\n"));
1103 bool CGCommand::DoExecuteStop()
1105 if(_parameters.size() > 1)
1107 if(!ValidateLayer(_parameters[1]))
1109 SetReplyString(TEXT("403 CG ERROR\r\n"));
1112 int layer = _ttoi(_parameters[1].c_str());
1113 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).stop(layer, 0);
1117 SetReplyString(TEXT("402 CG ERROR\r\n"));
1121 SetReplyString(TEXT("202 CG OK\r\n"));
1125 bool CGCommand::DoExecuteNext()
1127 if(_parameters.size() > 1)
1129 if(!ValidateLayer(_parameters[1]))
1131 SetReplyString(TEXT("403 CG ERROR\r\n"));
1135 int layer = _ttoi(_parameters[1].c_str());
1136 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).next(layer);
1140 SetReplyString(TEXT("402 CG ERROR\r\n"));
1144 SetReplyString(TEXT("202 CG OK\r\n"));
1148 bool CGCommand::DoExecuteRemove()
1150 if(_parameters.size() > 1)
1152 if(!ValidateLayer(_parameters[1]))
1154 SetReplyString(TEXT("403 CG ERROR\r\n"));
1158 int layer = _ttoi(_parameters[1].c_str());
1159 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).remove(layer);
1163 SetReplyString(TEXT("402 CG ERROR\r\n"));
1167 SetReplyString(TEXT("202 CG OK\r\n"));
1171 bool CGCommand::DoExecuteClear()
1173 GetChannel()->stage().clear(GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER));
1174 SetReplyString(TEXT("202 CG OK\r\n"));
1178 bool CGCommand::DoExecuteUpdate()
1182 if(!ValidateLayer(_parameters.at(1)))
1184 SetReplyString(TEXT("403 CG ERROR\r\n"));
1188 std::wstring dataString = _parameters2.at(2);
1189 if(dataString.at(0) != TEXT('<'))
1191 //The data is not an XML-string, it must be a filename
1192 std::wstring filename = env::data_folder();
1193 filename.append(dataString);
1194 filename.append(TEXT(".ftd"));
1196 dataString = read_file(boost::filesystem::wpath(filename));
1199 int layer = _ttoi(_parameters.at(1).c_str());
1200 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).update(layer, dataString);
1204 SetReplyString(TEXT("402 CG ERROR\r\n"));
1208 SetReplyString(TEXT("202 CG OK\r\n"));
1212 bool CGCommand::DoExecuteInvoke()
1214 std::wstringstream replyString;
1215 replyString << TEXT("201 CG OK\r\n");
1217 if(_parameters.size() > 2)
1219 if(!ValidateLayer(_parameters[1]))
1221 SetReplyString(TEXT("403 CG ERROR\r\n"));
1224 int layer = _ttoi(_parameters[1].c_str());
1225 auto result = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).invoke(layer, _parameters2[2]);
1226 replyString << result << TEXT("\r\n");
1230 SetReplyString(TEXT("402 CG ERROR\r\n"));
1234 SetReplyString(replyString.str());
1238 bool CGCommand::DoExecuteInfo()
1240 std::wstringstream replyString;
1241 replyString << TEXT("201 CG OK\r\n");
1243 if(_parameters.size() > 1)
1245 if(!ValidateLayer(_parameters[1]))
1247 SetReplyString(TEXT("403 CG ERROR\r\n"));
1251 int layer = _ttoi(_parameters[1].c_str());
1252 auto desc = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).description(layer);
1254 replyString << desc << TEXT("\r\n");
1258 auto info = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).template_host_info();
1259 replyString << info << TEXT("\r\n");
1262 SetReplyString(replyString.str());
1266 bool DataCommand::DoExecute()
1268 std::wstring command = _parameters[0];
1269 if(command == TEXT("STORE"))
1270 return DoExecuteStore();
1271 else if(command == TEXT("RETRIEVE"))
1272 return DoExecuteRetrieve();
1273 else if(command == TEXT("LIST"))
1274 return DoExecuteList();
1276 SetReplyString(TEXT("403 DATA ERROR\r\n"));
1280 bool DataCommand::DoExecuteStore()
1282 if(_parameters.size() < 3)
1284 SetReplyString(TEXT("402 DATA STORE ERROR\r\n"));
1288 std::wstring filename = env::data_folder();
1289 filename.append(_parameters[1]);
1290 filename.append(TEXT(".ftd"));
1292 std::wofstream datafile(filename.c_str());
1295 SetReplyString(TEXT("501 DATA STORE FAILED\r\n"));
1299 datafile << static_cast<wchar_t>(65279); // UTF-8 BOM character
1300 datafile << _parameters2[2] << std::flush;
1303 std::wstring replyString = TEXT("202 DATA STORE OK\r\n");
1304 SetReplyString(replyString);
1308 bool DataCommand::DoExecuteRetrieve()
1310 if(_parameters.size() < 2)
1312 SetReplyString(TEXT("402 DATA RETRIEVE ERROR\r\n"));
1316 std::wstring filename = env::data_folder();
1317 filename.append(_parameters[1]);
1318 filename.append(TEXT(".ftd"));
1320 std::wstring file_contents = read_file(boost::filesystem::wpath(filename));
1322 if (file_contents.empty())
1324 SetReplyString(TEXT("404 DATA RETRIEVE ERROR\r\n"));
1328 std::wstringstream reply(TEXT("201 DATA RETRIEVE OK\r\n"));
1330 reply << file_contents;
1332 SetReplyString(reply.str());
1336 bool DataCommand::DoExecuteList()
1338 std::wstringstream replyString;
1339 replyString << TEXT("200 DATA LIST OK\r\n");
1341 for (boost::filesystem::recursive_directory_iterator itr(env::data_folder()), end; itr != end; ++itr)
1343 if(boost::filesystem::is_regular_file(itr->path()))
1345 if(!boost::iequals(itr->path().extension().wstring(), L".ftd"))
1348 auto relativePath = boost::filesystem::wpath(itr->path().wstring().substr(env::data_folder().size()-1, itr->path().wstring().size()));
1350 auto str = relativePath.replace_extension(TEXT("")).native();
1351 if(str[0] == '\\' || str[0] == '/')
1352 str = std::wstring(str.begin() + 1, str.end());
1354 replyString << str << TEXT("\r\n");
1358 replyString << TEXT("\r\n");
1360 SetReplyString(boost::to_upper_copy(replyString.str()));
1364 bool CinfCommand::DoExecute()
1366 std::wstringstream replyString;
1371 for (boost::filesystem::recursive_directory_iterator itr(env::media_folder()), end; itr != end && info.empty(); ++itr)
1373 auto path = itr->path();
1374 auto file = path.replace_extension(L"").filename();
1375 if(boost::iequals(file.wstring(), _parameters.at(0)))
1376 info += MediaInfo(itr->path()) + L"\r\n";
1381 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1384 replyString << TEXT("200 CINF OK\r\n");
1385 replyString << info << "\r\n";
1389 CASPAR_LOG_CURRENT_EXCEPTION();
1390 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1394 SetReplyString(replyString.str());
1398 void GenerateChannelInfo(int index, const spl::shared_ptr<core::video_channel>& pChannel, std::wstringstream& replyString)
1400 replyString << index+1 << TEXT(" ") << pChannel->video_format_desc().name << TEXT(" PLAYING") << TEXT("\r\n");
1403 bool InfoCommand::DoExecute()
1405 std::wstringstream replyString;
1407 boost::property_tree::xml_writer_settings<wchar_t> w(' ', 3);
1411 if(_parameters.size() >= 1 && _parameters[0] == L"TEMPLATE")
1413 replyString << L"201 INFO TEMPLATE OK\r\n";
1415 // Needs to be extended for any file, not just flash.
1417 auto filename = flash::find_template(env::template_folder() + _parameters.at(1));
1419 std::wstringstream str;
1420 str << u16(flash::read_template_meta_info(filename));
1421 boost::property_tree::wptree info;
1422 boost::property_tree::xml_parser::read_xml(str, info, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
1424 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1426 else if(_parameters.size() >= 1 && _parameters[0] == L"CONFIG")
1428 replyString << L"201 INFO CONFIG OK\r\n";
1430 boost::property_tree::write_xml(replyString, caspar::env::properties(), w);
1432 else if(_parameters.size() >= 1 && _parameters[0] == L"PATHS")
1434 replyString << L"201 INFO PATHS OK\r\n";
1436 boost::property_tree::wptree info;
1437 info.add_child(L"paths", caspar::env::properties().get_child(L"configuration.paths"));
1438 info.add(L"paths.initial-path", boost::filesystem3::initial_path().wstring() + L"\\");
1440 boost::property_tree::write_xml(replyString, info, w);
1442 else if(_parameters.size() >= 1 && _parameters[0] == L"SYSTEM")
1444 replyString << L"201 INFO SYSTEM OK\r\n";
1446 boost::property_tree::wptree info;
1448 info.add(L"system.name", caspar::system_product_name());
1449 info.add(L"system.windows.name", caspar::win_product_name());
1450 info.add(L"system.windows.service-pack", caspar::win_sp_version());
1451 info.add(L"system.cpu", caspar::cpu_info());
1453 BOOST_FOREACH(auto device, caspar::decklink::device_list())
1454 info.add(L"system.decklink.device", device);
1456 BOOST_FOREACH(auto device, caspar::bluefish::device_list())
1457 info.add(L"system.bluefish.device", device);
1459 info.add(L"system.flash", caspar::flash::version());
1460 //info.add(L"system.free-image", caspar::image::version());
1461 info.add(L"system.ffmpeg.avcodec", caspar::ffmpeg::avcodec_version());
1462 info.add(L"system.ffmpeg.avformat", caspar::ffmpeg::avformat_version());
1463 info.add(L"system.ffmpeg.avfilter", caspar::ffmpeg::avfilter_version());
1464 info.add(L"system.ffmpeg.avutil", caspar::ffmpeg::avutil_version());
1465 info.add(L"system.ffmpeg.swscale", caspar::ffmpeg::swscale_version());
1467 boost::property_tree::write_xml(replyString, info, w);
1469 else if(_parameters.size() >= 1 && _parameters[0] == L"SERVER")
1471 replyString << L"201 INFO SERVER OK\r\n";
1473 boost::property_tree::wptree info;
1476 BOOST_FOREACH(auto channel, channels_)
1477 info.add_child(L"channels.channel", channel->info())
1478 .add(L"index", ++index);
1480 boost::property_tree::write_xml(replyString, info, w);
1484 if(_parameters.size() >= 1)
1486 replyString << TEXT("201 INFO OK\r\n");
1487 boost::property_tree::wptree info;
1489 std::vector<std::wstring> split;
1490 boost::split(split, _parameters[0], boost::is_any_of("-"));
1492 int layer = std::numeric_limits<int>::min();
1493 int channel = boost::lexical_cast<int>(split[0]) - 1;
1495 if(split.size() > 1)
1496 layer = boost::lexical_cast<int>(split[1]);
1498 if(layer == std::numeric_limits<int>::min())
1500 info.add_child(L"channel", channels_.at(channel)->info())
1501 .add(L"index", channel);
1505 if(_parameters.size() >= 2)
1507 if(_parameters[1] == L"B")
1508 info.add_child(L"producer", channels_.at(channel)->stage().background(layer).get()->info());
1510 info.add_child(L"producer", channels_.at(channel)->stage().foreground(layer).get()->info());
1514 info.add_child(L"layer", channels_.at(channel)->stage().info(layer).get())
1515 .add(L"index", layer);
1518 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1522 // This is needed for backwards compatibility with old clients
1523 replyString << TEXT("200 INFO OK\r\n");
1524 for(size_t n = 0; n < channels_.size(); ++n)
1525 GenerateChannelInfo(n, channels_[n], replyString);
1532 CASPAR_LOG_CURRENT_EXCEPTION();
1533 SetReplyString(TEXT("403 INFO ERROR\r\n"));
1537 replyString << TEXT("\r\n");
1538 SetReplyString(replyString.str());
1542 bool ClsCommand::DoExecute()
1554 std::wstringstream replyString;
1555 replyString << TEXT("200 CLS OK\r\n");
1556 replyString << ListMedia();
1557 replyString << TEXT("\r\n");
1558 SetReplyString(boost::to_upper_copy(replyString.str()));
1562 CASPAR_LOG_CURRENT_EXCEPTION();
1563 SetReplyString(TEXT("501 CLS FAILED\r\n"));
1570 bool TlsCommand::DoExecute()
1574 std::wstringstream replyString;
1575 replyString << TEXT("200 TLS OK\r\n");
1577 replyString << ListTemplates();
1578 replyString << TEXT("\r\n");
1580 SetReplyString(replyString.str());
1584 CASPAR_LOG_CURRENT_EXCEPTION();
1585 SetReplyString(TEXT("501 TLS FAILED\r\n"));
1591 bool VersionCommand::DoExecute()
1593 std::wstring replyString = TEXT("201 VERSION OK\r\n") + env::version() + TEXT("\r\n");
1595 if(_parameters.size() > 0)
1597 if(_parameters[0] == L"FLASH")
1598 replyString = TEXT("201 VERSION OK\r\n") + flash::version() + TEXT("\r\n");
1599 else if(_parameters[0] == L"TEMPLATEHOST")
1600 replyString = TEXT("201 VERSION OK\r\n") + flash::cg_version() + TEXT("\r\n");
1601 else if(_parameters[0] != L"SERVER")
1602 replyString = TEXT("403 VERSION ERROR\r\n");
1605 SetReplyString(replyString);
1609 bool ByeCommand::DoExecute()
1611 GetClientInfo()->Disconnect();
1615 bool SetCommand::DoExecute()
1619 std::wstring name = _parameters[0];
1620 std::transform(name.begin(), name.end(), name.begin(), toupper);
1622 std::wstring value = _parameters[1];
1623 std::transform(value.begin(), value.end(), value.begin(), toupper);
1625 if(name == TEXT("MODE"))
1627 auto format_desc = core::video_format_desc(value);
1628 if(format_desc.format != core::video_format::invalid)
1630 GetChannel()->video_format_desc(format_desc);
1631 SetReplyString(TEXT("202 SET MODE OK\r\n"));
1634 SetReplyString(TEXT("501 SET MODE FAILED\r\n"));
1638 this->SetReplyString(TEXT("403 SET ERROR\r\n"));
1643 CASPAR_LOG_CURRENT_EXCEPTION();
1644 SetReplyString(TEXT("501 SET FAILED\r\n"));
1653 }} //namespace caspar