Tizen 2.0 Release
[framework/multimedia/gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapiimagepool.c
1 /*
2  *  gstvaapiimagepool.c - Gst VA image pool
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 /**
23  * SECTION:gstvaapiimagepool
24  * @short_description: VA image pool
25  */
26
27 #include "sysdeps.h"
28 #include "gstvaapiimagepool.h"
29
30 #define DEBUG 1
31 #include "gstvaapidebug.h"
32
33 G_DEFINE_TYPE(
34     GstVaapiImagePool,
35     gst_vaapi_image_pool,
36     GST_VAAPI_TYPE_VIDEO_POOL);
37
38 #define GST_VAAPI_IMAGE_POOL_GET_PRIVATE(obj)                   \
39     (G_TYPE_INSTANCE_GET_PRIVATE((obj),                         \
40                                  GST_VAAPI_TYPE_IMAGE_POOL,     \
41                                  GstVaapiImagePoolPrivate))
42
43 struct _GstVaapiImagePoolPrivate {
44     GstVaapiImageFormat format;
45     guint               width;
46     guint               height;
47 };
48
49 static void
50 gst_vaapi_image_pool_set_caps(GstVaapiVideoPool *pool, GstCaps *caps)
51 {
52     GstVaapiImagePoolPrivate * const priv = GST_VAAPI_IMAGE_POOL(pool)->priv;
53     GstStructure *structure;
54     gint width, height;
55
56     structure = gst_caps_get_structure(caps, 0);
57     gst_structure_get_int(structure, "width", &width);
58     gst_structure_get_int(structure, "height", &height);
59
60     priv->format        = gst_vaapi_image_format_from_caps(caps);
61     priv->width         = width;
62     priv->height        = height;
63 }
64
65 gpointer
66 gst_vaapi_image_pool_alloc_object(
67     GstVaapiVideoPool *pool,
68     GstVaapiDisplay   *display
69 )
70 {
71     GstVaapiImagePoolPrivate * const priv = GST_VAAPI_IMAGE_POOL(pool)->priv;
72
73     return gst_vaapi_image_new(display,
74                                priv->format,
75                                priv->width,
76                                priv->height);
77 }
78
79 static void
80 gst_vaapi_image_pool_finalize(GObject *object)
81 {
82     G_OBJECT_CLASS(gst_vaapi_image_pool_parent_class)->finalize(object);
83 }
84
85 static void
86 gst_vaapi_image_pool_class_init(GstVaapiImagePoolClass *klass)
87 {
88     GObjectClass * const object_class = G_OBJECT_CLASS(klass);
89     GstVaapiVideoPoolClass * const pool_class = GST_VAAPI_VIDEO_POOL_CLASS(klass);
90
91     g_type_class_add_private(klass, sizeof(GstVaapiImagePoolPrivate));
92
93     object_class->finalize      = gst_vaapi_image_pool_finalize;
94
95     pool_class->set_caps        = gst_vaapi_image_pool_set_caps;
96     pool_class->alloc_object    = gst_vaapi_image_pool_alloc_object;
97 }
98
99 static void
100 gst_vaapi_image_pool_init(GstVaapiImagePool *pool)
101 {
102     GstVaapiImagePoolPrivate *priv = GST_VAAPI_IMAGE_POOL_GET_PRIVATE(pool);
103
104     pool->priv          = priv;
105     priv->format        = 0;
106     priv->width         = 0;
107     priv->height        = 0;
108 }
109
110 /**
111  * gst_vaapi_image_pool_new:
112  * @display: a #GstVaapiDisplay
113  * @caps: a #GstCaps
114  *
115  * Creates a new #GstVaapiVideoPool of #GstVaapiImage with the
116  * specified dimensions in @caps.
117  *
118  * Return value: the newly allocated #GstVaapiVideoPool
119  */
120 GstVaapiVideoPool *
121 gst_vaapi_image_pool_new(GstVaapiDisplay *display, GstCaps *caps)
122 {
123     return g_object_new(GST_VAAPI_TYPE_IMAGE_POOL,
124                         "display", display,
125                         "caps",    caps,
126                         NULL);
127 }