From 0bde4055872050f6b45c8d82b71fb0f6ece1504f Mon Sep 17 00:00:00 2001 From: Ralf Zerres Date: Sat, 9 Mar 2019 16:42:59 +0100 Subject: [PATCH 1/2] introduce structure buffer_type - define a V4L2 buffer type structure (.name, .type) - refer 'v4l2_buf_type' enum values to their lexical names Signed-off-by: Ralf Zerres --- v4l2-request-test.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ v4l2-request-test.h | 5 +++++ 2 files changed, 60 insertions(+) diff --git a/v4l2-request-test.c b/v4l2-request-test.c index 2531e7c..5f18f23 100644 --- a/v4l2-request-test.c +++ b/v4l2-request-test.c @@ -37,6 +37,61 @@ #include "v4l2-request-test.h" +const struct buffer_type buffer_type[] = { + { + .name = "Video Capture Buffer", + .type = V4L2_BUF_TYPE_VIDEO_CAPTURE + }, + { + .name = "Video Output Buffer", + .type = V4L2_BUF_TYPE_VIDEO_OUTPUT + }, + { + .name = "Video Overlay Buffer", + .type = V4L2_BUF_TYPE_VIDEO_OVERLAY + }, + { + .name = "VBI Capture Buffer", + .type = V4L2_BUF_TYPE_VBI_CAPTURE + }, + { + .name = "VBI Output Buffer", + .type = V4L2_BUF_TYPE_VBI_OUTPUT + }, + { + .name = "Sliced VBI Capture Buffer", + .type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE + }, + { + .name = "Sliced VBI Output Buffer", + .type = V4L2_BUF_TYPE_SLICED_VBI_OUTPUT + }, + { + .name = "Video Output Overlay Buffer", + .type = V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY + }, + { + .name = "Video Multi-Plane Capture Buffer", + .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE + }, + { + .name = "Video Multi-Plane Output Buffer", + .type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE + }, + { + .name = "SDR Capture Buffer", + .type = V4L2_BUF_TYPE_SDR_CAPTURE + }, + { + .name = "SDR Output Buffer", + .type = V4L2_BUF_TYPE_SDR_OUTPUT + }, + { + .name = "Meta Capture Buffer", + .type = V4L2_BUF_TYPE_META_CAPTURE + } +}; + struct format_description formats[] = { { .description = "NV12 YUV", diff --git a/v4l2-request-test.h b/v4l2-request-test.h index 7c8a1c3..02586e6 100644 --- a/v4l2-request-test.h +++ b/v4l2-request-test.h @@ -124,6 +124,11 @@ struct preset { unsigned int display_count; }; +extern const struct buffer_type { + char *name; + enum v4l2_buf_type type; +} buffer_type[]; + /* V4L2 */ struct video_setup { From 687c7a3ee432f567f927daba471922d57dc9d72d Mon Sep 17 00:00:00 2001 From: Ralf Zerres Date: Sat, 9 Mar 2019 16:46:11 +0100 Subject: [PATCH 2/2] extend error messages while referencing the involved buffer name - take the field value in question and output its dereferenced name from the referenced structure Signed-off-by: Ralf Zerres --- v4l2.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/v4l2.c b/v4l2.c index bcf5097..1a2f40c 100644 --- a/v4l2.c +++ b/v4l2.c @@ -140,8 +140,8 @@ static int try_format(int video_fd, unsigned int type, unsigned int width, rc = ioctl(video_fd, VIDIOC_TRY_FMT, &format); if (rc < 0) { - fprintf(stderr, "Unable to try format for type %d: %s\n", type, - strerror(errno)); + fprintf(stderr, "Unable to try format for %s (%d): %s (%d)\n", + buffer_type[type].name, type, strerror(errno), errno); return -1; } @@ -637,31 +637,42 @@ int video_engine_start(int video_fd, int media_fd, unsigned int width, rc = set_format(video_fd, output_type, width, height, source_format); if (rc < 0) { - fprintf(stderr, "Unable to set source format\n"); + fprintf(stderr, "Unable to set source format for %s\n", + buffer_type[output_type].name); goto error; } + else + fprintf(stderr, "Set format for source: %s\n", + buffer_type[output_type].name); destination_format = format->v4l2_format; rc = set_format(video_fd, capture_type, width, height, destination_format); if (rc < 0) { - fprintf(stderr, "Unable to set destination format\n"); + fprintf(stderr, "Unable to set destination format for %s\n", + buffer_type[capture_type].name); goto error; } + else + fprintf(stderr, "Set format for destination: %s\n", + buffer_type[capture_type].name); + destination_planes_count = format->planes_count; rc = get_format(video_fd, capture_type, &format_width, &format_height, destination_bytesperlines, destination_sizes, NULL); if (rc < 0) { - fprintf(stderr, "Unable to get destination format\n"); + fprintf(stderr, "Unable to get destination format for %s\n", + buffer_type[capture_type].name); goto error; } rc = create_buffers(video_fd, output_type, buffers_count, NULL); if (rc < 0) { - fprintf(stderr, "Unable to create source buffers\n"); + fprintf(stderr, "Unable to create source for %s\n", + buffer_type[output_type].name); goto error; } @@ -671,7 +682,8 @@ int video_engine_start(int video_fd, int media_fd, unsigned int width, rc = query_buffer(video_fd, output_type, i, &source_length, &source_map_offset, 1); if (rc < 0) { - fprintf(stderr, "Unable to request source buffer\n"); + fprintf(stderr, "Unable to request source for %s\n", + buffer_type[output_type].name); goto error; } @@ -689,7 +701,9 @@ int video_engine_start(int video_fd, int media_fd, unsigned int width, rc = create_buffers(video_fd, capture_type, buffers_count, NULL); if (rc < 0) { - fprintf(stderr, "Unable to create destination buffers\n"); + fprintf(stderr, "Unable to create destination for %s\n", + buffer_type[capture_type].name); + goto error; } @@ -800,13 +814,15 @@ int video_engine_start(int video_fd, int media_fd, unsigned int width, rc = set_stream(video_fd, output_type, true); if (rc < 0) { - fprintf(stderr, "Unable to enable source stream\n"); + fprintf(stderr, "Unable to enable source stream for %s\n", + buffer_type[setup->output_type].name); goto error; } rc = set_stream(video_fd, capture_type, true); if (rc < 0) { - fprintf(stderr, "Unable to enable destination stream\n"); + fprintf(stderr, "Unable to enable destination stream for %s\n", + buffer_type[setup->capture_type].name); goto error; } @@ -829,13 +845,15 @@ int video_engine_stop(int video_fd, struct video_buffer *buffers, rc = set_stream(video_fd, setup->output_type, false); if (rc < 0) { - fprintf(stderr, "Unable to enable source stream\n"); + fprintf(stderr, "Unable to enable source stream for %s\n", + buffer_type[setup->output_type].name); return -1; } rc = set_stream(video_fd, setup->capture_type, false); if (rc < 0) { - fprintf(stderr, "Unable to enable destination stream\n"); + fprintf(stderr, "Unable to enable destination stream for %s\n", + buffer_type[setup->capture_type].name); return -1; } @@ -892,13 +910,16 @@ int video_engine_decode(int video_fd, unsigned int index, union controls *frame, rc = queue_buffer(video_fd, request_fd, setup->output_type, ts, index, source_size, 1); if (rc < 0) { - fprintf(stderr, "Unable to queue source buffer\n"); + fprintf(stderr, "Unable to queue source for %s\n", + buffer_type[setup->output_type].name); return -1; } rc = queue_buffer(video_fd, -1, setup->capture_type, 0, index, 0, buffers[index].destination_buffers_count); if (rc < 0) { + fprintf(stderr, "Unable to queue source for %s\n", + buffer_type[setup->capture_type].name); fprintf(stderr, "Unable to queue destination buffer\n"); return -1; } @@ -934,7 +955,8 @@ int video_engine_decode(int video_fd, unsigned int index, union controls *frame, buffers[index].destination_buffers_count, &destination_error); if (rc < 0) { - fprintf(stderr, "Unable to dequeue destination buffer\n"); + fprintf(stderr, "Unable to dequeue destination for %s\n", + buffer_type[setup->capture_type].name); return -1; }