summaryrefslogtreecommitdiff
path: root/tests/examples/generic/test-display.c
blob: dbbf1f987fdc09cc638244129877ef5d2dc61bb1 (plain)
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
/*
 *  test-display.c - Test GstVaapiDisplayX11
 *
 *  gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#include <gst/video/video.h>
#include <gst/vaapi/gstvaapidisplay_x11.h>

static void
print_caps(GstCaps *caps, const gchar *name)
{
    guint i, n_caps = gst_caps_get_size(caps);

    g_print("%u %s caps\n", n_caps, name);

    for (i = 0; i < gst_caps_get_size(caps); i++) {
        GstStructure * const structure = gst_caps_get_structure(caps, i);
        if (!structure)
            g_error("could not get caps structure %d", i);

        g_print("  %s:", gst_structure_get_name(structure));

        if (gst_structure_has_name(structure, "video/x-raw-yuv")) {
            guint32 fourcc;

            gst_structure_get_fourcc(structure, "format", &fourcc);

            g_print(" fourcc '%c%c%c%c'",
                    fourcc & 0xff,
                    (fourcc >> 8) & 0xff,
                    (fourcc >> 16) & 0xff,
                    (fourcc >> 24) & 0xff);
        }
        else {
            gint bpp, endian, rmask, gmask, bmask, amask;
            gboolean has_alpha;

            gst_structure_get_int(structure, "bpp",         &bpp);
            gst_structure_get_int(structure, "endianness",  &endian);
            gst_structure_get_int(structure, "red_mask",    &rmask);
            gst_structure_get_int(structure, "blue_mask",   &bmask);
            gst_structure_get_int(structure, "green_mask",  &gmask);
            has_alpha = gst_structure_get_int(structure, "alpha_mask", &amask);

            g_print(" %d bits per pixel, %s endian,",
                    bpp, endian == G_BIG_ENDIAN ? "big" : "little");
            g_print(" %s masks", has_alpha ? "rgba" : "rgb");
            g_print(" 0x%08x 0x%08x 0x%08x", rmask, gmask, bmask);
            if (has_alpha)
                g_print(" 0x%08x", amask);
        }
        g_print("\n");
    }
}

int
main(int argc, char *argv[])
{
    GstVaapiDisplay *display;
    GstCaps *caps;

    gst_init(&argc, &argv);

    display = gst_vaapi_display_x11_new(NULL);
    if (!display)
        g_error("could not create VA-API display");

    caps = gst_vaapi_display_get_image_caps(display);
    if (!caps)
        g_error("could not get VA image caps");

    print_caps(caps, "image");
    gst_caps_unref(caps);

    caps = gst_vaapi_display_get_subpicture_caps(display);
    if (!caps)
        g_error("could not get VA subpicture caps");

    print_caps(caps, "subpicture");
    gst_caps_unref(caps);

    g_object_unref(display);
    gst_deinit();
    return 0;
}