1 #include "../StdAfx.h"
\r
3 #include <common/env.h>
\r
5 #include "cg_producer.h"
\r
7 #include "flash_producer.h"
\r
9 #include <boost/filesystem.hpp>
\r
10 #include <boost/format.hpp>
\r
12 using boost::format;
\r
13 using boost::io::group;
\r
17 struct cg_producer::implementation : boost::noncopyable
\r
19 printer parent_printer_;
\r
20 safe_ptr<flash_producer> flash_producer_;
\r
21 std::shared_ptr<core::frame_factory> frame_factory_;
\r
24 : flash_producer_(flash_producer(env::template_host())){}
\r
28 flash_producer_ = flash_producer(env::template_host());
\r
29 flash_producer_->set_parent_printer(parent_printer_);
\r
30 flash_producer_->initialize(safe_ptr<core::frame_factory>(frame_factory_));
\r
33 void add(int layer, const std::wstring& filename, bool play_on_load, const std::wstring& label, const std::wstring& data)
\r
35 CASPAR_LOG(info) << print() << " Invoking add-command";
\r
36 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
39 void remove(int layer)
\r
41 CASPAR_LOG(info) << print() << " Invoking remove-command";
\r
42 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
45 void play(int layer)
\r
47 CASPAR_LOG(info) << print() << " Invoking play-command";
\r
48 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
51 void stop(int layer, unsigned int)
\r
53 CASPAR_LOG(info) << print() << " Invoking stop-command";
\r
54 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
57 void next(int layer)
\r
59 CASPAR_LOG(info) << print() << " Invoking next-command";
\r
60 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
63 void update(int layer, const std::wstring& data)
\r
65 CASPAR_LOG(info) << print() <<" Invoking update-command";
\r
66 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
69 void invoke(int layer, const std::wstring& label)
\r
71 CASPAR_LOG(info) << print() << " Invoking invoke-command";
\r
72 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
75 safe_ptr<core::draw_frame> receive()
\r
77 return flash_producer_->receive();
\r
80 void initialize(const safe_ptr<core::frame_factory>& frame_factory)
\r
82 frame_factory_ = frame_factory;
\r
83 flash_producer_->set_parent_printer(parent_printer_);
\r
84 flash_producer_->initialize(frame_factory);
\r
87 void set_parent_printer(const printer& parent_printer)
\r
89 parent_printer_ = parent_printer;
\r
92 std::wstring print() const
\r
94 return flash_producer_->print();
\r
98 safe_ptr<cg_producer> get_default_cg_producer(const safe_ptr<core::channel>& channel, int render_layer)
\r
102 return dynamic_pointer_cast<cg_producer>(channel->producer().foreground(render_layer).get());
\r
104 catch(std::bad_cast&)
\r
106 auto producer = make_safe<cg_producer>();
\r
107 channel->producer().load(render_layer, producer, true);
\r
112 safe_ptr<core::frame_producer> create_ct_producer(const std::vector<std::wstring>& params)
\r
114 std::wstring filename = env::media_folder() + L"\\" + params[0] + L".ct";
\r
115 if(!boost::filesystem::exists(filename))
\r
116 return core::frame_producer::empty();
\r
118 auto producer = make_safe<cg_producer>();
\r
119 producer->add(0, filename, 1);
\r
124 cg_producer::cg_producer() : impl_(new implementation()){}
\r
125 cg_producer::cg_producer(cg_producer&& other) : impl_(std::move(other.impl_)){}
\r
126 safe_ptr<core::draw_frame> cg_producer::receive(){return impl_->receive();}
\r
127 void cg_producer::clear(){impl_->clear();}
\r
128 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
129 void cg_producer::remove(int layer){impl_->remove(layer);}
\r
130 void cg_producer::play(int layer){impl_->play(layer);}
\r
131 void cg_producer::stop(int layer, unsigned int mix_out_duration){impl_->stop(layer, mix_out_duration);}
\r
132 void cg_producer::next(int layer){impl_->next(layer);}
\r
133 void cg_producer::update(int layer, const std::wstring& data){impl_->update(layer, data);}
\r
134 void cg_producer::invoke(int layer, const std::wstring& label){impl_->invoke(layer, label);}
\r
135 void cg_producer::initialize(const safe_ptr<core::frame_factory>& frame_factory){impl_->initialize(frame_factory);}
\r
136 void cg_producer::set_parent_printer(const printer& parent_printer) { impl_->set_parent_printer(parent_printer);}
\r
137 std::wstring cg_producer::print() const{return impl_->print();}
\r