X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fflash%2Fproducer%2Fcg_producer.cpp;h=f3dbadcaf1c1a49669140dc243bd24f93949a4ae;hb=c4647c09f2092df9a71635d5866da89dce3a4fef;hp=39461dd655fb25bcd7e12f4a9982836e5f82c85d;hpb=52b74f3c499e70dc74e9f926b4783968b012cd37;p=casparcg diff --git a/modules/flash/producer/cg_producer.cpp b/modules/flash/producer/cg_producer.cpp index 39461dd65..f3dbadcaf 100644 --- a/modules/flash/producer/cg_producer.cpp +++ b/modules/flash/producer/cg_producer.cpp @@ -19,78 +19,90 @@ */ #include "../StdAfx.h" -#include - #include "cg_producer.h" #include "flash_producer.h" -#include -#include +#include -#include +#include -using boost::format; -using boost::io::group; +#include +#include +#include -namespace caspar { +namespace caspar { namespace flash { struct cg_producer::implementation : boost::noncopyable { - safe_ptr frame_factory_; safe_ptr flash_producer_; public: - implementation(const safe_ptr& frame_factory) - : frame_factory_(frame_factory) - , flash_producer_(create_flash_producer(frame_factory_, boost::assign::list_of(env::template_host()))) + implementation(const safe_ptr& frame_producer) + : flash_producer_(frame_producer) {} - void add(int layer, const std::wstring& filename, bool play_on_load, const std::wstring& label, const std::wstring& data) + void add(int layer, std::wstring filename, bool play_on_load, const std::wstring& label, const std::wstring& data) { - CASPAR_LOG(info) << flash_producer_->print() << " Invoking add-command"; - flash_producer_->param((boost::wformat(L"%1%%2%%3%%4%") % layer % filename % (play_on_load?TEXT(""):TEXT("")) % label % data).str()); + if(filename.size() > 0 && filename[0] == L'/') + filename = filename.substr(1, filename.size()-1); + + auto str = (boost::wformat(L"%1%%2%%3%%4%") % layer % filename % (play_on_load?TEXT(""):TEXT("")) % label % data).str(); + + CASPAR_LOG(info) << flash_producer_->print() << " Invoking add-command:" << str; + flash_producer_->param(str); } void remove(int layer) { - CASPAR_LOG(info) << flash_producer_->print() << " Invoking remove-command"; - flash_producer_->param((boost::wformat(L"%1%") % layer).str()); + auto str = (boost::wformat(L"%1%") % layer).str(); + CASPAR_LOG(info) << flash_producer_->print() << " Invoking remove-command:" << str; + flash_producer_->param(str); } void play(int layer) { - CASPAR_LOG(info) << flash_producer_->print() << " Invoking play-command"; - flash_producer_->param((boost::wformat(L"%1%") % layer).str()); + auto str = (boost::wformat(L"%1%") % layer).str(); + CASPAR_LOG(info) << flash_producer_->print() << " Invoking play-command: " << str; + flash_producer_->param(str); } void stop(int layer, unsigned int) { - CASPAR_LOG(info) << flash_producer_->print() << " Invoking stop-command"; - flash_producer_->param((boost::wformat(L"%1%0") % layer).str()); + auto str = (boost::wformat(L"%1%0") % layer).str(); + CASPAR_LOG(info) << flash_producer_->print() << " Invoking stop-command:" << str; + flash_producer_->param(str); } void next(int layer) { - CASPAR_LOG(info) << flash_producer_->print() << " Invoking next-command"; - flash_producer_->param((boost::wformat(L"%1%") % layer).str()); + auto str = (boost::wformat(L"%1%") % layer).str(); + CASPAR_LOG(info) << flash_producer_->print() << " Invoking next-command:" << str; + flash_producer_->param(str); } void update(int layer, const std::wstring& data) { - CASPAR_LOG(info) << flash_producer_->print() <<" Invoking update-command"; - flash_producer_->param((boost::wformat(L"%1%") % layer % data).str()); + auto str = (boost::wformat(L"%1%") % layer % data).str(); + CASPAR_LOG(info) << flash_producer_->print() <<" Invoking update-command:" << str; + flash_producer_->param(str); } void invoke(int layer, const std::wstring& label) { - CASPAR_LOG(info) << flash_producer_->print() << " Invoking invoke-command"; - flash_producer_->param((boost::wformat(L"%1%%2%") % layer % label).str()); + auto str = (boost::wformat(L"%1%%2%") % layer % label).str(); + CASPAR_LOG(info) << flash_producer_->print() << " Invoking invoke-command: " << str; + flash_producer_->param(str); } - safe_ptr receive() + virtual safe_ptr receive(int hints) { - return flash_producer_->receive(); + return flash_producer_->receive(hints); } + + virtual safe_ptr last_frame() const + { + return flash_producer_->last_frame(); + } std::wstring print() const { @@ -98,20 +110,18 @@ public: } }; -safe_ptr get_default_cg_producer(const safe_ptr& channel, int render_layer) +safe_ptr get_default_cg_producer(const safe_ptr& video_channel, int render_layer) { - try - { - return dynamic_pointer_cast(channel->producer()->foreground(render_layer).get()); - } - catch(std::bad_cast&) + auto flash_producer = video_channel->stage()->foreground(render_layer); + + if(flash_producer->print().find(L"flash[") == std::string::npos) // UGLY hack { - safe_ptr factory = channel->mixer(); - auto producer = make_safe(factory); - channel->producer()->load(render_layer, producer, true); - channel->producer()->play(render_layer); - return producer; + flash_producer = flash::create_producer(video_channel->mixer(), boost::assign::list_of()); + video_channel->stage()->load(render_layer, flash_producer); + video_channel->stage()->play(render_layer); } + + return make_safe(flash_producer); } safe_ptr create_ct_producer(const safe_ptr frame_factory, const std::vector& params) @@ -119,16 +129,22 @@ safe_ptr create_ct_producer(const safe_ptr(frame_factory); + auto flash_producer = flash::create_producer(frame_factory, boost::assign::list_of()); + auto producer = make_safe(flash_producer); producer->add(0, filename, 1); return producer; } -cg_producer::cg_producer(const safe_ptr& frame_factory) : impl_(new implementation(frame_factory)){} +cg_producer::cg_producer(const safe_ptr& frame_producer) : impl_(new implementation(frame_producer)){} cg_producer::cg_producer(cg_producer&& other) : impl_(std::move(other.impl_)){} -safe_ptr cg_producer::receive(){return impl_->receive();} +safe_ptr cg_producer::receive(int hints){return impl_->receive(hints);} +safe_ptr cg_producer::last_frame() const{return impl_->last_frame();} 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);} void cg_producer::remove(int layer){impl_->remove(layer);} void cg_producer::play(int layer){impl_->play(layer);} @@ -138,4 +154,4 @@ void cg_producer::update(int layer, const std::wstring& data){impl_->update(laye void cg_producer::invoke(int layer, const std::wstring& label){impl_->invoke(layer, label);} std::wstring cg_producer::print() const{return impl_->print();} -} \ No newline at end of file +}} \ No newline at end of file