[FFmpeg-devel] [PATCH] libavcodec: add h.264 dxva2 decoder to ffmpeg
Paul B Mahol
onemda at gmail.com
Sat Dec 29 01:08:08 CET 2012
On 12/28/12, Paul B Mahol <onemda at gmail.com> wrote:
> On 12/28/12, Wei Gao <highgod0401 at gmail.com> wrote:
>>
>>
>>
>> ---
>> configure | 1 +
>> libavcodec/Makefile | 5 +-
>> libavcodec/allcodecs.c | 1 +
>> libavcodec/dxva2_h264_dec.c | 228 ++++++++++++
>> libavcodec/dxva2_wrapper.c | 841
>> ++++++++++++++++++++++++++++++++++++++++++++
>> libavcodec/dxva2_wrapper.h | 392 +++++++++++++++++++++
>> 6 files changed, 1466 insertions(+), 2 deletions(-)
>> create mode 100644 libavcodec/dxva2_h264_dec.c
>> create mode 100644 libavcodec/dxva2_wrapper.c
>> create mode 100644 libavcodec/dxva2_wrapper.h
>>
>> diff --git a/configure b/configure
>> index 7cf8d9d..a7bef1f 100755
>> --- a/configure
>> +++ b/configure
>> @@ -1677,6 +1677,7 @@ h264_crystalhd_decoder_select="crystalhd
>> h264_mp4toannexb_bsf h264_parser"
>> h264_decoder_select="error_resilience golomb h264chroma h264dsp h264pred
>> h264qpel mpegvideo"
>> h264_dxva2_hwaccel_deps="dxva2api_h"
>> h264_dxva2_hwaccel_select="dxva2 h264_decoder"
>> +h264_dxva2_decoder_select="dxva2 h264_parser h264_decoder"
>> h264_vaapi_hwaccel_select="vaapi h264_decoder"
>> h264_vda_decoder_select="vda h264_parser h264_decoder"
>> h264_vda_hwaccel_deps="VideoDecodeAcceleration_VDADecoder_h pthreads"
>> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
>> index 0507028..a87142d 100644
>> --- a/libavcodec/Makefile
>> +++ b/libavcodec/Makefile
>> @@ -42,7 +42,7 @@ OBJS-$(CONFIG_AC3DSP) += ac3dsp.o
>> OBJS-$(CONFIG_CRYSTALHD) += crystalhd.o
>> OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o
>> dct32_float.o
>> OBJS-$(CONFIG_DWT) += dwt.o snow.o
>> -OBJS-$(CONFIG_DXVA2) += dxva2.o
>> +OBJS-$(CONFIG_DXVA2) += dxva2.o dxva2_wrapper.o
>> OBJS-$(CONFIG_ENCODERS) += faandct.o jfdctfst.o
>> jfdctint.o
>> OBJS-$(CONFIG_ERROR_RESILIENCE) += error_resilience.o
>> FFT-OBJS-$(CONFIG_HARDCODED_TABLES) += cos_tables.o
>> cos_fixed_tables.o
>> @@ -223,6 +223,7 @@ OBJS-$(CONFIG_H264_DECODER) += h264.o
>> \
>> cabac.o h264_sei.o h264_ps.o
>> \
>> h264_refs.o h264_cavlc.o
>> h264_cabac.o
>> OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o
>> +OBJS-$(CONFIG_H264_DXVA2_DECODER) += dxva2_h264_dec.o
>> OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o
>> OBJS-$(CONFIG_H264_VDA_HWACCEL) += vda_h264.o
>> OBJS-$(CONFIG_H264_VDA_DECODER) += vda_h264_dec.o
>> @@ -771,7 +772,7 @@ SKIPHEADERS += %_tablegen.h
>> \
>> tableprint.h
>> \
>> $(ARCH)/vp56_arith.h
>> \
>>
>> -SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h
>> +SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h
>> dxva2_wrapper.h
>> SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h
>> SKIPHEADERS-$(CONFIG_LIBUTVIDEO) += libutvideo.h
>> SKIPHEADERS-$(CONFIG_MPEG_XVMC_DECODER) += xvmc.h
>> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
>> index 4743bb1..00f4361 100644
>> --- a/libavcodec/allcodecs.c
>> +++ b/libavcodec/allcodecs.c
>> @@ -137,6 +137,7 @@ void avcodec_register_all(void)
>> REGISTER_ENCDEC (H263P, h263p);
>> REGISTER_DECODER (H264, h264);
>> REGISTER_DECODER (H264_CRYSTALHD, h264_crystalhd);
>> + REGISTER_DECODER (H264_DXVA2, h264_dxva2);
>> REGISTER_DECODER (H264_VDA, h264_vda);
>> REGISTER_DECODER (H264_VDPAU, h264_vdpau);
>> REGISTER_ENCDEC (HUFFYUV, huffyuv);
>> diff --git a/libavcodec/dxva2_h264_dec.c b/libavcodec/dxva2_h264_dec.c
>> new file mode 100644
>> index 0000000..79ee496
>> --- /dev/null
>> +++ b/libavcodec/dxva2_h264_dec.c
>> @@ -0,0 +1,228 @@
>> +/*
>> + * Call hardware decode acceleration through dxva2 API for h264
>> +
>> + * Copyright (c) 2012 Wei Gao <weigao at multicorewareinc.com>
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg 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.
>> + *
>> + * FFmpeg 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 FFmpeg; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
>> 02110-1301 USA
>> + */
>> +
>> +#include <string.h>
>> +#include "dxva2_wrapper.h"
>> +#include "h264.h"
>> +#include "avcodec.h"
>> +
>> +extern AVCodec ff_h264_decoder, ff_h264_dxva2_decoder;
>
> Hmm, is this really needed?
>
>> +
>> +static const enum AVPixelFormat dxva2_h264_pixfmts[] = {
>> + AV_PIX_FMT_YUV420P,
>> + AV_PIX_FMT_NONE
>> +};
>> +
>> +typedef struct {
>> + H264Context h264ctx;
>> + int h264_initialized;
>> + enum AVPixelFormat pix_fmt;
>> + uint8_t *databuffer;
>> + dxva2_context dxva2_ctx;
>
> vertical alignment is missing.
>
>> +} DXVA2_h264DecoderContext;
>> +
>> +static int get_buffer( struct AVCodecContext *avctx,
>> + AVFrame *pic )
>
> Weird formatting, next line is not needed and there are extra
> whitespaces after ( and before )
>
>> +{
>
> { Should not be on separate line.
Obviously ignore this one. But look and compare with some other files in tree
to fix obvious issues.
>
>> + DXVA2_h264DecoderContext *ctx = (DXVA2_h264DecoderContext
>> *)avctx->priv_data;
>> + dxva2_context *dxva2_ctx = &ctx->dxva2_ctx;
>> + pic->type = FF_BUFFER_TYPE_USER;
>> + pic->data[0] = (void *)1;
>> + if(dxva2_ctx) {
>
> Missing whitespace between if and (
>
>> + if( av_get_dxva2_surface( dxva2_ctx, pic) ) {
>
> again whitespace issue
>
>
> and so on ...
>
More information about the ffmpeg-devel
mailing list