Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce 'buffer_type' structure #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions v4l2-request-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions v4l2-request-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
50 changes: 36 additions & 14 deletions v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down