236ccd3a0eff4067b0604095338c4d131a159789
[platform/upstream/gstreamer.git] / subprojects / gstreamer-vaapi / gst / vaapi / gstvaapipluginutil.h
1 /*
2  *  gstvaapipluginutil.h - VA-API plugins private helper
3  *
4  *  Copyright (C) 2011-2014 Intel Corporation
5  *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
6  *  Copyright (C) 2011 Collabora
7  *    Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Lesser General Public License
11  *  as published by the Free Software Foundation; either version 2.1
12  *  of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Lesser General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Lesser General Public
20  *  License along with this library; if not, write to the Free
21  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  *  Boston, MA 02110-1301 USA
23  */
24
25 #ifndef GST_VAAPI_PLUGIN_UTIL_H
26 #define GST_VAAPI_PLUGIN_UTIL_H
27
28 #include <gst/vaapi/gstvaapidisplay.h>
29 #include <gst/vaapi/gstvaapisurface.h>
30 #include <gst/vaapi/gstvaapicontext.h>
31 #include "gstvaapivideomemory.h"
32
33 typedef GstVaapiProfile (*GstVaapiStrToProfileFunc) (const gchar * str);
34 typedef const gchar * (*GstVaapiProfileToStrFunc) (GstVaapiProfile profile);
35
36 G_GNUC_INTERNAL
37 gboolean
38 gst_vaapi_ensure_display (GstElement * element, GstVaapiDisplayType type);
39
40 G_GNUC_INTERNAL
41 gboolean
42 gst_vaapi_handle_context_query (GstElement * element, GstQuery * query);
43
44 G_GNUC_INTERNAL
45 gboolean
46 gst_vaapi_append_surface_caps (GstCaps * out_caps, GstCaps * in_caps);
47
48 G_GNUC_INTERNAL
49 gboolean
50 gst_vaapi_apply_composition (GstVaapiSurface * surface, GstBuffer * buffer);
51
52 #ifndef G_PRIMITIVE_SWAP
53 #define G_PRIMITIVE_SWAP(type, a, b) do {       \
54         const type t = a; a = b; b = t;         \
55     } while (0)
56 #endif
57
58 /* Helpers for GValue construction for video formats */
59 G_GNUC_INTERNAL
60 gboolean
61 gst_vaapi_value_set_format (GValue * value, GstVideoFormat format);
62
63 G_GNUC_INTERNAL
64 gboolean
65 gst_vaapi_value_set_format_list (GValue * value, GArray * formats);
66
67 /* Helpers to build video caps */
68 typedef enum
69 {
70   GST_VAAPI_CAPS_FEATURE_NOT_NEGOTIATED,
71   GST_VAAPI_CAPS_FEATURE_SYSTEM_MEMORY,
72   GST_VAAPI_CAPS_FEATURE_GL_TEXTURE_UPLOAD_META,
73   GST_VAAPI_CAPS_FEATURE_DMABUF,
74   GST_VAAPI_CAPS_FEATURE_VAAPI_SURFACE,
75 } GstVaapiCapsFeature;
76
77 G_GNUC_INTERNAL
78 GstCaps *
79 gst_vaapi_video_format_new_template_caps (GstVideoFormat format);
80
81 G_GNUC_INTERNAL
82 GstCaps *
83 gst_vaapi_video_format_new_template_caps_from_list (GArray * formats);
84
85 G_GNUC_INTERNAL
86 GstCaps *
87 gst_vaapi_video_format_new_template_caps_with_features (GstVideoFormat format,
88     const gchar * features_string);
89
90 G_GNUC_INTERNAL
91 GstVaapiCapsFeature
92 gst_vaapi_find_preferred_caps_feature (GstPad * pad, GstCaps * allowed_caps,
93     GstVideoFormat * out_format_ptr);
94
95 G_GNUC_INTERNAL
96 const gchar *
97 gst_vaapi_caps_feature_to_string (GstVaapiCapsFeature feature);
98
99 G_GNUC_INTERNAL
100 gboolean
101 gst_vaapi_caps_feature_contains (const GstCaps * caps,
102     GstVaapiCapsFeature feature);
103
104 /* Helpers to handle interlaced contents */
105 # define GST_CAPS_INTERLACED_MODES \
106     "interlace-mode = (string){ progressive, interleaved, mixed }"
107 # define GST_CAPS_INTERLACED_FALSE \
108     "interlace-mode = (string)progressive"
109
110 #define GST_VAAPI_MAKE_SURFACE_CAPS                                     \
111     GST_VIDEO_CAPS_MAKE_WITH_FEATURES(                                  \
112         GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE, GST_VAAPI_FORMATS_ALL)
113
114 #define GST_VAAPI_MAKE_GLTEXUPLOAD_CAPS                                 \
115     GST_VIDEO_CAPS_MAKE_WITH_FEATURES(                                  \
116         GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META, "{ RGBA, BGRA }")
117
118 #define GST_VAAPI_MAKE_DMABUF_CAPS                                      \
119     GST_VIDEO_CAPS_MAKE_WITH_FEATURES(                                  \
120         GST_CAPS_FEATURE_MEMORY_DMABUF, "{ I420, YV12, RGBA }")
121
122 G_GNUC_INTERNAL
123 gboolean
124 gst_caps_set_interlaced (GstCaps * caps, GstVideoInfo * vip);
125
126 G_GNUC_INTERNAL
127 gboolean
128 gst_caps_has_vaapi_surface (GstCaps * caps);
129
130 G_GNUC_INTERNAL
131 gboolean
132 gst_caps_is_video_raw (GstCaps * caps);
133
134 G_GNUC_INTERNAL
135 void
136 gst_video_info_change_format (GstVideoInfo * vip, GstVideoFormat format,
137     guint width, guint height);
138
139 G_GNUC_INTERNAL
140 gboolean
141 gst_video_info_changed (const GstVideoInfo * old, const GstVideoInfo * new);
142
143 G_GNUC_INTERNAL
144 void
145 gst_video_info_force_nv12_if_encoded (GstVideoInfo * vinfo);
146
147 G_GNUC_INTERNAL
148 GstVaapiDisplay *
149 gst_vaapi_create_test_display (void);
150
151 G_GNUC_INTERNAL
152 gboolean
153 gst_vaapi_driver_is_whitelisted (GstVaapiDisplay * display);
154
155 G_GNUC_INTERNAL
156 gboolean
157 gst_vaapi_codecs_has_codec (GArray * codecs, GstVaapiCodec codec);
158
159 G_GNUC_INTERNAL
160 GArray *
161 gst_vaapi_encoder_get_profiles_from_caps (GstCaps * caps,
162     GstVaapiStrToProfileFunc func);
163
164 G_GNUC_INTERNAL
165 void
166 gst_vaapi_caps_set_width_and_height_range (GstCaps * caps, gint min_width,
167     gint min_height, gint max_width, gint max_height);
168
169 G_GNUC_INTERNAL
170 GstCaps *
171 gst_vaapi_build_caps_from_formats (GArray * formats, gint min_width,
172     gint min_height, gint max_width, gint max_height, guint mem_type);
173
174 G_GNUC_INTERNAL
175 GstCaps *
176 gst_vaapi_build_template_raw_caps_by_codec (GstVaapiDisplay * display,
177     GstVaapiContextUsage usage, GstVaapiCodec codec, GArray * extra_fmts);
178
179 G_GNUC_INTERNAL
180 void
181 gst_vaapi_structure_set_profiles (GstStructure * st, gchar ** list);
182
183 G_GNUC_INTERNAL
184 GstCaps *
185 gst_vaapi_build_template_coded_caps_by_codec (GstVaapiDisplay * display,
186     GstVaapiContextUsage usage, GstVaapiCodec codec, const char *caps_str,
187     GstVaapiProfileToStrFunc func);
188
189 #endif /* GST_VAAPI_PLUGIN_UTIL_H */