gstvaapiimagepool.c 3.35 KB
Newer Older
1 2 3
/*
 *  gstvaapiimagepool.c - Gst VA image pool
 *
4
 *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5
 *    Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6
 *  Copyright (C) 2012 Intel Corporation
7
 *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
8
 *
gb's avatar
gb committed
9 10 11 12
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2.1
 *  of the License, or (at your option) any later version.
13
 *
gb's avatar
gb committed
14
 *  This library is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
gb's avatar
gb committed
16 17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
18
 *
gb's avatar
gb committed
19 20 21 22
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301 USA
23 24
 */

25
/**
gb's avatar
gb committed
26 27
 * SECTION:gstvaapiimagepool
 * @short_description: VA image pool
28 29
 */

30
#include "sysdeps.h"
31
#include "gstvaapiimagepool.h"
32
#include "gstvaapivideopool_priv.h"
33 34

#define DEBUG 1
gb's avatar
gb committed
35
#include "gstvaapidebug.h"
36

37 38 39 40 41 42 43 44
/**
 * GstVaapiImagePool:
 *
 * A pool of lazily allocated #GstVaapiImage objects.
 */
struct _GstVaapiImagePool {
    /*< private >*/
    GstVaapiVideoPool   parent_instance;
45

46
    GstVideoFormat      format;
47 48 49 50
    guint               width;
    guint               height;
};

51
static gboolean
52
image_pool_init(GstVaapiVideoPool *base_pool, const GstVideoInfo *vip)
53
{
54
    GstVaapiImagePool * const pool = GST_VAAPI_IMAGE_POOL(base_pool);
55

56 57 58
    pool->format = GST_VIDEO_INFO_FORMAT(vip);
    pool->width  = GST_VIDEO_INFO_WIDTH(vip);
    pool->height = GST_VIDEO_INFO_HEIGHT(vip);
59
    return gst_vaapi_display_has_image_format(base_pool->display, pool->format);
60 61
}

62 63
static gpointer
gst_vaapi_image_pool_alloc_object(GstVaapiVideoPool *base_pool)
64
{
65
    GstVaapiImagePool * const pool = GST_VAAPI_IMAGE_POOL(base_pool);
66

67 68
    return gst_vaapi_image_new(base_pool->display, pool->format,
        pool->width, pool->height);
69 70
}

71 72
static inline const GstVaapiMiniObjectClass *
gst_vaapi_image_pool_class(void)
73
{
74 75 76
    static const GstVaapiVideoPoolClass GstVaapiImagePoolClass = {
        { sizeof(GstVaapiImagePool),
          (GDestroyNotify)gst_vaapi_video_pool_finalize },
77

78 79 80
        .alloc_object   = gst_vaapi_image_pool_alloc_object
    };
    return GST_VAAPI_MINI_OBJECT_CLASS(&GstVaapiImagePoolClass);
81 82
}

83 84 85
/**
 * gst_vaapi_image_pool_new:
 * @display: a #GstVaapiDisplay
86
 * @vip: the #GstVideoInfo
87 88
 *
 * Creates a new #GstVaapiVideoPool of #GstVaapiImage with the
89
 * specified format and dimensions in @vip.
90 91 92
 *
 * Return value: the newly allocated #GstVaapiVideoPool
 */
93
GstVaapiVideoPool *
94
gst_vaapi_image_pool_new(GstVaapiDisplay *display, const GstVideoInfo *vip)
95
{
96 97
    GstVaapiVideoPool *pool;

98
    g_return_val_if_fail(display != NULL, NULL);
99
    g_return_val_if_fail(vip != NULL, NULL);
100 101 102 103 104 105

    pool = (GstVaapiVideoPool *)
        gst_vaapi_mini_object_new(gst_vaapi_image_pool_class());
    if (!pool)
        return NULL;

106 107
    gst_vaapi_video_pool_init(pool, display,
        GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_IMAGE);
108 109

    if (!image_pool_init(pool, vip))
110 111 112 113 114 115
        goto error;
    return pool;

error:
    gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(pool));
    return NULL;
116
}