d58501d14a65f2262260cb0ac7af7f94b7e66cc0
[platform/upstream/gstreamer-vaapi.git] / gst / vaapi / gstvaapivideomemory.h
1 /*
2  *  gstvaapivideomemory.h - Gstreamer/VA video memory
3  *
4  *  Copyright (C) 2013 Intel Corporation
5  *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
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 #ifndef GST_VAAPI_VIDEO_MEMORY_H
24 #define GST_VAAPI_VIDEO_MEMORY_H
25
26 #include <gst/gstallocator.h>
27 #include <gst/video/video-info.h>
28 #include <gst/vaapi/gstvaapidisplay.h>
29 #include <gst/vaapi/gstvaapisurfacepool.h>
30 #include "gstvaapivideometa.h"
31
32 G_BEGIN_DECLS
33
34 typedef struct _GstVaapiVideoMemory             GstVaapiVideoMemory;
35 typedef struct _GstVaapiVideoAllocator          GstVaapiVideoAllocator;
36 typedef struct _GstVaapiVideoAllocatorClass     GstVaapiVideoAllocatorClass;
37
38 /* ------------------------------------------------------------------------ */
39 /* --- GstVaapiVideoMemory                                              --- */
40 /* ------------------------------------------------------------------------ */
41
42 #define GST_VAAPI_VIDEO_MEMORY_CAST(mem) \
43     ((GstVaapiVideoMemory *)(mem))
44
45 #define GST_VAAPI_VIDEO_MEMORY_NAME             "GstVaapiVideoMemory"
46
47 #if GST_CHECK_VERSION(1,1,0)
48 #define GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE   "memory:VASurface"
49 #endif
50
51 /**
52  * GstVaapiVideoMemoryMapType:
53  * @GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_SURFACE: map with gst_buffer_map()
54  *   and flags = 0x00 to return a #GstVaapiSurfaceProxy
55  * @GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_PLANAR: map individual plane with
56  *   gst_video_frame_map()
57  * @GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_LINEAR: map with gst_buffer_map()
58  *   and flags = GST_MAP_READ to return the raw pixels of the whole image
59  *
60  * The set of all #GstVaapiVideoMemory map types.
61  */
62 typedef enum {
63     GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_SURFACE = 1,
64     GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_PLANAR,
65     GST_VAAPI_VIDEO_MEMORY_MAP_TYPE_LINEAR
66 } GstVaapiVideoMemoryMapType;
67
68 /**
69  * GstVaapiVideoMemory:
70  *
71  * A VA video memory object holder, including VA surfaces, images and
72  * proxies.
73  */
74 struct _GstVaapiVideoMemory {
75     GstMemory parent_instance;
76
77     /*< private >*/
78     GstVaapiSurfaceProxy *proxy;
79     const GstVideoInfo *surface_info;
80     GstVaapiSurface    *surface;
81     const GstVideoInfo *image_info;
82     GstVaapiImage      *image;
83     GstVaapiVideoMeta  *meta;
84     guint               map_type;
85     gint                map_count;
86     gboolean            use_direct_rendering;
87 };
88
89 G_GNUC_INTERNAL
90 GstMemory *
91 gst_vaapi_video_memory_new(GstAllocator *allocator, GstVaapiVideoMeta *meta);
92
93 G_GNUC_INTERNAL
94 gboolean
95 gst_video_meta_map_vaapi_memory(GstVideoMeta *meta, guint plane,
96     GstMapInfo *info, gpointer *data, gint *stride, GstMapFlags flags);
97
98 G_GNUC_INTERNAL
99 gboolean
100 gst_video_meta_unmap_vaapi_memory(GstVideoMeta *meta, guint plane,
101     GstMapInfo *info);
102
103 G_GNUC_INTERNAL
104 void
105 gst_vaapi_video_memory_reset_surface(GstVaapiVideoMemory *mem);
106
107 /* ------------------------------------------------------------------------ */
108 /* --- GstVaapiVideoAllocator                                           --- */
109 /* ------------------------------------------------------------------------ */
110
111 #define GST_VAAPI_VIDEO_ALLOCATOR_CAST(allocator) \
112     ((GstVaapiVideoAllocator *)(allocator))
113
114 #define GST_VAAPI_TYPE_VIDEO_ALLOCATOR \
115     (gst_vaapi_video_allocator_get_type())
116
117 #define GST_VAAPI_VIDEO_ALLOCATOR(obj)          \
118     (G_TYPE_CHECK_INSTANCE_CAST((obj),          \
119         GST_VAAPI_TYPE_VIDEO_ALLOCATOR,         \
120         GstVaapiVideoAllocator))
121
122 #define GST_VAAPI_IS_VIDEO_ALLOCATOR(obj) \
123     (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_VIDEO_ALLOCATOR))
124
125 #define GST_VAAPI_VIDEO_ALLOCATOR_NAME          "GstVaapiVideoAllocator"
126
127 /**
128  * GstVaapiVideoAllocator:
129  *
130  * A VA video memory allocator object.
131  */
132 struct _GstVaapiVideoAllocator {
133     GstAllocator parent_instance;
134
135     /*< private >*/
136     GstVideoInfo        video_info;
137     GstVideoInfo        surface_info;
138     GstVaapiVideoPool  *surface_pool;
139     GstVideoInfo        image_info;
140     gboolean            has_direct_rendering;
141 };
142
143 /**
144  * GstVaapiVideoAllocatorClass:
145  *
146  * A VA video memory allocator class.
147  */
148 struct _GstVaapiVideoAllocatorClass {
149     GstAllocatorClass parent_class;
150 };
151
152 G_GNUC_INTERNAL
153 GType
154 gst_vaapi_video_allocator_get_type(void) G_GNUC_CONST;
155
156 G_GNUC_INTERNAL
157 GstAllocator *
158 gst_vaapi_video_allocator_new(GstVaapiDisplay *display,
159     const GstVideoInfo *vip);
160
161 G_END_DECLS
162
163 #endif /* GST_VAAPI_VIDEO_MEMORY_H */