On Tue, 13 Dec 2016 14:19:35 +0100 Steve Lhomme <rob...@gmail.com> wrote:
> +static int d3d11va_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, > + const AVFrame *src) > +{ > + ID3D11VideoDecoderOutputView *surface; > + D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC surfaceDesc; > + D3D11_TEXTURE2D_DESC dstDesc; > + D3D11_MAPPED_SUBRESOURCE LockedRect; > + ID3D11Resource *pTexture; > + HRESULT hr; > + AVD3D11VAFramesContext *frames_hwctx = ctx->hwctx; > + D3D11VAFramesContext *s = ctx->internal->priv; > + > + uint8_t *surf_data[4] = { NULL }; > + int surf_linesize[4] = { 0 }; > + int i; > + > + int download = !!src->hw_frames_ctx; > + > + surface = (ID3D11VideoDecoderOutputView*)(download ? src->data[3] : > dst->data[3]); > + > + ID3D11VideoDecoderOutputView_GetDesc(surface, &surfaceDesc); > + ID3D11VideoDecoderOutputView_GetResource(surface, &pTexture); > + > + ID3D11DeviceContext_CopySubresourceRegion(s->d3d11_context, > (ID3D11Resource*)frames_hwctx->staging_texture, > + 0, 0, 0, 0, > + (ID3D11Resource*)pTexture, surfaceDesc.Texture2D.ArraySlice, > + NULL); > + ID3D11Resource_Release(pTexture); > + > + hr = ID3D11DeviceContext_Map(s->d3d11_context, > (ID3D11Resource*)frames_hwctx->staging_texture, > + 0, D3D11_MAP_READ, 0, &LockedRect); > + if (FAILED(hr)) { > + av_log(ctx, AV_LOG_ERROR, "Unable to lock D3D11VA surface %lx\n", > hr); > + return AVERROR_UNKNOWN; > + } > + > + for (i = 0; download ? dst->data[i] : src->data[i]; i++) > + surf_linesize[i] = LockedRect.RowPitch; > + > + ID3D11Texture2D_GetDesc(frames_hwctx->staging_texture, &dstDesc); > + av_image_fill_pointers(surf_data, ctx->sw_format, dstDesc.Height, > + (uint8_t*)LockedRect.pData, surf_linesize); > + > + if (download) { > + av_image_copy(dst->data, dst->linesize, surf_data, surf_linesize, > + ctx->sw_format, src->width, src->height); > + } else { > + av_image_copy(surf_data, surf_linesize, src->data, src->linesize, > + ctx->sw_format, src->width, src->height); > + } > + > + ID3D11DeviceContext_Unmap(s->d3d11_context, > (ID3D11Resource*)frames_hwctx->staging_texture, 0); > + > + return 0; > +} Missed this part during the first review, but: the staging_texture use should be either mutex-protected, or there should be a pool of staging textures. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel