1

I'm currently trying to make a application that will take one ndi video source channel, and one audio source channel and eventually combine it into one as its own stream, but as of right now my program isn't even recognized by the NDI Analysis tool, and I'm unsure what to do. What I'm hoping for at least for now is for my program to register the running sources and allow me to select one sour for video and one for audio.

#include <iostream>
#include "Processing.NDI.Lib.h"
int main() {
 // Initialize the NDI library
 NDIlib_initialize();
 // Find all available sources on the local network
 const NDIlib_find_create_t NDI_find_create_desc = { true, nullptr };
 NDIlib_find_instance_t pNDI_find = NDIlib_find_create_v2(&NDI_find_create_desc);
 if (!pNDI_find) {
 std::cerr << "Failed to create NDI find instance\n";
 return -1;
 }
 std::cout << "Searching for NDI sources...\n";
 uint32_t num_sources = 0;
 const NDIlib_source_t* pSources = nullptr;
 NDIlib_find_wait_for_sources(pNDI_find, 1000 /* timeout_ms */);
 pSources = NDIlib_find_get_current_sources(pNDI_find, &num_sources);
 if (num_sources == 0) {
 std::cout << "No NDI sources found\n";
 return 0;
 }
 // Print out the available sources`your text`
 std::cout << "Available NDI sources:\n";
 for (uint32_t i = 0; i < num_sources; ++i) {
 const NDIlib_source_t* pSource = &pSources[i];
 if (pSource->p_ndi_name && pSource->p_url_address && pSource->fourcc_type == NDIlib_fourCC_type_video) { //unable to find version 5.5 names 
 std::cout << i << ": " << pSource->p_ndi_name << " (" << pSource->p_url_address << ")\n";
 }
 }
 // Prompt the user to select an audio and video source
 uint32_t video_source_idx = 0;
 uint32_t audio_source_idx = 0;
 std::cout << "Enter the index of the video source you want to use: ";
 std::cin >> video_source_idx;
 std::cout << "Enter the index of the audio source you want to use: ";
 std::cin >> audio_source_idx;
 // Create an NDI source that combines the selected audio and video sources
 const NDIlib_send_create_t NDI_send_create_desc = {
 "Combined Source", // Name of the NDI source
 nullptr, // Groups (optional)
 true, // Clock video (required for synchronization)
 true // Clock audio (required for synchronization)
 };
 NDIlib_send_instance_t pNDI_send = NDIlib_send_create(&NDI_send_create_desc);
 if (!pNDI_send) {
 std::cerr << "Failed to create NDI send instance\n";
 return -1;
 }
 // Connect to the selected video and audio sources
 const NDIlib_routing_create_t NDI_routing_create_desc = {
 nullptr, // Groups (optional)
 1 // Number of inputs to create
 };
 NDIlib_routing_instance_t pNDI_routing = NDIlib_routing_create_v3(&NDI_routing_create_desc);
 if (!pNDI_routing) {
 std::cerr << "Failed to create NDI routing instance\n";
 return -1;
 }
 const NDIlib_source_t* pVideoSource = &pSources[video_source_idx];
 if (NDIlib_routing_change_v3(pNDI_routing, &pVideoSource->source_id, nullptr, NDIlib_routing_preference_best_quality) != NDIlib_frame_type_none) {
 std::cout << "Connected\n";
 return 0;
 }
}
Burak
2,5911 gold badge23 silver badges37 bronze badges
asked Mar 28, 2023 at 20:41

1 Answer 1

0

Here's how the official Finder example is implemented in the C++ examples that come with the NDI SDK:

#include <cstdio>
#include <chrono>
#include <Processing.NDI.Lib.h>
#ifdef _WIN32
#ifdef _WIN64
#pragma comment(lib, "Processing.NDI.Lib.x64.lib")
#else // _WIN64
#pragma comment(lib, "Processing.NDI.Lib.x86.lib")
#endif // _WIN64
#endif // _WIN32
int main(int argc, char* argv[])
{
 // Not required, but "correct" (see the SDK documentation).
 if (!NDIlib_initialize())
 return 0;
 // We are going to create an NDI finder that locates sources on the network. 
 NDIlib_find_instance_t pNDI_find = NDIlib_find_create_v2();
 if (!pNDI_find)
 return 0;
 // Run for one minute
 using namespace std::chrono;
 for (const auto start = high_resolution_clock::now(); high_resolution_clock::now() - start < minutes(1);) {
 // Wait up till 5 seconds to check for new sources to be added or removed
 if (!NDIlib_find_wait_for_sources(pNDI_find, 5000 /* milliseconds */)) {
 printf("No change to the sources found.\n");
 continue;
 }
 // Get the updated list of sources
 uint32_t no_sources = 0;
 const NDIlib_source_t* p_sources = NDIlib_find_get_current_sources(pNDI_find, &no_sources);
 // Display all the sources.
 printf("Network sources (%u found).\n", no_sources);
 for (uint32_t i = 0; i < no_sources; i++)
 printf("%u. %s\n", i + 1, p_sources[i].p_ndi_name);
 }
 // Destroy the NDI finder
 NDIlib_find_destroy(pNDI_find);
 // Finished
 NDIlib_destroy();
 // Success. We are done
 return 0;
answered Sep 19, 2024 at 18:08
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.