From 6b8b752068674445e735f076ca96588c39e77f5e Mon Sep 17 00:00:00 2001 From: ronag Date: Fri, 26 Aug 2011 13:04:32 +0000 Subject: [PATCH] git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1296 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- .../decklink/consumer/decklink_consumer.cpp | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/modules/decklink/consumer/decklink_consumer.cpp b/modules/decklink/consumer/decklink_consumer.cpp index dce653a55..d0949fd80 100644 --- a/modules/decklink/consumer/decklink_consumer.cpp +++ b/modules/decklink/consumer/decklink_consumer.cpp @@ -65,6 +65,7 @@ struct configuration class decklink_frame : public IDeckLinkVideoFrame { + tbb::atomic ref_count_; std::shared_ptr frame_; const core::video_format_desc format_desc_; @@ -74,11 +75,23 @@ public: decklink_frame(const safe_ptr& frame, const core::video_format_desc& format_desc, bool key_only) : frame_(frame) , format_desc_(format_desc) - , key_only_(key_only){} + , key_only_(key_only) + { + ref_count_ = 0; + } STDMETHOD (QueryInterface(REFIID, LPVOID*)) {return E_NOINTERFACE;} - STDMETHOD_(ULONG, AddRef()) {return 1;} - STDMETHOD_(ULONG, Release()) {return 1;} + STDMETHOD_(ULONG, AddRef()) + { + return ++ref_count_; + } + STDMETHOD_(ULONG, Release()) + { + --ref_count_; + if(ref_count_ == 0) + delete this; + return ref_count_; + } STDMETHOD_(long, GetWidth()) {return format_desc_.width;} STDMETHOD_(long, GetHeight()) {return format_desc_.height;} @@ -138,7 +151,6 @@ struct decklink_consumer : public IDeckLinkVideoOutputCallback, public IDeckLink size_t preroll_count_; - std::list> frame_container_; // Must be std::list in order to guarantee that pointers are always valid. boost::circular_buffer> audio_container_; tbb::concurrent_bounded_queue> video_frame_buffer_; @@ -305,11 +317,6 @@ public: else if(result == bmdOutputFrameFlushed) graph_->add_tag("flushed-frame"); - frame_container_.erase(std::find_if(frame_container_.begin(), frame_container_.end(), [&](const std::shared_ptr& frame) - { - return frame.get() == completed_frame; - })); - std::shared_ptr frame; video_frame_buffer_.pop(frame); schedule_next_video(make_safe(frame)); @@ -370,8 +377,8 @@ public: void schedule_next_video(const safe_ptr& frame) { - frame_container_.push_back(std::make_shared(frame, format_desc_, config_.key_only)); - if(FAILED(output_->ScheduleVideoFrame(frame_container_.back().get(), (frames_scheduled_++) * format_desc_.duration, format_desc_.duration, format_desc_.time_scale))) + CComPtr frame2(new decklink_frame(frame, format_desc_, config_.key_only)); + if(FAILED(output_->ScheduleVideoFrame(frame2, (frames_scheduled_++) * format_desc_.duration, format_desc_.duration, format_desc_.time_scale))) CASPAR_LOG(error) << print() << L" Failed to schedule video."; graph_->update_value("tick-time", tick_timer_.elapsed()*format_desc_.fps*0.5); -- 2.39.2