looks like i forgot about commits
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <Processing.NDI.Lib.h>
|
||||
|
||||
namespace dmf {
|
||||
class NDIHelper {
|
||||
public:
|
||||
NDIHelper() {
|
||||
if (!NDIlib_initialize()) {
|
||||
throw std::runtime_error("NDI lib init failed");
|
||||
if (!NDIlib_is_supported_CPU()) {
|
||||
throw std::runtime_error("CPU is not sufficient for NDI");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~NDIHelper() {
|
||||
NDIlib_destroy();
|
||||
NDIlib_recv_destroy(pNDI_recv);
|
||||
}
|
||||
|
||||
void find_sources(std::vector<std::string>* sources, u_int32_t timeout_ms) {
|
||||
pNDI_find = NDIlib_find_create_v2();
|
||||
if (!pNDI_find) {
|
||||
throw std::runtime_error("Cannot create NDI finder");
|
||||
}
|
||||
|
||||
while (!sources_amount) {
|
||||
NDIlib_find_wait_for_sources(pNDI_find, timeout_ms);
|
||||
p_sources = NDIlib_find_get_current_sources(pNDI_find, &sources_amount);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sources_amount; ++i){
|
||||
sources->push_back(p_sources[i].p_ndi_name);
|
||||
}
|
||||
NDIlib_find_destroy(pNDI_find);
|
||||
}
|
||||
|
||||
void select_source(uint32_t source_num) {
|
||||
if (sources_amount == 0) {
|
||||
throw std::runtime_error("0 sources found");
|
||||
} else if (source_num > sources_amount) {
|
||||
throw std::runtime_error("Source_num bigger that sources amount");
|
||||
}
|
||||
|
||||
pNDI_recv = NDIlib_recv_create_v3();
|
||||
if (!pNDI_recv) {
|
||||
NDIlib_recv_destroy(pNDI_recv);
|
||||
throw std::runtime_error("Cannot create NDI recieve instance");
|
||||
}
|
||||
NDIlib_recv_connect(pNDI_recv, p_sources + source_num);
|
||||
}
|
||||
|
||||
private:
|
||||
// receive
|
||||
NDIlib_find_instance_t pNDI_find = nullptr;
|
||||
uint32_t sources_amount = 0;
|
||||
const NDIlib_source_t* p_sources = NULL;
|
||||
NDIlib_recv_instance_t pNDI_recv = nullptr;
|
||||
|
||||
void get_source_info(uint32_t source_num) {
|
||||
NDIlib_video_frame_v2_t video_frame;
|
||||
uint8_t frames = 0;
|
||||
while (frames < 2) {
|
||||
NDIlib_recv_capture_v2(pNDI_recv, &video_frame, nullptr, nullptr, 1000);
|
||||
NDIlib_recv_free_video_v2(pNDI_recv, &video_frame);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user