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.
24 #include "gstd3d11format.h"
25 #include "gstd3d11utils.h"
26 #include "gstd3d11device.h"
27 #include "gstd3d11memory.h"
28 #include "gstd3d11_private.h"
32 #ifndef GST_DISABLE_GST_DEBUG
33 #define GST_CAT_DEFAULT ensure_debug_category()
34 static GstDebugCategory *
35 ensure_debug_category (void)
37 static gsize cat_gonce = 0;
39 if (g_once_init_enter (&cat_gonce)) {
42 cat_done = (gsize) _gst_debug_category_new ("d3d11format", 0,
43 "d3d11 specific formats");
45 g_once_init_leave (&cat_gonce, cat_done);
48 return (GstDebugCategory *) cat_gonce;
51 #define ensure_debug_category() /* NOOP */
52 #endif /* GST_DISABLE_GST_DEBUG */
55 * gst_d3d11_dxgi_format_n_planes:
56 * @format: a DXGI_FORMAT
58 * Returns: the number of planes for @format
63 gst_d3d11_dxgi_format_n_planes (DXGI_FORMAT format)
66 case DXGI_FORMAT_B8G8R8A8_UNORM:
67 case DXGI_FORMAT_R8G8B8A8_UNORM:
68 case DXGI_FORMAT_R10G10B10A2_UNORM:
69 case DXGI_FORMAT_AYUV:
70 case DXGI_FORMAT_YUY2:
71 case DXGI_FORMAT_R8_UNORM:
72 case DXGI_FORMAT_R8G8_UNORM:
73 case DXGI_FORMAT_R16_UNORM:
74 case DXGI_FORMAT_R16G16_UNORM:
75 case DXGI_FORMAT_G8R8_G8B8_UNORM:
76 case DXGI_FORMAT_R8G8_B8G8_UNORM:
77 case DXGI_FORMAT_Y210:
78 case DXGI_FORMAT_Y410:
79 case DXGI_FORMAT_R16G16B16A16_UNORM:
81 case DXGI_FORMAT_NV12:
82 case DXGI_FORMAT_P010:
83 case DXGI_FORMAT_P016:
93 * gst_d3d11_dxgi_format_get_size:
94 * @format: a DXGI_FORMAT
95 * @width: a texture width
96 * @height: a texture height
97 * @pitch: a pitch of texture
98 * @offset: offset for each plane
99 * @stride: stride for each plane
100 * @size: (out): required memory size for given format
102 * Calculate required memory size and per plane stride with
103 * based on information
105 * Returns: %TRUE if @size can be calculated with given information
110 gst_d3d11_dxgi_format_get_size (DXGI_FORMAT format, guint width, guint height,
111 guint pitch, gsize offset[GST_VIDEO_MAX_PLANES],
112 gint stride[GST_VIDEO_MAX_PLANES], gsize * size)
114 g_return_val_if_fail (format != DXGI_FORMAT_UNKNOWN, FALSE);
117 case DXGI_FORMAT_B8G8R8A8_UNORM:
118 case DXGI_FORMAT_R8G8B8A8_UNORM:
119 case DXGI_FORMAT_R10G10B10A2_UNORM:
120 case DXGI_FORMAT_AYUV:
121 case DXGI_FORMAT_YUY2:
122 case DXGI_FORMAT_R8_UNORM:
123 case DXGI_FORMAT_R8G8_UNORM:
124 case DXGI_FORMAT_R16_UNORM:
125 case DXGI_FORMAT_R16G16_UNORM:
126 case DXGI_FORMAT_G8R8_G8B8_UNORM:
127 case DXGI_FORMAT_R8G8_B8G8_UNORM:
128 case DXGI_FORMAT_Y210:
129 case DXGI_FORMAT_Y410:
130 case DXGI_FORMAT_R16G16B16A16_UNORM:
133 *size = pitch * height;
135 case DXGI_FORMAT_NV12:
136 case DXGI_FORMAT_P010:
137 case DXGI_FORMAT_P016:
140 offset[1] = offset[0] + stride[0] * height;
142 *size = offset[1] + stride[1] * GST_ROUND_UP_2 (height / 2);
148 GST_LOG ("Calculated buffer size: %" G_GSIZE_FORMAT
149 " (dxgi format:%d, %dx%d, Pitch %d)",
150 *size, format, width, height, pitch);
156 * gst_d3d11_dxgi_format_to_gst:
157 * @format: a DXGI_FORMAT
159 * Converts the @format to its #GstVideoFormat representation.
161 * Returns: a #GstVideoFormat equivalent to @format
166 gst_d3d11_dxgi_format_to_gst (DXGI_FORMAT format)
169 case DXGI_FORMAT_B8G8R8A8_UNORM:
170 return GST_VIDEO_FORMAT_BGRA;
171 case DXGI_FORMAT_R8G8B8A8_UNORM:
172 return GST_VIDEO_FORMAT_RGBA;
173 case DXGI_FORMAT_R10G10B10A2_UNORM:
174 return GST_VIDEO_FORMAT_RGB10A2_LE;
175 case DXGI_FORMAT_AYUV:
176 return GST_VIDEO_FORMAT_VUYA;
177 case DXGI_FORMAT_YUY2:
178 return GST_VIDEO_FORMAT_YUY2;
179 case DXGI_FORMAT_Y210:
180 return GST_VIDEO_FORMAT_Y210;
181 case DXGI_FORMAT_Y410:
182 return GST_VIDEO_FORMAT_Y410;
183 case DXGI_FORMAT_NV12:
184 return GST_VIDEO_FORMAT_NV12;
185 case DXGI_FORMAT_P010:
186 return GST_VIDEO_FORMAT_P010_10LE;
187 case DXGI_FORMAT_P016:
188 return GST_VIDEO_FORMAT_P016_LE;
193 return GST_VIDEO_FORMAT_UNKNOWN;