packaging: add packaging folder and update submodule pkgs
[platform/upstream/gstreamer-vaapi.git] / tests / output.c
1 /*
2  *  output.c - Video output helpers
3  *
4  *  Copyright (C) 2012-2013 Intel Corporation
5  *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
6  *
7  *  This library is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU Lesser General Public License
9  *  as published by the Free Software Foundation; either version 2.1
10  *  of the License, or (at your option) any later version.
11  *
12  *  This library is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public
18  *  License along with this library; if not, write to the Free
19  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  *  Boston, MA 02110-1301 USA
21  */
22
23 #include "gst/vaapi/sysdeps.h"
24 #include <string.h>
25 #include <gst/gst.h>
26 #if USE_DRM
27 # include <gst/vaapi/gstvaapidisplay_drm.h>
28 # include <gst/vaapi/gstvaapiwindow_drm.h>
29 #endif
30 #if USE_X11
31 # include <gst/vaapi/gstvaapidisplay_x11.h>
32 # include <gst/vaapi/gstvaapiwindow_x11.h>
33 # include <gst/vaapi/gstvaapipixmap_x11.h>
34 #endif
35 #if USE_GLX
36 # include <gst/vaapi/gstvaapidisplay_glx.h>
37 # include <gst/vaapi/gstvaapiwindow_glx.h>
38 #endif
39 #if USE_WAYLAND
40 # include <gst/vaapi/gstvaapidisplay_wayland.h>
41 # include <gst/vaapi/gstvaapiwindow_wayland.h>
42 #endif
43 #include "output.h"
44
45 static const VideoOutputInfo *g_video_output;
46 static const VideoOutputInfo g_video_outputs[] = {
47     /* Video outputs are sorted in test order for automatic characterisation */
48 #if USE_WAYLAND
49     { "wayland",
50       gst_vaapi_display_wayland_new,
51       gst_vaapi_window_wayland_new
52     },
53 #endif
54 #if USE_X11
55     { "x11",
56       gst_vaapi_display_x11_new,
57       gst_vaapi_window_x11_new,
58       gst_vaapi_pixmap_x11_new
59     },
60 #endif
61 #if USE_GLX
62     { "glx",
63       gst_vaapi_display_glx_new,
64       gst_vaapi_window_glx_new,
65       gst_vaapi_pixmap_x11_new
66     },
67 #endif
68 #if USE_DRM
69     { "drm",
70       gst_vaapi_display_drm_new,
71       gst_vaapi_window_drm_new
72     },
73 #endif
74     { NULL, }
75 };
76
77 static gchar *g_output_name;
78 static gboolean g_list_outputs = FALSE;
79 static gboolean g_fullscreen = FALSE;
80
81 static GOptionEntry g_options[] = {
82     { "list-outputs", 0,
83       0,
84       G_OPTION_ARG_NONE, &g_list_outputs,
85       "list video outputs", NULL },
86     { "output", 'o',
87       0,
88       G_OPTION_ARG_STRING, &g_output_name,
89       "video output name", NULL },
90     { "fullscreen", 'f',
91       0,
92       G_OPTION_ARG_NONE, &g_fullscreen,
93       "fullscreen mode", NULL },
94     { NULL, }
95 };
96
97 static void
98 list_outputs(void)
99 {
100     const VideoOutputInfo *o;
101
102     g_print("Video outputs:");
103     for (o = g_video_outputs; o->name != NULL; o++)
104         g_print(" %s", o->name);
105     g_print("\n");
106 }
107
108 gboolean
109 video_output_init(int *argc, char *argv[], GOptionEntry *options)
110 {
111     GOptionContext *ctx;
112     gboolean success;
113
114 #if !GLIB_CHECK_VERSION(2,31,0)
115     if (!g_thread_supported())
116         g_thread_init(NULL);
117 #endif
118
119     ctx = g_option_context_new("- test options");
120     if (!ctx)
121         return FALSE;
122
123     g_option_context_add_group(ctx, gst_init_get_option_group());
124     g_option_context_add_main_entries(ctx, g_options, NULL);
125     if (options)
126         g_option_context_add_main_entries(ctx, options, NULL);
127     success = g_option_context_parse(ctx, argc, &argv, NULL);
128     g_option_context_free(ctx);
129
130     if (g_list_outputs) {
131         list_outputs();
132         exit(0);
133     }
134     return success;
135 }
136
137 void
138 video_output_exit(void)
139 {
140     g_free(g_output_name);
141     gst_deinit();
142 }
143
144 const VideoOutputInfo *
145 video_output_lookup(const gchar *output_name)
146 {
147     const VideoOutputInfo *o;
148
149     if (!output_name)
150         return NULL;
151
152     for (o = g_video_outputs; o->name != NULL; o++) {
153         if (g_ascii_strcasecmp(o->name, output_name) == 0)
154             return o;
155     }
156     return NULL;
157 }
158
159 GstVaapiDisplay *
160 video_output_create_display(const gchar *display_name)
161 {
162     const VideoOutputInfo *o = g_video_output;
163     GstVaapiDisplay *display = NULL;
164
165     if (!o) {
166         if (g_output_name)
167             o = video_output_lookup(g_output_name);
168         else {
169             for (o = g_video_outputs; o->name != NULL; o++) {
170                 display = o->create_display(display_name);
171                 if (display) {
172                     if (gst_vaapi_display_get_display(display))
173                         break;
174                     gst_vaapi_display_unref(display);
175                     display = NULL;
176                 }
177             }
178         }
179         if (!o || !o->name)
180             return NULL;
181         g_print("Using %s video output\n", o->name);
182         g_video_output = o;
183     }
184
185     if (!display)
186         display = o->create_display(display_name);
187     return display;
188 }
189
190 GstVaapiWindow *
191 video_output_create_window(GstVaapiDisplay *display, guint width, guint height)
192 {
193     GstVaapiWindow *window;
194
195     if (!g_video_output)
196         return NULL;
197
198     window = g_video_output->create_window(display, width, height);
199     if (!window)
200         return NULL;
201
202     /* Force fullscreen mode, should this be requested by the user */
203     if (g_fullscreen)
204         gst_vaapi_window_set_fullscreen(window, TRUE);
205     return window;
206 }
207
208 GstVaapiPixmap *
209 video_output_create_pixmap(GstVaapiDisplay *display, GstVideoFormat format,
210     guint width, guint height)
211 {
212     if (!g_video_output || !g_video_output->create_pixmap)
213         return NULL;
214     return g_video_output->create_pixmap(display, format, width, height);
215 }