• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *alloc_response;
120 };
121 
122 /*
123  * GstMsdkVideoAllocatorClass:
124  *
125  * A MSDK video memory allocator class.
126  */
127 struct _GstMsdkVideoAllocatorClass
128 {
129   GstAllocatorClass parent_class;
130 };
131 
132 GType gst_msdk_video_allocator_get_type (void);
133 
134 GstAllocator * gst_msdk_video_allocator_new (GstMsdkContext * context,
135     GstVideoInfo *image_info, mfxFrameAllocResponse * alloc_resp);
136 
137 /* ---------------------------------------------------------------------*/
138 /* GstMsdkDmaBufMemory                                                  */
139 /* ---------------------------------------------------------------------*/
140 
141 #define GST_MSDK_DMABUF_MEMORY_NAME             "GstMsdkDmaBufMemory"
142 
143 GstMemory *
144 gst_msdk_dmabuf_memory_new (GstAllocator * allocator);
145 
146 GstMemory *
147 gst_msdk_dmabuf_memory_new_with_surface (GstAllocator * base_allocator, mfxFrameSurface1 * surface);
148 
149 /* ---------------------------------------------------------------------*/
150 /* GstMsdkDmaBufAllocator                                                */
151 /* ---------------------------------------------------------------------*/
152 
153 #define GST_MSDK_DMABUF_ALLOCATOR_CAST(allocator) \
154   ((GstMsdkDmaBufAllocator *) (allocator))
155 
156 #define GST_TYPE_MSDK_DMABUF_ALLOCATOR \
157   (gst_msdk_dmabuf_allocator_get_type ())
158 #define GST_MSDK_DMABUF_ALLOCATOR(obj) \
159   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MSDK_DMABUF_ALLOCATOR, \
160       GstMsdkDmaBufAllocator))
161 #define GST_IS_MSDK_DMABUF_ALLOCATOR(obj) \
162   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MSDK_DMABUF_ALLOCATOR))
163 
164 /*
165  * GstMsdkDmaBufAllocator:
166  *
167  * A MSDK DMABuf memory allocator object.
168  */
169 struct _GstMsdkDmaBufAllocator
170 {
171   GstDmaBufAllocator parent_instance;
172 
173   GstMsdkContext *context;
174   GstVideoInfo image_info;
175   mfxFrameAllocResponse *alloc_response;
176 };
177 
178 /*
179  * GstMsdkDmaBufAllocatorClass:
180  *
181  * A MSDK DMABuf memory allocator class.
182  */
183 struct _GstMsdkDmaBufAllocatorClass
184 {
185   GstDmaBufAllocatorClass parent_class;
186 };
187 
188 GType gst_msdk_dmabuf_allocator_get_type (void);
189 
190 GstAllocator * gst_msdk_dmabuf_allocator_new (GstMsdkContext * context,
191     GstVideoInfo *image_info, mfxFrameAllocResponse * alloc_resp);
192 
193 G_END_DECLS
194 
195 #endif /* GST_MSDK_VIDEO_MEMORY_H */
196