]> git.sesse.net Git - casparcg/blobdiff - modules/bluefish/consumer/bluefish_consumer.cpp
Changes to support the new way of setting bluefish properties.
[casparcg] / modules / bluefish / consumer / bluefish_consumer.cpp
index 74096f2789ead94e2aaee7ab95f09853f7d0018d..75ac170ccfb18237667b12115406ec3c2f7b2af9 100644 (file)
@@ -60,7 +60,8 @@ namespace caspar { namespace bluefish {
 enum class hardware_downstream_keyer_mode
 {
        disable = 0,
-       enable = 1,
+       external = 1,
+       internal = 2,           // Bluefish dedicated HW keyer - only available on some models.
 };
 
 enum class hardware_downstream_keyer_audio_source
@@ -71,14 +72,11 @@ enum class hardware_downstream_keyer_audio_source
 
 enum class bluefish_hardware_output_channel
 {
-       // ** current Bluefish hardware only support 4224  on channels A and C.
-       hardware_4224_channel_a,
-       hardware_4224_channel_c,
-       hardware_422_channel_a,
-       hardware_422_channel_b,
-       hardware_422_channel_c,
-       hardware_422_channel_d,
-       default_output_channel = hardware_422_channel_a
+       channel_a,
+       channel_b,
+       channel_c,
+       channel_d,
+       default_output_channel = channel_a
 };
 
 EBlueVideoChannel get_bluesdk_videochannel_from_streamid(bluefish_hardware_output_channel streamid)
@@ -86,12 +84,10 @@ EBlueVideoChannel get_bluesdk_videochannel_from_streamid(bluefish_hardware_outpu
        /*This function would return the corresponding EBlueVideoChannel from the device output channel*/
        switch (streamid)
        {
-               case bluefish_hardware_output_channel::hardware_422_channel_a:  return BLUE_VIDEO_OUTPUT_CHANNEL_A;
-               case bluefish_hardware_output_channel::hardware_4224_channel_a: return BLUE_VIDEO_OUTPUT_CHANNEL_A;
-               case bluefish_hardware_output_channel::hardware_422_channel_b:  return BLUE_VIDEO_OUTPUT_CHANNEL_B;
-               case bluefish_hardware_output_channel::hardware_4224_channel_c: return BLUE_VIDEO_OUTPUT_CHANNEL_C;
-               case bluefish_hardware_output_channel::hardware_422_channel_c:  return BLUE_VIDEO_OUTPUT_CHANNEL_C;
-               case bluefish_hardware_output_channel::hardware_422_channel_d:  return BLUE_VIDEO_OUTPUT_CHANNEL_D;
+               case bluefish_hardware_output_channel::channel_a:       return BLUE_VIDEO_OUTPUT_CHANNEL_A;
+               case bluefish_hardware_output_channel::channel_b:       return BLUE_VIDEO_OUTPUT_CHANNEL_B;
+               case bluefish_hardware_output_channel::channel_c:       return BLUE_VIDEO_OUTPUT_CHANNEL_C;
+               case bluefish_hardware_output_channel::channel_d:       return BLUE_VIDEO_OUTPUT_CHANNEL_D;
                default: return BLUE_VIDEO_OUTPUT_CHANNEL_A;
        }
 }
@@ -102,22 +98,16 @@ bool get_videooutput_channel_routing_info_from_streamid(bluefish_hardware_output
 {
        switch (streamid)
        {
-       case bluefish_hardware_output_channel::hardware_4224_channel_a: channelSrcElement = EPOCH_SRC_OUTPUT_MEM_INTERFACE_CHA;
+       case bluefish_hardware_output_channel::channel_a:       channelSrcElement = EPOCH_SRC_OUTPUT_MEM_INTERFACE_CHA;
                sdioutputDstElement = EPOCH_DEST_SDI_OUTPUT_A;
                break;
-       case bluefish_hardware_output_channel::hardware_4224_channel_c: channelSrcElement = EPOCH_SRC_OUTPUT_MEM_INTERFACE_CHC;
-               sdioutputDstElement = EPOCH_DEST_SDI_OUTPUT_C;
-               break;
-       case bluefish_hardware_output_channel::hardware_422_channel_a:  channelSrcElement = EPOCH_SRC_OUTPUT_MEM_INTERFACE_CHA;
-               sdioutputDstElement = EPOCH_DEST_SDI_OUTPUT_A;
-               break;
-       case bluefish_hardware_output_channel::hardware_422_channel_b:  channelSrcElement = EPOCH_SRC_OUTPUT_MEM_INTERFACE_CHB;
+       case bluefish_hardware_output_channel::channel_b:       channelSrcElement = EPOCH_SRC_OUTPUT_MEM_INTERFACE_CHB;
                sdioutputDstElement = EPOCH_DEST_SDI_OUTPUT_B;
                break;
-       case bluefish_hardware_output_channel::hardware_422_channel_c:  channelSrcElement = EPOCH_SRC_OUTPUT_MEM_INTERFACE_CHC;
+       case bluefish_hardware_output_channel::channel_c:       channelSrcElement = EPOCH_SRC_OUTPUT_MEM_INTERFACE_CHC;
                sdioutputDstElement = EPOCH_DEST_SDI_OUTPUT_C;
                break;
-       case bluefish_hardware_output_channel::hardware_422_channel_d:  channelSrcElement = EPOCH_SRC_OUTPUT_MEM_INTERFACE_CHD;
+       case bluefish_hardware_output_channel::channel_d:       channelSrcElement = EPOCH_SRC_OUTPUT_MEM_INTERFACE_CHD;
                sdioutputDstElement = EPOCH_DEST_SDI_OUTPUT_D;
                break;
        default: return false;
@@ -127,7 +117,7 @@ bool get_videooutput_channel_routing_info_from_streamid(bluefish_hardware_output
 
 struct bluefish_consumer : boost::noncopyable
 {
-       spl::shared_ptr<bvc_wrapper>                                                    blue_;
+       spl::shared_ptr<bvc_wrapper>                                            blue_;
        const unsigned int                                                                      device_index_;
        const core::video_format_desc                                           format_desc_;
        const core::audio_channel_layout                                        channel_layout_;
@@ -217,7 +207,7 @@ public:
                if(BLUE_FAIL(blue_->set_card_property32(VIDEO_RGB_DATA_RANGE, CGR_RANGE)))
                        CASPAR_LOG(warning) << print() << L" Failed to set RGB data range to CGR.";     
                
-               if(!embedded_audio_ || (hardware_keyer_ == hardware_downstream_keyer_mode::enable && keyer_audio_source_ == hardware_downstream_keyer_audio_source::VideoOutputChannel) )
+               if(!embedded_audio_ || (hardware_keyer_ == hardware_downstream_keyer_mode::internal && keyer_audio_source_ == hardware_downstream_keyer_audio_source::SDIVideoInput) )
                {
                        if(BLUE_FAIL(blue_->set_card_property32(EMBEDEDDED_AUDIO_OUTPUT, 0)))
                                CASPAR_LOG(warning) << TEXT("BLUECARD ERROR: Failed to disable embedded audio.");                       
@@ -295,8 +285,11 @@ public:
                        get_videooutput_channel_routing_info_from_streamid(device_output_channel_, src_element, dst_element);
                        bool duallink_4224_enabled = false;
 
-                       if (device_output_channel_ == bluefish_hardware_output_channel::hardware_4224_channel_a || device_output_channel_ == bluefish_hardware_output_channel::hardware_4224_channel_c)
+                       if ((device_output_channel_ == bluefish_hardware_output_channel::channel_a || device_output_channel_ == bluefish_hardware_output_channel::channel_c) &&
+                               (hardware_keyer_ == hardware_downstream_keyer_mode::external))
+                       {
                                duallink_4224_enabled = true;
+                       }
 
                        // Enable/Disable dual link output
                        if (BLUE_FAIL(blue_->set_card_property32(VIDEO_DUAL_LINK_OUTPUT, duallink_4224_enabled)))
@@ -376,12 +369,12 @@ public:
                if (nInputSDIConnector == 0 || nInputStreams == 0)
                        return;
 
-               if (keyer == hardware_downstream_keyer_mode::disable)
+               if (keyer == hardware_downstream_keyer_mode::disable || keyer == hardware_downstream_keyer_mode::external)
                {
                        keyer_control_value = VIDEO_ONBOARD_KEYER_SET_STATUS_DISABLED(keyer_control_value);
                        keyer_control_value = VIDEO_ONBOARD_KEYER_SET_STATUS_DISABLE_OVER_BLACK(keyer_control_value);
                }
-               else if (keyer == hardware_downstream_keyer_mode::enable)
+               else if (keyer == hardware_downstream_keyer_mode::internal)
                {
                        unsigned int invalidVideoModeFlag = 0;
                        unsigned int inputVideoSignal = 0;
@@ -402,7 +395,7 @@ public:
                                CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(" Failed to set the genlock to the input for the HW keyer"));
                }
 
-               if (audio_source == hardware_downstream_keyer_audio_source::SDIVideoInput && (keyer == hardware_downstream_keyer_mode::enable))
+               if (audio_source == hardware_downstream_keyer_audio_source::SDIVideoInput && (keyer == hardware_downstream_keyer_mode::internal))
                        keyer_control_value = VIDEO_ONBOARD_KEYER_SET_STATUS_USE_INPUT_ANCILLARY(keyer_control_value);
                else if (audio_source == hardware_downstream_keyer_audio_source::VideoOutputChannel)
                        keyer_control_value = VIDEO_ONBOARD_KEYER_SET_STATUS_USE_OUTPUT_ANCILLARY(keyer_control_value);
@@ -421,11 +414,14 @@ public:
        {
                blue_->video_playback_stop(0,0);
                if(BLUE_FAIL(blue_->set_card_property32(VIDEO_BLACKGENERATOR, 1)))
-                       CASPAR_LOG(error)<< print() << TEXT(" Failed to disable video output.");                
+                       CASPAR_LOG(error)<< print() << TEXT(" Failed to disable video output.");        
+               if (BLUE_FAIL(blue_->set_card_property32(EMBEDEDDED_AUDIO_OUTPUT, 0)))
+                       CASPAR_LOG(error) << print() << TEXT(" Failed to disable audio output.");
+
        }
        
        std::future<bool> send(core::const_frame& frame)
-       {                                       
+       {                               
                return executor_.begin_invoke([=]() -> bool
                {
                        try
@@ -440,13 +436,12 @@ public:
                        }
 
                        return true;
-               });
+               }, caspar::task_priority::higher_priority);
        }
 
        void display_frame(core::const_frame frame)
        {
                // Sync
-
                sync_timer_.restart();
                unsigned long n_field = 0;
                blue_->wait_video_output_sync(UPD_FMT_FRAME, n_field);
@@ -460,7 +455,6 @@ public:
                previous_frame_ = frame;
 
                // Copy to local buffers
-               
                if(!frame.image_data().empty())
                {
                        if(key_only_)                                           
@@ -471,9 +465,7 @@ public:
                else
                        A_memset(reserved_frames_.front()->image_data(), 0, reserved_frames_.front()->image_size());
                                                                
-
                // Send and display
-
                if(embedded_audio_)
                {
                        auto remapped_audio     = channel_remapper_.mix_and_rearrange(frame.audio_data());
@@ -508,7 +500,6 @@ public:
                }
 
                boost::range::rotate(reserved_frames_, std::begin(reserved_frames_)+1);
-               
                graph_->set_value("frame-time", static_cast<float>(frame_timer_.elapsed()*format_desc_.fps*0.5));
        }
 
@@ -667,37 +658,30 @@ public:
 void describe_consumer(core::help_sink& sink, const core::help_repository& repo)
 {
        sink.short_description(L"Sends video on an SDI output using Bluefish video cards.");
-       sink.syntax(L"BLUEFISH {[device_index:int]|1} {[embedded_audio:EMBEDDED_AUDIO]} {[key_only:KEY_ONLY]} {CHANNEL_LAYOUT [channel_layout:string]}");
+       sink.syntax(L"BLUEFISH {[device_index:int]|1} {[sdi_device:int]|a} {[embedded_audio:EMBEDDED_AUDIO]} {[key_only:KEY_ONLY]} {CHANNEL_LAYOUT [channel_layout:string]} {[keyer:string|disabled]} ");
        sink.para()
-               ->text(L"Sends video on an SDI output using Bluefish video cards. Multiple video cards can be ")
+               ->text(L"Sends video on an SDI output using Bluefish video cards. Multiple devices can be ")
                ->text(L"installed in the same machine and used at the same time, they will be addressed via ")
                ->text(L"different ")->code(L"device_index")->text(L" parameters.");
+       sink.para()->text(L"Multiple output channels can be accessed via the ")->code(L"sdi_device")->text(L" parameter.");
        sink.para()->text(L"Specify ")->code(L"embedded_audio")->text(L" to embed audio into the SDI signal.");
        sink.para()
                ->text(L"Specifying ")->code(L"key_only")->text(L" will extract only the alpha channel from the ")
                ->text(L"channel. This is useful when you have two SDI video cards, and neither has native support ")
                ->text(L"for separate fill/key output");
        sink.para()->text(L"Specify ")->code(L"channel_layout")->text(L" to output a different audio channel layout than the channel uses.");
-       sink.para()->text(L"Specify ")->code(L"BF_4224_CHANNELA")->text(L" to use channel A on the card to  be configured to output "
-               L"4:2:2:4 with fill and key HD-SDI output's A and B on the card.\n"
-               L"This is the default option\n");
-       sink.para()->text(L"Specify ")->code(L"BF_4224_CHANNELC")->text(L" to use channel C on the card to  be configured to output "
-               L" 4:2:2:4 with fill and key  HD-SDI output's C and D on the card\n"
-               L" Channel C 4:2:2:4 support is only available on 4 output variant of Supernova  and SupernovaS+ card\n");
-
-       sink.para()->text(L"Specify ")->code(L"ENABLE_KEYER")->text(L" to enable use of hardware keyer on the bluefish board.\n"
-               L"\t\t\tUsing this option hardware keyer would key using \n "
-               L"\t\t\tthe video input on the SDI as background layer \n"
-               L"\t\t\tand graphics Generated by CasparCG as foreground layer");
-       sink.para()->text(L"Specify ")->code(L"DISABLE_KEYER")->text(L" this option to disable hardware keyer on the bluefish board");
-       sink.para()->text(L"Specify ")->code(L"KEYER_AUDIO_SOURCE_SDIINPUT")->text(L" to enable SDI embedded audio to be transparently passed through the keyer to the SDI output\n");
-       sink.para()->text(L"Specify ")->code(L"KEYER_AUDIO_SOURCE_OUTPUT_CHANNEL")->text(L" to enable keyer to pass the audio provided by CasparCG to the SDI output\n");
+       sink.para()->text(L"Specify ")->code(L"keyer")->text(L" to control the output channel configuration and hardware keyer")
+               ->text(L"disabled results in a single SDI stream of 422 output - This is the default")
+               ->text(L"external results in a 4224 stream across 2 SDI connectors, ")
+               ->text(L"internal results in a 422 output keyed over the incoming SDI input using the dedicated hardware keyer on the Bleufish hadrware");
+       sink.para()->text(L"Specify ")->code(L"internal-keyer-audio-source")->text(L" to control the source of the audio and ANC data when using the internal/hardware keyer");
 
        sink.para()->text(L"Examples:");
        sink.example(L">> ADD 1 BLUEFISH", L"uses the default device_index of 1.");
        sink.example(L">> ADD 1 BLUEFISH 2", L"for device_index 2.");
        sink.example(
                L">> ADD 1 BLUEFISH 1 EMBEDDED_AUDIO\n"
+
                L">> ADD 1 BLUEFISH 2 KEY_ONLY", L"uses device with index 1 as fill output with audio and device with index 2 as key output.");
 
 }
@@ -710,12 +694,13 @@ spl::shared_ptr<core::frame_consumer> create_consumer(    const std::vector<std::ws
        if(params.size() < 1 || !boost::iequals(params.at(0), L"BLUEFISH"))
                return core::frame_consumer::empty();
 
-       const auto device_index = params.size() > 1 ? boost::lexical_cast<int>(params.at(1)) : 1;
-
-       const auto embedded_audio       = contains_param(       L"EMBEDDED_AUDIO",      params);
-       const auto key_only                     = contains_param(       L"KEY_ONLY",            params);
-       const auto channel_layout       = get_param(            L"CHANNEL_LAYOUT",      params);
-       const auto device_stream        = contains_param(       L"SDI-STREAM",          params);
+       const auto device_index                 = params.size() > 1 ? boost::lexical_cast<int>(params.at(1)) : 1;
+       const auto device_stream                = contains_param(       L"SDI-STREAM", params);
+       const auto embedded_audio               = contains_param(       L"EMBEDDED_AUDIO",      params);
+       const auto key_only                             = contains_param(       L"KEY_ONLY",            params);
+       const auto channel_layout               = get_param(            L"CHANNEL_LAYOUT",      params);
+       const auto keyer_option                 = contains_param(       L"KEYER",                       params);
+       const auto keyer_audio_option   = contains_param(       L"INTERNAL-KEYER-AUDIO-SOURCE", params);
 
        auto layout = core::audio_channel_layout::invalid();
 
@@ -728,33 +713,30 @@ spl::shared_ptr<core::frame_consumer> create_consumer(    const std::vector<std::ws
 
                layout = *found_layout;
        }
-       bluefish_hardware_output_channel device_output_channel = bluefish_hardware_output_channel::hardware_4224_channel_a;
-
-       if (contains_param(L"BLUE_4224_CHANNELA", params))
-               device_output_channel = bluefish_hardware_output_channel::hardware_4224_channel_a;
-       else if (contains_param(L"BLUE_4224_CHANNELC", params))
-               device_output_channel = bluefish_hardware_output_channel::hardware_4224_channel_c;
-       else if (contains_param(L"BLUE_422_CHANNELA", params))
-               device_output_channel = bluefish_hardware_output_channel::hardware_422_channel_a;
-       else if (contains_param(L"BLUE_422_CHANNELB", params))
-               device_output_channel = bluefish_hardware_output_channel::hardware_422_channel_b;
-       else if (contains_param(L"BLUE_422_CHANNELC", params))
-               device_output_channel = bluefish_hardware_output_channel::hardware_422_channel_c;
-       else if (contains_param(L"BLUE_422_CHANNELD", params))
-               device_output_channel = bluefish_hardware_output_channel::hardware_422_channel_d;
 
-       hardware_downstream_keyer_mode keyer = hardware_downstream_keyer_mode::disable;
+       bluefish_hardware_output_channel device_output_channel = bluefish_hardware_output_channel::channel_a;
+       if (contains_param(L"A", params))
+               device_output_channel = bluefish_hardware_output_channel::channel_a;
+       else if (contains_param(L"B", params))
+               device_output_channel = bluefish_hardware_output_channel::channel_b;
+       else if (contains_param(L"C", params))
+               device_output_channel = bluefish_hardware_output_channel::channel_c;
+       else if (contains_param(L"D", params))
+               device_output_channel = bluefish_hardware_output_channel::channel_d;
 
-       if (contains_param(L"KEYER_DISABLED", params))
+       hardware_downstream_keyer_mode keyer = hardware_downstream_keyer_mode::disable;
+       if (contains_param(L"DISABLED", params))
                keyer = hardware_downstream_keyer_mode::disable;
-       else if (contains_param(L"KEYER_ENABLED", params))
-               keyer = hardware_downstream_keyer_mode::enable;
+       else if (contains_param(L"EXTERNAL", params))
+               keyer = hardware_downstream_keyer_mode::external;
+       else if (contains_param(L"INTERNAL", params))
+               keyer = hardware_downstream_keyer_mode::internal;
 
        hardware_downstream_keyer_audio_source keyer_audio_source = hardware_downstream_keyer_audio_source::VideoOutputChannel;
-       if (contains_param(L"KEYER_AUDIO_SOURCE_SDIINPUT", params))
+       if (contains_param(L"SDIVIDEOINPUT", params))
                keyer_audio_source = hardware_downstream_keyer_audio_source::SDIVideoInput;
        else
-       if (contains_param(L"KEYER_AUDIO_SOURCE_OUTPUT_CHANNEL", params))
+       if (contains_param(L"VIDEOOUTPUTCHANNEL", params))
                keyer_audio_source = hardware_downstream_keyer_audio_source::VideoOutputChannel;
 
        return spl::make_shared<bluefish_consumer_proxy>(device_index, embedded_audio, key_only, keyer, keyer_audio_source, layout, device_output_channel);
@@ -765,13 +747,13 @@ spl::shared_ptr<core::frame_consumer> create_preconfigured_consumer(
                                                                                        std::vector<spl::shared_ptr<core::video_channel>> channels)
 {      
        const auto device_index         = ptree.get(                                            L"device",                      1);
+       const auto device_stream        = ptree.get(                                            L"sdi-stream", L"a");
        const auto embedded_audio       = ptree.get(                                            L"embedded-audio",      false);
        const auto key_only                     = ptree.get(                                            L"key-only",            false);
        const auto channel_layout       = ptree.get_optional<std::wstring>(     L"channel-layout");
-       const auto hardware_keyer_value = ptree.get(L"hardware-keyer", L"disabled");
-       const auto keyer_audio_source_value = ptree.get(L"hardware-keyer-audio-source", L"videooutputchannel");
-       const auto device_stream = ptree.get(L"sdi-stream", L"blue_4224_channela");
-
+       const auto hardware_keyer_value = ptree.get(                                    L"keyer", L"disabled");
+       const auto keyer_audio_source_value = ptree.get(                                L"internal-keyer-audio-source", L"videooutputchannel");
+       
        auto layout = core::audio_channel_layout::invalid();
 
        if (channel_layout)
@@ -786,29 +768,23 @@ spl::shared_ptr<core::frame_consumer> create_preconfigured_consumer(
                layout = *found_layout;
        }
 
-       bluefish_hardware_output_channel device_output_channel = bluefish_hardware_output_channel::hardware_4224_channel_a;
-       if (device_stream == L"blue_4224_channela")
-               device_output_channel = bluefish_hardware_output_channel::hardware_4224_channel_a;
-       else if (device_stream == L"blue_4224_channelc")
-               device_output_channel = bluefish_hardware_output_channel::hardware_4224_channel_c;
-       else if (device_stream == L"blue_422_channela")
-               device_output_channel = bluefish_hardware_output_channel::hardware_422_channel_a;
-       else if (device_stream == L"blue_422_channelb")
-               device_output_channel = bluefish_hardware_output_channel::hardware_422_channel_b;
-       else if (device_stream == L"blue_422_channelc")
-               device_output_channel = bluefish_hardware_output_channel::hardware_422_channel_c;
-       else if (device_stream == L"blue_422_channeld")
-               device_output_channel = bluefish_hardware_output_channel::hardware_422_channel_d;
+       bluefish_hardware_output_channel device_output_channel = bluefish_hardware_output_channel::channel_a;
+       if (device_stream == L"a")
+               device_output_channel = bluefish_hardware_output_channel::channel_a;
+       else if (device_stream == L"b")
+               device_output_channel = bluefish_hardware_output_channel::channel_b;
+       else if (device_stream == L"c")
+               device_output_channel = bluefish_hardware_output_channel::channel_c;
+       else if (device_stream == L"d")
+               device_output_channel = bluefish_hardware_output_channel::channel_d;
 
        hardware_downstream_keyer_mode keyer_mode = hardware_downstream_keyer_mode::disable;
        if (hardware_keyer_value == L"disabled")
-       {
                keyer_mode = hardware_downstream_keyer_mode::disable;
-       }
-       else if (hardware_keyer_value == L"enabled")
-       {
-               keyer_mode = hardware_downstream_keyer_mode::enable;
-       }
+       else if (hardware_keyer_value == L"external")
+               keyer_mode = hardware_downstream_keyer_mode::external;
+       else if (hardware_keyer_value == L"internal")
+               keyer_mode = hardware_downstream_keyer_mode::internal;
 
        hardware_downstream_keyer_audio_source keyer_audio_source = hardware_downstream_keyer_audio_source::VideoOutputChannel;
        if (keyer_audio_source_value == L"videooutputchannel")