Skip to content

Commit cb3089d

Browse files
committed
vdisp/ndi: set stride explicitly
The documentation in header for NDIlib_video_frame_v2_t.line_stride_in_bytes says that if set to 0, default value (size of pixel * bpp) will be used. However, this doesn't seem to work for P216 and PA16 in Windows. It does in Linux, also 8-bit formats do not require that. However in Windows, it causes "No data received.". see also GH-148
1 parent cc617d7 commit cb3089d

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/utils/macros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
#define SWAP(a, b) do { b ^= a; a ^= b; b ^= a; } while (0)
5858
#define SWAP_PTR(a, b) do { void *tmp = (a); (a) = (b); (b) = tmp; } while(0)
5959

60+
#define ARR_COUNT(arr) (sizeof (arr) / sizeof (arr)[0])
61+
6062
#undef MIN
6163
#define MIN(a,b) (((a)<(b))?(a):(b))
6264
#undef MAX

src/video_display/ndi.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#include "ndi_common.h"
5858
#include "types.h"
5959
#include "utils/color_out.h"
60-
#include "utils/macros.h" // OPTIMIZED_FOR
60+
#include "utils/macros.h" // for ARR_COUNT, OPTIMIZED_FOR
6161
#include "utils/misc.h"
6262
#include "video.h"
6363
#include "video_display.h"
@@ -95,35 +95,40 @@ static void display_ndi_probe(struct device_info **available_cards, int *count,
9595
*deleter = free;
9696
}
9797

98-
static const struct {
98+
static const struct mapping {
9999
codec_t ug_codec;
100+
int stride_per_pixel;
100101
NDIlib_FourCC_video_type_e ndi_fourcc;
101102
ndi_disp_convert_t *convert;
102103
} codec_mapping[] = {
103-
{ RGBA, NDIlib_FourCC_type_RGBA, NULL },
104-
{ UYVY, NDIlib_FourCC_type_UYVY, NULL },
105-
{ I420, NDIlib_FourCC_video_type_I420, NULL },
106-
{ Y216, NDIlib_FourCC_type_P216, ndi_disp_convert_Y216_to_P216 },
107-
{ Y416, NDIlib_FourCC_type_PA16, ndi_disp_convert_Y416_to_PA16 },
104+
{ RGBA, 4, NDIlib_FourCC_type_RGBA, NULL },
105+
{ UYVY, 2, NDIlib_FourCC_type_UYVY, NULL },
106+
{ I420, 1, NDIlib_FourCC_video_type_I420, NULL },
107+
{ Y216, 2, NDIlib_FourCC_type_P216, ndi_disp_convert_Y216_to_P216 },
108+
{ Y416, 2, NDIlib_FourCC_type_PA16, ndi_disp_convert_Y416_to_PA16 },
108109
};
109110

110111
static bool display_ndi_reconfigure(void *state, struct video_desc desc)
111112
{
112113
struct display_ndi *s = (struct display_ndi *) state;
113114

115+
const struct mapping *m = NULL;
116+
for (size_t i = 0; i < ARR_COUNT(codec_mapping); ++i) {
117+
if (codec_mapping[i].ug_codec == desc.color_spec) {
118+
m = &codec_mapping[i];
119+
}
120+
}
121+
assert(m != NULL);
122+
114123
s->desc = desc;
115124
free(s->convert_buffer);
116125
s->convert_buffer = malloc(MAX_BPS * desc.width * desc.height + MAX_PADDING);
126+
s->convert = m->convert;
117127

118128
s->NDI_video_frame.xres = s->desc.width;
119129
s->NDI_video_frame.yres = s->desc.height;
120-
for (size_t i = 0; i < sizeof codec_mapping / sizeof codec_mapping[0]; ++i) {
121-
if (codec_mapping[i].ug_codec == desc.color_spec) {
122-
s->NDI_video_frame.FourCC = codec_mapping[i].ndi_fourcc;
123-
s->convert = codec_mapping[i].convert;
124-
}
125-
}
126-
assert(s->NDI_video_frame.FourCC != 0);
130+
s->NDI_video_frame.line_stride_in_bytes = s->desc.width * m->stride_per_pixel;
131+
s->NDI_video_frame.FourCC = m->ndi_fourcc;
127132
s->NDI_video_frame.frame_rate_N = get_framerate_n(desc.fps);
128133
s->NDI_video_frame.frame_rate_D = get_framerate_d(desc.fps);
129134
s->NDI_video_frame.frame_format_type = desc.interlacing == PROGRESSIVE ? NDIlib_frame_format_type_progressive : NDIlib_frame_format_type_interleaved;

0 commit comments

Comments
 (0)