|
10 | 10 | #include "Misc.h" |
11 | 11 | #include "UniConversion.h" |
12 | 12 | #include "jsonxx.h" |
| 13 | +#include "Capture.h" |
13 | 14 |
|
14 | 15 | #ifdef WIN32 |
15 | 16 | #include <windows.h> |
16 | | -#ifdef BONZOMATIC_ENABLE_NDI |
17 | | -#include <Processing.NDI.Lib.h> |
18 | | -#endif |
19 | 17 | #endif |
20 | 18 |
|
21 | 19 | void ReplaceTokens( std::string &sDefShader, const char * sTokenBegin, const char * sTokenName, const char * sTokenEnd, std::vector<std::string> &tokens ) |
@@ -131,14 +129,6 @@ int main() |
131 | 129 | float fFFTSmoothingFactor = 0.9f; // higher value, smoother FFT |
132 | 130 | float fFFTSlightSmoothingFactor = 0.6f; // higher value, smoother FFT |
133 | 131 |
|
134 | | -#ifdef BONZOMATIC_ENABLE_NDI |
135 | | - std::string sNDIConnectionString; |
136 | | - float fNDIFrameRate = 60.0; |
137 | | - std::string sNDIIdentifier; |
138 | | - bool bNDIProgressive = true; |
139 | | - bool bNDIEnabled = true; |
140 | | -#endif // BONZOMATIC_ENABLE_NDI |
141 | | - |
142 | 132 | char szConfig[65535]; |
143 | 133 | FILE * fConf = fopen("config.json","rb"); |
144 | 134 | if (fConf) |
@@ -205,21 +195,12 @@ int main() |
205 | 195 | midiRoutes.insert( std::make_pair( it->second->number_value_, it->first ) ); |
206 | 196 | } |
207 | 197 | } |
208 | | -#ifdef BONZOMATIC_ENABLE_NDI |
209 | | - if (o.has<jsonxx::Object>("ndi")) |
210 | | - { |
211 | | - if (o.get<jsonxx::Object>("ndi").has<jsonxx::Boolean>("enabled")) |
212 | | - bNDIEnabled = o.get<jsonxx::Object>("ndi").get<jsonxx::Boolean>("enabled"); |
213 | | - if (o.get<jsonxx::Object>("ndi").has<jsonxx::String>("connectionString")) |
214 | | - sNDIConnectionString = o.get<jsonxx::Object>("ndi").get<jsonxx::String>("connectionString"); |
215 | | - if (o.get<jsonxx::Object>("ndi").has<jsonxx::String>("identifier")) |
216 | | - sNDIIdentifier = o.get<jsonxx::Object>("ndi").get<jsonxx::String>("identifier"); |
217 | | - if (o.get<jsonxx::Object>("ndi").has<jsonxx::Number>("frameRate")) |
218 | | - fNDIFrameRate = o.get<jsonxx::Object>("ndi").get<jsonxx::Number>("frameRate"); |
219 | | - if (o.get<jsonxx::Object>("ndi").has<jsonxx::Boolean>("progressive")) |
220 | | - bNDIProgressive = o.get<jsonxx::Object>("ndi").get<jsonxx::Boolean>("progressive"); |
221 | | - } |
222 | | -#endif // BONZOMATIC_ENABLE_NDI |
| 198 | + Capture::LoadSettings( o ); |
| 199 | + } |
| 200 | + if ( !Capture::Open( settings ) ) |
| 201 | + { |
| 202 | + printf("Initializing capture system failed!\n"); |
| 203 | + return 0; |
223 | 204 | } |
224 | 205 |
|
225 | 206 | Renderer::Texture * texFFT = Renderer::Create1DR32Texture( FFT_SIZE ); |
@@ -302,59 +283,6 @@ int main() |
302 | 283 | static float fftDataIntegrated[FFT_SIZE]; |
303 | 284 | memset(fftDataIntegrated, 0, sizeof(float) * FFT_SIZE); |
304 | 285 |
|
305 | | - // if we want to do some sort of frame capturing code |
306 | | - // (for e.g. sending frames through the network) |
307 | | - // we'd do it here, and then below. |
308 | | - |
309 | | -#ifdef BONZOMATIC_ENABLE_NDI |
310 | | - NDIlib_video_frame_t pNDIFrame; |
311 | | - NDIlib_send_instance_t pNDI_send; |
312 | | - unsigned int * pBuffer[2] = { NULL, NULL }; |
313 | | - unsigned int nBufferIndex = 0; |
314 | | - if (bNDIEnabled) |
315 | | - { |
316 | | - if (!NDIlib_initialize()) |
317 | | - { |
318 | | - printf("Cannot run NDI."); |
319 | | - return 0; |
320 | | - } |
321 | | - |
322 | | - NDIlib_send_create_t pNDICreateDesc; |
323 | | - sNDIIdentifier = "BONZOMATIC" + (sNDIIdentifier.length() ? (" - " + sNDIIdentifier) : ""); |
324 | | - pNDICreateDesc.p_ndi_name = sNDIIdentifier.c_str(); |
325 | | - pNDICreateDesc.p_groups = NULL; |
326 | | - pNDICreateDesc.clock_video = TRUE; |
327 | | - pNDICreateDesc.clock_audio = FALSE; |
328 | | - |
329 | | - pNDI_send = NDIlib_send_create(&pNDICreateDesc); |
330 | | - if (!pNDI_send) |
331 | | - { |
332 | | - printf("Cannot create NDI source"); |
333 | | - return 0; |
334 | | - } |
335 | | - |
336 | | - NDIlib_metadata_frame_t pNDIConnType; |
337 | | - pNDIConnType.length = sNDIConnectionString.length(); |
338 | | - pNDIConnType.timecode = NDIlib_send_timecode_synthesize; |
339 | | - pNDIConnType.p_data = (CHAR*)sNDIConnectionString.c_str(); |
340 | | - |
341 | | - NDIlib_send_add_connection_metadata(pNDI_send, &pNDIConnType); |
342 | | - |
343 | | - pNDIFrame.xres = settings.nWidth; |
344 | | - pNDIFrame.yres = settings.nHeight; |
345 | | - pNDIFrame.FourCC = NDIlib_FourCC_type_BGRA; |
346 | | - pNDIFrame.frame_rate_N = fNDIFrameRate * 100; |
347 | | - pNDIFrame.frame_rate_D = 100; |
348 | | - pNDIFrame.picture_aspect_ratio = settings.nWidth / (float)settings.nHeight; |
349 | | - pNDIFrame.frame_format_type = bNDIProgressive ? NDIlib_frame_format_type_progressive : NDIlib_frame_format_type_interleaved; |
350 | | - pNDIFrame.timecode = NDIlib_send_timecode_synthesize; |
351 | | - pBuffer[0] = new unsigned int[settings.nWidth * settings.nHeight * 4]; |
352 | | - pBuffer[1] = new unsigned int[settings.nWidth * settings.nHeight * 4]; |
353 | | - pNDIFrame.p_data = NULL; |
354 | | - pNDIFrame.line_stride_in_bytes = settings.nWidth * 4; |
355 | | - } |
356 | | -#endif // BONZOMATIC_ENABLE_NDI |
357 | | - |
358 | 286 | bool bShowGui = true; |
359 | 287 | Timer::Start(); |
360 | 288 | float fNextTick = 0.1; |
@@ -534,33 +462,9 @@ int main() |
534 | 462 |
|
535 | 463 | Renderer::EndFrame(); |
536 | 464 |
|
537 | | -#ifdef BONZOMATIC_ENABLE_NDI |
538 | | - if (pBuffer[0] && pBuffer[1]) |
539 | | - { |
540 | | - pNDIFrame.p_data = (BYTE*)pBuffer[ nBufferIndex ]; |
541 | | - nBufferIndex = (nBufferIndex + 1) & 1; |
542 | | - if (Renderer::GrabFrame( pNDIFrame.p_data )) |
543 | | - { |
544 | | - unsigned int * p = (unsigned int *)pNDIFrame.p_data; |
545 | | - for(int i=0; i < settings.nWidth * settings.nHeight; i++) |
546 | | - p[i] = (p[i] & 0x00FF00) | ((p[i] >> 16) & 0xFF) | ((p[i] & 0xFF) << 16) | 0xFF000000; |
547 | | - NDIlib_send_send_video_async(pNDI_send, &pNDIFrame); |
548 | | - } |
549 | | - } |
550 | | -#endif // BONZOMATIC_ENABLE_NDI |
| 465 | + Capture::CaptureFrame(); |
551 | 466 | } |
552 | 467 |
|
553 | | -#ifdef BONZOMATIC_ENABLE_NDI |
554 | | - if (pBuffer[0] && pBuffer[1]) |
555 | | - { |
556 | | - NDIlib_send_send_video_async(pNDI_send, NULL); // stop async thread |
557 | | - |
558 | | - delete[] pBuffer[0]; |
559 | | - delete[] pBuffer[1]; |
560 | | - NDIlib_send_destroy(pNDI_send); |
561 | | - NDIlib_destroy(); |
562 | | - } |
563 | | -#endif // BONZOMATIC_ENABLE_NDI |
564 | 468 |
|
565 | 469 | delete surface; |
566 | 470 |
|
|
0 commit comments