2016-07-01 07:01:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <gst/gst.h>
|
2019-07-15 19:23:21 +00:00
|
|
|
#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,}
|
|
|
|
};
|
2016-07-01 07:01:54 +00:00
|
|
|
|
|
|
|
typedef struct _CustomData
|
|
|
|
{
|
|
|
|
GstElement *pipeline;
|
2019-07-15 19:23:21 +00:00
|
|
|
GstElement *rotator;
|
2016-07-01 07:01:54 +00:00
|
|
|
GMainLoop *loop;
|
|
|
|
gboolean orient_automatic;
|
|
|
|
} AppData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_rotate_event (AppData * data)
|
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
GstEvent *event;
|
2016-07-05 18:59:49 +00:00
|
|
|
static gint counter = 0;
|
|
|
|
const static gchar *tags[] = { "rotate-90", "rotate-180", "rotate-270",
|
2019-07-15 19:23:21 +00:00
|
|
|
"rotate-0", "flip-rotate-0", "flip-rotate-90", "flip-rotate-180",
|
|
|
|
"flip-rotate-270",
|
2016-07-05 18:59:49 +00:00
|
|
|
};
|
2016-07-01 07:01:54 +00:00
|
|
|
|
|
|
|
event = gst_event_new_tag (gst_tag_list_new (GST_TAG_IMAGE_ORIENTATION,
|
2016-07-05 18:59:49 +00:00
|
|
|
tags[counter++ % G_N_ELEMENTS (tags)], NULL));
|
2016-07-01 07:01:54 +00:00
|
|
|
|
|
|
|
/* Send the event */
|
2019-07-15 19:23:21 +00:00
|
|
|
g_print ("Sending event %" GST_PTR_FORMAT ": ", event);
|
2017-05-12 16:17:55 +00:00
|
|
|
res = gst_element_send_event (data->pipeline, event);
|
2019-07-15 19:23:21 +00:00
|
|
|
g_print ("%s\n", res ? "ok" : "failed");
|
|
|
|
|
2016-07-01 07:01:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 16:46:50 +00:00
|
|
|
static void
|
|
|
|
keyboard_cb (const gchar * key, AppData * data)
|
2016-07-01 07:01:54 +00:00
|
|
|
{
|
2017-05-12 16:46:50 +00:00
|
|
|
switch (g_ascii_tolower (key[0])) {
|
2016-07-01 07:01:54 +00:00
|
|
|
case 'r':
|
|
|
|
send_rotate_event (data);
|
|
|
|
break;
|
|
|
|
case 's':{
|
2019-07-15 19:23:21 +00:00
|
|
|
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);
|
|
|
|
}
|
2016-07-01 07:01:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'q':
|
|
|
|
g_main_loop_quit (data->loop);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-05-12 16:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
bus_msg (GstBus * bus, GstMessage * msg, gpointer user_data)
|
|
|
|
{
|
|
|
|
AppData *data = user_data;
|
|
|
|
|
|
|
|
switch (GST_MESSAGE_TYPE (msg)) {
|
|
|
|
case GST_MESSAGE_ELEMENT:
|
|
|
|
{
|
|
|
|
GstNavigationMessageType mtype = gst_navigation_message_get_type (msg);
|
|
|
|
if (mtype == GST_NAVIGATION_MESSAGE_EVENT) {
|
|
|
|
GstEvent *ev = NULL;
|
|
|
|
|
|
|
|
if (gst_navigation_message_parse_event (msg, &ev)) {
|
|
|
|
GstNavigationEventType type = gst_navigation_event_get_type (ev);
|
|
|
|
if (type == GST_NAVIGATION_EVENT_KEY_PRESS) {
|
|
|
|
const gchar *key;
|
|
|
|
|
|
|
|
if (gst_navigation_event_parse_key_event (ev, &key))
|
|
|
|
keyboard_cb (key, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ev)
|
|
|
|
gst_event_unref (ev);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process keyboard input */
|
|
|
|
static gboolean
|
|
|
|
handle_keyboard (GIOChannel * source, GIOCondition cond, AppData * data)
|
|
|
|
{
|
|
|
|
gchar *str = NULL;
|
|
|
|
|
|
|
|
if (g_io_channel_read_line (source, &str, NULL, NULL,
|
|
|
|
NULL) != G_IO_STATUS_NORMAL) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-07-01 07:01:54 +00:00
|
|
|
|
2017-05-12 16:46:50 +00:00
|
|
|
keyboard_cb (str, data);
|
2016-07-01 07:01:54 +00:00
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
AppData data;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
GIOChannel *io_stdin;
|
2019-07-15 19:23:21 +00:00
|
|
|
GOptionContext *ctx;
|
2017-05-12 16:17:55 +00:00
|
|
|
GError *err = NULL;
|
2017-05-12 16:46:50 +00:00
|
|
|
guint srcid;
|
2016-07-01 07:01:54 +00:00
|
|
|
|
|
|
|
/* Initialize GStreamer */
|
2019-07-15 19:23:21 +00:00
|
|
|
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);
|
2016-07-01 07:01:54 +00:00
|
|
|
|
|
|
|
/* Print usage map */
|
|
|
|
g_print ("USAGE: Choose one of the following options, then press enter:\n"
|
2017-05-12 16:17:55 +00:00
|
|
|
" 'r' to send image-orientation tag event\n"
|
|
|
|
" 's' to set orient-automatic\n" " 'Q' to quit\n");
|
|
|
|
|
2019-07-15 19:23:21 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-05-12 16:17:55 +00:00
|
|
|
if (err) {
|
|
|
|
g_printerr ("failed to create pipeline: %s\n", err->message);
|
|
|
|
g_error_free (err);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-07-01 07:01:54 +00:00
|
|
|
|
2019-07-15 19:23:21 +00:00
|
|
|
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");
|
2017-05-12 16:46:50 +00:00
|
|
|
srcid = gst_bus_add_watch (GST_ELEMENT_BUS (data.pipeline), bus_msg, &data);
|
2016-07-01 07:01:54 +00:00
|
|
|
|
|
|
|
/* Add a keyboard watch so we get notified of keystrokes */
|
|
|
|
io_stdin = g_io_channel_unix_new (fileno (stdin));
|
|
|
|
g_io_add_watch (io_stdin, G_IO_IN, (GIOFunc) handle_keyboard, &data);
|
|
|
|
|
|
|
|
/* Start playing */
|
|
|
|
ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE) {
|
|
|
|
g_printerr ("Unable to set the pipeline to the playing state.\n");
|
2017-05-12 16:17:55 +00:00
|
|
|
goto bail;
|
2016-07-01 07:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a GLib Main Loop and set it to run */
|
|
|
|
data.loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
g_main_loop_run (data.loop);
|
|
|
|
|
2017-05-12 16:17:55 +00:00
|
|
|
gst_element_set_state (data.pipeline, GST_STATE_NULL);
|
|
|
|
|
|
|
|
bail:
|
2016-07-01 07:01:54 +00:00
|
|
|
/* Free resources */
|
2017-05-12 16:46:50 +00:00
|
|
|
g_source_remove (srcid);
|
2016-07-01 07:01:54 +00:00
|
|
|
g_main_loop_unref (data.loop);
|
|
|
|
g_io_channel_unref (io_stdin);
|
|
|
|
|
2019-07-15 19:23:21 +00:00
|
|
|
gst_object_unref (data.rotator);
|
2016-07-01 07:01:54 +00:00
|
|
|
gst_object_unref (data.pipeline);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|