X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fproducer%2Fframe_producer.cpp;h=f881d2adbb6d36353912b8cfb8b56b3c12e23335;hb=5bad7c1c1348fe338b748cff8dbc448155d3ae85;hp=7f3c48b22533a072296a5b901b37687c394515e5;hpb=16e844127bffeb26be1c0bd93fda1e745cf21119;p=casparcg diff --git a/core/producer/frame_producer.cpp b/core/producer/frame_producer.cpp index 7f3c48b22..f881d2adb 100644 --- a/core/producer/frame_producer.cpp +++ b/core/producer/frame_producer.cpp @@ -22,82 +22,69 @@ #include "frame_producer.h" #include "frame/basic_frame.h" +#include "frame/frame_transform.h" #include "color/color_producer.h" #include "separated/separated_producer.h" #include +#include namespace caspar { namespace core { std::vector g_factories; -const safe_ptr& frame_producer::empty() // nothrow +class last_frame_producer : public frame_producer { - struct empty_frame_producer : public frame_producer + const std::wstring print_; + const safe_ptr frame_; + const int64_t nb_frames_; +public: + last_frame_producer(const safe_ptr& producer) + : print_(producer->print()) + , frame_(producer->last_frame() != basic_frame::eof() ? producer->last_frame() : basic_frame::empty()) + , nb_frames_(producer->nb_frames()) { - virtual safe_ptr receive(){return basic_frame::empty();} - virtual void set_frame_factory(const safe_ptr&){} - virtual std::wstring print() const { return L"empty";} - }; - static safe_ptr producer = make_safe(); - return producer; -} + } + + virtual safe_ptr receive(int){return frame_;} + virtual safe_ptr last_frame() const{return frame_;} + virtual std::wstring print() const{return L"dummy[" + print_ + L"]";} + virtual int64_t nb_frames() const {return nb_frames_;} +}; -safe_ptr frame_producer::receive_w_last() +struct empty_frame_producer : public frame_producer { - auto frame = receive(); - if(frame != core::basic_frame::late()) - { - last_frame_ = make_safe(frame); - last_frame_->get_audio_transform().set_has_audio(false); - } - return frame; -} + virtual safe_ptr receive(int){return basic_frame::empty();} + virtual safe_ptr last_frame() const{return basic_frame::empty();} + virtual void set_frame_factory(const safe_ptr&){} + virtual int64_t nb_frames() const {return 0;} + virtual std::wstring print() const { return L"empty";} +}; -safe_ptr receive(const safe_ptr& producer) +const safe_ptr& frame_producer::empty() // nothrow { - return producer->receive_w_last(); -} + static safe_ptr producer = make_safe(); + return producer; +} -safe_ptr receive_and_follow(safe_ptr& producer) +safe_ptr receive_and_follow(safe_ptr& producer, int hints) { - if(producer == frame_producer::empty()) - return basic_frame::eof(); - - auto frame = basic_frame::eof(); - try - { - frame = receive(producer); - } - catch(...) - { - try - { - // Producer will be removed since frame == basic_frame::eof. - CASPAR_LOG_CURRENT_EXCEPTION(); - CASPAR_LOG(warning) << producer->print() << " Failed to receive frame. Removing producer."; - } - catch(...){} - } - + auto frame = producer->receive(hints); if(frame == basic_frame::eof()) { CASPAR_LOG(info) << producer->print() << " End Of File."; auto following = producer->get_following_producer(); - following->set_leading_producer(producer); - producer = std::move(following); - - return receive_and_follow(producer); - } - return frame; -} + if(following != frame_producer::empty()) + { + following->set_leading_producer(producer); + producer = std::move(following); + } + else + producer = make_safe(producer); -safe_ptr receive_and_follow_w_last(safe_ptr& producer) -{ - auto frame = receive_and_follow(producer); - if(frame == basic_frame::late()) - frame = producer->last_frame(); + return receive_and_follow(producer, hints); + } return frame; } @@ -127,10 +114,7 @@ safe_ptr do_create_producer(const safe_ptr& if(producer == frame_producer::empty()) producer = create_color_producer(my_frame_factory, params); - - if(producer == frame_producer::empty()) - BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax.")); - + return producer; } @@ -147,12 +131,25 @@ safe_ptr create_producer(const safe_ptr& my { params_copy[0] += L"_A"; key_producer = do_create_producer(my_frame_factory, params_copy); + if(key_producer == frame_producer::empty()) + { + params_copy[0] += L"LPHA"; + key_producer = do_create_producer(my_frame_factory, params_copy); + } } } catch(...){} - if(key_producer != frame_producer::empty()) - return create_separated_producer(producer, key_producer); + if(producer != frame_producer::empty() && key_producer != frame_producer::empty()) + producer = create_separated_producer(producer, key_producer); + + if(producer == frame_producer::empty()) + { + std::wstring str; + BOOST_FOREACH(auto& param, params) + str += param + L" "; + BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax.") << arg_value_info(narrow(str))); + } return producer; }