summaryrefslogtreecommitdiff
path: root/sys/vdpau/gstvdp/gstvdpvideobufferpool.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/vdpau/gstvdp/gstvdpvideobufferpool.c')
-rw-r--r--sys/vdpau/gstvdp/gstvdpvideobufferpool.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/sys/vdpau/gstvdp/gstvdpvideobufferpool.c b/sys/vdpau/gstvdp/gstvdpvideobufferpool.c
new file mode 100644
index 000000000..889367d98
--- /dev/null
+++ b/sys/vdpau/gstvdp/gstvdpvideobufferpool.c
@@ -0,0 +1,146 @@
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2/*
3 * gst-plugins-bad
4 * Copyright (C) Carl-Anton Ingmarsson 2010 <ca.ingmarsson@gmail.com>
5 *
6 * gst-plugins-bad is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * gst-plugins-bad is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "gstvdpdevice.h"
21#include "gstvdpvideobuffer.h"
22
23#include "gstvdpvideobufferpool.h"
24
25
26struct _GstVdpVideoBufferPool
27{
28 GstVdpBufferPool buffer_pool;
29
30 VdpChromaType chroma_type;
31 guint width, height;
32};
33
34G_DEFINE_TYPE (GstVdpVideoBufferPool, gst_vdp_video_buffer_pool,
35 GST_TYPE_VDP_BUFFER_POOL);
36
37GstVdpBufferPool *
38gst_vdp_video_buffer_pool_new (GstVdpDevice * device)
39{
40 g_return_val_if_fail (GST_IS_VDP_DEVICE (device), NULL);
41
42 return g_object_new (GST_TYPE_VDP_VIDEO_BUFFER_POOL, "device", device, NULL);
43}
44
45static gboolean
46parse_caps (const GstCaps * caps, VdpChromaType * chroma_type, gint * width,
47 gint * height)
48{
49 GstStructure *structure;
50
51 structure = gst_caps_get_structure (caps, 0);
52
53 if (!gst_structure_get_int (structure, "chroma-type", (gint *) chroma_type))
54 return FALSE;
55 if (!gst_structure_get_int (structure, "width", width))
56 return FALSE;
57 if (!gst_structure_get_int (structure, "height", height))
58 return FALSE;
59
60 return TRUE;
61}
62
63static gboolean
64gst_vdp_video_buffer_pool_check_caps (GstVdpBufferPool * bpool,
65 const GstCaps * caps)
66{
67 GstVdpVideoBufferPool *vpool = GST_VDP_VIDEO_BUFFER_POOL (bpool);
68
69 VdpChromaType chroma_type;
70 gint width, height;
71
72 if (!parse_caps (caps, &chroma_type, &width, &height))
73 return FALSE;
74
75 if (chroma_type != vpool->chroma_type || width != vpool->width ||
76 height != vpool->height)
77 return FALSE;
78
79 return TRUE;
80}
81
82static gboolean
83gst_vdp_video_buffer_pool_set_caps (GstVdpBufferPool * bpool,
84 const GstCaps * caps, gboolean * clear_bufs)
85{
86 GstVdpVideoBufferPool *vpool = GST_VDP_VIDEO_BUFFER_POOL (bpool);
87
88 VdpChromaType chroma_type;
89 gint width, height;
90
91 if (!parse_caps (caps, &chroma_type, &width, &height))
92 return FALSE;
93
94 if (chroma_type != vpool->chroma_type || width != vpool->width ||
95 height != vpool->height)
96 *clear_bufs = TRUE;
97 else
98 *clear_bufs = FALSE;
99
100 vpool->chroma_type = chroma_type;
101 vpool->width = width;
102 vpool->height = height;
103
104 return TRUE;
105}
106
107static GstVdpBuffer *
108gst_vdp_video_buffer_pool_alloc_buffer (GstVdpBufferPool * bpool,
109 GError ** error)
110{
111 GstVdpVideoBufferPool *vpool = GST_VDP_VIDEO_BUFFER_POOL (bpool);
112 GstVdpDevice *device;
113
114 device = gst_vdp_buffer_pool_get_device (bpool);
115 return GST_VDP_BUFFER_CAST (gst_vdp_video_buffer_new (device,
116 vpool->chroma_type, vpool->width, vpool->height, error));
117}
118
119static void
120gst_vdp_video_buffer_pool_finalize (GObject * object)
121{
122 /* TODO: Add deinitalization code here */
123
124 G_OBJECT_CLASS (gst_vdp_video_buffer_pool_parent_class)->finalize (object);
125}
126
127static void
128gst_vdp_video_buffer_pool_init (GstVdpVideoBufferPool * vpool)
129{
130 vpool->chroma_type = -1;
131 vpool->width = 0;
132 vpool->height = 0;
133}
134
135static void
136gst_vdp_video_buffer_pool_class_init (GstVdpVideoBufferPoolClass * klass)
137{
138 GObjectClass *object_class = G_OBJECT_CLASS (klass);
139 GstVdpBufferPoolClass *buffer_pool_class = GST_VDP_BUFFER_POOL_CLASS (klass);
140
141 buffer_pool_class->alloc_buffer = gst_vdp_video_buffer_pool_alloc_buffer;
142 buffer_pool_class->set_caps = gst_vdp_video_buffer_pool_set_caps;
143 buffer_pool_class->check_caps = gst_vdp_video_buffer_pool_check_caps;
144
145 object_class->finalize = gst_vdp_video_buffer_pool_finalize;
146}