examples: va: Add random cropping.
And remove unused caps filter. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2443>
This commit is contained in:
parent
6853c3eea8
commit
e9395bbcd1
@ -13,18 +13,21 @@ static gboolean camera = FALSE;
|
|||||||
static gboolean randomcb = FALSE;
|
static gboolean randomcb = FALSE;
|
||||||
static gboolean randomdir = FALSE;
|
static gboolean randomdir = FALSE;
|
||||||
static gboolean randomsharpen = FALSE;
|
static gboolean randomsharpen = FALSE;
|
||||||
|
static gboolean randomcrop = FALSE;
|
||||||
|
|
||||||
static GOptionEntry entries[] = {
|
static GOptionEntry entries[] = {
|
||||||
{"num-buffers", 'n', 0, G_OPTION_ARG_INT, &num_buffers,
|
{"num-buffers", 'n', 0, G_OPTION_ARG_INT, &num_buffers,
|
||||||
"Number of buffers (<= 0 : forever)", "N"},
|
"Number of buffers (<= 0 : forever)", "N"},
|
||||||
{"camera", 'c', 0, G_OPTION_ARG_NONE, &camera, "Use v4l2src as video source",
|
{"camera", 'c', 0, G_OPTION_ARG_NONE, &camera,
|
||||||
NULL},
|
"Use default v4l2src as video source", NULL},
|
||||||
{"random-cb", 'r', 0, G_OPTION_ARG_NONE, &randomcb,
|
{"random-cb", 'r', 0, G_OPTION_ARG_NONE, &randomcb,
|
||||||
"Change colorbalance randomly every second (if supported)", NULL},
|
"Change colorbalance randomly every second (if supported)", NULL},
|
||||||
{"random-dir", 'd', 0, G_OPTION_ARG_NONE, &randomdir,
|
{"random-dir", 'd', 0, G_OPTION_ARG_NONE, &randomdir,
|
||||||
"Change video direction randomly every second (if supported)", NULL},
|
"Change video direction randomly every second (if supported)", NULL},
|
||||||
{"random-sharpen", 's', 0, G_OPTION_ARG_NONE, &randomsharpen,
|
{"random-sharpen", 's', 0, G_OPTION_ARG_NONE, &randomsharpen,
|
||||||
"Change sharpen filter randombly every second (if supported)", NULL},
|
"Change sharpen filter randomly every second (if supported)", NULL},
|
||||||
|
{"random-crop", 'p', 0, G_OPTION_ARG_NONE, &randomcrop,
|
||||||
|
"Change cropping randomly every 150 miliseconds", NULL},
|
||||||
{NULL},
|
{NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -34,10 +37,12 @@ struct _app
|
|||||||
GstObject *display;
|
GstObject *display;
|
||||||
GstElement *pipeline;
|
GstElement *pipeline;
|
||||||
GstElement *vpp;
|
GstElement *vpp;
|
||||||
GstElement *caps;
|
GstElement *crop;
|
||||||
GMutex mutex;
|
GMutex mutex;
|
||||||
|
|
||||||
GstControlSource *sharpen;
|
GstControlSource *sharpen;
|
||||||
|
gint right, left, top, bottom;
|
||||||
|
gint ldir, rdir, tdir, bdir;
|
||||||
};
|
};
|
||||||
|
|
||||||
static GstBusSyncReply
|
static GstBusSyncReply
|
||||||
@ -183,7 +188,7 @@ build_pipeline (struct _app *app)
|
|||||||
const gchar *source = camera ? "v4l2src" : "videotestsrc";
|
const gchar *source = camera ? "v4l2src" : "videotestsrc";
|
||||||
|
|
||||||
g_string_printf (cmd, "%s name=src ! tee name=t "
|
g_string_printf (cmd, "%s name=src ! tee name=t "
|
||||||
"t. ! queue ! vapostproc name=vpp ! capsfilter name=caps ! "
|
"t. ! queue ! videocrop name=crop ! vapostproc name=vpp ! "
|
||||||
"fpsdisplaysink video-sink=autovideosink "
|
"fpsdisplaysink video-sink=autovideosink "
|
||||||
"t. ! queue ! vapostproc ! timeoverlay ! autovideosink", source);
|
"t. ! queue ! vapostproc ! timeoverlay ! autovideosink", source);
|
||||||
|
|
||||||
@ -202,10 +207,10 @@ build_pipeline (struct _app *app)
|
|||||||
}
|
}
|
||||||
|
|
||||||
app->vpp = gst_bin_get_by_name (GST_BIN (app->pipeline), "vpp");
|
app->vpp = gst_bin_get_by_name (GST_BIN (app->pipeline), "vpp");
|
||||||
if (!randomcb && !randomdir && !randomsharpen)
|
if (!randomcb && !randomdir && !randomsharpen && !randomcrop)
|
||||||
config_vpp (app->vpp);
|
config_vpp (app->vpp);
|
||||||
|
|
||||||
app->caps = gst_bin_get_by_name (GST_BIN (app->pipeline), "caps");
|
app->crop = gst_bin_get_by_name (GST_BIN (app->pipeline), "crop");
|
||||||
|
|
||||||
bus = gst_pipeline_get_bus (GST_PIPELINE (app->pipeline));
|
bus = gst_pipeline_get_bus (GST_PIPELINE (app->pipeline));
|
||||||
gst_bus_set_sync_handler (bus, context_handler, app, NULL);
|
gst_bus_set_sync_handler (bus, context_handler, app, NULL);
|
||||||
@ -308,6 +313,41 @@ change_sharpen_randomly (gpointer data)
|
|||||||
return G_SOURCE_CONTINUE;
|
return G_SOURCE_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
change_crop_randomly (gpointer data)
|
||||||
|
{
|
||||||
|
struct _app *app = data;
|
||||||
|
|
||||||
|
g_object_set (app->crop, "bottom", app->bottom, "top", app->top, "left",
|
||||||
|
app->left, "right", app->right, NULL);
|
||||||
|
|
||||||
|
app->top += app->tdir;
|
||||||
|
if (app->top >= 80)
|
||||||
|
app->tdir = -10;
|
||||||
|
else if (app->top < 10)
|
||||||
|
app->tdir = 10;
|
||||||
|
|
||||||
|
app->bottom += app->bdir;
|
||||||
|
if (app->bottom >= 60)
|
||||||
|
app->bdir = -10;
|
||||||
|
else if (app->bottom < 10)
|
||||||
|
app->bdir = 10;
|
||||||
|
|
||||||
|
app->left += app->ldir;
|
||||||
|
if (app->left >= 100)
|
||||||
|
app->ldir = -10;
|
||||||
|
else if (app->left < 10)
|
||||||
|
app->ldir = 10;
|
||||||
|
|
||||||
|
app->right += app->rdir;
|
||||||
|
if (app->right >= 80)
|
||||||
|
app->rdir = -10;
|
||||||
|
else if (app->right < 10)
|
||||||
|
app->rdir = 10;
|
||||||
|
|
||||||
|
return G_SOURCE_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
parse_arguments (int *argc, char ***argv)
|
parse_arguments (int *argc, char ***argv)
|
||||||
{
|
{
|
||||||
@ -368,6 +408,11 @@ main (int argc, char **argv)
|
|||||||
g_timeout_add_seconds (1, change_sharpen_randomly, &app);
|
g_timeout_add_seconds (1, change_sharpen_randomly, &app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (randomcrop) {
|
||||||
|
app.bdir = app.ldir = app.rdir = app.tdir = 10;
|
||||||
|
g_timeout_add (150, change_crop_randomly, &app);
|
||||||
|
}
|
||||||
|
|
||||||
gst_element_set_state (app.pipeline, GST_STATE_PLAYING);
|
gst_element_set_state (app.pipeline, GST_STATE_PLAYING);
|
||||||
|
|
||||||
g_main_loop_run (app.loop);
|
g_main_loop_run (app.loop);
|
||||||
@ -382,10 +427,10 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
gst_clear_object (&app.caps);
|
|
||||||
gst_clear_object (&app.vpp);
|
gst_clear_object (&app.vpp);
|
||||||
gst_clear_object (&app.pipeline);
|
gst_clear_object (&app.pipeline);
|
||||||
gst_clear_object (&app.sharpen);
|
gst_clear_object (&app.sharpen);
|
||||||
|
gst_clear_object (&app.crop);
|
||||||
|
|
||||||
gst_failed:
|
gst_failed:
|
||||||
g_mutex_clear (&app.mutex);
|
g_mutex_clear (&app.mutex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user