]> git.sesse.net Git - casparcg/blob - core/producer/scene/scene_cg_proxy.cpp
Started using ptree_get, ptree_get_value, witerate_children and welement_context_iter...
[casparcg] / core / producer / scene / scene_cg_proxy.cpp
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
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.
10 *
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.
15 *
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/>.
18 *
19 * Author: Helge Norberg, helge.norberg@svt.se
20 */
21
22 #include "../../StdAfx.h"
23
24 #include "scene_cg_proxy.h"
25
26 #include <common/ptree.h>
27
28 #include <core/producer/frame_producer.h>
29
30 #include <boost/property_tree/ptree.hpp>
31 #include <boost/property_tree/xml_parser.hpp>
32
33 #include <sstream>
34 #include <future>
35
36 namespace caspar { namespace core { namespace scene {
37
38 struct scene_cg_proxy::impl
39 {
40         spl::shared_ptr<frame_producer> producer_;
41
42         impl(spl::shared_ptr<frame_producer> producer)
43                 : producer_(std::move(producer))
44         {
45         }
46 };
47
48 scene_cg_proxy::scene_cg_proxy(spl::shared_ptr<frame_producer> producer)
49         : impl_(new impl(std::move(producer)))
50 {
51 }
52
53 void scene_cg_proxy::add(
54                 int layer,
55                 const std::wstring& template_name,
56                 bool play_on_load,
57                 const std::wstring& start_from_label,
58                 const std::wstring& data)
59 {
60         update(layer, data);
61
62         if (play_on_load)
63                 play(layer);
64 }
65
66 void scene_cg_proxy::remove(int layer)
67 {
68         impl_->producer_->call({ L"remove()" });
69 }
70
71 void scene_cg_proxy::play(int layer)
72 {
73         impl_->producer_->call({ L"play()", L"intro" });
74 }
75
76 void scene_cg_proxy::stop(int layer, unsigned int mix_out_duration)
77 {
78         impl_->producer_->call({ L"play()", L"outro" });
79 }
80
81 void scene_cg_proxy::next(int layer)
82 {
83         impl_->producer_->call({ L"next()" });
84 }
85
86 void scene_cg_proxy::update(int layer, const std::wstring& data)
87 {
88         if (data.empty())
89                 return;
90
91         std::wstringstream stream(data);
92         boost::property_tree::wptree root;
93         boost::property_tree::read_xml(
94                         stream,
95                         root,
96                         boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
97
98         std::vector<std::wstring> parameters;
99
100         for (auto value : root | witerate_children(L"templateData") | welement_context_iteration)
101         {
102                 ptree_verify_element_name(value, L"componentData");
103
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");
106
107                 parameters.push_back(std::move(id));
108                 parameters.push_back(std::move(val));
109         }
110
111         impl_->producer_->call(parameters);
112 }
113
114 std::wstring scene_cg_proxy::invoke(int layer, const std::wstring& label)
115 {
116         if (boost::ends_with(label, L")"))
117                 return impl_->producer_->call({ L"play()", label.substr(0, label.find(L"(")) }).get();
118         else
119                 return impl_->producer_->call({ L"play()", label }).get();
120 }
121
122 std::wstring scene_cg_proxy::description(int layer)
123 {
124         return L"<scene producer />";
125 }
126
127 std::wstring scene_cg_proxy::template_host_info()
128 {
129         return L"<scene producer />";
130 }
131
132 }}}