NDI SDK C++ sources project

510 Views Asked by At

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;
    }
}
0

There are 0 best solutions below