diff --git a/Makefile.dev b/Makefile.dev index 67aa4ef..fe18012 100644 --- a/Makefile.dev +++ b/Makefile.dev @@ -25,7 +25,7 @@ build: .PHONY: run run: build - ./build/$(TARGET) $(TEST_ARGS) --monitor-only --internal-size=240 --hot-reload + ./build/$(TARGET) $(TEST_ARGS) --monitor-only --internal-size=480 --hot-reload .PHONY: demo demo: build diff --git a/README.md b/README.md index 2b37019..e23ca8e 100644 --- a/README.md +++ b/README.md @@ -134,11 +134,11 @@ make -f Makefile.dev release-arch - [ ] Clean code and fix things - [ ] Video input - [x] Fixed camera video - - [x] Pass video info to shaders + - [ ] Pass video info to shaders - [x] Sub process video reading - [x] Shader based format mapping - [x] Video mapping config file - - [ ] Get first video size matching internal size + - [x] Get first video size matching internal size - [ ] Clean code and fix things - [x] Monitor screen - [x] 2nd window diff --git a/shaders/frag1.glsl b/shaders/frag1.glsl index d2ce06c..d8401e0 100644 --- a/shaders/frag1.glsl +++ b/shaders/frag1.glsl @@ -7,5 +7,5 @@ in vec2 vUV; out vec4 fragColor; void main() { - fragColor = yuyvTex(tex1, vUV, 320); + fragColor = yuyvTex(tex1, vUV, 480); // TODO uniform } \ No newline at end of file diff --git a/shaders/frag2.glsl b/shaders/frag2.glsl index 98aecd1..b42c6ad 100644 --- a/shaders/frag2.glsl +++ b/shaders/frag2.glsl @@ -7,5 +7,5 @@ in vec2 vUV; out vec4 fragColor; void main() { - fragColor = yuyvTex(tex2, vUV, 320); + fragColor = yuyvTex(tex2, vUV, 320); // TODO uniform } \ No newline at end of file diff --git a/src/forge.c b/src/forge.c index 88b8802..a1be28b 100644 --- a/src/forge.c +++ b/src/forge.c @@ -145,13 +145,14 @@ static void free_files(unsigned int frag_count) { file_free(&common_shader_code, true); } -static void init_devices(char *video_in[MAX_VIDEO], unsigned int video_count) { +static void init_devices(char *video_in[MAX_VIDEO], unsigned int video_count, + unsigned int internal_size) { unsigned int i; devices = malloc(video_count * sizeof(VideoDevice)); for (i = 0; i < video_count; i++) { - devices[i] = video_init(video_in[i], 320, 240); // TODO define in args + devices[i] = video_init(video_in[i], internal_size); } } @@ -242,7 +243,7 @@ void forge_run(Parameters params) { context.internal_size = params.internal_size; - init_devices(params.video_in, params.video_count); + init_devices(params.video_in, params.video_count, params.internal_size); if (params.output) { window_output = window_init(PACKAGE " " VERSION, params.output_screen, diff --git a/src/video.c b/src/video.c index 3604709..4f781f2 100644 --- a/src/video.c +++ b/src/video.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -92,8 +93,51 @@ static bool check_device_caps(VideoDevice *device) { return true; } -static bool set_device_format(VideoDevice *device, unsigned int preferred_width, - unsigned int preferred_height) { +static bool get_available_sizes(VideoDevice *device, + unsigned int preferred_height) { + struct v4l2_frmsizeenum fmt_enum; + unsigned int index; + + memset(&fmt_enum, 0, sizeof(fmt_enum)); + + index = 0; + fmt_enum.index = index; + fmt_enum.pixel_format = V4L2_PIX_FMT_YUYV; + + device->width = 0; + device->height = 0; + + while (ioctl(device->fd, VIDIOC_ENUM_FRAMESIZES, &fmt_enum) == 0) { + if (fmt_enum.type == V4L2_FRMSIZE_TYPE_DISCRETE) { + log_trace("(%s) %d: %dx%d", device->name, index, fmt_enum.discrete.width, + fmt_enum.discrete.height); + + if (fmt_enum.discrete.height == preferred_height) { + device->height = preferred_height; + if (device->width == 0 || device->width < fmt_enum.discrete.width) { + device->width = fmt_enum.discrete.width; + } + } else if (fmt_enum.discrete.height < preferred_height && + fmt_enum.discrete.height > device->height) { + device->height = fmt_enum.discrete.height; + device->width = fmt_enum.discrete.width; + } + } + + memset(&fmt_enum, 0, sizeof(fmt_enum)); + fmt_enum.index = ++index; + fmt_enum.pixel_format = V4L2_PIX_FMT_YUYV; + } + + if (device->height == 0) { + device->error = true; + return false; + } + + return true; +} + +static bool set_device_format(VideoDevice *device) { struct v4l2_format fmt; device->output = false; @@ -101,8 +145,8 @@ static bool set_device_format(VideoDevice *device, unsigned int preferred_width, memset(&fmt, 0, sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmt.fmt.pix.width = preferred_width; - fmt.fmt.pix.height = preferred_height; + fmt.fmt.pix.width = device->width; + fmt.fmt.pix.height = device->height; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; @@ -205,8 +249,7 @@ static void close_stream(VideoDevice device) { ioctl(device.fd, VIDIOC_STREAMOFF, &buf_type); } -VideoDevice video_init(char *name, unsigned int preferred_width, - unsigned int preferred_height) { +VideoDevice video_init(char *name, unsigned int preferred_height) { VideoDevice device; device = open_device(name); @@ -219,7 +262,11 @@ VideoDevice video_init(char *name, unsigned int preferred_width, return device; } - if (!set_device_format(&device, preferred_width, preferred_height)) { + if (!get_available_sizes(&device, preferred_height)) { + return device; + } + + if (!set_device_format(&device)) { return device; } diff --git a/src/video.h b/src/video.h index 9298ee3..bb38d13 100644 --- a/src/video.h +++ b/src/video.h @@ -3,8 +3,7 @@ #ifndef VIDEO_H #define VIDEO_H -VideoDevice video_init(char *name, unsigned int preferred_width, - unsigned int preferred_height); +VideoDevice video_init(char *name, unsigned int preferred_height); void video_background_read(VideoDevice *device, bool *stop);