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
99 503 [kommando] FAILED access denied
101 600 [kommando] FAILED funktion ej implementerad
104 namespace caspar { namespace protocol {
106 using namespace core;
108 std::wstring read_utf8_file(const boost::filesystem::wpath& file)
110 std::wstringstream result;
111 boost::filesystem::wifstream filestream(file);
118 result << filestream.rdbuf();
124 std::wstring read_latin1_file(const boost::filesystem::wpath& file)
126 boost::locale::generator gen;
127 gen.locale_cache_enabled(true);
128 gen.categories(boost::locale::codepage_facet);
130 std::stringstream result_stream;
131 boost::filesystem::ifstream filestream(file);
132 filestream.imbue(gen("en_US.ISO8859-1"));
137 result_stream << filestream.rdbuf();
140 std::string result = result_stream.str();
141 std::wstring widened_result;
143 // The first 255 codepoints in unicode is the same as in latin1
144 auto from_signed_to_signed = std::function<unsigned char(char)>(
145 [] (char c) { return static_cast<unsigned char>(c); }
148 result | boost::adaptors::transformed(from_signed_to_signed),
149 std::back_inserter(widened_result));
151 return widened_result;
154 std::wstring read_file(const boost::filesystem::wpath& file)
156 static const uint8_t BOM[] = {0xef, 0xbb, 0xbf};
158 if (!boost::filesystem::exists(file))
163 if (boost::filesystem::file_size(file) >= 3)
165 boost::filesystem::ifstream bom_stream(file);
168 bom_stream.read(header, 3);
171 if (std::memcmp(BOM, header, 3) == 0)
172 return read_utf8_file(file);
175 return read_latin1_file(file);
178 std::wstring MediaInfo(const boost::filesystem::path& path)
180 if(boost::filesystem::is_regular_file(path))
182 std::wstring clipttype = TEXT("N/A");
183 std::wstring extension = boost::to_upper_copy(path.extension().wstring());
184 if(extension == TEXT(".TGA") || extension == TEXT(".COL") || extension == L".PNG" || extension == L".JPEG" || extension == L".JPG" ||
185 extension == L"GIF" || extension == L"BMP")
186 clipttype = TEXT("STILL");
187 else if(extension == TEXT(".WAV") || extension == TEXT(".MP3"))
188 clipttype = TEXT("AUDIO");
189 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()))
190 clipttype = TEXT("MOVIE");
192 if(clipttype != TEXT("N/A"))
194 auto is_not_digit = [](char c){ return std::isdigit(c) == 0; };
196 auto relativePath = boost::filesystem::path(path.wstring().substr(env::media_folder().size()-1, path.wstring().size()));
198 auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(path)));
199 writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), is_not_digit), writeTimeStr.end());
200 auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end());
202 auto sizeStr = boost::lexical_cast<std::wstring>(boost::filesystem::file_size(path));
203 sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), is_not_digit), sizeStr.end());
204 auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end());
206 auto str = relativePath.replace_extension(TEXT("")).native();
207 while(str.size() > 0 && (str[0] == '\\' || str[0] == '/'))
208 str = std::wstring(str.begin() + 1, str.end());
210 return std::wstring() + TEXT("\"") + str +
211 + TEXT("\" ") + clipttype +
212 + TEXT(" ") + sizeStr +
213 + TEXT(" ") + writeTimeWStr +
220 std::wstring ListMedia()
222 std::wstringstream replyString;
223 for (boost::filesystem::recursive_directory_iterator itr(env::media_folder()), end; itr != end; ++itr)
224 replyString << MediaInfo(itr->path());
226 return boost::to_upper_copy(replyString.str());
229 std::wstring ListTemplates()
231 std::wstringstream replyString;
233 for (boost::filesystem::recursive_directory_iterator itr(env::template_folder()), end; itr != end; ++itr)
235 if(boost::filesystem::is_regular_file(itr->path()) && (itr->path().extension() == L".ft" || itr->path().extension() == L".ct"))
237 auto relativePath = boost::filesystem::wpath(itr->path().wstring().substr(env::template_folder().size()-1, itr->path().wstring().size()));
239 auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(itr->path())));
240 writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), [](char c){ return std::isdigit(c) == 0;}), writeTimeStr.end());
241 auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end());
243 auto sizeStr = boost::lexical_cast<std::string>(boost::filesystem::file_size(itr->path()));
244 sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), [](char c){ return std::isdigit(c) == 0;}), sizeStr.end());
246 auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end());
248 std::wstring dir = relativePath.parent_path().native();
249 std::wstring file = boost::to_upper_copy(relativePath.filename().wstring());
250 relativePath = boost::filesystem::wpath(dir + L"/" + file);
252 auto str = relativePath.replace_extension(TEXT("")).native();
253 boost::trim_if(str, boost::is_any_of("\\/"));
255 replyString << TEXT("\"") << str
256 << TEXT("\" ") << sizeWStr
257 << TEXT(" ") << writeTimeWStr
261 return replyString.str();
266 void AMCPCommand::SendReply()
268 if(replyString_.empty())
271 client_->send(std::move(replyString_));
274 bool DiagnosticsCommand::DoExecute()
278 diagnostics::show_graphs(true);
280 SetReplyString(TEXT("202 DIAG OK\r\n"));
286 CASPAR_LOG_CURRENT_EXCEPTION();
287 SetReplyString(TEXT("502 DIAG FAILED\r\n"));
292 bool ChannelGridCommand::DoExecute()
294 CASPAR_THROW_EXCEPTION(not_implemented());
297 //auto self = channels().back();
299 //std::vector<std::wstring> params;
300 //params.push_back(L"SCREEN");
301 //params.push_back(L"NAME");
302 //params.push_back(L"Channel Grid Window");
303 //auto screen = create_consumer(params);
305 //self->output().add(screen);
307 //BOOST_FOREACH(auto channel, channels())
309 // if(channel != self)
311 // auto producer = reroute::create_producer(self->frame_factory(), *channel);
312 // self->stage().load(index, producer, false);
313 // self->stage().play(index);
318 //int n = channels().size()-1;
319 //double delta = 1.0/static_cast<double>(n);
320 //for(int x = 0; x < n; ++x)
322 // for(int y = 0; y < n; ++y)
324 // int index = x+y*n+1;
325 // auto transform = [=](frame_transform transform) -> frame_transform
327 // transform.image_transform.fill_translation[0] = x*delta;
328 // transform.image_transform.fill_translation[1] = y*delta;
329 // transform.image_transform.fill_scale[0] = delta;
330 // transform.image_transform.fill_scale[1] = delta;
331 // transform.image_transform.clip_translation[0] = x*delta;
332 // transform.image_transform.clip_translation[1] = y*delta;
333 // transform.image_transform.clip_scale[0] = delta;
334 // transform.image_transform.clip_scale[1] = delta;
337 // self->stage().apply_transform(index, transform);
344 bool CallCommand::DoExecute()
346 //Perform loading of the clip
349 auto result = channel()->stage().call(layer_index(), parameters());
351 if(!result.timed_wait(boost::posix_time::seconds(2)))
352 CASPAR_THROW_EXCEPTION(timed_out());
354 std::wstringstream replyString;
355 if(result.get().empty())
356 replyString << TEXT("202 CALL OK\r\n");
358 replyString << TEXT("201 CALL OK\r\n") << result.get() << L"\r\n";
360 SetReplyString(replyString.str());
366 CASPAR_LOG_CURRENT_EXCEPTION();
367 SetReplyString(TEXT("502 CALL FAILED\r\n"));
372 tbb::concurrent_unordered_map<int, std::vector<stage::transform_tuple_t>> deferred_transforms;
374 bool MixerCommand::DoExecute()
376 //Perform loading of the clip
379 bool defer = boost::iequals(parameters().back(), L"DEFER");
381 parameters().pop_back();
383 std::vector<stage::transform_tuple_t> transforms;
385 if(boost::iequals(parameters()[0], L"KEYER") || boost::iequals(parameters()[0], L"IS_KEY"))
387 bool value = boost::lexical_cast<int>(parameters().at(1));
388 transforms.push_back(stage::transform_tuple_t(layer_index(), [=](frame_transform transform) -> frame_transform
390 transform.image_transform.is_key = value;
394 else if(boost::iequals(parameters()[0], L"OPACITY"))
396 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
397 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
399 double value = boost::lexical_cast<double>(parameters().at(1));
401 transforms.push_back(stage::transform_tuple_t(layer_index(), [=](frame_transform transform) -> frame_transform
403 transform.image_transform.opacity = value;
405 }, duration, tween));
407 else if(boost::iequals(parameters()[0], L"FILL") || boost::iequals(parameters()[0], L"FILL_RECT"))
409 int duration = parameters().size() > 5 ? boost::lexical_cast<int>(parameters()[5]) : 0;
410 std::wstring tween = parameters().size() > 6 ? parameters()[6] : L"linear";
411 double x = boost::lexical_cast<double>(parameters().at(1));
412 double y = boost::lexical_cast<double>(parameters().at(2));
413 double x_s = boost::lexical_cast<double>(parameters().at(3));
414 double y_s = boost::lexical_cast<double>(parameters().at(4));
416 transforms.push_back(stage::transform_tuple_t(layer_index(), [=](frame_transform transform) mutable -> frame_transform
418 transform.image_transform.fill_translation[0] = x;
419 transform.image_transform.fill_translation[1] = y;
420 transform.image_transform.fill_scale[0] = x_s;
421 transform.image_transform.fill_scale[1] = y_s;
423 }, duration, tween));
425 else if(boost::iequals(parameters()[0], L"CLIP") || boost::iequals(parameters()[0], L"CLIP_RECT"))
427 int duration = parameters().size() > 5 ? boost::lexical_cast<int>(parameters()[5]) : 0;
428 std::wstring tween = parameters().size() > 6 ? parameters()[6] : L"linear";
429 double x = boost::lexical_cast<double>(parameters().at(1));
430 double y = boost::lexical_cast<double>(parameters().at(2));
431 double x_s = boost::lexical_cast<double>(parameters().at(3));
432 double y_s = boost::lexical_cast<double>(parameters().at(4));
434 transforms.push_back(stage::transform_tuple_t(layer_index(), [=](frame_transform transform) -> frame_transform
436 transform.image_transform.clip_translation[0] = x;
437 transform.image_transform.clip_translation[1] = y;
438 transform.image_transform.clip_scale[0] = x_s;
439 transform.image_transform.clip_scale[1] = y_s;
441 }, duration, tween));
443 else if(boost::iequals(parameters()[0], L"GRID"))
445 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
446 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
447 int n = boost::lexical_cast<int>(parameters().at(1));
448 double delta = 1.0/static_cast<double>(n);
449 for(int x = 0; x < n; ++x)
451 for(int y = 0; y < n; ++y)
454 transforms.push_back(stage::transform_tuple_t(index, [=](frame_transform transform) -> frame_transform
456 transform.image_transform.fill_translation[0] = x*delta;
457 transform.image_transform.fill_translation[1] = y*delta;
458 transform.image_transform.fill_scale[0] = delta;
459 transform.image_transform.fill_scale[1] = delta;
460 transform.image_transform.clip_translation[0] = x*delta;
461 transform.image_transform.clip_translation[1] = y*delta;
462 transform.image_transform.clip_scale[0] = delta;
463 transform.image_transform.clip_scale[1] = delta;
465 }, duration, tween));
469 else if(boost::iequals(parameters()[0], L"BLEND"))
471 auto blend_str = parameters().at(1);
472 int layer = layer_index();
473 channel()->mixer().set_blend_mode(layer_index(), get_blend_mode(blend_str));
475 else if(boost::iequals(parameters()[0], L"MASTERVOLUME"))
477 float master_volume = boost::lexical_cast<float>(parameters().at(1));
478 channel()->mixer().set_master_volume(master_volume);
480 else if(boost::iequals(parameters()[0], L"BRIGHTNESS"))
482 auto value = boost::lexical_cast<double>(parameters().at(1));
483 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
484 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
485 transforms.push_back(stage::transform_tuple_t(layer_index(), [=](frame_transform transform) -> frame_transform
487 transform.image_transform.brightness = value;
489 }, duration, tween));
491 else if(boost::iequals(parameters()[0], L"SATURATION"))
493 auto value = boost::lexical_cast<double>(parameters().at(1));
494 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
495 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
496 transforms.push_back(stage::transform_tuple_t(layer_index(), [=](frame_transform transform) -> frame_transform
498 transform.image_transform.saturation = value;
500 }, duration, tween));
502 else if(parameters()[0] == L"CONTRAST")
504 auto value = boost::lexical_cast<double>(parameters().at(1));
505 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
506 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
507 transforms.push_back(stage::transform_tuple_t(layer_index(), [=](frame_transform transform) -> frame_transform
509 transform.image_transform.contrast = value;
511 }, duration, tween));
513 else if(boost::iequals(parameters()[0], L"LEVELS"))
516 value.min_input = boost::lexical_cast<double>(parameters().at(1));
517 value.max_input = boost::lexical_cast<double>(parameters().at(2));
518 value.gamma = boost::lexical_cast<double>(parameters().at(3));
519 value.min_output = boost::lexical_cast<double>(parameters().at(4));
520 value.max_output = boost::lexical_cast<double>(parameters().at(5));
521 int duration = parameters().size() > 6 ? boost::lexical_cast<int>(parameters()[6]) : 0;
522 std::wstring tween = parameters().size() > 7 ? parameters()[7] : L"linear";
524 transforms.push_back(stage::transform_tuple_t(layer_index(), [=](frame_transform transform) -> frame_transform
526 transform.image_transform.levels = value;
528 }, duration, tween));
530 else if(boost::iequals(parameters()[0], L"VOLUME"))
532 int duration = parameters().size() > 2 ? boost::lexical_cast<int>(parameters()[2]) : 0;
533 std::wstring tween = parameters().size() > 3 ? parameters()[3] : L"linear";
534 double value = boost::lexical_cast<double>(parameters()[1]);
536 transforms.push_back(stage::transform_tuple_t(layer_index(), [=](frame_transform transform) -> frame_transform
538 transform.audio_transform.volume = value;
540 }, duration, tween));
542 else if(boost::iequals(parameters()[0], L"CLEAR"))
544 int layer = layer_index(std::numeric_limits<int>::max());
546 if (layer == std::numeric_limits<int>::max())
548 channel()->stage().clear_transforms();
549 channel()->mixer().clear_blend_modes();
553 channel()->stage().clear_transforms(layer);
554 channel()->mixer().clear_blend_mode(layer);
557 else if(boost::iequals(parameters()[0], L"COMMIT"))
559 transforms = std::move(deferred_transforms[channel_index()]);
563 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
569 auto& defer_tranforms = deferred_transforms[channel_index()];
570 defer_tranforms.insert(defer_tranforms.end(), transforms.begin(), transforms.end());
573 channel()->stage().apply_transforms(transforms);
575 SetReplyString(TEXT("202 MIXER OK\r\n"));
579 catch(file_not_found&)
581 CASPAR_LOG_CURRENT_EXCEPTION();
582 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
587 CASPAR_LOG_CURRENT_EXCEPTION();
588 SetReplyString(TEXT("502 MIXER FAILED\r\n"));
593 bool SwapCommand::DoExecute()
595 //Perform loading of the clip
598 if(layer_index(-1) != -1)
600 std::vector<std::string> strs;
601 boost::split(strs, parameters()[0], boost::is_any_of("-"));
603 auto ch1 = channel();
604 auto ch2 = channels().at(boost::lexical_cast<int>(strs.at(0))-1);
606 int l1 = layer_index();
607 int l2 = boost::lexical_cast<int>(strs.at(1));
609 ch1->stage().swap_layer(l1, l2, ch2.channel->stage());
613 auto ch1 = channel();
614 auto ch2 = channels().at(boost::lexical_cast<int>(parameters()[0])-1);
615 ch1->stage().swap_layers(ch2.channel->stage());
618 SetReplyString(TEXT("202 SWAP OK\r\n"));
622 catch(file_not_found&)
624 CASPAR_LOG_CURRENT_EXCEPTION();
625 SetReplyString(TEXT("404 SWAP ERROR\r\n"));
630 CASPAR_LOG_CURRENT_EXCEPTION();
631 SetReplyString(TEXT("502 SWAP FAILED\r\n"));
636 bool AddCommand::DoExecute()
638 //Perform loading of the clip
641 //create_consumer still expects all parameters to be uppercase
642 BOOST_FOREACH(std::wstring& str, parameters())
644 boost::to_upper(str);
647 auto consumer = create_consumer(parameters());
648 channel()->output().add(layer_index(consumer->index()), consumer);
650 SetReplyString(TEXT("202 ADD OK\r\n"));
654 catch(file_not_found&)
656 CASPAR_LOG_CURRENT_EXCEPTION();
657 SetReplyString(TEXT("404 ADD ERROR\r\n"));
662 CASPAR_LOG_CURRENT_EXCEPTION();
663 SetReplyString(TEXT("502 ADD FAILED\r\n"));
668 bool RemoveCommand::DoExecute()
670 //Perform loading of the clip
673 auto index = layer_index(std::numeric_limits<int>::min());
674 if(index == std::numeric_limits<int>::min())
676 //create_consumer still expects all parameters to be uppercase
677 BOOST_FOREACH(std::wstring& str, parameters())
679 boost::to_upper(str);
682 index = create_consumer(parameters())->index();
685 channel()->output().remove(index);
687 SetReplyString(TEXT("202 REMOVE OK\r\n"));
691 catch(file_not_found&)
693 CASPAR_LOG_CURRENT_EXCEPTION();
694 SetReplyString(TEXT("404 REMOVE ERROR\r\n"));
699 CASPAR_LOG_CURRENT_EXCEPTION();
700 SetReplyString(TEXT("502 REMOVE FAILED\r\n"));
705 bool LoadCommand::DoExecute()
707 //Perform loading of the clip
710 auto pFP = create_producer(channel()->frame_factory(), channel()->video_format_desc(), parameters());
711 channel()->stage().load(layer_index(), pFP, true);
713 SetReplyString(TEXT("202 LOAD OK\r\n"));
717 catch(file_not_found&)
719 CASPAR_LOG_CURRENT_EXCEPTION();
720 SetReplyString(TEXT("404 LOAD ERROR\r\n"));
725 CASPAR_LOG_CURRENT_EXCEPTION();
726 SetReplyString(TEXT("502 LOAD FAILED\r\n"));
733 //std::function<std::wstring()> channel_cg_add_command::parse(const std::wstring& message, const std::vector<renderer::render_device_ptr>& channels)
735 // 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>.*)?");
737 // boost::wsmatch what;
738 // if(!boost::regex_match(message, what, expr))
741 // auto info = channel_info::parse(what, channels);
743 // int flash_layer_index = boost::lexical_cast<int>(what["FLASH_LAYER"].str());
745 // std::wstring templatename = what["TEMPLATE"].str();
746 // bool play_on_load = what["PLAY_ON_LOAD"].matched ? what["PLAY_ON_LOAD"].str() != L"0" : 0;
747 // std::wstring start_label = what["START_LABEL"].str();
748 // std::wstring data = get_data(what["DATA"].str());
750 // boost::replace_all(templatename, "\"", "");
752 // return [=]() -> std::wstring
754 // std::wstring fullFilename = flash::flash_producer::find_template(server::template_folder() + templatename);
755 // if(fullFilename.empty())
756 // CASPAR_THROW_EXCEPTION(file_not_found());
758 // std::wstring extension = boost::filesystem::wpath(fullFilename).extension();
759 // std::wstring filename = templatename;
760 // filename.append(extension);
762 // flash::flash::create_cg_proxy(info.video_channel, std::max<int>(DEFAULT_CHANNEL_LAYER+1, info.layer_index))
763 // ->add(flash_layer_index, filename, play_on_load, start_label, data);
765 // CASPAR_LOG(info) << L"Executed [amcp_channel_cg_add]";
769 bool LoadbgCommand::DoExecute()
771 transition_info transitionInfo;
777 std::wstring message;
778 for(size_t n = 0; n < parameters().size(); ++n)
779 message += boost::to_upper_copy(parameters()[n]) + L" ";
781 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)?.*");
783 if(boost::regex_match(message, what, expr))
785 auto transition = what["TRANSITION"].str();
786 transitionInfo.duration = boost::lexical_cast<size_t>(what["DURATION"].str());
787 auto direction = what["DIRECTION"].matched ? what["DIRECTION"].str() : L"";
788 auto tween = what["TWEEN"].matched ? what["TWEEN"].str() : L"";
789 transitionInfo.tweener = tween;
791 if(transition == TEXT("CUT"))
792 transitionInfo.type = transition_type::cut;
793 else if(transition == TEXT("MIX"))
794 transitionInfo.type = transition_type::mix;
795 else if(transition == TEXT("PUSH"))
796 transitionInfo.type = transition_type::push;
797 else if(transition == TEXT("SLIDE"))
798 transitionInfo.type = transition_type::slide;
799 else if(transition == TEXT("WIPE"))
800 transitionInfo.type = transition_type::wipe;
802 if(direction == TEXT("FROMLEFT"))
803 transitionInfo.direction = transition_direction::from_left;
804 else if(direction == TEXT("FROMRIGHT"))
805 transitionInfo.direction = transition_direction::from_right;
806 else if(direction == TEXT("LEFT"))
807 transitionInfo.direction = transition_direction::from_right;
808 else if(direction == TEXT("RIGHT"))
809 transitionInfo.direction = transition_direction::from_left;
812 //Perform loading of the clip
815 std::shared_ptr<core::frame_producer> pFP;
817 static boost::wregex expr(L"\\[(?<CHANNEL>\\d+)\\]", boost::regex::icase);
820 if(boost::regex_match(parameters().at(0), what, expr))
822 auto channel_index = boost::lexical_cast<int>(what["CHANNEL"].str());
823 pFP = reroute::create_producer(*channels().at(channel_index-1).channel);
827 pFP = create_producer(channel()->frame_factory(), channel()->video_format_desc(), parameters());
830 if(pFP == frame_producer::empty())
831 CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(parameters().size() > 0 ? parameters()[0] : L""));
833 bool auto_play = contains_param(L"AUTO", parameters());
835 auto pFP2 = create_transition_producer(channel()->video_format_desc().field_mode, spl::make_shared_ptr(pFP), transitionInfo);
837 channel()->stage().load(layer_index(), pFP2, false, transitionInfo.duration); // TODO: LOOP
839 channel()->stage().load(layer_index(), pFP2, false); // TODO: LOOP
842 SetReplyString(TEXT("202 LOADBG OK\r\n"));
846 catch(file_not_found&)
848 CASPAR_LOG(error) << L"File not found. No match found for parameters. Check syntax.";
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 channel()->stage().pause(layer_index());
865 SetReplyString(TEXT("202 PAUSE OK\r\n"));
870 SetReplyString(TEXT("501 PAUSE FAILED\r\n"));
876 bool PlayCommand::DoExecute()
880 if(!parameters().empty())
882 LoadbgCommand lbg(*this);
885 throw std::exception();
888 channel()->stage().play(layer_index());
890 SetReplyString(TEXT("202 PLAY OK\r\n"));
895 SetReplyString(TEXT("501 PLAY FAILED\r\n"));
901 bool StopCommand::DoExecute()
905 channel()->stage().stop(layer_index());
906 SetReplyString(TEXT("202 STOP OK\r\n"));
911 SetReplyString(TEXT("501 STOP FAILED\r\n"));
917 bool ClearCommand::DoExecute()
919 int index = layer_index(std::numeric_limits<int>::min());
920 if(index != std::numeric_limits<int>::min())
921 channel()->stage().clear(index);
923 channel()->stage().clear();
925 SetReplyString(TEXT("202 CLEAR OK\r\n"));
930 bool PrintCommand::DoExecute()
932 channel()->output().add(create_consumer(boost::assign::list_of(L"IMAGE")));
934 SetReplyString(TEXT("202 PRINT OK\r\n"));
939 bool LogCommand::DoExecute()
941 if(boost::iequals(parameters().at(0), L"LEVEL"))
942 log::set_log_level(parameters().at(1));
944 SetReplyString(TEXT("202 LOG OK\r\n"));
949 bool CGCommand::DoExecute()
953 std::wstring command = boost::to_upper_copy(parameters()[0]);
954 if(command == TEXT("ADD"))
955 return DoExecuteAdd();
956 else if(command == TEXT("PLAY"))
957 return DoExecutePlay();
958 else if(command == TEXT("STOP"))
959 return DoExecuteStop();
960 else if(command == TEXT("NEXT"))
961 return DoExecuteNext();
962 else if(command == TEXT("REMOVE"))
963 return DoExecuteRemove();
964 else if(command == TEXT("CLEAR"))
965 return DoExecuteClear();
966 else if(command == TEXT("UPDATE"))
967 return DoExecuteUpdate();
968 else if(command == TEXT("INVOKE"))
969 return DoExecuteInvoke();
970 else if(command == TEXT("INFO"))
971 return DoExecuteInfo();
975 CASPAR_LOG_CURRENT_EXCEPTION();
978 SetReplyString(TEXT("403 CG ERROR\r\n"));
982 bool CGCommand::ValidateLayer(const std::wstring& layerstring) {
983 int length = layerstring.length();
984 for(int i = 0; i < length; ++i) {
985 if(!_istdigit(layerstring[i])) {
993 bool CGCommand::DoExecuteAdd() {
994 //CG 1 ADD 0 "template_folder/templatename" [STARTLABEL] 0/1 [DATA]
996 int layer = 0; //_parameters[1]
997 // std::wstring templateName; //_parameters[2]
998 std::wstring label; //_parameters[3]
999 bool bDoStart = false; //_parameters[3] alt. _parameters[4]
1000 // std::wstring data; //_parameters[4] alt. _parameters[5]
1002 if(parameters().size() < 4)
1004 SetReplyString(TEXT("402 CG ERROR\r\n"));
1007 unsigned int dataIndex = 4;
1009 if(!ValidateLayer(parameters()[1]))
1011 SetReplyString(TEXT("403 CG ERROR\r\n"));
1015 layer = boost::lexical_cast<int>(parameters()[1]);
1017 if(parameters()[3].length() > 1)
1019 label = parameters()[3];
1022 if(parameters().size() > 4 && parameters()[4].length() > 0) //read play-on-load-flag
1023 bDoStart = (parameters()[4][0]==TEXT('1')) ? true : false;
1026 SetReplyString(TEXT("402 CG ERROR\r\n"));
1030 else if(parameters()[3].length() > 0) { //read play-on-load-flag
1031 bDoStart = (parameters()[3][0]==TEXT('1')) ? true : false;
1035 SetReplyString(TEXT("403 CG ERROR\r\n"));
1039 const TCHAR* pDataString = 0;
1040 std::wstringstream data;
1041 std::wstring dataFromFile;
1042 if(parameters().size() > dataIndex)
1044 const std::wstring& dataString = parameters()[dataIndex];
1046 if(dataString[0] == TEXT('<')) //the data is an XML-string
1047 pDataString = dataString.c_str();
1050 //The data is not an XML-string, it must be a filename
1051 std::wstring filename = env::data_folder();
1052 filename.append(dataString);
1053 filename.append(TEXT(".ftd"));
1055 dataFromFile = read_file(boost::filesystem::wpath(filename));
1056 pDataString = dataFromFile.c_str();
1060 std::wstring fullFilename = flash::find_template(env::template_folder() + parameters()[2]);
1061 if(!fullFilename.empty())
1063 std::wstring extension = boost::filesystem::path(fullFilename).extension().wstring();
1064 std::wstring filename = parameters()[2];
1065 filename.append(extension);
1067 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(channel()), layer_index(flash::cg_proxy::DEFAULT_LAYER)).add(layer, filename, bDoStart, label, (pDataString!=0) ? pDataString : TEXT(""));
1068 SetReplyString(TEXT("202 CG OK\r\n"));
1072 CASPAR_LOG(warning) << "Could not find template " << parameters()[2];
1073 SetReplyString(TEXT("404 CG ERROR\r\n"));
1078 bool CGCommand::DoExecutePlay()
1080 if(parameters().size() > 1)
1082 if(!ValidateLayer(parameters()[1]))
1084 SetReplyString(TEXT("403 CG ERROR\r\n"));
1087 int layer = boost::lexical_cast<int>(parameters()[1]);
1088 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(channel()), layer_index(flash::cg_proxy::DEFAULT_LAYER)).play(layer);
1092 SetReplyString(TEXT("402 CG ERROR\r\n"));
1096 SetReplyString(TEXT("202 CG OK\r\n"));
1100 bool CGCommand::DoExecuteStop()
1102 if(parameters().size() > 1)
1104 if(!ValidateLayer(parameters()[1]))
1106 SetReplyString(TEXT("403 CG ERROR\r\n"));
1109 int layer = boost::lexical_cast<int>(parameters()[1]);
1110 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(channel()), layer_index(flash::cg_proxy::DEFAULT_LAYER)).stop(layer, 0);
1114 SetReplyString(TEXT("402 CG ERROR\r\n"));
1118 SetReplyString(TEXT("202 CG OK\r\n"));
1122 bool CGCommand::DoExecuteNext()
1124 if(parameters().size() > 1)
1126 if(!ValidateLayer(parameters()[1]))
1128 SetReplyString(TEXT("403 CG ERROR\r\n"));
1132 int layer = boost::lexical_cast<int>(parameters()[1]);
1133 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(channel()), layer_index(flash::cg_proxy::DEFAULT_LAYER)).next(layer);
1137 SetReplyString(TEXT("402 CG ERROR\r\n"));
1141 SetReplyString(TEXT("202 CG OK\r\n"));
1145 bool CGCommand::DoExecuteRemove()
1147 if(parameters().size() > 1)
1149 if(!ValidateLayer(parameters()[1]))
1151 SetReplyString(TEXT("403 CG ERROR\r\n"));
1155 int layer = boost::lexical_cast<int>(parameters()[1]);
1156 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(channel()), layer_index(flash::cg_proxy::DEFAULT_LAYER)).remove(layer);
1160 SetReplyString(TEXT("402 CG ERROR\r\n"));
1164 SetReplyString(TEXT("202 CG OK\r\n"));
1168 bool CGCommand::DoExecuteClear()
1170 channel()->stage().clear(layer_index(flash::cg_proxy::DEFAULT_LAYER));
1171 SetReplyString(TEXT("202 CG OK\r\n"));
1175 bool CGCommand::DoExecuteUpdate()
1179 if(!ValidateLayer(parameters().at(1)))
1181 SetReplyString(TEXT("403 CG ERROR\r\n"));
1185 std::wstring dataString = parameters().at(2);
1186 if(dataString.at(0) != TEXT('<'))
1188 //The data is not an XML-string, it must be a filename
1189 std::wstring filename = env::data_folder();
1190 filename.append(dataString);
1191 filename.append(TEXT(".ftd"));
1193 dataString = read_file(boost::filesystem::wpath(filename));
1196 int layer = boost::lexical_cast<int>(parameters()[1]);
1197 flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(channel()), layer_index(flash::cg_proxy::DEFAULT_LAYER)).update(layer, dataString);
1201 SetReplyString(TEXT("402 CG ERROR\r\n"));
1205 SetReplyString(TEXT("202 CG OK\r\n"));
1209 bool CGCommand::DoExecuteInvoke()
1211 std::wstringstream replyString;
1212 replyString << TEXT("201 CG OK\r\n");
1214 if(parameters().size() > 2)
1216 if(!ValidateLayer(parameters()[1]))
1218 SetReplyString(TEXT("403 CG ERROR\r\n"));
1221 int layer = boost::lexical_cast<int>(parameters()[1]);
1222 auto result = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(channel()), layer_index(flash::cg_proxy::DEFAULT_LAYER)).invoke(layer, parameters()[2]);
1223 replyString << result << TEXT("\r\n");
1227 SetReplyString(TEXT("402 CG ERROR\r\n"));
1231 SetReplyString(replyString.str());
1235 bool CGCommand::DoExecuteInfo()
1237 std::wstringstream replyString;
1238 replyString << TEXT("201 CG OK\r\n");
1240 if(parameters().size() > 1)
1242 if(!ValidateLayer(parameters()[1]))
1244 SetReplyString(TEXT("403 CG ERROR\r\n"));
1248 int layer = boost::lexical_cast<int>(parameters()[1]);
1249 auto desc = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(channel()), layer_index(flash::cg_proxy::DEFAULT_LAYER)).description(layer);
1251 replyString << desc << TEXT("\r\n");
1255 auto info = flash::create_cg_proxy(spl::shared_ptr<core::video_channel>(channel()), layer_index(flash::cg_proxy::DEFAULT_LAYER)).template_host_info();
1256 replyString << info << TEXT("\r\n");
1259 SetReplyString(replyString.str());
1263 bool DataCommand::DoExecute()
1265 std::wstring command = boost::to_upper_copy(parameters()[0]);
1266 if(command == TEXT("STORE"))
1267 return DoExecuteStore();
1268 else if(command == TEXT("RETRIEVE"))
1269 return DoExecuteRetrieve();
1270 else if(command == TEXT("REMOVE"))
1271 return DoExecuteRemove();
1272 else if(command == TEXT("LIST"))
1273 return DoExecuteList();
1275 SetReplyString(TEXT("403 DATA ERROR\r\n"));
1279 bool DataCommand::DoExecuteStore()
1281 if(parameters().size() < 3)
1283 SetReplyString(TEXT("402 DATA STORE ERROR\r\n"));
1287 std::wstring filename = env::data_folder();
1288 filename.append(parameters()[1]);
1289 filename.append(TEXT(".ftd"));
1291 auto data_path = boost::filesystem::wpath(
1292 boost::filesystem::wpath(filename).parent_path());
1294 if(!boost::filesystem::exists(data_path))
1295 boost::filesystem::create_directories(data_path);
1297 std::wofstream datafile(filename.c_str());
1300 SetReplyString(TEXT("501 DATA STORE FAILED\r\n"));
1304 datafile << static_cast<wchar_t>(65279); // UTF-8 BOM character
1305 datafile << parameters()[2] << std::flush;
1308 std::wstring replyString = TEXT("202 DATA STORE OK\r\n");
1309 SetReplyString(replyString);
1313 bool DataCommand::DoExecuteRetrieve()
1315 if(parameters().size() < 2)
1317 SetReplyString(TEXT("402 DATA RETRIEVE ERROR\r\n"));
1321 std::wstring filename = env::data_folder();
1322 filename.append(parameters()[1]);
1323 filename.append(TEXT(".ftd"));
1325 std::wstring file_contents = read_file(boost::filesystem::wpath(filename));
1327 if (file_contents.empty())
1329 SetReplyString(TEXT("404 DATA RETRIEVE ERROR\r\n"));
1333 std::wstringstream reply(TEXT("201 DATA RETRIEVE OK\r\n"));
1335 reply << file_contents;
1337 SetReplyString(reply.str());
1341 bool DataCommand::DoExecuteRemove()
1343 if (parameters().size() < 2)
1345 SetReplyString(TEXT("402 DATA REMOVE ERROR\r\n"));
1349 std::wstring filename = env::data_folder();
1350 filename.append(parameters()[1]);
1351 filename.append(TEXT(".ftd"));
1353 if (!boost::filesystem::exists(filename))
1355 SetReplyString(TEXT("404 DATA REMOVE ERROR\r\n"));
1359 if (!boost::filesystem::remove(filename))
1361 SetReplyString(TEXT("403 DATA REMOVE ERROR\r\n"));
1365 SetReplyString(TEXT("201 DATA REMOVE OK\r\n"));
1370 bool DataCommand::DoExecuteList()
1372 std::wstringstream replyString;
1373 replyString << TEXT("200 DATA LIST OK\r\n");
1375 for (boost::filesystem::recursive_directory_iterator itr(env::data_folder()), end; itr != end; ++itr)
1377 if(boost::filesystem::is_regular_file(itr->path()))
1379 if(!boost::iequals(itr->path().extension().wstring(), L".ftd"))
1382 auto relativePath = boost::filesystem::wpath(itr->path().wstring().substr(env::data_folder().size()-1, itr->path().wstring().size()));
1384 auto str = relativePath.replace_extension(TEXT("")).native();
1385 if(str[0] == '\\' || str[0] == '/')
1386 str = std::wstring(str.begin() + 1, str.end());
1388 replyString << str << TEXT("\r\n");
1392 replyString << TEXT("\r\n");
1394 SetReplyString(boost::to_upper_copy(replyString.str()));
1398 bool CinfCommand::DoExecute()
1400 std::wstringstream replyString;
1405 for (boost::filesystem::recursive_directory_iterator itr(env::media_folder()), end; itr != end && info.empty(); ++itr)
1407 auto path = itr->path();
1408 auto file = path.replace_extension(L"").filename();
1409 if(boost::iequals(file.wstring(), parameters().at(0)))
1410 info += MediaInfo(itr->path()) + L"\r\n";
1415 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1418 replyString << TEXT("200 CINF OK\r\n");
1419 replyString << info << "\r\n";
1423 CASPAR_LOG_CURRENT_EXCEPTION();
1424 SetReplyString(TEXT("404 CINF ERROR\r\n"));
1428 SetReplyString(replyString.str());
1432 void GenerateChannelInfo(int index, const spl::shared_ptr<core::video_channel>& pChannel, std::wstringstream& replyString)
1434 replyString << index+1 << TEXT(" ") << pChannel->video_format_desc().name << TEXT(" PLAYING") << TEXT("\r\n");
1437 bool InfoCommand::DoExecute()
1439 std::wstringstream replyString;
1441 boost::property_tree::xml_writer_settings<wchar_t> w(' ', 3);
1445 if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"TEMPLATE"))
1447 replyString << L"201 INFO TEMPLATE OK\r\n";
1449 // Needs to be extended for any file, not just flash.
1451 auto filename = flash::find_template(env::template_folder() + parameters().at(1));
1453 std::wstringstream str;
1454 str << u16(flash::read_template_meta_info(filename));
1455 boost::property_tree::wptree info;
1456 boost::property_tree::xml_parser::read_xml(str, info, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
1458 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1460 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"CONFIG"))
1462 replyString << L"201 INFO CONFIG OK\r\n";
1464 boost::property_tree::write_xml(replyString, caspar::env::properties(), w);
1466 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"PATHS"))
1468 replyString << L"201 INFO PATHS OK\r\n";
1470 boost::property_tree::wptree info;
1471 info.add_child(L"paths", caspar::env::properties().get_child(L"configuration.paths"));
1472 info.add(L"paths.initial-path", boost::filesystem3::initial_path().wstring() + L"\\");
1474 boost::property_tree::write_xml(replyString, info, w);
1476 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"SYSTEM"))
1478 replyString << L"201 INFO SYSTEM OK\r\n";
1480 boost::property_tree::wptree info;
1482 info.add(L"system.name", caspar::system_product_name());
1483 info.add(L"system.windows.name", caspar::win_product_name());
1484 info.add(L"system.windows.service-pack", caspar::win_sp_version());
1485 info.add(L"system.cpu", caspar::cpu_info());
1487 BOOST_FOREACH(auto device, caspar::decklink::device_list())
1488 info.add(L"system.decklink.device", device);
1490 BOOST_FOREACH(auto device, caspar::bluefish::device_list())
1491 info.add(L"system.bluefish.device", device);
1493 info.add(L"system.flash", caspar::flash::version());
1494 //info.add(L"system.free-image", caspar::image::version());
1495 info.add(L"system.ffmpeg.avcodec", caspar::ffmpeg::avcodec_version());
1496 info.add(L"system.ffmpeg.avformat", caspar::ffmpeg::avformat_version());
1497 info.add(L"system.ffmpeg.avfilter", caspar::ffmpeg::avfilter_version());
1498 info.add(L"system.ffmpeg.avutil", caspar::ffmpeg::avutil_version());
1499 info.add(L"system.ffmpeg.swscale", caspar::ffmpeg::swscale_version());
1501 boost::property_tree::write_xml(replyString, info, w);
1503 else if(parameters().size() >= 1 && boost::iequals(parameters()[0], L"SERVER"))
1505 replyString << L"201 INFO SERVER OK\r\n";
1507 boost::property_tree::wptree info;
1510 BOOST_FOREACH(auto channel, channels())
1511 info.add_child(L"channels.channel", channel.channel->info())
1512 .add(L"index", ++index);
1514 boost::property_tree::write_xml(replyString, info, w);
1518 if(parameters().size() >= 1)
1520 replyString << TEXT("201 INFO OK\r\n");
1521 boost::property_tree::wptree info;
1523 std::vector<std::wstring> split;
1524 boost::split(split, parameters()[0], boost::is_any_of("-"));
1526 int layer = std::numeric_limits<int>::min();
1527 int channel = boost::lexical_cast<int>(split[0]) - 1;
1529 if(split.size() > 1)
1530 layer = boost::lexical_cast<int>(split[1]);
1532 if(layer == std::numeric_limits<int>::min())
1534 info.add_child(L"channel", channels().at(channel).channel->info())
1535 .add(L"index", channel);
1539 if(parameters().size() >= 2)
1541 if(boost::iequals(parameters()[1], L"B"))
1542 info.add_child(L"producer", channels().at(channel).channel->stage().background(layer).get()->info());
1544 info.add_child(L"producer", channels().at(channel).channel->stage().foreground(layer).get()->info());
1548 info.add_child(L"layer", channels().at(channel).channel->stage().info(layer).get())
1549 .add(L"index", layer);
1552 boost::property_tree::xml_parser::write_xml(replyString, info, w);
1556 // This is needed for backwards compatibility with old clients
1557 replyString << TEXT("200 INFO OK\r\n");
1558 for(size_t n = 0; n < channels().size(); ++n)
1559 GenerateChannelInfo(n, channels()[n].channel, replyString);
1566 CASPAR_LOG_CURRENT_EXCEPTION();
1567 SetReplyString(TEXT("403 INFO ERROR\r\n"));
1571 replyString << TEXT("\r\n");
1572 SetReplyString(replyString.str());
1576 bool ClsCommand::DoExecute()
1588 std::wstringstream replyString;
1589 replyString << TEXT("200 CLS OK\r\n");
1590 replyString << ListMedia();
1591 replyString << TEXT("\r\n");
1592 SetReplyString(boost::to_upper_copy(replyString.str()));
1596 CASPAR_LOG_CURRENT_EXCEPTION();
1597 SetReplyString(TEXT("501 CLS FAILED\r\n"));
1604 bool TlsCommand::DoExecute()
1608 std::wstringstream replyString;
1609 replyString << TEXT("200 TLS OK\r\n");
1611 replyString << ListTemplates();
1612 replyString << TEXT("\r\n");
1614 SetReplyString(replyString.str());
1618 CASPAR_LOG_CURRENT_EXCEPTION();
1619 SetReplyString(TEXT("501 TLS FAILED\r\n"));
1625 bool VersionCommand::DoExecute()
1627 std::wstring replyString = TEXT("201 VERSION OK\r\n") + env::version() + TEXT("\r\n");
1629 if(parameters().size() > 0)
1631 if(boost::iequals(parameters()[0], L"FLASH"))
1632 replyString = TEXT("201 VERSION OK\r\n") + flash::version() + TEXT("\r\n");
1633 else if(boost::iequals(parameters()[0], L"TEMPLATEHOST"))
1634 replyString = TEXT("201 VERSION OK\r\n") + flash::cg_version() + TEXT("\r\n");
1635 else if(!boost::iequals(parameters()[0], L"SERVER"))
1636 replyString = TEXT("403 VERSION ERROR\r\n");
1639 SetReplyString(replyString);
1643 bool ByeCommand::DoExecute()
1645 client()->disconnect();
1649 bool SetCommand::DoExecute()
1653 std::wstring name = boost::to_upper_copy(parameters()[0]);
1654 std::wstring value = boost::to_upper_copy(parameters()[1]);
1656 if(name == TEXT("MODE"))
1658 auto format_desc = core::video_format_desc(value);
1659 if(format_desc.format != core::video_format::invalid)
1661 channel()->video_format_desc(format_desc);
1662 SetReplyString(TEXT("202 SET MODE OK\r\n"));
1665 SetReplyString(TEXT("501 SET MODE FAILED\r\n"));
1669 this->SetReplyString(TEXT("403 SET ERROR\r\n"));
1674 CASPAR_LOG_CURRENT_EXCEPTION();
1675 SetReplyString(TEXT("501 SET FAILED\r\n"));
1682 bool LockCommand::DoExecute()
1686 auto it = parameters().begin();
1688 std::shared_ptr<caspar::IO::lock_container> lock;
1691 int channel_index = boost::lexical_cast<int>(*it) - 1;
1692 lock = channels().at(channel_index).lock;
1694 catch(const boost::bad_lexical_cast&) {}
1697 SetReplyString(L"401 LOCK ERROR\r\n");
1704 if(it == parameters().end()) //too few parameters
1706 SetReplyString(L"402 LOCK ERROR\r\n");
1710 std::wstring command = boost::to_upper_copy(*it);
1711 if(command == L"ACQUIRE")
1714 if(it == parameters().end()) //too few parameters
1716 SetReplyString(L"402 LOCK ACQUIRE ERROR\r\n");
1719 std::wstring lock_phrase = (*it);
1721 //TODO: read options
1725 //just lock one channel
1726 if(!lock->try_lock(lock_phrase, client()))
1728 SetReplyString(L"503 LOCK ACQUIRE FAILED\r\n");
1734 //TODO: lock all channels
1735 CASPAR_THROW_EXCEPTION(not_implemented());
1737 SetReplyString(L"202 LOCK ACQUIRE OK\r\n");
1740 else if(command == L"RELEASE")
1744 client()->remove_lifecycle_bound_object(lock->lifecycle_key());
1748 //TODO: lock all channels
1749 CASPAR_THROW_EXCEPTION(not_implemented());
1751 SetReplyString(L"202 LOCK RELEASE OK\r\n");
1753 else if(command == L"CLEAR")
1756 if(it == parameters().end())
1758 SetReplyString(L"402 LOCK CLEAR ERROR\r\n");
1761 std::wstring override_phrase = (*it);
1766 SetReplyString(L"202 LOCK CLEAR OK\r\n");
1770 SetReplyString(L"403 LOCK ERROR\r\n");
1776 CASPAR_LOG_CURRENT_EXCEPTION();
1777 SetReplyString(L"501 LOCK FAILED\r\n");
1786 }} //namespace caspar