]> git.sesse.net Git - casparcg/blob - core/producer/scene/scene_cg_proxy.cpp
a741aae5e95271c240350c4c3eb3c496ced6b182
[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 <core/producer/frame_producer.h>
27
28 #include <boost/property_tree/ptree.hpp>
29 #include <boost/property_tree/xml_parser.hpp>
30
31 #include <sstream>
32 #include <future>
33
34 namespace caspar { namespace core { namespace scene {
35
36 struct scene_cg_proxy::impl
37 {
38         spl::shared_ptr<frame_producer> producer_;
39
40         impl(spl::shared_ptr<frame_producer> producer)
41                 : producer_(std::move(producer))
42         {
43         }
44 };
45
46 scene_cg_proxy::scene_cg_proxy(spl::shared_ptr<frame_producer> producer)
47         : impl_(new impl(std::move(producer)))
48 {
49 }
50
51 void scene_cg_proxy::add(
52                 int layer,
53                 const std::wstring& template_name,
54                 bool play_on_load,
55                 const std::wstring& start_from_label,
56                 const std::wstring& data)
57 {
58         update(layer, data);
59
60         if (play_on_load)
61                 play(layer);
62 }
63
64 void scene_cg_proxy::remove(int layer)
65 {
66         impl_->producer_->call({ L"remove()" });
67 }
68
69 void scene_cg_proxy::play(int layer)
70 {
71         impl_->producer_->call({ L"play()", L"intro" });
72 }
73
74 void scene_cg_proxy::stop(int layer, unsigned int mix_out_duration)
75 {
76         impl_->producer_->call({ L"play()", L"outro" });
77 }
78
79 void scene_cg_proxy::next(int layer)
80 {
81         impl_->producer_->call({ L"next()" });
82 }
83
84 void scene_cg_proxy::update(int layer, const std::wstring& data)
85 {
86         if (data.empty())
87                 return;
88
89         std::wstringstream stream(data);
90         boost::property_tree::wptree root;
91         boost::property_tree::read_xml(
92                         stream,
93                         root,
94                         boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
95
96         std::vector<std::wstring> parameters;
97
98         for (auto value : root.get_child(L"templateData"))
99         {
100                 auto id = value.second.get<std::wstring>(L"<xmlattr>.id");
101                 auto val = value.second.get<std::wstring>(L"data.<xmlattr>.value");
102
103                 parameters.push_back(std::move(id));
104                 parameters.push_back(std::move(val));
105         }
106
107         impl_->producer_->call(parameters);
108 }
109
110 std::wstring scene_cg_proxy::invoke(int layer, const std::wstring& label)
111 {
112         if (boost::ends_with(label, L")"))
113                 return impl_->producer_->call({ L"play()", label.substr(0, label.find(L"(")) }).get();
114         else
115                 return impl_->producer_->call({ L"play()", label }).get();
116 }
117
118 std::wstring scene_cg_proxy::description(int layer)
119 {
120         return L"<scene producer />";
121 }
122
123 std::wstring scene_cg_proxy::template_host_info()
124 {
125         return L"<scene producer />";
126 }
127
128 }}}