d3d11device: Store device formats in hash map

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5580>
This commit is contained in:
Seungha Yang 2023-11-01 01:20:02 +09:00 committed by GStreamer Marge Bot
parent ac265bc4f9
commit e134cd8e09

View file

@ -40,6 +40,7 @@
#include <atomic> #include <atomic>
#include <mutex> #include <mutex>
#include <string.h> #include <string.h>
#include <unordered_map>
/** /**
* SECTION:gstd3d11device * SECTION:gstd3d11device
@ -120,7 +121,7 @@ struct _GstD3D11DevicePrivate
ID3D11VideoContext *video_context = nullptr; ID3D11VideoContext *video_context = nullptr;
IDXGIFactory1 *factory = nullptr; IDXGIFactory1 *factory = nullptr;
GArray *format_table = nullptr; std::unordered_map<GstVideoFormat, GstD3D11Format> format_table;
std::recursive_mutex extern_lock; std::recursive_mutex extern_lock;
std::mutex resource_lock; std::mutex resource_lock;
@ -422,14 +423,7 @@ gst_d3d11_device_class_init (GstD3D11DeviceClass * klass)
static void static void
gst_d3d11_device_init (GstD3D11Device * self) gst_d3d11_device_init (GstD3D11Device * self)
{ {
GstD3D11DevicePrivate *priv; self->priv = new GstD3D11DevicePrivate ();
priv = new GstD3D11DevicePrivate ();
priv->adapter = DEFAULT_ADAPTER;
priv->format_table = g_array_sized_new (FALSE, FALSE,
sizeof (GstD3D11Format), GST_D3D11_N_FORMATS);
self->priv = priv;
} }
static gboolean static gboolean
@ -624,7 +618,7 @@ gst_d3d11_device_setup_format_table (GstD3D11Device * self)
if (gst_debug_category_get_threshold (GST_CAT_DEFAULT) >= GST_LEVEL_LOG) if (gst_debug_category_get_threshold (GST_CAT_DEFAULT) >= GST_LEVEL_LOG)
dump_format (self, &format); dump_format (self, &format);
g_array_append_val (priv->format_table, format); priv->format_table[format.format] = format;
} }
/* FIXME: d3d11 sampler doesn't support packed-and-subsampled formats /* FIXME: d3d11 sampler doesn't support packed-and-subsampled formats
@ -784,7 +778,6 @@ gst_d3d11_device_finalize (GObject * object)
GST_LOG_OBJECT (self, "finalize"); GST_LOG_OBJECT (self, "finalize");
g_array_unref (priv->format_table);
g_free (priv->description); g_free (priv->description);
delete priv; delete priv;
@ -1415,23 +1408,18 @@ gst_d3d11_device_get_format (GstD3D11Device * device, GstVideoFormat format,
priv = device->priv; priv = device->priv;
for (guint i = 0; i < priv->format_table->len; i++) { const auto & target = priv->format_table.find (format);
const GstD3D11Format *d3d11_fmt = if (target == priv->format_table.end ()) {
&g_array_index (priv->format_table, GstD3D11Format, i);
if (d3d11_fmt->format != format)
continue;
if (device_format)
*device_format = *d3d11_fmt;
return TRUE;
}
if (device_format) if (device_format)
gst_d3d11_format_init (device_format); gst_d3d11_format_init (device_format);
return FALSE; return FALSE;
}
if (device_format)
*device_format = target->second;
return TRUE;
} }
GST_DEFINE_MINI_OBJECT_TYPE (GstD3D11Fence, gst_d3d11_fence); GST_DEFINE_MINI_OBJECT_TYPE (GstD3D11Fence, gst_d3d11_fence);