2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG (www.casparcg.com).
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
19 * Author: Nicklas P Andersson
\r
22 #include "../StdAfx.h"
\r
24 #if defined(_MSC_VER)
\r
25 #pragma warning (push, 1) // TODO: Legacy code, just disable warnings
\r
28 #include "AMCPCommandsImpl.h"
\r
29 #include "AMCPProtocolStrategy.h"
\r
31 #include <common/env.h>
\r
33 #include <common/log/log.h>
\r
34 #include <common/diagnostics/graph.h>
\r
35 #include <common/os/windows/current_version.h>
\r
36 #include <common/os/windows/system_info.h>
\r
38 #include <core/producer/frame_producer.h>
\r
39 #include <core/video_format.h>
\r
40 #include <core/producer/transition/transition_producer.h>
\r
41 #include <core/producer/frame/frame_transform.h>
\r
42 #include <core/producer/stage.h>
\r
43 #include <core/producer/layer.h>
\r
44 #include <core/mixer/mixer.h>
\r
45 #include <core/consumer/output.h>
\r
47 #include <modules/bluefish/bluefish.h>
\r
48 #include <modules/decklink/decklink.h>
\r
49 #include <modules/ffmpeg/ffmpeg.h>
\r
50 #include <modules/flash/flash.h>
\r
51 #include <modules/flash/util/swf.h>
\r
52 #include <modules/flash/producer/flash_producer.h>
\r
53 #include <modules/flash/producer/cg_producer.h>
\r
54 #include <modules/ffmpeg/producer/util/util.h>
\r
55 #include <modules/image/image.h>
\r
57 #include <algorithm>
\r
63 #include <boost/date_time/posix_time/posix_time.hpp>
\r
64 #include <boost/lexical_cast.hpp>
\r
65 #include <boost/algorithm/string.hpp>
\r
66 #include <boost/filesystem.hpp>
\r
67 #include <boost/regex.hpp>
\r
68 #include <boost/property_tree/xml_parser.hpp>
\r
72 100 [action] Information om att något har hänt
\r
73 101 [action] Information om att något har hänt, en rad data skickas
\r
75 202 [kommando] OK Kommandot har utförts
\r
76 201 [kommando] OK Kommandot har utförts, och en rad data skickas tillbaka
\r
77 200 [kommando] OK Kommandot har utförts, och flera rader data skickas tillbaka. Avslutas med tomrad
\r
79 400 ERROR Kommandot kunde inte förstås
\r
80 401 [kommando] ERROR Ogiltig kanal
\r
81 402 [kommando] ERROR Parameter saknas
\r
82 403 [kommando] ERROR Ogiltig parameter
\r
83 404 [kommando] ERROR Mediafilen hittades inte
\r
85 500 FAILED Internt configurationfel
\r
86 501 [kommando] FAILED Internt configurationfel
\r
87 502 [kommando] FAILED Oläslig mediafil
\r
89 600 [kommando] FAILED funktion ej implementerad
\r
92 namespace caspar { namespace protocol {
\r
94 using namespace core;
\r
96 std::wstring MediaInfo(const boost::filesystem::wpath& path)
\r
98 if(boost::filesystem::is_regular_file(path))
\r
100 std::wstring clipttype = TEXT(" N/A ");
\r
101 std::wstring extension = boost::to_upper_copy(path.extension());
\r
102 if(extension == TEXT(".TGA") || extension == TEXT(".COL") || extension == L".PNG" || extension == L".JPEG" || extension == L".JPG" ||
\r
103 extension == L"GIF" || extension == L"BMP")
\r
104 clipttype = TEXT(" STILL ");
\r
105 else if(extension == TEXT(".WAV") || extension == TEXT(".MP3"))
\r
106 clipttype = TEXT(" STILL ");
\r
107 else if(caspar::ffmpeg::is_valid_file(path.file_string()) || extension == L".CT")
\r
108 clipttype = TEXT(" MOVIE ");
\r
110 if(clipttype != TEXT(" N/A "))
\r
112 auto is_not_digit = [](char c){ return std::isdigit(c) == 0; };
\r
114 auto relativePath = boost::filesystem::wpath(path.file_string().substr(env::media_folder().size()-1, path.file_string().size()));
\r
116 auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(path)));
\r
117 writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), is_not_digit), writeTimeStr.end());
\r
118 auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end());
\r
120 auto sizeStr = boost::lexical_cast<std::wstring>(boost::filesystem::file_size(path));
\r
121 sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), is_not_digit), sizeStr.end());
\r
122 auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end());
\r
124 auto str = relativePath.replace_extension(TEXT("")).external_file_string();
\r
125 if(str[0] == '\\' || str[0] == '/')
\r
126 str = std::wstring(str.begin() + 1, str.end());
\r
128 return std::wstring() + TEXT("\"") + str +
\r
129 + TEXT("\" ") + clipttype +
\r
130 + TEXT(" ") + sizeStr +
\r
131 + TEXT(" ") + writeTimeWStr +
\r
138 std::wstring ListMedia()
\r
140 std::wstringstream replyString;
\r
141 for (boost::filesystem::wrecursive_directory_iterator itr(env::media_folder()), end; itr != end; ++itr)
\r
142 replyString << MediaInfo(itr->path());
\r
144 return boost::to_upper_copy(replyString.str());
\r
147 std::wstring ListTemplates()
\r
149 std::wstringstream replyString;
\r
151 for (boost::filesystem::wrecursive_directory_iterator itr(env::template_folder()), end; itr != end; ++itr)
\r
153 if(boost::filesystem::is_regular_file(itr->path()) && (itr->path().extension() == L".ft" || itr->path().extension() == L".ct"))
\r
155 auto relativePath = boost::filesystem::wpath(itr->path().file_string().substr(env::template_folder().size()-1, itr->path().file_string().size()));
\r
157 auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(itr->path())));
\r
158 writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), [](char c){ return std::isdigit(c) == 0;}), writeTimeStr.end());
\r
159 auto writeTimeWStr = std::wstring(writeTimeStr.begin(), writeTimeStr.end());
\r
161 auto sizeStr = boost::lexical_cast<std::string>(boost::filesystem::file_size(itr->path()));
\r
162 sizeStr.erase(std::remove_if(sizeStr.begin(), sizeStr.end(), [](char c){ return std::isdigit(c) == 0;}), sizeStr.end());
\r
164 auto sizeWStr = std::wstring(sizeStr.begin(), sizeStr.end());
\r
166 std::wstring dir = relativePath.parent_path().external_directory_string();
\r
167 std::wstring file = boost::to_upper_copy(relativePath.filename());
\r
168 relativePath = boost::filesystem::wpath(dir + L"/" + file);
\r
170 auto str = relativePath.replace_extension(TEXT("")).external_file_string();
\r
171 if(str[0] == '\\' || str[0] == '/')
\r
172 str = std::wstring(str.begin() + 1, str.end());
\r
174 replyString << TEXT("\"") << str
\r
175 << TEXT("\" ") << sizeWStr
\r
176 << TEXT(" ") << writeTimeWStr
\r
180 return replyString.str();
\r
185 AMCPCommand::AMCPCommand() : channelIndex_(0), scheduling_(Default), layerIndex_(-1)
\r
188 void AMCPCommand::SendReply()
\r
193 if(replyString_.empty())
\r
195 pClientInfo_->Send(replyString_);
\r
198 void AMCPCommand::Clear()
\r
200 pChannel_->stage()->clear();
\r
201 pClientInfo_.reset();
\r
203 _parameters.clear();
\r
206 bool DiagnosticsCommand::DoExecute()
\r
210 diagnostics::show_graphs(true);
\r
212 SetReplyString(TEXT("202 DIAG OK\r\n"));
\r
218 CASPAR_LOG_CURRENT_EXCEPTION();
\r
219 SetReplyString(TEXT("502 DIAG FAILED\r\n"));
\r
224 bool CallCommand::DoExecute()
\r
226 //Perform loading of the clip
\r
229 auto what = _parameters.at(0);
\r
231 std::wstring param = _parameters2.at(1);
\r
232 for(auto it = std::begin(_parameters2)+2; it != std::end(_parameters2); ++it)
\r
233 param += L" " + *it;
\r
235 boost::unique_future<std::wstring> result;
\r
237 result = GetChannel()->stage()->call(GetLayerIndex(), false, param);
\r
238 else if(what == L"F")
\r
239 result = GetChannel()->stage()->call(GetLayerIndex(), true, param);
\r
241 result = GetChannel()->stage()->call(GetLayerIndex(), true, _parameters.at(0) + L" " + param);
\r
243 if(!result.timed_wait(boost::posix_time::seconds(2)))
\r
244 BOOST_THROW_EXCEPTION(timed_out());
\r
246 CASPAR_LOG(info) << "Executed call: " << _parameters[0] << TEXT(" successfully");
\r
248 std::wstringstream replyString;
\r
249 if(result.get().empty())
\r
250 replyString << TEXT("202 CALL OK\r\n");
\r
252 replyString << TEXT("201 CALL OK\r\n") << result.get() << L"\r\n";
\r
254 SetReplyString(replyString.str());
\r
260 CASPAR_LOG_CURRENT_EXCEPTION();
\r
261 SetReplyString(TEXT("502 CALL FAILED\r\n"));
\r
266 bool MixerCommand::DoExecute()
\r
268 //Perform loading of the clip
\r
271 if(_parameters[0] == L"KEYER" || _parameters[0] == L"IS_KEY")
\r
273 bool value = lexical_cast_or_default(_parameters.at(1), false);
\r
274 auto transform = [=](frame_transform transform) -> frame_transform
\r
276 transform.is_key = value;
\r
280 int layer = GetLayerIndex();
\r
281 GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform);
\r
283 else if(_parameters[0] == L"OPACITY")
\r
285 int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0;
\r
286 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
\r
288 double value = boost::lexical_cast<double>(_parameters.at(1));
\r
290 auto transform = [=](frame_transform transform) -> frame_transform
\r
292 transform.opacity = value;
\r
296 int layer = GetLayerIndex();
\r
297 GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);
\r
299 else if(_parameters[0] == L"FILL" || _parameters[0] == L"FILL_RECT")
\r
301 int duration = _parameters.size() > 5 ? lexical_cast_or_default(_parameters[5], 0) : 0;
\r
302 std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear";
\r
303 double x = boost::lexical_cast<double>(_parameters.at(1));
\r
304 double y = boost::lexical_cast<double>(_parameters.at(2));
\r
305 double x_s = boost::lexical_cast<double>(_parameters.at(3));
\r
306 double y_s = boost::lexical_cast<double>(_parameters.at(4));
\r
308 auto transform = [=](frame_transform transform) mutable -> frame_transform
\r
310 transform.fill_translation[0] = x;
\r
311 transform.fill_translation[1] = y;
\r
312 transform.fill_scale[0] = x_s;
\r
313 transform.fill_scale[1] = y_s;
\r
314 transform.clip_translation[0] = x;
\r
315 transform.clip_translation[1] = y;
\r
316 transform.clip_scale[0] = x_s;
\r
317 transform.clip_scale[1] = y_s;
\r
321 int layer = GetLayerIndex();
\r
322 GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);
\r
324 else if(_parameters[0] == L"CLIP" || _parameters[0] == L"CLIP_RECT")
\r
326 int duration = _parameters.size() > 5 ? lexical_cast_or_default(_parameters[5], 0) : 0;
\r
327 std::wstring tween = _parameters.size() > 6 ? _parameters[6] : L"linear";
\r
328 double x = boost::lexical_cast<double>(_parameters.at(1));
\r
329 double y = boost::lexical_cast<double>(_parameters.at(2));
\r
330 double x_s = boost::lexical_cast<double>(_parameters.at(3));
\r
331 double y_s = boost::lexical_cast<double>(_parameters.at(4));
\r
333 auto transform = [=](frame_transform transform) -> frame_transform
\r
335 transform.clip_translation[0] = x;
\r
336 transform.clip_translation[1] = y;
\r
337 transform.clip_scale[0] = x_s;
\r
338 transform.clip_scale[1] = y_s;
\r
342 int layer = GetLayerIndex();
\r
343 GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);
\r
345 else if(_parameters[0] == L"GRID")
\r
347 int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0;
\r
348 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
\r
349 int n = boost::lexical_cast<int>(_parameters.at(1));
\r
350 double delta = 1.0/static_cast<double>(n);
\r
351 for(int x = 0; x < n; ++x)
\r
353 for(int y = 0; y < n; ++y)
\r
355 int index = x+y*n+1;
\r
356 auto transform = [=](frame_transform transform) -> frame_transform
\r
358 transform.fill_translation[0] = x*delta;
\r
359 transform.fill_translation[1] = y*delta;
\r
360 transform.fill_scale[0] = delta;
\r
361 transform.fill_scale[1] = delta;
\r
362 transform.clip_translation[0] = x*delta;
\r
363 transform.clip_translation[1] = y*delta;
\r
364 transform.clip_scale[0] = delta;
\r
365 transform.clip_scale[1] = delta;
\r
368 GetChannel()->stage()->apply_frame_transform(index, transform, duration, tween);
\r
372 else if(_parameters[0] == L"BLEND")
\r
374 auto blend_str = _parameters.at(1);
\r
375 int layer = GetLayerIndex();
\r
376 GetChannel()->mixer()->set_blend_mode(GetLayerIndex(), get_blend_mode(blend_str));
\r
378 else if(_parameters[0] == L"BRIGHTNESS")
\r
380 auto value = boost::lexical_cast<double>(_parameters.at(1));
\r
381 int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0;
\r
382 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
\r
383 auto transform = [=](frame_transform transform) -> frame_transform
\r
385 transform.brightness = value;
\r
389 int layer = GetLayerIndex();
\r
390 GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);
\r
392 else if(_parameters[0] == L"SATURATION")
\r
394 auto value = boost::lexical_cast<double>(_parameters.at(1));
\r
395 int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0;
\r
396 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
\r
397 auto transform = [=](frame_transform transform) -> frame_transform
\r
399 transform.saturation = value;
\r
403 int layer = GetLayerIndex();
\r
404 GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);
\r
406 else if(_parameters[0] == L"CONTRAST")
\r
408 auto value = boost::lexical_cast<double>(_parameters.at(1));
\r
409 int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0;
\r
410 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
\r
411 auto transform = [=](frame_transform transform) -> frame_transform
\r
413 transform.contrast = value;
\r
417 int layer = GetLayerIndex();
\r
418 GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);
\r
420 else if(_parameters[0] == L"LEVELS")
\r
423 value.min_input = boost::lexical_cast<double>(_parameters.at(1));
\r
424 value.max_input = boost::lexical_cast<double>(_parameters.at(2));
\r
425 value.gamma = boost::lexical_cast<double>(_parameters.at(3));
\r
426 value.min_output = boost::lexical_cast<double>(_parameters.at(4));
\r
427 value.max_output = boost::lexical_cast<double>(_parameters.at(5));
\r
428 int duration = _parameters.size() > 6 ? lexical_cast_or_default(_parameters[6], 0) : 0;
\r
429 std::wstring tween = _parameters.size() > 7 ? _parameters[7] : L"linear";
\r
431 auto transform = [=](frame_transform transform) -> frame_transform
\r
433 transform.levels = value;
\r
437 int layer = GetLayerIndex();
\r
438 GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);
\r
440 else if(_parameters[0] == L"VOLUME")
\r
442 int duration = _parameters.size() > 2 ? lexical_cast_or_default(_parameters[2], 0) : 0;
\r
443 std::wstring tween = _parameters.size() > 3 ? _parameters[3] : L"linear";
\r
444 double value = boost::lexical_cast<double>(_parameters[1]);
\r
446 auto transform = [=](frame_transform transform) -> frame_transform
\r
448 transform.volume = value;
\r
452 int layer = GetLayerIndex();
\r
453 GetChannel()->stage()->apply_frame_transform(GetLayerIndex(), transform, duration, tween);
\r
455 else if(_parameters[0] == L"CLEAR")
\r
457 int layer = GetLayerIndex(std::numeric_limits<int>::max());
\r
458 if(layer == std::numeric_limits<int>::max())
\r
459 GetChannel()->stage()->clear_transforms();
\r
461 GetChannel()->stage()->clear_transforms(layer);
\r
465 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
\r
469 SetReplyString(TEXT("202 MIXER OK\r\n"));
\r
473 catch(file_not_found&)
\r
475 CASPAR_LOG_CURRENT_EXCEPTION();
\r
476 SetReplyString(TEXT("404 MIXER ERROR\r\n"));
\r
481 CASPAR_LOG_CURRENT_EXCEPTION();
\r
482 SetReplyString(TEXT("502 MIXER FAILED\r\n"));
\r
487 bool SwapCommand::DoExecute()
\r
489 //Perform loading of the clip
\r
492 if(GetLayerIndex(-1) != -1)
\r
494 std::vector<std::string> strs;
\r
495 boost::split(strs, _parameters[0], boost::is_any_of("-"));
\r
497 auto ch1 = GetChannel();
\r
498 auto ch2 = GetChannels().at(boost::lexical_cast<int>(strs.at(0))-1);
\r
500 int l1 = GetLayerIndex();
\r
501 int l2 = boost::lexical_cast<int>(strs.at(1));
\r
503 ch1->stage()->swap_layer(l1, l2, ch2->stage());
\r
507 auto ch1 = GetChannel();
\r
508 auto ch2 = GetChannels().at(boost::lexical_cast<int>(_parameters[0])-1);
\r
509 ch1->stage()->swap_layers(ch2->stage());
\r
512 CASPAR_LOG(info) << "Swapped successfully";
\r
514 SetReplyString(TEXT("202 SWAP OK\r\n"));
\r
518 catch(file_not_found&)
\r
520 CASPAR_LOG_CURRENT_EXCEPTION();
\r
521 SetReplyString(TEXT("404 SWAP ERROR\r\n"));
\r
526 CASPAR_LOG_CURRENT_EXCEPTION();
\r
527 SetReplyString(TEXT("502 SWAP FAILED\r\n"));
\r
532 bool AddCommand::DoExecute()
\r
534 //Perform loading of the clip
\r
537 auto consumer = create_consumer(_parameters);
\r
538 GetChannel()->output()->add(GetLayerIndex(consumer->index()), consumer);
\r
540 CASPAR_LOG(info) << "Added " << _parameters[0] << TEXT(" successfully");
\r
542 SetReplyString(TEXT("202 ADD OK\r\n"));
\r
546 catch(file_not_found&)
\r
548 CASPAR_LOG_CURRENT_EXCEPTION();
\r
549 SetReplyString(TEXT("404 ADD ERROR\r\n"));
\r
554 CASPAR_LOG_CURRENT_EXCEPTION();
\r
555 SetReplyString(TEXT("502 ADD FAILED\r\n"));
\r
560 bool RemoveCommand::DoExecute()
\r
562 //Perform loading of the clip
\r
565 auto index = GetLayerIndex(std::numeric_limits<int>::min());
\r
566 if(index == std::numeric_limits<int>::min())
\r
567 index = create_consumer(_parameters)->index();
\r
569 GetChannel()->output()->remove(index);
\r
571 SetReplyString(TEXT("202 REMOVE OK\r\n"));
\r
575 catch(file_not_found&)
\r
577 CASPAR_LOG_CURRENT_EXCEPTION();
\r
578 SetReplyString(TEXT("404 REMOVE ERROR\r\n"));
\r
583 CASPAR_LOG_CURRENT_EXCEPTION();
\r
584 SetReplyString(TEXT("502 REMOVE FAILED\r\n"));
\r
589 bool LoadCommand::DoExecute()
\r
591 //Perform loading of the clip
\r
594 _parameters[0] = _parameters[0];
\r
595 auto pFP = create_producer(GetChannel()->mixer(), _parameters);
\r
596 GetChannel()->stage()->load(GetLayerIndex(), pFP, true);
\r
598 CASPAR_LOG(info) << "Loaded " << _parameters[0] << TEXT(" successfully");
\r
600 SetReplyString(TEXT("202 LOAD OK\r\n"));
\r
604 catch(file_not_found&)
\r
606 CASPAR_LOG_CURRENT_EXCEPTION();
\r
607 SetReplyString(TEXT("404 LOAD ERROR\r\n"));
\r
612 CASPAR_LOG_CURRENT_EXCEPTION();
\r
613 SetReplyString(TEXT("502 LOAD FAILED\r\n"));
\r
620 //std::function<std::wstring()> channel_cg_add_command::parse(const std::wstring& message, const std::vector<renderer::render_device_ptr>& channels)
\r
622 // 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>.*)?");
\r
624 // boost::wsmatch what;
\r
625 // if(!boost::regex_match(message, what, expr))
\r
628 // auto info = channel_info::parse(what, channels);
\r
630 // int flash_layer_index = boost::lexical_cast<int>(what["FLASH_LAYER"].str());
\r
632 // std::wstring templatename = what["TEMPLATE"].str();
\r
633 // bool play_on_load = what["PLAY_ON_LOAD"].matched ? what["PLAY_ON_LOAD"].str() != L"0" : 0;
\r
634 // std::wstring start_label = what["START_LABEL"].str();
\r
635 // std::wstring data = get_data(what["DATA"].str());
\r
637 // boost::replace_all(templatename, "\"", "");
\r
639 // return [=]() -> std::wstring
\r
641 // std::wstring fullFilename = flash::flash_producer::find_template(server::template_folder() + templatename);
\r
642 // if(fullFilename.empty())
\r
643 // BOOST_THROW_EXCEPTION(file_not_found());
\r
645 // std::wstring extension = boost::filesystem::wpath(fullFilename).extension();
\r
646 // std::wstring filename = templatename;
\r
647 // filename.append(extension);
\r
649 // flash::flash::get_default_cg_producer(info.video_channel, std::max<int>(DEFAULT_CHANNEL_LAYER+1, info.layer_index))
\r
650 // ->add(flash_layer_index, filename, play_on_load, start_label, data);
\r
652 // CASPAR_LOG(info) << L"Executed [amcp_channel_cg_add]";
\r
656 bool LoadbgCommand::DoExecute()
\r
658 transition_info transitionInfo;
\r
660 bool bLoop = false;
\r
664 std::wstring message;
\r
665 for(size_t n = 0; n < _parameters.size(); ++n)
\r
666 message += _parameters[n] + L" ";
\r
668 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)?.*");
\r
669 boost::wsmatch what;
\r
670 if(boost::regex_match(message, what, expr))
\r
672 auto transition = what["TRANSITION"].str();
\r
673 transitionInfo.duration = lexical_cast_or_default<size_t>(what["DURATION"].str());
\r
674 auto direction = what["DIRECTION"].matched ? what["DIRECTION"].str() : L"";
\r
675 auto tween = what["TWEEN"].matched ? what["TWEEN"].str() : L"";
\r
676 transitionInfo.tweener = get_tweener(tween);
\r
678 if(transition == TEXT("CUT"))
\r
679 transitionInfo.type = transition::cut;
\r
680 else if(transition == TEXT("MIX"))
\r
681 transitionInfo.type = transition::mix;
\r
682 else if(transition == TEXT("PUSH"))
\r
683 transitionInfo.type = transition::push;
\r
684 else if(transition == TEXT("SLIDE"))
\r
685 transitionInfo.type = transition::slide;
\r
686 else if(transition == TEXT("WIPE"))
\r
687 transitionInfo.type = transition::wipe;
\r
689 if(direction == TEXT("FROMLEFT"))
\r
690 transitionInfo.direction = transition_direction::from_left;
\r
691 else if(direction == TEXT("FROMRIGHT"))
\r
692 transitionInfo.direction = transition_direction::from_right;
\r
693 else if(direction == TEXT("LEFT"))
\r
694 transitionInfo.direction = transition_direction::from_right;
\r
695 else if(direction == TEXT("RIGHT"))
\r
696 transitionInfo.direction = transition_direction::from_left;
\r
699 //Perform loading of the clip
\r
702 _parameters[0] = _parameters[0];
\r
703 auto pFP = create_producer(GetChannel()->mixer(), _parameters);
\r
704 if(pFP == frame_producer::empty())
\r
705 BOOST_THROW_EXCEPTION(file_not_found() << msg_info(_parameters.size() > 0 ? u8(_parameters[0]) : ""));
\r
707 bool auto_play = std::find(_parameters.begin(), _parameters.end(), L"AUTO") != _parameters.end();
\r
709 auto pFP2 = create_transition_producer(GetChannel()->get_video_format_desc().field_mode, pFP, transitionInfo);
\r
710 GetChannel()->stage()->load(GetLayerIndex(), pFP2, false, auto_play ? transitionInfo.duration : -1); // TODO: LOOP
\r
712 CASPAR_LOG(info) << "Loaded " << _parameters[0] << TEXT(" successfully to background");
\r
713 SetReplyString(TEXT("202 LOADBG OK\r\n"));
\r
717 catch(file_not_found&)
\r
719 CASPAR_LOG_CURRENT_EXCEPTION();
\r
720 SetReplyString(TEXT("404 LOADBG ERROR\r\n"));
\r
725 CASPAR_LOG_CURRENT_EXCEPTION();
\r
726 SetReplyString(TEXT("502 LOADBG FAILED\r\n"));
\r
731 bool PauseCommand::DoExecute()
\r
735 GetChannel()->stage()->pause(GetLayerIndex());
\r
736 SetReplyString(TEXT("202 PAUSE OK\r\n"));
\r
741 SetReplyString(TEXT("501 PAUSE FAILED\r\n"));
\r
747 bool PlayCommand::DoExecute()
\r
751 if(!_parameters.empty())
\r
754 lbg.SetChannel(GetChannel());
\r
755 lbg.SetChannelIndex(GetChannelIndex());
\r
756 lbg.SetLayerIntex(GetLayerIndex());
\r
757 lbg.SetClientInfo(GetClientInfo());
\r
758 for(auto it = _parameters.begin(); it != _parameters.end(); ++it)
\r
759 lbg.AddParameter(*it);
\r
761 CASPAR_LOG(warning) << " Failed to play.";
\r
763 CASPAR_LOG(info) << "Playing " << _parameters[0];
\r
766 GetChannel()->stage()->play(GetLayerIndex());
\r
768 SetReplyString(TEXT("202 PLAY OK\r\n"));
\r
773 SetReplyString(TEXT("501 PLAY FAILED\r\n"));
\r
779 bool StopCommand::DoExecute()
\r
783 GetChannel()->stage()->stop(GetLayerIndex());
\r
784 SetReplyString(TEXT("202 STOP OK\r\n"));
\r
789 SetReplyString(TEXT("501 STOP FAILED\r\n"));
\r
795 bool ClearCommand::DoExecute()
\r
797 int index = GetLayerIndex(std::numeric_limits<int>::min());
\r
798 if(index != std::numeric_limits<int>::min())
\r
799 GetChannel()->stage()->clear(index);
\r
801 GetChannel()->stage()->clear();
\r
803 SetReplyString(TEXT("202 CLEAR OK\r\n"));
\r
808 bool PrintCommand::DoExecute()
\r
810 GetChannel()->output()->add(create_consumer(boost::assign::list_of(L"IMAGE")));
\r
812 SetReplyString(TEXT("202 PRINT OK\r\n"));
\r
817 bool LogCommand::DoExecute()
\r
819 if(_parameters.at(0) == L"LEVEL")
\r
820 log::set_log_level(_parameters.at(1));
\r
822 SetReplyString(TEXT("202 LOG OK\r\n"));
\r
827 bool CGCommand::DoExecute()
\r
829 std::wstring command = _parameters[0];
\r
830 if(command == TEXT("ADD"))
\r
831 return DoExecuteAdd();
\r
832 else if(command == TEXT("PLAY"))
\r
833 return DoExecutePlay();
\r
834 else if(command == TEXT("STOP"))
\r
835 return DoExecuteStop();
\r
836 else if(command == TEXT("NEXT"))
\r
837 return DoExecuteNext();
\r
838 else if(command == TEXT("REMOVE"))
\r
839 return DoExecuteRemove();
\r
840 else if(command == TEXT("CLEAR"))
\r
841 return DoExecuteClear();
\r
842 else if(command == TEXT("UPDATE"))
\r
843 return DoExecuteUpdate();
\r
844 else if(command == TEXT("INVOKE"))
\r
845 return DoExecuteInvoke();
\r
846 else if(command == TEXT("INFO"))
\r
847 return DoExecuteInfo();
\r
849 SetReplyString(TEXT("403 CG ERROR\r\n"));
\r
853 bool CGCommand::ValidateLayer(const std::wstring& layerstring) {
\r
854 int length = layerstring.length();
\r
855 for(int i = 0; i < length; ++i) {
\r
856 if(!_istdigit(layerstring[i])) {
\r
864 bool CGCommand::DoExecuteAdd() {
\r
865 //CG 1 ADD 0 "template_folder/templatename" [STARTLABEL] 0/1 [DATA]
\r
867 int layer = 0; //_parameters[1]
\r
868 // std::wstring templateName; //_parameters[2]
\r
869 std::wstring label; //_parameters[3]
\r
870 bool bDoStart = false; //_parameters[3] alt. _parameters[4]
\r
871 // std::wstring data; //_parameters[4] alt. _parameters[5]
\r
873 if(_parameters.size() < 4)
\r
875 SetReplyString(TEXT("402 CG ERROR\r\n"));
\r
878 unsigned int dataIndex = 4;
\r
880 if(!ValidateLayer(_parameters[1]))
\r
882 SetReplyString(TEXT("403 CG ERROR\r\n"));
\r
886 layer = _ttoi(_parameters[1].c_str());
\r
888 if(_parameters[3].length() > 1)
\r
890 label = _parameters2[3];
\r
893 if(_parameters.size() > 4 && _parameters[4].length() > 0) //read play-on-load-flag
\r
894 bDoStart = (_parameters[4][0]==TEXT('1')) ? true : false;
\r
897 SetReplyString(TEXT("402 CG ERROR\r\n"));
\r
901 else if(_parameters[3].length() > 0) { //read play-on-load-flag
\r
902 bDoStart = (_parameters[3][0]==TEXT('1')) ? true : false;
\r
906 SetReplyString(TEXT("403 CG ERROR\r\n"));
\r
910 const TCHAR* pDataString = 0;
\r
911 std::wstringstream data;
\r
912 std::wstring dataFromFile;
\r
913 if(_parameters.size() > dataIndex)
\r
915 const std::wstring& dataString = _parameters2[dataIndex];
\r
917 if(dataString[0] == TEXT('<')) //the data is an XML-string
\r
918 pDataString = dataString.c_str();
\r
921 //The data is not an XML-string, it must be a filename
\r
922 std::wstring filename = env::data_folder();
\r
923 filename.append(dataString);
\r
924 filename.append(TEXT(".ftd"));
\r
927 std::wifstream datafile(filename.c_str());
\r
931 data << datafile.rdbuf();
\r
934 //extract data to _parameters
\r
935 dataFromFile = data.str();
\r
936 pDataString = dataFromFile.c_str();
\r
941 std::wstring fullFilename = flash::find_template(env::template_folder() + _parameters[2]);
\r
942 if(!fullFilename.empty())
\r
944 std::wstring extension = boost::filesystem::wpath(fullFilename).extension();
\r
945 std::wstring filename = _parameters[2];
\r
946 filename.append(extension);
\r
948 flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->add(layer, filename, bDoStart, label, (pDataString!=0) ? pDataString : TEXT(""));
\r
949 SetReplyString(TEXT("202 CG OK\r\n"));
\r
953 CASPAR_LOG(warning) << "Could not find template " << _parameters[2];
\r
954 SetReplyString(TEXT("404 CG ERROR\r\n"));
\r
959 bool CGCommand::DoExecutePlay()
\r
961 if(_parameters.size() > 1)
\r
963 if(!ValidateLayer(_parameters[1]))
\r
965 SetReplyString(TEXT("403 CG ERROR\r\n"));
\r
968 int layer = _ttoi(_parameters[1].c_str());
\r
969 flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->play(layer);
\r
973 SetReplyString(TEXT("402 CG ERROR\r\n"));
\r
977 SetReplyString(TEXT("202 CG OK\r\n"));
\r
981 bool CGCommand::DoExecuteStop()
\r
983 if(_parameters.size() > 1)
\r
985 if(!ValidateLayer(_parameters[1]))
\r
987 SetReplyString(TEXT("403 CG ERROR\r\n"));
\r
990 int layer = _ttoi(_parameters[1].c_str());
\r
991 flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->stop(layer, 0);
\r
995 SetReplyString(TEXT("402 CG ERROR\r\n"));
\r
999 SetReplyString(TEXT("202 CG OK\r\n"));
\r
1003 bool CGCommand::DoExecuteNext()
\r
1005 if(_parameters.size() > 1)
\r
1007 if(!ValidateLayer(_parameters[1]))
\r
1009 SetReplyString(TEXT("403 CG ERROR\r\n"));
\r
1013 int layer = _ttoi(_parameters[1].c_str());
\r
1014 flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->next(layer);
\r
1018 SetReplyString(TEXT("402 CG ERROR\r\n"));
\r
1022 SetReplyString(TEXT("202 CG OK\r\n"));
\r
1026 bool CGCommand::DoExecuteRemove()
\r
1028 if(_parameters.size() > 1)
\r
1030 if(!ValidateLayer(_parameters[1]))
\r
1032 SetReplyString(TEXT("403 CG ERROR\r\n"));
\r
1036 int layer = _ttoi(_parameters[1].c_str());
\r
1037 flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->remove(layer);
\r
1041 SetReplyString(TEXT("402 CG ERROR\r\n"));
\r
1045 SetReplyString(TEXT("202 CG OK\r\n"));
\r
1049 bool CGCommand::DoExecuteClear()
\r
1051 GetChannel()->stage()->clear(GetLayerIndex(flash::cg_producer::DEFAULT_LAYER));
\r
1052 SetReplyString(TEXT("202 CG OK\r\n"));
\r
1056 bool CGCommand::DoExecuteUpdate()
\r
1060 if(!ValidateLayer(_parameters.at(1)))
\r
1062 SetReplyString(TEXT("403 CG ERROR\r\n"));
\r
1066 std::wstring dataString = _parameters2.at(2);
\r
1067 if(dataString.at(0) != TEXT('<'))
\r
1069 //The data is not an XML-string, it must be a filename
\r
1070 std::wstring filename = env::data_folder();
\r
1071 filename.append(dataString);
\r
1072 filename.append(TEXT(".ftd"));
\r
1075 std::wifstream datafile(filename.c_str());
\r
1078 std::wstringstream data;
\r
1080 data << datafile.rdbuf();
\r
1083 //extract data to _parameters
\r
1084 dataString = data.str();
\r
1088 int layer = _ttoi(_parameters.at(1).c_str());
\r
1089 flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->update(layer, dataString);
\r
1093 SetReplyString(TEXT("402 CG ERROR\r\n"));
\r
1097 SetReplyString(TEXT("202 CG OK\r\n"));
\r
1101 bool CGCommand::DoExecuteInvoke()
\r
1103 std::wstringstream replyString;
\r
1104 replyString << TEXT("201 CG OK\r\n");
\r
1106 if(_parameters.size() > 2)
\r
1108 if(!ValidateLayer(_parameters[1]))
\r
1110 SetReplyString(TEXT("403 CG ERROR\r\n"));
\r
1113 int layer = _ttoi(_parameters[1].c_str());
\r
1114 auto result = flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->invoke(layer, _parameters2[2]);
\r
1115 replyString << result << TEXT("\r\n");
\r
1119 SetReplyString(TEXT("402 CG ERROR\r\n"));
\r
1123 SetReplyString(replyString.str());
\r
1127 bool CGCommand::DoExecuteInfo()
\r
1129 std::wstringstream replyString;
\r
1130 replyString << TEXT("201 CG OK\r\n");
\r
1132 if(_parameters.size() > 1)
\r
1134 if(!ValidateLayer(_parameters[1]))
\r
1136 SetReplyString(TEXT("403 CG ERROR\r\n"));
\r
1140 int layer = _ttoi(_parameters[1].c_str());
\r
1141 auto desc = flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->description(layer);
\r
1143 replyString << desc << TEXT("\r\n");
\r
1147 auto info = flash::get_default_cg_producer(safe_ptr<core::video_channel>(GetChannel()), GetLayerIndex(flash::cg_producer::DEFAULT_LAYER))->template_host_info();
\r
1148 replyString << info << TEXT("\r\n");
\r
1151 SetReplyString(replyString.str());
\r
1155 bool DataCommand::DoExecute()
\r
1157 std::wstring command = _parameters[0];
\r
1158 if(command == TEXT("STORE"))
\r
1159 return DoExecuteStore();
\r
1160 else if(command == TEXT("RETRIEVE"))
\r
1161 return DoExecuteRetrieve();
\r
1162 else if(command == TEXT("LIST"))
\r
1163 return DoExecuteList();
\r
1165 SetReplyString(TEXT("403 DATA ERROR\r\n"));
\r
1169 bool DataCommand::DoExecuteStore()
\r
1171 if(_parameters.size() < 3)
\r
1173 SetReplyString(TEXT("402 DATA STORE ERROR\r\n"));
\r
1177 std::wstring filename = env::data_folder();
\r
1178 filename.append(_parameters[1]);
\r
1179 filename.append(TEXT(".ftd"));
\r
1181 std::wofstream datafile(filename.c_str());
\r
1184 SetReplyString(TEXT("501 DATA STORE FAILED\r\n"));
\r
1188 datafile << _parameters2[2];
\r
1191 std::wstring replyString = TEXT("202 DATA STORE OK\r\n");
\r
1192 SetReplyString(replyString);
\r
1196 bool DataCommand::DoExecuteRetrieve()
\r
1198 if(_parameters.size() < 2)
\r
1200 SetReplyString(TEXT("402 DATA RETRIEVE ERROR\r\n"));
\r
1204 std::wstring filename = env::data_folder();
\r
1205 filename.append(_parameters[1]);
\r
1206 filename.append(TEXT(".ftd"));
\r
1208 std::wifstream datafile(filename.c_str());
\r
1211 SetReplyString(TEXT("404 DATA RETRIEVE ERROR\r\n"));
\r
1215 std::wstringstream reply(TEXT("201 DATA RETRIEVE OK\r\n"));
\r
1216 std::wstring line;
\r
1217 bool bFirstLine = true;
\r
1218 while(std::getline(datafile, line))
\r
1223 bFirstLine = false;
\r
1230 SetReplyString(reply.str());
\r
1234 bool DataCommand::DoExecuteList()
\r
1236 std::wstringstream replyString;
\r
1237 replyString << TEXT("200 DATA LIST OK\r\n");
\r
1239 for (boost::filesystem::wrecursive_directory_iterator itr(env::data_folder()), end; itr != end; ++itr)
\r
1241 if(boost::filesystem::is_regular_file(itr->path()))
\r
1243 if(!boost::iequals(itr->path().extension(), L".ftd"))
\r
1246 auto relativePath = boost::filesystem::wpath(itr->path().file_string().substr(env::data_folder().size()-1, itr->path().file_string().size()));
\r
1248 auto str = relativePath.replace_extension(TEXT("")).external_file_string();
\r
1249 if(str[0] == '\\' || str[0] == '/')
\r
1250 str = std::wstring(str.begin() + 1, str.end());
\r
1252 replyString << str << TEXT("\r\n");
\r
1256 replyString << TEXT("\r\n");
\r
1258 SetReplyString(boost::to_upper_copy(replyString.str()));
\r
1262 bool CinfCommand::DoExecute()
\r
1264 std::wstringstream replyString;
\r
1268 std::wstring info;
\r
1269 for (boost::filesystem::wrecursive_directory_iterator itr(env::media_folder()), end; itr != end; ++itr)
\r
1271 auto path = itr->path();
\r
1272 auto file = path.replace_extension(L"").filename();
\r
1273 if(boost::iequals(file, _parameters.at(0)))
\r
1274 info += MediaInfo(itr->path()) + L"\r\n";
\r
1279 SetReplyString(TEXT("404 CINF ERROR\r\n"));
\r
1282 replyString << TEXT("200 CINF OK\r\n");
\r
1283 replyString << info << "\r\n";
\r
1287 SetReplyString(TEXT("404 CINF ERROR\r\n"));
\r
1291 SetReplyString(replyString.str());
\r
1295 void GenerateChannelInfo(int index, const safe_ptr<core::video_channel>& pChannel, std::wstringstream& replyString)
\r
1297 replyString << index+1 << TEXT(" ") << pChannel->get_video_format_desc().name << TEXT(" PLAYING") << TEXT("\r\n");
\r
1300 bool InfoCommand::DoExecute()
\r
1302 std::wstringstream replyString;
\r
1304 boost::property_tree::xml_writer_settings<wchar_t> w(' ', 3);
\r
1308 if(_parameters.size() >= 1 && _parameters[0] == L"TEMPLATE")
\r
1310 replyString << L"201 INFO TEMPLATE OK\r\n";
\r
1312 // Needs to be extended for any file, not just flash.
\r
1314 auto filename = flash::find_template(env::template_folder() + _parameters.at(1));
\r
1316 std::wstringstream str;
\r
1317 str << u16(flash::read_template_meta_info(filename));
\r
1318 boost::property_tree::wptree info;
\r
1319 boost::property_tree::xml_parser::read_xml(str, info, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
\r
1321 boost::property_tree::xml_parser::write_xml(replyString, info, w);
\r
1323 else if(_parameters.size() >= 1 && _parameters[0] == L"CONFIG")
\r
1325 replyString << L"201 INFO CONFIG OK\r\n";
\r
1327 boost::property_tree::write_xml(replyString, caspar::env::properties(), w);
\r
1329 else if(_parameters.size() >= 1 && _parameters[0] == L"PATHS")
\r
1331 replyString << L"201 INFO PATHS OK\r\n";
\r
1333 boost::property_tree::wptree info;
\r
1334 info.add_child(L"paths", caspar::env::properties().get_child(L"configuration.paths"));
\r
1335 info.add(L"paths.initial-path", boost::filesystem2::initial_path<boost::filesystem2::wpath>().directory_string() + L"\\");
\r
1337 boost::property_tree::write_xml(replyString, info, w);
\r
1339 else if(_parameters.size() >= 1 && _parameters[0] == L"SYSTEM")
\r
1341 replyString << L"201 INFO SYSTEM OK\r\n";
\r
1343 boost::property_tree::wptree info;
\r
1345 info.add(L"system.name", caspar::get_system_product_name());
\r
1346 info.add(L"system.windows.name", caspar::get_win_product_name());
\r
1347 info.add(L"system.windows.service-pack", caspar::get_win_sp_version());
\r
1348 info.add(L"system.cpu", caspar::get_cpu_info());
\r
1350 BOOST_FOREACH(auto device, caspar::decklink::get_device_list())
\r
1351 info.add(L"system.decklink.device", device);
\r
1353 BOOST_FOREACH(auto device, caspar::bluefish::get_device_list())
\r
1354 info.add(L"system.bluefish.device", device);
\r
1356 info.add(L"system.flash", caspar::flash::get_version());
\r
1357 info.add(L"system.free-image", caspar::image::get_version());
\r
1358 info.add(L"system.ffmpeg.avcodec", caspar::ffmpeg::get_avcodec_version());
\r
1359 info.add(L"system.ffmpeg.avformat", caspar::ffmpeg::get_avformat_version());
\r
1360 info.add(L"system.ffmpeg.avfilter", caspar::ffmpeg::get_avfilter_version());
\r
1361 info.add(L"system.ffmpeg.avutil", caspar::ffmpeg::get_avutil_version());
\r
1362 info.add(L"system.ffmpeg.swscale", caspar::ffmpeg::get_swscale_version());
\r
1364 boost::property_tree::write_xml(replyString, info, w);
\r
1366 else if(_parameters.size() >= 1 && _parameters[0] == L"SERVER")
\r
1368 replyString << L"201 INFO SYSTEM OK\r\n";
\r
1370 boost::property_tree::wptree info;
\r
1373 BOOST_FOREACH(auto channel, channels_)
\r
1374 info.add_child(L"channels.channel", channel->info())
\r
1375 .add(L"index", ++index);
\r
1377 boost::property_tree::write_xml(replyString, info, w);
\r
1381 if(_parameters.size() >= 1)
\r
1383 replyString << TEXT("201 INFO OK\r\n");
\r
1384 boost::property_tree::wptree info;
\r
1386 std::vector<std::wstring> split;
\r
1387 boost::split(split, _parameters[0], boost::is_any_of("-"));
\r
1389 int layer = std::numeric_limits<int>::min();
\r
1390 int channel = boost::lexical_cast<int>(split[0]) - 1;
\r
1392 if(split.size() > 1)
\r
1393 layer = boost::lexical_cast<int>(split[1]);
\r
1395 if(layer == std::numeric_limits<int>::min())
\r
1397 info.add_child(L"channel", channels_.at(channel)->info())
\r
1398 .add(L"index", channel);
\r
1402 if(_parameters.size() >= 2)
\r
1404 if(_parameters[1] == L"B")
\r
1405 info.add_child(L"producer", channels_.at(channel)->stage()->background(layer).get()->info());
\r
1407 info.add_child(L"producer", channels_.at(channel)->stage()->foreground(layer).get()->info());
\r
1411 info.add_child(L"layer", channels_.at(channel)->stage()->info(layer).get())
\r
1412 .add(L"index", layer);
\r
1415 boost::property_tree::xml_parser::write_xml(replyString, info, w);
\r
1419 // This is needed for backwards compatibility with old clients
\r
1420 replyString << TEXT("200 INFO OK\r\n");
\r
1421 for(size_t n = 0; n < channels_.size(); ++n)
\r
1422 GenerateChannelInfo(n, channels_[n], replyString);
\r
1429 SetReplyString(TEXT("403 INFO ERROR\r\n"));
\r
1433 replyString << TEXT("\r\n");
\r
1434 SetReplyString(replyString.str());
\r
1438 bool ClsCommand::DoExecute()
\r
1448 std::wstringstream replyString;
\r
1449 replyString << TEXT("200 CLS OK\r\n");
\r
1450 replyString << ListMedia();
\r
1451 replyString << TEXT("\r\n");
\r
1452 SetReplyString(boost::to_upper_copy(replyString.str()));
\r
1456 bool TlsCommand::DoExecute()
\r
1458 std::wstringstream replyString;
\r
1459 replyString << TEXT("200 TLS OK\r\n");
\r
1461 replyString << ListTemplates();
\r
1462 replyString << TEXT("\r\n");
\r
1464 SetReplyString(replyString.str());
\r
1468 bool VersionCommand::DoExecute()
\r
1470 std::wstring replyString = TEXT("201 VERSION OK\r\n") + env::version() + TEXT("\r\n");
\r
1472 if(_parameters.size() > 0)
\r
1474 if(_parameters[0] == L"FLASH")
\r
1475 replyString = TEXT("201 VERSION OK\r\n") + flash::get_version() + TEXT("\r\n");
\r
1476 else if(_parameters[0] == L"TEMPLATEHOST")
\r
1477 replyString = TEXT("201 VERSION OK\r\n") + flash::get_cg_version() + TEXT("\r\n");
\r
1478 else if(_parameters[0] != L"SERVER")
\r
1479 replyString = TEXT("403 VERSION ERROR\r\n");
\r
1482 SetReplyString(replyString);
\r
1486 bool ByeCommand::DoExecute()
\r
1488 GetClientInfo()->Disconnect();
\r
1492 bool SetCommand::DoExecute()
\r
1494 std::wstring name = _parameters[0];
\r
1495 std::transform(name.begin(), name.end(), name.begin(), toupper);
\r
1497 std::wstring value = _parameters[1];
\r
1498 std::transform(value.begin(), value.end(), value.begin(), toupper);
\r
1500 if(name == TEXT("MODE"))
\r
1502 auto format_desc = core::video_format_desc::get(value);
\r
1503 if(format_desc.format != core::video_format::invalid)
\r
1505 GetChannel()->set_video_format_desc(format_desc);
\r
1506 SetReplyString(TEXT("202 SET MODE OK\r\n"));
\r
1509 SetReplyString(TEXT("501 SET MODE FAILED\r\n"));
\r
1513 this->SetReplyString(TEXT("403 SET ERROR\r\n"));
\r
1520 } //namespace amcp
\r
1521 }} //namespace caspar