+
+gboolean
+gst_d3d11_memory_ensure_processor_input_view (GstD3D11Memory * mem,
+ ID3D11VideoDevice * video_device,
+ ID3D11VideoProcessorEnumerator * enumerator)
+{
+ GstD3D11Allocator *allocator;
+ GstD3D11AllocatorPrivate *priv;
+ D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC desc;
+ ID3D11VideoProcessorInputView *view = NULL;
+ HRESULT hr;
+
+ g_return_val_if_fail (gst_is_d3d11_memory (GST_MEMORY_CAST (mem)), FALSE);
+ g_return_val_if_fail (video_device != NULL, FALSE);
+ g_return_val_if_fail (enumerator != NULL, FALSE);
+
+ allocator = GST_D3D11_ALLOCATOR (GST_MEMORY_CAST (mem)->allocator);
+ priv = allocator->priv;
+
+ if (mem->processor_input_view)
+ return TRUE;
+
+ if (!check_bind_flags_for_processor_input_view (mem->desc.BindFlags)) {
+ GST_WARNING_OBJECT (allocator,
+ "Need BindFlags, current flag 0x%x", mem->desc.BindFlags);
+ return FALSE;
+ }
+
+ if (priv->processor_input_view_array) {
+ view = g_array_index (priv->processor_input_view_array,
+ ID3D11VideoProcessorInputView *, mem->subresource_index);
+ }
+
+ /* Increase refcount and reuse existing view */
+ if (view) {
+ mem->processor_input_view = view;
+ ID3D11VideoProcessorInputView_AddRef (view);
+
+ return TRUE;
+ }
+
+ desc.FourCC = 0;
+ desc.ViewDimension = D3D11_VPIV_DIMENSION_TEXTURE2D;
+ desc.Texture2D.MipSlice = 0;
+ desc.Texture2D.ArraySlice = mem->subresource_index;
+
+ hr = ID3D11VideoDevice_CreateVideoProcessorInputView (video_device,
+ (ID3D11Resource *) mem->texture, enumerator, &desc,
+ &mem->processor_input_view);
+ if (!gst_d3d11_result (hr, mem->device)) {
+ GST_ERROR_OBJECT (allocator,
+ "Could not create processor input view, hr: 0x%x", (guint) hr);
+ return FALSE;
+ }
+
+ /* Store view array for later reuse */
+ if (priv->processor_input_view_array) {
+ view = g_array_index (priv->processor_input_view_array,
+ ID3D11VideoProcessorInputView *, mem->subresource_index);
+
+ if (view)
+ ID3D11VideoProcessorInputView_Release (view);
+
+ g_array_index (priv->processor_input_view_array,
+ ID3D11VideoProcessorInputView *, mem->subresource_index) =
+ mem->processor_input_view;
+ ID3D11VideoProcessorInputView_AddRef (mem->processor_input_view);
+ }
+
+ return TRUE;
+}