2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Robert Nagy, ronag89@gmail.com
22 #include "../StdAfx.h"
24 #include "blue_velvet.h"
26 #include <common/utf.h>
28 #include <core/video_format.h>
30 namespace caspar { namespace bluefish {
32 CBlueVelvet4* (*BlueVelvetFactory4)() = nullptr;
33 void (*BlueVelvetDestroy)(CBlueVelvet4* pObj) = nullptr;
34 const char* (*BlueVelvetVersion)() = nullptr;
35 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;
36 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;
38 void blue_velvet_initialize()
41 std::string module_str = "BlueVelvet64_d.dll";
43 std::string module_str = "BlueVelvet64.dll";
46 auto module = LoadLibrary(u16(module_str).c_str());
48 LoadLibrary(u16(std::string(getenv("SystemDrive")) + "\\Program Files\\Bluefish444\\Driver\\" + module_str).c_str());
50 LoadLibrary(u16(std::string(getenv("SystemDrive")) + "\\Program Files (x86)\\BlueFish444\\Driver\\" + module_str).c_str());
52 CASPAR_THROW_EXCEPTION(file_not_found() << msg_info("Could not find BlueVelvet3.dll. Required drivers are not installed."));
53 static std::shared_ptr<void> lib(module, FreeLibrary);
54 BlueVelvetFactory4 = reinterpret_cast<decltype(BlueVelvetFactory4)>(GetProcAddress(module, "BlueVelvetFactory4"));
55 BlueVelvetDestroy = reinterpret_cast<decltype(BlueVelvetDestroy)>(GetProcAddress(module, "BlueVelvetDestroy"));
56 BlueVelvetVersion = reinterpret_cast<decltype(BlueVelvetVersion)>(GetProcAddress(module, "BlueVelvetVersion"));
59 void blue_hanc_initialize()
62 std::string module_str = "BlueHancUtils64_d.dll";
64 std::string module_str = "BlueHancUtils64.dll";
67 auto module = LoadLibrary(u16(module_str).c_str());
69 LoadLibrary(u16(std::string(getenv("SystemDrive")) + "\\Program Files\\Bluefish444\\Driver\\" + module_str).c_str());
71 LoadLibrary(u16(std::string(getenv("SystemDrive")) + "\\Program Files (x86)\\BlueFish444\\Driver\\" + module_str).c_str());
73 CASPAR_THROW_EXCEPTION(file_not_found() << msg_info("Could not find BlueHancUtils.dll. Required drivers are not installed."));
74 static std::shared_ptr<void> lib(module, FreeLibrary);
75 encode_hanc_frame = reinterpret_cast<decltype(encode_hanc_frame)>(GetProcAddress(module, "encode_hanc_frame"));
76 encode_hanc_frame_ex = reinterpret_cast<decltype(encode_hanc_frame_ex)>(GetProcAddress(module, "encode_hanc_frame_ex"));
79 void blue_initialize()
81 blue_hanc_initialize();
82 blue_velvet_initialize();
85 EVideoMode vid_fmt_from_video_format(const core::video_format& fmt)
89 case core::video_format::pal: return VID_FMT_PAL;
90 case core::video_format::ntsc: return VID_FMT_NTSC;
91 case core::video_format::x576p2500: return VID_FMT_INVALID; //not supported
92 case core::video_format::x720p2398: return VID_FMT_720P_2398;
93 case core::video_format::x720p2400: return VID_FMT_720P_2400;
94 case core::video_format::x720p2500: return VID_FMT_720P_2500;
95 case core::video_format::x720p5000: return VID_FMT_720P_5000;
96 case core::video_format::x720p2997: return VID_FMT_720P_2997;
97 case core::video_format::x720p5994: return VID_FMT_720P_5994;
98 case core::video_format::x720p3000: return VID_FMT_720P_3000;
99 case core::video_format::x720p6000: return VID_FMT_720P_6000;
100 case core::video_format::x1080p2398: return VID_FMT_1080P_2397;
101 case core::video_format::x1080p2400: return VID_FMT_1080P_2400;
102 case core::video_format::x1080i5000: return VID_FMT_1080I_5000;
103 case core::video_format::x1080i5994: return VID_FMT_1080I_5994;
104 case core::video_format::x1080i6000: return VID_FMT_1080I_6000;
105 case core::video_format::x1080p2500: return VID_FMT_1080P_2500;
106 case core::video_format::x1080p2997: return VID_FMT_1080P_2997;
107 case core::video_format::x1080p3000: return VID_FMT_1080P_3000;
108 case core::video_format::x1080p5000: return VID_FMT_1080P_5000;
109 case core::video_format::x1080p5994: return VID_FMT_1080P_5994;
110 case core::video_format::x1080p6000: return VID_FMT_1080P_6000;
111 default: return VID_FMT_INVALID;
115 bool is_epoch_card(CBlueVelvet4& blue)
117 switch(blue.has_video_cardtype())
119 case CRD_BLUE_EPOCH_HORIZON:
120 case CRD_BLUE_EPOCH_CORE:
121 case CRD_BLUE_EPOCH_ULTRA:
122 case CRD_BLUE_EPOCH_2K_HORIZON:
123 case CRD_BLUE_EPOCH_2K_CORE:
124 case CRD_BLUE_EPOCH_2K_ULTRA:
125 case CRD_BLUE_CREATE_HD:
126 case CRD_BLUE_CREATE_2K:
127 case CRD_BLUE_CREATE_2K_ULTRA:
128 case CRD_BLUE_SUPER_NOVA:
135 std::wstring get_card_desc(CBlueVelvet4& blue)
137 switch(blue.has_video_cardtype())
139 case CRD_BLUEDEEP_LT: return L"Deepblue LT";// D64 Lite
140 case CRD_BLUEDEEP_SD: return L"Iridium SD";// Iridium SD
141 case CRD_BLUEDEEP_AV: return L"Iridium AV";// Iridium AV
142 case CRD_BLUEDEEP_IO: return L"Deepblue IO";// D64 Full
143 case CRD_BLUEWILD_AV: return L"Wildblue AV";// D64 AV
144 case CRD_IRIDIUM_HD: return L"Iridium HD";// * Iridium HD
145 case CRD_BLUEWILD_RT: return L"Wildblue RT";// D64 RT
146 case CRD_BLUEWILD_HD: return L"Wildblue HD";// * BadAss G2
147 case CRD_REDDEVIL: return L"Iridium Full";// Iridium Full
148 case CRD_BLUEDEEP_HD:
149 case CRD_BLUEDEEP_HDS: return L"Reserved for \"BasAss G2";// * BadAss G2 variant, proposed, reserved
150 case CRD_BLUE_ENVY: return L"Blue Envy"; // Mini Din
151 case CRD_BLUE_PRIDE: return L"Blue Pride";//Mini Din Output
152 case CRD_BLUE_GREED: return L"Blue Greed";
153 case CRD_BLUE_INGEST: return L"Blue Ingest";
154 case CRD_BLUE_SD_DUALLINK: return L"Blue SD Duallink";
155 case CRD_BLUE_CATALYST: return L"Blue Catalyst";
156 case CRD_BLUE_SD_DUALLINK_PRO: return L"Blue SD Duallink Pro";
157 case CRD_BLUE_SD_INGEST_PRO: return L"Blue SD Ingest pro";
158 case CRD_BLUE_SD_DEEPBLUE_LITE_PRO: return L"Blue SD Deepblue lite Pro";
159 case CRD_BLUE_SD_SINGLELINK_PRO: return L"Blue SD Singlelink Pro";
160 case CRD_BLUE_SD_IRIDIUM_AV_PRO: return L"Blue SD Iridium AV Pro";
161 case CRD_BLUE_SD_FIDELITY: return L"Blue SD Fidelity";
162 case CRD_BLUE_SD_FOCUS: return L"Blue SD Focus";
163 case CRD_BLUE_SD_PRIME: return L"Blue SD Prime";
164 case CRD_BLUE_EPOCH_2K_CORE: return L"Blue Epoch 2K Core";
165 case CRD_BLUE_EPOCH_2K_ULTRA: return L"Blue Epoch 2K Ultra";
166 case CRD_BLUE_EPOCH_HORIZON: return L"Blue Epoch Horizon";
167 case CRD_BLUE_EPOCH_CORE: return L"Blue Epoch Core";
168 case CRD_BLUE_EPOCH_ULTRA: return L"Blue Epoch Ultra";
169 case CRD_BLUE_CREATE_HD: return L"Blue Create HD";
170 case CRD_BLUE_CREATE_2K: return L"Blue Create 2K";
171 case CRD_BLUE_CREATE_2K_ULTRA: return L"Blue Create 2K Ultra";
172 default: return L"Unknown";
176 EVideoMode get_video_mode(CBlueVelvet4& blue, const core::video_format_desc& format_desc)
178 EVideoMode vid_fmt = VID_FMT_INVALID;
179 auto desiredVideoFormat = vid_fmt_from_video_format(format_desc.format);
180 int videoModeCount = blue.count_video_mode();
181 for(int videoModeIndex = 1; videoModeIndex <= videoModeCount; ++videoModeIndex)
183 EVideoMode videoMode = blue.enum_video_mode(videoModeIndex);
184 if(videoMode == desiredVideoFormat)
187 if(vid_fmt == VID_FMT_INVALID)
188 CASPAR_THROW_EXCEPTION(not_supported() << msg_info(L"video-mode not supported: " + format_desc.name));
193 spl::shared_ptr<CBlueVelvet4> create_blue()
195 if(!BlueVelvetFactory4 || !encode_hanc_frame)
196 CASPAR_THROW_EXCEPTION(not_supported() << msg_info("Bluefish drivers not found."));
198 return spl::shared_ptr<CBlueVelvet4>(BlueVelvetFactory4(), BlueVelvetDestroy);
201 spl::shared_ptr<CBlueVelvet4> create_blue(int device_index)
203 auto blue = create_blue();
205 if(BLUE_FAIL(blue->device_attach(device_index, FALSE)))
206 CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to attach device."));