#include #include #include #include #include #include #include #include #ifdef _WIN32 #include #define strncasecmp _strnicmp #ifdef _WIN64 #pragma comment(lib, "Processing.NDI.Lib.x64.lib") #else // _WIN64 #pragma comment(lib, "Processing.NDI.Lib.x86.lib") #endif // _WIN64 #else #include #endif #include static std::atomic exit_loop(false); static void sigint_handler(int) { exit_loop = true; } int main(int argc, char* argv[]) { // Not required, but "correct" (see the SDK documentation. if (!NDIlib_initialize()) { // Cannot run NDI. Most likely because the CPU is not sufficient (see SDK documentation). // you can check this directly with a call to NDIlib_is_supported_CPU() printf("Cannot run NDI."); return 0; } // Catch interrupt so that we can shut down gracefully signal(SIGINT, sigint_handler); // Create an NDI source that is called "My Video" and is clocked to the video. NDIlib_send_create_t NDI_send_create_desc; NDI_send_create_desc.p_ndi_name = "My Video"; // We create the NDI sender NDIlib_send_instance_t pNDI_send = NDIlib_send_create(&NDI_send_create_desc); if (!pNDI_send) return 0; // Provide a meta-data registration that allows people to know what we are. Note that this is optional. // Note that it is possible for senders to also register their preferred video formats. NDIlib_metadata_frame_t NDI_connection_type; NDI_connection_type.p_data = ""; NDIlib_send_add_connection_metadata(pNDI_send, &NDI_connection_type); // We are going to create a 1920x1080 interlaced frame at 59.94Hz. NDIlib_video_frame_v2_t NDI_video_frame; NDI_video_frame.xres = 1920; NDI_video_frame.yres = 1080; NDI_video_frame.FourCC = NDIlib_FourCC_type_BGRA; NDI_video_frame.p_data = (uint8_t*)malloc(NDI_video_frame.xres * NDI_video_frame.yres * 4); NDI_video_frame.line_stride_in_bytes = 1920 * 4; // We will send 1000 frames of video. for (int idx = 0; !exit_loop; idx++) { // We do not use any resources until we are actually connected. if (!NDIlib_send_get_no_connections(pNDI_send, 10000)) { // Display status printf("No current connections, so no rendering needed (%d).\n", idx); } else { // Have we received any meta-data NDIlib_metadata_frame_t metadata_desc; if (NDIlib_send_capture(pNDI_send, &metadata_desc, 0)) { // For example, this might be a connection meta-data string that might include information // about preferred video formats. A full XML parser should be used here, this code is for // illustration purposes only if (strncasecmp(metadata_desc.p_data, "