Commit e150afed authored by Gargaj's avatar Gargaj
Browse files

Merge branch 'ndi'

# Conflicts:
#	CMakeLists.txt
#	src/main.cpp
parents 8a13f47a fddfc655
......@@ -40,9 +40,9 @@ if (MSVC)
#set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /VERBOSE")
#set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /VERBOSE")
if (BONZOMATIC_64BIT)
link_directories($ENV{DXSDK_DIR}/lib/x64)
set(BZC_LINK_DIRS ${BZC_LINK_DIRS} $ENV{DXSDK_DIR}/lib/x64)
else ()
link_directories($ENV{DXSDK_DIR}/lib/x86)
set(BZC_LINK_DIRS ${BZC_LINK_DIRS} $ENV{DXSDK_DIR}/lib/x86)
endif ()
endif ()
......@@ -125,6 +125,17 @@ endif ()
set(BZC_PROJECT_INCLUDES ${BZC_PROJECT_INCLUDES} ${CMAKE_SOURCE_DIR}/external/jsonxx)
set(BZC_PROJECT_LIBS ${BZC_PROJECT_LIBS} bzc_jsonxx)
##############################################################################
# NDI
if (MSVC)
set(BZC_PROJECT_INCLUDES ${BZC_PROJECT_INCLUDES} "c:/Program Files/NewTek/NewTek NDI SDK/Include/")
if (BONZOMATIC_64BIT)
set(BZC_LINK_DIRS ${BZC_LINK_DIRS} "c:/Program Files/NewTek/NewTek NDI SDK/Lib/x64/")
else ()
set(BZC_LINK_DIRS ${BZC_LINK_DIRS} "c:/Program Files/NewTek/NewTek NDI SDK/Lib/x86/")
endif ()
endif ()
##############################################################################
# SCINTILLA
set(SCINTILLA_SRCS
......@@ -404,6 +415,7 @@ set(BZC_PROJECT_LIBS ${BZC_PROJECT_LIBS} ${PLATFORM_LIBS})
##############################################################################
# create the executable
link_directories(${BZC_LINK_DIRS})
add_executable(${BZC_EXE_NAME} ${BZC_PROJECT_SRCS})
if (APPLE AND GLFW_USE_RETINA)
# Add special plist to enable Retina display support
......@@ -429,5 +441,10 @@ if (MSVC)
elseif ()
add_custom_command(TARGET ${BZC_EXE_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/external/bass/x86/bass.dll" $<TARGET_FILE_DIR:${BZC_EXE_NAME}>)
endif ()
if (BONZOMATIC_64BIT)
add_custom_command(TARGET ${BZC_EXE_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "c:/Program Files/NewTek/NewTek NDI SDK/Bin/x64/Processing.NDI.Lib.x64.dll" $<TARGET_FILE_DIR:${BZC_EXE_NAME}>)
elseif ()
add_custom_command(TARGET ${BZC_EXE_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "c:/Program Files/NewTek/NewTek NDI SDK/Bin/x86/Processing.NDI.Lib.x86.dll" $<TARGET_FILE_DIR:${BZC_EXE_NAME}>)
endif ()
endif ()
......@@ -11,6 +11,11 @@
#include "UniConversion.h"
#include "jsonxx.h"
#ifdef WIN32
#include <windows.h>
#include <Processing.NDI.Lib.h>
#endif
void ReplaceTokens( std::string &sDefShader, const char * sTokenBegin, const char * sTokenName, const char * sTokenEnd, std::vector<std::string> &tokens )
{
if (sDefShader.find(sTokenBegin) != std::string::npos
......@@ -124,6 +129,12 @@ int main()
float fFFTSmoothingFactor = 0.9f; // higher value, smoother FFT
float fFFTSlightSmoothingFactor = 0.6f; // higher value, smoother FFT
std::string sNDIConnectionString;
float fNDIFrameRate = 60.0;
std::string sNDIIdentifier;
bool bNDIProgressive = true;
bool bNDIEnabled = true;
char szConfig[65535];
FILE * fConf = fopen("config.json","rb");
if (fConf)
......@@ -190,6 +201,19 @@ int main()
midiRoutes.insert( std::make_pair( it->second->number_value_, it->first ) );
}
}
if (o.has<jsonxx::Object>("ndi"))
{
if (o.get<jsonxx::Object>("ndi").has<jsonxx::Boolean>("enabled"))
bNDIEnabled = o.get<jsonxx::Object>("ndi").get<jsonxx::Boolean>("enabled");
if (o.get<jsonxx::Object>("ndi").has<jsonxx::String>("connectionString"))
sNDIConnectionString = o.get<jsonxx::Object>("ndi").get<jsonxx::String>("connectionString");
if (o.get<jsonxx::Object>("ndi").has<jsonxx::String>("identifier"))
sNDIIdentifier = o.get<jsonxx::Object>("ndi").get<jsonxx::String>("identifier");
if (o.get<jsonxx::Object>("ndi").has<jsonxx::Number>("frameRate"))
fNDIFrameRate = o.get<jsonxx::Object>("ndi").get<jsonxx::Number>("frameRate");
if (o.get<jsonxx::Object>("ndi").has<jsonxx::Boolean>("progressive"))
bNDIProgressive = o.get<jsonxx::Object>("ndi").get<jsonxx::Boolean>("progressive");
}
}
Renderer::Texture * texFFT = Renderer::Create1DR32Texture( FFT_SIZE );
......@@ -266,15 +290,64 @@ int main()
static float fftDataSmoothed[FFT_SIZE];
memset(fftDataSmoothed, 0, sizeof(float) * FFT_SIZE);
static float fftDataSlightlySmoothed[FFT_SIZE];
memset(fftDataSlightlySmoothed, 0, sizeof(float) * FFT_SIZE);
static float fftDataIntegrated[FFT_SIZE];
memset(fftDataIntegrated, 0, sizeof(float) * FFT_SIZE);
// if we want to do some sort of frame capturing code
// if we want to do some sort of frame capturing code
// (for e.g. sending frames through the network)
// we'd do it here, and then below.
unsigned int * pFrameContents = NULL;// new unsigned int[ settings.nWidth * settings.nHeight ];
NDIlib_video_frame_t pNDIFrame;
NDIlib_send_instance_t pNDI_send;
unsigned int * pBuffer[2] = { NULL, NULL };
unsigned int nBufferIndex = 0;
if (bNDIEnabled)
{
if (!NDIlib_initialize())
{
printf("Cannot run NDI.");
return 0;
}
NDIlib_send_create_t pNDICreateDesc;
sNDIIdentifier = "BONZOMATIC" + (sNDIIdentifier.length() ? (" - " + sNDIIdentifier) : "");
pNDICreateDesc.p_ndi_name = sNDIIdentifier.c_str();
pNDICreateDesc.p_groups = NULL;
pNDICreateDesc.clock_video = TRUE;
pNDICreateDesc.clock_audio = FALSE;
pNDI_send = NDIlib_send_create(&pNDICreateDesc);
if (!pNDI_send)
{
printf("Cannot create NDI source");
return 0;
}
NDIlib_metadata_frame_t pNDIConnType;
pNDIConnType.length = sNDIConnectionString.length();
pNDIConnType.timecode = NDIlib_send_timecode_synthesize;
pNDIConnType.p_data = (CHAR*)sNDIConnectionString.c_str();
NDIlib_send_add_connection_metadata(pNDI_send, &pNDIConnType);
pNDIFrame.xres = settings.nWidth;
pNDIFrame.yres = settings.nHeight;
pNDIFrame.FourCC = NDIlib_FourCC_type_BGRA;
pNDIFrame.frame_rate_N = fNDIFrameRate * 100;
pNDIFrame.frame_rate_D = 100;
pNDIFrame.picture_aspect_ratio = settings.nWidth / (float)settings.nHeight;
pNDIFrame.frame_format_type = bNDIProgressive ? NDIlib_frame_format_type_progressive : NDIlib_frame_format_type_interleaved;
pNDIFrame.timecode = NDIlib_send_timecode_synthesize;
pBuffer[0] = new unsigned int[settings.nWidth * settings.nHeight * 4];
pBuffer[1] = new unsigned int[settings.nWidth * settings.nHeight * 4];
pNDIFrame.p_data = NULL;
pNDIFrame.line_stride_in_bytes = settings.nWidth * 4;
}
bool bShowGui = true;
Timer::Start();
......@@ -455,17 +528,29 @@ int main()
Renderer::EndFrame();
if (pFrameContents)
if (pBuffer[0] && pBuffer[1])
{
if (Renderer::GrabFrame( pFrameContents ))
pNDIFrame.p_data = (BYTE*)pBuffer[ nBufferIndex ];
nBufferIndex = (nBufferIndex + 1) & 1;
if (Renderer::GrabFrame( pNDIFrame.p_data ))
{
// send framebuffer through network here.
unsigned int * p = (unsigned int *)pNDIFrame.p_data;
for(int i=0; i < settings.nWidth * settings.nHeight; i++)
p[i] = (p[i] & 0x00FF00) | ((p[i] >> 16) & 0xFF) | ((p[i] & 0xFF) << 16) | 0xFF000000;
NDIlib_send_send_video_async(pNDI_send, &pNDIFrame);
}
}
}
if (pFrameContents)
delete[] pFrameContents;
if (pBuffer[0] && pBuffer[1])
{
NDIlib_send_send_video_async(pNDI_send, NULL); // stop async thread
delete[] pBuffer[0];
delete[] pBuffer[1];
NDIlib_send_destroy(pNDI_send);
NDIlib_destroy();
}
delete surface;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment