plugins: drop gstvaapipluginbuffer.[ch] helper files.
[vaapi:gstreamer-vaapi.git] / gst / vaapi / gstvaapivideobuffer.c
1 /*
2  *  gstvaapivideobuffer.c - Gstreamer/VA video buffer
3  *
4  *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5  *  Copyright (C) 2011-2013 Intel Corporation
6  *
7  *  This library is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU Lesser General Public License
9  *  as published by the Free Software Foundation; either version 2.1
10  *  of the License, or (at your option) any later version.
11  *
12  *  This library is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public
18  *  License along with this library; if not, write to the Free
19  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  *  Boston, MA 02110-1301 USA
21  */
22
23 /**
24  * SECTION:gstvaapivideobuffer
25  * @short_description: VA video buffer for GStreamer
26  */
27
28 #include "gst/vaapi/sysdeps.h"
29 #include <gst/video/gstsurfacebuffer.h>
30 #include "gstvaapivideobuffer.h"
31 #if USE_GLX
32 # include "gstvaapivideoconverter_glx.h"
33 #endif
34
35 #define GST_VAAPI_TYPE_VIDEO_BUFFER \
36     (gst_vaapi_video_buffer_get_type())
37
38 #define GST_VAAPI_VIDEO_BUFFER(obj)             \
39     (G_TYPE_CHECK_INSTANCE_CAST((obj),          \
40         GST_VAAPI_TYPE_VIDEO_BUFFER,            \
41         GstVaapiVideoBuffer))
42
43 #define GST_VAAPI_VIDEO_BUFFER_CLASS(klass)     \
44     (G_TYPE_CHECK_CLASS_CAST((klass),           \
45         GST_VAAPI_TYPE_VIDEO_BUFFER,            \
46         GstVaapiVideoBufferClass))
47
48 #define GST_VAAPI_IS_VIDEO_BUFFER(obj) \
49     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_VIDEO_BUFFER))
50
51 #define GST_VAAPI_IS_VIDEO_BUFFER_CLASS(klass) \
52     (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_VIDEO_BUFFER))
53
54 #define GST_VAAPI_VIDEO_BUFFER_GET_CLASS(obj)   \
55     (G_TYPE_INSTANCE_GET_CLASS((obj),           \
56         GST_VAAPI_TYPE_VIDEO_BUFFER,            \
57         GstVaapiVideoBufferClass))
58
59 typedef struct _GstVaapiVideoBufferClass        GstVaapiVideoBufferClass;
60
61 /**
62  * GstVaapiVideoBuffer:
63  *
64  * A #GstBuffer holding video objects (#GstVaapiSurface and #GstVaapiImage).
65  */
66 struct _GstVaapiVideoBuffer {
67     /*< private >*/
68     GstSurfaceBuffer parent_instance;
69
70     GstVaapiVideoMeta *meta;
71 };
72
73 /**
74  * GstVaapiVideoBufferClass:
75  *
76  * A #GstBuffer holding video objects
77  */
78 struct _GstVaapiVideoBufferClass {
79     /*< private >*/
80     GstSurfaceBufferClass parent_class;
81 };
82
83 GType
84 gst_vaapi_video_buffer_get_type(void) G_GNUC_CONST;
85
86 G_DEFINE_TYPE(GstVaapiVideoBuffer,
87               gst_vaapi_video_buffer,
88               GST_TYPE_SURFACE_BUFFER)
89
90 typedef GstSurfaceConverter *(*GstSurfaceConverterCreateFunc)(
91     GstSurfaceBuffer *surface, const gchar *type, GValue *dest);
92
93 static GstSurfaceConverter *
94 gst_vaapi_video_buffer_create_converter(GstSurfaceBuffer *surface,
95     const gchar *type, GValue *dest)
96 {
97     GstVaapiVideoBuffer * const vbuffer = GST_VAAPI_VIDEO_BUFFER(surface);
98     GstSurfaceConverterCreateFunc func;
99
100     func = (GstSurfaceConverterCreateFunc)
101         gst_vaapi_video_meta_get_surface_converter(vbuffer->meta);
102
103     return func ? func(surface, type, dest) : NULL;
104 }
105
106 static void
107 gst_vaapi_video_buffer_class_init(GstVaapiVideoBufferClass *klass)
108 {
109     GstSurfaceBufferClass * const surface_class =
110         GST_SURFACE_BUFFER_CLASS(klass);
111
112     surface_class->create_converter = gst_vaapi_video_buffer_create_converter;
113 }
114
115 static void
116 gst_vaapi_video_buffer_init(GstVaapiVideoBuffer *buffer)
117 {
118 }
119
120 static GFunc
121 get_surface_converter(GstVaapiDisplay *display)
122 {
123     GFunc func;
124
125     switch (gst_vaapi_display_get_display_type(display)) {
126 #if USE_GLX
127     case GST_VAAPI_DISPLAY_TYPE_GLX:
128         func = (GFunc)gst_vaapi_video_converter_glx_new;
129         break;
130 #endif
131     default:
132         func = NULL;
133         break;
134     }
135     return func;
136 }
137
138 static GstBuffer *
139 new_vbuffer(GstVaapiVideoMeta *meta)
140 {
141     GstBuffer *buffer;
142
143     g_return_val_if_fail(meta != NULL, NULL);
144
145     gst_vaapi_video_meta_set_surface_converter(meta,
146         get_surface_converter(gst_vaapi_video_meta_get_display(meta)));
147
148     buffer = GST_BUFFER_CAST(gst_mini_object_new(GST_TYPE_SURFACE_BUFFER));
149     if (buffer)
150         gst_buffer_set_vaapi_video_meta(buffer, meta);
151     gst_vaapi_video_meta_unref(meta);
152     return buffer;
153 }
154
155 GstBuffer *
156 gst_vaapi_video_buffer_new_from_pool(GstVaapiVideoPool *pool)
157 {
158     return new_vbuffer(gst_vaapi_video_meta_new_from_pool(pool));
159 }
160
161 GstBuffer *
162 gst_vaapi_video_buffer_new_from_buffer(GstBuffer *buffer)
163 {
164     GstVaapiVideoMeta * const meta = gst_buffer_get_vaapi_video_meta(buffer);
165
166     return meta ? new_vbuffer(gst_vaapi_video_meta_ref(meta)) : NULL;
167 }
168
169 GstBuffer *
170 gst_vaapi_video_buffer_new_with_image(GstVaapiImage *image)
171 {
172     return new_vbuffer(gst_vaapi_video_meta_new_with_image(image));
173 }
174
175 GstBuffer *
176 gst_vaapi_video_buffer_new_with_surface(GstVaapiSurface *surface)
177 {
178     return new_vbuffer(gst_vaapi_video_meta_new_with_surface(surface));
179 }
180
181 GstBuffer *
182 gst_vaapi_video_buffer_new_with_surface_proxy(GstVaapiSurfaceProxy *proxy)
183 {
184     return new_vbuffer(gst_vaapi_video_meta_new_with_surface_proxy(proxy));
185 }
186
187 GstVaapiVideoMeta *
188 gst_vaapi_video_buffer_get_meta(GstVaapiVideoBuffer *buffer)
189 {
190     g_return_val_if_fail(GST_VAAPI_IS_VIDEO_BUFFER(buffer), NULL);
191
192     return buffer->meta;
193 }