From: ronag Date: Sun, 12 Feb 2012 14:33:41 +0000 (+0000) Subject: 2.1.0: -frame_producer: Refactored last_frame. X-Git-Tag: 2.1.0_Beta1~840 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=c10279387895a1a0e18ea1d089ccd9f2a4bbd44c;p=casparcg 2.1.0: -frame_producer: Refactored last_frame. git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.1.0@2372 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- diff --git a/core/producer/color/color_producer.cpp b/core/producer/color/color_producer.cpp index 6b6c2188f..26b9d35d5 100644 --- a/core/producer/color/color_producer.cpp +++ b/core/producer/color/color_producer.cpp @@ -54,12 +54,7 @@ public: { return frame_; } - - virtual spl::shared_ptr last_frame() const override - { - return frame_; - } - + virtual std::wstring print() const override { return L"color[" + color_str_ + L"]"; diff --git a/core/producer/frame_producer.cpp b/core/producer/frame_producer.cpp index 0557e2e74..2b0a295fb 100644 --- a/core/producer/frame_producer.cpp +++ b/core/producer/frame_producer.cpp @@ -44,6 +44,11 @@ void register_producer_factory(const producer_factory_t& factory) g_factories.push_back(factory); } +spl::shared_ptr frame_producer::last_frame() const +{ + BOOST_THROW_EXCEPTION(not_implemented()); +} + boost::unique_future frame_producer::call(const std::wstring&) { BOOST_THROW_EXCEPTION(not_supported()); @@ -90,60 +95,12 @@ public: virtual std::wstring name() const override {return producer_->name();} virtual boost::property_tree::wptree info() const override {return producer_->info();} virtual boost::unique_future call(const std::wstring& str) override {return producer_->call(str);} - virtual spl::shared_ptr following_producer() const override {return producer_->following_producer();} - virtual void leading_producer(const spl::shared_ptr& producer) override {return producer_->leading_producer(producer);} + virtual void leading_producer(const spl::shared_ptr& producer) override {return producer_->leading_producer(producer);} virtual uint32_t nb_frames() const override {return producer_->nb_frames();} virtual void subscribe(const monitor::observable::observer_ptr& o) {return producer_->subscribe(o);} virtual void unsubscribe(const monitor::observable::observer_ptr& o) {return producer_->unsubscribe(o);} }; -class follow_producer_proxy : public producer_proxy_base -{ - monitor::basic_subject event_subject_; -public: - follow_producer_proxy(spl::shared_ptr&& producer) - : producer_proxy_base(std::move(producer)) - { - producer->subscribe(event_subject_); - } - - virtual spl::shared_ptr receive(int hints) override - { - auto frame = producer_->receive(hints); - if(frame == draw_frame::eof()) - { - CASPAR_LOG(info) << producer_->print() << " End Of File."; - auto following = producer_->following_producer(); - if(following != frame_producer::empty()) - { - following->leading_producer(spl::make_shared_ptr(producer_)); - - producer_->unsubscribe(event_subject_); - producer_ = std::move(following); - producer_->subscribe(event_subject_); - } - - return receive(hints); - } - return frame; - } - - virtual spl::shared_ptr last_frame() const override - { - return draw_frame::mute(producer_->last_frame()); - } - - virtual void subscribe(const monitor::observable::observer_ptr& o) override - { - event_subject_.subscribe(o); - } - - virtual void unsubscribe(const monitor::observable::observer_ptr& o) override - { - event_subject_.unsubscribe(o); - } -}; - class destroy_producer_proxy : public producer_proxy_base { public: @@ -198,12 +155,32 @@ public: } }; +class last_frame_producer_proxy : public producer_proxy_base +{ +public: + last_frame_producer_proxy(spl::shared_ptr&& producer) + : producer_proxy_base(std::move(producer)) + , last_frame_(draw_frame::empty()) + { + CASPAR_LOG(info) << producer_->print() << L" Initialized."; + } + + virtual spl::shared_ptr receive(int hints) override + { + return last_frame_ = producer_->receive(hints); + } + + virtual spl::shared_ptr last_frame() const override + { + return last_frame_; + } +}; + spl::shared_ptr wrap_producer(spl::shared_ptr producer) { - return spl::make_shared( - spl::make_shared( + return spl::make_shared( spl::make_shared( - std::move(producer)))); + std::move(producer))); } spl::shared_ptr do_create_producer(const spl::shared_ptr& my_frame_factory, const std::vector& params) diff --git a/core/producer/frame_producer.h b/core/producer/frame_producer.h index ab3d24a26..a89bbd301 100644 --- a/core/producer/frame_producer.h +++ b/core/producer/frame_producer.h @@ -64,13 +64,12 @@ struct frame_producer : public monitor::observable virtual boost::unique_future call(const std::wstring&); - virtual spl::shared_ptr following_producer() const {return frame_producer::empty();} // nothrow virtual void leading_producer(const spl::shared_ptr&) {} // nothrow virtual uint32_t nb_frames() const {return std::numeric_limits::max();} virtual spl::shared_ptr receive(int fBlags) = 0; - virtual spl::shared_ptr last_frame() const = 0; + virtual spl::shared_ptr last_frame() const; static const spl::shared_ptr& empty(); // nothrow diff --git a/core/producer/layer.cpp b/core/producer/layer.cpp index 55bd73230..9c79e6661 100644 --- a/core/producer/layer.cpp +++ b/core/producer/layer.cpp @@ -119,12 +119,19 @@ public: try { if(is_paused_) - return draw_frame::mute(foreground_->last_frame()); + return foreground_->last_frame(); auto frame = foreground_->receive(flags.value()); + if(frame == core::draw_frame::late()) return foreground_->last_frame(); + if(frame == core::draw_frame::eof()) + { + stop(); + return core::draw_frame::empty(); + } + ++frame_number_; if(auto_play_delta_) diff --git a/core/producer/separated/separated_producer.cpp b/core/producer/separated/separated_producer.cpp index 5774fd43e..ee845c74d 100644 --- a/core/producer/separated/separated_producer.cpp +++ b/core/producer/separated/separated_producer.cpp @@ -36,14 +36,12 @@ struct separated_producer : public frame_producer spl::shared_ptr key_producer_; spl::shared_ptr fill_; spl::shared_ptr key_; - spl::shared_ptr last_frame_; explicit separated_producer(const spl::shared_ptr& fill, const spl::shared_ptr& key) : fill_producer_(fill) , key_producer_(key) , fill_(core::draw_frame::late()) , key_(core::draw_frame::late()) - , last_frame_(core::draw_frame::empty()) { } @@ -74,14 +72,9 @@ struct separated_producer : public frame_producer fill_ = draw_frame::late(); key_ = draw_frame::late(); - return last_frame_ = frame; + return frame; } - - virtual spl::shared_ptr last_frame() const override - { - return last_frame_; - } - + virtual uint32_t nb_frames() const override { return std::min(fill_producer_->nb_frames(), key_producer_->nb_frames()); diff --git a/core/producer/transition/transition_producer.cpp b/core/producer/transition/transition_producer.cpp index 9d6176f54..eaac208da 100644 --- a/core/producer/transition/transition_producer.cpp +++ b/core/producer/transition/transition_producer.cpp @@ -42,8 +42,6 @@ struct transition_producer : public frame_producer spl::shared_ptr dest_producer_; spl::shared_ptr source_producer_; - - spl::shared_ptr last_frame_; explicit transition_producer(const field_mode& mode, const spl::shared_ptr& dest, const transition_info& info) : mode_(mode) @@ -51,18 +49,12 @@ struct transition_producer : public frame_producer , info_(info) , dest_producer_(dest) , source_producer_(frame_producer::empty()) - , last_frame_(draw_frame::empty()) { dest->subscribe(event_subject_); } // frame_producer - - virtual spl::shared_ptr following_producer() const override - { - return dest_producer_; - } - + virtual void leading_producer(const spl::shared_ptr& producer) override { source_producer_ = producer; @@ -70,9 +62,11 @@ struct transition_producer : public frame_producer virtual spl::shared_ptr receive(int flags) override { - if(++current_frame_ >= info_.duration) - return draw_frame::eof(); + if(current_frame_ >= info_.duration) + return dest_producer_->receive(flags); + ++current_frame_; + event_subject_ << monitor::event("transition/frame") % current_frame_ % info_.duration << monitor::event("transition/type") % [&]() -> std::string { @@ -106,15 +100,10 @@ struct transition_producer : public frame_producer return compose(dest, source); } - - virtual spl::shared_ptr last_frame() const override - { - return last_frame_; - } - + virtual uint32_t nb_frames() const override { - return following_producer()->nb_frames(); + return dest_producer_->nb_frames(); } virtual std::wstring print() const override @@ -188,8 +177,6 @@ struct transition_producer : public frame_producer const auto s_frame = s_frame1->get_frame_transform() == s_frame2->get_frame_transform() ? s_frame2 : draw_frame::interlace(s_frame1, s_frame2, mode_); const auto d_frame = d_frame1->get_frame_transform() == d_frame2->get_frame_transform() ? d_frame2 : draw_frame::interlace(d_frame1, d_frame2, mode_); - last_frame_ = draw_frame::over(s_frame2, d_frame2); - return draw_frame::over(s_frame, d_frame); } diff --git a/modules/decklink/producer/decklink_producer.cpp b/modules/decklink/producer/decklink_producer.cpp index bf30599ed..e634ee57e 100644 --- a/modules/decklink/producer/decklink_producer.cpp +++ b/modules/decklink/producer/decklink_producer.cpp @@ -269,14 +269,12 @@ public: class decklink_producer_proxy : public core::frame_producer { - spl::shared_ptr last_frame_; std::unique_ptr producer_; const uint32_t length_; executor executor_; public: explicit decklink_producer_proxy(const spl::shared_ptr& frame_factory, const core::video_format_desc& format_desc, size_t device_index, const std::wstring& filter_str, uint32_t length) : executor_(L"decklink_producer[" + boost::lexical_cast(device_index) + L"]") - , last_frame_(core::draw_frame::empty()) , length_(length) { executor_.invoke([=] @@ -299,17 +297,9 @@ public: virtual spl::shared_ptr receive(int flags) override { - auto frame = producer_->get_frame(flags); - if(frame != core::draw_frame::late()) - last_frame_ = frame; - return frame; - } - - virtual spl::shared_ptr last_frame() const override - { - return last_frame_; + return producer_->get_frame(flags); } - + virtual uint32_t nb_frames() const override { return length_; diff --git a/modules/ffmpeg/producer/ffmpeg_producer.cpp b/modules/ffmpeg/producer/ffmpeg_producer.cpp index 2e32a1ae8..919011fc2 100644 --- a/modules/ffmpeg/producer/ffmpeg_producer.cpp +++ b/modules/ffmpeg/producer/ffmpeg_producer.cpp @@ -81,9 +81,7 @@ struct ffmpeg_producer : public core::frame_producer const double fps_; const uint32_t start_; const uint32_t length_; - - spl::shared_ptr last_frame_; - + int64_t frame_number_; public: @@ -95,7 +93,6 @@ public: , fps_(read_fps(*input_.context(), format_desc_.fps)) , start_(start) , length_(length) - , last_frame_(core::draw_frame::empty()) , frame_number_(0) { graph_->set_color("frame-time", diagnostics::color(0.1f, 1.0f, 0.1f)); @@ -163,21 +160,16 @@ public: { if(!input_.eof()) graph_->set_tag("underflow"); - return last_frame(); + return core::draw_frame::late(); } ++frame_number_; graph_->set_text(print()); - return last_frame_ = spl::make_shared_ptr(frame); - } - - virtual spl::shared_ptr last_frame() const override - { - return core::draw_frame::mute(last_frame_); + return spl::make_shared_ptr(frame); } - + virtual uint32_t nb_frames() const override { if(input_.loop()) diff --git a/modules/flash/producer/flash_producer.cpp b/modules/flash/producer/flash_producer.cpp index a1ba140c0..26b95aae3 100644 --- a/modules/flash/producer/flash_producer.cpp +++ b/modules/flash/producer/flash_producer.cpp @@ -332,10 +332,7 @@ struct flash_producer : public core::frame_producer std::queue> frame_buffer_; tbb::concurrent_bounded_queue> output_buffer_; - - spl::shared_ptr last_frame_; - mutable tbb::spin_mutex last_frame_mutex_; - + std::unique_ptr renderer_; executor executor_; @@ -346,7 +343,6 @@ public: , width_(width > 0 ? width : frame_factory->video_format_desc().width) , height_(height > 0 ? height : frame_factory->video_format_desc().height) , buffer_size_(env::properties().get(L"configuration.flash.buffer-depth", frame_factory_->video_format_desc().fps > 30.0 ? 4 : 2)) - , last_frame_(core::draw_frame::empty()) , executor_(L"flash_producer") { sync_ = true; @@ -382,14 +378,6 @@ public: return frame; } - - virtual spl::shared_ptr last_frame() const override - { - return lock(last_frame_mutex_, [this] - { - return last_frame_; - }); - } virtual boost::unique_future call(const std::wstring& param) override { @@ -435,15 +423,7 @@ public: } // flash_producer - - spl::shared_ptr render() - { - return lock(last_frame_mutex_, [this] - { - return last_frame_ = renderer_->render(); - }); - } - + void tick() { renderer_->tick(sync_); @@ -459,13 +439,13 @@ public: auto format_desc = frame_factory_->video_format_desc(); tick(); - auto frame = render(); + auto frame = renderer_->render(); if(abs(renderer_->fps()/2.0 - format_desc.fps) < 2.0) // flash == 2 * format -> interlace { tick(); if(format_desc.field_mode != core::field_mode::progressive) - frame = core::draw_frame::interlace(frame, render(), format_desc.field_mode); + frame = core::draw_frame::interlace(frame, renderer_->render(), format_desc.field_mode); frame_buffer_.push(frame); } diff --git a/modules/image/producer/image_producer.cpp b/modules/image/producer/image_producer.cpp index 09068e0f5..fa5b516d8 100644 --- a/modules/image/producer/image_producer.cpp +++ b/modules/image/producer/image_producer.cpp @@ -70,11 +70,6 @@ struct image_producer : public core::frame_producer return frame_; } - virtual spl::shared_ptr last_frame() const override - { - return frame_; - } - virtual std::wstring print() const override { return L"image_producer[" + filename_ + L"]"; diff --git a/modules/image/producer/image_scroll_producer.cpp b/modules/image/producer/image_scroll_producer.cpp index 8f9869e03..aa297c32f 100644 --- a/modules/image/producer/image_scroll_producer.cpp +++ b/modules/image/producer/image_scroll_producer.cpp @@ -50,25 +50,22 @@ namespace caspar { namespace image { struct image_scroll_producer : public core::frame_producer { - const std::wstring filename_; + const std::wstring filename_; std::vector> frames_; - core::video_format_desc format_desc_; - int width_; - int height_; + core::video_format_desc format_desc_; + int width_; + int height_; - int delta_; - int speed_; + int delta_; + int speed_; - std::array start_offset_; + std::array start_offset_; - spl::shared_ptr last_frame_; - explicit image_scroll_producer(const spl::shared_ptr& frame_factory, const std::wstring& filename, int speed) : filename_(filename) , delta_(0) , format_desc_(frame_factory->video_format_desc()) , speed_(speed) - , last_frame_(core::draw_frame::empty()) { start_offset_.assign(0.0); @@ -188,14 +185,9 @@ struct image_scroll_producer : public core::frame_producer } } - return last_frame_ = spl::make_shared(frames_); - } - - virtual spl::shared_ptr last_frame() const override - { - return last_frame_; + return spl::make_shared(frames_); } - + virtual std::wstring print() const override { return L"image_scroll_producer[" + filename_ + L"]"; diff --git a/modules/reroute/producer/reroute_producer.cpp b/modules/reroute/producer/reroute_producer.cpp index b821181e0..d2a7823c6 100644 --- a/modules/reroute/producer/reroute_producer.cpp +++ b/modules/reroute/producer/reroute_producer.cpp @@ -52,15 +52,13 @@ class reroute_producer : public reactive::observer graph_; const spl::shared_ptr frame_factory_; - tbb::concurrent_bounded_queue> input_buffer_; + tbb::concurrent_bounded_queue> input_buffer_; std::queue> frame_buffer_; - spl::shared_ptr last_frame_; - uint64_t frame_number_; + uint64_t frame_number_; public: explicit reroute_producer(const spl::shared_ptr& frame_factory) : frame_factory_(frame_factory) - , last_frame_(core::draw_frame::empty()) , frame_number_(0) { graph_->set_color("late-frame", diagnostics::color(0.6f, 0.3f, 0.3f)); @@ -87,7 +85,7 @@ public: { auto frame = frame_buffer_.front(); frame_buffer_.pop(); - return last_frame_ = frame; + return frame; } std::shared_ptr read_frame; @@ -117,12 +115,7 @@ public: return receive(0); } - - virtual spl::shared_ptr last_frame() const override - { - return last_frame_; - } - + virtual std::wstring print() const override { return L"reroute[]"; diff --git a/shell/casparcg.config b/shell/casparcg.config index e49f87cc9..823e3884c 100644 --- a/shell/casparcg.config +++ b/shell/casparcg.config @@ -7,7 +7,7 @@ D:\casparcg\_templates\ trace - cpu + auto PAL