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);
361 auto result = GetChannel()->stage().call(GetLayerIndex(), _parameters2);
363 if(!result.timed_wait(boost::posix_time::seconds(2)))
364 CASPAR_THROW_EXCEPTION(timed_out());
366 std::wstringstream replyString;
367 if(result.get().empty())
368 replyString << TEXT("202 CALL OK\r\n");
370 replyString << TEXT("201 CALL OK\r\n") << result.get() << L"\r\n";
372 SetReplyString(replyString.str());
378 CASPAR_LOG_CURRENT_EXCEPTION();
379 SetReplyString(TEXT("502 CALL FAILED\r\n"));
384 tbb::concurrent_unordered_map<int, std::vector<stage::transform_tuple_t>> deferred_transforms;
386 bool MixerCommand::DoExecute()
388 //Perform loading of the clip
391 bool defer = _parameters.back() == L"DEFER";
393 _parameters.pop_back();
395 std::vector<stage::transform_tuple_t> transforms;
397 if(_parameters[0] == L"KEYER" || _parameters[0] == L"IS_KEY")
399 bool value = boost::lexical_cast<int>(_parameters.at(1));
400 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
402 transform.image_transform.is_key = value;
406 else if(_parameters[0] == L"OPACITY")
408 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
409 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
411 double value = boost::lexical_cast<double>(_parameters.at(1));
413 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
415 transform.image_transform.opacity = value;
417 }, duration, tween));
419 else if(_parameters[0] == L"FILL" || _parameters[0] == L"FILL_RECT")
421 int duration = _parameters.size() > 5 ? boost::lexical_cast<int>(_parameters[5]) : 0;
422 std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear";
423 double x = boost::lexical_cast<double>(_parameters.at(1));
424 double y = boost::lexical_cast<double>(_parameters.at(2));
425 double x_s = boost::lexical_cast<double>(_parameters.at(3));
426 double y_s = boost::lexical_cast<double>(_parameters.at(4));
428 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) mutable -> frame_transform
430 transform.image_transform.fill_translation[0] = x;
431 transform.image_transform.fill_translation[1] = y;
432 transform.image_transform.fill_scale[0] = x_s;
433 transform.image_transform.fill_scale[1] = y_s;
435 }, duration, tween));
437 else if(_parameters[0] == L"CLIP" || _parameters[0] == L"CLIP_RECT")
439 int duration = _parameters.size() > 5 ? boost::lexical_cast<int>(_parameters[5]) : 0;
440 std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear";
441 double x = boost::lexical_cast<double>(_parameters.at(1));
442 double y = boost::lexical_cast<double>(_parameters.at(2));
443 double x_s = boost::lexical_cast<double>(_parameters.at(3));
444 double y_s = boost::lexical_cast<double>(_parameters.at(4));
446 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
448 transform.image_transform.clip_translation[0] = x;
449 transform.image_transform.clip_translation[1] = y;
450 transform.image_transform.clip_scale[0] = x_s;
451 transform.image_transform.clip_scale[1] = y_s;
453 }, duration, tween));
455 else if(_parameters[0] == L"GRID")
457 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
458 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
459 int n = boost::lexical_cast<int>(_parameters.at(1));
460 double delta = 1.0/static_cast<double>(n);
461 for(int x = 0; x < n; ++x)
463 for(int y = 0; y < n; ++y)
466 transforms.push_back(stage::transform_tuple_t(index, [=](frame_transform transform) -> frame_transform
468 transform.image_transform.fill_translation[0] = x*delta;
469 transform.image_transform.fill_translation[1] = y*delta;
470 transform.image_transform.fill_scale[0] = delta;
471 transform.image_transform.fill_scale[1] = delta;
472 transform.image_transform.clip_translation[0] = x*delta;
473 transform.image_transform.clip_translation[1] = y*delta;
474 transform.image_transform.clip_scale[0] = delta;
475 transform.image_transform.clip_scale[1] = delta;
477 }, duration, tween));
481 else if(_parameters[0] == L"BLEND")
483 auto blend_str = _parameters.at(1);
484 int layer = GetLayerIndex();
485 GetChannel()->mixer().set_blend_mode(GetLayerIndex(), get_blend_mode(blend_str));
487 else if(_parameters[0] == L"MASTERVOLUME")
489 float master_volume = boost::lexical_cast<float>(_parameters.at(1));
490 GetChannel()->mixer().set_master_volume(master_volume);
492 else if(_parameters[0] == L"BRIGHTNESS")
494 auto value = boost::lexical_cast<double>(_parameters.at(1));
495 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
496 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
497 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
499 transform.image_transform.brightness = value;
501 }, duration, tween));
503 else if(_parameters[0] == L"SATURATION")
505 auto value = boost::lexical_cast<double>(_parameters.at(1));
506 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
507 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
508 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
510 transform.image_transform.saturation = value;
512 }, duration, tween));
514 else if(_parameters[0] == L"CONTRAST")
516 auto value = boost::lexical_cast<double>(_parameters.at(1));
517 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
518 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
519 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
521 transform.image_transform.contrast = value;
523 }, duration, tween));
525 else if(_parameters[0] == L"LEVELS")
528 value.min_input = boost::lexical_cast<double>(_parameters.at(1));
529 value.max_input = boost::lexical_cast<double>(_parameters.at(2));
530 value.gamma = boost::lexical_cast<double>(_parameters.at(3));
531 value.min_output = boost::lexical_cast<double>(_parameters.at(4));
532 value.max_output = boost::lexical_cast<double>(_parameters.at(5));
533 int duration = _parameters.size() > 6 ? boost::lexical_cast<int>(_parameters[6]) : 0;
534 std::wstring tween = _parameters.size() > 7 ? _parameters[7] : L"linear";
536 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
538 transform.image_transform.levels = value;
540 }, duration, tween));
542 else if(_parameters[0] == L"VOLUME")
544 int duration = _parameters.size() > 2 ? boost::lexical_cast<int>(_parameters[2]) : 0;
545 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
546 double value = boost::lexical_cast<double>(_parameters[1]);
548 transforms.push_back(stage::transform_tuple_t(GetLayerIndex(), [=](frame_transform transform) -> frame_transform
550 transform.audio_transform.volume = value;
552 }, duration, tween));
554 else if(_parameters[0] == L"CLEAR")
556 int layer = GetLayerIndex(std::numeric_limits<int>::max());
558 if (layer == std::numeric_limits<int>::max())
560 GetChannel()->stage().clear_transforms();
561 GetChannel()->mixer().clear_blend_modes();
565 GetChannel()->stage().clear_transforms(layer);
566 GetChannel()->mixer().clear_blend_mode(layer);
569 else if(_parameters[0] == L"COMMIT")
571 transforms = std::move(deferred_transforms[GetChannelIndex()]);
575 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
581 auto& defer_tranforms = deferred_transforms[GetChannelIndex()];
582 defer_tranforms.insert(defer_tranforms.end(), transforms.begin(), transforms.end());
585 GetChannel()->stage().apply_transforms(transforms);
587 SetReplyString(TEXT("202 MIXER OK\r\n"));
591 catch(file_not_found&)
593 CASPAR_LOG_CURRENT_EXCEPTION();
594 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
599 CASPAR_LOG_CURRENT_EXCEPTION();
600 SetReplyString(TEXT("502 MIXER FAILED\r\n"));
605 bool SwapCommand::DoExecute()
607 //Perform loading of the clip
610 if(GetLayerIndex(-1) != -1)
612 std::vector<std::string> strs;
613 boost::split(strs, _parameters[0], boost::is_any_of("-"));
615 auto ch1 = GetChannel();
616 auto ch2 = GetChannels().at(boost::lexical_cast<int>(strs.at(0))-1);
618 int l1 = GetLayerIndex();
619 int l2 = boost::lexical_cast<int>(strs.at(1));
621 ch1->stage().swap_layer(l1, l2, ch2->stage());
625 auto ch1 = GetChannel();
626 auto ch2 = GetChannels().at(boost::lexical_cast<int>(_parameters[0])-1);
627 ch1->stage().swap_layers(ch2->stage());
630 SetReplyString(TEXT("202 SWAP OK\r\n"));
634 catch(file_not_found&)
636 CASPAR_LOG_CURRENT_EXCEPTION();
637 SetReplyString(TEXT("404 SWAP ERROR\r\n"));
642 CASPAR_LOG_CURRENT_EXCEPTION();
643 SetReplyString(TEXT("502 SWAP FAILED\r\n"));
648 bool AddCommand::DoExecute()
650 //Perform loading of the clip
653 auto consumer = create_consumer(_parameters);
654 GetChannel()->output().add(GetLayerIndex(consumer->index()), consumer);
656 SetReplyString(TEXT("202 ADD OK\r\n"));
660 catch(file_not_found&)
662 CASPAR_LOG_CURRENT_EXCEPTION();
663 SetReplyString(TEXT("404 ADD ERROR\r\n"));
668 CASPAR_LOG_CURRENT_EXCEPTION();
669 SetReplyString(TEXT("502 ADD FAILED\r\n"));
674 bool RemoveCommand::DoExecute()
676 //Perform loading of the clip
679 auto index = GetLayerIndex(std::numeric_limits<int>::min());
680 if(index == std::numeric_limits<int>::min())
681 index = create_consumer(_parameters)->index();
683 GetChannel()->output().remove(index);
685 SetReplyString(TEXT("202 REMOVE OK\r\n"));
689 catch(file_not_found&)
691 CASPAR_LOG_CURRENT_EXCEPTION();
692 SetReplyString(TEXT("404 REMOVE ERROR\r\n"));
697 CASPAR_LOG_CURRENT_EXCEPTION();
698 SetReplyString(TEXT("502 REMOVE FAILED\r\n"));
703 bool LoadCommand::DoExecute()
705 //Perform loading of the clip
708 _parameters[0] = _parameters[0];
709 auto pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), _parameters);
710 GetChannel()->stage().load(GetLayerIndex(), pFP, true);
712 SetReplyString(TEXT("202 LOAD OK\r\n"));
716 catch(file_not_found&)
718 CASPAR_LOG_CURRENT_EXCEPTION();
719 SetReplyString(TEXT("404 LOAD ERROR\r\n"));
724 CASPAR_LOG_CURRENT_EXCEPTION();
725 SetReplyString(TEXT("502 LOAD FAILED\r\n"));
732 //std::function<std::wstring()> channel_cg_add_command::parse(const std::wstring& message, const std::vector<renderer::render_device_ptr>& channels)
734 // 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>.*)?");
736 // boost::wsmatch what;
737 // if(!boost::regex_match(message, what, expr))
740 // auto info = channel_info::parse(what, channels);
742 // int flash_layer_index = boost::lexical_cast<int>(what["FLASH_LAYER"].str());
744 // std::wstring templatename = what["TEMPLATE"].str();
745 // bool play_on_load = what["PLAY_ON_LOAD"].matched ? what["PLAY_ON_LOAD"].str() != L"0" : 0;
746 // std::wstring start_label = what["START_LABEL"].str();
747 // std::wstring data = get_data(what["DATA"].str());
749 // boost::replace_all(templatename, "\"", "");
751 // return [=]() -> std::wstring
753 // std::wstring fullFilename = flash::flash_producer::find_template(server::template_folder() + templatename);
754 // if(fullFilename.empty())
755 // CASPAR_THROW_EXCEPTION(file_not_found());
757 // std::wstring extension = boost::filesystem::wpath(fullFilename).extension();
758 // std::wstring filename = templatename;
759 // filename.append(extension);
761 // flash::flash::create_cg_proxy(info.video_channel, std::max<int>(DEFAULT_CHANNEL_LAYER+1, info.layer_index))
762 // ->add(flash_layer_index, filename, play_on_load, start_label, data);
764 // CASPAR_LOG(info) << L"Executed [amcp_channel_cg_add]";
768 bool LoadbgCommand::DoExecute()
770 transition_info transitionInfo;
776 std::wstring message;
777 for(size_t n = 0; n < _parameters.size(); ++n)
778 message += _parameters[n] + L" ";
780 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)?.*");
782 if(boost::regex_match(message, what, expr))
784 auto transition = what["TRANSITION"].str();
785 transitionInfo.duration = boost::lexical_cast<size_t>(what["DURATION"].str());
786 auto direction = what["DIRECTION"].matched ? what["DIRECTION"].str() : L"";
787 auto tween = what["TWEEN"].matched ? what["TWEEN"].str() : L"";
788 transitionInfo.tweener = tween;
790 if(transition == TEXT("CUT"))
791 transitionInfo.type = transition_type::cut;
792 else if(transition == TEXT("MIX"))
793 transitionInfo.type = transition_type::mix;
794 else if(transition == TEXT("PUSH"))
795 transitionInfo.type = transition_type::push;
796 else if(transition == TEXT("SLIDE"))
797 transitionInfo.type = transition_type::slide;
798 else if(transition == TEXT("WIPE"))
799 transitionInfo.type = transition_type::wipe;
801 if(direction == TEXT("FROMLEFT"))
802 transitionInfo.direction = transition_direction::from_left;
803 else if(direction == TEXT("FROMRIGHT"))
804 transitionInfo.direction = transition_direction::from_right;
805 else if(direction == TEXT("LEFT"))
806 transitionInfo.direction = transition_direction::from_right;
807 else if(direction == TEXT("RIGHT"))
808 transitionInfo.direction = transition_direction::from_left;
811 //Perform loading of the clip
814 std::shared_ptr<core::frame_producer> pFP;
816 static boost::wregex expr(L"\\[(?<CHANNEL>\\d+)\\]", boost::regex::icase);
819 if(boost::regex_match(_parameters.at(0), what, expr))
821 auto channel_index = boost::lexical_cast<int>(what["CHANNEL"].str());
822 pFP = reroute::create_producer(*GetChannels().at(channel_index-1));
825 pFP = create_producer(GetChannel()->frame_factory(), GetChannel()->video_format_desc(), _parameters);
827 if(pFP == frame_producer::empty())
828 CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(_parameters.size() > 0 ? _parameters[0] : L""));
830 bool auto_play = std::find(_parameters.begin(), _parameters.end(), L"AUTO") != _parameters.end();
832 auto pFP2 = create_transition_producer(GetChannel()->video_format_desc().field_mode, spl::make_shared_ptr(pFP), transitionInfo);
834 GetChannel()->stage().load(GetLayerIndex(), pFP2, false, transitionInfo.duration); // TODO: LOOP
836 GetChannel()->stage().load(GetLayerIndex(), pFP2, false); // TODO: LOOP
839 SetReplyString(TEXT("202 LOADBG OK\r\n"));
843 catch(file_not_found&)
845 std::wstring params2;
846 for(auto it = _parameters.begin(); it != _parameters.end(); ++it)
847 params2 += L" " + *it;
848 CASPAR_LOG(error) << L"File not found. No match found for parameters. Check syntax:" << params2;
849 SetReplyString(TEXT("404 LOADBG ERROR\r\n"));
854 CASPAR_LOG_CURRENT_EXCEPTION();
855 SetReplyString(TEXT("502 LOADBG FAILED\r\n"));
860 bool PauseCommand::DoExecute()
864 GetChannel()->stage().pause(GetLayerIndex());
865 SetReplyString(TEXT("202 PAUSE OK\r\n"));
870 SetReplyString(TEXT("501 PAUSE FAILED\r\n"));
876 bool PlayCommand::DoExecute()
880 if(!_parameters.empty())
883 lbg.SetChannel(GetChannel());
884 lbg.SetChannels(GetChannels());
885 lbg.SetChannelIndex(GetChannelIndex());
886 lbg.SetLayerIntex(GetLayerIndex());
887 lbg.SetClientInfo(GetClientInfo());
888 for(auto it = _parameters.begin(); it != _parameters.end(); ++it)
889 lbg.AddParameter(*it);
891 throw std::exception();
894 GetChannel()->stage().play(GetLayerIndex());
896 SetReplyString(TEXT("202 PLAY OK\r\n"));
901 SetReplyString(TEXT("501 PLAY FAILED\r\n"));
907 bool StopCommand::DoExecute()
911 GetChannel()->stage().stop(GetLayerIndex());
912 SetReplyString(TEXT("202 STOP OK\r\n"));
917 SetReplyString(TEXT("501 STOP FAILED\r\n"));
923 bool ClearCommand::DoExecute()
925 int index = GetLayerIndex(std::numeric_limits<int>::min());
926 if(index != std::numeric_limits<int>::min())
927 GetChannel()->stage().clear(index);
929 GetChannel()->stage().clear();
931 SetReplyString(TEXT("202 CLEAR OK\r\n"));
936 bool PrintCommand::DoExecute()
938 GetChannel()->output().add(create_consumer(boost::assign::list_of(L"IMAGE")));
940 SetReplyString(TEXT("202 PRINT OK\r\n"));
945 bool LogCommand::DoExecute()
947 if(_parameters.at(0) == L"LEVEL")
948 log::set_log_level(_parameters.at(1));
950 SetReplyString(TEXT("202 LOG OK\r\n"));
955 bool CGCommand::DoExecute()
959 std::wstring command = _parameters[0];
960 if(command == TEXT("ADD"))
961 return DoExecuteAdd();
962 else if(command == TEXT("PLAY"))
963 return DoExecutePlay();
964 else if(command == TEXT("STOP"))
965 return DoExecuteStop();
966 else if(command == TEXT("NEXT"))
967 return DoExecuteNext();
968 else if(command == TEXT("REMOVE"))
969 return DoExecuteRemove();
970 else if(command == TEXT("CLEAR"))
971 return DoExecuteClear();
972 else if(command == TEXT("UPDATE"))
973 return DoExecuteUpdate();
974 else if(command == TEXT("INVOKE"))
975 return DoExecuteInvoke();
976 else if(command == TEXT("INFO"))
977 return DoExecuteInfo();
981 CASPAR_LOG_CURRENT_EXCEPTION();
984 SetReplyString(TEXT("403 CG ERROR\r\n"));
988 bool CGCommand::ValidateLayer(const std::wstring& layerstring) {
989 int length = layerstring.length();
990 for(int i = 0; i < length; ++i) {
991 if(!_istdigit(layerstring[i])) {
999 bool CGCommand::DoExecuteAdd() {
1000 //CG 1 ADD 0 "template_folder/templatename" [STARTLABEL] 0/1 [DATA]
1002 int layer = 0; //_parameters[1]
1003 // std::wstring templateName; //_parameters[2]
1004 std::wstring label; //_parameters[3]
1005 bool bDoStart = false; //_parameters[3] alt. _parameters[4]
1006 // std::wstring data; //_parameters[4] alt. _parameters[5]
1008 if(_parameters.size() < 4)
1010 SetReplyString(TEXT("402 CG ERROR\r\n"));
1013 unsigned int dataIndex = 4;
1015 if(!ValidateLayer(_parameters[1]))
1017 SetReplyString(TEXT("403 CG ERROR\r\n"));
1021 layer = _ttoi(_parameters[1].c_str());
1023 if(_parameters[3].length() > 1)
1025 label = _parameters2[3];
1028 if(_parameters.size() > 4 && _parameters[4].length() > 0) //read play-on-load-flag
1029 bDoStart = (_parameters[4][0]==TEXT('1')) ? true : false;
1032 SetReplyString(TEXT("402 CG ERROR\r\n"));
1036 else if(_parameters[3].length() > 0) { //read play-on-load-flag
1037 bDoStart = (_parameters[3][0]==TEXT('1')) ? true : false;
1041 SetReplyString(TEXT("403 CG ERROR\r\n"));
1045 const TCHAR* pDataString = 0;
1046 std::wstringstream data;
1047 std::wstring dataFromFile;
1048 if(_parameters.size() > dataIndex)
1050 const std::wstring& dataString = _parameters2[dataIndex];
1052 if(dataString[0] == TEXT('<')) //the data is an XML-string
1053 pDataString = dataString.c_str();
1056 //The data is not an XML-string, it must be a filename
1057 std::wstring filename = env::data_folder();
1058 filename.append(dataString);
1059 filename.append(TEXT(".ftd"));
1061 dataFromFile = read_file(boost::filesystem::wpath(filename));
1062 pDataString = dataFromFile.c_str();
1066 std::wstring fullFilename = flash::find_template(env::template_folder() + _parameters[2]);
1067 if(!fullFilename.empty())
1069 std::wstring extension = boost::filesystem::path(fullFilename).extension().wstring();
1070 std::wstring filename = _parameters[2];
1071 filename.append(extension);
1073 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(""));
1074 SetReplyString(TEXT("202 CG OK\r\n"));
1078 CASPAR_LOG(warning) << "Could not find template " << _parameters[2];
1079 SetReplyString(TEXT("404 CG ERROR\r\n"));
1084 bool CGCommand::DoExecutePlay()
1086 if(_parameters.size() > 1)
1088 if(!ValidateLayer(_parameters[1]))
1090 SetReplyString(TEXT("403 CG ERROR\r\n"));
1093 int layer = _ttoi(_parameters[1].c_str());
1094 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).play(layer);
1098 SetReplyString(TEXT("402 CG ERROR\r\n"));
1102 SetReplyString(TEXT("202 CG OK\r\n"));
1106 bool CGCommand::DoExecuteStop()
1108 if(_parameters.size() > 1)
1110 if(!ValidateLayer(_parameters[1]))
1112 SetReplyString(TEXT("403 CG ERROR\r\n"));
1115 int layer = _ttoi(_parameters[1].c_str());
1116 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).stop(layer, 0);
1120 SetReplyString(TEXT("402 CG ERROR\r\n"));
1124 SetReplyString(TEXT("202 CG OK\r\n"));
1128 bool CGCommand::DoExecuteNext()
1130 if(_parameters.size() > 1)
1132 if(!ValidateLayer(_parameters[1]))
1134 SetReplyString(TEXT("403 CG ERROR\r\n"));
1138 int layer = _ttoi(_parameters[1].c_str());
1139 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).next(layer);
1143 SetReplyString(TEXT("402 CG ERROR\r\n"));
1147 SetReplyString(TEXT("202 CG OK\r\n"));
1151 bool CGCommand::DoExecuteRemove()
1153 if(_parameters.size() > 1)
1155 if(!ValidateLayer(_parameters[1]))
1157 SetReplyString(TEXT("403 CG ERROR\r\n"));
1161 int layer = _ttoi(_parameters[1].c_str());
1162 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).remove(layer);
1166 SetReplyString(TEXT("402 CG ERROR\r\n"));
1170 SetReplyString(TEXT("202 CG OK\r\n"));
1174 bool CGCommand::DoExecuteClear()
1176 GetChannel()->stage().clear(GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER));
1177 SetReplyString(TEXT("202 CG OK\r\n"));
1181 bool CGCommand::DoExecuteUpdate()
1185 if(!ValidateLayer(_parameters.at(1)))
1187 SetReplyString(TEXT("403 CG ERROR\r\n"));
1191 std::wstring dataString = _parameters2.at(2);
1192 if(dataString.at(0) != TEXT('<'))
1194 //The data is not an XML-string, it must be a filename
1195 std::wstring filename = env::data_folder();
1196 filename.append(dataString);
1197 filename.append(TEXT(".ftd"));
1199 dataString = read_file(boost::filesystem::wpath(filename));
1202 int layer = _ttoi(_parameters.at(1).c_str());
1203 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).update(layer, dataString);
1207 SetReplyString(TEXT("402 CG ERROR\r\n"));
1211 SetReplyString(TEXT("202 CG OK\r\n"));
1215 bool CGCommand::DoExecuteInvoke()
1217 std::wstringstream replyString;
1218 replyString << TEXT("201 CG OK\r\n");
1220 if(_parameters.size() > 2)
1222 if(!ValidateLayer(_parameters[1]))
1224 SetReplyString(TEXT("403 CG ERROR\r\n"));
1227 int layer = _ttoi(_parameters[1].c_str());
1228 auto result = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).invoke(layer, _parameters2[2]);
1229 replyString << result << TEXT("\r\n");
1233 SetReplyString(TEXT("402 CG ERROR\r\n"));
1237 SetReplyString(replyString.str());
1241 bool CGCommand::DoExecuteInfo()
1243 std::wstringstream replyString;
1244 replyString << TEXT("201 CG OK\r\n");
1246 if(_parameters.size() > 1)
1248 if(!ValidateLayer(_parameters[1]))
1250 SetReplyString(TEXT("403 CG ERROR\r\n"));
1254 int layer = _ttoi(_parameters[1].c_str());
1255 auto desc = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).description(layer);
1257 replyString << desc << TEXT("\r\n");
1261 auto info = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_proxy::DEFAULT_LAYER)).template_host_info();
1262 replyString << info << TEXT("\r\n");
1265 SetReplyString(replyString.str());
1269 bool DataCommand::DoExecute()
1271 std::wstring command = _parameters[0];
1272 if(command == TEXT("STORE"))
1273 return DoExecuteStore();
1274 else if(command == TEXT("RETRIEVE"))
1275 return DoExecuteRetrieve();
1276 else if(command == TEXT("REMOVE"))
1277 return DoExecuteRemove();
1278 else if(command == TEXT("LIST"))
1279 return DoExecuteList();
1281 SetReplyString(TEXT("403 DATA ERROR\r\n"));
1285 bool DataCommand::DoExecuteStore()
1287 if(_parameters.size() < 3)
1289 SetReplyString(TEXT("402 DATA STORE ERROR\r\n"));
1293 std::wstring filename = env::data_folder();
1294 filename.append(_parameters[1]);
1295 filename.append(TEXT(".ftd"));
1297 auto data_path = boost::filesystem::wpath(
1298 boost::filesystem::wpath(filename).parent_path());
1300 if(!boost::filesystem::exists(data_path))
1301 boost::filesystem::create_directories(data_path);
1303 std::wofstream datafile(filename.c_str());
1306 SetReplyString(TEXT("501 DATA STORE FAILED\r\n"));
1310 datafile << static_cast<wchar_t>(65279); // UTF-8 BOM character
1311 datafile << _parameters2[2] << std::flush;
1314 std::wstring replyString = TEXT("202 DATA STORE OK\r\n");
1315 SetReplyString(replyString);
1319 bool DataCommand::DoExecuteRetrieve()
1321 if(_parameters.size() < 2)
1323 SetReplyString(TEXT("402 DATA RETRIEVE ERROR\r\n"));
1327 std::wstring filename = env::data_folder();
1328 filename.append(_parameters[1]);
1329 filename.append(TEXT(".ftd"));
1331 std::wstring file_contents = read_file(boost::filesystem::wpath(filename));
1333 if (file_contents.empty())
1335 SetReplyString(TEXT("404 DATA RETRIEVE ERROR\r\n"));
1339 std::wstringstream reply(TEXT("201 DATA RETRIEVE OK\r\n"));
1341 reply << file_contents;
1343 SetReplyString(reply.str());
1347 bool DataCommand::DoExecuteRemove()
1349 if (_parameters.size() < 2)
1351 SetReplyString(TEXT("402 DATA REMOVE ERROR\r\n"));
1355 std::wstring filename = env::data_folder();
1356 filename.append(_parameters[1]);
1357 filename.append(TEXT(".ftd"));
1359 if (!boost::filesystem::exists(filename))
1361 SetReplyString(TEXT("404 DATA REMOVE ERROR\r\n"));
1365 if (!boost::filesystem::remove(filename))
1367 SetReplyString(TEXT("403 DATA REMOVE ERROR\r\n"));
1371 SetReplyString(TEXT("201 DATA REMOVE OK\r\n"));
1376 bool DataCommand::DoExecuteList()
1378 std::wstringstream replyString;
1379 replyString << TEXT("200 DATA LIST OK\r\n");
1381 for (boost::filesystem::recursive_directory_iterator itr(env::data_folder()), end; itr != end; ++itr)
1383 if(boost::filesystem::is_regular_file(itr->path()))
1385 if(!boost::iequals(itr->path().extension().wstring(), L".ftd"))
1388 auto relativePath = boost::filesystem::wpath(itr->path().wstring().substr(env::data_folder().size()-1, itr->path().wstring().size()));
1390 auto str = relativePath.replace_extension(TEXT("")).native();
1391 if(str[0] == '\\' || str[0] == '/')
1392 str = std::wstring(str.begin() + 1, str.end());
1394 replyString << str << TEXT("\r\n");
1398 replyString << TEXT("\r\n");
1400 SetReplyString(boost::to_upper_copy(replyString.str()));
1404 bool CinfCommand::DoExecute()
1406 std::wstringstream replyString;
1411 for (boost::filesystem::recursive_directory_iterator itr(env::media_folder()), end; itr != end && info.empty(); ++itr)
1413 auto path = itr->path();
1414 auto file = path.replace_extension(L"").filename();
1415 if(boost::iequals(file.wstring(), _parameters.at(0)))
1416 info += MediaInfo(itr->path()) + L"\r\n";
1421 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1424 replyString << TEXT("200 CINF OK\r\n");
1425 replyString << info << "\r\n";
1429 CASPAR_LOG_CURRENT_EXCEPTION();
1430 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1434 SetReplyString(replyString.str());
1438 void GenerateChannelInfo(int index, const spl::shared_ptr<core::video_channel>& pChannel, std::wstringstream& replyString)
1440 replyString << index+1 << TEXT(" ") << pChannel->video_format_desc().name << TEXT(" PLAYING") << TEXT("\r\n");
1443 bool InfoCommand::DoExecute()
1445 std::wstringstream replyString;
1447 boost::property_tree::xml_writer_settings<wchar_t> w(' ', 3);
1451 if(_parameters.size() >= 1 && _parameters[0] == L"TEMPLATE")
1453 replyString << L"201 INFO TEMPLATE OK\r\n";
1455 // Needs to be extended for any file, not just flash.
1457 auto filename = flash::find_template(env::template_folder() + _parameters.at(1));
1459 std::wstringstream str;
1460 str << u16(flash::read_template_meta_info(filename));
1461 boost::property_tree::wptree info;
1462 boost::property_tree::xml_parser::read_xml(str, info, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
1464 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1466 else if(_parameters.size() >= 1 && _parameters[0] == L"CONFIG")
1468 replyString << L"201 INFO CONFIG OK\r\n";
1470 boost::property_tree::write_xml(replyString, caspar::env::properties(), w);
1472 else if(_parameters.size() >= 1 && _parameters[0] == L"PATHS")
1474 replyString << L"201 INFO PATHS OK\r\n";
1476 boost::property_tree::wptree info;
1477 info.add_child(L"paths", caspar::env::properties().get_child(L"configuration.paths"));
1478 info.add(L"paths.initial-path", boost::filesystem3::initial_path().wstring() + L"\\");
1480 boost::property_tree::write_xml(replyString, info, w);
1482 else if(_parameters.size() >= 1 && _parameters[0] == L"SYSTEM")
1484 replyString << L"201 INFO SYSTEM OK\r\n";
1486 boost::property_tree::wptree info;
1488 info.add(L"system.name", caspar::system_product_name());
1489 info.add(L"system.windows.name", caspar::win_product_name());
1490 info.add(L"system.windows.service-pack", caspar::win_sp_version());
1491 info.add(L"system.cpu", caspar::cpu_info());
1493 BOOST_FOREACH(auto device, caspar::decklink::device_list())
1494 info.add(L"system.decklink.device", device);
1496 BOOST_FOREACH(auto device, caspar::bluefish::device_list())
1497 info.add(L"system.bluefish.device", device);
1499 info.add(L"system.flash", caspar::flash::version());
1500 //info.add(L"system.free-image", caspar::image::version());
1501 info.add(L"system.ffmpeg.avcodec", caspar::ffmpeg::avcodec_version());
1502 info.add(L"system.ffmpeg.avformat", caspar::ffmpeg::avformat_version());
1503 info.add(L"system.ffmpeg.avfilter", caspar::ffmpeg::avfilter_version());
1504 info.add(L"system.ffmpeg.avutil", caspar::ffmpeg::avutil_version());
1505 info.add(L"system.ffmpeg.swscale", caspar::ffmpeg::swscale_version());
1507 boost::property_tree::write_xml(replyString, info, w);
1509 else if(_parameters.size() >= 1 && _parameters[0] == L"SERVER")
1511 replyString << L"201 INFO SERVER OK\r\n";
1513 boost::property_tree::wptree info;
1516 BOOST_FOREACH(auto channel, channels_)
1517 info.add_child(L"channels.channel", channel->info())
1518 .add(L"index", ++index);
1520 boost::property_tree::write_xml(replyString, info, w);
1524 if(_parameters.size() >= 1)
1526 replyString << TEXT("201 INFO OK\r\n");
1527 boost::property_tree::wptree info;
1529 std::vector<std::wstring> split;
1530 boost::split(split, _parameters[0], boost::is_any_of("-"));
1532 int layer = std::numeric_limits<int>::min();
1533 int channel = boost::lexical_cast<int>(split[0]) - 1;
1535 if(split.size() > 1)
1536 layer = boost::lexical_cast<int>(split[1]);
1538 if(layer == std::numeric_limits<int>::min())
1540 info.add_child(L"channel", channels_.at(channel)->info())
1541 .add(L"index", channel);
1545 if(_parameters.size() >= 2)
1547 if(_parameters[1] == L"B")
1548 info.add_child(L"producer", channels_.at(channel)->stage().background(layer).get()->info());
1550 info.add_child(L"producer", channels_.at(channel)->stage().foreground(layer).get()->info());
1554 info.add_child(L"layer", channels_.at(channel)->stage().info(layer).get())
1555 .add(L"index", layer);
1558 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1562 // This is needed for backwards compatibility with old clients
1563 replyString << TEXT("200 INFO OK\r\n");
1564 for(size_t n = 0; n < channels_.size(); ++n)
1565 GenerateChannelInfo(n, channels_[n], replyString);
1572 CASPAR_LOG_CURRENT_EXCEPTION();
1573 SetReplyString(TEXT("403 INFO ERROR\r\n"));
1577 replyString << TEXT("\r\n");
1578 SetReplyString(replyString.str());
1582 bool ClsCommand::DoExecute()
1594 std::wstringstream replyString;
1595 replyString << TEXT("200 CLS OK\r\n");
1596 replyString << ListMedia();
1597 replyString << TEXT("\r\n");
1598 SetReplyString(boost::to_upper_copy(replyString.str()));
1602 CASPAR_LOG_CURRENT_EXCEPTION();
1603 SetReplyString(TEXT("501 CLS FAILED\r\n"));
1610 bool TlsCommand::DoExecute()
1614 std::wstringstream replyString;
1615 replyString << TEXT("200 TLS OK\r\n");
1617 replyString << ListTemplates();
1618 replyString << TEXT("\r\n");
1620 SetReplyString(replyString.str());
1624 CASPAR_LOG_CURRENT_EXCEPTION();
1625 SetReplyString(TEXT("501 TLS FAILED\r\n"));
1631 bool VersionCommand::DoExecute()
1633 std::wstring replyString = TEXT("201 VERSION OK\r\n") + env::version() + TEXT("\r\n");
1635 if(_parameters.size() > 0)
1637 if(_parameters[0] == L"FLASH")
1638 replyString = TEXT("201 VERSION OK\r\n") + flash::version() + TEXT("\r\n");
1639 else if(_parameters[0] == L"TEMPLATEHOST")
1640 replyString = TEXT("201 VERSION OK\r\n") + flash::cg_version() + TEXT("\r\n");
1641 else if(_parameters[0] != L"SERVER")
1642 replyString = TEXT("403 VERSION ERROR\r\n");
1645 SetReplyString(replyString);
1649 bool ByeCommand::DoExecute()
1651 GetClientInfo()->Disconnect();
1655 bool SetCommand::DoExecute()
1659 std::wstring name = _parameters[0];
1660 std::transform(name.begin(), name.end(), name.begin(), toupper);
1662 std::wstring value = _parameters[1];
1663 std::transform(value.begin(), value.end(), value.begin(), toupper);
1665 if(name == TEXT("MODE"))
1667 auto format_desc = core::video_format_desc(value);
1668 if(format_desc.format != core::video_format::invalid)
1670 GetChannel()->video_format_desc(format_desc);
1671 SetReplyString(TEXT("202 SET MODE OK\r\n"));
1674 SetReplyString(TEXT("501 SET MODE FAILED\r\n"));
1678 this->SetReplyString(TEXT("403 SET ERROR\r\n"));
1683 CASPAR_LOG_CURRENT_EXCEPTION();
1684 SetReplyString(TEXT("501 SET FAILED\r\n"));
1693 }} //namespace caspar