mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
tests: use common display and window creation routines.
Add new --output option to select the renderer. Use --list-outputs to print a list of supported renderers.
This commit is contained in:
parent
0c8dc604cb
commit
9e0c97a3d3
6 changed files with 232 additions and 31 deletions
|
@ -44,8 +44,8 @@ endif
|
|||
test_codecs_source_c = test-mpeg2.c test-h264.c test-vc1.c test-jpeg.c
|
||||
test_codecs_source_h = $(test_codecs_source_c:%.c=%.h) test-decode.h
|
||||
|
||||
test_utils_source_c = image.c $(test_codecs_source_c)
|
||||
test_utils_source_h = image.h $(test_codecs_source_h)
|
||||
test_utils_source_c = image.c output.c $(test_codecs_source_c)
|
||||
test_utils_source_h = image.h output.h $(test_codecs_source_h)
|
||||
|
||||
noinst_LTLIBRARIES = libutils.la
|
||||
libutils_la_SOURCES = $(test_utils_source_c)
|
||||
|
|
157
tests/output.c
Normal file
157
tests/output.c
Normal file
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
* output.c - Video output helpers
|
||||
*
|
||||
* Copyright (C) 2012 Intel Corporation
|
||||
*
|
||||
* 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 "config.h"
|
||||
#include <string.h>
|
||||
#include <gst/gst.h>
|
||||
#if USE_X11
|
||||
# include <gst/vaapi/gstvaapidisplay_x11.h>
|
||||
# include <gst/vaapi/gstvaapiwindow_x11.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 USE_X11
|
||||
{ "x11",
|
||||
gst_vaapi_display_x11_new,
|
||||
gst_vaapi_window_x11_new
|
||||
},
|
||||
#endif
|
||||
{ NULL, }
|
||||
};
|
||||
|
||||
static gchar *g_output_name;
|
||||
static gboolean g_list_outputs = FALSE;
|
||||
|
||||
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 },
|
||||
{ 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;
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2,31,0)
|
||||
if (!g_thread_supported())
|
||||
g_thread_init(NULL);
|
||||
#endif
|
||||
|
||||
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 *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;
|
||||
g_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);
|
||||
return display;
|
||||
}
|
||||
|
||||
GstVaapiWindow *
|
||||
video_output_create_window(GstVaapiDisplay *display, guint width, guint height)
|
||||
{
|
||||
if (!g_video_output)
|
||||
return NULL;
|
||||
return g_video_output->create_window(display, width, height);
|
||||
}
|
55
tests/output.h
Normal file
55
tests/output.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* output.h - Video output helpers
|
||||
*
|
||||
* Copyright (C) 2012 Intel Corporation
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef OUTPUT_H
|
||||
#define OUTPUT_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <gst/vaapi/gstvaapidisplay.h>
|
||||
#include <gst/vaapi/gstvaapiwindow.h>
|
||||
|
||||
typedef GstVaapiDisplay *(*CreateDisplayFunc)(const gchar *display_name);
|
||||
typedef GstVaapiWindow *(*CreateWindowFunc)(GstVaapiDisplay *display,
|
||||
guint width, guint height);
|
||||
|
||||
typedef struct _VideoOutputInfo VideoOutputInfo;
|
||||
struct _VideoOutputInfo {
|
||||
const gchar *name;
|
||||
CreateDisplayFunc create_display;
|
||||
CreateWindowFunc create_window;
|
||||
};
|
||||
|
||||
gboolean
|
||||
video_output_init(int *argc, char *argv[], GOptionEntry *options);
|
||||
|
||||
void
|
||||
video_output_exit(void);
|
||||
|
||||
const VideoOutputInfo *
|
||||
video_output_lookup(const gchar *output_name);
|
||||
|
||||
GstVaapiDisplay *
|
||||
video_output_create_display(const gchar *display_name);
|
||||
|
||||
GstVaapiWindow *
|
||||
video_output_create_window(GstVaapiDisplay *display, guint width, guint height);
|
||||
|
||||
#endif /* OUTPUT_H */
|
|
@ -22,8 +22,6 @@
|
|||
|
||||
#include "config.h"
|
||||
#include <string.h>
|
||||
#include <gst/vaapi/gstvaapidisplay_x11.h>
|
||||
#include <gst/vaapi/gstvaapiwindow_x11.h>
|
||||
#include <gst/vaapi/gstvaapidecoder.h>
|
||||
#include <gst/vaapi/gstvaapisurface.h>
|
||||
#include <gst/vaapi/gstvaapidecoder_h264.h>
|
||||
|
@ -34,6 +32,7 @@
|
|||
#include "test-mpeg2.h"
|
||||
#include "test-h264.h"
|
||||
#include "test-vc1.h"
|
||||
#include "output.h"
|
||||
|
||||
/* Set to 1 to check display cache works (shared VA display) */
|
||||
#define CHECK_DISPLAY_CACHE 1
|
||||
|
@ -85,7 +84,6 @@ static GOptionEntry g_options[] = {
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
GOptionContext *options;
|
||||
GstVaapiDisplay *display, *display2;
|
||||
GstVaapiWindow *window;
|
||||
GstVaapiDecoder *decoder;
|
||||
|
@ -100,12 +98,8 @@ main(int argc, char *argv[])
|
|||
static const guint win_width = 640;
|
||||
static const guint win_height = 480;
|
||||
|
||||
gst_init(&argc, &argv);
|
||||
|
||||
options = g_option_context_new(" - test-decode options");
|
||||
g_option_context_add_main_entries(options, g_options, NULL);
|
||||
g_option_context_parse(options, &argc, &argv, NULL);
|
||||
g_option_context_free(options);
|
||||
if (!video_output_init(&argc, argv, g_options))
|
||||
g_error("failed to initialize video output subsystem");
|
||||
|
||||
if (!g_codec_str)
|
||||
g_codec_str = g_strdup("h264");
|
||||
|
@ -115,18 +109,18 @@ main(int argc, char *argv[])
|
|||
if (!codec)
|
||||
g_error("no %s codec data found", g_codec_str);
|
||||
|
||||
display = gst_vaapi_display_x11_new(NULL);
|
||||
display = video_output_create_display(NULL);
|
||||
if (!display)
|
||||
g_error("could not create VA display");
|
||||
|
||||
if (CHECK_DISPLAY_CACHE)
|
||||
display2 = gst_vaapi_display_x11_new(NULL);
|
||||
display2 = video_output_create_display(NULL);
|
||||
else
|
||||
display2 = g_object_ref(display);
|
||||
if (!display2)
|
||||
g_error("could not create second VA display");
|
||||
|
||||
window = gst_vaapi_window_x11_new(display, win_width, win_height);
|
||||
window = video_output_create_window(display, win_width, win_height);
|
||||
if (!window)
|
||||
g_error("could not create window");
|
||||
|
||||
|
@ -200,6 +194,6 @@ main(int argc, char *argv[])
|
|||
g_object_unref(display);
|
||||
g_object_unref(display2);
|
||||
g_free(g_codec_str);
|
||||
gst_deinit();
|
||||
video_output_exit();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -22,11 +22,10 @@
|
|||
|
||||
#include "config.h"
|
||||
#include <string.h>
|
||||
#include <gst/vaapi/gstvaapidisplay_x11.h>
|
||||
#include <gst/vaapi/gstvaapiwindow_x11.h>
|
||||
#include <gst/vaapi/gstvaapidecoder.h>
|
||||
#include <gst/vaapi/gstvaapidecoder_mpeg2.h>
|
||||
#include <gst/vaapi/gstvaapisurface.h>
|
||||
#include "output.h"
|
||||
#include "test-mpeg2.h"
|
||||
#include "test-subpicture-data.h"
|
||||
|
||||
|
@ -87,7 +86,6 @@ upload_image (guint8 *dst, const guint32 *src, guint size)
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
GOptionContext *options;
|
||||
GstVaapiDisplay *display;
|
||||
GstVaapiWindow *window;
|
||||
GstVaapiDecoder *decoder = NULL;
|
||||
|
@ -109,12 +107,8 @@ main(int argc, char *argv[])
|
|||
static const guint win_width = 640;
|
||||
static const guint win_height = 480;
|
||||
|
||||
gst_init(&argc, &argv);
|
||||
|
||||
options = g_option_context_new(" - test-decode options");
|
||||
g_option_context_add_main_entries(options, g_options, NULL);
|
||||
g_option_context_parse(options, &argc, &argv, NULL);
|
||||
g_option_context_free(options);
|
||||
if (!video_output_init(&argc, argv, g_options))
|
||||
g_error("failed to initialize video output subsystem");
|
||||
|
||||
if (!g_codec_str)
|
||||
g_codec_str = g_strdup("mpeg2");
|
||||
|
@ -124,11 +118,11 @@ main(int argc, char *argv[])
|
|||
if (!codec)
|
||||
g_error("no %s codec data found", g_codec_str);
|
||||
|
||||
display = gst_vaapi_display_x11_new(NULL);
|
||||
display = video_output_create_display(NULL);
|
||||
if (!display)
|
||||
g_error("could not create VA display");
|
||||
|
||||
window = gst_vaapi_window_x11_new(display, win_width, win_height);
|
||||
window = video_output_create_window(display, win_width, win_height);
|
||||
if (!window)
|
||||
g_error("could not create window");
|
||||
|
||||
|
@ -230,6 +224,6 @@ main(int argc, char *argv[])
|
|||
g_object_unref(window);
|
||||
g_object_unref(display);
|
||||
g_free(g_codec_str);
|
||||
gst_deinit();
|
||||
video_output_exit();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include <gst/vaapi/gstvaapisurface.h>
|
||||
#include <gst/vaapi/gstvaapisurfacepool.h>
|
||||
#include <gst/vaapi/gstvaapidisplay_x11.h>
|
||||
#include "output.h"
|
||||
|
||||
#define MAX_SURFACES 4
|
||||
|
||||
|
@ -46,9 +46,10 @@ main(int argc, char *argv[])
|
|||
static const guint width = 320;
|
||||
static const guint height = 240;
|
||||
|
||||
gst_init(&argc, &argv);
|
||||
if (!video_output_init(&argc, argv, NULL))
|
||||
g_error("failed to initialize video output subsystem");
|
||||
|
||||
display = gst_vaapi_display_x11_new(NULL);
|
||||
display = video_output_create_display(NULL);
|
||||
if (!display)
|
||||
g_error("could not create Gst/VA display");
|
||||
|
||||
|
@ -126,6 +127,6 @@ main(int argc, char *argv[])
|
|||
g_object_unref(pool);
|
||||
g_print("unref surface\n");
|
||||
g_object_unref(surface);
|
||||
gst_deinit();
|
||||
video_output_exit();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue