]> git.sesse.net Git - casparcg/blobdiff - modules/decklink/producer/decklink_producer.cpp
* Created custom decklink allocator for reducing memory footprint.
[casparcg] / modules / decklink / producer / decklink_producer.cpp
index d88834d329f65eb7e3fe2b302324144a29975c2a..02a98663d0f95970cd00c6cbeb790eca932c8f3a 100644 (file)
@@ -25,6 +25,7 @@
 \r
 #include "../interop/DeckLinkAPI_h.h"\r
 #include "../util/util.h"\r
+#include "../util/decklink_allocator.h"\r
 \r
 #include "../../ffmpeg/producer/filter/filter.h"\r
 #include "../../ffmpeg/producer/util/util.h"\r
@@ -34,6 +35,7 @@
 #include <common/concurrency/com_context.h>\r
 #include <common/diagnostics/graph.h>\r
 #include <common/exception/exceptions.h>\r
+#include <common/exception/win32_exception.h>\r
 #include <common/log/log.h>\r
 #include <common/memory/memclr.h>\r
 \r
@@ -86,6 +88,7 @@ class decklink_producer : boost::noncopyable, public IDeckLinkInputCallback
        boost::timer                                                                                            tick_timer_;\r
        boost::timer                                                                                            frame_timer_;\r
 \r
+       std::unique_ptr<thread_safe_decklink_allocator>                         allocator_;\r
        CComPtr<IDeckLink>                                                                                      decklink_;\r
        CComQIPtr<IDeckLinkInput>                                                                       input_;\r
        CComQIPtr<IDeckLinkAttributes >                                                         attributes_;\r
@@ -148,7 +151,14 @@ public:
                diagnostics::register_graph(graph_);\r
                \r
                auto display_mode = get_display_mode(input_, format_desc_.format, bmdFormat8BitYUV, bmdVideoInputFlagDefault);\r
-                               \r
+               \r
+               allocator_.reset(new thread_safe_decklink_allocator(print()));\r
+\r
+               if(FAILED(input_->SetVideoInputFrameMemoryAllocator(allocator_.get()))) \r
+                       BOOST_THROW_EXCEPTION(caspar_exception()\r
+                                                                       << msg_info(narrow(print()) + " Could not enable use of custom allocator.")\r
+                                                                       << boost::errinfo_api_function("SetVideoInputFrameMemoryAllocator"));\r
+\r
                // NOTE: bmdFormat8BitARGB is currently not supported by any decklink card. (2011-05-08)\r
                if(FAILED(input_->EnableVideoInput(display_mode, bmdFormat8BitYUV, bmdVideoInputFlagDefault))) \r
                        BOOST_THROW_EXCEPTION(caspar_exception() \r
@@ -191,6 +201,7 @@ public:
 \r
        virtual HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(IDeckLinkVideoInputFrame* video, IDeckLinkAudioInputPacket* audio)\r
        {       \r
+               win32_exception::ensure_handler_installed_for_thread("decklink-VideoInputFrameArrived");\r
                if(!video)\r
                        return S_OK;\r
 \r