-static int ff_dxva2_common_end_frame(AVCodecContext *avctx, MpegEncContext *s,
- const void *pp, unsigned pp_size,
- const void *qm, unsigned qm_size,
- int (*commit_bs_si)(AVCodecContext *,
- DXVA2_DecodeBufferDesc *bs,
- DXVA2_DecodeBufferDesc *slice))
-{
- struct dxva_context *ctx = avctx->hwaccel_context;
- unsigned buffer_count = 0;
- DXVA2_DecodeBufferDesc buffer[4];
- DXVA2_DecodeExecuteParams exec;
- int result;
-
- if (FAILED(IDirectXVideoDecoder_BeginFrame(ctx->decoder,
- get_surface(s->current_picture_ptr),
- NULL))) {
- av_log(avctx, AV_LOG_ERROR, "Failed to begin frame\n");
- return -1;
- }
-
- result = commit_buffer(avctx, ctx, &buffer[buffer_count],
- DXVA2_PictureParametersBufferType,
- pp, pp_size, 0);
- if (result) {
- av_log(avctx, AV_LOG_ERROR,
- "Failed to add picture parameter buffer\n");
- goto end;
- }
- buffer_count++;
-
- if (qm_size > 0) {
- result = commit_buffer(avctx, ctx, &buffer[buffer_count],
- DXVA2_InverseQuantizationMatrixBufferType,
- qm, qm_size, 0);
- if (result) {
- av_log(avctx, AV_LOG_ERROR,
- "Failed to add inverse quantization matrix buffer\n");
- goto end;
- }
- buffer_count++;
- }
-
- result = commit_bs_si(avctx,
- &buffer[buffer_count + 0],
- &buffer[buffer_count + 1]);
- if (result) {
- av_log(avctx, AV_LOG_ERROR,
- "Failed to add bitstream or slice control buffer\n");
- goto end;
- }
- buffer_count += 2;
-
- /* TODO Film Grain when possible */
-
- assert(buffer_count == 1 + (qm_size > 0) + 2);
-
- memset(&exec, 0, sizeof(exec));
- exec.NumCompBuffers = buffer_count;
- exec.pCompressedBuffers = buffer;
- exec.pExtensionData = NULL;
- if (FAILED(IDirectXVideoDecoder_Execute(ctx->decoder, &exec))) {
- av_log(avctx, AV_LOG_ERROR, "Failed to execute\n");
- result = -1;
- }
-
-end:
- if (FAILED(IDirectXVideoDecoder_EndFrame(ctx->decoder, NULL))) {
- av_log(avctx, AV_LOG_ERROR, "Failed to end frame\n");
- result = -1;
- }
-
- if (!result)
- ff_draw_horiz_band(s, 0, s->avctx->height);
- return result;
-}
-
-static int end_frame(AVCodecContext *avctx)