2 * Copyright (C) 2021 Seungha Yang <seungha@centricular.com>
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.
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.
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.
23 #include <gst/video/video.h>
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)
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)
40 typedef struct _GstQsvFrame GstQsvFrame;
41 typedef struct _GstQsvAllocator GstQsvAllocator;
42 typedef struct _GstQsvAllocatorClass GstQsvAllocatorClass;
43 typedef struct _GstQsvAllocatorPrivate GstQsvAllocatorPrivate;
45 GType gst_qsv_frame_get_type (void);
47 GstBuffer * gst_qsv_frame_peek_buffer (GstQsvFrame * frame);
49 gboolean gst_qsv_frame_set_buffer (GstQsvFrame * frame,
52 static inline GstQsvFrame *
53 gst_qsv_frame_ref (GstQsvFrame * frame)
55 return (GstQsvFrame *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (frame));
59 gst_qsv_frame_unref (GstQsvFrame * frame)
61 gst_mini_object_unref (GST_MINI_OBJECT_CAST (frame));
65 gst_clear_qsv_frame (GstQsvFrame ** frame)
67 gst_clear_mini_object ((GstMiniObject **) frame);
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),
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)
81 struct _GstQsvAllocator
85 GstQsvAllocatorPrivate *priv;
88 struct _GstQsvAllocatorClass
90 GstObjectClass parent_class;
92 mfxStatus (*alloc) (GstQsvAllocator * allocator,
94 mfxFrameAllocRequest * request,
95 mfxFrameAllocResponse * response);
97 GstBuffer * (*upload) (GstQsvAllocator * allocator,
98 const GstVideoInfo * info,
100 GstBufferPool * pool);
102 GstBuffer * (*download) (GstQsvAllocator * allocator,
103 const GstVideoInfo * info,
106 GstBufferPool * pool);
109 GType gst_qsv_allocator_get_type (void);
111 GstQsvFrame * gst_qsv_allocator_acquire_frame (GstQsvAllocator * allocator,
112 GstQsvMemoryType mem_type,
113 const GstVideoInfo * info,
115 GstBufferPool * pool);
117 GstBuffer * gst_qsv_allocator_download_frame (GstQsvAllocator * allocator,
120 GstBufferPool * pool);
122 mfxFrameAllocator * gst_qsv_allocator_get_allocator_handle (GstQsvAllocator * allocator);
124 gboolean gst_qsv_allocator_get_cached_response (GstQsvAllocator * allocator,
125 mfxFrameAllocResponse * response);
127 void gst_qsv_allocator_set_options (GstQsvAllocator * allocator,
128 guint16 extra_alloc_size,
129 gboolean dummy_alloc);
131 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstQsvAllocator, gst_object_unref)
136 inline GstQsvMemoryType
137 operator | (const GstQsvMemoryType & lhs, const GstQsvMemoryType & rhs)
139 return static_cast<GstQsvMemoryType> (static_cast<guint>(lhs) |
140 static_cast<guint> (rhs));
143 inline GstQsvMemoryType &
144 operator |= (GstQsvMemoryType & lhs, const GstQsvMemoryType & rhs)
146 return lhs = lhs | rhs;