qsv: Update SDK version to v2022.2.4
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / sys / qsv / gstqsvallocator.h
1 /* GStreamer
2  * Copyright (C) 2021 Seungha Yang <seungha@centricular.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #pragma once
21
22 #include <gst/gst.h>
23 #include <gst/video/video.h>
24 #include <mfx.h>
25
26 G_BEGIN_DECLS
27
28 #define GST_TYPE_QSV_FRAME                (gst_qsv_frame_get_type())
29 #define GST_IS_QSV_FRAME(obj)             (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_QSV_FRAME))
30 #define GST_QSV_FRAME_CAST(obj)           ((GstQsvFrame *) obj)
31
32 #define GST_TYPE_QSV_ALLOCATOR            (gst_qsv_allocator_get_type())
33 #define GST_QSV_ALLOCATOR(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_QSV_ALLOCATOR, GstQsvAllocator))
34 #define GST_QSV_ALLOCATOR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_QSV_ALLOCATOR, GstQsvAllocatorClass))
35 #define GST_IS_QSV_ALLOCATOR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_QSV_ALLOCATOR))
36 #define GST_IS_QSV_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_QSV_ALLOCATOR))
37 #define GST_QSV_ALLOCATOR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_QSV_ALLOCATOR, GstQsvAllocatorClass))
38 #define GST_QSV_ALLOCATOR_CAST(obj)       ((GstQsvAllocator *)obj)
39
40 typedef struct _GstQsvFrame GstQsvFrame;
41 typedef struct _GstQsvAllocator GstQsvAllocator;
42 typedef struct _GstQsvAllocatorClass GstQsvAllocatorClass;
43 typedef struct _GstQsvAllocatorPrivate GstQsvAllocatorPrivate;
44
45 GType       gst_qsv_frame_get_type (void);
46
47 GstBuffer * gst_qsv_frame_peek_buffer (GstQsvFrame * frame);
48
49 gboolean    gst_qsv_frame_set_buffer  (GstQsvFrame * frame,
50                                        GstBuffer * buffer);
51
52 static inline GstQsvFrame *
53 gst_qsv_frame_ref (GstQsvFrame * frame)
54 {
55   return (GstQsvFrame *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (frame));
56 }
57
58 static inline void
59 gst_qsv_frame_unref (GstQsvFrame * frame)
60 {
61   gst_mini_object_unref (GST_MINI_OBJECT_CAST (frame));
62 }
63
64 static inline void
65 gst_clear_qsv_frame (GstQsvFrame ** frame)
66 {
67   gst_clear_mini_object ((GstMiniObject **) frame);
68 }
69
70 typedef enum
71 {
72   GST_QSV_SYSTEM_MEMORY = (1 << 0),
73   GST_QSV_VIDEO_MEMORY = (1 << 1),
74   GST_QSV_ENCODER_IN_MEMORY = (1 << 2),
75   GST_QSV_DECODER_OUT_MEMORY = (1 << 3),
76 } GstQsvMemoryType;
77
78 #define GST_QSV_MEM_TYPE_IS_SYSTEM(type) ((type & GST_QSV_SYSTEM_MEMORY) != 0)
79 #define GST_QSV_MEM_TYPE_IS_VIDEO(type) ((type & GST_QSV_VIDEO_MEMORY) != 0)
80
81 struct _GstQsvAllocator
82 {
83   GstObject parent;
84
85   GstQsvAllocatorPrivate *priv;
86 };
87
88 struct _GstQsvAllocatorClass
89 {
90   GstObjectClass parent_class;
91
92   mfxStatus   (*alloc)      (GstQsvAllocator * allocator,
93                              gboolean dummy_alloc,
94                              mfxFrameAllocRequest * request,
95                              mfxFrameAllocResponse * response);
96
97   GstBuffer * (*upload)     (GstQsvAllocator * allocator,
98                              const GstVideoInfo * info,
99                              GstBuffer * buffer,
100                              GstBufferPool * pool);
101
102   GstBuffer * (*download)   (GstQsvAllocator * allocator,
103                              const GstVideoInfo * info,
104                              gboolean force_copy,
105                              GstQsvFrame * frame,
106                              GstBufferPool * pool);
107 };
108
109 GType               gst_qsv_allocator_get_type        (void);
110
111 GstQsvFrame *       gst_qsv_allocator_acquire_frame   (GstQsvAllocator * allocator,
112                                                        GstQsvMemoryType mem_type,
113                                                        const GstVideoInfo * info,
114                                                        GstBuffer * buffer,
115                                                        GstBufferPool * pool);
116
117 GstBuffer *         gst_qsv_allocator_download_frame  (GstQsvAllocator * allocator,
118                                                        gboolean force_copy,
119                                                        GstQsvFrame * frame,
120                                                        GstBufferPool * pool);
121
122 mfxFrameAllocator * gst_qsv_allocator_get_allocator_handle (GstQsvAllocator * allocator);
123
124 gboolean            gst_qsv_allocator_get_cached_response  (GstQsvAllocator * allocator,
125                                                             mfxFrameAllocResponse * response);
126
127 void                gst_qsv_allocator_set_options          (GstQsvAllocator * allocator,
128                                                             guint16 extra_alloc_size,
129                                                             gboolean dummy_alloc);
130
131 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstQsvAllocator, gst_object_unref)
132
133 G_END_DECLS
134
135 #ifdef __cplusplus
136 inline GstQsvMemoryType
137 operator | (const GstQsvMemoryType & lhs, const GstQsvMemoryType & rhs)
138 {
139   return static_cast<GstQsvMemoryType> (static_cast<guint>(lhs) |
140       static_cast<guint> (rhs));
141 }
142
143 inline GstQsvMemoryType &
144 operator |= (GstQsvMemoryType & lhs, const GstQsvMemoryType & rhs)
145 {
146   return lhs = lhs | rhs;
147 }
148 #endif