]> git.sesse.net Git - casparcg/blob - modules/bluefish/util/blue_velvet.cpp
86b6178e64c9c033520f4435fc6d35e6c6b5dbec
[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                 bvc_ = nullptr;
44                 h_module_ = nullptr;
45                 init_function_pointers();
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                 if (bvc_)
154                         return (BLUE_UINT32)bfcQueryCardProperty32((BLUEVELVETC_HANDLE)bvc_.get(), iProperty, nValue);
155                 else
156                         return 0;
157         }
158
159         BLUE_UINT32 bvc_wrapper::set_card_property32(const int iProperty, const unsigned int nValue)
160         {
161                 return bfcSetCardProperty32((BLUEVELVETC_HANDLE)bvc_.get(), iProperty, nValue);
162         }
163
164         BLUE_UINT32 bvc_wrapper::enumerate(int & iDevices)
165         {
166                 return bfcEnumerate((BLUEVELVETC_HANDLE)bvc_.get(), iDevices);
167         }
168
169         BLUE_UINT32 bvc_wrapper::query_card_type(int & iCardType, int iDeviceID)
170         {
171                 return bfcQueryCardType((BLUEVELVETC_HANDLE)bvc_.get(), iCardType, iDeviceID);
172         }
173
174         BLUE_UINT32 bvc_wrapper::system_buffer_write(unsigned char * pPixels, unsigned long ulSize, unsigned long ulBufferID, unsigned long ulOffset)
175         {
176                 return bfcSystemBufferWriteAsync((BLUEVELVETC_HANDLE)bvc_.get(), pPixels, ulSize, nullptr, ulBufferID, ulOffset);
177         }
178
179         BLUE_UINT32 bvc_wrapper::system_buffer_read(unsigned char* pPixels, unsigned long ulSize, unsigned long ulBufferID, unsigned long ulOffset)
180         {
181                 return bfcSystemBufferReadAsync((BLUEVELVETC_HANDLE)bvc_.get(), pPixels, ulSize, nullptr, ulBufferID, ulOffset);
182         }
183
184         BLUE_UINT32 bvc_wrapper::video_playback_stop(int iWait, int iFlush)
185         {
186                 return bfcVideoPlaybackStop((BLUEVELVETC_HANDLE)bvc_.get(), iWait, iFlush);
187         }
188
189         BLUE_UINT32 bvc_wrapper::wait_video_output_sync(unsigned long ulUpdateType, unsigned long & ulFieldCount)
190         {
191                 return bfcWaitVideoOutputSync((BLUEVELVETC_HANDLE)bvc_.get(), ulUpdateType, ulFieldCount);
192         }
193
194         BLUE_UINT32 bvc_wrapper::wait_video_input_sync(unsigned long ulUpdateType, unsigned long & ulFieldCount)
195         {
196                 return bfcWaitVideoInputSync((BLUEVELVETC_HANDLE)bvc_.get(), ulUpdateType, ulFieldCount);
197         }
198
199         BLUE_UINT32 bvc_wrapper::render_buffer_update( unsigned long ulBufferID)
200         {
201                 return bfcRenderBufferUpdate((BLUEVELVETC_HANDLE)bvc_.get(), ulBufferID);
202         }
203
204         BLUE_UINT32 bvc_wrapper::render_buffer_capture(unsigned long ulBufferID)
205         {
206                 return bfcRenderBufferCapture((BLUEVELVETC_HANDLE)bvc_.get(), ulBufferID);
207         }
208
209         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)
210         {
211                 return bfcEncodeHancFrameEx((BLUEVELVETC_HANDLE)bvc_.get(), CRD_BLUE_NEUTRON, pHancEncodeInfo, pAudioBuffer, nAudioChannels, nAudioSamples, nSampleType, nAudioFlags);
212         }
213
214         BLUE_UINT32 bvc_wrapper::decode_hanc_frame(unsigned int nCardType, unsigned int * pHancBuffer, hanc_decode_struct * pHancDecodeInfo)
215         {
216                 return bfcDecodeHancFrameEx((BLUEVELVETC_HANDLE)bvc_.get(), CRD_BLUE_NEUTRON, pHancBuffer, pHancDecodeInfo);
217         }
218
219         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)
220         {
221                 return bfcUtilsGetFrameInfoForVideoMode(nVideoMode, nWidth, nHeight, nRate, bIs1001, bIsProgressive);
222         }
223
224         BLUE_UINT32 bvc_wrapper::get_bytes_per_frame(EVideoMode nVideoMode, EMemoryFormat nMemoryFormat, EUpdateMethod nUpdateMethod, unsigned int& nBytesPerFrame)
225         {
226                 return bfcGetBytesPerFrame(nVideoMode, nMemoryFormat, nUpdateMethod, nBytesPerFrame);
227         }
228
229
230 EVideoMode vid_fmt_from_video_format(const core::video_format& fmt) 
231 {
232         switch(fmt)
233         {
234         case core::video_format::pal:                   return VID_FMT_PAL;
235         case core::video_format::ntsc:                  return VID_FMT_NTSC;
236         case core::video_format::x576p2500:             return VID_FMT_INVALID; //not supported
237         case core::video_format::x720p2398:             return VID_FMT_720P_2398;
238         case core::video_format::x720p2400:             return VID_FMT_720P_2400;
239         case core::video_format::x720p2500:             return VID_FMT_720P_2500;
240         case core::video_format::x720p5000:             return VID_FMT_720P_5000;
241         case core::video_format::x720p2997:             return VID_FMT_720P_2997;
242         case core::video_format::x720p5994:             return VID_FMT_720P_5994;
243         case core::video_format::x720p3000:             return VID_FMT_720P_3000;
244         case core::video_format::x720p6000:             return VID_FMT_720P_6000;
245         case core::video_format::x1080p2398:    return VID_FMT_1080P_2397;
246         case core::video_format::x1080p2400:    return VID_FMT_1080P_2400;
247         case core::video_format::x1080i5000:    return VID_FMT_1080I_5000;
248         case core::video_format::x1080i5994:    return VID_FMT_1080I_5994;
249         case core::video_format::x1080i6000:    return VID_FMT_1080I_6000;
250         case core::video_format::x1080p2500:    return VID_FMT_1080P_2500;
251         case core::video_format::x1080p2997:    return VID_FMT_1080P_2997;
252         case core::video_format::x1080p3000:    return VID_FMT_1080P_3000;
253         case core::video_format::x1080p5000:    return VID_FMT_1080P_5000;
254         case core::video_format::x1080p5994:    return VID_FMT_1080P_5994;
255         case core::video_format::x1080p6000:    return VID_FMT_1080P_6000;
256         default:                                                                return VID_FMT_INVALID;
257         }
258 }
259
260 bool is_epoch_card(bvc_wrapper& blue)
261 {
262         int device_id = 1;
263         int card_type = 0;
264         blue.query_card_type(card_type, device_id);
265
266         switch(card_type)
267         {
268                 case CRD_BLUE_EPOCH_HORIZON:
269                 case CRD_BLUE_EPOCH_CORE:
270                 case CRD_BLUE_EPOCH_ULTRA:
271                 case CRD_BLUE_EPOCH_2K_HORIZON:
272                 case CRD_BLUE_EPOCH_2K_CORE:
273                 case CRD_BLUE_EPOCH_2K_ULTRA:
274                 case CRD_BLUE_CREATE_HD:
275                 case CRD_BLUE_CREATE_2K:
276                 case CRD_BLUE_CREATE_2K_ULTRA:
277                 case CRD_BLUE_SUPER_NOVA:
278                 case CRD_BLUE_SUPER_NOVA_S_PLUS:
279                 case CRD_BLUE_NEUTRON:
280                 case CRD_BLUE_EPOCH_CG:
281                 return true;
282         default:
283                 return false;
284         }
285 }
286
287 bool is_epoch_neutron_1i2o_card(bvc_wrapper& blue)
288 {
289         BLUE_UINT32 val = 0;
290         blue.get_card_property32(EPOCH_GET_PRODUCT_ID, val);
291         if (val == ORAC_NEUTRON_1_IN_2_OUT_FIRMWARE_PRODUCTID)
292                 return true;
293         else
294                 return false;
295 }
296
297 bool is_epoch_neutron_3o_card(bvc_wrapper& blue)
298 {
299         BLUE_UINT32 val = 0;
300         blue.get_card_property32(EPOCH_GET_PRODUCT_ID, val);
301
302         if (val == ORAC_NEUTRON_0_IN_3_OUT_FIRMWARE_PRODUCTID)
303                 return true;
304         else
305                 return false;
306 }
307
308 std::wstring get_card_desc(bvc_wrapper& blue, int device_id)
309 {
310         int card_type = 0;
311         blue.query_card_type(card_type, device_id);
312
313         switch(card_type)
314         {
315                 case CRD_BLUEDEEP_LT:                           return L"Deepblue LT";// D64 Lite
316                 case CRD_BLUEDEEP_SD:                           return L"Iridium SD";// Iridium SD
317                 case CRD_BLUEDEEP_AV:                           return L"Iridium AV";// Iridium AV
318                 case CRD_BLUEDEEP_IO:                           return L"Deepblue IO";// D64 Full
319                 case CRD_BLUEWILD_AV:                           return L"Wildblue AV";// D64 AV
320                 case CRD_IRIDIUM_HD:                            return L"Iridium HD";// * Iridium HD
321                 case CRD_BLUEWILD_RT:                           return L"Wildblue RT";// D64 RT
322                 case CRD_BLUEWILD_HD:                           return L"Wildblue HD";// * BadAss G2
323                 case CRD_REDDEVIL:                                      return L"Iridium Full";// Iridium Full
324                 case CRD_BLUEDEEP_HD:   
325                 case CRD_BLUEDEEP_HDS:                          return L"Reserved for \"BasAss G2";// * BadAss G2 variant, proposed, reserved
326                 case CRD_BLUE_ENVY:                                     return L"Blue Envy"; // Mini Din 
327                 case CRD_BLUE_PRIDE:                            return L"Blue Pride";//Mini Din Output 
328                 case CRD_BLUE_GREED:                            return L"Blue Greed";
329                 case CRD_BLUE_INGEST:                           return L"Blue Ingest";
330                 case CRD_BLUE_SD_DUALLINK:                      return L"Blue SD Duallink";
331                 case CRD_BLUE_CATALYST:                         return L"Blue Catalyst";
332                 case CRD_BLUE_SD_DUALLINK_PRO:          return L"Blue SD Duallink Pro";
333                 case CRD_BLUE_SD_INGEST_PRO:            return L"Blue SD Ingest pro";
334                 case CRD_BLUE_SD_DEEPBLUE_LITE_PRO:     return L"Blue SD Deepblue lite Pro";
335                 case CRD_BLUE_SD_SINGLELINK_PRO:        return L"Blue SD Singlelink Pro";
336                 case CRD_BLUE_SD_IRIDIUM_AV_PRO:        return L"Blue SD Iridium AV Pro";
337                 case CRD_BLUE_SD_FIDELITY:                      return L"Blue SD Fidelity";
338                 case CRD_BLUE_SD_FOCUS:                         return L"Blue SD Focus";
339                 case CRD_BLUE_SD_PRIME:                         return L"Blue SD Prime";
340                 case CRD_BLUE_EPOCH_2K_CORE:            return L"Blue Epoch 2K Core";
341                 case CRD_BLUE_EPOCH_2K_ULTRA:           return L"Blue Epoch 2K Ultra";
342                 case CRD_BLUE_EPOCH_HORIZON:            return L"Blue Epoch Horizon";
343                 case CRD_BLUE_EPOCH_CORE:                       return L"Blue Epoch Core";
344                 case CRD_BLUE_EPOCH_ULTRA:                      return L"Blue Epoch Ultra";
345                 case CRD_BLUE_CREATE_HD:                        return L"Blue Create HD";
346                 case CRD_BLUE_CREATE_2K:                        return L"Blue Create 2K";
347                 case CRD_BLUE_CREATE_2K_ULTRA:          return L"Blue Create 2K Ultra";
348                 case CRD_BLUE_SUPER_NOVA:                       return L"Blue SuperNova";
349                 case CRD_BLUE_SUPER_NOVA_S_PLUS:        return L"Blue SuperNova s+";
350                 case CRD_BLUE_NEUTRON:                          return L"Blue Neutron 4k";
351                 case CRD_BLUE_EPOCH_CG:                         return L"Blue Epopch CG";
352                 default:                                                        return L"Unknown";
353         }
354 }
355
356 EVideoMode get_video_mode(bvc_wrapper& blue, const core::video_format_desc& format_desc)
357 {
358         EVideoMode vid_fmt = VID_FMT_INVALID;
359         BLUE_UINT32 invalid_fmt = 0;
360         BErr err = 0;
361         err = blue.get_card_property32(INVALID_VIDEO_MODE_FLAG, invalid_fmt);
362         vid_fmt = vid_fmt_from_video_format(format_desc.format);
363
364         if (vid_fmt == VID_FMT_INVALID)
365                 CASPAR_THROW_EXCEPTION(not_supported() << msg_info(L"video-mode not supported: " + format_desc.name));
366
367
368         if ((unsigned int)vid_fmt >= invalid_fmt)
369                 CASPAR_THROW_EXCEPTION(not_supported() << msg_info(L"video-mode not supported - Outside of valid range: " + format_desc.name));
370
371         return vid_fmt;
372 }
373
374 spl::shared_ptr<bvc_wrapper> create_blue()
375 {
376         auto pWrap = new bvc_wrapper();
377         return spl::shared_ptr<bvc_wrapper>(pWrap);
378 }
379
380 spl::shared_ptr<bvc_wrapper> create_blue(int device_index)
381 {
382         auto blue = create_blue();
383         
384         if(BLUE_FAIL(blue->attach(device_index)))
385                 CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to attach device."));
386
387         return blue;
388 }
389
390 core::video_format video_format_from_vid_fmt(EVideoMode fmt)
391 {
392         switch (fmt)
393         {
394         case VID_FMT_PAL: return core::video_format::pal;
395         case VID_FMT_NTSC: return core::video_format::ntsc;
396         case VID_FMT_720P_2398: return core::video_format::x720p2398;
397         case VID_FMT_720P_2400: return core::video_format::x720p2400;
398         case VID_FMT_720P_2500: return core::video_format::x720p2500;
399         case VID_FMT_720P_5000: return core::video_format::x720p5000;
400         case VID_FMT_720P_2997: return core::video_format::x720p2997;
401         case VID_FMT_720P_5994: return core::video_format::x720p5994;
402         case VID_FMT_720P_3000: return core::video_format::x720p3000;
403         case VID_FMT_720P_6000: return core::video_format::x720p6000;
404         case VID_FMT_1080P_2397: return core::video_format::x1080p2398;
405         case VID_FMT_1080P_2400: return core::video_format::x1080p2400;
406         case VID_FMT_1080I_5000: return core::video_format::x1080i5000;
407         case VID_FMT_1080I_5994: return core::video_format::x1080i5994;
408         case VID_FMT_1080I_6000: return core::video_format::x1080i6000;
409         case VID_FMT_1080P_2500: return core::video_format::x1080p2500;
410         case VID_FMT_1080P_2997: return core::video_format::x1080p2997;
411         case VID_FMT_1080P_3000: return core::video_format::x1080p3000;
412         case VID_FMT_1080P_5000: return core::video_format::x1080p5000;
413         case VID_FMT_1080P_5994: return core::video_format::x1080p5994;
414         case VID_FMT_1080P_6000: return core::video_format::x1080p6000;
415         default: return core::video_format::invalid;
416         }
417 }
418
419 core::video_format_desc get_format_desc(bvc_wrapper& blue, EVideoMode vid_fmt, EMemoryFormat mem_fmt)
420 {
421         core::video_format_desc fmt;
422         unsigned int width, height, duration = 0, time_scale = 0, rate = 0, bIs1001 = 0, bIsProgressive = 0, size = 0;
423         std::vector<int>        audio_cadence;
424         core::field_mode video_field_mode = core::field_mode::progressive;
425
426         blue.get_frame_info_for_video_mode(vid_fmt, width, height, rate, bIs1001, bIsProgressive);
427         blue.get_bytes_per_frame(vid_fmt, mem_fmt, UPD_FMT_FRAME, size);
428
429         switch (vid_fmt)
430         {
431         case VID_FMT_NTSC:
432         case VID_FMT_1080I_5994:
433                 duration = 30000;
434                 time_scale = 1001;
435                 audio_cadence = { 1601,1602,1601,1602,1602 };
436                 video_field_mode = core::field_mode::upper;
437                 break;
438         case VID_FMT_2048_1080P_2500:
439         case VID_FMT_2048_1080PSF_2500:
440         case VID_FMT_576I_5000:
441         case VID_FMT_1080P_2500:
442         case VID_FMT_1080I_5000:
443         case VID_FMT_1080PSF_2500:
444         case VID_FMT_720P_2500:
445                 duration = 25000;
446                 time_scale = 1000;
447                 audio_cadence = { 1920,1920,1920,1920,1920 };
448                 break;
449
450         case VID_FMT_720P_5994:
451         case VID_FMT_2048_1080P_5994:
452         case VID_FMT_1080P_5994:
453                 duration = 60000;
454                 time_scale = 1001;
455                 audio_cadence = { 801,800,801,800,800 };
456                 break;
457
458         case VID_FMT_1080P_6000:
459         case VID_FMT_2048_1080P_6000:
460         case VID_FMT_720P_6000:
461                 duration = 60000;
462                 time_scale = 1000;
463                 audio_cadence = { 801,800,801,800,800 };
464                 break;
465
466         case VID_FMT_1080PSF_2397:
467         case VID_FMT_1080P_2397:
468         case VID_FMT_720P_2398:
469         case VID_FMT_2048_1080PSF_2397:
470         case VID_FMT_2048_1080P_2397:
471                 duration = 24000;
472                 time_scale = 1000;
473                 break;
474
475         case VID_FMT_1080PSF_2400:
476         case VID_FMT_1080P_2400:
477         case VID_FMT_720P_2400:
478         case VID_FMT_2048_1080PSF_2400:
479         case VID_FMT_2048_1080P_2400:
480                 duration = 24000;
481                 time_scale = 1000;
482                 break;
483
484         case VID_FMT_1080I_6000:
485         case VID_FMT_1080PSF_3000:
486                 duration = 30000;
487                 time_scale = 1000;
488                 break;
489
490         case VID_FMT_720P_2997:
491         case VID_FMT_1080P_2997:
492         case VID_FMT_2048_1080PSF_2997:
493         case VID_FMT_2048_1080P_2997:
494         case VID_FMT_1080PSF_2997:
495                 duration = 30000;
496                 time_scale = 1001;
497                 break;
498
499         case VID_FMT_720P_3000:
500         case VID_FMT_1080P_3000:
501         case VID_FMT_2048_1080PSF_3000:
502         case VID_FMT_2048_1080P_3000:
503                 duration = 30000;
504                 time_scale = 1001;
505                 break;
506
507         case VID_FMT_720P_5000:
508         case VID_FMT_1080P_5000:
509         case VID_FMT_2048_1080P_5000:
510                 audio_cadence = { 960,960,960,960,960 };
511                 duration = 50000;
512                 time_scale = 1000;
513                 break;
514                 /*case VID_FMT_1080P_4800:
515                 case VID_FMT_2048_1080P_4800:
516                 fmt.duration = 48000;
517                 fmt.time_scale = 1000;
518                 break;*/
519         }
520         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);
521         fmt.size = size;
522         return fmt;
523 }
524
525 }}