2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\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
20 #include "../StdAfx.h"
\r
22 #include "cg_producer.h"
\r
24 #include "flash_producer.h"
\r
26 #include <common/env.h>
\r
28 #include <boost/filesystem.hpp>
\r
29 #include <boost/format.hpp>
\r
33 struct cg_producer::implementation : boost::noncopyable
\r
35 safe_ptr<core::frame_producer> flash_producer_;
\r
37 implementation(const safe_ptr<core::frame_producer>& frame_producer)
\r
38 : flash_producer_(frame_producer)
\r
41 void add(int layer, const std::wstring& filename, bool play_on_load, const std::wstring& label, const std::wstring& data)
\r
43 CASPAR_LOG(info) << flash_producer_->print() << " Invoking add-command";
\r
44 flash_producer_->param((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?TEXT("<true/>"):TEXT("<false/>")) % label % data).str());
\r
47 void remove(int layer)
\r
49 CASPAR_LOG(info) << flash_producer_->print() << " Invoking remove-command";
\r
50 flash_producer_->param((boost::wformat(L"<invoke name=\"Delete\" returntype=\"xml\"><arguments><array><property id=\"0\"><number>%1%</number></property></array></arguments></invoke>") % layer).str());
\r
53 void play(int layer)
\r
55 CASPAR_LOG(info) << flash_producer_->print() << " Invoking play-command";
\r
56 flash_producer_->param((boost::wformat(L"<invoke name=\"Play\" returntype=\"xml\"><arguments><array><property id=\"0\"><number>%1%</number></property></array></arguments></invoke>") % layer).str());
\r
59 void stop(int layer, unsigned int)
\r
61 CASPAR_LOG(info) << flash_producer_->print() << " Invoking stop-command";
\r
62 flash_producer_->param((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
65 void next(int layer)
\r
67 CASPAR_LOG(info) << flash_producer_->print() << " Invoking next-command";
\r
68 flash_producer_->param((boost::wformat(L"<invoke name=\"Next\" returntype=\"xml\"><arguments><array><property id=\"0\"><number>%1%</number></property></array></arguments></invoke>") % layer).str());
\r
71 void update(int layer, const std::wstring& data)
\r
73 CASPAR_LOG(info) << flash_producer_->print() <<" Invoking update-command";
\r
74 flash_producer_->param((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
77 void invoke(int layer, const std::wstring& label)
\r
79 CASPAR_LOG(info) << flash_producer_->print() << " Invoking invoke-command";
\r
80 flash_producer_->param((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
83 safe_ptr<core::basic_frame> receive()
\r
85 return flash_producer_->receive();
\r
88 std::wstring print() const
\r
90 return flash_producer_->print();
\r
94 safe_ptr<cg_producer> get_default_cg_producer(const safe_ptr<core::channel>& channel, int render_layer)
\r
96 auto flash_producer = channel->producer()->foreground(render_layer).get();
\r
98 if(flash_producer->print().find(L"flash") == std::string::npos)
\r
100 flash_producer = create_flash_producer(channel->mixer(), boost::assign::list_of(env::template_host()));
\r
101 channel->producer()->load(render_layer, flash_producer, true);
\r
102 channel->producer()->play(render_layer);
\r
105 return make_safe<cg_producer>(flash_producer);
\r
108 safe_ptr<core::frame_producer> create_ct_producer(const safe_ptr<core::frame_factory> frame_factory, const std::vector<std::wstring>& params)
\r
110 std::wstring filename = env::media_folder() + L"\\" + params[0] + L".ct";
\r
111 if(!boost::filesystem::exists(filename))
\r
112 return core::frame_producer::empty();
\r
114 auto flash_producer = create_flash_producer(frame_factory, boost::assign::list_of(env::template_host()));
\r
115 auto producer = make_safe<cg_producer>(flash_producer);
\r
116 producer->add(0, filename, 1);
\r
121 cg_producer::cg_producer(const safe_ptr<core::frame_producer>& frame_producer) : impl_(new implementation(frame_producer)){}
\r
122 cg_producer::cg_producer(cg_producer&& other) : impl_(std::move(other.impl_)){}
\r
123 safe_ptr<core::basic_frame> cg_producer::receive(){return impl_->receive();}
\r
124 void cg_producer::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
125 void cg_producer::remove(int layer){impl_->remove(layer);}
\r
126 void cg_producer::play(int layer){impl_->play(layer);}
\r
127 void cg_producer::stop(int layer, unsigned int mix_out_duration){impl_->stop(layer, mix_out_duration);}
\r
128 void cg_producer::next(int layer){impl_->next(layer);}
\r
129 void cg_producer::update(int layer, const std::wstring& data){impl_->update(layer, data);}
\r
130 void cg_producer::invoke(int layer, const std::wstring& label){impl_->invoke(layer, label);}
\r
131 std::wstring cg_producer::print() const{return impl_->print();}
\r