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

[RFC] Enhance message content send to 'stderr' #9

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
9 changes: 6 additions & 3 deletions drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,8 @@ int display_engine_start(int drm_fd, unsigned int width, unsigned int height,
struct format_description *format,
struct video_buffer *video_buffers, unsigned int count,
struct gem_buffer **buffers,
struct display_setup *setup)
struct display_setup *setup,
bool quiet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions are not expected to interact with the user other than for printing out errors, so I don't think I'll take this in.

{
struct video_buffer *video_buffer;
struct gem_buffer *buffer;
Expand Down Expand Up @@ -824,7 +825,8 @@ int display_engine_start(int drm_fd, unsigned int width, unsigned int height,
}

int display_engine_stop(int drm_fd, struct gem_buffer *buffers,
struct display_setup *setup)
struct display_setup *setup,
bool quiet)
{
struct gem_buffer *buffer;
unsigned int i;
Expand Down Expand Up @@ -862,7 +864,8 @@ int display_engine_stop(int drm_fd, struct gem_buffer *buffers,

int display_engine_show(int drm_fd, unsigned int index,
struct video_buffer *video_buffers,
struct gem_buffer *buffers, struct display_setup *setup)
struct gem_buffer *buffers, struct display_setup *setup,
bool quiet)
{
struct video_buffer *video_buffer;
struct gem_buffer *buffer;
Expand Down
4 changes: 2 additions & 2 deletions presets.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <linux/media.h>
#include <linux/videodev2.h>
#include <mpeg2-ctrls.h>
#include <h264-ctrls.h>
#include <hevc-ctrls.h>
//#include <h264-ctrls.h>
//#include <hevc-ctrls.h>

#include "v4l2-request-test.h"

Expand Down
141 changes: 93 additions & 48 deletions v4l2-request-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@

#include "v4l2-request-test.h"

const struct codec codec[] = {
{
.name = "MPEG-2",
.description = "Moving Pictures Expert Group Version-4 (MPEG-2)",
.type = CODEC_TYPE_MPEG2,
},
{
.name = "H.264",
.description = "Moving Pictures Expert Group Version-4 (MPEG-4)",
.type = CODEC_TYPE_H264,
},
{
.name = "H.265",
.description = "High-Efficiency Video Coding (HEVC)",
.type = CODEC_TYPE_H265,
},
};

struct format_description formats[] = {
{
.description = "NV12 YUV",
Expand Down Expand Up @@ -64,58 +82,57 @@ struct format_description formats[] = {

static void print_help(void)
{
printf("Usage: v4l2-request-test [OPTIONS] [SLICES PATH]\n\n"
"Options:\n"
" -v [video path] path for the video node\n"
" -m [media path] path for the media node\n"
" -d [DRM path] path for the DRM node\n"
" -D [DRM driver] DRM driver to use\n"
" -s [slices filename format] format for filenames in the slices path\n"
" -f [fps] number of frames to display per second\n"
" -P [video preset] video preset to use\n"
" -i enable interactive mode\n"
" -l loop preset frames\n"
" -q enable quiet mode\n"
" -h help\n\n"
"Video presets:\n");
printf("Usage: v4l2-request-test [OPTIONS]\n\n"
"Options:\n"
" -v, --device <dev>\n"
" --video-device <dev> Use device <dev> as the video device.\n"
" -m, --media-device <dev> Use device <dev> as the media device.\n"
" -d, --drm-device <dev> Use device <dev > as DRM device.\n"
" -D, --drm-driver <name> Use given DRM driver.\n"
" -s, --slices-path <path> Use <path> to find stored video slices.\n"
" -S, --slices-format <slices format>\n"
" Regex/format describing filenames stored in the slices path.\n"
" -f, --fps <fps> Display given number of frames per seconds.\n"
" -P, --preset-name <name> Use given preset-name for video decoding.\n"
" -i, --interactive Enable interactive mode.\n"
" -l, --loop Loop preset frames.\n"
" -q, --quiet Enable quiet mode.\n"
" -h, --help This help message.\n\n");

presets_usage();
}

static void print_summary(struct config *config, struct preset *preset)
{
printf("Config:\n");
printf(" Video path: %s\n", config->video_path);
printf(" Media path: %s\n", config->media_path);
printf(" DRM path: %s\n", config->drm_path);
printf(" DRM driver: %s\n", config->drm_driver);
printf(" Slices path: %s\n", config->slices_path);
printf(" Slices filename format: %s\n", config->slices_filename_format);
printf(" FPS: %d\n\n", config->fps);
printf(" Video device: %s\n", config->video_path);
printf(" Media device: %s\n", config->media_path);
printf(" DRM device: %s\n", config->drm_path);
printf(" DRM driver: %s\n", config->drm_driver);
printf(" Slices path: %s\n", config->slices_path);
printf(" Slices format: %s\n", config->slices_filename_format);
printf(" FPS: %d\n\n", config->fps);

printf("Preset:\n");
printf(" Name: %s\n", preset->name);
printf(" Description: %s\n", preset->description);
printf(" License: %s\n", preset->license);
printf(" Attribution: %s\n", preset->attribution);
printf(" Width: %d\n", preset->width);
printf(" Height: %d\n", preset->height);
printf(" Name: %s\n", preset->name);
printf(" Description: %s\n", preset->description);
printf(" License: %s\n", preset->license);
printf(" Attribution: %s\n", preset->attribution);
printf(" Width: %d\n", preset->width);
printf(" Height: %d\n", preset->height);
printf(" Frames count: %d\n", preset->frames_count);

printf(" Format: ");
printf(" Codec Type: ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing Format with Codec is definitely a change I would take in, but adding more than the short names for the codecs seems overkill. If you'd like to improve this area, one thing would be to use proper names: MPEG-2, H.264 and H.265 instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will produce an update.


switch (preset->type) {
case CODEC_TYPE_MPEG2:
printf("MPEG2");
break;
case CODEC_TYPE_H264:
printf("H264");
break;
case CODEC_TYPE_H265:
printf("H265");
printf("%s -> %s",
codec[preset->type].name, codec[preset->type].description);
break;
default:
printf("Invalid");
printf("Invalid codec type!");
break;
}

Expand Down Expand Up @@ -257,7 +274,26 @@ int main(int argc, char *argv[])
setup_config(&config);

while (1) {
opt = getopt(argc, argv, "v:m:d:D:s:f:P:ilqh");
int option_index = 0;
static struct option long_options[] = {
{ "device", required_argument, 0, 'v' },
{ "video-device", required_argument, 0, 'v' },
{ "media-device", required_argument, 0, 'm' },
{ "drm-device", required_argument, 0, 'd' },
{ "drm-driver", required_argument, 0, 'D' },
{ "slices-path", required_argument, 0, 's'},
{ "slices-format", required_argument, 0, 'S'},
{ "fps", required_argument, 0, 'f' },
{ "preset-name", required_argument, 0, 'P'},
{ "interactive", no_argument, 0, 'i'},
{ "loop", no_argument, 0, 'l'},
{ "quiet", no_argument, 0, 'q'},
{ "help", no_argument, 0, 'h'},
{ 0, 0, 0, 0 }
};

opt = getopt_long(argc, argv, "v:m:d:D:s:S:f:P:ilqh",
long_options, &option_index);
if (opt == -1)
break;

Expand All @@ -279,6 +315,10 @@ int main(int argc, char *argv[])
config.drm_driver = strdup(optarg);
break;
case 's':
free(config.slices_path);
config.slices_path = strdup(optarg);
break;
case 'S':
free(config.slices_filename_format);
config.slices_filename_format = strdup(optarg);
break;
Expand Down Expand Up @@ -320,9 +360,7 @@ int main(int argc, char *argv[])

width = preset->width;
height = preset->height;
if (optind < argc)
config.slices_path = strdup(argv[optind]);
else
if (config.slices_path == NULL)
asprintf(&config.slices_path, "data/%s", config.preset_name);

print_summary(&config, preset);
Expand Down Expand Up @@ -360,7 +398,8 @@ int main(int argc, char *argv[])
for (i = 0; i < ARRAY_SIZE(formats); i++) {
test = video_engine_format_test(video_fd,
formats[i].v4l2_mplane, width,
height, formats[i].v4l2_format);
height, formats[i].v4l2_format,
config.quiet);
if (test) {
selected_format = &formats[i];
break;
Expand All @@ -375,18 +414,21 @@ int main(int argc, char *argv[])

printf("Destination format: %s\n", selected_format->description);

test = video_engine_capabilities_test(video_fd, V4L2_CAP_STREAMING);
test = video_engine_capabilities_test(video_fd, V4L2_CAP_STREAMING,
config.quiet);
if (!test) {
fprintf(stderr, "Missing required driver streaming capability\n");
goto error;
}

if (selected_format->v4l2_mplane)
test = video_engine_capabilities_test(video_fd,
V4L2_CAP_VIDEO_M2M_MPLANE);
V4L2_CAP_VIDEO_M2M_MPLANE,
config.quiet);
else
test = video_engine_capabilities_test(video_fd,
V4L2_CAP_VIDEO_M2M);
V4L2_CAP_VIDEO_M2M,
config.quiet);

if (!test) {
fprintf(stderr, "Missing required driver M2M capability\n");
Expand All @@ -395,15 +437,16 @@ int main(int argc, char *argv[])

rc = video_engine_start(video_fd, media_fd, width, height,
selected_format, preset->type, &video_buffers,
config.buffers_count, &video_setup);
config.buffers_count, &video_setup,
config.quiet);
if (rc < 0) {
fprintf(stderr, "Unable to start video engine\n");
goto error;
}

rc = display_engine_start(drm_fd, width, height, selected_format,
video_buffers, config.buffers_count,
&gem_buffers, &display_setup);
&gem_buffers, &display_setup, config.quiet);
if (rc < 0) {
fprintf(stderr, "Unable to start display engine\n");
goto error;
Expand Down Expand Up @@ -487,7 +530,7 @@ int main(int argc, char *argv[])
rc = video_engine_decode(video_fd, v4l2_index, &frame.frame,
preset->type, ts, slice_data,
slice_size, video_buffers,
&video_setup);
&video_setup, config.quiet);
if (rc < 0) {
fprintf(stderr, "Unable to decode video frame\n");
goto error;
Expand Down Expand Up @@ -523,7 +566,8 @@ int main(int argc, char *argv[])
clock_gettime(CLOCK_MONOTONIC, &display_before);

rc = display_engine_show(drm_fd, v4l2_index, video_buffers,
gem_buffers, &display_setup);
gem_buffers, &display_setup,
config.quiet);
if (rc < 0) {
fprintf(stderr, "Unable to display video frame\n");
goto error;
Expand Down Expand Up @@ -564,13 +608,14 @@ int main(int argc, char *argv[])
}

rc = video_engine_stop(video_fd, video_buffers, config.buffers_count,
&video_setup);
&video_setup, config.quiet);
if (rc < 0) {
fprintf(stderr, "Unable to stop video engine\n");
goto error;
}

rc = display_engine_stop(drm_fd, gem_buffers, &display_setup);
rc = display_engine_stop(drm_fd, gem_buffers, &display_setup,
config.quiet);
if (rc < 0) {
fprintf(stderr, "Unable to stop display engine\n");
goto error;
Expand Down
29 changes: 21 additions & 8 deletions v4l2-request-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ struct preset {
unsigned int display_count;
};

extern const struct codec {
char *name;
char *description;
enum codec_type type;
} codec[];

/* V4L2 */

struct video_setup {
Expand Down Expand Up @@ -220,32 +226,39 @@ int frame_gop_schedule(struct preset *preset, unsigned int index);
/* V4L2 */

bool video_engine_capabilities_test(int video_fd,
unsigned int capabilities_required);
unsigned int capabilities_required,
bool quiet);
bool video_engine_format_test(int video_fd, bool mplane, unsigned int width,
unsigned int height, unsigned int format);
unsigned int height, unsigned int format,
bool quiet);
int video_engine_start(int video_fd, int media_fd, unsigned int width,
unsigned int height, struct format_description *format,
enum codec_type type, struct video_buffer **buffers,
unsigned int buffers_count, struct video_setup *setup);
unsigned int buffers_count, struct video_setup *setup,
bool quiet);
int video_engine_stop(int video_fd, struct video_buffer *buffers,
unsigned int buffers_count, struct video_setup *setup);
unsigned int buffers_count, struct video_setup *setup,
bool quiet);
int video_engine_decode(int video_fd, unsigned int index, union controls *frame,
enum codec_type type, uint64_t ts, void *source_data,
unsigned int source_size, struct video_buffer *buffers,
struct video_setup *setup);
struct video_setup *setup, bool quiet);

/* DRM */

int display_engine_start(int drm_fd, unsigned int width, unsigned int height,
struct format_description *format,
struct video_buffer *video_buffers, unsigned int count,
struct gem_buffer **buffers,
struct display_setup *setup);
struct display_setup *setup,
bool quiet);
int display_engine_stop(int drm_fd, struct gem_buffer *buffers,
struct display_setup *setup);
struct display_setup *setup,
bool quiet);
int display_engine_show(int drm_fd, unsigned int index,
struct video_buffer *video_buffers,
struct gem_buffer *buffers,
struct display_setup *setup);
struct display_setup *setup,
bool quiet);

#endif
Loading