test-vaapisink: also use vaapipostproc to change orientation

This commit is contained in:
Víctor Manuel Jáquez Leal 2019-07-15 21:23:21 +02:00
parent bcb29e8399
commit a6aba119b4

View file

@ -1,12 +1,19 @@
#include <stdio.h>
#include <string.h>
#include <gst/gst.h>
#include <gst/video/navigation.h>
#include <gst/video/video.h>
static gboolean use_postproc;
static GOptionEntry g_options[] = {
{"postproc", 'p', 0, G_OPTION_ARG_NONE, &use_postproc,
"use vaapipostproc to rotate rather than vaapisink", NULL},
{NULL,}
};
typedef struct _CustomData
{
GstElement *pipeline;
GstElement *video_sink;
GstElement *rotator;
GMainLoop *loop;
gboolean orient_automatic;
} AppData;
@ -18,15 +25,18 @@ send_rotate_event (AppData * data)
GstEvent *event;
static gint counter = 0;
const static gchar *tags[] = { "rotate-90", "rotate-180", "rotate-270",
"rotate-0"
"rotate-0", "flip-rotate-0", "flip-rotate-90", "flip-rotate-180",
"flip-rotate-270",
};
event = gst_event_new_tag (gst_tag_list_new (GST_TAG_IMAGE_ORIENTATION,
tags[counter++ % G_N_ELEMENTS (tags)], NULL));
/* Send the event */
g_print ("Sending event %" GST_PTR_FORMAT ": ", event);
res = gst_element_send_event (data->pipeline, event);
g_print ("Sending event %p done: %d\n", event, res);
g_print ("%s\n", res ? "ok" : "failed");
}
static void
@ -37,7 +47,13 @@ keyboard_cb (const gchar * key, AppData * data)
send_rotate_event (data);
break;
case 's':{
g_object_set (G_OBJECT (data->video_sink), "rotation", 360, NULL);
if (use_postproc) {
g_object_set (G_OBJECT (data->rotator), "video-direction",
GST_VIDEO_ORIENTATION_AUTO, NULL);
} else {
/* rotation=360 means auto for vaapisnk */
g_object_set (G_OBJECT (data->rotator), "rotation", 360, NULL);
}
break;
}
case 'q':
@ -104,25 +120,43 @@ main (int argc, char *argv[])
AppData data;
GstStateChangeReturn ret;
GIOChannel *io_stdin;
GOptionContext *ctx;
GError *err = NULL;
guint srcid;
/* Initialize GStreamer */
gst_init (&argc, &argv);
ctx = g_option_context_new ("- test options");
if (!ctx)
return -1;
g_option_context_add_group (ctx, gst_init_get_option_group ());
g_option_context_add_main_entries (ctx, g_options, NULL);
if (!g_option_context_parse (ctx, &argc, &argv, NULL))
return -1;
g_option_context_free (ctx);
/* Print usage map */
g_print ("USAGE: Choose one of the following options, then press enter:\n"
" 'r' to send image-orientation tag event\n"
" 's' to set orient-automatic\n" " 'Q' to quit\n");
data.pipeline = gst_parse_launch ("videotestsrc ! vaapisink name=sink", &err);
if (use_postproc) {
data.pipeline =
gst_parse_launch ("videotestsrc ! vaapipostproc name=pp ! xvimagesink",
&err);
} else {
data.pipeline =
gst_parse_launch ("videotestsrc ! vaapisink name=sink", &err);
}
if (err) {
g_printerr ("failed to create pipeline: %s\n", err->message);
g_error_free (err);
return -1;
}
data.video_sink = gst_bin_get_by_name (GST_BIN (data.pipeline), "sink");
if (use_postproc)
data.rotator = gst_bin_get_by_name (GST_BIN (data.pipeline), "pp");
else
data.rotator = gst_bin_get_by_name (GST_BIN (data.pipeline), "sink");
srcid = gst_bus_add_watch (GST_ELEMENT_BUS (data.pipeline), bus_msg, &data);
/* Add a keyboard watch so we get notified of keystrokes */
@ -148,7 +182,7 @@ bail:
g_main_loop_unref (data.loop);
g_io_channel_unref (io_stdin);
gst_object_unref (data.video_sink);
gst_object_unref (data.rotator);
gst_object_unref (data.pipeline);
return 0;