if (!priv->d3d11_params) {
/* allocate memory with resource format by default */
priv->d3d11_params = gst_d3d11_allocation_params_new (&info,
- GST_D3D11_ALLOCATION_FLAG_USE_RESOURCE_FORMAT, D3D11_USAGE_DEFAULT, 0);
+ GST_D3D11_ALLOCATION_FLAG_USE_RESOURCE_FORMAT, 0);
}
#ifndef GST_DISABLE_GST_DEBUG
{
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
if (!d3d11_params) {
d3d11_params = gst_d3d11_allocation_params_new (&info,
- GST_D3D11_ALLOCATION_FLAG_USE_RESOURCE_FORMAT, D3D11_USAGE_DEFAULT,
+ GST_D3D11_ALLOCATION_FLAG_USE_RESOURCE_FORMAT,
D3D11_BIND_SHADER_RESOURCE);
} else {
/* Set bind flag */
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
if (!d3d11_params) {
d3d11_params = gst_d3d11_allocation_params_new (&info,
- GST_D3D11_ALLOCATION_FLAG_USE_RESOURCE_FORMAT, D3D11_USAGE_DEFAULT,
+ GST_D3D11_ALLOCATION_FLAG_USE_RESOURCE_FORMAT,
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET);
} else {
/* Set bind flag */
gst_clear_object (&priv->internal_pool);
alloc_params = gst_d3d11_allocation_params_new (info,
- GST_D3D11_ALLOCATION_FLAG_TEXTURE_ARRAY, D3D11_USAGE_DEFAULT,
- D3D11_BIND_DECODER);
+ GST_D3D11_ALLOCATION_FLAG_TEXTURE_ARRAY, D3D11_BIND_DECODER);
if (!alloc_params) {
GST_ERROR_OBJECT (self, "Failed to create allocation param");
GstQuery * query);
static GstFlowReturn gst_d3d11_download_transform (GstBaseTransform * trans,
GstBuffer * inbuf, GstBuffer * outbuf);
-static gboolean gst_d3d11_download_query (GstBaseTransform * trans,
- GstPadDirection direction, GstQuery * query);
static void
gst_d3d11_download_class_init (GstD3D11DownloadClass * klass)
trans_class->decide_allocation =
GST_DEBUG_FUNCPTR (gst_d3d11_download_decide_allocation);
trans_class->transform = GST_DEBUG_FUNCPTR (gst_d3d11_download_transform);
- trans_class->query = GST_DEBUG_FUNCPTR (gst_d3d11_download_query);
GST_DEBUG_CATEGORY_INIT (gst_d3d11_download_debug,
"d3d11download", 0, "d3d11download Element");
return GST_FLOW_ERROR;
}
}
-
-static gboolean
-gst_d3d11_download_query (GstBaseTransform * trans, GstPadDirection direction,
- GstQuery * query)
-{
- if (gst_query_is_d3d11_usage (query) && direction == GST_PAD_SINK) {
- GstD3D11BaseFilter *filter = GST_D3D11_BASE_FILTER (trans);
- D3D11_USAGE usage = D3D11_USAGE_DEFAULT;
- GstD3D11Device *device;
-
- gst_query_parse_d3d11_usage (query, &device, &usage);
- if (filter->device == device && usage == D3D11_USAGE_DEFAULT) {
- gst_query_set_d3d11_usage_result (query, TRUE);
- gst_object_unref (device);
- } else {
- gst_query_set_d3d11_usage_result (query, FALSE);
- gst_object_unref (device);
-
- return TRUE;
- }
- }
-
- return GST_BASE_TRANSFORM_CLASS (parent_class)->query (trans, direction,
- query);
-}
if (self->use_d3d11_output) {
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
if (!d3d11_params)
- d3d11_params = gst_d3d11_allocation_params_new (&vinfo, 0,
- D3D11_USAGE_DEFAULT, 0);
+ d3d11_params = gst_d3d11_allocation_params_new (&vinfo, 0, 0);
/* dxva2 decoder uses non-resource format
* (e.g., use NV12 instead of R8 + R8G8 */
if (self->use_d3d11_output) {
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
if (!d3d11_params)
- d3d11_params = gst_d3d11_allocation_params_new (&vinfo, 0,
- D3D11_USAGE_DEFAULT, 0);
+ d3d11_params = gst_d3d11_allocation_params_new (&vinfo, 0, 0);
/* dxva2 decoder uses non-resource format
* (e.g., use NV12 instead of R8 + R8G8 */
GstD3D11AllocationParams *
gst_d3d11_allocation_params_new (GstVideoInfo * info,
- GstD3D11AllocationFlags flags, D3D11_USAGE usage, gint bind_flags)
+ GstD3D11AllocationFlags flags, gint bind_flags)
{
GstD3D11AllocationParams *ret;
const GstD3D11Format *d3d11_format;
gint i;
- gint cpu_access_flags;
g_return_val_if_fail (info != NULL, NULL);
return NULL;
}
- if (usage == D3D11_USAGE_DEFAULT) {
- cpu_access_flags = 0;
- } else if (usage == D3D11_USAGE_DYNAMIC) {
- cpu_access_flags = D3D11_CPU_ACCESS_WRITE;
- } else {
- GST_FIXME ("Neither default nor dynamic usage");
- return NULL;
- }
-
ret = g_new0 (GstD3D11AllocationParams, 1);
ret->info = *info;
ret->desc[i].Format = d3d11_format->resource_format[i];
ret->desc[i].SampleDesc.Count = 1;
ret->desc[i].SampleDesc.Quality = 0;
- ret->desc[i].Usage = usage;
+ ret->desc[i].Usage = D3D11_USAGE_DEFAULT;
ret->desc[i].BindFlags = bind_flags;
- ret->desc[i].CPUAccessFlags = cpu_access_flags;
}
} else {
g_assert (d3d11_format->dxgi_format != DXGI_FORMAT_UNKNOWN);
ret->desc[0].Format = d3d11_format->dxgi_format;
ret->desc[0].SampleDesc.Count = 1;
ret->desc[0].SampleDesc.Quality = 0;
- ret->desc[0].Usage = usage;
+ ret->desc[0].Usage = D3D11_USAGE_DEFAULT;
ret->desc[0].BindFlags = bind_flags;
- ret->desc[0].CPUAccessFlags = cpu_access_flags;
}
ret->flags = flags;
{
GstD3D11Memory *dmem = (GstD3D11Memory *) mem;
- if (dmem->desc.Usage == D3D11_USAGE_DYNAMIC) {
- GST_FIXME_OBJECT (mem->allocator,
- "D3D11_USAGE_DYNAMIC shouldn't be used with gst_memory_map");
- return NULL;
- }
-
g_mutex_lock (&dmem->lock);
if ((flags & GST_MAP_D3D11) == GST_MAP_D3D11) {
if (dmem->staging &&
{
GstD3D11Memory *dmem = (GstD3D11Memory *) mem;
- if (dmem->desc.Usage == D3D11_USAGE_DYNAMIC) {
- GST_FIXME_OBJECT (mem->allocator,
- "D3D11_USAGE_DYNAMIC shouldn't be used with gst_memory_unmap");
- return;
- }
-
g_mutex_lock (&dmem->lock);
if ((info->flags & GST_MAP_D3D11) == GST_MAP_D3D11) {
if ((info->flags & GST_MAP_WRITE) == GST_MAP_WRITE)
D3D11_TEXTURE2D_DESC *desc;
gsize *size;
gboolean is_first = FALSE;
- GstMemoryFlags memory_flags;
guint index_to_use = 0;
GstD3D11MemoryType type = GST_D3D11_MEMORY_TYPE_TEXTURE;
desc = ¶ms->desc[params->plane];
size = ¶ms->size[params->plane];
- if (desc->Usage == D3D11_USAGE_DEFAULT) {
- memory_flags = 0;
- } else if (desc->Usage == D3D11_USAGE_DYNAMIC) {
- /* FIXME: how we can make D3D11_USAGE_DYNAMIC work with GST_MAP_READWRITE ? */
- memory_flags = GST_MEMORY_FLAG_NOT_MAPPABLE;
- } else {
- GST_FIXME_OBJECT (allocator, "Cannot support usage %d", desc->Usage);
- return NULL;
- }
-
if (*size == 0)
is_first = TRUE;
/* per plane, allocated staging texture to calculate actual size,
* stride, and offset */
if (is_first) {
- ID3D11Texture2D *target;
- D3D11_MAP map_type;
gint num_plane;
gint stride[GST_VIDEO_MAX_PLANES];
gsize mem_size;
gint i;
- if (desc->Usage == D3D11_USAGE_DEFAULT) {
- staging = create_staging_texture (device, desc);
- if (!staging) {
- GST_ERROR_OBJECT (allocator, "Couldn't create staging texture");
- goto error;
- }
-
- target = staging;
- map_type = D3D11_MAP_READ;
- } else if (desc->Usage == D3D11_USAGE_DYNAMIC) {
- target = texture;
- map_type = D3D11_MAP_WRITE_DISCARD;
- } else {
- g_assert_not_reached ();
+ staging = create_staging_texture (device, desc);
+ if (!staging) {
+ GST_ERROR_OBJECT (allocator, "Couldn't create staging texture");
+ goto error;
}
- if (!calculate_mem_size (device, target, desc, map_type, stride, &mem_size))
+ if (!calculate_mem_size (device,
+ staging, desc, D3D11_MAP_READ, stride, &mem_size))
goto error;
num_plane = gst_d3d11_dxgi_format_n_planes (desc->Format);
mem = g_new0 (GstD3D11Memory, 1);
gst_memory_init (GST_MEMORY_CAST (mem),
- memory_flags, GST_ALLOCATOR_CAST (allocator), NULL, *size, 0, 0, *size);
+ 0, GST_ALLOCATOR_CAST (allocator), NULL, *size, 0, 0, *size);
g_mutex_init (&mem->lock);
mem->info = params->info;
GstD3D11AllocationParams * gst_d3d11_allocation_params_new (GstVideoInfo * info,
GstD3D11AllocationFlags flags,
- D3D11_USAGE usage,
gint bind_flags);
GstD3D11AllocationParams * gst_d3d11_allocation_params_copy (GstD3D11AllocationParams * src);
GstStructure *config;
gboolean update_pool = FALSE;
GstVideoInfo vinfo;
- gint i;
gst_query_parse_allocation (query, &outcaps, NULL);
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
- {
- GstQuery *usage_query;
- gboolean can_dynamic = FALSE;
-
- usage_query =
- gst_query_new_d3d11_usage (filter->device, D3D11_USAGE_DYNAMIC);
- gst_pad_peer_query (GST_BASE_TRANSFORM_SRC_PAD (trans), usage_query);
- gst_query_parse_d3d11_usage_result (usage_query, &can_dynamic);
- gst_query_unref (usage_query);
-
- if (can_dynamic) {
- GstD3D11AllocationParams *d3d11_params;
-
- GST_DEBUG_OBJECT (trans, "downstream support dynamic usage");
-
- d3d11_params =
- gst_buffer_pool_config_get_d3d11_allocation_params (config);
- if (!d3d11_params) {
- /* dynamic usage should have at least one bind flag.
- * but followings are not allowed in this case
- * D3D11_BIND_STREAM_OUTPUT
- * D3D11_BIND_RENDER_TARGET
- * D3D11_BIND_DEPTH_STENCIL
- * D3D11_BIND_UNORDERED_ACCESS */
- d3d11_params = gst_d3d11_allocation_params_new (&vinfo,
- GST_D3D11_ALLOCATION_FLAG_USE_RESOURCE_FORMAT,
- D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE);
- } else {
- for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
- d3d11_params->desc[i].Usage = D3D11_USAGE_DYNAMIC;
- d3d11_params->desc[i].CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
- }
- }
-
- gst_buffer_pool_config_set_d3d11_allocation_params (config, d3d11_params);
- gst_d3d11_allocation_params_free (d3d11_params);
- }
- }
-
gst_buffer_pool_set_config (pool, config);
/* update size with calculated one */
}
static GstFlowReturn
-upload_transform_dynamic (GstD3D11BaseFilter * filter,
- GstD3D11Device * device, GstBuffer * inbuf, GstBuffer * outbuf)
-{
- GstVideoFrame in_frame;
- gint i, j, k;
- GstFlowReturn ret = GST_FLOW_OK;
- ID3D11DeviceContext *device_context =
- gst_d3d11_device_get_device_context_handle (device);
-
- if (!gst_video_frame_map (&in_frame, &filter->in_info, inbuf,
- GST_MAP_READ | GST_VIDEO_FRAME_MAP_FLAG_NO_REF))
- goto invalid_buffer;
-
- gst_d3d11_device_lock (device);
- for (i = 0, j = 0; i < gst_buffer_n_memory (outbuf); i++) {
- GstD3D11Memory *dmem =
- (GstD3D11Memory *) gst_buffer_peek_memory (outbuf, i);
- D3D11_MAPPED_SUBRESOURCE map;
- HRESULT hr;
- D3D11_TEXTURE2D_DESC *desc = &dmem->desc;
- gsize offset[GST_VIDEO_MAX_PLANES];
- gint stride[GST_VIDEO_MAX_PLANES];
- gsize dummy;
-
- hr = ID3D11DeviceContext_Map (device_context,
- (ID3D11Resource *) dmem->texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
-
- if (!gst_d3d11_result (hr, device)) {
- GST_ERROR_OBJECT (filter,
- "Failed to map staging texture (0x%x)", (guint) hr);
- gst_d3d11_device_unlock (device);
- ret = GST_FLOW_ERROR;
- goto done;
- }
-
- gst_d3d11_dxgi_format_get_size (desc->Format, desc->Width, desc->Height,
- map.RowPitch, offset, stride, &dummy);
-
- for (k = 0; k < gst_d3d11_dxgi_format_n_planes (dmem->desc.Format); k++) {
- gint h, width;
- guint8 *dst, *src;
-
- dst = (guint8 *) map.pData + offset[k];
- src = GST_VIDEO_FRAME_PLANE_DATA (&in_frame, j);
- width = GST_VIDEO_FRAME_COMP_WIDTH (&in_frame, j) *
- GST_VIDEO_FRAME_COMP_PSTRIDE (&in_frame, j);
-
- for (h = 0; h < GST_VIDEO_FRAME_COMP_HEIGHT (&in_frame, j); h++) {
- memcpy (dst, src, width);
- dst += stride[k];
- src += GST_VIDEO_FRAME_PLANE_STRIDE (&in_frame, j);
- }
-
- j++;
- }
-
- ID3D11DeviceContext_Unmap (device_context,
- (ID3D11Resource *) dmem->texture, 0);
- }
- gst_d3d11_device_unlock (device);
-
-done:
- gst_video_frame_unmap (&in_frame);
-
- return ret;
-
- /* ERRORS */
-invalid_buffer:
- {
- GST_ELEMENT_WARNING (filter, CORE, NOT_IMPLEMENTED, (NULL),
- ("invalid video buffer received"));
- return GST_FLOW_ERROR;
- }
-}
-
-static GstFlowReturn
-upload_transform (GstD3D11BaseFilter * filter, GstBuffer * inbuf,
+gst_d3d11_upload_transform (GstBaseTransform * trans, GstBuffer * inbuf,
GstBuffer * outbuf)
{
+ GstD3D11BaseFilter *filter = GST_D3D11_BASE_FILTER (trans);
+
GstVideoFrame in_frame, out_frame;
gint i;
GstFlowReturn ret = GST_FLOW_OK;
return GST_FLOW_ERROR;
}
}
-
-static GstFlowReturn
-gst_d3d11_upload_transform (GstBaseTransform * trans, GstBuffer * inbuf,
- GstBuffer * outbuf)
-{
- GstD3D11BaseFilter *filter = GST_D3D11_BASE_FILTER (trans);
- GstMemory *mem;
- GstD3D11Device *device;
-
- mem = gst_buffer_peek_memory (outbuf, 0);
- if (gst_is_d3d11_memory (mem)) {
- GstD3D11Memory *dmem = (GstD3D11Memory *) mem;
- device = dmem->device;
-
- if (dmem->desc.Usage == D3D11_USAGE_DYNAMIC) {
- return upload_transform_dynamic (filter, device, inbuf, outbuf);
- }
- }
-
- return upload_transform (filter, inbuf, outbuf);
-}
return ret;
}
-GstQuery *
-gst_query_new_d3d11_usage (GstD3D11Device * device, D3D11_USAGE usage)
-{
- GstQuery *query;
- GstStructure *structure;
-
- g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL);
-
- structure = gst_structure_new ("GstQueryD3D11Usage",
- "device", GST_TYPE_D3D11_DEVICE, device,
- "usage", G_TYPE_INT, usage, "result", G_TYPE_BOOLEAN, FALSE, NULL);
- query = gst_query_new_custom (GST_QUERY_CUSTOM, structure);
-
- return query;
-}
-
-void
-gst_query_parse_d3d11_usage (GstQuery * query, GstD3D11Device ** device,
- D3D11_USAGE * usage)
-{
- const GstStructure *structure;
-
- g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CUSTOM);
-
- if (!gst_query_is_d3d11_usage (query))
- return;
-
- structure = gst_query_get_structure (query);
-
- gst_structure_get (structure, "device", GST_TYPE_D3D11_DEVICE, device,
- "usage", G_TYPE_INT, usage, NULL);
-}
-
-void
-gst_query_set_d3d11_usage_result (GstQuery * query, gboolean result)
-{
- GstStructure *structure;
- const gchar *name;
-
- g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CUSTOM);
- g_return_if_fail (gst_query_is_writable (query));
-
- structure = gst_query_writable_structure (query);
- name = gst_structure_get_name (structure);
-
- g_return_if_fail (g_strcmp0 (name, "GstQueryD3D11Usage") == 0);
- gst_structure_set (structure, "result", G_TYPE_BOOLEAN, result, NULL);
-}
-
-void
-gst_query_parse_d3d11_usage_result (GstQuery * query, gboolean * result)
-{
- const GstStructure *structure;
- const gchar *name;
-
- g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CUSTOM);
- g_return_if_fail (gst_query_is_writable (query));
- g_return_if_fail (result != NULL);
-
- structure = gst_query_get_structure (query);
- name = gst_structure_get_name (structure);
-
- g_return_if_fail (g_strcmp0 (name, "GstQueryD3D11Usage") == 0);
-
- gst_structure_get (structure, "result", G_TYPE_BOOLEAN, result, NULL);
-}
-
-gboolean
-gst_query_is_d3d11_usage (GstQuery * query)
-{
- const GstStructure *structure;
-
- g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
-
- if (GST_QUERY_TYPE (query) != GST_QUERY_CUSTOM)
- return FALSE;
-
- structure = gst_query_get_structure (query);
-
- if (!structure ||
- g_strcmp0 (gst_structure_get_name (structure), "GstQueryD3D11Usage"))
- return FALSE;
-
- return TRUE;
-}
-
/*
* This is an incomplete matrix of in formats and a score for the prefered output
* format.
gboolean gst_d3d11_is_windows_8_or_greater (void);
-GstQuery * gst_query_new_d3d11_usage (GstD3D11Device * device,
- D3D11_USAGE usage);
-
-void gst_query_parse_d3d11_usage (GstQuery * query,
- GstD3D11Device ** device,
- D3D11_USAGE *usage);
-
-void gst_query_set_d3d11_usage_result (GstQuery * query,
- gboolean result);
-
-void gst_query_parse_d3d11_usage_result (GstQuery * query,
- gboolean * result);
-
-gboolean gst_query_is_d3d11_usage (GstQuery * query);
-
GstCaps * gst_d3d11_caps_fixate_format (GstCaps * caps,
GstCaps * othercaps);
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
if (!d3d11_params) {
d3d11_params = gst_d3d11_allocation_params_new (&self->info,
- GST_D3D11_ALLOCATION_FLAG_USE_RESOURCE_FORMAT, D3D11_USAGE_DYNAMIC,
+ GST_D3D11_ALLOCATION_FLAG_USE_RESOURCE_FORMAT,
D3D11_BIND_SHADER_RESOURCE);
} else {
/* Set bind flag */
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&self->info); i++) {
- d3d11_params->desc[i].Usage = D3D11_USAGE_DYNAMIC;
- d3d11_params->desc[i].CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
d3d11_params->desc[i].BindFlags |= D3D11_BIND_SHADER_RESOURCE;
}
}
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
if (!d3d11_params) {
d3d11_params = gst_d3d11_allocation_params_new (&info,
- GST_D3D11_ALLOCATION_FLAG_USE_RESOURCE_FORMAT, D3D11_USAGE_DEFAULT,
+ GST_D3D11_ALLOCATION_FLAG_USE_RESOURCE_FORMAT,
D3D11_BIND_SHADER_RESOURCE);
} else {
/* Set bind flag */
return TRUE;
}
break;
- case GST_QUERY_CUSTOM:
- if (gst_query_is_d3d11_usage (query)) {
- D3D11_USAGE usage = D3D11_USAGE_DEFAULT;
- GstD3D11Device *device;
-
- gst_query_parse_d3d11_usage (query, &device, &usage);
- if (device == self->device &&
- (usage == D3D11_USAGE_DEFAULT || usage == D3D11_USAGE_DYNAMIC)) {
- gst_query_set_d3d11_usage_result (query, TRUE);
- gst_object_unref (device);
- } else {
- gst_query_set_d3d11_usage_result (query, FALSE);
- gst_object_unref (device);
-
- return TRUE;
- }
- }
- break;
default:
break;
}
if (self->use_d3d11_output) {
d3d11_params = gst_buffer_pool_config_get_d3d11_allocation_params (config);
if (!d3d11_params)
- d3d11_params = gst_d3d11_allocation_params_new (&vinfo, 0,
- D3D11_USAGE_DEFAULT, 0);
+ d3d11_params = gst_d3d11_allocation_params_new (&vinfo, 0, 0);
/* dxva2 decoder uses non-resource format
* (e.g., use NV12 instead of R8 + R8G8 */