Tizen 2.0 Release
[framework/multimedia/gstreamer-vaapi.git] / gst / vaapi / gstvaapipluginbuffer.c
1 /*
2  *  gstvaapipluginbuffer.c - Private GStreamer/VA video buffers
3  *
4  *  Copyright (C) 2012 Intel Corporation
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 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
25
26 #include <gst/vaapi/gstvaapivideobuffer.h>
27 #include <gst/vaapi/gstvaapivideobuffer_priv.h>
28 #if USE_GLX
29 # include <gst/vaapi/gstvaapivideobuffer_glx.h>
30 #endif
31 #include "gstvaapipluginbuffer.h"
32
33 static GType
34 get_type(GstVaapiDisplay *display)
35 {
36     GType type;
37
38     switch (gst_vaapi_display_get_display_type(display)) {
39 #if USE_GLX
40     case GST_VAAPI_DISPLAY_TYPE_GLX:
41         type = GST_VAAPI_TYPE_VIDEO_BUFFER_GLX;
42         break;
43 #endif
44     default:
45         type = GST_VAAPI_TYPE_VIDEO_BUFFER;
46         break;
47     }
48     return type;
49 }
50
51 GstBuffer *
52 gst_vaapi_video_buffer_new(GstVaapiDisplay *display)
53 {
54     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
55
56     return gst_vaapi_video_buffer_typed_new(get_type(display), display);
57 }
58
59 GstBuffer *
60 gst_vaapi_video_buffer_new_from_pool(GstVaapiVideoPool *pool)
61 {
62     GstVaapiDisplay *display;
63
64     g_return_val_if_fail(GST_VAAPI_IS_VIDEO_POOL(pool), NULL);
65
66     display = gst_vaapi_video_pool_get_display(pool);
67     if (!display)
68         return NULL;
69     return gst_vaapi_video_buffer_typed_new_from_pool(get_type(display), pool);
70 }
71
72 GstBuffer *
73 gst_vaapi_video_buffer_new_from_buffer(GstBuffer *buffer)
74 {
75     GstVaapiVideoBuffer *vbuffer;
76     GstVaapiDisplay *display;
77
78     g_return_val_if_fail(GST_VAAPI_IS_VIDEO_BUFFER(buffer), NULL);
79
80     vbuffer = GST_VAAPI_VIDEO_BUFFER(buffer);
81     display = gst_vaapi_video_buffer_get_display(vbuffer);
82     if (!display)
83         return NULL;
84
85     return gst_vaapi_video_buffer_typed_new_from_buffer(
86         get_type(display), buffer);
87 }
88
89 GstBuffer *
90 gst_vaapi_video_buffer_new_with_image(GstVaapiImage *image)
91 {
92     GstVaapiDisplay *display;
93
94     g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), NULL);
95
96     display = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(image));
97     if (!display)
98         return NULL;
99
100     return gst_vaapi_video_buffer_typed_new_with_image(
101         get_type(display), image);
102 }
103
104 GstBuffer *
105 gst_vaapi_video_buffer_new_with_surface(GstVaapiSurface *surface)
106 {
107     GstVaapiDisplay *display;
108
109     g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);
110
111     display = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(surface));
112     if (!display)
113         return NULL;
114
115     return gst_vaapi_video_buffer_typed_new_with_surface(
116         get_type(display), surface);
117 }
118
119 GstBuffer *
120 gst_vaapi_video_buffer_new_with_surface_proxy(GstVaapiSurfaceProxy *proxy)
121 {
122     GstVaapiDisplay *display;
123     GstVaapiSurface *surface;
124
125     g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
126
127     surface = gst_vaapi_surface_proxy_get_surface(proxy);
128     if (!surface)
129         return NULL;
130
131     display = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(surface));
132     if (!display)
133         return NULL;
134
135     return gst_vaapi_video_buffer_typed_new_with_surface_proxy(
136         get_type(display), proxy);
137 }