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: Helge Norberg, helge.norberg@svt.se
22 #include "../../StdAfx.h"
24 #include "scene_cg_proxy.h"
26 #include <common/ptree.h>
28 #include <core/producer/frame_producer.h>
30 #include <boost/property_tree/ptree.hpp>
31 #include <boost/property_tree/xml_parser.hpp>
36 namespace caspar { namespace core { namespace scene {
38 struct scene_cg_proxy::impl
40 spl::shared_ptr<frame_producer> producer_;
42 impl(spl::shared_ptr<frame_producer> producer)
43 : producer_(std::move(producer))
48 scene_cg_proxy::scene_cg_proxy(spl::shared_ptr<frame_producer> producer)
49 : impl_(new impl(std::move(producer)))
53 void scene_cg_proxy::add(
55 const std::wstring& template_name,
57 const std::wstring& start_from_label,
58 const std::wstring& data)
66 void scene_cg_proxy::remove(int layer)
68 impl_->producer_->call({ L"remove()" });
71 void scene_cg_proxy::play(int layer)
73 impl_->producer_->call({ L"play()", L"intro" });
76 void scene_cg_proxy::stop(int layer, unsigned int mix_out_duration)
78 impl_->producer_->call({ L"play()", L"outro" });
81 void scene_cg_proxy::next(int layer)
83 impl_->producer_->call({ L"next()" });
86 void scene_cg_proxy::update(int layer, const std::wstring& data)
91 std::wstringstream stream(data);
92 boost::property_tree::wptree root;
93 boost::property_tree::read_xml(
96 boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
98 std::vector<std::wstring> parameters;
100 for (auto value : root | witerate_children(L"templateData") | welement_context_iteration)
102 ptree_verify_element_name(value, L"componentData");
104 auto id = ptree_get<std::wstring>(value.second, L"<xmlattr>.id");
105 auto val = ptree_get<std::wstring>(value.second, L"data.<xmlattr>.value");
107 parameters.push_back(std::move(id));
108 parameters.push_back(std::move(val));
111 impl_->producer_->call(parameters);
114 std::wstring scene_cg_proxy::invoke(int layer, const std::wstring& label)
116 if (boost::ends_with(label, L")"))
117 return impl_->producer_->call({ L"play()", label.substr(0, label.find(L"(")) }).get();
119 return impl_->producer_->call({ L"play()", label }).get();
122 std::wstring scene_cg_proxy::description(int layer)
124 return L"<scene producer />";
127 std::wstring scene_cg_proxy::template_host_info()
129 return L"<scene producer />";