Add initial VA/GLX support.
[profile/ivi/gstreamer-vaapi.git] / tests / test-display.c
1 /*
2  *  test-display.c - Test GstVaapiDisplayX11
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/video/video.h>
22 #include <gst/vaapi/gstvaapidisplay_x11.h>
23
24 static void
25 print_caps(GstCaps *caps, const gchar *name)
26 {
27     guint i, n_caps = gst_caps_get_size(caps);
28
29     g_print("%u %s caps\n", n_caps, name);
30
31     for (i = 0; i < gst_caps_get_size(caps); i++) {
32         GstStructure * const structure = gst_caps_get_structure(caps, i);
33         if (!structure)
34             g_error("could not get caps structure %d", i);
35
36         g_print("  %s:", gst_structure_get_name(structure));
37
38         if (gst_structure_has_name(structure, "video/x-raw-yuv")) {
39             guint32 fourcc;
40
41             gst_structure_get_fourcc(structure, "format", &fourcc);
42
43             g_print(" fourcc '%c%c%c%c'",
44                     fourcc & 0xff,
45                     (fourcc >> 8) & 0xff,
46                     (fourcc >> 16) & 0xff,
47                     (fourcc >> 24) & 0xff);
48         }
49         else {
50             gint bpp, endian, rmask, gmask, bmask, amask;
51             gboolean has_alpha;
52
53             gst_structure_get_int(structure, "bpp",         &bpp);
54             gst_structure_get_int(structure, "endianness",  &endian);
55             gst_structure_get_int(structure, "red_mask",    &rmask);
56             gst_structure_get_int(structure, "blue_mask",   &bmask);
57             gst_structure_get_int(structure, "green_mask",  &gmask);
58             has_alpha = gst_structure_get_int(structure, "alpha_mask", &amask);
59
60             g_print(" %d bits per pixel, %s endian,",
61                     bpp, endian == G_BIG_ENDIAN ? "big" : "little");
62             g_print(" %s masks", has_alpha ? "rgba" : "rgb");
63             g_print(" 0x%08x 0x%08x 0x%08x", rmask, gmask, bmask);
64             if (has_alpha)
65                 g_print(" 0x%08x", amask);
66         }
67         g_print("\n");
68     }
69 }
70
71 static void
72 dump_caps(GstVaapiDisplay *display)
73 {
74     GstCaps *caps;
75
76     caps = gst_vaapi_display_get_image_caps(display);
77     if (!caps)
78         g_error("could not get VA image caps");
79
80     print_caps(caps, "image");
81     gst_caps_unref(caps);
82
83     caps = gst_vaapi_display_get_subpicture_caps(display);
84     if (!caps)
85         g_error("could not get VA subpicture caps");
86
87     print_caps(caps, "subpicture");
88     gst_caps_unref(caps);
89 }
90
91 int
92 main(int argc, char *argv[])
93 {
94     Display *x11_display;
95     VADisplay va_display;
96     GstVaapiDisplay *display;
97     guint width, height, par_n, par_d;
98
99     gst_init(&argc, &argv);
100
101     g_print("#\n");
102     g_print("# Create display with gst_vaapi_display_x11_new()\n");
103     g_print("#\n");
104     {
105         display = gst_vaapi_display_x11_new(NULL);
106         if (!display)
107             g_error("could not create Gst/VA display");
108
109         gst_vaapi_display_get_size(display, &width, &height);
110         g_print("Display size: %ux%u\n", width, height);
111
112         gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
113         g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);
114
115         dump_caps(display);
116         g_object_unref(display);
117     }
118     g_print("\n");
119
120     g_print("#\n");
121     g_print("# Create display with gst_vaapi_display_x11_new_with_display()\n");
122     g_print("#\n");
123     {
124         x11_display = XOpenDisplay(NULL);
125         if (!x11_display)
126             g_error("could not create X11 display");
127
128         display = gst_vaapi_display_x11_new_with_display(x11_display);
129         if (!display)
130             g_error("could not create Gst/VA display");
131
132         dump_caps(display);
133         g_object_unref(display);
134         XCloseDisplay(x11_display);
135     }
136     g_print("\n");
137
138     g_print("#\n");
139     g_print("# Create display with gst_vaapi_display_new_with_display()\n");
140     g_print("#\n");
141     {
142         x11_display = XOpenDisplay(NULL);
143         if (!x11_display)
144             g_error("could not create X11 display");
145
146         va_display = vaGetDisplay(x11_display);
147         if (!va_display)
148             g_error("could not create VA display");
149
150         display = gst_vaapi_display_new_with_display(va_display);
151         if (!display)
152             g_error("could not create Gst/VA display");
153
154         dump_caps(display);
155         g_object_unref(display);
156         XCloseDisplay(x11_display);
157     }
158     g_print("\n");
159
160     gst_deinit();
161     return 0;
162 }