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