static struct mp_image *d3d11va_new_ref(ID3D11VideoDecoderOutputView *view, int w, int h) { if (!view) return NULL; struct d3d11va_surface *surface = talloc_zero(NULL, struct d3d11va_surface); surface->surface = view; ID3D11VideoDecoderOutputView_AddRef(surface->surface); ID3D11VideoDecoderOutputView_GetResource( surface->surface, (ID3D11Resource **)&surface->texture); D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC surface_desc; ID3D11VideoDecoderOutputView_GetDesc(surface->surface, &surface_desc); surface->subindex = surface_desc.Texture2D.ArraySlice; struct mp_image *mpi = mp_image_new_custom_ref(NULL, surface, d3d11va_release_img); if (!mpi) abort(); mp_image_setfmt(mpi, IMGFMT_D3D11VA); mp_image_set_size(mpi, w, h); mpi->planes[0] = NULL; mpi->planes[1] = (void *)surface->texture; mpi->planes[2] = (void *)(intptr_t)surface->subindex; mpi->planes[3] = (void *)surface->surface; return mpi; }
static void DxDestroySurfaces(vlc_va_t *va) { directx_sys_t *dx_sys = &va->sys->dx_sys; if (dx_sys->surface_count) { ID3D11Resource *p_texture; ID3D11VideoDecoderOutputView_GetResource( (ID3D11VideoDecoderOutputView*) dx_sys->hw_surface[0], &p_texture ); ID3D11Resource_Release(p_texture); ID3D11Resource_Release(p_texture); } }
struct mp_image *d3d11va_new_ref(ID3D11VideoDecoderOutputView *view, int w, int h) { if (!view) return NULL; struct d3d11va_surface *surface = talloc_zero(NULL, struct d3d11va_surface); surface->d3d11_dll = LoadLibrary(L"d3d11.dll"); if (!surface->d3d11_dll) goto fail; surface->surface = view; ID3D11VideoDecoderOutputView_AddRef(surface->surface); ID3D11VideoDecoderOutputView_GetResource( surface->surface, (ID3D11Resource **)&surface->texture); struct mp_image *mpi = mp_image_new_custom_ref( &(struct mp_image){0}, surface, d3d11va_release_img);
static picture_t *DxAllocPicture(vlc_va_t *va, const video_format_t *fmt, unsigned index) { video_format_t src_fmt = *fmt; src_fmt.i_chroma = VLC_CODEC_D3D11_OPAQUE; picture_sys_t *pic_sys = calloc(1, sizeof(*pic_sys)); if (unlikely(pic_sys == NULL)) return NULL; pic_sys->decoder = (ID3D11VideoDecoderOutputView*) va->sys->dx_sys.hw_surface[index]; ID3D11VideoDecoderOutputView_GetResource(pic_sys->decoder, (ID3D11Resource**) &pic_sys->texture); pic_sys->context = va->sys->d3dctx; picture_resource_t res = { .p_sys = pic_sys, .pf_destroy = DestroyPicture, }; picture_t *pic = picture_NewFromResource(&src_fmt, &res); if (unlikely(pic == NULL)) { free(pic_sys); return NULL; } return pic; }