New patch with a "template" naming scheme incoming.

On Wed, May 6, 2015 at 1:42 PM, Steve Lhomme <[email protected]> wrote:
> most calls to DXVA are now done via macros and the core C code is included
> ---
>  libavcodec/Makefile         | 12 ++++-----
>  libavcodec/dxva.c           | 23 ++++++++++++++++++
>  libavcodec/dxva2.c          | 42 +++++++++++++-------------------
>  libavcodec/dxva2_h264.c     | 31 +++++++-----------------
>  libavcodec/dxva2_hevc.c     | 30 +++++++----------------
>  libavcodec/dxva2_internal.h | 19 +++++----------
>  libavcodec/dxva2_mpeg2.c    | 31 +++++++-----------------
>  libavcodec/dxva2_vc1.c      | 43 +++++++--------------------------
>  libavcodec/dxva_h264.c      | 35 +++++++++++++++++++++++++++
>  libavcodec/dxva_hevc.c      | 35 +++++++++++++++++++++++++++
>  libavcodec/dxva_internal.h  | 59 
> +++++++++++++++++++++++++++++++++++++++++++++
>  libavcodec/dxva_mpeg2.c     | 35 +++++++++++++++++++++++++++
>  libavcodec/dxva_vc1.c       | 48 ++++++++++++++++++++++++++++++++++++
>  13 files changed, 300 insertions(+), 143 deletions(-)
>  create mode 100644 libavcodec/dxva.c
>  create mode 100644 libavcodec/dxva_h264.c
>  create mode 100644 libavcodec/dxva_hevc.c
>  create mode 100644 libavcodec/dxva_internal.h
>  create mode 100644 libavcodec/dxva_mpeg2.c
>  create mode 100644 libavcodec/dxva_vc1.c
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index fc8c6e9..66b3cbe 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -557,25 +557,25 @@ OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER)       += adpcm.o 
> adpcm_data.o
>  OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER)       += adpcmenc.o adpcm_data.o
>
>  # hardware accelerators
> -OBJS-$(CONFIG_DXVA2)                      += dxva2.o
> +OBJS-$(CONFIG_DXVA2)                      += dxva.o
>  OBJS-$(CONFIG_VAAPI)                      += vaapi.o
>  OBJS-$(CONFIG_VDA)                        += vda.o
>  OBJS-$(CONFIG_VDPAU)                      += vdpau.o
>
>  OBJS-$(CONFIG_H263_VAAPI_HWACCEL)         += vaapi_mpeg4.o
>  OBJS-$(CONFIG_H263_VDPAU_HWACCEL)         += vdpau_mpeg4.o
> -OBJS-$(CONFIG_H264_DXVA2_HWACCEL)         += dxva2_h264.o
> +OBJS-$(CONFIG_H264_DXVA2_HWACCEL)         += dxva_h264.o
>  OBJS-$(CONFIG_H264_VAAPI_HWACCEL)         += vaapi_h264.o
>  OBJS-$(CONFIG_H264_VDA_HWACCEL)           += vda_h264.o
>  OBJS-$(CONFIG_H264_VDPAU_HWACCEL)         += vdpau_h264.o
> -OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL)         += dxva2_hevc.o
> +OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL)         += dxva_hevc.o
>  OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)        += vdpau_mpeg12.o
> -OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)        += dxva2_mpeg2.o
> +OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)        += dxva_mpeg2.o
>  OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)        += vaapi_mpeg2.o
>  OBJS-$(CONFIG_MPEG2_VDPAU_HWACCEL)        += vdpau_mpeg12.o
>  OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL)        += vaapi_mpeg4.o
>  OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)        += vdpau_mpeg4.o
> -OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)          += dxva2_vc1.o
> +OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)          += dxva_vc1.o
>  OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)          += vaapi_vc1.o
>  OBJS-$(CONFIG_VC1_VDPAU_HWACCEL)          += vdpau_vc1.o
>
> @@ -723,7 +723,7 @@ SKIPHEADERS                            += %_tablegen.h    
>               \
>                                            tableprint.h                  \
>                                            $(ARCH)/vp56_arith.h          \
>
> -SKIPHEADERS-$(CONFIG_DXVA2)            += dxva2.h dxva2_internal.h
> +SKIPHEADERS-$(CONFIG_DXVA2)            += dxva.h dxva_internal.h 
> dxva2_internal.h
>  SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER)  += libschroedinger.h
>  SKIPHEADERS-$(CONFIG_MPEG_XVMC_DECODER) += xvmc.h
>  SKIPHEADERS-$(CONFIG_QSV)              += qsv.h qsv_internal.h
> diff --git a/libavcodec/dxva.c b/libavcodec/dxva.c
> new file mode 100644
> index 0000000..b28bea4
> --- /dev/null
> +++ b/libavcodec/dxva.c
> @@ -0,0 +1,23 @@
> +/*
> + * DXVA2 HW acceleration.
> + *
> + * copyright (c) 2010 Laurent Aimar
> + *
> + * This file is part of Libav.
> + *
> + * Libav is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * Libav is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with Libav; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +#include "dxva_internal.h"
> +#include "dxva2.c"
> diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
> index 9ee22c8..2ab2cb0 100644
> --- a/libavcodec/dxva2.c
> +++ b/libavcodec/dxva2.c
> @@ -1,5 +1,5 @@
>  /*
> - * DXVA2 HW acceleration.
> + * DirectX HW acceleration.
>   *
>   * copyright (c) 2010 Laurent Aimar
>   *
> @@ -28,17 +28,16 @@
>
>  #include "avcodec.h"
>  #include "mpegvideo.h"
> -#include "dxva2_internal.h"
>
> -void *ff_dxva2_get_surface(const AVFrame *frame)
> +dxva_surface_t *ff_dxva2_get_surface(const AVFrame *frame)
>  {
> -    return frame->data[3];
> +    return (dxva_surface_t*) frame->data[3];
>  }
>
>  unsigned ff_dxva2_get_surface_index(const struct dxva_context *ctx,
>                                      const AVFrame *frame)
>  {
> -    void *surface = ff_dxva2_get_surface(frame);
> +    dxva_surface_t *surface = ff_dxva2_get_surface(frame);
>      unsigned i;
>
>      for (i = 0; i < ctx->surface_count; i++)
> @@ -51,8 +50,8 @@ unsigned ff_dxva2_get_surface_index(const struct 
> dxva_context *ctx,
>
>  int ff_dxva2_commit_buffer(AVCodecContext *avctx,
>                             struct dxva_context *ctx,
> -                           DXVA2_DecodeBufferDesc *dsc,
> -                           unsigned type, const void *data, unsigned size,
> +                           DECODER_BUFFER_DESC *dsc,
> +                           DECODER_BUFFER_TYPE type, const void *data, 
> unsigned size,
>                             unsigned mb_count)
>  {
>      void     *dxva_data;
> @@ -60,8 +59,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx,
>      int      result;
>      HRESULT hr;
>
> -    hr = IDirectXVideoDecoder_GetBuffer(ctx->decoder, type,
> -                                        &dxva_data, &dxva_size);
> +    hr = DECODER_GET_BUFFER(ctx, type, &dxva_data, &dxva_size);
>      if (FAILED(hr)) {
>          av_log(avctx, AV_LOG_ERROR, "Failed to get a buffer for %u: 0x%lx\n",
>                 type, hr);
> @@ -71,7 +69,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx,
>          memcpy(dxva_data, data, size);
>
>          memset(dsc, 0, sizeof(*dsc));
> -        dsc->CompressedBufferType = type;
> +        DECODER_BUFFER_DESC_SET_TYPE(dsc, type);
>          dsc->DataSize             = size;
>          dsc->NumMBsInBuffer       = mb_count;
>
> @@ -81,7 +79,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx,
>          result = -1;
>      }
>
> -    hr = IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder, type);
> +    hr = DECODER_RELEASE_BUFFER(ctx, type);
>      if (FAILED(hr)) {
>          av_log(avctx, AV_LOG_ERROR,
>                 "Failed to release buffer type %u: 0x%lx\n",
> @@ -95,20 +93,17 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, 
> AVFrame *frame,
>                                const void *pp, unsigned pp_size,
>                                const void *qm, unsigned qm_size,
>                                int (*commit_bs_si)(AVCodecContext *,
> -                                                  DXVA2_DecodeBufferDesc *bs,
> -                                                  DXVA2_DecodeBufferDesc 
> *slice))
> +                                                  DECODER_BUFFER_DESC *bs,
> +                                                  DECODER_BUFFER_DESC 
> *slice))
>  {
>      struct dxva_context *ctx = avctx->hwaccel_context;
>      unsigned               buffer_count = 0;
> -    DXVA2_DecodeBufferDesc buffer[4];
> -    DXVA2_DecodeExecuteParams exec = { 0 };
> +    DECODER_BUFFER_DESC buffer[4];
>      int result, runs = 0;
>      HRESULT hr;
>
>      do {
> -        hr = IDirectXVideoDecoder_BeginFrame(ctx->decoder,
> -                                             ff_dxva2_get_surface(frame),
> -                                             NULL);
> +        hr = DECODER_BEGIN_FRAME(ctx, ff_dxva2_get_surface(frame));
>          if (hr == E_PENDING)
>              av_usleep(2000);
>      } while (hr == E_PENDING && ++runs < 50);
> @@ -119,7 +114,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, 
> AVFrame *frame,
>      }
>
>      result = ff_dxva2_commit_buffer(avctx, ctx, &buffer[buffer_count],
> -                                    DXVA2_PictureParametersBufferType,
> +                                    DECODER_BUFTYPE_PICTURE_PARAMS,
>                                      pp, pp_size, 0);
>      if (result) {
>          av_log(avctx, AV_LOG_ERROR,
> @@ -130,7 +125,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, 
> AVFrame *frame,
>
>      if (qm_size > 0) {
>          result = ff_dxva2_commit_buffer(avctx, ctx, &buffer[buffer_count],
> -                                        
> DXVA2_InverseQuantizationMatrixBufferType,
> +                                        DECODER_BUFTYPE_QUANT_MATRIX,
>                                          qm, qm_size, 0);
>          if (result) {
>              av_log(avctx, AV_LOG_ERROR,
> @@ -154,17 +149,14 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, 
> AVFrame *frame,
>
>      assert(buffer_count == 1 + (qm_size > 0) + 2);
>
> -    exec.NumCompBuffers      = buffer_count;
> -    exec.pCompressedBuffers  = buffer;
> -    exec.pExtensionData      = NULL;
> -    hr = IDirectXVideoDecoder_Execute(ctx->decoder, &exec);
> +    hr = DECODER_SUBMIT_BUFFER(ctx, buffer, buffer_count);
>      if (FAILED(hr)) {
>          av_log(avctx, AV_LOG_ERROR, "Failed to execute: 0x%lx\n", hr);
>          result = -1;
>      }
>
>  end:
> -    hr = IDirectXVideoDecoder_EndFrame(ctx->decoder, NULL);
> +    hr = DECODER_END_FRAME(ctx);
>      if (FAILED(hr)) {
>          av_log(avctx, AV_LOG_ERROR, "Failed to end frame: 0x%lx\n", hr);
>          result = -1;
> diff --git a/libavcodec/dxva2_h264.c b/libavcodec/dxva2_h264.c
> index a5e9705..777086b 100644
> --- a/libavcodec/dxva2_h264.c
> +++ b/libavcodec/dxva2_h264.c
> @@ -1,5 +1,5 @@
>  /*
> - * DXVA2 H264 HW acceleration.
> + * DirectX H264 HW acceleration.
>   *
>   * copyright (c) 2009 Laurent Aimar
>   *
> @@ -20,7 +20,6 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
>   */
>
> -#include "dxva2_internal.h"
>  #include "h264.h"
>  #include "h264data.h"
>  #include "mpegutils.h"
> @@ -289,8 +288,8 @@ static void fill_slice_long(AVCodecContext *avctx, 
> DXVA_Slice_H264_Long *slice,
>  }
>
>  static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
> -                                             DXVA2_DecodeBufferDesc *bs,
> -                                             DXVA2_DecodeBufferDesc *sc)
> +                                             DECODER_BUFFER_DESC *bs,
> +                                             DECODER_BUFFER_DESC *sc)
>  {
>      const H264Context *h = avctx->priv_data;
>      const unsigned mb_count = h->mb_width * h->mb_height;
> @@ -307,9 +306,9 @@ static int 
> commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
>      unsigned i;
>
>      /* Create an annex B bitstream buffer with only slice NAL and finalize 
> slice */
> -    if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder,
> -                                              DXVA2_BitStreamDateBufferType,
> -                                              &dxva_data_ptr, &dxva_size)))
> +    if (FAILED(DECODER_GET_BUFFER(ctx,
> +                                     DECODER_BUFTYPE_BITSTREAM,
> +                                     &dxva_data_ptr, &dxva_size)))
>          return -1;
>
>      dxva_data = dxva_data_ptr;
> @@ -363,14 +362,13 @@ static int 
> commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
>
>          slice->SliceBytesInBuffer += padding;
>      }
> -    if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder,
> -                                                  
> DXVA2_BitStreamDateBufferType)))
> +    if (FAILED(DECODER_RELEASE_BUFFER(ctx, DECODER_BUFTYPE_BITSTREAM)))
>          return -1;
>      if (i < ctx_pic->slice_count)
>          return -1;
>
>      memset(bs, 0, sizeof(*bs));
> -    bs->CompressedBufferType = DXVA2_BitStreamDateBufferType;
> +    DECODER_BUFFER_DESC_SET_TYPE(bs, DECODER_BUFTYPE_BITSTREAM);
>      bs->DataSize             = current - dxva_data;
>      bs->NumMBsInBuffer       = mb_count;
>
> @@ -383,7 +381,7 @@ static int 
> commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
>      }
>      assert((bs->DataSize & 127) == 0);
>      return ff_dxva2_commit_buffer(avctx, ctx, sc,
> -                                  DXVA2_SliceControlBufferType,
> +                                  DECODER_BUFTYPE_SLICE_CONTROL,
>                                    slice_data, slice_size, mb_count);
>  }
>
> @@ -462,14 +460,3 @@ static int dxva2_h264_end_frame(AVCodecContext *avctx)
>          ff_h264_draw_horiz_band(h, sl, 0, h->avctx->height);
>      return ret;
>  }
> -
> -AVHWAccel ff_h264_dxva2_hwaccel = {
> -    .name           = "h264_dxva2",
> -    .type           = AVMEDIA_TYPE_VIDEO,
> -    .id             = AV_CODEC_ID_H264,
> -    .pix_fmt        = AV_PIX_FMT_DXVA2_VLD,
> -    .start_frame    = dxva2_h264_start_frame,
> -    .decode_slice   = dxva2_h264_decode_slice,
> -    .end_frame      = dxva2_h264_end_frame,
> -    .frame_priv_data_size = sizeof(struct dxva2_picture_context),
> -};
> diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
> index 257bee7..6821689 100644
> --- a/libavcodec/dxva2_hevc.c
> +++ b/libavcodec/dxva2_hevc.c
> @@ -1,5 +1,5 @@
>  /*
> - * DXVA2 HEVC HW acceleration.
> + * DirectX HEVC HW acceleration.
>   *
>   * copyright (c) 2014 - 2015 Hendrik Leppkes
>   *
> @@ -22,7 +22,6 @@
>
>  #include "libavutil/avassert.h"
>
> -#include "dxva2_internal.h"
>  #include "hevc.h"
>
>  #define MAX_SLICES 256
> @@ -228,8 +227,8 @@ static void fill_slice_short(DXVA_Slice_HEVC_Short *slice,
>  }
>
>  static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
> -                                             DXVA2_DecodeBufferDesc *bs,
> -                                             DXVA2_DecodeBufferDesc *sc)
> +                                             DECODER_BUFFER_DESC *bs,
> +                                             DECODER_BUFFER_DESC *sc)
>  {
>      const HEVCContext *h = avctx->priv_data;
>      struct dxva_context *ctx = avctx->hwaccel_context;
> @@ -245,9 +244,9 @@ static int 
> commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
>      unsigned i;
>
>      /* Create an annex B bitstream buffer with only slice NAL and finalize 
> slice */
> -    if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder,
> -                                              DXVA2_BitStreamDateBufferType,
> -                                              &dxva_data_ptr, &dxva_size)))
> +    if (FAILED(DECODER_GET_BUFFER(ctx,
> +                                     DECODER_BUFTYPE_BITSTREAM,
> +                                     &dxva_data_ptr, &dxva_size)))
>          return -1;
>
>      dxva_data = dxva_data_ptr;
> @@ -284,14 +283,13 @@ static int 
> commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
>
>          slice->SliceBytesInBuffer += padding;
>      }
> -    if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder,
> -                                                  
> DXVA2_BitStreamDateBufferType)))
> +    if (FAILED(DECODER_RELEASE_BUFFER(ctx, DECODER_BUFTYPE_BITSTREAM)))
>          return -1;
>      if (i < ctx_pic->slice_count)
>          return -1;
>
>      memset(bs, 0, sizeof(*bs));
> -    bs->CompressedBufferType = DXVA2_BitStreamDateBufferType;
> +    DECODER_BUFFER_DESC_SET_TYPE(bs, DECODER_BUFTYPE_BITSTREAM);
>      bs->DataSize             = current - dxva_data;
>      bs->NumMBsInBuffer       = 0;
>
> @@ -300,7 +298,7 @@ static int 
> commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
>
>      av_assert0((bs->DataSize & 127) == 0);
>      return ff_dxva2_commit_buffer(avctx, ctx, sc,
> -                                  DXVA2_SliceControlBufferType,
> +                                  DECODER_BUFTYPE_SLICE_CONTROL,
>                                    slice_data, slice_size, 0);
>  }
>
> @@ -369,13 +367,3 @@ static int dxva2_hevc_end_frame(AVCodecContext *avctx)
>      return ret;
>  }
>
> -AVHWAccel ff_hevc_dxva2_hwaccel = {
> -    .name           = "hevc_dxva2",
> -    .type           = AVMEDIA_TYPE_VIDEO,
> -    .id             = AV_CODEC_ID_HEVC,
> -    .pix_fmt        = AV_PIX_FMT_DXVA2_VLD,
> -    .start_frame    = dxva2_hevc_start_frame,
> -    .decode_slice   = dxva2_hevc_decode_slice,
> -    .end_frame      = dxva2_hevc_end_frame,
> -    .frame_priv_data_size = sizeof(struct hevc_dxva2_picture_context),
> -};
> diff --git a/libavcodec/dxva2_internal.h b/libavcodec/dxva2_internal.h
> index b775e6c..9ff08e7 100644
> --- a/libavcodec/dxva2_internal.h
> +++ b/libavcodec/dxva2_internal.h
> @@ -1,5 +1,5 @@
>  /*
> - * DXVA2 HW acceleration
> + * DirectX HW acceleration
>   *
>   * copyright (c) 2010 Laurent Aimar
>   *
> @@ -23,26 +23,19 @@
>  #ifndef AVCODEC_DXVA_INTERNAL_H
>  #define AVCODEC_DXVA_INTERNAL_H
>
> -#define COBJMACROS
> -
>  #include "config.h"
>
> -#include "dxva2.h"
> -#if HAVE_DXVA_H
> -#include <dxva.h>
> -#endif
> -
>  #include "avcodec.h"
>  #include "mpegvideo.h"
>
> -void *ff_dxva2_get_surface(const AVFrame *frame);
> +dxva_surface_t *ff_dxva2_get_surface(const AVFrame *frame);
>
>  unsigned ff_dxva2_get_surface_index(const struct dxva_context *,
>                                      const AVFrame *frame);
>
>  int ff_dxva2_commit_buffer(AVCodecContext *, struct dxva_context *,
> -                           DXVA2_DecodeBufferDesc *,
> -                           unsigned type, const void *data, unsigned size,
> +                           DECODER_BUFFER_DESC *,
> +                           DECODER_BUFFER_TYPE type, const void *data, 
> unsigned size,
>                             unsigned mb_count);
>
>
> @@ -50,7 +43,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *, AVFrame *,
>                                const void *pp, unsigned pp_size,
>                                const void *qm, unsigned qm_size,
>                                int (*commit_bs_si)(AVCodecContext *,
> -                                                  DXVA2_DecodeBufferDesc *bs,
> -                                                  DXVA2_DecodeBufferDesc 
> *slice));
> +                                                  DECODER_BUFFER_DESC *bs,
> +                                                  DECODER_BUFFER_DESC 
> *slice));
>
>  #endif /* AVCODEC_DXVA_INTERNAL_H */
> diff --git a/libavcodec/dxva2_mpeg2.c b/libavcodec/dxva2_mpeg2.c
> index 65624e3..1edda82 100644
> --- a/libavcodec/dxva2_mpeg2.c
> +++ b/libavcodec/dxva2_mpeg2.c
> @@ -1,5 +1,5 @@
>  /*
> - * MPEG-2 HW acceleration.
> + * DirectX MPEG-2 HW acceleration.
>   *
>   * copyright (c) 2010 Laurent Aimar
>   *
> @@ -21,7 +21,6 @@
>   */
>
>  #include "libavutil/log.h"
> -#include "dxva2_internal.h"
>  #include "mpegutils.h"
>
>  #define MAX_SLICES 1024
> @@ -147,8 +146,8 @@ static void fill_slice(AVCodecContext *avctx,
>      slice->wMBbitOffset        = 4 * 8 + get_bits_count(&gb);
>  }
>  static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
> -                                             DXVA2_DecodeBufferDesc *bs,
> -                                             DXVA2_DecodeBufferDesc *sc)
> +                                             DECODER_BUFFER_DESC *bs,
> +                                             DECODER_BUFFER_DESC *sc)
>  {
>      const struct MpegEncContext *s = avctx->priv_data;
>      struct dxva_context *ctx = avctx->hwaccel_context;
> @@ -161,9 +160,9 @@ static int 
> commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
>      unsigned dxva_size;
>      unsigned i;
>
> -    if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder,
> -                                              DXVA2_BitStreamDateBufferType,
> -                                              &dxva_data_ptr, &dxva_size)))
> +    if (FAILED(DECODER_GET_BUFFER(ctx,
> +                                     DECODER_BUFTYPE_BITSTREAM,
> +                                  &dxva_data_ptr, &dxva_size)))
>          return -1;
>
>      dxva_data = dxva_data_ptr;
> @@ -190,19 +189,18 @@ static int 
> commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
>          memcpy(current, &ctx_pic->bitstream[position], size);
>          current += size;
>      }
> -    if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder,
> -                                                  
> DXVA2_BitStreamDateBufferType)))
> +    if (FAILED(DECODER_RELEASE_BUFFER(ctx, DECODER_BUFTYPE_BITSTREAM)))
>          return -1;
>      if (i < ctx_pic->slice_count)
>          return -1;
>
>      memset(bs, 0, sizeof(*bs));
> -    bs->CompressedBufferType = DXVA2_BitStreamDateBufferType;
> +    DECODER_BUFFER_DESC_SET_TYPE(bs, DECODER_BUFTYPE_BITSTREAM);
>      bs->DataSize             = current - dxva_data;
>      bs->NumMBsInBuffer       = mb_count;
>
>      return ff_dxva2_commit_buffer(avctx, ctx, sc,
> -                                  DXVA2_SliceControlBufferType,
> +                                  DECODER_BUFTYPE_SLICE_CONTROL,
>                                    ctx_pic->slice,
>                                    ctx_pic->slice_count * 
> sizeof(*ctx_pic->slice),
>                                    mb_count);
> @@ -270,14 +268,3 @@ static int dxva2_mpeg2_end_frame(AVCodecContext *avctx)
>          ff_mpeg_draw_horiz_band(s, 0, avctx->height);
>      return ret;
>  }
> -
> -AVHWAccel ff_mpeg2_dxva2_hwaccel = {
> -    .name           = "mpeg2_dxva2",
> -    .type           = AVMEDIA_TYPE_VIDEO,
> -    .id             = AV_CODEC_ID_MPEG2VIDEO,
> -    .pix_fmt        = AV_PIX_FMT_DXVA2_VLD,
> -    .start_frame    = dxva2_mpeg2_start_frame,
> -    .decode_slice   = dxva2_mpeg2_decode_slice,
> -    .end_frame      = dxva2_mpeg2_end_frame,
> -    .frame_priv_data_size = sizeof(struct dxva2_picture_context),
> -};
> diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c
> index 1524b51..210b95d 100644
> --- a/libavcodec/dxva2_vc1.c
> +++ b/libavcodec/dxva2_vc1.c
> @@ -1,5 +1,5 @@
>  /*
> - * DXVA2 WMV3/VC-1 HW acceleration.
> + * DirectX WMV3/VC-1 HW acceleration.
>   *
>   * copyright (c) 2010 Laurent Aimar
>   *
> @@ -20,7 +20,6 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
>   */
>
> -#include "dxva2_internal.h"
>  #include "mpegutils.h"
>  #include "vc1.h"
>  #include "vc1data.h"
> @@ -157,8 +156,8 @@ static void fill_slice(AVCodecContext *avctx, 
> DXVA_SliceInfo *slice,
>  }
>
>  static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
> -                                             DXVA2_DecodeBufferDesc *bs,
> -                                             DXVA2_DecodeBufferDesc *sc)
> +                                             DECODER_BUFFER_DESC *bs,
> +                                             DECODER_BUFFER_DESC *sc)
>  {
>      const VC1Context *v = avctx->priv_data;
>      struct dxva_context *ctx = avctx->hwaccel_context;
> @@ -178,9 +177,9 @@ static int 
> commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
>      unsigned dxva_size;
>      int result;
>
> -    if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder,
> -                                              DXVA2_BitStreamDateBufferType,
> -                                              &dxva_data_ptr, &dxva_size)))
> +    if (FAILED(DECODER_GET_BUFFER(ctx,
> +                                     DECODER_BUFTYPE_BITSTREAM,
> +                                  &dxva_data_ptr, &dxva_size)))
>          return -1;
>
>      dxva_data = dxva_data_ptr;
> @@ -194,20 +193,19 @@ static int 
> commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
>              memset(dxva_data + start_code_size + slice_size, 0, padding);
>          slice->dwSliceBitsInBuffer = 8 * data_size;
>      }
> -    if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder,
> -                                                  
> DXVA2_BitStreamDateBufferType)))
> +    if (FAILED(DECODER_RELEASE_BUFFER(ctx, DECODER_BUFTYPE_BITSTREAM)))
>          return -1;
>      if (result)
>          return result;
>
>      memset(bs, 0, sizeof(*bs));
> -    bs->CompressedBufferType = DXVA2_BitStreamDateBufferType;
> +    DECODER_BUFFER_DESC_SET_TYPE(bs, DECODER_BUFTYPE_BITSTREAM);
>      bs->DataSize             = data_size;
>      bs->NumMBsInBuffer       = s->mb_width * s->mb_height;
>      assert((bs->DataSize & 127) == 0);
>
>      return ff_dxva2_commit_buffer(avctx, ctx, sc,
> -                                  DXVA2_SliceControlBufferType,
> +                                  DECODER_BUFTYPE_SLICE_CONTROL,
>                                    slice, sizeof(*slice), bs->NumMBsInBuffer);
>  }
>
> @@ -272,26 +270,3 @@ static int dxva2_vc1_end_frame(AVCodecContext *avctx)
>      return ret;
>  }
>
> -#if CONFIG_WMV3_DXVA2_HWACCEL
> -AVHWAccel ff_wmv3_dxva2_hwaccel = {
> -    .name           = "wmv3_dxva2",
> -    .type           = AVMEDIA_TYPE_VIDEO,
> -    .id             = AV_CODEC_ID_WMV3,
> -    .pix_fmt        = AV_PIX_FMT_DXVA2_VLD,
> -    .start_frame    = dxva2_vc1_start_frame,
> -    .decode_slice   = dxva2_vc1_decode_slice,
> -    .end_frame      = dxva2_vc1_end_frame,
> -    .frame_priv_data_size = sizeof(struct dxva2_picture_context),
> -};
> -#endif
> -
> -AVHWAccel ff_vc1_dxva2_hwaccel = {
> -    .name           = "vc1_dxva2",
> -    .type           = AVMEDIA_TYPE_VIDEO,
> -    .id             = AV_CODEC_ID_VC1,
> -    .pix_fmt        = AV_PIX_FMT_DXVA2_VLD,
> -    .start_frame    = dxva2_vc1_start_frame,
> -    .decode_slice   = dxva2_vc1_decode_slice,
> -    .end_frame      = dxva2_vc1_end_frame,
> -    .frame_priv_data_size = sizeof(struct dxva2_picture_context),
> -};
> diff --git a/libavcodec/dxva_h264.c b/libavcodec/dxva_h264.c
> new file mode 100644
> index 0000000..68bf70d
> --- /dev/null
> +++ b/libavcodec/dxva_h264.c
> @@ -0,0 +1,35 @@
> +/*
> + * DXVA2 H264 HW acceleration.
> + *
> + * copyright (c) 2009 Laurent Aimar
> + *
> + * This file is part of Libav.
> + *
> + * Libav is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * Libav is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with Libav; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "dxva_internal.h"
> +#include "dxva2_h264.c"
> +
> +AVHWAccel ff_h264_dxva2_hwaccel = {
> +    .name           = "h264_dxva2",
> +    .type           = AVMEDIA_TYPE_VIDEO,
> +    .id             = AV_CODEC_ID_H264,
> +    .pix_fmt        = AV_PIX_FMT_DXVA2_VLD,
> +    .start_frame    = dxva2_h264_start_frame,
> +    .decode_slice   = dxva2_h264_decode_slice,
> +    .end_frame      = dxva2_h264_end_frame,
> +    .frame_priv_data_size = sizeof(struct dxva2_picture_context),
> +};
> diff --git a/libavcodec/dxva_hevc.c b/libavcodec/dxva_hevc.c
> new file mode 100644
> index 0000000..ee6ebde
> --- /dev/null
> +++ b/libavcodec/dxva_hevc.c
> @@ -0,0 +1,35 @@
> +/*
> + * DXVA2 HEVC HW acceleration.
> + *
> + * copyright (c) 2014 - 2015 Hendrik Leppkes
> + *
> + * This file is part of Libav.
> + *
> + * Libav is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * Libav is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with Libav; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "dxva_internal.h"
> +#include "dxva2_hevc.c"
> +
> +AVHWAccel ff_hevc_dxva2_hwaccel = {
> +    .name           = "hevc_dxva2",
> +    .type           = AVMEDIA_TYPE_VIDEO,
> +    .id             = AV_CODEC_ID_HEVC,
> +    .pix_fmt        = AV_PIX_FMT_DXVA2_VLD,
> +    .start_frame    = dxva2_hevc_start_frame,
> +    .decode_slice   = dxva2_hevc_decode_slice,
> +    .end_frame      = dxva2_hevc_end_frame,
> +    .frame_priv_data_size = sizeof(struct hevc_dxva2_picture_context),
> +};
> diff --git a/libavcodec/dxva_internal.h b/libavcodec/dxva_internal.h
> new file mode 100644
> index 0000000..8050730
> --- /dev/null
> +++ b/libavcodec/dxva_internal.h
> @@ -0,0 +1,59 @@
> +/*
> + * DXVA2 HW acceleration
> + *
> + * copyright (c) 2010 Laurent Aimar
> + * copyright (c) 2015 Steve Lhomme
> + *
> + * This file is part of Libav.
> + *
> + * Libav is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * Libav is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with Libav; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#ifndef AVCODEC_DXVA2_INTERNAL_H
> +#define AVCODEC_DXVA2_INTERNAL_H
> +
> +#define COBJMACROS
> +
> +#include "dxva2.h"
> +#include <dxva.h>
> +
> +#define dxva_surface_t                    IDirect3DSurface9
> +#define DECODER_BUFFER_DESC               DXVA2_DecodeBufferDesc
> +#define DECODER_BUFFER_TYPE               unsigned
> +#define DECODER_GET_BUFFER(ctx,t,b,s)     
> IDirectXVideoDecoder_GetBuffer(ctx->decoder, t,b,s)
> +
> +static inline HRESULT DECODER_SUBMIT_BUFFER(struct dxva_context *ctx, 
> DECODER_BUFFER_DESC *buffer, unsigned buffer_count) {
> +    DXVA2_DecodeExecuteParams exec = {
> +        .pCompressedBuffers = buffer,
> +        .NumCompBuffers = buffer_count,
> +        .pExtensionData = NULL,
> +    };
> +    return IDirectXVideoDecoder_Execute(ctx->decoder, &exec);
> +}
> +
> +#define DECODER_RELEASE_BUFFER(ctx,t)     
> IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder, t)
> +#define DECODER_BEGIN_FRAME(ctx,s)        
> IDirectXVideoDecoder_BeginFrame(ctx->decoder, s, NULL)
> +#define DECODER_END_FRAME(ctx)            
> IDirectXVideoDecoder_EndFrame(ctx->decoder, NULL)
> +
> +#define DECODER_BUFTYPE_PICTURE_PARAMS    DXVA2_PictureParametersBufferType
> +#define DECODER_BUFTYPE_QUANT_MATRIX      
> DXVA2_InverseQuantizationMatrixBufferType
> +#define DECODER_BUFTYPE_BITSTREAM         DXVA2_BitStreamDateBufferType
> +#define DECODER_BUFTYPE_SLICE_CONTROL     DXVA2_SliceControlBufferType
> +
> +#define DECODER_BUFFER_DESC_SET_TYPE(dsc, type)   dsc->CompressedBufferType 
> = type
> +
> +#include "dxva2_internal.h"
> +
> +#endif /* AVCODEC_DXVA2_INTERNAL_H */
> diff --git a/libavcodec/dxva_mpeg2.c b/libavcodec/dxva_mpeg2.c
> new file mode 100644
> index 0000000..681288c
> --- /dev/null
> +++ b/libavcodec/dxva_mpeg2.c
> @@ -0,0 +1,35 @@
> +/*
> + * DXVA2 MPEG-2 HW acceleration.
> + *
> + * copyright (c) 2010 Laurent Aimar
> + *
> + * This file is part of Libav.
> + *
> + * Libav is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * Libav is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with Libav; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "dxva_internal.h"
> +#include "dxva2_mpeg2.c"
> +
> +AVHWAccel ff_mpeg2_dxva2_hwaccel = {
> +    .name           = "mpeg2_dxva2",
> +    .type           = AVMEDIA_TYPE_VIDEO,
> +    .id             = AV_CODEC_ID_MPEG2VIDEO,
> +    .pix_fmt        = AV_PIX_FMT_DXVA2_VLD,
> +    .start_frame    = dxva2_mpeg2_start_frame,
> +    .decode_slice   = dxva2_mpeg2_decode_slice,
> +    .end_frame      = dxva2_mpeg2_end_frame,
> +    .frame_priv_data_size = sizeof(struct dxva2_picture_context),
> +};
> diff --git a/libavcodec/dxva_vc1.c b/libavcodec/dxva_vc1.c
> new file mode 100644
> index 0000000..12a74c5
> --- /dev/null
> +++ b/libavcodec/dxva_vc1.c
> @@ -0,0 +1,48 @@
> +/*
> + * DXVA2 WMV3/VC-1 HW acceleration.
> + *
> + * copyright (c) 2010 Laurent Aimar
> + *
> + * This file is part of Libav.
> + *
> + * Libav is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * Libav is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with Libav; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "dxva_internal.h"
> +#include "dxva2_vc1.c"
> +
> +#if CONFIG_WMV3_DXVA2_HWACCEL
> +AVHWAccel ff_wmv3_dxva2_hwaccel = {
> +    .name           = "wmv3_dxva2",
> +    .type           = AVMEDIA_TYPE_VIDEO,
> +    .id             = AV_CODEC_ID_WMV3,
> +    .pix_fmt        = AV_PIX_FMT_DXVA2_VLD,
> +    .start_frame    = dxva2_vc1_start_frame,
> +    .decode_slice   = dxva2_vc1_decode_slice,
> +    .end_frame      = dxva2_vc1_end_frame,
> +    .frame_priv_data_size = sizeof(struct dxva2_picture_context),
> +};
> +#endif
> +
> +AVHWAccel ff_vc1_dxva2_hwaccel = {
> +    .name           = "vc1_dxva2",
> +    .type           = AVMEDIA_TYPE_VIDEO,
> +    .id             = AV_CODEC_ID_VC1,
> +    .pix_fmt        = AV_PIX_FMT_DXVA2_VLD,
> +    .start_frame    = dxva2_vc1_start_frame,
> +    .decode_slice   = dxva2_vc1_decode_slice,
> +    .end_frame      = dxva2_vc1_end_frame,
> +    .frame_priv_data_size = sizeof(struct dxva2_picture_context),
> +};
> --
> 2.4.0
>
> _______________________________________________
> libav-devel mailing list
> [email protected]
> https://lists.libav.org/mailman/listinfo/libav-devel
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to