docker/windows: Pass a couple installargs to python3
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / gst-libs / gst / d3d11 / gstd3d11-private.h
1 /* GStreamer
2  * Copyright (C) 2020 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 <d3d11_4.h>
23 #include <dxgi1_6.h>
24
25 #include <gst/gst.h>
26 #include <gst/video/video.h>
27 #include <gst/d3d11/gstd3d11format.h>
28 #include <gst/d3d11/gstd3d11device.h>
29
30 G_BEGIN_DECLS
31
32 #define GST_TYPE_D3D11_FORMAT_SUPPORT (gst_d3d11_format_support_get_type())
33 GType gst_d3d11_format_support_get_type (void);
34
35 void  gst_d3d11_device_d3d11_debug (GstD3D11Device * device,
36                                     const gchar * file,
37                                     const gchar * function,
38                                     gint line);
39
40 void  gst_d3d11_device_dxgi_debug  (GstD3D11Device * device,
41                                     const gchar * file,
42                                     const gchar * function,
43                                     gint line);
44
45 #define GST_D3D11_CLEAR_COM(obj) G_STMT_START { \
46     if (obj) { \
47       (obj)->Release (); \
48       (obj) = NULL; \
49     } \
50   } G_STMT_END
51
52
53 #define MAKE_FORMAT_MAP_YUV(g,d,r0,r1,r2,r3) \
54   { GST_VIDEO_FORMAT_ ##g, DXGI_FORMAT_ ##d, \
55     { DXGI_FORMAT_ ##r0, DXGI_FORMAT_ ##r1, DXGI_FORMAT_ ##r2, DXGI_FORMAT_ ##r3 }, \
56     { DXGI_FORMAT_ ##r0, DXGI_FORMAT_ ##r1, DXGI_FORMAT_ ##r2, DXGI_FORMAT_ ##r3 }, \
57     (D3D11_FORMAT_SUPPORT) (D3D11_FORMAT_SUPPORT_RENDER_TARGET | D3D11_FORMAT_SUPPORT_SHADER_SAMPLE) }
58
59 #define MAKE_FORMAT_MAP_YUV_FULL(g,d,r0,r1,r2,r3,f) \
60   { GST_VIDEO_FORMAT_ ##g, DXGI_FORMAT_ ##d, \
61     { DXGI_FORMAT_ ##r0, DXGI_FORMAT_ ##r1, DXGI_FORMAT_ ##r2, DXGI_FORMAT_ ##r3 }, \
62     { DXGI_FORMAT_ ##r0, DXGI_FORMAT_ ##r1, DXGI_FORMAT_ ##r2, DXGI_FORMAT_ ##r3 }, \
63     (D3D11_FORMAT_SUPPORT) (f) }
64
65 #define MAKE_FORMAT_MAP_RGB(g,d) \
66   { GST_VIDEO_FORMAT_ ##g, DXGI_FORMAT_ ##d, \
67     { DXGI_FORMAT_ ##d, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, \
68     { DXGI_FORMAT_ ##d, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, \
69     (D3D11_FORMAT_SUPPORT) (D3D11_FORMAT_SUPPORT_RENDER_TARGET | D3D11_FORMAT_SUPPORT_SHADER_SAMPLE) }
70
71 static const GstD3D11Format _gst_d3d11_default_format_map[] = {
72   MAKE_FORMAT_MAP_RGB (BGRA, B8G8R8A8_UNORM),
73   MAKE_FORMAT_MAP_RGB (RGBA, R8G8B8A8_UNORM),
74   MAKE_FORMAT_MAP_RGB (BGRx, B8G8R8A8_UNORM),
75   MAKE_FORMAT_MAP_RGB (RGBx, R8G8B8A8_UNORM),
76   MAKE_FORMAT_MAP_RGB (RGB10A2_LE, R10G10B10A2_UNORM),
77   MAKE_FORMAT_MAP_RGB (RGBA64_LE, R16G16B16A16_UNORM),
78   MAKE_FORMAT_MAP_YUV (AYUV, UNKNOWN, R8G8B8A8_UNORM, UNKNOWN, UNKNOWN, UNKNOWN),
79   MAKE_FORMAT_MAP_YUV (AYUV64, UNKNOWN, R16G16B16A16_UNORM, UNKNOWN, UNKNOWN, UNKNOWN),
80   MAKE_FORMAT_MAP_YUV (VUYA, AYUV, R8G8B8A8_UNORM, UNKNOWN, UNKNOWN, UNKNOWN),
81   MAKE_FORMAT_MAP_YUV (NV12, NV12, R8_UNORM, R8G8_UNORM, UNKNOWN, UNKNOWN),
82   MAKE_FORMAT_MAP_YUV (NV21, UNKNOWN, R8_UNORM, R8G8_UNORM, UNKNOWN, UNKNOWN),
83   MAKE_FORMAT_MAP_YUV (P010_10LE, P010, R16_UNORM, R16G16_UNORM, UNKNOWN, UNKNOWN),
84   MAKE_FORMAT_MAP_YUV (P012_LE, P016, R16_UNORM, R16G16_UNORM, UNKNOWN, UNKNOWN),
85   MAKE_FORMAT_MAP_YUV (P016_LE, P016, R16_UNORM, R16G16_UNORM, UNKNOWN, UNKNOWN),
86   MAKE_FORMAT_MAP_YUV (I420, UNKNOWN, R8_UNORM, R8_UNORM, R8_UNORM, UNKNOWN),
87   MAKE_FORMAT_MAP_YUV (YV12, UNKNOWN, R8_UNORM, R8_UNORM, R8_UNORM, UNKNOWN),
88   MAKE_FORMAT_MAP_YUV (I420_10LE, UNKNOWN, R16_UNORM, R16_UNORM, R16_UNORM, UNKNOWN),
89   MAKE_FORMAT_MAP_YUV (I420_12LE, UNKNOWN, R16_UNORM, R16_UNORM, R16_UNORM, UNKNOWN),
90   MAKE_FORMAT_MAP_YUV (Y42B, UNKNOWN, R8_UNORM, R8_UNORM, R8_UNORM, UNKNOWN),
91   MAKE_FORMAT_MAP_YUV (I422_10LE, UNKNOWN, R16_UNORM, R16_UNORM, R16_UNORM, UNKNOWN),
92   MAKE_FORMAT_MAP_YUV (I422_12LE, UNKNOWN, R16_UNORM, R16_UNORM, R16_UNORM, UNKNOWN),
93   MAKE_FORMAT_MAP_YUV (Y444, UNKNOWN, R8_UNORM, R8_UNORM, R8_UNORM, UNKNOWN),
94   MAKE_FORMAT_MAP_YUV (Y444_10LE, UNKNOWN, R16_UNORM, R16_UNORM, R16_UNORM, UNKNOWN),
95   MAKE_FORMAT_MAP_YUV (Y444_12LE, UNKNOWN, R16_UNORM, R16_UNORM, R16_UNORM, UNKNOWN),
96   MAKE_FORMAT_MAP_YUV (Y444_16LE, UNKNOWN, R16_UNORM, R16_UNORM, R16_UNORM, UNKNOWN),
97   /* GRAY */
98   /* NOTE: To support conversion by using video processor,
99    * mark DXGI_FORMAT_{R8,R16}_UNORM formats as known dxgi_format.
100    * Otherwise, d3d11 elements will not try to use video processor for
101    * those formats */
102   MAKE_FORMAT_MAP_RGB (GRAY8, R8_UNORM),
103   MAKE_FORMAT_MAP_RGB (GRAY16_LE, R16_UNORM),
104   MAKE_FORMAT_MAP_YUV_FULL (Y410, Y410, R10G10B10A2_UNORM, UNKNOWN, UNKNOWN, UNKNOWN,
105       D3D11_FORMAT_SUPPORT_SHADER_SAMPLE),
106 };
107
108 #undef MAKE_FORMAT_MAP_YUV
109 #undef MAKE_FORMAT_MAP_YUV_FULL
110 #undef MAKE_FORMAT_MAP_RGB
111
112 #define GST_D3D11_N_FORMATS G_N_ELEMENTS(_gst_d3d11_default_format_map)
113
114 typedef struct _GstD3D11ColorMatrix
115 {
116   gdouble matrix[3][3];
117   gdouble offset[3];
118   gdouble min[3];
119   gdouble max[3];
120 } GstD3D11ColorMatrix;
121
122 GST_D3D11_API
123 gchar *         gst_d3d11_dump_color_matrix (GstD3D11ColorMatrix * matrix);
124
125 GST_D3D11_API
126 gboolean        gst_d3d11_color_range_adjust_matrix_unorm (const GstVideoInfo * in_info,
127                                                            const GstVideoInfo * out_info,
128                                                            GstD3D11ColorMatrix * matrix);
129
130 GST_D3D11_API
131 gboolean        gst_d3d11_yuv_to_rgb_matrix_unorm (const GstVideoInfo * in_yuv_info,
132                                                    const GstVideoInfo * out_rgb_info,
133                                                    GstD3D11ColorMatrix * matrix);
134
135 GST_D3D11_API
136 gboolean        gst_d3d11_rgb_to_yuv_matrix_unorm (const GstVideoInfo * in_rgb_info,
137                                                    const GstVideoInfo * out_yuv_info,
138                                                    GstD3D11ColorMatrix * matrix);
139
140 GST_D3D11_API
141 gboolean        gst_d3d11_color_primaries_matrix_unorm (const GstVideoColorPrimariesInfo * in_info,
142                                                         const GstVideoColorPrimariesInfo * out_info,
143                                                         GstD3D11ColorMatrix * matrix);
144
145 G_END_DECLS
146
147 #ifdef __cplusplus
148 #include <mutex>
149
150 class GstD3D11DeviceLockGuard
151 {
152 public:
153   explicit GstD3D11DeviceLockGuard(GstD3D11Device * device) : device_ (device)
154   {
155     gst_d3d11_device_lock (device_);
156   }
157
158   ~GstD3D11DeviceLockGuard()
159   {
160     gst_d3d11_device_unlock (device_);
161   }
162
163   GstD3D11DeviceLockGuard(const GstD3D11DeviceLockGuard&) = delete;
164   GstD3D11DeviceLockGuard& operator=(const GstD3D11DeviceLockGuard&) = delete;
165
166 private:
167   GstD3D11Device *device_;
168 };
169
170 class GstD3D11CSLockGuard
171 {
172 public:
173   explicit GstD3D11CSLockGuard(CRITICAL_SECTION * cs) : cs_ (cs)
174   {
175     EnterCriticalSection (cs_);
176   }
177
178   ~GstD3D11CSLockGuard()
179   {
180     LeaveCriticalSection (cs_);
181   }
182
183   GstD3D11CSLockGuard(const GstD3D11CSLockGuard&) = delete;
184   GstD3D11CSLockGuard& operator=(const GstD3D11CSLockGuard&) = delete;
185
186 private:
187   CRITICAL_SECTION *cs_;
188 };
189
190 class GstD3D11SRWLockGuard
191 {
192 public:
193   explicit GstD3D11SRWLockGuard(SRWLOCK * lock) : lock_ (lock)
194   {
195     AcquireSRWLockExclusive (lock_);
196   }
197
198   ~GstD3D11SRWLockGuard()
199   {
200     ReleaseSRWLockExclusive (lock_);
201   }
202
203   GstD3D11SRWLockGuard(const GstD3D11SRWLockGuard&) = delete;
204   GstD3D11SRWLockGuard& operator=(const GstD3D11SRWLockGuard&) = delete;
205
206 private:
207   SRWLOCK *lock_;
208 };
209
210 #define GST_D3D11_CALL_ONCE_BEGIN \
211     static std::once_flag __once_flag; \
212     std::call_once (__once_flag, [&]()
213
214 #define GST_D3D11_CALL_ONCE_END )
215
216 #endif /* __cplusplus */