Merging gst-rtsp-server
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / sys / msdk / gstmsdkvideomemory.h
1 /* GStreamer Intel MSDK plugin
2  * Copyright (c) 2018, Intel Corporation
3  * Copyright (c) 2018, Igalia S.L.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  *    this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  *    this list of conditions and the following disclaimer in the documentation
14  *    and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of the copyright holder nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGDECE
29  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef GST_MSDK_VIDEO_MEMORY_H
34 #define GST_MSDK_VIDEO_MEMORY_H
35
36 #include "msdk.h"
37 #include "gstmsdkcontext.h"
38 #include "gstmsdkallocator.h"
39 #include <gst/allocators/allocators.h>
40
41 G_BEGIN_DECLS
42
43 typedef struct _GstMsdkVideoMemory GstMsdkVideoMemory;
44 typedef struct _GstMsdkVideoAllocator GstMsdkVideoAllocator;
45 typedef struct _GstMsdkVideoAllocatorClass GstMsdkVideoAllocatorClass;
46 typedef struct _GstMsdkDmaBufAllocator GstMsdkDmaBufAllocator;
47 typedef struct _GstMsdkDmaBufAllocatorClass GstMsdkDmaBufAllocatorClass;
48
49 /* ---------------------------------------------------------------------*/
50 /* GstMsdkVideoMemory                                                        */
51 /* ---------------------------------------------------------------------*/
52
53 #define GST_MSDK_VIDEO_MEMORY_CAST(mem) \
54   ((GstMsdkVideoMemory *) (mem))
55
56 #define GST_IS_MSDK_VIDEO_MEMORY(mem) \
57   ((mem) && (mem)->allocator && GST_IS_MSDK_VIDEO_ALLOCATOR((mem)->allocator))
58
59 #define GST_MSDK_VIDEO_MEMORY_NAME             "GstMsdkVideoMemory"
60
61 /*
62  * GstMsdkVideoMemory:
63  *
64  * A MSDK memory object holder, including mfxFrameSurface,
65  * video info of the surface.
66  */
67 struct _GstMsdkVideoMemory
68 {
69   GstMemory parent_instance;
70
71   mfxFrameSurface1 *surface;
72   guint mapped;
73 };
74
75 GstMemory *
76 gst_msdk_video_memory_new (GstAllocator * allocator);
77
78 gboolean
79 gst_msdk_video_memory_get_surface_available (GstMemory * mem);
80
81 void
82 gst_msdk_video_memory_release_surface (GstMemory * mem);
83
84 gboolean
85 gst_video_meta_map_msdk_memory (GstVideoMeta * meta, guint plane,
86     GstMapInfo * info, gpointer * data, gint * stride, GstMapFlags flags);
87
88 gboolean
89 gst_video_meta_unmap_msdk_memory (GstVideoMeta * meta, guint plane,
90     GstMapInfo * info);
91
92
93 /* ---------------------------------------------------------------------*/
94 /* GstMsdkVideoAllocator                                                */
95 /* ---------------------------------------------------------------------*/
96
97 #define GST_MSDK_VIDEO_ALLOCATOR_CAST(allocator) \
98   ((GstMsdkVideoAllocator *) (allocator))
99
100 #define GST_TYPE_MSDK_VIDEO_ALLOCATOR \
101   (gst_msdk_video_allocator_get_type ())
102 #define GST_MSDK_VIDEO_ALLOCATOR(obj) \
103   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MSDK_VIDEO_ALLOCATOR, \
104       GstMsdkVideoAllocator))
105 #define GST_IS_MSDK_VIDEO_ALLOCATOR(obj) \
106   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MSDK_VIDEO_ALLOCATOR))
107
108 /*
109  * GstMsdkVideoAllocator:
110  *
111  * A MSDK video memory allocator object.
112  */
113 struct _GstMsdkVideoAllocator
114 {
115   GstAllocator parent_instance;
116
117   GstMsdkContext *context;
118   GstVideoInfo image_info;
119   mfxFrameAllocResponse mfx_response;
120   mfxFrameAllocResponse *alloc_response;
121 };
122
123 /*
124  * GstMsdkVideoAllocatorClass:
125  *
126  * A MSDK video memory allocator class.
127  */
128 struct _GstMsdkVideoAllocatorClass
129 {
130   GstAllocatorClass parent_class;
131 };
132
133 GType gst_msdk_video_allocator_get_type (void);
134
135 GstAllocator * gst_msdk_video_allocator_new (GstMsdkContext * context,
136     GstVideoInfo *image_info, mfxFrameAllocResponse * alloc_resp);
137
138 /* ---------------------------------------------------------------------*/
139 /* GstMsdkDmaBufMemory                                                  */
140 /* ---------------------------------------------------------------------*/
141
142 #define GST_MSDK_DMABUF_MEMORY_NAME             "GstMsdkDmaBufMemory"
143
144 GstMemory *
145 gst_msdk_dmabuf_memory_new (GstAllocator * allocator);
146
147 GstMemory *
148 gst_msdk_dmabuf_memory_new_with_surface (GstAllocator * base_allocator, mfxFrameSurface1 * surface);
149
150 /* ---------------------------------------------------------------------*/
151 /* GstMsdkDmaBufAllocator                                                */
152 /* ---------------------------------------------------------------------*/
153
154 #define GST_MSDK_DMABUF_ALLOCATOR_CAST(allocator) \
155   ((GstMsdkDmaBufAllocator *) (allocator))
156
157 #define GST_TYPE_MSDK_DMABUF_ALLOCATOR \
158   (gst_msdk_dmabuf_allocator_get_type ())
159 #define GST_MSDK_DMABUF_ALLOCATOR(obj) \
160   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MSDK_DMABUF_ALLOCATOR, \
161       GstMsdkDmaBufAllocator))
162 #define GST_IS_MSDK_DMABUF_ALLOCATOR(obj) \
163   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MSDK_DMABUF_ALLOCATOR))
164
165 /*
166  * GstMsdkDmaBufAllocator:
167  *
168  * A MSDK DMABuf memory allocator object.
169  */
170 struct _GstMsdkDmaBufAllocator
171 {
172   GstDmaBufAllocator parent_instance;
173
174   GstMsdkContext *context;
175   GstVideoInfo image_info;
176   mfxFrameAllocResponse mfx_response;
177   mfxFrameAllocResponse *alloc_response;
178 };
179
180 /*
181  * GstMsdkDmaBufAllocatorClass:
182  *
183  * A MSDK DMABuf memory allocator class.
184  */
185 struct _GstMsdkDmaBufAllocatorClass
186 {
187   GstDmaBufAllocatorClass parent_class;
188 };
189
190 GType gst_msdk_dmabuf_allocator_get_type (void);
191
192 GstAllocator * gst_msdk_dmabuf_allocator_new (GstMsdkContext * context,
193     GstVideoInfo *image_info, mfxFrameAllocResponse * alloc_resp);
194
195 G_END_DECLS
196
197 #endif /* GST_MSDK_VIDEO_MEMORY_H */