~ubuntu-branches/ubuntu/quantal/gstreamer-vaapi/quantal

« back to all changes in this revision

Viewing changes to tests/test-surfaces.c

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2012-02-10 14:35:09 UTC
  • Revision ID: package-import@ubuntu.com-20120210143509-wq9j8uqb5leu1iik
Tags: upstream-0.3.4
ImportĀ upstreamĀ versionĀ 0.3.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  test-surfaces.c - Test GstVaapiSurface and GstVaapiSurfacePool
 
3
 *
 
4
 *  Copyright (C) 2010-2011 Splitted-Desktop Systems
 
5
 *
 
6
 *  This library is free software; you can redistribute it and/or
 
7
 *  modify it under the terms of the GNU Lesser General Public License
 
8
 *  as published by the Free Software Foundation; either version 2.1
 
9
 *  of the License, or (at your option) any later version.
 
10
 *
 
11
 *  This library 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 GNU
 
14
 *  Lesser General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU Lesser General Public
 
17
 *  License along with this library; if not, write to the Free
 
18
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
 *  Boston, MA 02110-1301 USA
 
20
 */
 
21
 
 
22
#include <gst/vaapi/gstvaapisurface.h>
 
23
#include <gst/vaapi/gstvaapisurfacepool.h>
 
24
#include <gst/vaapi/gstvaapidisplay_x11.h>
 
25
 
 
26
#define MAX_SURFACES 4
 
27
 
 
28
static void
 
29
gst_vaapi_object_destroy_cb(gpointer object, gpointer user_data)
 
30
{
 
31
    g_print("destroying GstVaapiObject %p\n", object);
 
32
}
 
33
 
 
34
int
 
35
main(int argc, char *argv[])
 
36
{
 
37
    GstVaapiDisplay    *display;
 
38
    GstVaapiSurface    *surface;
 
39
    GstVaapiID          surface_id;
 
40
    GstVaapiSurface    *surfaces[MAX_SURFACES];
 
41
    GstVaapiVideoPool  *pool;
 
42
    GstCaps            *caps;
 
43
    gint                i;
 
44
 
 
45
    static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
 
46
    static const guint              width       = 320;
 
47
    static const guint              height      = 240;
 
48
 
 
49
    gst_init(&argc, &argv);
 
50
 
 
51
    display = gst_vaapi_display_x11_new(NULL);
 
52
    if (!display)
 
53
        g_error("could not create Gst/VA display");
 
54
 
 
55
    surface = gst_vaapi_surface_new(display, chroma_type, width, height);
 
56
    if (!surface)
 
57
        g_error("could not create Gst/VA surface");
 
58
 
 
59
    /* This also tests for the GstVaapiParamSpecID */
 
60
    g_object_get(G_OBJECT(surface), "id", &surface_id, NULL);
 
61
    if (surface_id != gst_vaapi_surface_get_id(surface))
 
62
        g_error("could not retrieve the native surface ID");
 
63
    g_print("created surface %" GST_VAAPI_ID_FORMAT "\n",
 
64
            GST_VAAPI_ID_ARGS(surface_id));
 
65
 
 
66
    g_object_unref(surface);
 
67
 
 
68
    caps = gst_caps_new_simple(
 
69
        GST_VAAPI_SURFACE_CAPS_NAME,
 
70
        "type", G_TYPE_STRING, "vaapi",
 
71
        "width", G_TYPE_INT, width,
 
72
        "height", G_TYPE_INT, height,
 
73
        NULL
 
74
    );
 
75
    if (!caps)
 
76
        g_error("cound not create Gst/VA surface caps");
 
77
 
 
78
    pool = gst_vaapi_surface_pool_new(display, caps);
 
79
    if (!pool)
 
80
        g_error("could not create Gst/VA surface pool");
 
81
 
 
82
    for (i = 0; i < MAX_SURFACES; i++) {
 
83
        surface = gst_vaapi_video_pool_get_object(pool);
 
84
        if (!surface)
 
85
            g_error("could not allocate Gst/VA surface from pool");
 
86
        g_print("created surface %" GST_VAAPI_ID_FORMAT " from pool\n",
 
87
                GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surface)));
 
88
        surfaces[i] = surface;
 
89
    }
 
90
 
 
91
    /* Check the pool doesn't return the last free'd surface */
 
92
    surface = g_object_ref(surfaces[1]);
 
93
 
 
94
    for (i = 0; i < 2; i++)
 
95
        gst_vaapi_video_pool_put_object(pool, surfaces[i]);
 
96
 
 
97
    for (i = 0; i < 2; i++) {
 
98
        surfaces[i] = gst_vaapi_video_pool_get_object(pool);
 
99
        if (!surfaces[i])
 
100
            g_error("could not re-allocate Gst/VA surface%d from pool", i);
 
101
        g_print("created surface %" GST_VAAPI_ID_FORMAT " from pool (realloc)\n",
 
102
                GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surfaces[i])));
 
103
    }
 
104
 
 
105
    if (surface == surfaces[0])
 
106
        g_error("Gst/VA pool doesn't queue free surfaces");
 
107
 
 
108
    for (i = MAX_SURFACES - 1; i >= 0; i--) {
 
109
        if (!surfaces[i])
 
110
            continue;
 
111
        gst_vaapi_video_pool_put_object(pool, surfaces[i]);
 
112
        surfaces[i] = NULL;
 
113
    }
 
114
 
 
115
    g_signal_connect(
 
116
        G_OBJECT(surface),
 
117
        "destroy",
 
118
        G_CALLBACK(gst_vaapi_object_destroy_cb), NULL
 
119
    );
 
120
 
 
121
    /* Unref in random order to check objects are correctly refcounted */
 
122
    g_print("unref display\n");
 
123
    g_object_unref(display);
 
124
    gst_caps_unref(caps);
 
125
    g_print("unref pool\n");
 
126
    g_object_unref(pool);
 
127
    g_print("unref surface\n");
 
128
    g_object_unref(surface);
 
129
    gst_deinit();
 
130
    return 0;
 
131
}