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: Robert Nagy, ronag89@gmail.com
\r
22 #include "../StdAfx.h"
\r
24 #include "cg_proxy.h"
\r
26 #include "flash_producer.h"
\r
28 #include <common/env.h>
\r
30 #include <core/mixer/mixer.h>
\r
32 #include <boost/filesystem.hpp>
\r
33 #include <boost/format.hpp>
\r
34 #include <boost/algorithm/string.hpp>
\r
35 #include <boost/regex.hpp>
\r
36 #include <boost/property_tree/ptree.hpp>
\r
38 namespace caspar { namespace flash {
\r
40 struct cg_proxy::impl : boost::noncopyable
\r
42 spl::shared_ptr<core::frame_producer> flash_producer_;
\r
44 impl(const spl::shared_ptr<core::frame_producer>& frame_producer)
\r
45 : flash_producer_(frame_producer)
\r
48 boost::unique_future<std::wstring> add(int layer, std::wstring filename, bool play_on_load, const std::wstring& label, const std::wstring& data)
\r
50 if(filename.size() > 0 && filename[0] == L'/')
\r
51 filename = filename.substr(1, filename.size()-1);
\r
53 if(boost::filesystem::wpath(filename).extension() == L"")
\r
56 auto str = (boost::wformat(L"<invoke name=\"Add\" returntype=\"xml\"><arguments><number>%1%</number><string>%2%</string>%3%<string>%4%</string><string><![CDATA[%5%]]></string></arguments></invoke>") % layer % filename % (play_on_load?L"<true/>":L"<false/>") % label % data).str();
\r
58 CASPAR_LOG(info) << flash_producer_->print() << " Invoking add-command: " << str;
\r
59 return flash_producer_->call(str);
\r
62 boost::unique_future<std::wstring> remove(int layer)
\r
64 auto str = (boost::wformat(L"<invoke name=\"Delete\" returntype=\"xml\"><arguments><array><property id=\"0\"><number>%1%</number></property></array></arguments></invoke>") % layer).str();
\r
65 CASPAR_LOG(info) << flash_producer_->print() << " Invoking remove-command: " << str;
\r
66 return flash_producer_->call(str);
\r
69 boost::unique_future<std::wstring> play(int layer)
\r
71 auto str = (boost::wformat(L"<invoke name=\"Play\" returntype=\"xml\"><arguments><array><property id=\"0\"><number>%1%</number></property></array></arguments></invoke>") % layer).str();
\r
72 CASPAR_LOG(info) << flash_producer_->print() << " Invoking play-command: " << str;
\r
73 return flash_producer_->call(str);
\r
76 boost::unique_future<std::wstring> stop(int layer, unsigned int)
\r
78 auto str = (boost::wformat(L"<invoke name=\"Stop\" returntype=\"xml\"><arguments><array><property id=\"0\"><number>%1%</number></property></array><number>0</number></arguments></invoke>") % layer).str();
\r
79 CASPAR_LOG(info) << flash_producer_->print() << " Invoking stop-command: " << str;
\r
80 return flash_producer_->call(str);
\r
83 boost::unique_future<std::wstring> next(int layer)
\r
85 auto str = (boost::wformat(L"<invoke name=\"Next\" returntype=\"xml\"><arguments><array><property id=\"0\"><number>%1%</number></property></array></arguments></invoke>") % layer).str();
\r
86 CASPAR_LOG(info) << flash_producer_->print() << " Invoking next-command: " << str;
\r
87 return flash_producer_->call(str);
\r
90 boost::unique_future<std::wstring> update(int layer, const std::wstring& data)
\r
92 auto str = (boost::wformat(L"<invoke name=\"SetData\" returntype=\"xml\"><arguments><array><property id=\"0\"><number>%1%</number></property></array><string><![CDATA[%2%]]></string></arguments></invoke>") % layer % data).str();
\r
93 CASPAR_LOG(info) << flash_producer_->print() <<" Invoking update-command: " << str;
\r
94 return flash_producer_->call(str);
\r
97 boost::unique_future<std::wstring> invoke(int layer, const std::wstring& label)
\r
99 auto str = (boost::wformat(L"<invoke name=\"Invoke\" returntype=\"xml\"><arguments><array><property id=\"0\"><number>%1%</number></property></array><string>%2%</string></arguments></invoke>") % layer % label).str();
\r
100 CASPAR_LOG(info) << flash_producer_->print() << " Invoking invoke-command: " << str;
\r
101 return flash_producer_->call(str);
\r
104 boost::unique_future<std::wstring> description(int layer)
\r
106 auto str = (boost::wformat(L"<invoke name=\"GetDescription\" returntype=\"xml\"><arguments><array><property id=\"0\"><number>%1%</number></property></array></arguments></invoke>") % layer).str();
\r
107 CASPAR_LOG(info) << flash_producer_->print() << " Invoking description-command: " << str;
\r
108 return flash_producer_->call(str);
\r
111 boost::unique_future<std::wstring> template_host_info()
\r
113 auto str = (boost::wformat(L"<invoke name=\"GetInfo\" returntype=\"xml\"><arguments></arguments></invoke>")).str();
\r
114 CASPAR_LOG(info) << flash_producer_->print() << " Invoking info-command: " << str;
\r
115 return flash_producer_->call(str);
\r
118 std::wstring timed_invoke(int layer, const std::wstring& label)
\r
120 auto result = invoke(layer, label);
\r
121 if(result.timed_wait(boost::posix_time::seconds(2)))
\r
122 return result.get();
\r
125 std::wstring timed_description(int layer)
\r
127 auto result = description(layer);
\r
128 if(result.timed_wait(boost::posix_time::seconds(2)))
\r
129 return result.get();
\r
132 std::wstring timed_template_host_info()
\r
134 auto result = template_host_info();
\r
135 if(result.timed_wait(boost::posix_time::seconds(2)))
\r
136 return result.get();
\r
141 cg_proxy create_cg_proxy(const spl::shared_ptr<core::video_channel>& video_channel, int render_layer)
\r
143 auto flash_producer = video_channel->stage().foreground(render_layer).get();
\r
147 if(flash_producer->name() != L"flash")
\r
149 flash_producer = flash::create_producer(video_channel->frame_factory(), video_channel->video_format_desc(), boost::assign::list_of<std::wstring>());
\r
150 video_channel->stage().load(render_layer, flash_producer);
\r
151 video_channel->stage().play(render_layer);
\r
156 CASPAR_LOG_CURRENT_EXCEPTION();
\r
160 return cg_proxy(std::move(flash_producer));
\r
163 spl::shared_ptr<core::frame_producer> create_cg_producer_and_autoplay_file(
\r
164 const spl::shared_ptr<core::frame_factory> frame_factory,
\r
165 const core::video_format_desc& format_desc,
\r
166 const std::vector<std::wstring>& params,
\r
167 const std::wstring& filename)
\r
169 if(!boost::filesystem::exists(filename))
\r
170 return core::frame_producer::empty();
\r
172 boost::filesystem::path path(filename);
\r
173 path = boost::filesystem3::complete(path);
\r
174 auto filename2 = path.wstring();
\r
176 auto flash_producer = flash::create_producer(frame_factory, format_desc, boost::assign::list_of<std::wstring>());
\r
177 auto producer = flash_producer;
\r
178 cg_proxy(producer).add(0, filename2, 1);
\r
183 spl::shared_ptr<core::frame_producer> create_ct_producer(const spl::shared_ptr<core::frame_factory> frame_factory, const core::video_format_desc& format_desc, const std::vector<std::wstring>& params)
\r
185 return create_cg_producer_and_autoplay_file(
\r
186 frame_factory, format_desc, params, env::media_folder() + L"\\" + params[0] + L".ct");
\r
189 spl::shared_ptr<core::frame_producer> create_swf_producer(const spl::shared_ptr<core::frame_factory> frame_factory, const core::video_format_desc& format_desc, const std::vector<std::wstring>& params)
\r
191 return create_cg_producer_and_autoplay_file(
\r
192 frame_factory, format_desc, params, env::media_folder() + L"\\" + params[0] + L".swf");
\r
195 cg_proxy::cg_proxy(const spl::shared_ptr<core::frame_producer>& frame_producer) : impl_(new impl(frame_producer)){}
\r
196 cg_proxy::cg_proxy(cg_proxy&& other) : impl_(std::move(other.impl_)){}
\r
197 void cg_proxy::add(int layer, const std::wstring& template_name, bool play_on_load, const std::wstring& startFromLabel, const std::wstring& data){impl_->add(layer, template_name, play_on_load, startFromLabel, data);}
\r
198 void cg_proxy::remove(int layer){impl_->remove(layer);}
\r
199 void cg_proxy::play(int layer){impl_->play(layer);}
\r
200 void cg_proxy::stop(int layer, unsigned int mix_out_duration){impl_->stop(layer, mix_out_duration);}
\r
201 void cg_proxy::next(int layer){impl_->next(layer);}
\r
202 void cg_proxy::update(int layer, const std::wstring& data){impl_->update(layer, data);}
\r
203 std::wstring cg_proxy::invoke(int layer, const std::wstring& label){return impl_->timed_invoke(layer, label);}
\r
204 std::wstring cg_proxy::description(int layer){return impl_->timed_description(layer);}
\r
205 std::wstring cg_proxy::template_host_info(){return impl_->timed_template_host_info();}
\r