s->staging_texture = NULL;
}
+static int d3d11va_frames_get_constraints(AVHWDeviceContext *ctx,
+ const void *hwconfig,
+ AVHWFramesConstraints *constraints)
+{
+ AVD3D11VADeviceContext *device_hwctx = ctx->hwctx;
+ int nb_sw_formats = 0;
+ HRESULT hr;
+ int i;
+
+ constraints->valid_sw_formats = av_malloc_array(FF_ARRAY_ELEMS(supported_formats) + 1,
+ sizeof(*constraints->valid_sw_formats));
+ if (!constraints->valid_sw_formats)
+ return AVERROR(ENOMEM);
+
+ for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
+ UINT format_support = 0;
+ hr = ID3D11Device_CheckFormatSupport(device_hwctx->device, supported_formats[i].d3d_format, &format_support);
+ if (SUCCEEDED(hr) && (format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
+ constraints->valid_sw_formats[nb_sw_formats++] = supported_formats[i].pix_fmt;
+ }
+ constraints->valid_sw_formats[nb_sw_formats] = AV_PIX_FMT_NONE;
+
+ constraints->valid_hw_formats = av_malloc_array(2, sizeof(*constraints->valid_hw_formats));
+ if (!constraints->valid_hw_formats)
+ return AVERROR(ENOMEM);
+
+ constraints->valid_hw_formats[0] = AV_PIX_FMT_D3D11;
+ constraints->valid_hw_formats[1] = AV_PIX_FMT_NONE;
+
+ return 0;
+}
+
static void free_texture(void *opaque, uint8_t *data)
{
ID3D11Texture2D_Release((ID3D11Texture2D *)opaque);
{
AVD3D11VADeviceContext *device_hwctx = hwdev->hwctx;
- if (device_hwctx->device)
+ if (device_hwctx->device) {
ID3D11Device_Release(device_hwctx->device);
+ device_hwctx->device = NULL;
+ }
- if (device_hwctx->device_context)
+ if (device_hwctx->device_context) {
ID3D11DeviceContext_Release(device_hwctx->device_context);
+ device_hwctx->device_context = NULL;
+ }
- if (device_hwctx->video_device)
+ if (device_hwctx->video_device) {
ID3D11VideoDevice_Release(device_hwctx->video_device);
+ device_hwctx->video_device = NULL;
+ }
- if (device_hwctx->video_context)
+ if (device_hwctx->video_context) {
ID3D11VideoContext_Release(device_hwctx->video_context);
+ device_hwctx->video_context = NULL;
+ }
- if (device_hwctx->lock == d3d11va_default_lock)
+ if (device_hwctx->lock == d3d11va_default_lock) {
CloseHandle(device_hwctx->lock_ctx);
+ device_hwctx->lock_ctx = INVALID_HANDLE_VALUE;
+ device_hwctx->lock = NULL;
+ }
}
static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
hr = mD3D11CreateDevice(pAdapter, pAdapter ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE, NULL, creationFlags, NULL, 0,
D3D11_SDK_VERSION, &device_hwctx->device, NULL, NULL);
- if (pAdapter)
+ if (pAdapter) {
+ DXGI_ADAPTER_DESC2 desc;
+ hr = IDXGIAdapter2_GetDesc(pAdapter, &desc);
+ if (!FAILED(hr)) {
+ av_log(ctx, AV_LOG_INFO, "Using device %04x:%04x (%ls).\n",
+ desc.VendorId, desc.DeviceId, desc.Description);
+ }
IDXGIAdapter_Release(pAdapter);
+ }
if (FAILED(hr)) {
av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device (%lx)\n", (long)hr);
return AVERROR_UNKNOWN;
.device_create = d3d11va_device_create,
.device_init = d3d11va_device_init,
.device_uninit = d3d11va_device_uninit,
+ .frames_get_constraints = d3d11va_frames_get_constraints,
.frames_init = d3d11va_frames_init,
.frames_uninit = d3d11va_frames_uninit,
.frames_get_buffer = d3d11va_get_buffer,