Skip to content

Commit

Permalink
Fixes to input device
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Sep 1, 2021
1 parent ca2ec5f commit d01bca8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Ndi/InputFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class InputEnumerator : public Device::DeviceEnumerator
auto sources = find.get_current_sources(&num_sources);

std::set<QString> new_nodes;
for(int i = 0; i < num_sources; i++)
for(uint32_t i = 0; i < num_sources; i++)
{
QString name = sources[i].p_ndi_name;
new_nodes.insert(name);
Expand All @@ -39,7 +39,7 @@ class InputEnumerator : public Device::DeviceEnumerator
dev.name = name;
dev.protocol = InputFactory::static_concreteKey();
dev.deviceSpecificSettings = QVariant::fromValue(set);
deviceAdded(std::move(dev));
deviceAdded(dev);

m_known.insert(name);
}
Expand Down
26 changes: 22 additions & 4 deletions Ndi/InputNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,17 @@ bool InputStream::load(const std::string& inputDevice) noexcept
NDIlib_source_t source;
source.p_ndi_name = inputDevice.c_str();
source.p_url_address = nullptr;
m_receiver.connect(&source);
NDIlib_recv_create_v3_t info;
info.allow_video_fields = false;
info.bandwidth = NDIlib_recv_bandwidth_highest;
info.color_format = NDIlib_recv_color_format_UYVY_RGBA;
info.source_to_connect_to = source;

m_receiver.create(info);

pixel_format = AV_PIX_FMT_UYVY422;
width = 1920;
height = 1080;
width = 0;
height = 0;

return true;
}
Expand Down Expand Up @@ -88,6 +95,13 @@ AVFrame* InputStream::dequeue_frame() noexcept

void InputStream::release_frame(AVFrame* frame) noexcept
{
NDIlib_video_frame_v2_t ndi_frame{};
ndi_frame.p_data = frame->data[0];
ndi_frame.p_metadata = nullptr;
frame->data[0] = nullptr;

m_receiver.free_video(&ndi_frame);

m_frames.release(frame);
}

Expand Down Expand Up @@ -143,19 +157,23 @@ static std::optional<AVPixelFormat> getPixelFormat(NDIlib_FourCC_video_type_e fo
AVFrame* InputStream::read_frame_impl() noexcept
{
NDIlib_video_frame_v2_t ndi_frame;
ndi_frame.p_metadata = nullptr;
switch (m_receiver.capture(&ndi_frame, nullptr, nullptr, 1000))
{
case NDIlib_frame_type_video:
{
if(auto format = getPixelFormat(ndi_frame.FourCC))
{
AVFrame* frame = m_frames.newFrame();
AVFrame* frame = m_frames.newFrame().release();

frame->format = *format;

frame->data[0] = ndi_frame.p_data;
frame->linesize[0] = ndi_frame.line_stride_in_bytes;
frame->width = ndi_frame.xres;
frame->height = ndi_frame.yres;
height = frame->height;
width = frame->width;

return frame;
}
Expand Down
13 changes: 9 additions & 4 deletions Ndi/Loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ struct Loader
}

// Recv API
auto recv_create() const noexcept
auto recv_create(NDIlib_recv_create_v3_t* inst = nullptr) const noexcept
{
return m_lib->recv_create_v3(nullptr);
return m_lib->recv_create_v3(inst);
}
auto recv_destroy(NDIlib_recv_instance_t recv) const noexcept
{
Expand Down Expand Up @@ -153,14 +153,19 @@ struct Receiver

Receiver(const Loader& ndi)
: ndi{ndi}
, impl{ndi.recv_create()}
{

}

~Receiver()
{
ndi.recv_destroy(impl);
if(impl)
ndi.recv_destroy(impl);
}

auto create(NDIlib_recv_create_v3_t setup)
{
impl = ndi.recv_create(&setup);
}

auto connect(const NDIlib_source_t* source)
Expand Down
2 changes: 1 addition & 1 deletion addon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"src": "https://github.com/ossia/score-addon-ndi/releases/download/v4.1.0/score-addon-ndi.zip",
"name": "NDI support",
"raw_name": "score-addon-ndi",
"version": "4.1",
"version": "4.2",
"kind": "addon",
"short": "Support for NDI input and output",
"long": "This addon provides NDI input and output devices",
Expand Down

0 comments on commit d01bca8

Please sign in to comment.