X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fbluefish%2Fconsumer%2Fbluefish_consumer.cpp;h=b6cb00da8a260fb16ddd972e4a5b783fd4b2db21;hb=722f60f03da38348021488872e57f2d451a91955;hp=68418770229a73cc561c24c7b15c9ff5c5fe8c82;hpb=4188ce4dd0d1dffd9f8d139e0a9a69fa5946d159;p=casparcg diff --git a/modules/bluefish/consumer/bluefish_consumer.cpp b/modules/bluefish/consumer/bluefish_consumer.cpp index 684187702..b6cb00da8 100644 --- a/modules/bluefish/consumer/bluefish_consumer.cpp +++ b/modules/bluefish/consumer/bluefish_consumer.cpp @@ -1,195 +1,131 @@ /* -* copyright (c) 2010 Sveriges Television AB +* Copyright (c) 2011 Sveriges Television AB * -* This file is part of CasparCG. +* This file is part of CasparCG (www.casparcg.com). * -* CasparCG is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. +* CasparCG is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. * -* CasparCG is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. - -* You should have received a copy of the GNU General Public License -* along with CasparCG. If not, see . +* CasparCG is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CasparCG. If not, see . * +* Author: Robert Nagy, ronag89@gmail.com */ #include "../StdAfx.h" #include "bluefish_consumer.h" -#include "../util/util.h" +#include "../util/blue_velvet.h" #include "../util/memory.h" -#include +#include +#include #include #include -#include +#include #include +#include + +#include +#include #include #include +#include +#include -#include -#include +#include #include #include -namespace caspar { - -CBlueVelvet4* (*BlueVelvetFactory4)() = nullptr; -const char* (*BlueVelvetVersion)() = nullptr; -BLUE_UINT32 (*encode_hanc_frame)(struct hanc_stream_info_struct * hanc_stream_ptr, void * audio_pcm_ptr,BLUE_UINT32 no_audio_ch,BLUE_UINT32 no_audio_samples,BLUE_UINT32 nTypeOfSample,BLUE_UINT32 emb_audio_flag) = nullptr; -BLUE_UINT32 (*encode_hanc_frame_ex)(BLUE_UINT32 card_type, struct hanc_stream_info_struct * hanc_stream_ptr, void * audio_pcm_ptr, BLUE_UINT32 no_audio_ch, BLUE_UINT32 no_audio_samples, BLUE_UINT32 nTypeOfSample, BLUE_UINT32 emb_audio_flag) = nullptr; - -void blue_velvet_initialize() -{ -#ifdef _DEBUG - auto module = LoadLibrary(L"BlueVelvet3_d.dll"); -#else - auto module = LoadLibrary(L"BlueVelvet3.dll"); -#endif - if(!module) - BOOST_THROW_EXCEPTION(file_not_found() << msg_info("Could not find BlueVelvet3.dll")); - static std::shared_ptr lib(module, FreeLibrary); - BlueVelvetFactory4 = reinterpret_cast(GetProcAddress(module, "BlueVelvetFactory4")); - BlueVelvetVersion = reinterpret_cast(GetProcAddress(module, "BlueVelvetVersion")); -} - -void blue_hanc_initialize() -{ -#ifdef _DEBUG - auto module = LoadLibrary(L"BlueHancUtils_d.dll"); -#else - auto module = LoadLibrary(L"BlueHancUtils.dll"); -#endif - if(!module) - BOOST_THROW_EXCEPTION(file_not_found() << msg_info("Could not find BlueHancUtils.dll")); - static std::shared_ptr lib(module, FreeLibrary); - encode_hanc_frame = reinterpret_cast(GetProcAddress(module, "encode_hanc_frame")); - encode_hanc_frame_ex = reinterpret_cast(GetProcAddress(module, "encode_hanc_frame_ex")); -} - -void blue_initialize() -{ - blue_velvet_initialize(); - blue_hanc_initialize(); -} - +namespace caspar { namespace bluefish { + struct bluefish_consumer : boost::noncopyable { - std::wstring model_name_; - const unsigned int device_index_; + safe_ptr blue_; + const unsigned int device_index_; + const core::video_format_desc format_desc_; + const int channel_index_; - std::shared_ptr graph_; - boost::timer perf_timer_; + const std::wstring model_name_; - boost::unique_future active_; + safe_ptr graph_; + boost::timer frame_timer_; + boost::timer tick_timer_; + boost::timer sync_timer_; - std::shared_ptr blue_; + unsigned int vid_fmt_; + + std::array reserved_frames_; + tbb::concurrent_bounded_queue> frame_buffer_; - const core::video_format_desc format_desc_; + const bool embedded_audio_; + const bool key_only_; - const unsigned long mem_fmt_; - const unsigned long upd_fmt_; - const unsigned long res_fmt_; - unsigned long engine_mode_; - EVideoMode vid_fmt_; - - std::array reserved_frames_; - - const bool embedded_audio_; - - executor executor_; + executor executor_; public: - bluefish_consumer(const core::video_format_desc& format_desc, unsigned int device_index, bool embedded_audio) - : model_name_(L"BLUEFISH") - , device_index_(device_index) - , format_desc_(format_desc) - , mem_fmt_(MEM_FMT_ARGB_PC) - , upd_fmt_(UPD_FMT_FRAME) - , res_fmt_(RES_FMT_NORMAL) - , engine_mode_(VIDEO_ENGINE_FRAMESTORE) - , vid_fmt_(VID_FMT_INVALID) + bluefish_consumer(const core::video_format_desc& format_desc, int device_index, bool embedded_audio, bool key_only, int channel_index) + : blue_(create_blue(device_index)) + , device_index_(device_index) + , format_desc_(format_desc) + , channel_index_(channel_index) + , model_name_(get_card_desc(*blue_)) + , vid_fmt_(get_video_mode(*blue_, format_desc)) , embedded_audio_(embedded_audio) - , executor_(print(), true) + , key_only_(key_only) + , executor_(print()) { - if(!BlueVelvetFactory4 || (embedded_audio_ && (!encode_hanc_frame || !encode_hanc_frame))) - BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Bluefish drivers not found.")); - - blue_.reset(BlueVelvetFactory4()); - - if(BLUE_FAIL(blue_->device_attach(device_index_, FALSE))) - BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info(narrow(print()) + " Failed to attach device.")); - - int videoCardType = blue_->has_video_cardtype(); - model_name_ = get_card_desc(videoCardType); + executor_.set_capacity(1); - graph_ = diagnostics::create_graph(narrow(print())); graph_->add_guide("tick-time", 0.5); - graph_->set_color("tick-time", diagnostics::color(0.1f, 0.7f, 0.8f)); + graph_->set_color("tick-time", diagnostics::color(0.0f, 0.6f, 0.9f)); + graph_->add_guide("frame-time", 0.5f); + graph_->set_color("sync-time", diagnostics::color(1.0f, 0.0f, 0.0f)); + graph_->set_color("frame-time", diagnostics::color(0.5f, 1.0f, 0.2f)); + graph_->set_text(print()); + diagnostics::register_graph(graph_); - //void* pBlueDevice = blue_attach_to_device(1); - //EBlueConnectorPropertySetting video_routing[1]; - //auto channel = BLUE_VIDEO_OUTPUT_CHANNEL_A; - //video_routing[0].channel = channel; - //video_routing[0].propType = BLUE_CONNECTOR_PROP_SINGLE_LINK; - //video_routing[0].connector = channel == BLUE_VIDEO_OUTPUT_CHANNEL_A ? BLUE_CONNECTOR_SDI_OUTPUT_A : BLUE_CONNECTOR_SDI_OUTPUT_B; - //blue_set_connector_property(pBlueDevice, 1, video_routing); - //blue_detach_from_device(&pBlueDevice); - - auto desiredVideoFormat = vid_fmt_from_video_format(format_desc_.format); - int videoModeCount = blue_->count_video_mode(); - for(int videoModeIndex = 1; videoModeIndex <= videoModeCount; ++videoModeIndex) - { - EVideoMode videoMode = blue_->enum_video_mode(videoModeIndex); - if(videoMode == desiredVideoFormat) - vid_fmt_ = videoMode; - } - if(vid_fmt_ == VID_FMT_INVALID) - BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info(narrow(print()) + " Failed to set videomode.")); - - // Set default video output channel - //if(BLUE_FAIL(set_card_property(blue_, DEFAULT_VIDEO_OUTPUT_CHANNEL, channel))) - // CASPAR_LOG(error) << TEXT("BLUECARD ERROR: Failed to set default channel. (device ") << device_index_ << TEXT(")"); - //Setting output Video mode if(BLUE_FAIL(set_card_property(blue_, VIDEO_MODE, vid_fmt_))) - BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info(narrow(print()) + " Failed to set videomode.")); + BOOST_THROW_EXCEPTION(caspar_exception() << wmsg_info(print() + L" Failed to set videomode.")); //Select Update Mode for output - if(BLUE_FAIL(set_card_property(blue_, VIDEO_UPDATE_TYPE, upd_fmt_))) - BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info(narrow(print()) + " Failed to set update type.")); + if(BLUE_FAIL(set_card_property(blue_, VIDEO_UPDATE_TYPE, UPD_FMT_FRAME))) + BOOST_THROW_EXCEPTION(caspar_exception() << wmsg_info(print() + L" Failed to set update type.")); disable_video_output(); //Enable dual link output if(BLUE_FAIL(set_card_property(blue_, VIDEO_DUAL_LINK_OUTPUT, 1))) - BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info(narrow(print()) + " Failed to enable dual link.")); + BOOST_THROW_EXCEPTION(caspar_exception() << wmsg_info(print() + L" Failed to enable dual link.")); if(BLUE_FAIL(set_card_property(blue_, VIDEO_DUAL_LINK_OUTPUT_SIGNAL_FORMAT_TYPE, Signal_FormatType_4224))) - BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info(narrow(print()) + " Failed to set dual link format type to 4:2:2:4.")); + BOOST_THROW_EXCEPTION(caspar_exception() << wmsg_info(print() + L" Failed to set dual link format type to 4:2:2:4.")); //Select output memory format - if(BLUE_FAIL(set_card_property(blue_, VIDEO_MEMORY_FORMAT, mem_fmt_))) - BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info(narrow(print()) + " Failed to set memory format.")); + if(BLUE_FAIL(set_card_property(blue_, VIDEO_MEMORY_FORMAT, MEM_FMT_ARGB_PC))) + BOOST_THROW_EXCEPTION(caspar_exception() << wmsg_info(print() + L" Failed to set memory format.")); //Select image orientation if(BLUE_FAIL(set_card_property(blue_, VIDEO_IMAGE_ORIENTATION, ImageOrientation_Normal))) - CASPAR_LOG(warning) << print() << TEXT(" Failed to set image orientation to normal."); + CASPAR_LOG(warning) << print() << L" Failed to set image orientation to normal."; // Select data range if(BLUE_FAIL(set_card_property(blue_, VIDEO_RGB_DATA_RANGE, CGR_RANGE))) - CASPAR_LOG(warning) << print() << TEXT(" Failed to set RGB data range to CGR."); + CASPAR_LOG(warning) << print() << L" Failed to set RGB data range to CGR."; if(BLUE_FAIL(set_card_property(blue_, VIDEO_PREDEFINED_COLOR_MATRIX, vid_fmt_ == VID_FMT_PAL ? MATRIX_601_CGR : MATRIX_709_CGR))) - CASPAR_LOG(warning) << print() << TEXT(" Failed to set colormatrix to ") << (vid_fmt_ == VID_FMT_PAL ? TEXT("601 CGR") : TEXT("709 CGR")) << TEXT("."); + CASPAR_LOG(warning) << print() << L" Failed to set colormatrix to " << (vid_fmt_ == VID_FMT_PAL ? L"601 CGR" : L"709 CGR") << L"."; if(!embedded_audio_) { @@ -213,33 +149,31 @@ public: if(blue_->GetHDCardType(device_index_) != CRD_HD_INVALID) blue_->Set_DownConverterSignalType(vid_fmt_ == VID_FMT_PAL ? SD_SDI : HD_SDI); - if(BLUE_FAIL(blue_->set_video_engine(engine_mode_))) - BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info(narrow(print()) + " Failed to set video engine.")); - + if(BLUE_FAIL(set_card_property(blue_, VIDEO_OUTPUT_ENGINE, VIDEO_ENGINE_FRAMESTORE))) + CASPAR_LOG(warning) << print() << TEXT(" Failed to set video engine."); + enable_video_output(); - for(size_t n = 0; n < reserved_frames_.size(); ++n) - reserved_frames_[n] = std::make_shared(format_desc_.size, n); - - active_ = executor_.begin_invoke([]{}); - - CASPAR_LOG(info) << print() << TEXT(" Successfully initialized for ") << format_desc_ << TEXT("."); + int n = 0; + boost::range::generate(reserved_frames_, [&]{return std::make_shared(format_desc_.size, n++);}); } ~bluefish_consumer() { - executor_.clear(); - executor_.invoke([&] + try { - disable_video_output(); - - if(blue_) + executor_.invoke([&] + { + disable_video_output(); blue_->device_detach(); - }); - - CASPAR_LOG(info) << print() << L" Shutting down."; + }); + } + catch(...) + { + CASPAR_LOG_CURRENT_EXCEPTION(); + } } - + void enable_video_output() { if(!BLUE_PASS(set_card_property(blue_, VIDEO_BLACKGENERATOR, 0))) @@ -248,60 +182,20 @@ public: void disable_video_output() { + blue_->video_playback_stop(0,0); if(!BLUE_PASS(set_card_property(blue_, VIDEO_BLACKGENERATOR, 1))) CASPAR_LOG(error)<< print() << TEXT(" Failed to disable video output."); } - - void send(const safe_ptr& frame) - { - static std::vector silence(MAX_HANC_BUFFER_SIZE, 0); - - active_.get(); - active_ = executor_.begin_invoke([=] + + void send(const safe_ptr& frame) + { + executor_.begin_invoke([=] { try - { - const size_t audio_samples = static_cast(48000.0 / format_desc_.fps); - const size_t audio_nchannels = 2; - - fast_memcpy(reserved_frames_.front()->image_data(), frame->image_data().begin(), frame->image_data().size()); - - if(embedded_audio_) - { - auto frame_audio_data = frame->audio_data().empty() ? silence.data() : const_cast(frame->audio_data().begin()); - - encode_hanc(reinterpret_cast(reserved_frames_.front()->hanc_data()), frame_audio_data, audio_samples, audio_nchannels); - - blue_->system_buffer_write_async(const_cast(reserved_frames_.front()->image_data()), - reserved_frames_.front()->image_size(), - nullptr, - BlueImage_HANC_DMABuffer(reserved_frames_.front()->id(), BLUE_DATA_IMAGE)); - - blue_->system_buffer_write_async(reserved_frames_.front()->hanc_data(), - reserved_frames_.front()->hanc_size(), - nullptr, - BlueImage_HANC_DMABuffer(reserved_frames_.front()->id(), BLUE_DATA_HANC)); - - if(BLUE_FAIL(blue_->render_buffer_update(BlueBuffer_Image_HANC(reserved_frames_.front()->id())))) - CASPAR_LOG(warning) << print() << TEXT(" render_buffer_update failed."); - } - else - { - blue_->system_buffer_write_async(const_cast(reserved_frames_.front()->image_data()), - reserved_frames_.front()->image_size(), - nullptr, - BlueImage_DMABuffer(reserved_frames_.front()->id(), BLUE_DATA_IMAGE)); - - if(BLUE_FAIL(blue_->render_buffer_update(BlueBuffer_Image(reserved_frames_.front()->id())))) - CASPAR_LOG(warning) << print() << TEXT(" render_buffer_update failed."); - } - - unsigned long n_field = 0; - blue_->wait_output_video_synch(UPD_FMT_FRAME, n_field); - - std::rotate(reserved_frames_.begin(), reserved_frames_.begin() + 1, reserved_frames_.end()); - graph_->update_value("tick-time", static_cast(perf_timer_.elapsed()/format_desc_.interval*0.5)); - perf_timer_.restart(); + { + display_frame(frame); + graph_->update_value("tick-time", static_cast(tick_timer_.elapsed()*format_desc_.fps*0.5)); + tick_timer_.restart(); } catch(...) { @@ -310,10 +204,73 @@ public: }); } - void encode_hanc(BLUE_UINT32* hanc_data, void* audio_data, size_t audio_samples, size_t audio_nchannels) + void display_frame(const safe_ptr& frame) + { + // Sync + + sync_timer_.restart(); + unsigned long n_field = 0; + blue_->wait_output_video_synch(UPD_FMT_FRAME, n_field); + graph_->update_value("sync-time", sync_timer_.elapsed()*format_desc_.fps*0.5); + + frame_timer_.restart(); + + // Copy to local buffers + + if(!frame->image_data().empty()) + { + if(key_only_) + aligned_memshfl(reserved_frames_.front()->image_data(), std::begin(frame->image_data()), frame->image_data().size(), 0x0F0F0F0F, 0x0B0B0B0B, 0x07070707, 0x03030303); + else + A_memcpy(reserved_frames_.front()->image_data(), std::begin(frame->image_data()), frame->image_data().size()); + } + else + A_memset(reserved_frames_.front()->image_data(), 0, reserved_frames_.front()->image_size()); + + + // Send and display + + if(embedded_audio_) + { + auto frame_audio = core::audio_32_to_24(frame->audio_data()); + encode_hanc(reinterpret_cast(reserved_frames_.front()->hanc_data()), + frame_audio.data(), + static_cast(frame->audio_data().size()/format_desc_.audio_channels), + format_desc_.audio_channels); + + blue_->system_buffer_write_async(const_cast(reserved_frames_.front()->image_data()), + static_cast(reserved_frames_.front()->image_size()), + nullptr, + BlueImage_HANC_DMABuffer(reserved_frames_.front()->id(), BLUE_DATA_IMAGE)); + + blue_->system_buffer_write_async(reserved_frames_.front()->hanc_data(), + static_cast(reserved_frames_.front()->hanc_size()), + nullptr, + BlueImage_HANC_DMABuffer(reserved_frames_.front()->id(), BLUE_DATA_HANC)); + + if(BLUE_FAIL(blue_->render_buffer_update(BlueBuffer_Image_HANC(reserved_frames_.front()->id())))) + CASPAR_LOG(warning) << print() << TEXT(" render_buffer_update failed."); + } + else + { + blue_->system_buffer_write_async(const_cast(reserved_frames_.front()->image_data()), + static_cast(reserved_frames_.front()->image_size()), + nullptr, + BlueImage_DMABuffer(reserved_frames_.front()->id(), BLUE_DATA_IMAGE)); + + if(BLUE_FAIL(blue_->render_buffer_update(BlueBuffer_Image(reserved_frames_.front()->id())))) + CASPAR_LOG(warning) << print() << TEXT(" render_buffer_update failed."); + } + + boost::range::rotate(reserved_frames_, std::begin(reserved_frames_)+1); + + graph_->update_value("frame-time", static_cast(frame_timer_.elapsed()*format_desc_.fps*0.5)); + } + + void encode_hanc(BLUE_UINT32* hanc_data, void* audio_data, int audio_samples, int audio_nchannels) { - auto card_type = blue_->has_video_cardtype(); - auto sample_type = (AUDIO_CHANNEL_16BIT | AUDIO_CHANNEL_LITTLEENDIAN); + const auto sample_type = AUDIO_CHANNEL_24BIT | AUDIO_CHANNEL_LITTLEENDIAN; + const auto emb_audio_flag = blue_emb_audio_enable | blue_emb_audio_group1_enable; hanc_stream_info_struct hanc_stream_info; memset(&hanc_stream_info, 0, sizeof(hanc_stream_info)); @@ -322,108 +279,112 @@ public: hanc_stream_info.AudioDBNArray[1] = -1; hanc_stream_info.AudioDBNArray[2] = -1; hanc_stream_info.AudioDBNArray[3] = -1; - hanc_stream_info.hanc_data_ptr = hanc_data; - hanc_stream_info.video_mode = vid_fmt_; + hanc_stream_info.hanc_data_ptr = hanc_data; + hanc_stream_info.video_mode = vid_fmt_; - auto emb_audio_flag = (blue_emb_audio_enable | blue_emb_audio_group1_enable); - - if (!is_epoch_card(card_type)) + if (!is_epoch_card(*blue_)) encode_hanc_frame(&hanc_stream_info, audio_data, audio_nchannels, audio_samples, sample_type, emb_audio_flag); else - encode_hanc_frame_ex(card_type, &hanc_stream_info, audio_data, audio_nchannels, audio_samples, sample_type, emb_audio_flag); + encode_hanc_frame_ex(blue_->has_video_cardtype(), &hanc_stream_info, audio_data, audio_nchannels, audio_samples, sample_type, emb_audio_flag); } std::wstring print() const { - return model_name_ + L" [" + boost::lexical_cast(device_index_) + L"]"; + return model_name_ + L" [" + boost::lexical_cast(channel_index_) + L"-" + + boost::lexical_cast(device_index_) + L"|" + format_desc_.name + L"]"; } }; struct bluefish_consumer_proxy : public core::frame_consumer { - std::unique_ptr consumer_; - const size_t device_index_; - const bool embedded_audio_; + std::unique_ptr consumer_; + const int device_index_; + const bool embedded_audio_; + const bool key_only_; + std::vector audio_cadence_; public: - bluefish_consumer_proxy(size_t device_index, bool embedded_audio) + bluefish_consumer_proxy(int device_index, bool embedded_audio, bool key_only) : device_index_(device_index) - , embedded_audio_(embedded_audio){} - - virtual void initialize(const core::video_format_desc& format_desc) + , embedded_audio_(embedded_audio) + , key_only_(key_only) { - consumer_.reset(new bluefish_consumer(format_desc, device_index_, embedded_audio_)); } - virtual void send(const safe_ptr& frame) + ~bluefish_consumer_proxy() { - consumer_->send(frame); + if(consumer_) + { + auto str = print(); + consumer_.reset(); + CASPAR_LOG(info) << str << L" Successfully Uninitialized."; + } } + + // frame_consumer - virtual std::wstring print() const + virtual void initialize(const core::video_format_desc& format_desc, int channel_index) override { - return consumer_->print(); + consumer_.reset(new bluefish_consumer(format_desc, device_index_, embedded_audio_, key_only_, channel_index)); + audio_cadence_ = format_desc.audio_cadence; + CASPAR_LOG(info) << print() << L" Successfully Initialized."; } -}; - -std::wstring get_bluefish_version() -{ - try + + virtual bool send(const safe_ptr& frame) override { - blue_initialize(); + CASPAR_VERIFY(audio_cadence_.front() == static_cast(frame->audio_data().size())); + boost::range::rotate(audio_cadence_, std::begin(audio_cadence_)+1); + + consumer_->send(frame); + return true; } - catch(...) + + virtual std::wstring print() const override { - return L"Not found"; + return consumer_ ? consumer_->print() : L"[bluefish_consumer]"; } - if(!BlueVelvetVersion) - return L"Unknown"; - - return widen(std::string(BlueVelvetVersion())); -} - -std::vector get_bluefish_device_list() -{ - std::vector devices; - - try - { - if(!BlueVelvetFactory4) - return devices; - - std::shared_ptr blue(BlueVelvetFactory4()); - for(int n = 1; BLUE_PASS(blue->device_attach(n, FALSE)); ++n) - { - devices.push_back(L"[" + boost::lexical_cast(n) + L"] " + get_card_desc(blue->has_video_cardtype())); - blue->device_detach(); - } + virtual boost::property_tree::wptree info() const override + { + boost::property_tree::wptree info; + info.add(L"type", L"bluefish-consumer"); + info.add(L"key-only", key_only_); + info.add(L"device", device_index_); + info.add(L"embedded-audio", embedded_audio_); + return info; } - catch(...){} - return devices; -} + int buffer_depth() const override + { + return 1; + } + + virtual int index() const override + { + return 400 + device_index_; + } +}; -safe_ptr create_bluefish_consumer(const std::vector& params) +safe_ptr create_consumer(const std::vector& params) { if(params.size() < 1 || params[0] != L"BLUEFISH") return core::frame_consumer::empty(); - int device_index = 1; - if(params.size() > 1) - device_index = lexical_cast_or_default(params[1], 1); + const auto device_index = params.size() > 1 ? lexical_cast_or_default(params[1], 1) : 1; - bool embedded_audio = std::find(params.begin(), params.end(), L"EMBEDDED_AUDIO") != params.end(); + const auto embedded_audio = std::find(params.begin(), params.end(), L"EMBEDDED_AUDIO") != params.end(); + const auto key_only = std::find(params.begin(), params.end(), L"KEY_ONLY") != params.end(); - return make_safe(device_index, embedded_audio); + return make_safe(device_index, embedded_audio, key_only); } -safe_ptr create_bluefish_consumer(const boost::property_tree::ptree& ptree) +safe_ptr create_consumer(const boost::property_tree::wptree& ptree) { - auto device_index = ptree.get("device", 0); - auto embedded_audio = ptree.get("embedded-audio", false); + const auto device_index = ptree.get(L"device", 1); + const auto embedded_audio = ptree.get(L"embedded-audio", false); + const auto key_only = ptree.get(L"key-only", false); - return make_safe(device_index, embedded_audio); + return make_safe(device_index, embedded_audio, key_only); } -} \ No newline at end of file +}} \ No newline at end of file