]> git.sesse.net Git - casparcg/blobdiff - modules/decklink/consumer/decklink_consumer.cpp
* Created custom decklink allocator for reducing memory footprint.
[casparcg] / modules / decklink / consumer / decklink_consumer.cpp
index 11b6fd7f538c065c82e559f4af73be29e6ed6367..8b30bd2571e3f312a7a4a2087ff72839f402b2dc 100644 (file)
@@ -24,6 +24,7 @@
 #include "decklink_consumer.h"\r
 \r
 #include "../util/util.h"\r
+#include "../util/decklink_allocator.h"\r
 \r
 #include "../interop/DeckLinkAPI_h.h"\r
 \r
@@ -33,6 +34,7 @@
 #include <common/concurrency/future_util.h>\r
 #include <common/diagnostics/graph.h>\r
 #include <common/exception/exceptions.h>\r
+#include <common/exception/win32_exception.h>\r
 #include <common/utility/assert.h>\r
 \r
 #include <core/parameters/parameters.h>\r
 namespace caspar { namespace decklink { \r
 \r
 struct decklink_consumer : public IDeckLinkVideoOutputCallback, public IDeckLinkAudioOutputCallback, boost::noncopyable\r
-{              \r
+{\r
        const int                                                       channel_index_;\r
        const configuration                                     config_;\r
 \r
+       std::unique_ptr<thread_safe_decklink_allocator> allocator_;\r
        CComPtr<IDeckLink>                                      decklink_;\r
        CComQIPtr<IDeckLinkOutput>                      output_;\r
        CComQIPtr<IDeckLinkKeyer>                       keyer_;\r
@@ -172,6 +175,16 @@ public:
 \r
        void enable_video(BMDDisplayMode display_mode)\r
        {\r
+               if (config_.custom_allocator)\r
+               {\r
+                       allocator_.reset(new thread_safe_decklink_allocator(print()));\r
+\r
+                       if (FAILED(output_->SetVideoOutputFrameMemoryAllocator(allocator_.get())))\r
+                               BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Could not set custom memory allocator."));\r
+\r
+                       CASPAR_LOG(info) << print() << L" Using custom allocator.";\r
+               }\r
+\r
                if(FAILED(output_->EnableVideoOutput(display_mode, bmdVideoOutputFlagDefault))) \r
                        BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Could not enable video output."));\r
                \r
@@ -200,6 +213,7 @@ public:
 \r
        STDMETHOD(ScheduledFrameCompleted(IDeckLinkVideoFrame* completed_frame, BMDOutputFrameCompletionResult result))\r
        {\r
+               win32_exception::ensure_handler_installed_for_thread("decklink-ScheduledFrameCompleted");\r
                if(!is_running_)\r
                        return E_FAIL;\r
                \r
@@ -243,6 +257,8 @@ public:
                \r
        STDMETHOD(RenderAudioSamples(BOOL preroll))\r
        {\r
+               win32_exception::ensure_handler_installed_for_thread("decklink-RenderAudioSamples");\r
+\r
                if(!is_running_)\r
                        return E_FAIL;\r
                \r
@@ -510,10 +526,11 @@ safe_ptr<core::frame_consumer> create_consumer(const boost::property_tree::wptre
        else if(latency == L"normal")\r
                config.latency = configuration::normal_latency;\r
 \r
-       config.key_only                         = ptree.get(L"key-only",                config.key_only);\r
-       config.device_index                     = ptree.get(L"device",                  config.device_index);\r
-       config.embedded_audio           = ptree.get(L"embedded-audio",  config.embedded_audio);\r
-       config.base_buffer_depth        = ptree.get(L"buffer-depth",    config.base_buffer_depth);\r
+       config.key_only                         = ptree.get(L"key-only",                        config.key_only);\r
+       config.device_index                     = ptree.get(L"device",                          config.device_index);\r
+       config.embedded_audio           = ptree.get(L"embedded-audio",          config.embedded_audio);\r
+       config.base_buffer_depth        = ptree.get(L"buffer-depth",            config.base_buffer_depth);\r
+       config.custom_allocator         = ptree.get(L"custom-allocator",        config.custom_allocator);\r
        config.audio_layout =\r
                core::default_channel_layout_repository().get_by_name(\r
                                boost::to_upper_copy(ptree.get(L"channel-layout", L"STEREO")));\r