Add initial VA/GLX support.
[profile/ivi/gstreamer-vaapi.git] / tests / test-textures.c
1 /*
2  *  test-textures.c - Test GstVaapiTexture
3  *
4  *  gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program 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
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19  */
20
21 #include <gst/vaapi/gstvaapidisplay_glx.h>
22 #include <gst/vaapi/gstvaapiwindow_glx.h>
23
24 static inline void pause(void)
25 {
26     g_print("Press any key to continue...\n");
27     getchar();
28 }
29
30 static void
31 print_caps(GstCaps *caps, const gchar *name)
32 {
33     guint i, n_caps = gst_caps_get_size(caps);
34
35     g_print("%u %s caps\n", n_caps, name);
36
37     for (i = 0; i < gst_caps_get_size(caps); i++) {
38         GstStructure * const structure = gst_caps_get_structure(caps, i);
39         if (!structure)
40             g_error("could not get caps structure %d", i);
41
42         g_print("  %s:", gst_structure_get_name(structure));
43
44         if (gst_structure_has_name(structure, "video/x-raw-yuv")) {
45             guint32 fourcc;
46
47             gst_structure_get_fourcc(structure, "format", &fourcc);
48
49             g_print(" fourcc '%c%c%c%c'",
50                     fourcc & 0xff,
51                     (fourcc >> 8) & 0xff,
52                     (fourcc >> 16) & 0xff,
53                     (fourcc >> 24) & 0xff);
54         }
55         else {
56             gint bpp, endian, rmask, gmask, bmask, amask;
57             gboolean has_alpha;
58
59             gst_structure_get_int(structure, "bpp",         &bpp);
60             gst_structure_get_int(structure, "endianness",  &endian);
61             gst_structure_get_int(structure, "red_mask",    &rmask);
62             gst_structure_get_int(structure, "blue_mask",   &bmask);
63             gst_structure_get_int(structure, "green_mask",  &gmask);
64             has_alpha = gst_structure_get_int(structure, "alpha_mask", &amask);
65
66             g_print(" %d bits per pixel, %s endian,",
67                     bpp, endian == G_BIG_ENDIAN ? "big" : "little");
68             g_print(" %s masks", has_alpha ? "rgba" : "rgb");
69             g_print(" 0x%08x 0x%08x 0x%08x", rmask, gmask, bmask);
70             if (has_alpha)
71                 g_print(" 0x%08x", amask);
72         }
73         g_print("\n");
74     }
75 }
76
77 static void
78 dump_caps(GstVaapiDisplay *display)
79 {
80     GstCaps *caps;
81
82     caps = gst_vaapi_display_get_image_caps(display);
83     if (!caps)
84         g_error("could not get VA image caps");
85
86     print_caps(caps, "image");
87     gst_caps_unref(caps);
88
89     caps = gst_vaapi_display_get_subpicture_caps(display);
90     if (!caps)
91         g_error("could not get VA subpicture caps");
92
93     print_caps(caps, "subpicture");
94     gst_caps_unref(caps);
95 }
96
97 int
98 main(int argc, char *argv[])
99 {
100     GstVaapiDisplay    *display;
101     GstVaapiWindow     *window;
102     GstVaapiWindowGLX  *glx_window;
103     GLXContext          glx_context;
104     Display            *x11_display;
105     Window              x11_window;
106
107     static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
108     static const guint              width       = 320;
109     static const guint              height      = 240;
110     static const guint              win_width   = 640;
111     static const guint              win_height  = 480;
112
113     gst_init(&argc, &argv);
114
115     display = gst_vaapi_display_glx_new(NULL);
116     if (!display)
117         g_error("could not create Gst/VA display");
118
119     dump_caps(display);
120
121     window = gst_vaapi_window_glx_new(display, win_width, win_height);
122     if (!window)
123         g_error("could not create window");
124
125     gst_vaapi_window_show(window);
126
127     glx_window  = GST_VAAPI_WINDOW_GLX(window);
128     glx_context = gst_vaapi_window_glx_get_context(glx_window);
129     x11_display = gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(display));
130     x11_window  = gst_vaapi_object_get_id(GST_VAAPI_OBJECT(window));
131
132     if (!glXMakeCurrent(x11_display, x11_window, glx_context))
133         g_error("could not make VA/GLX window context current");
134
135     pause();
136
137     g_object_unref(window);
138     g_object_unref(display);
139     gst_deinit();
140     return 0;
141 }