]> git.sesse.net Git - casparcg/blob - modules/bluefish/util/blue_velvet.cpp
8ec40156822350ee8cd9a6dc852c0779ab95a710
[casparcg] / modules / bluefish / util / blue_velvet.cpp
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
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.
10 *
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.
15 *
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/>.
18 *
19 * Author: Robert Nagy, ronag89@gmail.com
20 */
21
22 #include "../StdAfx.h"
23 #include "blue_velvet.h"
24 #include <common/utf.h> 
25 #include <core/video_format.h>
26 #include <BlueVelvetCUtils.h>
27
28 #if defined(__APPLE__)
29 #include <dlfcn.h>
30 #endif
31
32 #if defined(_WIN32)
33         #define GET_PROCADDR_FOR_FUNC(name, module) { name = (pFunc_##name)GetProcAddress(reinterpret_cast<HMODULE>(module), #name); if(!name) { return false; } }
34 #elif defined(__APPLE__)
35         #define GET_PROCADDR_FOR_FUNC(name, module) { name = (pFunc_##name)dlsym(module, #name); if(!name) { return false; } }
36 #endif
37
38 namespace caspar { namespace bluefish {
39
40         bvc_wrapper::bvc_wrapper()
41         {
42                 if(!init_function_pointers())
43                         CASPAR_THROW_EXCEPTION(not_supported() << msg_info("Bluefish drivers not found.  Unable to init Funcion Pointers"));
44                 
45                 bvc_ = std::shared_ptr<void>(bfcFactory(), bfcDestroy);
46                 
47                 if (!bvc_)
48                         CASPAR_THROW_EXCEPTION(not_supported() << msg_info("Bluefish drivers not found."));
49         }
50
51         bool bvc_wrapper::init_function_pointers()
52         {
53                 bool res = false;
54 #if defined(_WIN32)
55 #ifdef _DEBUG
56                 h_module_ = std::shared_ptr<void>(LoadLibraryExA("BlueVelvetC64_d.dll", NULL, 0), FreeLibrary);
57 #else
58                 h_module_ = std::shared_ptr<void>(LoadLibraryExA("BlueVelvetC64.dll", NULL, 0), FreeLibrary);
59 #endif
60                 
61 #elif defined(__APPLE__)
62                 // Look for the framework and load it accordingly.
63                 char* libraryPath("/Library/Frameworks/BlueVelvetC.framework");         // full path may not be required, OSX might check in /l/f by default - MUST TEST!
64                 h_module_ = std::shared_ptr<void>(dlopen(libraryPath, RTLD_NOW), dlclose);
65 #endif
66                 
67                 if (h_module_)
68                 {
69                         GET_PROCADDR_FOR_FUNC(bfcGetVersion, h_module_.get());
70                         GET_PROCADDR_FOR_FUNC(bfcFactory, h_module_.get());
71                         GET_PROCADDR_FOR_FUNC(bfcDestroy, h_module_.get());
72                         GET_PROCADDR_FOR_FUNC(bfcEnumerate, h_module_.get());
73                         GET_PROCADDR_FOR_FUNC(bfcQueryCardType, h_module_.get());
74                         GET_PROCADDR_FOR_FUNC(bfcAttach, h_module_.get());
75                         GET_PROCADDR_FOR_FUNC(bfcDetach, h_module_.get());
76                         GET_PROCADDR_FOR_FUNC(bfcQueryCardProperty32, h_module_.get());
77                         GET_PROCADDR_FOR_FUNC(bfcQueryCardProperty64, h_module_.get());
78                         GET_PROCADDR_FOR_FUNC(bfcSetCardProperty32, h_module_.get());
79                         GET_PROCADDR_FOR_FUNC(bfcSetCardProperty64, h_module_.get());
80                         GET_PROCADDR_FOR_FUNC(bfcGetCardSerialNumber, h_module_.get());
81                         GET_PROCADDR_FOR_FUNC(bfcGetCardFwVersion, h_module_.get());
82                         GET_PROCADDR_FOR_FUNC(bfcWaitVideoSyncAsync, h_module_.get());
83                         GET_PROCADDR_FOR_FUNC(bfcWaitVideoInputSync, h_module_.get());
84                         GET_PROCADDR_FOR_FUNC(bfcWaitVideoOutputSync, h_module_.get());
85                         GET_PROCADDR_FOR_FUNC(bfcGetVideoOutputCurrentFieldCount, h_module_.get());
86                         GET_PROCADDR_FOR_FUNC(bfcGetVideoInputCurrentFieldCount, h_module_.get());
87                         GET_PROCADDR_FOR_FUNC(bfcVideoCaptureStart, h_module_.get());
88                         GET_PROCADDR_FOR_FUNC(bfcVideoCaptureStop, h_module_.get());
89                         GET_PROCADDR_FOR_FUNC(bfcVideoPlaybackStart, h_module_.get());
90                         GET_PROCADDR_FOR_FUNC(bfcVideoPlaybackStop, h_module_.get());
91                         GET_PROCADDR_FOR_FUNC(bfcVideoPlaybackAllocate, h_module_.get());
92                         GET_PROCADDR_FOR_FUNC(bfcVideoPlaybackPresent, h_module_.get());
93                         GET_PROCADDR_FOR_FUNC(bfcVideoPlaybackRelease, h_module_.get());
94                         GET_PROCADDR_FOR_FUNC(bfcGetCaptureVideoFrameInfoEx, h_module_.get());
95                         GET_PROCADDR_FOR_FUNC(bfcRenderBufferCapture, h_module_.get());
96                         GET_PROCADDR_FOR_FUNC(bfcRenderBufferUpdate, h_module_.get());
97                         GET_PROCADDR_FOR_FUNC(bfcGetRenderBufferCount, h_module_.get());
98                         GET_PROCADDR_FOR_FUNC(bfcEncodeHancFrameEx, h_module_.get());
99                         GET_PROCADDR_FOR_FUNC(bfcDecodeHancFrameEx, h_module_.get());
100                         GET_PROCADDR_FOR_FUNC(bfcSystemBufferReadAsync, h_module_.get());
101                         GET_PROCADDR_FOR_FUNC(bfcSystemBufferWriteAsync, h_module_.get());
102                         GET_PROCADDR_FOR_FUNC(bfcGetBytesForGroupPixels, h_module_.get());
103                         GET_PROCADDR_FOR_FUNC(bfcGetPixelsPerLine, h_module_.get());
104                         GET_PROCADDR_FOR_FUNC(bfcGetLinesPerFrame, h_module_.get());
105                         GET_PROCADDR_FOR_FUNC(bfcGetBytesPerLine, h_module_.get());
106                         GET_PROCADDR_FOR_FUNC(bfcGetBytesPerFrame, h_module_.get());
107                         GET_PROCADDR_FOR_FUNC(bfcGetGoldenValue, h_module_.get());
108                         GET_PROCADDR_FOR_FUNC(bfcGetVBILines, h_module_.get());
109                         GET_PROCADDR_FOR_FUNC(bfcGetVANCGoldenValue, h_module_.get());
110                         GET_PROCADDR_FOR_FUNC(bfcGetVANCLineBytes, h_module_.get());
111                         GET_PROCADDR_FOR_FUNC(bfcGetVANCLineCount, h_module_.get());
112                         GET_PROCADDR_FOR_FUNC(bfcGetWindowsDriverHandle, h_module_.get());
113                         GET_PROCADDR_FOR_FUNC(bfcUtilsGetStringForCardType, h_module_.get());
114                         GET_PROCADDR_FOR_FUNC(bfcUtilsGetStringForBlueProductId, h_module_.get());
115                         GET_PROCADDR_FOR_FUNC(bfcUtilsGetStringForVideoMode, h_module_.get());
116                         GET_PROCADDR_FOR_FUNC(bfcUtilsGetStringForMemoryFormat, h_module_.get());
117                         GET_PROCADDR_FOR_FUNC(bfcUtilsGetMR2Routing, h_module_.get());
118                         GET_PROCADDR_FOR_FUNC(bfcUtilsSetMR2Routing, h_module_.get());
119                         GET_PROCADDR_FOR_FUNC(bfcUtilsGetAudioOutputRouting, h_module_.get());
120                         GET_PROCADDR_FOR_FUNC(bfcUtilsSetAudioOutputRouting, h_module_.get());
121                         GET_PROCADDR_FOR_FUNC(bfcUtilsIsVideoModeProgressive, h_module_.get());
122                         GET_PROCADDR_FOR_FUNC(bfcUtilsIsVideoMode1001Framerate, h_module_.get());
123                         GET_PROCADDR_FOR_FUNC(bfcUtilsGetFpsForVideoMode, h_module_.get());
124                         GET_PROCADDR_FOR_FUNC(bfcUtilsGetVideoModeForFrameInfo, h_module_.get());
125                         GET_PROCADDR_FOR_FUNC(bfcUtilsGetFrameInfoForVideoMode, h_module_.get());
126                         GET_PROCADDR_FOR_FUNC(bfcUtilsGetAudioSamplesPerFrame, h_module_.get());
127                         res = true;
128                 }
129                 return res;
130         }
131
132         const char * bvc_wrapper::get_version()
133         {
134                 return bfcGetVersion();
135         }
136
137         BLUE_UINT32 bvc_wrapper::attach(int iDeviceId)
138         {
139                 return bfcAttach((BLUEVELVETC_HANDLE)bvc_.get(), iDeviceId);
140         }
141
142         BLUE_UINT32 bvc_wrapper::detach()
143         {
144                 return bfcDetach((BLUEVELVETC_HANDLE)bvc_.get());
145         }
146
147         BLUE_UINT32 bvc_wrapper::get_card_property32(const int iProperty, unsigned int & nValue)
148         {
149                 return (BLUE_UINT32)bfcQueryCardProperty32((BLUEVELVETC_HANDLE)bvc_.get(), iProperty, nValue);
150         }
151
152         BLUE_UINT32 bvc_wrapper::set_card_property32(const int iProperty, const unsigned int nValue)
153         {
154                 return bfcSetCardProperty32((BLUEVELVETC_HANDLE)bvc_.get(), iProperty, nValue);
155         }
156
157         BLUE_UINT32 bvc_wrapper::enumerate(int & iDevices)
158         {
159                 return bfcEnumerate((BLUEVELVETC_HANDLE)bvc_.get(), iDevices);
160         }
161
162         BLUE_UINT32 bvc_wrapper::query_card_type(int & iCardType, int iDeviceID)
163         {
164                 return bfcQueryCardType((BLUEVELVETC_HANDLE)bvc_.get(), iCardType, iDeviceID);
165         }
166
167         BLUE_UINT32 bvc_wrapper::system_buffer_write(unsigned char * pPixels, unsigned long ulSize, unsigned long ulBufferID, unsigned long ulOffset)
168         {
169                 return bfcSystemBufferWriteAsync((BLUEVELVETC_HANDLE)bvc_.get(), pPixels, ulSize, nullptr, ulBufferID, ulOffset);
170         }
171
172         BLUE_UINT32 bvc_wrapper::system_buffer_read(unsigned char* pPixels, unsigned long ulSize, unsigned long ulBufferID, unsigned long ulOffset)
173         {
174                 return bfcSystemBufferReadAsync((BLUEVELVETC_HANDLE)bvc_.get(), pPixels, ulSize, nullptr, ulBufferID, ulOffset);
175         }
176
177         BLUE_UINT32 bvc_wrapper::video_playback_stop(int iWait, int iFlush)
178         {
179                 return bfcVideoPlaybackStop((BLUEVELVETC_HANDLE)bvc_.get(), iWait, iFlush);
180         }
181
182         BLUE_UINT32 bvc_wrapper::wait_video_output_sync(unsigned long ulUpdateType, unsigned long & ulFieldCount)
183         {
184                 return bfcWaitVideoOutputSync((BLUEVELVETC_HANDLE)bvc_.get(), ulUpdateType, ulFieldCount);
185         }
186
187         BLUE_UINT32 bvc_wrapper::wait_video_input_sync(unsigned long ulUpdateType, unsigned long & ulFieldCount)
188         {
189                 return bfcWaitVideoInputSync((BLUEVELVETC_HANDLE)bvc_.get(), ulUpdateType, ulFieldCount);
190         }
191
192         BLUE_UINT32 bvc_wrapper::render_buffer_update( unsigned long ulBufferID)
193         {
194                 return bfcRenderBufferUpdate((BLUEVELVETC_HANDLE)bvc_.get(), ulBufferID);
195         }
196
197         BLUE_UINT32 bvc_wrapper::render_buffer_capture(unsigned long ulBufferID)
198         {
199                 return bfcRenderBufferCapture((BLUEVELVETC_HANDLE)bvc_.get(), ulBufferID);
200         }
201
202         BLUE_UINT32 bvc_wrapper::encode_hanc_frame(unsigned int nCardType, hanc_stream_info_struct * pHancEncodeInfo, void * pAudioBuffer, unsigned int nAudioChannels, unsigned int nAudioSamples, unsigned int nSampleType, unsigned int nAudioFlags)
203         {
204                 return bfcEncodeHancFrameEx((BLUEVELVETC_HANDLE)bvc_.get(), CRD_BLUE_NEUTRON, pHancEncodeInfo, pAudioBuffer, nAudioChannels, nAudioSamples, nSampleType, nAudioFlags);
205         }
206
207         BLUE_UINT32 bvc_wrapper::decode_hanc_frame(unsigned int nCardType, unsigned int * pHancBuffer, hanc_decode_struct * pHancDecodeInfo)
208         {
209                 return bfcDecodeHancFrameEx((BLUEVELVETC_HANDLE)bvc_.get(), CRD_BLUE_NEUTRON, pHancBuffer, pHancDecodeInfo);
210         }
211
212         BLUE_UINT32 bvc_wrapper::get_frame_info_for_video_mode(const unsigned int nVideoMode, unsigned int&  nWidth, unsigned int& nHeight, unsigned int& nRate, unsigned int& bIs1001, unsigned int& bIsProgressive)
213         {
214                 return bfcUtilsGetFrameInfoForVideoMode(nVideoMode, nWidth, nHeight, nRate, bIs1001, bIsProgressive);
215         }
216
217         BLUE_UINT32 bvc_wrapper::get_bytes_per_frame(EVideoMode nVideoMode, EMemoryFormat nMemoryFormat, EUpdateMethod nUpdateMethod, unsigned int& nBytesPerFrame)
218         {
219                 return bfcGetBytesPerFrame(nVideoMode, nMemoryFormat, nUpdateMethod, nBytesPerFrame);
220         }
221
222
223 EVideoMode vid_fmt_from_video_format(const core::video_format& fmt) 
224 {
225         switch(fmt)
226         {
227         case core::video_format::pal:                   return VID_FMT_PAL;
228         case core::video_format::ntsc:                  return VID_FMT_NTSC;
229         case core::video_format::x576p2500:             return VID_FMT_INVALID; //not supported
230         case core::video_format::x720p2398:             return VID_FMT_720P_2398;
231         case core::video_format::x720p2400:             return VID_FMT_720P_2400;
232         case core::video_format::x720p2500:             return VID_FMT_720P_2500;
233         case core::video_format::x720p5000:             return VID_FMT_720P_5000;
234         case core::video_format::x720p2997:             return VID_FMT_720P_2997;
235         case core::video_format::x720p5994:             return VID_FMT_720P_5994;
236         case core::video_format::x720p3000:             return VID_FMT_720P_3000;
237         case core::video_format::x720p6000:             return VID_FMT_720P_6000;
238         case core::video_format::x1080p2398:    return VID_FMT_1080P_2397;
239         case core::video_format::x1080p2400:    return VID_FMT_1080P_2400;
240         case core::video_format::x1080i5000:    return VID_FMT_1080I_5000;
241         case core::video_format::x1080i5994:    return VID_FMT_1080I_5994;
242         case core::video_format::x1080i6000:    return VID_FMT_1080I_6000;
243         case core::video_format::x1080p2500:    return VID_FMT_1080P_2500;
244         case core::video_format::x1080p2997:    return VID_FMT_1080P_2997;
245         case core::video_format::x1080p3000:    return VID_FMT_1080P_3000;
246         case core::video_format::x1080p5000:    return VID_FMT_1080P_5000;
247         case core::video_format::x1080p5994:    return VID_FMT_1080P_5994;
248         case core::video_format::x1080p6000:    return VID_FMT_1080P_6000;
249         default:                                                                return VID_FMT_INVALID;
250         }
251 }
252
253 bool is_epoch_card(bvc_wrapper& blue)
254 {
255         int device_id = 1;
256         int card_type = 0;
257         blue.query_card_type(card_type, device_id);
258
259         switch(card_type)
260         {
261                 case CRD_BLUE_EPOCH_HORIZON:
262                 case CRD_BLUE_EPOCH_CORE:
263                 case CRD_BLUE_EPOCH_ULTRA:
264                 case CRD_BLUE_EPOCH_2K_HORIZON:
265                 case CRD_BLUE_EPOCH_2K_CORE:
266                 case CRD_BLUE_EPOCH_2K_ULTRA:
267                 case CRD_BLUE_CREATE_HD:
268                 case CRD_BLUE_CREATE_2K:
269                 case CRD_BLUE_CREATE_2K_ULTRA:
270                 case CRD_BLUE_SUPER_NOVA:
271                 case CRD_BLUE_SUPER_NOVA_S_PLUS:
272                 case CRD_BLUE_NEUTRON:
273                 case CRD_BLUE_EPOCH_CG:
274                 return true;
275         default:
276                 return false;
277         }
278 }
279
280 bool is_epoch_neutron_1i2o_card(bvc_wrapper& blue)
281 {
282         BLUE_UINT32 val = 0;
283         blue.get_card_property32(EPOCH_GET_PRODUCT_ID, val);
284         if (val == ORAC_NEUTRON_1_IN_2_OUT_FIRMWARE_PRODUCTID)
285                 return true;
286         else
287                 return false;
288 }
289
290 bool is_epoch_neutron_3o_card(bvc_wrapper& blue)
291 {
292         BLUE_UINT32 val = 0;
293         blue.get_card_property32(EPOCH_GET_PRODUCT_ID, val);
294
295         if (val == ORAC_NEUTRON_0_IN_3_OUT_FIRMWARE_PRODUCTID)
296                 return true;
297         else
298                 return false;
299 }
300
301 std::wstring get_card_desc(bvc_wrapper& blue, int device_id)
302 {
303         int card_type = 0;
304         blue.query_card_type(card_type, device_id);
305
306         switch(card_type)
307         {
308                 case CRD_BLUEDEEP_LT:                           return L"Deepblue LT";// D64 Lite
309                 case CRD_BLUEDEEP_SD:                           return L"Iridium SD";// Iridium SD
310                 case CRD_BLUEDEEP_AV:                           return L"Iridium AV";// Iridium AV
311                 case CRD_BLUEDEEP_IO:                           return L"Deepblue IO";// D64 Full
312                 case CRD_BLUEWILD_AV:                           return L"Wildblue AV";// D64 AV
313                 case CRD_IRIDIUM_HD:                            return L"Iridium HD";// * Iridium HD
314                 case CRD_BLUEWILD_RT:                           return L"Wildblue RT";// D64 RT
315                 case CRD_BLUEWILD_HD:                           return L"Wildblue HD";// * BadAss G2
316                 case CRD_REDDEVIL:                                      return L"Iridium Full";// Iridium Full
317                 case CRD_BLUEDEEP_HD:   
318                 case CRD_BLUEDEEP_HDS:                          return L"Reserved for \"BasAss G2";// * BadAss G2 variant, proposed, reserved
319                 case CRD_BLUE_ENVY:                                     return L"Blue Envy"; // Mini Din 
320                 case CRD_BLUE_PRIDE:                            return L"Blue Pride";//Mini Din Output 
321                 case CRD_BLUE_GREED:                            return L"Blue Greed";
322                 case CRD_BLUE_INGEST:                           return L"Blue Ingest";
323                 case CRD_BLUE_SD_DUALLINK:                      return L"Blue SD Duallink";
324                 case CRD_BLUE_CATALYST:                         return L"Blue Catalyst";
325                 case CRD_BLUE_SD_DUALLINK_PRO:          return L"Blue SD Duallink Pro";
326                 case CRD_BLUE_SD_INGEST_PRO:            return L"Blue SD Ingest pro";
327                 case CRD_BLUE_SD_DEEPBLUE_LITE_PRO:     return L"Blue SD Deepblue lite Pro";
328                 case CRD_BLUE_SD_SINGLELINK_PRO:        return L"Blue SD Singlelink Pro";
329                 case CRD_BLUE_SD_IRIDIUM_AV_PRO:        return L"Blue SD Iridium AV Pro";
330                 case CRD_BLUE_SD_FIDELITY:                      return L"Blue SD Fidelity";
331                 case CRD_BLUE_SD_FOCUS:                         return L"Blue SD Focus";
332                 case CRD_BLUE_SD_PRIME:                         return L"Blue SD Prime";
333                 case CRD_BLUE_EPOCH_2K_CORE:            return L"Blue Epoch 2K Core";
334                 case CRD_BLUE_EPOCH_2K_ULTRA:           return L"Blue Epoch 2K Ultra";
335                 case CRD_BLUE_EPOCH_HORIZON:            return L"Blue Epoch Horizon";
336                 case CRD_BLUE_EPOCH_CORE:                       return L"Blue Epoch Core";
337                 case CRD_BLUE_EPOCH_ULTRA:                      return L"Blue Epoch Ultra";
338                 case CRD_BLUE_CREATE_HD:                        return L"Blue Create HD";
339                 case CRD_BLUE_CREATE_2K:                        return L"Blue Create 2K";
340                 case CRD_BLUE_CREATE_2K_ULTRA:          return L"Blue Create 2K Ultra";
341                 case CRD_BLUE_SUPER_NOVA:                       return L"Blue SuperNova";
342                 case CRD_BLUE_SUPER_NOVA_S_PLUS:        return L"Blue SuperNova s+";
343                 case CRD_BLUE_NEUTRON:                          return L"Blue Neutron 4k";
344                 case CRD_BLUE_EPOCH_CG:                         return L"Blue Epopch CG";
345                 default:                                                        return L"Unknown";
346         }
347 }
348
349 EVideoMode get_video_mode(bvc_wrapper& blue, const core::video_format_desc& format_desc)
350 {
351         EVideoMode vid_fmt = VID_FMT_INVALID;
352         BLUE_UINT32 invalid_fmt = 0;
353         BErr err = 0;
354         err = blue.get_card_property32(INVALID_VIDEO_MODE_FLAG, invalid_fmt);
355         vid_fmt = vid_fmt_from_video_format(format_desc.format);
356
357         if (vid_fmt == VID_FMT_INVALID)
358                 CASPAR_THROW_EXCEPTION(not_supported() << msg_info(L"video-mode not supported: " + format_desc.name));
359
360
361         if ((unsigned int)vid_fmt >= invalid_fmt)
362                 CASPAR_THROW_EXCEPTION(not_supported() << msg_info(L"video-mode not supported - Outside of valid range: " + format_desc.name));
363
364         return vid_fmt;
365 }
366
367 spl::shared_ptr<bvc_wrapper> create_blue()
368 {
369         auto pWrap = new bvc_wrapper();
370         return spl::shared_ptr<bvc_wrapper>(pWrap);
371 }
372
373 spl::shared_ptr<bvc_wrapper> create_blue(int device_index)
374 {
375         auto blue = create_blue();
376         
377         if(BLUE_FAIL(blue->attach(device_index)))
378                 CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to attach device."));
379
380         return blue;
381 }
382
383 core::video_format video_format_from_vid_fmt(EVideoMode fmt)
384 {
385         switch (fmt)
386         {
387         case VID_FMT_PAL: return core::video_format::pal;
388         case VID_FMT_NTSC: return core::video_format::ntsc;
389         case VID_FMT_720P_2398: return core::video_format::x720p2398;
390         case VID_FMT_720P_2400: return core::video_format::x720p2400;
391         case VID_FMT_720P_2500: return core::video_format::x720p2500;
392         case VID_FMT_720P_5000: return core::video_format::x720p5000;
393         case VID_FMT_720P_2997: return core::video_format::x720p2997;
394         case VID_FMT_720P_5994: return core::video_format::x720p5994;
395         case VID_FMT_720P_3000: return core::video_format::x720p3000;
396         case VID_FMT_720P_6000: return core::video_format::x720p6000;
397         case VID_FMT_1080P_2397: return core::video_format::x1080p2398;
398         case VID_FMT_1080P_2400: return core::video_format::x1080p2400;
399         case VID_FMT_1080I_5000: return core::video_format::x1080i5000;
400         case VID_FMT_1080I_5994: return core::video_format::x1080i5994;
401         case VID_FMT_1080I_6000: return core::video_format::x1080i6000;
402         case VID_FMT_1080P_2500: return core::video_format::x1080p2500;
403         case VID_FMT_1080P_2997: return core::video_format::x1080p2997;
404         case VID_FMT_1080P_3000: return core::video_format::x1080p3000;
405         case VID_FMT_1080P_5000: return core::video_format::x1080p5000;
406         case VID_FMT_1080P_5994: return core::video_format::x1080p5994;
407         case VID_FMT_1080P_6000: return core::video_format::x1080p6000;
408         default: return core::video_format::invalid;
409         }
410 }
411
412 core::video_format_desc get_format_desc(bvc_wrapper& blue, EVideoMode vid_fmt, EMemoryFormat mem_fmt)
413 {
414         core::video_format_desc fmt;
415         unsigned int width, height, duration = 0, time_scale = 0, rate = 0, bIs1001 = 0, bIsProgressive = 0, size = 0;
416         std::vector<int>        audio_cadence;
417         core::field_mode video_field_mode = core::field_mode::progressive;
418
419         blue.get_frame_info_for_video_mode(vid_fmt, width, height, rate, bIs1001, bIsProgressive);
420         blue.get_bytes_per_frame(vid_fmt, mem_fmt, UPD_FMT_FRAME, size);
421
422         switch (vid_fmt)
423         {
424         case VID_FMT_NTSC:
425         case VID_FMT_1080I_5994:
426                 duration = 30000;
427                 time_scale = 1001;
428                 audio_cadence = { 1601,1602,1601,1602,1602 };
429                 video_field_mode = core::field_mode::upper;
430                 break;
431         case VID_FMT_2048_1080P_2500:
432         case VID_FMT_2048_1080PSF_2500:
433         case VID_FMT_576I_5000:
434         case VID_FMT_1080P_2500:
435         case VID_FMT_1080I_5000:
436         case VID_FMT_1080PSF_2500:
437         case VID_FMT_720P_2500:
438                 duration = 25000;
439                 time_scale = 1000;
440                 audio_cadence = { 1920,1920,1920,1920,1920 };
441                 break;
442
443         case VID_FMT_720P_5994:
444         case VID_FMT_2048_1080P_5994:
445         case VID_FMT_1080P_5994:
446                 duration = 60000;
447                 time_scale = 1001;
448                 audio_cadence = { 801,800,801,800,800 };
449                 break;
450
451         case VID_FMT_1080P_6000:
452         case VID_FMT_2048_1080P_6000:
453         case VID_FMT_720P_6000:
454                 duration = 60000;
455                 time_scale = 1000;
456                 audio_cadence = { 801,800,801,800,800 };
457                 break;
458
459         case VID_FMT_1080PSF_2397:
460         case VID_FMT_1080P_2397:
461         case VID_FMT_720P_2398:
462         case VID_FMT_2048_1080PSF_2397:
463         case VID_FMT_2048_1080P_2397:
464                 duration = 24000;
465                 time_scale = 1000;
466                 break;
467
468         case VID_FMT_1080PSF_2400:
469         case VID_FMT_1080P_2400:
470         case VID_FMT_720P_2400:
471         case VID_FMT_2048_1080PSF_2400:
472         case VID_FMT_2048_1080P_2400:
473                 duration = 24000;
474                 time_scale = 1000;
475                 break;
476
477         case VID_FMT_1080I_6000:
478         case VID_FMT_1080PSF_3000:
479                 duration = 30000;
480                 time_scale = 1000;
481                 break;
482
483         case VID_FMT_720P_2997:
484         case VID_FMT_1080P_2997:
485         case VID_FMT_2048_1080PSF_2997:
486         case VID_FMT_2048_1080P_2997:
487         case VID_FMT_1080PSF_2997:
488                 duration = 30000;
489                 time_scale = 1001;
490                 break;
491
492         case VID_FMT_720P_3000:
493         case VID_FMT_1080P_3000:
494         case VID_FMT_2048_1080PSF_3000:
495         case VID_FMT_2048_1080P_3000:
496                 duration = 30000;
497                 time_scale = 1001;
498                 break;
499
500         case VID_FMT_720P_5000:
501         case VID_FMT_1080P_5000:
502         case VID_FMT_2048_1080P_5000:
503                 audio_cadence = { 960,960,960,960,960 };
504                 duration = 50000;
505                 time_scale = 1000;
506                 break;
507                 /*case VID_FMT_1080P_4800:
508                 case VID_FMT_2048_1080P_4800:
509                 fmt.duration = 48000;
510                 fmt.time_scale = 1000;
511                 break;*/
512         }
513         fmt = core::video_format_desc(video_format_from_vid_fmt(vid_fmt), width, height, width, height, video_field_mode, time_scale, duration, std::wstring(L""), audio_cadence);
514         fmt.size = size;
515         return fmt;
516 }
517
518 }}