diff options
author | Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com> | 2010-07-30 11:06:17 +0200 |
---|---|---|
committer | Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com> | 2010-07-30 11:33:13 +0200 |
commit | 2d9132c590ca2ee54a03b44733a4d0544cb7ec6c (patch) | |
tree | f2a544ec425ea7d5a68f139f91554ea90af2fa79 | |
parent | d82c4acd8a6f7580c3ff69a356920e51a8096423 (diff) |
vdpau: add GstVdpOutputBufferPool
GstVdpVideoOutputPool is a subclass of GstVdpBufferPool that caches
GstVdpOutputBuffers
-rw-r--r-- | sys/vdpau/gstvdp/Makefile.am | 2 | ||||
-rw-r--r-- | sys/vdpau/gstvdp/gstvdpoutputbuffer.c | 21 | ||||
-rw-r--r-- | sys/vdpau/gstvdp/gstvdpoutputbuffer.h | 5 | ||||
-rw-r--r-- | sys/vdpau/gstvdp/gstvdpoutputbufferpool.c | 146 | ||||
-rw-r--r-- | sys/vdpau/gstvdp/gstvdpoutputbufferpool.h | 50 | ||||
-rw-r--r-- | sys/vdpau/gstvdp/gstvdpoutputsrcpad.c | 2 | ||||
-rw-r--r-- | sys/vdpau/gstvdpsink.c | 2 |
7 files changed, 216 insertions, 12 deletions
diff --git a/sys/vdpau/gstvdp/Makefile.am b/sys/vdpau/gstvdp/Makefile.am index c79ca55c0..375969087 100644 --- a/sys/vdpau/gstvdp/Makefile.am +++ b/sys/vdpau/gstvdp/Makefile.am | |||
@@ -8,6 +8,7 @@ libgstvdp_@GST_MAJORMINOR@_la_SOURCES = \ | |||
8 | gstvdpvideobuffer.c \ | 8 | gstvdpvideobuffer.c \ |
9 | gstvdpvideobufferpool.c \ | 9 | gstvdpvideobufferpool.c \ |
10 | gstvdpoutputbuffer.c \ | 10 | gstvdpoutputbuffer.c \ |
11 | gstvdpoutputbufferpool.c \ | ||
11 | gstvdpvideosrcpad.c \ | 12 | gstvdpvideosrcpad.c \ |
12 | gstvdpoutputsrcpad.c \ | 13 | gstvdpoutputsrcpad.c \ |
13 | gstvdpdecoder.c \ | 14 | gstvdpdecoder.c \ |
@@ -22,6 +23,7 @@ libgstvdp_@GST_MAJORMINOR@include_HEADERS = \ | |||
22 | gstvdpvideobuffer.h \ | 23 | gstvdpvideobuffer.h \ |
23 | gstvdpvideobufferpool.h \ | 24 | gstvdpvideobufferpool.h \ |
24 | gstvdpoutputbuffer.h \ | 25 | gstvdpoutputbuffer.h \ |
26 | gstvdpoutputbufferpool.h \ | ||
25 | gstvdpvideosrcpad.h \ | 27 | gstvdpvideosrcpad.h \ |
26 | gstvdpoutputsrcpad.h \ | 28 | gstvdpoutputsrcpad.h \ |
27 | gstvdpdecoder.h \ | 29 | gstvdpdecoder.h \ |
diff --git a/sys/vdpau/gstvdp/gstvdpoutputbuffer.c b/sys/vdpau/gstvdp/gstvdpoutputbuffer.c index 04a3cb50a..68c0cd056 100644 --- a/sys/vdpau/gstvdp/gstvdpoutputbuffer.c +++ b/sys/vdpau/gstvdp/gstvdpoutputbuffer.c | |||
@@ -32,7 +32,7 @@ GST_DEBUG_CATEGORY_INIT (gst_vdp_output_buffer_debug, "vdpoutputbuffer", 0, "VDP | |||
32 | 32 | ||
33 | GstVdpOutputBuffer * | 33 | GstVdpOutputBuffer * |
34 | gst_vdp_output_buffer_new (GstVdpDevice * device, VdpRGBAFormat rgba_format, | 34 | gst_vdp_output_buffer_new (GstVdpDevice * device, VdpRGBAFormat rgba_format, |
35 | gint width, gint height) | 35 | gint width, gint height, GError ** error) |
36 | { | 36 | { |
37 | GstVdpOutputBuffer *buffer; | 37 | GstVdpOutputBuffer *buffer; |
38 | VdpStatus status; | 38 | VdpStatus status; |
@@ -41,12 +41,8 @@ gst_vdp_output_buffer_new (GstVdpDevice * device, VdpRGBAFormat rgba_format, | |||
41 | status = | 41 | status = |
42 | device->vdp_output_surface_create (device->device, rgba_format, width, | 42 | device->vdp_output_surface_create (device->device, rgba_format, width, |
43 | height, &surface); | 43 | height, &surface); |
44 | if (status != VDP_STATUS_OK) { | 44 | if (status != VDP_STATUS_OK) |
45 | GST_ERROR ("Couldn't create a VdpOutputSurface, error returned was: %s", | 45 | goto create_error; |
46 | device->vdp_get_error_string (status)); | ||
47 | return NULL; | ||
48 | } | ||
49 | |||
50 | 46 | ||
51 | buffer = | 47 | buffer = |
52 | (GstVdpOutputBuffer *) gst_mini_object_new (GST_TYPE_VDP_OUTPUT_BUFFER); | 48 | (GstVdpOutputBuffer *) gst_mini_object_new (GST_TYPE_VDP_OUTPUT_BUFFER); |
@@ -59,6 +55,12 @@ gst_vdp_output_buffer_new (GstVdpDevice * device, VdpRGBAFormat rgba_format, | |||
59 | buffer->surface = surface; | 55 | buffer->surface = surface; |
60 | 56 | ||
61 | return buffer; | 57 | return buffer; |
58 | |||
59 | create_error: | ||
60 | g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_READ, | ||
61 | "Couldn't create a VdpOutputSurface, error returned from vdpau was: %s", | ||
62 | device->vdp_get_error_string (status)); | ||
63 | return NULL; | ||
62 | } | 64 | } |
63 | 65 | ||
64 | static GObjectClass *gst_vdp_output_buffer_parent_class; | 66 | static GObjectClass *gst_vdp_output_buffer_parent_class; |
@@ -69,6 +71,9 @@ gst_vdp_output_buffer_finalize (GstVdpOutputBuffer * buffer) | |||
69 | GstVdpDevice *device; | 71 | GstVdpDevice *device; |
70 | VdpStatus status; | 72 | VdpStatus status; |
71 | 73 | ||
74 | if (gst_vdp_buffer_revive (GST_VDP_BUFFER_CAST (buffer))) | ||
75 | return; | ||
76 | |||
72 | device = buffer->device; | 77 | device = buffer->device; |
73 | 78 | ||
74 | status = device->vdp_output_surface_destroy (buffer->surface); | 79 | status = device->vdp_output_surface_destroy (buffer->surface); |
@@ -120,7 +125,7 @@ gst_vdp_output_buffer_get_type (void) | |||
120 | (GInstanceInitFunc) gst_vdp_output_buffer_init, | 125 | (GInstanceInitFunc) gst_vdp_output_buffer_init, |
121 | NULL | 126 | NULL |
122 | }; | 127 | }; |
123 | _gst_vdp_output_buffer_type = g_type_register_static (GST_TYPE_BUFFER, | 128 | _gst_vdp_output_buffer_type = g_type_register_static (GST_TYPE_VDP_BUFFER, |
124 | "GstVdpOutputBuffer", &info, 0); | 129 | "GstVdpOutputBuffer", &info, 0); |
125 | 130 | ||
126 | DEBUG_INIT (); | 131 | DEBUG_INIT (); |
diff --git a/sys/vdpau/gstvdp/gstvdpoutputbuffer.h b/sys/vdpau/gstvdp/gstvdpoutputbuffer.h index be6a30e3c..4f2e56124 100644 --- a/sys/vdpau/gstvdp/gstvdpoutputbuffer.h +++ b/sys/vdpau/gstvdp/gstvdpoutputbuffer.h | |||
@@ -23,6 +23,7 @@ | |||
23 | 23 | ||
24 | #include <gst/gst.h> | 24 | #include <gst/gst.h> |
25 | 25 | ||
26 | #include "gstvdpbuffer.h" | ||
26 | #include "gstvdpdevice.h" | 27 | #include "gstvdpdevice.h" |
27 | 28 | ||
28 | typedef struct _GstVdpOutputBuffer GstVdpOutputBuffer; | 29 | typedef struct _GstVdpOutputBuffer GstVdpOutputBuffer; |
@@ -32,7 +33,7 @@ typedef struct _GstVdpOutputBuffer GstVdpOutputBuffer; | |||
32 | #define GST_VDP_OUTPUT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VDP_OUTPUT_BUFFER, GstVdpOutputBuffer)) | 33 | #define GST_VDP_OUTPUT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VDP_OUTPUT_BUFFER, GstVdpOutputBuffer)) |
33 | 34 | ||
34 | struct _GstVdpOutputBuffer { | 35 | struct _GstVdpOutputBuffer { |
35 | GstBuffer buffer; | 36 | GstVdpBuffer vdp_buffer; |
36 | 37 | ||
37 | GstVdpDevice *device; | 38 | GstVdpDevice *device; |
38 | VdpRGBAFormat rgba_format; | 39 | VdpRGBAFormat rgba_format; |
@@ -43,7 +44,7 @@ struct _GstVdpOutputBuffer { | |||
43 | 44 | ||
44 | GType gst_vdp_output_buffer_get_type (void); | 45 | GType gst_vdp_output_buffer_get_type (void); |
45 | 46 | ||
46 | GstVdpOutputBuffer* gst_vdp_output_buffer_new (GstVdpDevice * device, VdpRGBAFormat rgba_format, gint width, gint height); | 47 | GstVdpOutputBuffer* gst_vdp_output_buffer_new (GstVdpDevice * device, VdpRGBAFormat rgba_format, gint width, gint height, GError **error); |
47 | 48 | ||
48 | GstCaps *gst_vdp_output_buffer_get_template_caps (void); | 49 | GstCaps *gst_vdp_output_buffer_get_template_caps (void); |
49 | GstCaps *gst_vdp_output_buffer_get_allowed_caps (GstVdpDevice *device); | 50 | GstCaps *gst_vdp_output_buffer_get_allowed_caps (GstVdpDevice *device); |
diff --git a/sys/vdpau/gstvdp/gstvdpoutputbufferpool.c b/sys/vdpau/gstvdp/gstvdpoutputbufferpool.c new file mode 100644 index 000000000..826ef218b --- /dev/null +++ b/sys/vdpau/gstvdp/gstvdpoutputbufferpool.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 "gstvdpoutputbuffer.h" | ||
22 | |||
23 | #include "gstvdpoutputbufferpool.h" | ||
24 | |||
25 | |||
26 | struct _GstVdpOutputBufferPool | ||
27 | { | ||
28 | GstVdpBufferPool buffer_pool; | ||
29 | |||
30 | VdpRGBAFormat rgba_format; | ||
31 | guint width, height; | ||
32 | }; | ||
33 | |||
34 | G_DEFINE_TYPE (GstVdpOutputBufferPool, gst_vdp_output_buffer_pool, | ||
35 | GST_TYPE_VDP_BUFFER_POOL); | ||
36 | |||
37 | GstVdpBufferPool * | ||
38 | gst_vdp_output_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_OUTPUT_BUFFER_POOL, "device", device, NULL); | ||
43 | } | ||
44 | |||
45 | static gboolean | ||
46 | parse_caps (const GstCaps * caps, VdpChromaType * rgba_format, 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, "rgba-format", (gint *) rgba_format)) | ||
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 | |||
63 | static gboolean | ||
64 | gst_vdp_output_buffer_pool_check_caps (GstVdpBufferPool * bpool, | ||
65 | const GstCaps * caps) | ||
66 | { | ||
67 | GstVdpOutputBufferPool *opool = GST_VDP_OUTPUT_BUFFER_POOL (bpool); | ||
68 | |||
69 | VdpChromaType rgba_format; | ||
70 | gint width, height; | ||
71 | |||
72 | if (!parse_caps (caps, &rgba_format, &width, &height)) | ||
73 | return FALSE; | ||
74 | |||
75 | if (rgba_format != opool->rgba_format || width != opool->width || | ||
76 | height != opool->height) | ||
77 | return FALSE; | ||
78 | |||
79 | return TRUE; | ||
80 | } | ||
81 | |||
82 | static gboolean | ||
83 | gst_vdp_output_buffer_pool_set_caps (GstVdpBufferPool * bpool, | ||
84 | const GstCaps * caps, gboolean * clear_bufs) | ||
85 | { | ||
86 | GstVdpOutputBufferPool *opool = GST_VDP_OUTPUT_BUFFER_POOL (bpool); | ||
87 | |||
88 | VdpChromaType rgba_format; | ||
89 | gint width, height; | ||
90 | |||
91 | if (!parse_caps (caps, &rgba_format, &width, &height)) | ||
92 | return FALSE; | ||
93 | |||
94 | if (rgba_format != opool->rgba_format || width != opool->width || | ||
95 | height != opool->height) | ||
96 | *clear_bufs = TRUE; | ||
97 | else | ||
98 | *clear_bufs = FALSE; | ||
99 | |||
100 | opool->rgba_format = rgba_format; | ||
101 | opool->width = width; | ||
102 | opool->height = height; | ||
103 | |||
104 | return TRUE; | ||
105 | } | ||
106 | |||
107 | static GstVdpBuffer * | ||
108 | gst_vdp_output_buffer_pool_alloc_buffer (GstVdpBufferPool * bpool, | ||
109 | GError ** error) | ||
110 | { | ||
111 | GstVdpOutputBufferPool *opool = GST_VDP_OUTPUT_BUFFER_POOL (bpool); | ||
112 | GstVdpDevice *device; | ||
113 | |||
114 | device = gst_vdp_buffer_pool_get_device (bpool); | ||
115 | return GST_VDP_BUFFER_CAST (gst_vdp_output_buffer_new (device, | ||
116 | opool->rgba_format, opool->width, opool->height, error)); | ||
117 | } | ||
118 | |||
119 | static void | ||
120 | gst_vdp_output_buffer_pool_finalize (GObject * object) | ||
121 | { | ||
122 | /* TODO: Add deinitalization code here */ | ||
123 | |||
124 | G_OBJECT_CLASS (gst_vdp_output_buffer_pool_parent_class)->finalize (object); | ||
125 | } | ||
126 | |||
127 | static void | ||
128 | gst_vdp_output_buffer_pool_init (GstVdpOutputBufferPool * opool) | ||
129 | { | ||
130 | opool->rgba_format = -1; | ||
131 | opool->width = 0; | ||
132 | opool->height = 0; | ||
133 | } | ||
134 | |||
135 | static void | ||
136 | gst_vdp_output_buffer_pool_class_init (GstVdpOutputBufferPoolClass * 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_output_buffer_pool_alloc_buffer; | ||
142 | buffer_pool_class->set_caps = gst_vdp_output_buffer_pool_set_caps; | ||
143 | buffer_pool_class->check_caps = gst_vdp_output_buffer_pool_check_caps; | ||
144 | |||
145 | object_class->finalize = gst_vdp_output_buffer_pool_finalize; | ||
146 | } | ||
diff --git a/sys/vdpau/gstvdp/gstvdpoutputbufferpool.h b/sys/vdpau/gstvdp/gstvdpoutputbufferpool.h new file mode 100644 index 000000000..354461c0e --- /dev/null +++ b/sys/vdpau/gstvdp/gstvdpoutputbufferpool.h | |||
@@ -0,0 +1,50 @@ | |||
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 | #ifndef _GST_VDP_OUTPUT_BUFFER_POOL_H_ | ||
21 | #define _GST_VDP_OUTPUT_BUFFER_POOL_H_ | ||
22 | |||
23 | #include <gst/gst.h> | ||
24 | |||
25 | #include "gstvdpbufferpool.h" | ||
26 | |||
27 | G_BEGIN_DECLS | ||
28 | |||
29 | #define GST_TYPE_VDP_OUTPUT_BUFFER_POOL (gst_vdp_output_buffer_pool_get_type ()) | ||
30 | #define GST_VDP_OUTPUT_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VDP_OUTPUT_BUFFER_POOL, GstVdpOutputBufferPool)) | ||
31 | #define GST_VDP_OUTPUT_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VDP_OUTPUT_BUFFER_POOL, GstVdpOutputBufferPoolClass)) | ||
32 | #define GST_IS_VDP_OUTPUT_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VDP_OUTPUT_BUFFER_POOL)) | ||
33 | #define GST_IS_VDP_OUTPUT_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VDP_OUTPUT_BUFFER_POOL)) | ||
34 | #define GST_VDP_OUTPUT_BUFFER_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_VDP_OUTPUT_BUFFER_POOL, GstVdpOutputBufferPoolClass)) | ||
35 | |||
36 | typedef struct _GstVdpOutputBufferPool GstVdpOutputBufferPool; | ||
37 | typedef struct _GstVdpOutputBufferPoolClass GstVdpOutputBufferPoolClass; | ||
38 | |||
39 | struct _GstVdpOutputBufferPoolClass | ||
40 | { | ||
41 | GstVdpBufferPoolClass buffer_pool_class; | ||
42 | }; | ||
43 | |||
44 | GstVdpBufferPool *gst_vdp_output_buffer_pool_new (GstVdpDevice *device); | ||
45 | |||
46 | GType gst_vdp_output_buffer_pool_get_type (void) G_GNUC_CONST; | ||
47 | |||
48 | G_END_DECLS | ||
49 | |||
50 | #endif /* _GST_VDP_OUTPUT_BUFFER_POOL_H_ */ | ||
diff --git a/sys/vdpau/gstvdp/gstvdpoutputsrcpad.c b/sys/vdpau/gstvdp/gstvdpoutputsrcpad.c index f2b384208..9813f68ef 100644 --- a/sys/vdpau/gstvdp/gstvdpoutputsrcpad.c +++ b/sys/vdpau/gstvdp/gstvdpoutputsrcpad.c | |||
@@ -156,7 +156,7 @@ gst_vdp_output_src_pad_create_buffer (GstVdpOutputSrcPad * vdp_pad, | |||
156 | } | 156 | } |
157 | 157 | ||
158 | *output_buf = gst_vdp_output_buffer_new (vdp_pad->device, | 158 | *output_buf = gst_vdp_output_buffer_new (vdp_pad->device, |
159 | vdp_pad->rgba_format, vdp_pad->width, vdp_pad->height); | 159 | vdp_pad->rgba_format, vdp_pad->width, vdp_pad->height, NULL); |
160 | if (!*output_buf) | 160 | if (!*output_buf) |
161 | goto output_buf_error; | 161 | goto output_buf_error; |
162 | 162 | ||
diff --git a/sys/vdpau/gstvdpsink.c b/sys/vdpau/gstvdpsink.c index 815c74dd0..933990f8c 100644 --- a/sys/vdpau/gstvdpsink.c +++ b/sys/vdpau/gstvdpsink.c | |||
@@ -912,7 +912,7 @@ gst_vdp_sink_get_output_buffer (VdpSink * vdp_sink, GstCaps * caps, | |||
912 | } | 912 | } |
913 | 913 | ||
914 | *buf = GST_BUFFER (gst_vdp_output_buffer_new (vdp_sink->device, | 914 | *buf = GST_BUFFER (gst_vdp_output_buffer_new (vdp_sink->device, |
915 | rgba_format, width, height)); | 915 | rgba_format, width, height, NULL)); |
916 | if (*buf == NULL) { | 916 | if (*buf == NULL) { |
917 | return GST_FLOW_ERROR; | 917 | return GST_FLOW_ERROR; |
918 | } | 918 | } |