]> git.sesse.net Git - casparcg/blobdiff - modules/bluefish/consumer/bluefish_consumer.cpp
- Refactored so that consumers get the input channel_layout at initialization, instea...
[casparcg] / modules / bluefish / consumer / bluefish_consumer.cpp
index 62e840670f79c40b74d0479b06d3c96e5109bea8..aa354394429b853cc3412091ed601dc05fecc6c9 100644 (file)
@@ -1,21 +1,22 @@
 /*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+* Copyright 2013 Sveriges Television AB http://casparcg.com/\r
 *\r
-*  This file is part of CasparCG.\r
+* This file is part of CasparCG (www.casparcg.com).\r
 *\r
-*    CasparCG is free software: you can redistribute it and/or modify\r
-*    it under the terms of the GNU General Public License as published by\r
-*    the Free Software Foundation, either version 3 of the License, or\r
-*    (at your option) any later version.\r
+* CasparCG is free software: you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation, either version 3 of the License, or\r
+* (at your option) any later version.\r
 *\r
-*    CasparCG is distributed in the hope that it will be useful,\r
-*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-*    GNU General Public License for more details.\r
-\r
-*    You should have received a copy of the GNU General Public License\r
-*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+* CasparCG is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
 *\r
+* Author: Robert Nagy, ronag89@gmail.com\r
 */\r
  \r
 #include "../StdAfx.h"\r
@@ -24,6 +25,8 @@
 #include "../util/blue_velvet.h"\r
 #include "../util/memory.h"\r
 \r
+#include <core/parameters/parameters.h>\r
+#include <core/video_format.h>\r
 #include <core/mixer/read_frame.h>\r
 \r
 #include <common/concurrency/executor.h>\r
 #include <core/mixer/audio/audio_util.h>\r
 \r
 #include <tbb/concurrent_queue.h>\r
+#include <tbb/atomic.h>\r
 \r
 #include <boost/timer.hpp>\r
+#include <boost/range/algorithm.hpp>\r
+#include <boost/algorithm/string.hpp>\r
+#include <boost/property_tree/ptree.hpp>\r
 \r
 #include <memory>\r
 #include <array>\r
@@ -50,10 +57,12 @@ struct bluefish_consumer : boost::noncopyable
        safe_ptr<CBlueVelvet4>                          blue_;\r
        const unsigned int                                      device_index_;\r
        const core::video_format_desc           format_desc_;\r
+       const int                                                       channel_index_;\r
+       const core::channel_layout                      channel_layout_;\r
 \r
        const std::wstring                                      model_name_;\r
 \r
-       std::shared_ptr<diagnostics::graph> graph_;\r
+       safe_ptr<diagnostics::graph>            graph_;\r
        boost::timer                                            frame_timer_;\r
        boost::timer                                            tick_timer_;\r
        boost::timer                                            sync_timer_;    \r
@@ -62,34 +71,40 @@ struct bluefish_consumer : boost::noncopyable
 \r
        std::array<blue_dma_buffer_ptr, 4>      reserved_frames_;       \r
        tbb::concurrent_bounded_queue<std::shared_ptr<core::read_frame>> frame_buffer_;\r
-\r
-       int                                                                     preroll_count_;\r
-\r
+       tbb::atomic<int64_t>                            presentation_delay_millis_;\r
+       std::shared_ptr<core::read_frame>       previous_frame_;\r
+       \r
        const bool                                                      embedded_audio_;\r
        const bool                                                      key_only_;\r
-       \r
+               \r
        executor                                                        executor_;\r
 public:\r
-       bluefish_consumer(const core::video_format_desc& format_desc, unsigned int device_index, bool embedded_audio, bool key_only) \r
+       bluefish_consumer(\r
+                       const core::video_format_desc& format_desc,\r
+                       unsigned int device_index,\r
+                       bool embedded_audio,\r
+                       bool key_only,\r
+                       int channel_index,\r
+                       const core::channel_layout& channel_layout)\r
                : blue_(create_blue(device_index))\r
                , device_index_(device_index)\r
                , format_desc_(format_desc) \r
+               , channel_index_(channel_index)\r
+               , channel_layout_(channel_layout)\r
                , model_name_(get_card_desc(*blue_))\r
                , 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
+               executor_.set_capacity(1);\r
+               presentation_delay_millis_ = 0;\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.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
-               graph_->set_color("input-buffer", diagnostics::color(1.0f, 1.0f, 0.0f));\r
+               graph_->set_color("sync-time", diagnostics::color(1.0f, 0.0f, 0.0f));\r
+               graph_->set_color("frame-time", diagnostics::color(0.5f, 1.0f, 0.2f));\r
+               graph_->set_text(print());\r
+               diagnostics::register_graph(graph_);\r
                        \r
                //Setting output Video mode\r
                if(BLUE_FAIL(set_card_property(blue_, VIDEO_MODE, vid_fmt_))) \r
@@ -131,7 +146,19 @@ public:
                }\r
                else\r
                {\r
-                       if(BLUE_FAIL(set_card_property(blue_, EMBEDEDDED_AUDIO_OUTPUT, blue_emb_audio_enable | blue_emb_audio_group1_enable))) \r
+                       ULONG audio_value =\r
+                               EMBEDDED_AUDIO_OUTPUT | blue_emb_audio_group1_enable;\r
+\r
+                       if (channel_layout_.num_channels > 4)\r
+                               audio_value |= blue_emb_audio_group2_enable;\r
+\r
+                       if (channel_layout_.num_channels > 8)\r
+                               audio_value |= blue_emb_audio_group3_enable;\r
+\r
+                       if (channel_layout_.num_channels > 12)\r
+                               audio_value |= blue_emb_audio_group4_enable;\r
+\r
+                       if(BLUE_FAIL(set_card_property(blue_, EMBEDEDDED_AUDIO_OUTPUT, audio_value))) \r
                                CASPAR_LOG(warning) << print() << TEXT(" Failed to enable embedded audio.");                    \r
                        CASPAR_LOG(info) << print() << TEXT(" Enabled embedded-audio.");\r
                }\r
@@ -145,19 +172,13 @@ public:
                if(blue_->GetHDCardType(device_index_) != CRD_HD_INVALID) \r
                        blue_->Set_DownConverterSignalType(vid_fmt_ == VID_FMT_PAL ? SD_SDI : HD_SDI);  \r
        \r
-               unsigned long engine_mode = VIDEO_ENGINE_FRAMESTORE;\r
-               if(BLUE_FAIL(blue_->set_video_engine(engine_mode)))\r
-                       BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Failed to set video engine."));\r
-\r
+               if(BLUE_FAIL(set_card_property(blue_, VIDEO_OUTPUT_ENGINE, VIDEO_ENGINE_FRAMESTORE))) \r
+                       CASPAR_LOG(warning) << print() << TEXT(" Failed to set video engine."); \r
+               \r
                enable_video_output();\r
                                                \r
                int n = 0;\r
-               std::generate(reserved_frames_.begin(), reserved_frames_.end(), [&]\r
-               {\r
-                       return std::make_shared<blue_dma_buffer>(format_desc_.size, n++);\r
-               });\r
-                                                               \r
-               CASPAR_LOG(info) << print() << L" Successfully Initialized.";\r
+               boost::range::generate(reserved_frames_, [&]{return std::make_shared<blue_dma_buffer>(format_desc_.size, n++);});\r
        }\r
 \r
        ~bluefish_consumer()\r
@@ -174,15 +195,8 @@ public:
                {\r
                        CASPAR_LOG_CURRENT_EXCEPTION();\r
                }\r
-               \r
-               CASPAR_LOG(info) << print() << L" Shutting down.";      \r
        }\r
        \r
-       const core::video_format_desc& get_video_format_desc() const\r
-       {\r
-               return format_desc_;\r
-       }\r
-\r
        void enable_video_output()\r
        {\r
                if(!BLUE_PASS(set_card_property(blue_, VIDEO_BLACKGENERATOR, 0)))\r
@@ -191,106 +205,117 @@ public:
 \r
        void disable_video_output()\r
        {\r
+               blue_->video_playback_stop(0,0);\r
                if(!BLUE_PASS(set_card_property(blue_, VIDEO_BLACKGENERATOR, 1)))\r
                        CASPAR_LOG(error)<< print() << TEXT(" Failed to disable video output.");                \r
        }\r
        \r
-       void send(const safe_ptr<core::read_frame>& frame)\r
-       {       \r
-               if(preroll_count_ < executor_.capacity())\r
-               {\r
-                       while(preroll_count_++ < executor_.capacity())\r
-                               schedule_next_video(make_safe<core::read_frame>());\r
-               }\r
-               \r
-               schedule_next_video(frame);                     \r
-       }\r
-       \r
-       void schedule_next_video(const safe_ptr<core::read_frame>& frame)\r
+       boost::unique_future<bool> send(const safe_ptr<core::read_frame>& frame)\r
        {\r
-               static std::vector<int16_t> silence(MAX_HANC_BUFFER_SIZE, 0);\r
-               \r
-               executor_.begin_invoke([=]\r
+               return executor_.begin_invoke([=]() -> bool\r
                {\r
                        try\r
+                       {       \r
+                               display_frame(frame);                           \r
+                               graph_->set_value("tick-time", static_cast<float>(tick_timer_.elapsed()*format_desc_.fps*0.5));\r
+                               tick_timer_.restart();\r
+                       }\r
+                       catch(...)\r
                        {\r
-                               const size_t audio_samples       = format_desc_.audio_samples_per_frame;\r
-                               const size_t audio_nchannels = format_desc_.audio_channels;\r
-\r
-                               frame_timer_.restart();\r
-                               \r
-                               // Copy to local buffers\r
-\r
-                               if(!frame->image_data().empty())\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
-                               // Sync\r
+                               CASPAR_LOG_CURRENT_EXCEPTION();\r
+                       }\r
 \r
-                               sync_timer_.restart();\r
-                               unsigned long n_field = 0;\r
-                               blue_->wait_output_video_synch(UPD_FMT_FRAME, n_field);\r
-                               graph_->update_value("sync-time", static_cast<float>(sync_timer_.elapsed()*format_desc_.fps*0.5));\r
+                       return true;\r
+               });\r
+       }\r
+\r
+       void display_frame(const safe_ptr<core::read_frame>& frame)\r
+       {\r
+               // Sync\r
+\r
+               sync_timer_.restart();\r
+               unsigned long n_field = 0;\r
+               blue_->wait_output_video_synch(UPD_FMT_FRAME, n_field);\r
+               graph_->set_value("sync-time", sync_timer_.elapsed()*format_desc_.fps*0.5);\r
+               \r
+               frame_timer_.restart();\r
 \r
-                               // Send and display\r
+               if (previous_frame_)\r
+                       presentation_delay_millis_ = previous_frame_->get_age_millis();\r
 \r
-                               if(embedded_audio_)\r
-                               {               \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
+               previous_frame_ = frame;\r
 \r
-                                       encode_hanc(reinterpret_cast<BLUE_UINT32*>(reserved_frames_.front()->hanc_data()), frame_audio_data, audio_samples, audio_nchannels);\r
+               // Copy to local buffers\r
+               \r
+               if(!frame->image_data().empty())\r
+               {\r
+                       if(key_only_)                                           \r
+                               fast_memshfl(reserved_frames_.front()->image_data(), std::begin(frame->image_data()), frame->image_data().size(), 0x0F0F0F0F, 0x0B0B0B0B, 0x07070707, 0x03030303);\r
+                       else\r
+                               fast_memcpy(reserved_frames_.front()->image_data(), std::begin(frame->image_data()), frame->image_data().size());\r
+               }\r
+               else\r
+                       fast_memclr(reserved_frames_.front()->image_data(), reserved_frames_.front()->image_size());\r
                                                                \r
-                                       blue_->system_buffer_write_async(const_cast<uint8_t*>(reserved_frames_.front()->image_data()), \r
-                                                                                                       reserved_frames_.front()->image_size(), \r
-                                                                                                       nullptr, \r
-                                                                                                       BlueImage_HANC_DMABuffer(reserved_frames_.front()->id(), BLUE_DATA_IMAGE));\r
-\r
-                                       blue_->system_buffer_write_async(reserved_frames_.front()->hanc_data(),\r
-                                                                                                       reserved_frames_.front()->hanc_size(), \r
-                                                                                                       nullptr,                 \r
-                                                                                                       BlueImage_HANC_DMABuffer(reserved_frames_.front()->id(), BLUE_DATA_HANC));\r
-\r
-                                       if(BLUE_FAIL(blue_->render_buffer_update(BlueBuffer_Image_HANC(reserved_frames_.front()->id()))))\r
-                                               CASPAR_LOG(warning) << print() << TEXT(" render_buffer_update failed.");\r
-                               }\r
-                               else\r
-                               {\r
-                                       blue_->system_buffer_write_async(const_cast<uint8_t*>(reserved_frames_.front()->image_data()),\r
-                                                                                                       reserved_frames_.front()->image_size(), \r
-                                                                                                       nullptr,                 \r
-                                                                                                       BlueImage_DMABuffer(reserved_frames_.front()->id(), BLUE_DATA_IMAGE));\r
-                       \r
-                                       if(BLUE_FAIL(blue_->render_buffer_update(BlueBuffer_Image(reserved_frames_.front()->id()))))\r
-                                               CASPAR_LOG(warning) << print() << TEXT(" render_buffer_update failed.");\r
-                               }\r
 \r
-                               std::rotate(reserved_frames_.begin(), reserved_frames_.begin() + 1, reserved_frames_.end());\r
-                               \r
-                               graph_->update_value("frame-time", static_cast<float>(frame_timer_.elapsed()*format_desc_.fps*0.5));\r
+               // Send and display\r
 \r
-                               graph_->update_value("tick-time", static_cast<float>(tick_timer_.elapsed()*format_desc_.fps*0.5));\r
-                               tick_timer_.restart();\r
-                       }\r
-                       catch(...)\r
-                       {\r
-                               CASPAR_LOG_CURRENT_EXCEPTION();\r
-                       }\r
-                       graph_->set_value("input-buffer", static_cast<double>(executor_.size())/static_cast<double>(executor_.capacity()));\r
-               });\r
-               graph_->set_value("input-buffer", static_cast<double>(executor_.size())/static_cast<double>(executor_.capacity()));\r
+               if(embedded_audio_)\r
+               {\r
+                       auto src_view = frame->multichannel_view();\r
+                       auto frame_audio = core::audio_32_to_24(\r
+                                       core::get_rearranged_and_mixed(\r
+                                                       src_view,\r
+                                                       channel_layout_,\r
+                                                       channel_layout_.num_channels));\r
+                       encode_hanc(\r
+                                       reinterpret_cast<BLUE_UINT32*>(reserved_frames_.front()->hanc_data()),\r
+                                       frame_audio.data(),\r
+                                       src_view.num_samples(),\r
+                                       channel_layout_.num_channels);\r
+\r
+                       blue_->system_buffer_write_async(const_cast<uint8_t*>(reserved_frames_.front()->image_data()), \r
+                                                                                       reserved_frames_.front()->image_size(), \r
+                                                                                       nullptr, \r
+                                                                                       BlueImage_HANC_DMABuffer(reserved_frames_.front()->id(), BLUE_DATA_IMAGE));\r
+\r
+                       blue_->system_buffer_write_async(reserved_frames_.front()->hanc_data(),\r
+                                                                                       reserved_frames_.front()->hanc_size(), \r
+                                                                                       nullptr,                 \r
+                                                                                       BlueImage_HANC_DMABuffer(reserved_frames_.front()->id(), BLUE_DATA_HANC));\r
+\r
+                       if(BLUE_FAIL(blue_->render_buffer_update(BlueBuffer_Image_HANC(reserved_frames_.front()->id()))))\r
+                               CASPAR_LOG(warning) << print() << TEXT(" render_buffer_update failed.");\r
+               }\r
+               else\r
+               {\r
+                       blue_->system_buffer_write_async(const_cast<uint8_t*>(reserved_frames_.front()->image_data()),\r
+                                                                                       reserved_frames_.front()->image_size(), \r
+                                                                                       nullptr,                 \r
+                                                                                       BlueImage_DMABuffer(reserved_frames_.front()->id(), BLUE_DATA_IMAGE));\r
+                       \r
+                       if(BLUE_FAIL(blue_->render_buffer_update(BlueBuffer_Image(reserved_frames_.front()->id()))))\r
+                               CASPAR_LOG(warning) << print() << TEXT(" render_buffer_update failed.");\r
+               }\r
+\r
+               boost::range::rotate(reserved_frames_, std::begin(reserved_frames_)+1);\r
+               \r
+               graph_->set_value("frame-time", static_cast<float>(frame_timer_.elapsed()*format_desc_.fps*0.5));\r
        }\r
 \r
        void encode_hanc(BLUE_UINT32* hanc_data, void* audio_data, size_t audio_samples, size_t audio_nchannels)\r
        {       \r
-               const auto sample_type = AUDIO_CHANNEL_16BIT | AUDIO_CHANNEL_LITTLEENDIAN;\r
-               const auto emb_audio_flag = blue_emb_audio_enable | blue_emb_audio_group1_enable;\r
+               const auto sample_type = AUDIO_CHANNEL_24BIT | AUDIO_CHANNEL_LITTLEENDIAN;\r
+               auto emb_audio_flag = blue_emb_audio_enable | blue_emb_audio_group1_enable;\r
+\r
+               if (audio_nchannels > 4)\r
+                       emb_audio_flag |= blue_emb_audio_group2_enable;\r
+\r
+               if (audio_nchannels > 8)\r
+                       emb_audio_flag |= blue_emb_audio_group3_enable;\r
+\r
+               if (audio_nchannels > 12)\r
+                       emb_audio_flag |= blue_emb_audio_group4_enable;\r
                \r
                hanc_stream_info_struct hanc_stream_info;\r
                memset(&hanc_stream_info, 0, sizeof(hanc_stream_info));\r
@@ -310,7 +335,13 @@ public:
        \r
        std::wstring print() const\r
        {\r
-               return model_name_ + L" [" + boost::lexical_cast<std::wstring>(device_index_) + L"|" +  format_desc_.name + L"]";\r
+               return model_name_ + L" [" + boost::lexical_cast<std::wstring>(channel_index_) + L"-" + \r
+                       boost::lexical_cast<std::wstring>(device_index_) + L"|" +  format_desc_.name + L"]";\r
+       }\r
+\r
+       int64_t presentation_delay_millis() const\r
+       {\r
+               return presentation_delay_millis_;\r
        }\r
 };\r
 \r
@@ -320,62 +351,119 @@ struct bluefish_consumer_proxy : public core::frame_consumer
        const size_t                                            device_index_;\r
        const bool                                                      embedded_audio_;\r
        const bool                                                      key_only_;\r
+       std::vector<size_t>                                     audio_cadence_;\r
        core::video_format_desc                         format_desc_;\r
+       core::channel_layout                            channel_layout_;\r
+\r
 public:\r
 \r
-       bluefish_consumer_proxy(size_t device_index, bool embedded_audio, bool key_only)\r
+       bluefish_consumer_proxy(\r
+                       size_t device_index,\r
+                       bool embedded_audio,\r
+                       bool key_only,\r
+                       const core::channel_layout& channel_layout)\r
                : device_index_(device_index)\r
                , embedded_audio_(embedded_audio)\r
                , key_only_(key_only)\r
+               , channel_layout_(channel_layout)\r
        {\r
        }\r
        \r
-       virtual void initialize(const core::video_format_desc& format_desc)\r
+       ~bluefish_consumer_proxy()\r
        {\r
-               format_desc_ = format_desc;\r
-               consumer_.reset(new bluefish_consumer(format_desc, device_index_, embedded_audio_, key_only_));\r
+               if(consumer_)\r
+               {\r
+                       auto str = print();\r
+                       consumer_.reset();\r
+                       CASPAR_LOG(info) << str << L" Successfully Uninitialized.";     \r
+               }\r
        }\r
+\r
+       // frame_consumer\r
        \r
-       virtual bool send(const safe_ptr<core::read_frame>& frame)\r
+       virtual void initialize(\r
+                       const core::video_format_desc& format_desc,\r
+                       const core::channel_layout& audio_channel_layout,\r
+                       int channel_index) override\r
        {\r
-               consumer_->send(frame);\r
-               return true;\r
+               consumer_.reset(new bluefish_consumer(\r
+                               format_desc,\r
+                               device_index_,\r
+                               embedded_audio_,\r
+                               key_only_,\r
+                               channel_index,\r
+                               channel_layout_));\r
+               audio_cadence_ = format_desc.audio_cadence;\r
+               format_desc_ = format_desc;\r
+               CASPAR_LOG(info) << print() << L" Successfully Initialized.";   \r
        }\r
 \r
-       virtual const core::video_format_desc& get_video_format_desc() const\r
+       virtual boost::unique_future<bool> send(const safe_ptr<core::read_frame>& frame) override\r
+       {\r
+               CASPAR_VERIFY(audio_cadence_.front() * frame->num_channels() == static_cast<size_t>(frame->audio_data().size()));\r
+               boost::range::rotate(audio_cadence_, std::begin(audio_cadence_)+1);\r
+\r
+               return consumer_->send(frame);\r
+       }\r
+               \r
+       virtual std::wstring print() const override\r
        {\r
-               return consumer_->get_video_format_desc();\r
+               return consumer_ ? consumer_->print() : L"[bluefish_consumer]";\r
+       }\r
+\r
+       virtual boost::property_tree::wptree info() const override\r
+       {\r
+               boost::property_tree::wptree info;\r
+               info.add(L"type", L"bluefish-consumer");\r
+               info.add(L"key-only", key_only_);\r
+               info.add(L"device", device_index_);\r
+               info.add(L"embedded-audio", embedded_audio_);\r
+               info.add(L"presentation-frame-age", presentation_frame_age_millis());\r
+               return info;\r
+       }\r
+\r
+       virtual size_t buffer_depth() const override\r
+       {\r
+               return 1;\r
        }\r
        \r
-       virtual std::wstring print() const\r
+       virtual int index() const override\r
        {\r
-               if(consumer_)\r
-                       consumer_->print();\r
+               return 400 + device_index_;\r
+       }\r
 \r
-               return L"bluefish [" + boost::lexical_cast<std::wstring>(device_index_) + L"]";\r
+       virtual int64_t presentation_frame_age_millis() const override\r
+       {\r
+               return consumer_ ? consumer_->presentation_delay_millis() : 0;\r
        }\r
 };     \r
 \r
-safe_ptr<core::frame_consumer> create_consumer(const std::vector<std::wstring>& params)\r
+safe_ptr<core::frame_consumer> create_consumer(const core::parameters& params)\r
 {\r
        if(params.size() < 1 || params[0] != L"BLUEFISH")\r
                return core::frame_consumer::empty();\r
                \r
        const auto device_index = params.size() > 1 ? lexical_cast_or_default<int>(params[1], 1) : 1;\r
 \r
-       const auto embedded_audio = std::find(params.begin(), params.end(), L"EMBEDDED_AUDIO") != params.end();\r
-       const auto key_only               = std::find(params.begin(), params.end(), L"KEY_ONLY")           != params.end();\r
+       const auto embedded_audio       = std::find(params.begin(), params.end(), L"EMBEDDED_AUDIO") != params.end();\r
+       const auto key_only                     = std::find(params.begin(), params.end(), L"KEY_ONLY")     != params.end();\r
+       const auto audio_layout         = core::default_channel_layout_repository().get_by_name(\r
+                       params.get(L"CHANNEL_LAYOUT", L"STEREO"));\r
 \r
-       return make_safe<bluefish_consumer_proxy>(device_index, embedded_audio, key_only);\r
+       return make_safe<bluefish_consumer_proxy>(device_index, embedded_audio, key_only, audio_layout);\r
 }\r
 \r
-safe_ptr<core::frame_consumer> create_consumer(const boost::property_tree::ptree& ptree) \r
+safe_ptr<core::frame_consumer> create_consumer(const boost::property_tree::wptree& ptree) \r
 {      \r
-       const auto device_index         = ptree.get("device",             1);\r
-       const auto embedded_audio       = ptree.get("embedded-audio", false);\r
-       const auto key_only                     = ptree.get("key-only",           false);\r
-\r
-       return make_safe<bluefish_consumer_proxy>(device_index, embedded_audio, key_only);\r
+       const auto device_index         = ptree.get(L"device",                  1);\r
+       const auto embedded_audio       = ptree.get(L"embedded-audio",  false);\r
+       const auto key_only                     = ptree.get(L"key-only",                false);\r
+       const auto audio_layout =\r
+               core::default_channel_layout_repository().get_by_name(\r
+                               boost::to_upper_copy(ptree.get(L"channel-layout", L"STEREO")));\r
+\r
+       return make_safe<bluefish_consumer_proxy>(\r
+                       device_index, embedded_audio, key_only, audio_layout);\r
 }\r
 \r
 }}
\ No newline at end of file