Merge branch 'move_subdir_editing-services' into tizen_gst_1.19.2_mono
[platform/upstream/gstreamer.git] / subprojects / gstreamer-vaapi / tests / examples / test-vaapipostproc.c
1 /*
2  *  test-vaapipostproc.c - Testsuite for VAAPI Postprocessor
3  *
4  *  Copyright (C) 2017 Intel Corporation
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public License
8  *  as published by the Free Software Foundation; either version 2.1
9  *  of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free
18  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  *  Boston, MA 02110-1301 USA
20  */
21
22 #include <stdio.h>
23 #include <gst/gst.h>
24 #include <gst/base/gstbasetransform.h>
25
26 typedef struct _CustomData
27 {
28   GstElement *pipeline;
29   GstElement *postproc;
30   GMainLoop *loop;
31 } AppData;
32
33 static gboolean
34 _check_passthrough_mode (gpointer user_data)
35 {
36   gboolean ret;
37   AppData *data = (AppData *) user_data;
38
39   ret = gst_base_transform_is_passthrough (GST_BASE_TRANSFORM (data->postproc));
40
41   if (ret)
42     gst_println ("Now this pipeline is on passthrough mode");
43   else
44     gst_println ("Now this pipeline is NOT on passthrough mode");
45
46   return FALSE;
47 }
48
49 static void
50 set_contrast (AppData * data)
51 {
52   static gfloat value = 1.0;
53
54   value = value == 1.0 ? 0.5 : 1.0;
55   g_object_set (data->postproc, "contrast", value, NULL);
56   gst_println ("contrast value is changed to %f", value);
57
58   g_timeout_add (300, _check_passthrough_mode, data);
59 }
60
61 static void
62 change_size (AppData * data)
63 {
64   static gint i = 0;
65   if (i == 0) {
66     g_object_set (data->postproc, "width", 1280, "height", 720, NULL);
67     gst_println ("frame size is changed to 1280x720");
68     i++;
69   } else {
70     g_object_set (data->postproc, "width", 0, "height", 0, NULL);
71     gst_println ("frame size is changed to default");
72     i = 0;
73   }
74
75   g_timeout_add (300, _check_passthrough_mode, data);
76 }
77
78 /* Process keyboard input */
79 static gboolean
80 handle_keyboard (GIOChannel * source, GIOCondition cond, AppData * data)
81 {
82   gchar *str = NULL;
83
84   if (g_io_channel_read_line (source, &str, NULL, NULL,
85           NULL) != G_IO_STATUS_NORMAL) {
86     return TRUE;
87   }
88
89   switch (g_ascii_tolower (str[0])) {
90     case 's':{
91       set_contrast (data);
92       break;
93     }
94     case 'c':{
95       change_size (data);
96       break;
97     }
98     case 'q':
99       g_main_loop_quit (data->loop);
100       break;
101     default:
102       break;
103   }
104
105   g_free (str);
106
107   return TRUE;
108 }
109
110 int
111 main (int argc, char *argv[])
112 {
113   AppData data = { 0, };
114   GstStateChangeReturn ret;
115   GIOChannel *io_stdin;
116
117   /* Initialize GStreamer */
118   gst_init (&argc, &argv);
119
120   /* Print usage map */
121   gst_println ("USAGE: Choose one of the following options, then press enter:\n"
122       " 's' to set contrast\n" " 'c' to change size\n" " 'q' to quit\n");
123
124   data.pipeline =
125       gst_parse_launch
126       ("videotestsrc name=src ! vaapih264enc ! vaapih264dec ! vaapipostproc name=postproc ! vaapisink",
127       NULL);
128   data.postproc = gst_bin_get_by_name (GST_BIN (data.pipeline), "postproc");
129
130   /* Add a keyboard watch so we get notified of keystrokes */
131   io_stdin = g_io_channel_unix_new (fileno (stdin));
132   g_io_add_watch (io_stdin, G_IO_IN, (GIOFunc) handle_keyboard, &data);
133
134   /* Start playing */
135   ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
136   if (ret == GST_STATE_CHANGE_FAILURE) {
137     g_printerr ("Unable to set the pipeline to the playing state.\n");
138     gst_object_unref (data.pipeline);
139     return -1;
140   }
141
142   g_timeout_add (300, _check_passthrough_mode, &data);
143
144   /* Create a GLib Main Loop and set it to run */
145   data.loop = g_main_loop_new (NULL, FALSE);
146   g_main_loop_run (data.loop);
147
148   /* Free resources */
149   g_main_loop_unref (data.loop);
150   g_io_channel_unref (io_stdin);
151   gst_element_set_state (data.pipeline, GST_STATE_NULL);
152
153   gst_object_unref (data.postproc);
154   gst_object_unref (data.pipeline);
155
156   return 0;
157 }