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