]> git.sesse.net Git - casparcg/blobdiff - modules/bluefish/consumer/bluefish_consumer.cpp
2.0. Updated namespaces.
[casparcg] / modules / bluefish / consumer / bluefish_consumer.cpp
index a25ab8baf7793ca49a88b87a719f476bb9554c9f..62e840670f79c40b74d0479b06d3c96e5109bea8 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
+#include <core/mixer/audio/audio_util.h>\r
 \r
 #include <tbb/concurrent_queue.h>\r
 \r
@@ -41,7 +43,7 @@
 #include <memory>\r
 #include <array>\r
 \r
-namespace caspar { \r
+namespace caspar { namespace bluefish { \r
                        \r
 struct bluefish_consumer : boost::noncopyable\r
 {\r
@@ -64,10 +66,11 @@ struct bluefish_consumer : boost::noncopyable
        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
@@ -75,6 +78,7 @@ 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(core::consumer_buffer_depth());\r
@@ -218,10 +222,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
@@ -233,7 +242,8 @@ public:
 \r
                                if(embedded_audio_)\r
                                {               \r
-                                       auto frame_audio_data = frame->audio_data().empty() ? silence.data() : const_cast<int16_t*>(frame->audio_data().begin());\r
+                                       auto frame_audio          = core::audio_32_to_16_sse(frame->audio_data());\r
+                                       auto frame_audio_data = frame_audio.size() != audio_samples ? silence.data() : frame_audio.data();      \r
 \r
                                        encode_hanc(reinterpret_cast<BLUE_UINT32*>(reserved_frames_.front()->hanc_data()), frame_audio_data, audio_samples, audio_nchannels);\r
                                                                \r
@@ -310,17 +320,20 @@ 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 bool send(const safe_ptr<core::read_frame>& frame)\r
@@ -341,14 +354,9 @@ 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
+safe_ptr<core::frame_consumer> create_consumer(const std::vector<std::wstring>& params)\r
 {\r
        if(params.size() < 1 || params[0] != L"BLUEFISH")\r
                return core::frame_consumer::empty();\r
@@ -361,7 +369,7 @@ safe_ptr<core::frame_consumer> create_bluefish_consumer(const std::vector<std::w
        return make_safe<bluefish_consumer_proxy>(device_index, embedded_audio, key_only);\r
 }\r
 \r
-safe_ptr<core::frame_consumer> create_bluefish_consumer(const boost::property_tree::ptree& ptree) \r
+safe_ptr<core::frame_consumer> create_consumer(const boost::property_tree::ptree& ptree) \r
 {      \r
        const auto device_index         = ptree.get("device",             1);\r
        const auto embedded_audio       = ptree.get("embedded-audio", false);\r
@@ -370,4 +378,4 @@ safe_ptr<core::frame_consumer> create_bluefish_consumer(const boost::property_tr
        return make_safe<bluefish_consumer_proxy>(device_index, embedded_audio, key_only);\r
 }\r
 \r
-}
\ No newline at end of file
+}}
\ No newline at end of file