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
23 #include "../StdAfx.h"
25 #pragma warning (disable: 4244)
27 #include "CIIProtocolStrategy.h"
28 #include "CIICommandsImpl.h"
31 #include <modules/flash/producer/cg_proxy.h>
32 #include <boost/locale.hpp>
33 #include <boost/algorithm/string/trim.hpp>
34 #include <boost/algorithm/string/split.hpp>
35 #include <boost/lexical_cast.hpp>
37 namespace caspar { namespace protocol { namespace cii {
41 void MediaCommand::Setup(const std::vector<std::wstring>& parameters)
43 graphicProfile_ = parameters[1].substr(2);
46 void MediaCommand::Execute()
48 pCIIStrategy_->SetProfile(graphicProfile_);
54 void WriteCommand::Setup(const std::vector<std::wstring>& parameters)
58 if(parameters.size() > 2)
60 targetName_ = parameters[1];
61 templateName_ = parameters[2];
63 std::wstringstream dataStream;
65 dataStream << TEXT("<templateData>");
67 std::vector<std::wstring>::size_type end = parameters.size();
68 for(std::vector<std::wstring>::size_type i = 3; i < end; ++i)
69 dataStream << TEXT("<componentData id=\"field") << i-2 << TEXT("\"><data id=\"text\" value=\"") << parameters[i] << TEXT("\" /></componentData>");
71 dataStream << TEXT("</templateData>");
72 xmlData_ = dataStream.str();
75 catch(std::exception) {
79 void WriteCommand::Execute()
81 pCIIStrategy_->WriteTemplateData(templateName_, targetName_, xmlData_);
87 void ImagestoreCommand::Setup(const std::vector<std::wstring>& parameters)
89 if(parameters[1] == TEXT("7") && parameters.size() > 2)
90 titleName_ = parameters[2].substr(0, 4);
93 void ImagestoreCommand::Execute()
95 pCIIStrategy_->DisplayTemplate(titleName_);
100 // MiscellaneousCommand
101 void MiscellaneousCommand::Setup(const std::vector<std::wstring>& parameters)
103 //HAWRYS: V\5\3\1\1\namn.tga\1
105 if((parameters.size() > 5) && parameters[1] == TEXT("5") && parameters[2] == TEXT("3"))
107 filename_ = parameters[5];
108 filename_ = filename_.substr(0, filename_.find_last_of(TEXT('.')));
109 filename_.append(L".ft");
114 //NEPTUNE: V\5\13\1\X\Template\0\TabField1\TabField2...
115 // Add Template to layer X in the active templatehost
116 if((parameters.size() > 5) && parameters[1] == TEXT("5") && parameters[2] == TEXT("13"))
118 layer_ = _ttoi(parameters[4].c_str());
119 filename_ = parameters[5];
120 if(filename_.find(L"PK/") == std::wstring::npos && filename_.find(L"PK\\") == std::wstring::npos)
121 filename_ = L"PK/" + filename_;
124 if(parameters.size() > 7) {
125 std::wstringstream dataStream;
127 dataStream << TEXT("<templateData>");
128 std::vector<std::wstring>::size_type end = parameters.size();
129 for(std::vector<std::wstring>::size_type i = 7; i < end; ++i) {
130 dataStream << TEXT("<componentData id=\"f") << i-7 << TEXT("\"><data id=\"text\" value=\"") << parameters[i] << TEXT("\" /></componentData>");
132 dataStream << TEXT("</templateData>");
134 xmlData_ = dataStream.str();
138 // VIDEO MODE V\5\14\MODE
139 if((parameters.size() > 3) && parameters[1] == TEXT("5") && parameters[2] == TEXT("14"))
141 std::wstring value = parameters[3];
142 std::transform(value.begin(), value.end(), value.begin(), toupper);
144 this->pCIIStrategy_->GetChannel()->video_format_desc(core::video_format_desc(value));
148 void MiscellaneousCommand::Execute()
151 pCIIStrategy_->DisplayMediaFile(filename_);
153 //TODO: Need to be checked for validity
156 // HACK fix. The data sent is UTF8, however the protocol is implemented for ISO-8859-1. Instead of doing risky changes we simply convert into proper encoding when leaving protocol code.
157 auto xmlData2 = boost::locale::conv::utf_to_utf<wchar_t, char>(std::string(xmlData_.begin(), xmlData_.end()));
158 flash::create_cg_proxy(pCIIStrategy_->GetChannel()).add(layer_, filename_, false, TEXT(""), xmlData2);
165 void KeydataCommand::Execute()
168 pCIIStrategy_->DisplayTemplate(titleName_);
171 //TODO: Need to be checked for validity
173 flash::create_cg_proxy(pCIIStrategy_->GetChannel(), casparLayer_).stop(layer_, 0);
175 pCIIStrategy_->GetChannel()->stage().clear();
177 flash::create_cg_proxy(pCIIStrategy_->GetChannel(), casparLayer_).play(layer_);
180 void KeydataCommand::Setup(const std::vector<std::wstring>& parameters) {
181 //HAWRYS: Y\<205><247><202><196><192><192><200><248>
182 //parameter[1] looks like this: "=g:XXXXh" where XXXX is the name that we want
183 if(parameters[1].size() > 6)
185 titleName_.resize(4);
188 if(parameters[1][i+3] < 176) {
189 titleName_ = TEXT("");
192 titleName_[i] = parameters[1][i+3]-144;
197 casparLayer_ = flash::cg_proxy::DEFAULT_LAYER;
198 if(parameters.size() > 2)
200 //The layer parameter now supports casparlayers.
201 //the format is [CasparLayer]-[FlashLayer]
202 std::wstring str = boost::trim_copy(parameters[2]);
203 std::vector<std::wstring> split;
204 boost::split(split, str, boost::is_any_of("-"));
208 casparLayer_ = boost::lexical_cast<int>(split[0]);
211 layer_ = boost::lexical_cast<int>(split[1]);
215 casparLayer_ = flash::cg_proxy::DEFAULT_LAYER;
221 if(parameters[1].at(0) == 27) //NEPTUNE: Y\<27>\X Stop layer X.
223 else if(static_cast<unsigned char>(parameters[1].at(1)) == 190) //NEPTUNE: Y\<254> Clear Canvas.
225 else if(static_cast<unsigned char>(parameters[1].at(1)) == 149) //NEPTUNE: Y\<213><243>\X Play layer X.
226 state_ = 3; //UPDATE 2011-05-09: These char-codes are aparently not valid after converting to wide-chars
227 //the correct sequence is <195><149><195><179>