]> git.sesse.net Git - casparcg/blobdiff - modules/bluefish/consumer/bluefish_consumer.cpp
2.0. stage: Changed error handling.
[casparcg] / modules / bluefish / consumer / bluefish_consumer.cpp
index ca87f509249c48a46248e50149ea499e0ab65643..d04fc435135519a8bb5a273ae4f0bbf397b3ae6b 100644 (file)
 \r
 #include <common/concurrency/executor.h>\r
 #include <common/diagnostics/graph.h>\r
-#include <common/memory/memcpy.h>\r
 #include <common/memory/memclr.h>\r
+#include <common/memory/memcpy.h>\r
+#include <common/memory/memshfl.h>\r
 #include <common/utility/timer.h>\r
 \r
+#include <core/consumer/frame_consumer.h>\r
+\r
 #include <tbb/concurrent_queue.h>\r
 \r
 #include <boost/timer.hpp>\r
@@ -57,15 +60,16 @@ struct bluefish_consumer : boost::noncopyable
        unsigned int                                            vid_fmt_;\r
 \r
        std::array<blue_dma_buffer_ptr, 4>      reserved_frames_;       \r
-       tbb::concurrent_bounded_queue<std::shared_ptr<const core::read_frame>> frame_buffer_;\r
+       tbb::concurrent_bounded_queue<std::shared_ptr<core::read_frame>> frame_buffer_;\r
 \r
        int                                                                     preroll_count_;\r
 \r
        const bool                                                      embedded_audio_;\r
+       const bool                                                      key_only_;\r
        \r
        executor                                                        executor_;\r
 public:\r
-       bluefish_consumer(const core::video_format_desc& format_desc, unsigned int device_index, bool embedded_audio) \r
+       bluefish_consumer(const core::video_format_desc& format_desc, unsigned int device_index, bool embedded_audio, bool key_only\r
                : blue_(create_blue(device_index))\r
                , device_index_(device_index)\r
                , format_desc_(format_desc) \r
@@ -73,13 +77,14 @@ public:
                , vid_fmt_(get_video_mode(*blue_, format_desc))\r
                , preroll_count_(0)\r
                , embedded_audio_(embedded_audio)\r
+               , key_only_(key_only)\r
                , executor_(print())\r
        {\r
-               executor_.set_capacity(CONSUMER_BUFFER_DEPTH);\r
+               executor_.set_capacity(core::consumer_buffer_depth());\r
 \r
                graph_ = diagnostics::create_graph(narrow(print()));\r
                graph_->add_guide("tick-time", 0.5);\r
-               graph_->set_color("tick-time", diagnostics::color(0.1f, 0.7f, 0.8f));\r
+               graph_->set_color("tick-time", diagnostics::color(0.0f, 0.6f, 0.9f));   \r
                graph_->add_guide("frame-time", 0.5f);  \r
                graph_->set_color("frame-time", diagnostics::color(1.0f, 0.0f, 0.0f));\r
                graph_->set_color("sync-time", diagnostics::color(0.5f, 1.0f, 0.2f));\r
@@ -156,18 +161,18 @@ public:
 \r
        ~bluefish_consumer()\r
        {\r
-               //try\r
-               //{\r
-               //      executor_.invoke([&]\r
-               //      {\r
-               //              disable_video_output();\r
-               //              blue_->device_detach();         \r
-               //      });\r
-               //}\r
-               //catch(...)\r
-               //{\r
-               //      CASPAR_LOG_CURRENT_EXCEPTION();\r
-               //}\r
+               try\r
+               {\r
+                       executor_.invoke([&]\r
+                       {\r
+                               disable_video_output();\r
+                               blue_->device_detach();         \r
+                       });\r
+               }\r
+               catch(...)\r
+               {\r
+                       CASPAR_LOG_CURRENT_EXCEPTION();\r
+               }\r
                \r
                CASPAR_LOG(info) << print() << L" Shutting down.";      \r
        }\r
@@ -189,7 +194,7 @@ public:
                        CASPAR_LOG(error)<< print() << TEXT(" Failed to disable video output.");                \r
        }\r
        \r
-       void send(const safe_ptr<const core::read_frame>& frame)\r
+       void send(const safe_ptr<core::read_frame>& frame)\r
        {       \r
                if(preroll_count_ < executor_.capacity())\r
                {\r
@@ -200,7 +205,7 @@ public:
                schedule_next_video(frame);                     \r
        }\r
        \r
-       void schedule_next_video(const safe_ptr<const core::read_frame>& frame)\r
+       void schedule_next_video(const safe_ptr<core::read_frame>& frame)\r
        {\r
                static std::vector<int16_t> silence(MAX_HANC_BUFFER_SIZE, 0);\r
                \r
@@ -216,10 +221,15 @@ public:
                                // Copy to local buffers\r
 \r
                                if(!frame->image_data().empty())\r
-                                       fast_memcpy(reserved_frames_.front()->image_data(), frame->image_data().begin(), frame->image_data().size());\r
+                               {\r
+                                       if(key_only_)                                           \r
+                                               fast_memshfl(reserved_frames_.front()->image_data(), frame->image_data().begin(), frame->image_data().size(), 0x0F0F0F0F, 0x0B0B0B0B, 0x07070707, 0x03030303);\r
+                                       else\r
+                                               fast_memcpy(reserved_frames_.front()->image_data(), frame->image_data().begin(), frame->image_data().size());\r
+                               }\r
                                else\r
                                        fast_memclr(reserved_frames_.front()->image_data(), reserved_frames_.front()->image_size());\r
-\r
+                                                               \r
                                // Sync\r
 \r
                                sync_timer_.restart();\r
@@ -308,22 +318,26 @@ struct bluefish_consumer_proxy : public core::frame_consumer
        const size_t                                            device_index_;\r
        const bool                                                      embedded_audio_;\r
        const bool                                                      key_only_;\r
+       core::video_format_desc                         format_desc_;\r
 public:\r
 \r
        bluefish_consumer_proxy(size_t device_index, bool embedded_audio, bool key_only)\r
                : device_index_(device_index)\r
                , embedded_audio_(embedded_audio)\r
-               , key_only_(key_only){}\r
+               , key_only_(key_only)\r
+       {\r
+       }\r
        \r
        virtual void initialize(const core::video_format_desc& format_desc)\r
        {\r
-               consumer_.reset();\r
-               consumer_.reset(new bluefish_consumer(format_desc, device_index_, embedded_audio_));\r
+               format_desc_ = format_desc;\r
+               consumer_.reset(new bluefish_consumer(format_desc, device_index_, embedded_audio_, key_only_));\r
        }\r
        \r
-       virtual void send(const safe_ptr<const core::read_frame>& frame)\r
+       virtual bool send(const safe_ptr<core::read_frame>& frame)\r
        {\r
                consumer_->send(frame);\r
+               return true;\r
        }\r
 \r
        virtual const core::video_format_desc& get_video_format_desc() const\r
@@ -338,11 +352,6 @@ public:
 \r
                return L"bluefish [" + boost::lexical_cast<std::wstring>(device_index_) + L"]";\r
        }\r
-\r
-       virtual bool key_only() const\r
-       {\r
-               return key_only_;\r
-       }\r
 };     \r
 \r
 safe_ptr<core::frame_consumer> create_bluefish_consumer(const std::vector<std::wstring>& params)\r