From: ronag Date: Thu, 13 Jan 2011 17:56:20 +0000 (+0000) Subject: 2.0.0.2: X-Git-Tag: 2.0.1~855 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=38292123d99570075c01d9ac865b622a902f6f87;hp=11aee674e83fc8f24540d05e9c5e06ee8cbb1a94;p=casparcg 2.0.0.2: - bluefish_consumer: Dlls are loaded dynamically on-demand. Which means that a separate compilation is for running CasparCG on a machine without bluefish drivers installed. - bluefish_consumer: Embedded audio is now disabled when not used. git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@350 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- diff --git a/core/consumer/bluefish/bluefish_consumer.cpp b/core/consumer/bluefish/bluefish_consumer.cpp index 0d7726708..dc8e81e01 100644 --- a/core/consumer/bluefish/bluefish_consumer.cpp +++ b/core/consumer/bluefish/bluefish_consumer.cpp @@ -20,8 +20,6 @@ #include "..\..\StdAfx.h" -#ifndef DISABLE_BLUEFISH - #include "bluefish_consumer.h" #include "util.h" #include "memory.h" @@ -37,14 +35,77 @@ #include +#include + namespace caspar { namespace core { namespace bluefish { +class BlueVelvetLib +{ + HINSTANCE lib_; + + BlueVelvetLib() + { +#ifdef _DEBUG + auto lib_str = L"BlueVelvet3_d.dll"; +#else + auto lib_str = L"BlueVelvet3.dll"; +#endif + lib_ = LoadLibrary(lib_str); + if(!lib_) + BOOST_THROW_EXCEPTION(file_not_found() << msg_info("Could not find BlueVelvet3.dll")); + BlueVelvetFactory4 = (BlueVelvetFactory4Func)GetProcAddress(lib_, "BlueVelvetFactory4"); + } +public: + typedef CBlueVelvet4* (*BlueVelvetFactory4Func)(); + BlueVelvetFactory4Func BlueVelvetFactory4; + + ~BlueVelvetLib(){FreeLibrary(lib_);} + + static BlueVelvetLib& get_instance() + { + static BlueVelvetLib instance; + return instance; + } +}; + +class BlueHancUtilLib +{ + HINSTANCE lib_; + BlueHancUtilLib() + { +#ifdef _DEBUG + auto lib_str = L"BlueHancUtils_d.dll"; +#else + auto lib_str = L"BlueHancUtils.dll"; +#endif + lib_ = LoadLibrary(lib_str); + if(!lib_) + BOOST_THROW_EXCEPTION(file_not_found() << msg_info("Could not find BlueHancUtils.dll")); + encode_hanc_frame = (encode_hanc_frame_func)GetProcAddress(lib_, "encode_hanc_frame"); + encode_hanc_frame_ex = (encode_hanc_frame_ex_func)GetProcAddress(lib_, "encode_hanc_frame_ex"); + } +public: + typedef BLUE_UINT32 (*encode_hanc_frame_func)(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); + encode_hanc_frame_func encode_hanc_frame; + + typedef BLUE_UINT32 (*encode_hanc_frame_ex_func)(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); + encode_hanc_frame_ex_func encode_hanc_frame_ex; + + ~BlueHancUtilLib(){FreeLibrary(lib_);} + + static BlueHancUtilLib& get_instance() + { + static BlueHancUtilLib instance; + return instance; + } +}; + struct consumer::implementation : boost::noncopyable { boost::unique_future active_; executor executor_; - std::shared_ptr sdk_; + std::shared_ptr blue_; unsigned int device_index_; video_format_desc format_desc_; @@ -61,7 +122,7 @@ struct consumer::implementation : boost::noncopyable public: implementation::implementation(const video_format_desc& format_desc, unsigned int device_index, bool embed_audio) - : sdk_(BlueVelvetFactory4()) + : blue_(BlueVelvetLib::get_instance().BlueVelvetFactory4()) , device_index_(device_index) , format_desc_(format_desc) , mem_fmt_(MEM_FMT_ARGB_PC) @@ -72,10 +133,10 @@ public: , embed_audio_(embed_audio) { - if(BLUE_FAIL(sdk_->device_attach(device_index_, FALSE))) + if(BLUE_FAIL(blue_->device_attach(device_index_, FALSE))) BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info("BLUECARD ERROR: Failed to attach device.")); - int videoCardType = sdk_->has_video_cardtype(); + int videoCardType = blue_->has_video_cardtype(); CASPAR_LOG(info) << TEXT("BLUECARD INFO: Card type: ") << get_card_desc(videoCardType) << TEXT(". (device ") << device_index_ << TEXT(")"); //void* pBlueDevice = blue_attach_to_device(1); @@ -88,10 +149,10 @@ public: //blue_detach_from_device(&pBlueDevice); auto desiredVideoFormat = vid_fmt_from_video_format(format_desc_.format); - int videoModeCount = sdk_->count_video_mode(); + int videoModeCount = blue_->count_video_mode(); for(int videoModeIndex = 1; videoModeIndex <= videoModeCount; ++videoModeIndex) { - EVideoMode videoMode = sdk_->enum_video_mode(videoModeIndex); + EVideoMode videoMode = blue_->enum_video_mode(videoModeIndex); if(videoMode == desiredVideoFormat) vid_fmt_ = videoMode; } @@ -99,61 +160,66 @@ public: BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info("BLUECARD ERROR: Failed to set videomode.")); // Set default video output channel - //if(BLUE_FAIL(set_card_property(sdk_, DEFAULT_VIDEO_OUTPUT_CHANNEL, 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(sdk_, VIDEO_MODE, vid_fmt_))) + if(BLUE_FAIL(set_card_property(blue_, VIDEO_MODE, vid_fmt_))) BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info("BLUECARD ERROR: Failed to set videomode.")); //Select Update Mode for output - if(BLUE_FAIL(set_card_property(sdk_, VIDEO_UPDATE_TYPE, upd_fmt_))) + if(BLUE_FAIL(set_card_property(blue_, VIDEO_UPDATE_TYPE, upd_fmt_))) BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info("BLUECARD ERROR: Failed to set update type. ")); disable_video_output(); //Enable dual link output - if(BLUE_FAIL(set_card_property(sdk_, VIDEO_DUAL_LINK_OUTPUT, 1))) + if(BLUE_FAIL(set_card_property(blue_, VIDEO_DUAL_LINK_OUTPUT, 1))) BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info("BLUECARD ERROR: Failed to enable dual link.")); - if(BLUE_FAIL(set_card_property(sdk_, VIDEO_DUAL_LINK_OUTPUT_SIGNAL_FORMAT_TYPE, Signal_FormatType_4224))) + if(BLUE_FAIL(set_card_property(blue_, VIDEO_DUAL_LINK_OUTPUT_SIGNAL_FORMAT_TYPE, Signal_FormatType_4224))) BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info("BLUECARD ERROR: Failed to set dual link format type to 4:2:2:4. (device " + boost::lexical_cast(device_index_) + ")")); //Select output memory format - if(BLUE_FAIL(set_card_property(sdk_, VIDEO_MEMORY_FORMAT, mem_fmt_))) + if(BLUE_FAIL(set_card_property(blue_, VIDEO_MEMORY_FORMAT, mem_fmt_))) BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info("BLUECARD ERROR: Failed to set memory format.")); //Select image orientation - if(BLUE_FAIL(set_card_property(sdk_, VIDEO_IMAGE_ORIENTATION, ImageOrientation_Normal))) + if(BLUE_FAIL(set_card_property(blue_, VIDEO_IMAGE_ORIENTATION, ImageOrientation_Normal))) CASPAR_LOG(error) << TEXT("BLUECARD ERROR: Failed to set image orientation to normal. (device ") << device_index_ << TEXT(")"); // Select data range - if(BLUE_FAIL(set_card_property(sdk_, VIDEO_RGB_DATA_RANGE, CGR_RANGE))) + if(BLUE_FAIL(set_card_property(blue_, VIDEO_RGB_DATA_RANGE, CGR_RANGE))) CASPAR_LOG(error) << TEXT("BLUECARD ERROR: Failed to set RGB data range to CGR. (device ") << device_index_ << TEXT(")"); - if(BLUE_FAIL(set_card_property(sdk_, VIDEO_PREDEFINED_COLOR_MATRIX, vid_fmt_ == VID_FMT_PAL ? MATRIX_601_CGR : MATRIX_709_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(error) << TEXT("BLUECARD ERROR: Failed to set colormatrix to ") << (vid_fmt_ == VID_FMT_PAL ? TEXT("601 CGR") : TEXT("709 CGR")) << TEXT(". (device ") << device_index_ << TEXT(")"); - - //if(BLUE_FAIL(set_card_property(sdk_, EMBEDDED_AUDIO_OUTPUT, 0))) - // CASPAR_LOG(error) << TEXT("BLUECARD ERROR: Failed to enable embedded audio. (device ") << device_index_ << TEXT(")"); - //else - //{ - // CASPAR_LOG(info) << TEXT("BLUECARD INFO: Enabled embedded audio. (device ") << device_index_ << TEXT(")"); - // hasEmbeddedAudio_ = true; - //} + + if(!embed_audio_) + { + if(BLUE_FAIL(set_card_property(blue_, EMBEDEDDED_AUDIO_OUTPUT, 0))) + CASPAR_LOG(error) << TEXT("BLUECARD ERROR: Failed to disable embedded audio. (device ") << device_index_ << TEXT(")"); + CASPAR_LOG(info) << TEXT("BLUECARD INFO: Disabled embedded-audio. device ") << device_index_ << TEXT(")"); + } + else + { + if(BLUE_FAIL(set_card_property(blue_, EMBEDEDDED_AUDIO_OUTPUT, blue_emb_audio_enable | blue_emb_audio_group1_enable))) + CASPAR_LOG(error) << TEXT("BLUECARD ERROR: Failed to enable embedded audio. (device ") << device_index_ << TEXT(")"); + CASPAR_LOG(info) << TEXT("BLUECARD INFO: Enabled embedded-audio. device ") << device_index_ << TEXT(")"); + } CASPAR_LOG(info) << TEXT("BLUECARD INFO: Successfully configured bluecard for ") << format_desc_ << TEXT(". (device ") << device_index_ << TEXT(")"); - if (sdk_->has_output_key()) + if (blue_->has_output_key()) { int dummy = TRUE; int v4444 = FALSE; int invert = FALSE; int white = FALSE; - sdk_->set_output_key(dummy, v4444, invert, white); + blue_->set_output_key(dummy, v4444, invert, white); } - if(sdk_->GetHDCardType(device_index_) != CRD_HD_INVALID) - sdk_->Set_DownConverterSignalType(vid_fmt_ == VID_FMT_PAL ? SD_SDI : HD_SDI); + if(blue_->GetHDCardType(device_index_) != CRD_HD_INVALID) + blue_->Set_DownConverterSignalType(vid_fmt_ == VID_FMT_PAL ? SD_SDI : HD_SDI); - if(BLUE_FAIL(sdk_->set_video_engine(engine_mode_))) + if(BLUE_FAIL(blue_->set_video_engine(engine_mode_))) BOOST_THROW_EXCEPTION(bluefish_exception() << msg_info("BLUECARD ERROR: Failed to set vido engine.")); enable_video_output(); @@ -172,21 +238,21 @@ public: { disable_video_output(); - if(sdk_) - sdk_->device_detach(); + if(blue_) + blue_->device_detach(); CASPAR_LOG(info) << "BLUECARD INFO: Successfully released device " << device_index_; } void enable_video_output() { - if(!BLUE_PASS(set_card_property(sdk_, VIDEO_BLACKGENERATOR, 0))) + if(!BLUE_PASS(set_card_property(blue_, VIDEO_BLACKGENERATOR, 0))) CASPAR_LOG(error) << "BLUECARD ERROR: Failed to disable video output. (device " << device_index_ << TEXT(")"); } void disable_video_output() { - if(!BLUE_PASS(set_card_property(sdk_, VIDEO_BLACKGENERATOR, 1))) + if(!BLUE_PASS(set_card_property(blue_, VIDEO_BLACKGENERATOR, 1))) CASPAR_LOG(error) << "BLUECARD ERROR: Failed to disable video output. (device " << device_index_ << TEXT(")"); } @@ -205,7 +271,7 @@ public: std::copy_n(frame->image_data().begin(), frame->image_data().size(), reserved_frames_.front()->image_data()); unsigned long n_field = 0; - sdk_->wait_output_video_synch(UPD_FMT_FRAME, n_field); + blue_->wait_output_video_synch(UPD_FMT_FRAME, n_field); if(embed_audio_) { @@ -213,27 +279,27 @@ public: encode_hanc(reinterpret_cast(reserved_frames_.front()->hanc_data()), frame_audio_data, audio_samples, audio_nchannels); - sdk_->system_buffer_write_async(const_cast(reserved_frames_.front()->image_data()), + 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)); - sdk_->system_buffer_write_async(reserved_frames_.front()->hanc_data(), + 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(sdk_->render_buffer_update(BlueBuffer_Image_HANC(reserved_frames_.front()->id())))) + if(BLUE_FAIL(blue_->render_buffer_update(BlueBuffer_Image_HANC(reserved_frames_.front()->id())))) CASPAR_LOG(trace) << TEXT("BLUEFISH: render_buffer_update failed"); } else { - sdk_->system_buffer_write_async(const_cast(reserved_frames_.front()->image_data()), + 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(sdk_->render_buffer_update(BlueBuffer_Image(reserved_frames_.front()->id())))) + if(BLUE_FAIL(blue_->render_buffer_update(BlueBuffer_Image(reserved_frames_.front()->id())))) CASPAR_LOG(trace) << TEXT("BLUEFISH: render_buffer_update failed"); } @@ -253,7 +319,7 @@ public: void encode_hanc(BLUE_UINT32* hanc_data, void* audio_data, size_t audio_samples, size_t audio_nchannels) { - auto card_type = sdk_->has_video_cardtype(); + auto card_type = blue_->has_video_cardtype(); auto sample_type = (AUDIO_CHANNEL_16BIT | AUDIO_CHANNEL_LITTLEENDIAN); hanc_stream_info_struct hanc_stream_info; @@ -269,15 +335,9 @@ public: auto emb_audio_flag = (blue_emb_audio_enable | blue_emb_audio_group1_enable); if (!is_epoch_card(card_type)) - { - encode_hanc_frame(&hanc_stream_info, audio_data, audio_nchannels, - audio_samples, sample_type, emb_audio_flag); - } + BlueHancUtilLib::get_instance().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); - } + BlueHancUtilLib::get_instance().encode_hanc_frame_ex(card_type, &hanc_stream_info, audio_data, audio_nchannels, audio_samples, sample_type, emb_audio_flag); } }; @@ -285,6 +345,4 @@ consumer::consumer(consumer&& other) : impl_(std::move(other.impl_)){} consumer::consumer(const video_format_desc& format_desc, unsigned int device_index, bool embed_audio) : impl_(new implementation(format_desc, device_index, embed_audio)){} void consumer::send(const safe_ptr& frame){impl_->send(frame);} size_t consumer::buffer_depth() const{return impl_->buffer_depth();} -}}} - -#endif \ No newline at end of file +}}} \ No newline at end of file diff --git a/core/consumer/frame_consumer_device.cpp b/core/consumer/frame_consumer_device.cpp index 8ef68465d..9056a79a5 100644 --- a/core/consumer/frame_consumer_device.cpp +++ b/core/consumer/frame_consumer_device.cpp @@ -21,7 +21,7 @@ struct frame_consumer_device::implementation timer clock_; executor executor_; - size_t max_depth_; + size_t depth_; std::deque> buffer_; std::vector> consumers_; @@ -38,7 +38,7 @@ public: std::vector depths; boost::range::transform(consumers_, std::back_inserter(depths), std::mem_fn(&frame_consumer::buffer_depth)); - max_depth_ = *boost::range::max_element(depths); + depth_ = *boost::range::max_element(depths); executor_.set_capacity(3); executor_.start(); } @@ -49,7 +49,7 @@ public: { buffer_.push_back(frame); - if(buffer_.size() < max_depth_) + if(buffer_.size() < depth_) return; boost::range::for_each(consumers_, [&](const safe_ptr& consumer) diff --git a/shell/boostrapper.cpp b/shell/boostrapper.cpp index 646456a0c..838fd0332 100644 --- a/shell/boostrapper.cpp +++ b/shell/boostrapper.cpp @@ -3,9 +3,7 @@ #include #include -#ifndef DISABLE_BLUEFISH #include -#endif #include #include #include @@ -82,12 +80,10 @@ struct bootstrapper::implementation : boost::noncopyable bool windowed = xml_consumer.second.get("windowed", false); consumers.push_back(ogl::consumer(format_desc, device, stretch, windowed)); } - #ifndef DISABLE_BLUEFISH else if(name == "bluefish") consumers.push_back(bluefish::consumer(format_desc, xml_consumer.second.get("device", 0), xml_consumer.second.get("embedded-audio", false))); - #endif else if(name == "decklink") - consumers.push_back(make_safe(format_desc, xml_consumer.second.get("device", 0), xml_consumer.second.get("embedded-audio", false), xml_consumer.second.get("internalkey", false))); + consumers.push_back(make_safe(format_desc, xml_consumer.second.get("device", 0), xml_consumer.second.get("internalkey", false))); else if(name == "audio") consumers.push_back(oal::consumer(format_desc)); } diff --git a/shell/caspar.config b/shell/caspar.config index a0135f35b..94a7f7654 100644 --- a/shell/caspar.config +++ b/shell/caspar.config @@ -4,23 +4,9 @@ C:\\Casparcg\\_media\\ C:\\Casparcg\\_log\\ C:\\Casparcg\\ - C:\\Casparcg\\cg.fth.18 C:\\Casparcg\\_data\\ - - PAL - - - - 1 - true - - - PAL @@ -29,6 +15,15 @@ uniform true + diff --git a/shell/shell.vcxproj b/shell/shell.vcxproj index 8495ded14..8d7e43314 100644 --- a/shell/shell.vcxproj +++ b/shell/shell.vcxproj @@ -113,7 +113,7 @@ true - dxguid.lib;BlueHancUtils_d.lib;sfml-audio-d.lib;sfml-window-d.lib;sfml-graphics-d.lib;OpenGL32.lib;FreeImage.lib;GLee.lib;Winmm.lib;Ws2_32.lib;BlueVelvet3_d.lib;avformat-52.lib;avcodec-52.lib;avutil-50.lib;swscale-0.lib;%(AdditionalDependencies) + dxguid.lib;sfml-audio-d.lib;sfml-window-d.lib;sfml-graphics-d.lib;OpenGL32.lib;FreeImage.lib;GLee.lib;Winmm.lib;Ws2_32.lib;avformat-52.lib;avcodec-52.lib;avutil-50.lib;swscale-0.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories) @@ -162,7 +162,7 @@ - dxguid.lib; BlueHancUtils.lib;sfml-audio.lib;sfml-window.lib;sfml-graphics.lib;OpenGL32.lib;FreeImage.lib;Winmm.lib;Ws2_32.lib;Bluevelvet3.lib;avformat-52.lib;avcodec-52.lib;avutil-50.lib;SWSCALE-0.lib;tbb.lib;Glee.lib;%(AdditionalDependencies) + dxguid.lib;sfml-audio.lib;sfml-window.lib;sfml-graphics.lib;OpenGL32.lib;FreeImage.lib;Winmm.lib;Ws2_32.lib;avformat-52.lib;avcodec-52.lib;avutil-50.lib;SWSCALE-0.lib;tbb.lib;Glee.lib;%(AdditionalDependencies) %(AdditionalLibraryDirectories)