|
57 | 57 | #include "ndi_common.h" |
58 | 58 | #include "types.h" |
59 | 59 | #include "utils/color_out.h" |
60 | | -#include "utils/macros.h" // OPTIMIZED_FOR |
| 60 | +#include "utils/macros.h" // for ARR_COUNT, OPTIMIZED_FOR |
61 | 61 | #include "utils/misc.h" |
62 | 62 | #include "video.h" |
63 | 63 | #include "video_display.h" |
@@ -95,35 +95,40 @@ static void display_ndi_probe(struct device_info **available_cards, int *count, |
95 | 95 | *deleter = free; |
96 | 96 | } |
97 | 97 |
|
98 | | -static const struct { |
| 98 | +static const struct mapping { |
99 | 99 | codec_t ug_codec; |
| 100 | + int stride_per_pixel; |
100 | 101 | NDIlib_FourCC_video_type_e ndi_fourcc; |
101 | 102 | ndi_disp_convert_t *convert; |
102 | 103 | } 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 }, |
108 | 109 | }; |
109 | 110 |
|
110 | 111 | static bool display_ndi_reconfigure(void *state, struct video_desc desc) |
111 | 112 | { |
112 | 113 | struct display_ndi *s = (struct display_ndi *) state; |
113 | 114 |
|
| 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 | + |
114 | 123 | s->desc = desc; |
115 | 124 | free(s->convert_buffer); |
116 | 125 | s->convert_buffer = malloc(MAX_BPS * desc.width * desc.height + MAX_PADDING); |
| 126 | + s->convert = m->convert; |
117 | 127 |
|
118 | 128 | s->NDI_video_frame.xres = s->desc.width; |
119 | 129 | 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; |
127 | 132 | s->NDI_video_frame.frame_rate_N = get_framerate_n(desc.fps); |
128 | 133 | s->NDI_video_frame.frame_rate_D = get_framerate_d(desc.fps); |
129 | 134 | s->NDI_video_frame.frame_format_type = desc.interlacing == PROGRESSIVE ? NDIlib_frame_format_type_progressive : NDIlib_frame_format_type_interleaved; |
|
0 commit comments