2 * Copyright (C) 2020 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.
26 #include <gst/video/video.h>
27 #include <gst/d3d11/gstd3d11format.h>
28 #include <gst/d3d11/gstd3d11device.h>
32 #define GST_TYPE_D3D11_FORMAT_SUPPORT (gst_d3d11_format_support_get_type())
33 GType gst_d3d11_format_support_get_type (void);
35 void gst_d3d11_device_d3d11_debug (GstD3D11Device * device,
37 const gchar * function,
40 void gst_d3d11_device_dxgi_debug (GstD3D11Device * device,
42 const gchar * function,
45 #define GST_D3D11_CLEAR_COM(obj) G_STMT_START { \
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) }
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) }
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) }
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),
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
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),
108 #undef MAKE_FORMAT_MAP_YUV
109 #undef MAKE_FORMAT_MAP_YUV_FULL
110 #undef MAKE_FORMAT_MAP_RGB
112 #define GST_D3D11_N_FORMATS G_N_ELEMENTS(_gst_d3d11_default_format_map)
114 typedef struct _GstD3D11ColorMatrix
116 gdouble matrix[3][3];
120 } GstD3D11ColorMatrix;
123 gchar * gst_d3d11_dump_color_matrix (GstD3D11ColorMatrix * matrix);
126 gboolean gst_d3d11_color_range_adjust_matrix_unorm (const GstVideoInfo * in_info,
127 const GstVideoInfo * out_info,
128 GstD3D11ColorMatrix * matrix);
131 gboolean gst_d3d11_yuv_to_rgb_matrix_unorm (const GstVideoInfo * in_yuv_info,
132 const GstVideoInfo * out_rgb_info,
133 GstD3D11ColorMatrix * matrix);
136 gboolean gst_d3d11_rgb_to_yuv_matrix_unorm (const GstVideoInfo * in_rgb_info,
137 const GstVideoInfo * out_yuv_info,
138 GstD3D11ColorMatrix * matrix);
141 gboolean gst_d3d11_color_primaries_matrix_unorm (const GstVideoColorPrimariesInfo * in_info,
142 const GstVideoColorPrimariesInfo * out_info,
143 GstD3D11ColorMatrix * matrix);
150 class GstD3D11DeviceLockGuard
153 explicit GstD3D11DeviceLockGuard(GstD3D11Device * device) : device_ (device)
155 gst_d3d11_device_lock (device_);
158 ~GstD3D11DeviceLockGuard()
160 gst_d3d11_device_unlock (device_);
163 GstD3D11DeviceLockGuard(const GstD3D11DeviceLockGuard&) = delete;
164 GstD3D11DeviceLockGuard& operator=(const GstD3D11DeviceLockGuard&) = delete;
167 GstD3D11Device *device_;
170 class GstD3D11CSLockGuard
173 explicit GstD3D11CSLockGuard(CRITICAL_SECTION * cs) : cs_ (cs)
175 EnterCriticalSection (cs_);
178 ~GstD3D11CSLockGuard()
180 LeaveCriticalSection (cs_);
183 GstD3D11CSLockGuard(const GstD3D11CSLockGuard&) = delete;
184 GstD3D11CSLockGuard& operator=(const GstD3D11CSLockGuard&) = delete;
187 CRITICAL_SECTION *cs_;
190 class GstD3D11SRWLockGuard
193 explicit GstD3D11SRWLockGuard(SRWLOCK * lock) : lock_ (lock)
195 AcquireSRWLockExclusive (lock_);
198 ~GstD3D11SRWLockGuard()
200 ReleaseSRWLockExclusive (lock_);
203 GstD3D11SRWLockGuard(const GstD3D11SRWLockGuard&) = delete;
204 GstD3D11SRWLockGuard& operator=(const GstD3D11SRWLockGuard&) = delete;
210 #define GST_D3D11_CALL_ONCE_BEGIN \
211 static std::once_flag __once_flag; \
212 std::call_once (__once_flag, [&]()
214 #define GST_D3D11_CALL_ONCE_END )
216 #endif /* __cplusplus */