configure: drop check for --enable-vaapi-glx.
[profile/ivi/gstreamer-vaapi.git] / tests / output.c
1 /*
2  *  output.c - Video output helpers
3  *
4  *  Copyright (C) 2012 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 "config.h"
23 #include <string.h>
24 #include <gst/gst.h>
25 #if USE_X11
26 # include <gst/vaapi/gstvaapidisplay_x11.h>
27 # include <gst/vaapi/gstvaapiwindow_x11.h>
28 #endif
29 #if USE_GLX
30 # include <gst/vaapi/gstvaapidisplay_glx.h>
31 # include <gst/vaapi/gstvaapiwindow_glx.h>
32 #endif
33 #include "output.h"
34
35 static const VideoOutputInfo *g_video_output;
36 static const VideoOutputInfo g_video_outputs[] = {
37     /* Video outputs are sorted in test order for automatic characterisation */
38 #if USE_X11
39     { "x11",
40       gst_vaapi_display_x11_new,
41       gst_vaapi_window_x11_new
42     },
43 #endif
44 #if USE_GLX
45     { "glx",
46       gst_vaapi_display_glx_new,
47       gst_vaapi_window_glx_new
48     },
49 #endif
50     { NULL, }
51 };
52
53 static gchar *g_output_name;
54 static gboolean g_list_outputs = FALSE;
55
56 static GOptionEntry g_options[] = {
57     { "list-outputs", 0,
58       0,
59       G_OPTION_ARG_NONE, &g_list_outputs,
60       "list video outputs", NULL },
61     { "output", 'o',
62       0,
63       G_OPTION_ARG_STRING, &g_output_name,
64       "video output name", NULL },
65     { NULL, }
66 };
67
68 static void
69 list_outputs(void)
70 {
71     const VideoOutputInfo *o;
72
73     g_print("Video outputs:");
74     for (o = g_video_outputs; o->name != NULL; o++)
75         g_print(" %s", o->name);
76     g_print("\n");
77 }
78
79 gboolean
80 video_output_init(int *argc, char *argv[], GOptionEntry *options)
81 {
82     GOptionContext *ctx;
83     gboolean success;
84
85 #if !GLIB_CHECK_VERSION(2,31,0)
86     if (!g_thread_supported())
87         g_thread_init(NULL);
88 #endif
89
90     ctx = g_option_context_new("- test options");
91     if (!ctx)
92         return FALSE;
93
94     g_option_context_add_group(ctx, gst_init_get_option_group());
95     g_option_context_add_main_entries(ctx, g_options, NULL);
96     if (options)
97         g_option_context_add_main_entries(ctx, options, NULL);
98     success = g_option_context_parse(ctx, argc, &argv, NULL);
99     g_option_context_free(ctx);
100
101     if (g_list_outputs) {
102         list_outputs();
103         exit(0);
104     }
105     return success;
106 }
107
108 void
109 video_output_exit(void)
110 {
111     g_free(g_output_name);
112     gst_deinit();
113 }
114
115 const VideoOutputInfo *
116 video_output_lookup(const gchar *output_name)
117 {
118     const VideoOutputInfo *o;
119
120     if (!output_name)
121         return NULL;
122
123     for (o = g_video_outputs; o->name != NULL; o++) {
124         if (g_ascii_strcasecmp(o->name, output_name) == 0)
125             return o;
126     }
127     return NULL;
128 }
129
130 GstVaapiDisplay *
131 video_output_create_display(const gchar *display_name)
132 {
133     const VideoOutputInfo *o = g_video_output;
134     GstVaapiDisplay *display = NULL;
135
136     if (!o) {
137         if (g_output_name)
138             o = video_output_lookup(g_output_name);
139         else {
140             for (o = g_video_outputs; o->name != NULL; o++) {
141                 display = o->create_display(display_name);
142                 if (display) {
143                     if (gst_vaapi_display_get_display(display))
144                         break;
145                     g_object_unref(display);
146                     display = NULL;
147                 }
148             }
149         }
150         if (!o || !o->name)
151             return NULL;
152         g_print("Using %s video output\n", o->name);
153         g_video_output = o;
154     }
155
156     if (!display)
157         display = o->create_display(display_name);
158     return display;
159 }
160
161 GstVaapiWindow *
162 video_output_create_window(GstVaapiDisplay *display, guint width, guint height)
163 {
164     if (!g_video_output)
165         return NULL;
166     return g_video_output->create_window(display, width, height);
167 }