Ticket #1009: ffmpeg-1.0.4-xvba_support.patch

File ffmpeg-1.0.4-xvba_support.patch, 33.4 KB (added by ryszardzonk, 13 years ago)

ffmpeg-1.0.4-xvba_support.patch

  • ffmpeg-1.0.4

    diff -Naur ffmpeg-1.0.4.old/configure ffmpeg-1.0.4/configure
    old new  
    132132  --disable-fft            disable FFT code
    133133  --enable-dxva2           enable DXVA2 code
    134134  --enable-vaapi           enable VAAPI code [autodetect]
     135  --enable-xvba            enable XVBA code  [autodetect]
    135136  --enable-vda             enable VDA code   [autodetect]
    136137  --enable-vdpau           enable VDPAU code [autodetect]
    137138
     
    11721173    swscale_alpha
    11731174    thumb
    11741175    vaapi
     1176    xvba
    11751177    vda
    11761178    vdpau
    11771179    version3
     
    16161618h264_dxva2_hwaccel_deps="dxva2api_h"
    16171619h264_dxva2_hwaccel_select="dxva2 h264_decoder"
    16181620h264_vaapi_hwaccel_select="vaapi h264_decoder"
     1621h264_xvba_hwaccel_select="xvba h264_decoder"
    16191622h264_vda_decoder_select="vda h264_parser h264_decoder"
    16201623h264_vda_hwaccel_deps="VideoDecodeAcceleration_VDADecoder_h pthreads"
    16211624h264_vda_hwaccel_select="vda h264_decoder"
     
    16541657mpeg2_dxva2_hwaccel_select="dxva2 mpeg2video_decoder"
    16551658mpeg2_vdpau_hwaccel_select="vdpau mpeg2video_decoder"
    16561659mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder"
     1660mpeg2_xvba_hwaccel_select="xvba mpeg2video_decoder"
    16571661mpeg2video_decoder_select="error_resilience mpegvideo"
    16581662mpeg2video_encoder_select="aandcttables error_resilience mpegvideoenc"
    16591663mpeg4_crystalhd_decoder_select="crystalhd"
     
    17061710vc1_dxva2_hwaccel_deps="dxva2api_h"
    17071711vc1_dxva2_hwaccel_select="dxva2 vc1_decoder"
    17081712vc1_vaapi_hwaccel_select="vaapi vc1_decoder"
     1713vc1_xvba_hwaccel_select="xvba vc1_decoder"
    17091714vc1_vdpau_decoder_select="vdpau vc1_decoder"
    17101715vc1image_decoder_select="vc1_decoder"
    17111716vorbis_decoder_select="mdct"
     
    17301735wmv3_crystalhd_decoder_select="crystalhd"
    17311736wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
    17321737wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
     1738wmv3_xvba_hwaccel_select="vc1_xvba_hwaccel"
    17331739wmv3_vdpau_decoder_select="vc1_vdpau_decoder"
    17341740wmv3image_decoder_select="wmv3_decoder"
    17351741zerocodec_decoder_select="zlib"
     
    17401746
    17411747crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
    17421748vaapi_deps="va_va_h"
     1749xvba_deps="amdxvba_h"
    17431750vda_deps="VideoDecodeAcceleration_VDADecoder_h pthreads"
    17441751vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
    17451752
     
    35583565check_header unistd.h
    35593566check_header vdpau/vdpau.h
    35603567check_header vdpau/vdpau_x11.h
     3568check_header amd/amdxvba.h
    35613569check_header windows.h
    35623570check_header X11/extensions/XvMClib.h
    35633571check_header asm/types.h
     
    36113619check_lib math.h sin -lm && LIBM="-lm"
    36123620disabled crystalhd || check_lib libcrystalhd/libcrystalhd_if.h DtsCrystalHDVersion -lcrystalhd || disable crystalhd
    36133621enabled vaapi && require vaapi va/va.h vaInitialize -lva
     3622#enabled xvba && require xvba amd/amdxvba.h
    36143623
    36153624check_mathfunc cbrtf
    36163625check_mathfunc exp2
     
    40264035echo "SDL support               ${sdl-no}"
    40274036echo "libdxva2 enabled          ${dxva2-no}"
    40284037echo "libva enabled             ${vaapi-no}"
     4038echo "xvba enabled              ${xvba-no}"
    40294039echo "libvdpau enabled          ${vdpau-no}"
    40304040echo "AVISynth enabled          ${avisynth-no}"
    40314041echo "frei0r enabled            ${frei0r-no}"
  • libavcodec/allcodecs.c

    diff -Naur ffmpeg-1.0.4.old/libavcodec/allcodecs.c ffmpeg-1.0.4/libavcodec/allcodecs.c
    old new  
    5858    REGISTER_HWACCEL (H263_VAAPI, h263_vaapi);
    5959    REGISTER_HWACCEL (H264_DXVA2, h264_dxva2);
    6060    REGISTER_HWACCEL (H264_VAAPI, h264_vaapi);
     61    REGISTER_HWACCEL (H264_XVBA, h264_xvba);
    6162    REGISTER_HWACCEL (H264_VDA, h264_vda);
    6263    REGISTER_HWACCEL (MPEG1_VDPAU, mpeg1_vdpau);
    6364    REGISTER_HWACCEL (MPEG2_DXVA2, mpeg2_dxva2);
    6465    REGISTER_HWACCEL (MPEG2_VAAPI, mpeg2_vaapi);
     66    REGISTER_HWACCEL (MPEG2_XVBA, mpeg2_xvba);
    6567    REGISTER_HWACCEL (MPEG2_VDPAU, mpeg2_vdpau);
    6668    REGISTER_HWACCEL (MPEG4_VAAPI, mpeg4_vaapi);
    6769    REGISTER_HWACCEL (VC1_DXVA2, vc1_dxva2);
    6870    REGISTER_HWACCEL (VC1_VAAPI, vc1_vaapi);
     71    REGISTER_HWACCEL (VC1_XVBA, vc1_xvba);
    6972    REGISTER_HWACCEL (WMV3_DXVA2, wmv3_dxva2);
    7073    REGISTER_HWACCEL (WMV3_VAAPI, wmv3_vaapi);
     74    REGISTER_HWACCEL (WMV3_XVBA, wmv3_xvba);
    7175
    7276    /* video codecs */
    7377    REGISTER_ENCODER (A64MULTI, a64multi);
  • libavcodec/h264.c

    diff -Naur ffmpeg-1.0.4.old/libavcodec/h264.c ffmpeg-1.0.4/libavcodec/h264.c
    old new  
    6969static const enum PixelFormat hwaccel_pixfmt_list_h264_jpeg_420[] = {
    7070    PIX_FMT_DXVA2_VLD,
    7171    PIX_FMT_VAAPI_VLD,
     72    PIX_FMT_XVBA_VLD,
    7273    PIX_FMT_VDA_VLD,
    7374    PIX_FMT_YUVJ420P,
    7475    PIX_FMT_NONE
  • libavcodec/Makefile

    diff -Naur ffmpeg-1.0.4.old/libavcodec/Makefile ffmpeg-1.0.4/libavcodec/Makefile
    old new  
    1212          vdpau.h                                                       \
    1313          version.h                                                     \
    1414          xvmc.h                                                        \
     15          xvba.h                                                        \
    1516
    1617OBJS = allcodecs.o                                                      \
    1718       audioconvert.o                                                   \
     
    6667OBJS-$(CONFIG_SINEWIN)                 += sinewin.o
    6768OBJS-$(CONFIG_VAAPI)                   += vaapi.o
    6869OBJS-$(CONFIG_VDPAU)                   += vdpau.o
     70OBJS-$(CONFIG_XVBA)                    += xvba.o
    6971OBJS-$(CONFIG_VP3DSP)                  += vp3dsp.o
    7072
    7173# decoders/encoders/hardware accelerators
     
    216218                                          h264_refs.o h264_cavlc.o h264_cabac.o
    217219OBJS-$(CONFIG_H264_DXVA2_HWACCEL)      += dxva2_h264.o
    218220OBJS-$(CONFIG_H264_VAAPI_HWACCEL)      += vaapi_h264.o
     221OBJS-$(CONFIG_H264_XVBA_HWACCEL)       += xvba_h264.o
    219222OBJS-$(CONFIG_H264_VDA_HWACCEL)        += vda_h264.o
    220223OBJS-$(CONFIG_H264_VDA_DECODER)        += vda_h264_dec.o
    221224OBJS-$(CONFIG_HUFFYUV_DECODER)         += huffyuv.o
     
    291294                                          timecode.o
    292295OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)     += dxva2_mpeg2.o
    293296OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)     += vaapi_mpeg2.o
     297OBJS-$(CONFIG_MPEG2_XVBA_HWACCEL)      += xvba_mpeg2.o
    294298OBJS-$(CONFIG_MPEG2VIDEO_DECODER)      += mpeg12.o mpeg12data.o
    295299OBJS-$(CONFIG_MPEG2VIDEO_ENCODER)      += mpeg12enc.o mpeg12.o          \
    296300                                          timecode.o
     
    446450                                          intrax8.o intrax8dsp.o
    447451OBJS-$(CONFIG_VC1_DXVA2_HWACCEL)       += dxva2_vc1.o
    448452OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)       += vaapi_vc1.o
     453OBJS-$(CONFIG_VC1_XVBA_HWACCEL)        += xvba_vc1.o
    449454OBJS-$(CONFIG_VCR1_DECODER)            += vcr1.o
    450455OBJS-$(CONFIG_VCR1_ENCODER)            += vcr1.o
    451456OBJS-$(CONFIG_VMDAUDIO_DECODER)        += vmdav.o
     
    767772SKIPHEADERS-$(CONFIG_LIBUTVIDEO)       += libutvideo.h
    768773SKIPHEADERS-$(CONFIG_MPEG_XVMC_DECODER) += xvmc.h
    769774SKIPHEADERS-$(CONFIG_VAAPI)            += vaapi_internal.h
     775SKIPHEADERS-$(CONFIG_XVBA)             += xvba_internal.h
    770776SKIPHEADERS-$(CONFIG_VDA)              += vda.h
    771777SKIPHEADERS-$(CONFIG_VDPAU)            += vdpau.h
    772778SKIPHEADERS-$(HAVE_OS2THREADS)         += os2threads.h
  • libavcodec/mpegvideo.c

    diff -Naur ffmpeg-1.0.4.old/libavcodec/mpegvideo.c ffmpeg-1.0.4/libavcodec/mpegvideo.c
    old new  
    133133const enum PixelFormat ff_hwaccel_pixfmt_list_420[] = {
    134134    PIX_FMT_DXVA2_VLD,
    135135    PIX_FMT_VAAPI_VLD,
     136    PIX_FMT_XVBA_VLD,
    136137    PIX_FMT_VDA_VLD,
    137138    PIX_FMT_YUV420P,
    138139    PIX_FMT_NONE
  • libavcodec/xvba.c

    diff -Naur ffmpeg-1.0.4.old/libavcodec/xvba.c ffmpeg-1.0.4/libavcodec/xvba.c
    old new  
     1/*
     2 * HW decode acceleration for MPEG-2, H.264 and VC-1
     3 *
     4 * Copyright (C) 2005-2011 Team XBMC
     5 *
     6 * This file is part of FFmpeg.
     7 *
     8 * FFmpeg is free software; you can redistribute it and/or
     9 * modify it under the terms of the GNU Lesser General Public
     10 * License as published by the Free Software Foundation; either
     11 * version 2.1 of the License, or (at your option) any later version.
     12 *
     13 * FFmpeg is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16 * Lesser General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU Lesser General Public
     19 * License along with FFmpeg; if not, write to the Free Software
     20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     21 */
     22
     23
     24/**
     25 * \addtogroup XVBA_Decoding
     26 *
     27 * @{
     28 */
     29
     30#include <stdint.h>
     31#include "xvba.h"
     32#include "xvba_internal.h"
     33#include "avcodec.h"
     34
     35int ff_xvba_translate_profile(int profile) {
     36
     37  if (profile == 66)
     38    return 1;
     39  else if (profile == 77)
     40    return 2;
     41  else if (profile == 100)
     42    return 3;
     43  else if (profile == 0)
     44    return 4;
     45  else if (profile == 1)
     46    return 5;
     47  else if (profile == 3)
     48    return 6;
     49  else
     50    return -1;
     51}
     52
     53void ff_xvba_add_slice_data(struct xvba_render_state *render, const uint8_t *buffer, uint32_t size) {
     54
     55  render->buffers = av_fast_realloc(
     56         render->buffers,
     57         &render->buffers_alllocated,
     58         sizeof(struct xvba_bitstream_buffers)*(render->num_slices + 1)
     59  );
     60
     61  render->buffers[render->num_slices].buffer = buffer;
     62  render->buffers[render->num_slices].size = size;
     63
     64  render->num_slices++;
     65}
     66
  • libavcodec/xvba.h

    diff -Naur ffmpeg-1.0.4.old/libavcodec/xvba.h ffmpeg-1.0.4/libavcodec/xvba.h
    old new  
     1/*
     2 * HW decode acceleration for MPEG-2, H.264 and VC-1
     3 *
     4 * Copyright (C) 2005-2011 Team XBMC
     5 *
     6 * This file is part of FFmpeg.
     7 *
     8 * FFmpeg is free software; you can redistribute it and/or
     9 * modify it under the terms of the GNU Lesser General Public
     10 * License as published by the Free Software Foundation; either
     11 * version 2.1 of the License, or (at your option) any later version.
     12 *
     13 * FFmpeg is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16 * Lesser General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU Lesser General Public
     19 * License along with FFmpeg; if not, write to the Free Software
     20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     21 */
     22
     23#ifndef AVCODEC_XVBA_H
     24#define AVCODEC_XVBA_H
     25
     26#include <stdint.h>
     27#include <X11/Xlib.h>
     28#include <amd/amdxvba.h>
     29
     30
     31/**
     32 * \defgroup XVBA_Decoding VA API Decoding
     33 * \ingroup Decoder
     34 * @{
     35 */
     36
     37/** \brief The videoSurface is used for rendering. */
     38#define FF_XVBA_STATE_USED_FOR_RENDER 1
     39
     40/**
     41 * \brief The videoSurface is needed for reference/prediction.
     42 * The codec manipulates this.
     43 */
     44#define FF_XVBA_STATE_USED_FOR_REFERENCE 2
     45
     46/**
     47 * \brief The videoSurface holds a decoded frame.
     48 * The codec manipulates this.
     49 */
     50#define FF_XVBA_STATE_DECODED 4
     51
     52/* @} */
     53
     54struct xvba_bitstream_buffers
     55{
     56  const void *buffer;
     57  unsigned int size;
     58};
     59
     60struct xvba_render_state {
     61
     62  int state; ///< Holds FF_XVBA_STATE_* values.
     63  void *surface;
     64  XVBAPictureDescriptor *picture_descriptor;
     65  XVBAQuantMatrixAvc *iq_matrix;
     66  unsigned int num_slices;
     67  struct xvba_bitstream_buffers *buffers;
     68  uint32_t buffers_alllocated;
     69};
     70
     71#endif /* AVCODEC_XVBA_H */
  • libavcodec/xvba_h264.c

    diff -Naur ffmpeg-1.0.4.old/libavcodec/xvba_h264.c ffmpeg-1.0.4/libavcodec/xvba_h264.c
    old new  
     1/*
     2 * H.264 HW decode acceleration through XVBA
     3 *
     4 * Copyright (C) 2005-2011 Team XBMC
     5 *
     6 * This file is part of FFmpeg.
     7 *
     8 * FFmpeg is free software; you can redistribute it and/or
     9 * modify it under the terms of the GNU Lesser General Public
     10 * License as published by the Free Software Foundation; either
     11 * version 2.1 of the License, or (at your option) any later version.
     12 *
     13 * FFmpeg is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16 * Lesser General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU Lesser General Public
     19 * License along with FFmpeg; if not, write to the Free Software
     20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     21 */
     22
     23#include "xvba.h"
     24#include "xvba_internal.h"
     25#include "h264.h"
     26#include <assert.h>
     27
     28/** @file
     29 *  This file implements the glue code between FFmpeg's and XvBA API's
     30 *  structures for H.264 decoding.
     31 */
     32
     33
     34/** Initialize and start decoding a frame with XVBA. */
     35static int start_frame(AVCodecContext          *avctx,
     36                       av_unused const uint8_t *buffer,
     37                       av_unused uint32_t       size)
     38{
     39  H264Context * const h = avctx->priv_data;
     40  MpegEncContext * const s = &h->s;
     41  struct xvba_render_state *render;
     42  XVBAPictureDescriptor *pic_descriptor;
     43  int i;
     44
     45  render = (struct xvba_render_state *)s->current_picture_ptr->f.data[0];
     46  assert(render);
     47
     48  if (render->picture_descriptor == 0)
     49    return -1;
     50
     51  pic_descriptor = render->picture_descriptor;
     52
     53  for (i = 0; i < 2; ++i) {
     54      int foc = s->current_picture_ptr->field_poc[i];
     55      if (foc == INT_MAX)
     56          foc = 0;
     57      pic_descriptor->avc_curr_field_order_cnt_list[i] = foc;
     58  }
     59
     60  pic_descriptor->avc_frame_num = h->frame_num;
     61
     62  render->num_slices = 0;
     63
     64  return 0;
     65}
     66
     67/** End a hardware decoding based frame. */
     68static int end_frame(AVCodecContext *avctx)
     69{
     70  H264Context * const h = avctx->priv_data;
     71  MpegEncContext * const s = &h->s;
     72  struct xvba_render_state *render;
     73  XVBAPictureDescriptor *pic_descriptor;
     74  XVBAQuantMatrixAvc *iq_matrix;
     75
     76  render = (struct xvba_render_state *)s->current_picture_ptr->f.data[0];
     77  assert(render);
     78
     79  if (render->picture_descriptor == 0 || render->iq_matrix == 0)
     80    return -1;
     81
     82  pic_descriptor = render->picture_descriptor;
     83  iq_matrix = render->iq_matrix;
     84
     85  av_dlog(avctx, "end_frame()\n");
     86
     87  /* Fill in Picture Parameters*/
     88  pic_descriptor->profile                                     = ff_xvba_translate_profile(avctx->profile);
     89  pic_descriptor->level                                       = avctx->level;
     90  pic_descriptor->width_in_mb                                 = s->mb_width;
     91  pic_descriptor->height_in_mb                                = s->mb_height;
     92  pic_descriptor->picture_structure                           = s->picture_structure;
     93  pic_descriptor->chroma_format                               = s->chroma_format ? s->chroma_format : 1;
     94  pic_descriptor->avc_intra_flag                              = (h->slice_type == AV_PICTURE_TYPE_I) ? 1 : 0;
     95  pic_descriptor->avc_reference                               = (s->current_picture_ptr->f.reference & 3) ? 1 : 0;
     96
     97  pic_descriptor->avc_bit_depth_luma_minus8                   = h->sps.bit_depth_luma - 8;
     98  pic_descriptor->avc_bit_depth_chroma_minus8                 = h->sps.bit_depth_chroma - 8;
     99  pic_descriptor->avc_log2_max_frame_num_minus4               = h->sps.log2_max_frame_num -4;
     100  pic_descriptor->avc_pic_order_cnt_type                      = h->sps.poc_type;
     101  pic_descriptor->avc_log2_max_pic_order_cnt_lsb_minus4       = h->sps.log2_max_poc_lsb - 4;
     102  pic_descriptor->avc_num_ref_frames                          = h->sps.ref_frame_count;
     103  pic_descriptor->avc_reserved_8bit                           = 0;
     104
     105  /* Set a level that can decode stuff in every case without a lookup table
     106     xvba seems to have problems only when the number of Reframes goes beyond
     107     the max support number of Level4.1@High. So in praxis decoding a Level 3.0
     108     file that in deed has level4.1@High specs does not matter. We use this fact
     109     and check if the ref_frames stay in the range Level4.1@high can decode if
     110     not, we set Level5.1 */
     111  if (pic_descriptor->avc_num_ref_frames > 4) {
     112    const unsigned int mbw = pic_descriptor->width_in_mb;
     113    const unsigned int mbh = pic_descriptor->height_in_mb;
     114    // this matches Level4.1@High stats to differ between <= 4.1 and 5.1
     115    const unsigned int max_ref_frames = 12288 * 1024 / (mbw * mbh * 384);
     116    const unsigned int num_ref_frames = pic_descriptor->avc_num_ref_frames;
     117    if (max_ref_frames < num_ref_frames)
     118        pic_descriptor->level = 51;
     119  }
     120
     121  pic_descriptor->avc_num_slice_groups_minus1                 = h->pps.slice_group_count - 1;
     122  pic_descriptor->avc_num_ref_idx_l0_active_minus1            = h->pps.ref_count[0] - 1;
     123  pic_descriptor->avc_num_ref_idx_l1_active_minus1            = h->pps.ref_count[1] - 1;
     124
     125  pic_descriptor->avc_pic_init_qp_minus26                     = h->pps.init_qp - 26;
     126  pic_descriptor->avc_pic_init_qs_minus26                     = h->pps.init_qs - 26;
     127  pic_descriptor->avc_chroma_qp_index_offset                  = h->pps.chroma_qp_index_offset[0];
     128  pic_descriptor->avc_second_chroma_qp_index_offset           = h->pps.chroma_qp_index_offset[1];
     129  pic_descriptor->avc_slice_group_change_rate_minus1          = 0; // not implemented in ffmpeg
     130  pic_descriptor->avc_reserved_16bit                          = 0; // must be 0
     131  memset(pic_descriptor->avc_field_order_cnt_list,0,sizeof(pic_descriptor->avc_field_order_cnt_list)); // must be 0
     132  memset(pic_descriptor->avc_slice_group_map,0,sizeof(pic_descriptor->avc_slice_group_map)); // must be 0
     133
     134  // sps
     135  pic_descriptor->sps_info.avc.delta_pic_always_zero_flag     = h->sps.delta_pic_order_always_zero_flag;
     136  pic_descriptor->sps_info.avc.direct_8x8_inference_flag      = h->sps.direct_8x8_inference_flag;
     137  pic_descriptor->sps_info.avc.frame_mbs_only_flag            = h->sps.frame_mbs_only_flag;
     138  pic_descriptor->sps_info.avc.gaps_in_frame_num_value_allowed_flag = h->sps.gaps_in_frame_num_allowed_flag;
     139  pic_descriptor->sps_info.avc.mb_adaptive_frame_field_flag   = h->sps.mb_aff;
     140  pic_descriptor->sps_info.avc.residual_colour_transform_flag = h->sps.residual_color_transform_flag;
     141  pic_descriptor->sps_info.avc.xvba_avc_sps_reserved          = 0;
     142
     143  // pps
     144  pic_descriptor->pps_info.avc.entropy_coding_mode_flag       = h->pps.cabac;
     145  pic_descriptor->pps_info.avc.pic_order_present_flag         = h->pps.pic_order_present;
     146  pic_descriptor->pps_info.avc.weighted_pred_flag             = h->pps.weighted_pred;
     147  pic_descriptor->pps_info.avc.weighted_bipred_idc            = h->pps.weighted_bipred_idc;
     148  pic_descriptor->pps_info.avc.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present;
     149  pic_descriptor->pps_info.avc.constrained_intra_pred_flag    = h->pps.constrained_intra_pred;
     150  pic_descriptor->pps_info.avc.redundant_pic_cnt_present_flag = h->pps.redundant_pic_cnt_present;
     151  pic_descriptor->pps_info.avc.transform_8x8_mode_flag        = h->pps.transform_8x8_mode;
     152  pic_descriptor->pps_info.avc.xvba_avc_pps_reserved          = 0; // must be 0
     153
     154  memcpy(iq_matrix->bScalingLists4x4, h->pps.scaling_matrix4, sizeof(iq_matrix->bScalingLists4x4));
     155  memcpy(iq_matrix->bScalingLists8x8[0], h->pps.scaling_matrix8[0], sizeof(iq_matrix->bScalingLists8x8[0]));
     156  memcpy(iq_matrix->bScalingLists8x8[1], h->pps.scaling_matrix8[3], sizeof(iq_matrix->bScalingLists8x8[0]));
     157
     158  // Wait for an I-frame before start decoding. Workaround for ATI UVD and UVD+ GPUs
     159  if (!h->got_first_iframe) {
     160      if (h->slice_type != AV_PICTURE_TYPE_I && h->slice_type != AV_PICTURE_TYPE_SI)
     161          return -1;
     162      h->got_first_iframe = 1;
     163  }
     164
     165  ff_draw_horiz_band(s, 0, s->avctx->height);
     166
     167  return 0;
     168}
     169
     170/** Decode the given H.264 slice with XVBA. */
     171static int decode_slice(AVCodecContext *avctx,
     172                        const uint8_t  *buffer,
     173                        uint32_t        size)
     174{
     175  H264Context * const h = avctx->priv_data;
     176  MpegEncContext * const s = &h->s;
     177  struct xvba_render_state *render;
     178
     179  render = (struct xvba_render_state *)s->current_picture_ptr->f.data[0];
     180  assert(render);
     181
     182  ff_xvba_add_slice_data(render, buffer, size);
     183
     184  return 0;
     185}
     186
     187AVHWAccel ff_h264_xvba_hwaccel = {
     188    .name           = "h264_xvba",
     189    .type           = AVMEDIA_TYPE_VIDEO,
     190    .id             = CODEC_ID_H264,
     191    .pix_fmt        = PIX_FMT_XVBA_VLD,
     192    .start_frame    = start_frame,
     193    .end_frame      = end_frame,
     194    .decode_slice   = decode_slice,
     195};
  • libavcodec/xvba_internal.h

    diff -Naur ffmpeg-1.0.4.old/libavcodec/xvba_internal.h ffmpeg-1.0.4/libavcodec/xvba_internal.h
    old new  
     1/*
     2 * HW decode acceleration for MPEG-2, H.264 and VC-1
     3 *
     4 * Copyright (C) 2005-2011 Team XBMC
     5 *
     6 * This file is part of FFmpeg.
     7 *
     8 * FFmpeg is free software; you can redistribute it and/or
     9 * modify it under the terms of the GNU Lesser General Public
     10 * License as published by the Free Software Foundation; either
     11 * version 2.1 of the License, or (at your option) any later version.
     12 *
     13 * FFmpeg is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16 * Lesser General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU Lesser General Public
     19 * License along with FFmpeg; if not, write to the Free Software
     20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     21 */
     22
     23int ff_xvba_translate_profile(int profile);
     24void ff_xvba_add_slice_data(struct xvba_render_state *render, const uint8_t *buffer, uint32_t size);
  • libavcodec/xvba_mpeg2.c

    diff -Naur ffmpeg-1.0.4.old/libavcodec/xvba_mpeg2.c ffmpeg-1.0.4/libavcodec/xvba_mpeg2.c
    old new  
     1/*
     2 * MPEG-2 HW decode acceleration through XVBA
     3 *
     4 * Copyright (C) 2005-2011 Team XBMC
     5 *
     6 * This file is part of FFmpeg.
     7 *
     8 * FFmpeg is free software; you can redistribute it and/or
     9 * modify it under the terms of the GNU Lesser General Public
     10 * License as published by the Free Software Foundation; either
     11 * version 2.1 of the License, or (at your option) any later version.
     12 *
     13 * FFmpeg is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16 * Lesser General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU Lesser General Public
     19 * License along with FFmpeg; if not, write to the Free Software
     20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     21 */
     22
     23#include "dsputil.h"
     24
     25static int start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
     26{
     27    struct MpegEncContext * const s = avctx->priv_data;
     28    return 0;
     29}
     30
     31static int end_frame(AVCodecContext *avctx)
     32{
     33    return 0;
     34}
     35
     36static int decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
     37{
     38    struct MpegEncContext * const s = avctx->priv_data;
     39    return 0;
     40}
     41
     42AVHWAccel ff_mpeg2_xvba_hwaccel = {
     43    .name           = "mpeg2_xvba",
     44    .type           = AVMEDIA_TYPE_VIDEO,
     45    .id             = CODEC_ID_MPEG2VIDEO,
     46    .pix_fmt        = PIX_FMT_XVBA_VLD,
     47    .capabilities   = 0,
     48    .start_frame    = start_frame,
     49    .end_frame      = end_frame,
     50    .decode_slice   = decode_slice,
     51    .priv_data_size = 0,
     52};
  • libavcodec/xvba_vc1.c

    diff -Naur ffmpeg-1.0.4.old/libavcodec/xvba_vc1.c ffmpeg-1.0.4/libavcodec/xvba_vc1.c
    old new  
     1/*
     2 * VC-1 HW decode acceleration through XVBA
     3 *
     4 * Copyright (C) 2005-2011 Team XBMC
     5 *
     6 * This file is part of FFmpeg.
     7 *
     8 * FFmpeg is free software; you can redistribute it and/or
     9 * modify it under the terms of the GNU Lesser General Public
     10 * License as published by the Free Software Foundation; either
     11 * version 2.1 of the License, or (at your option) any later version.
     12 *
     13 * FFmpeg is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16 * Lesser General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU Lesser General Public
     19 * License along with FFmpeg; if not, write to the Free Software
     20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     21 */
     22
     23#include "xvba.h"
     24#include "xvba_internal.h"
     25#include "vc1.h"
     26#include "vc1data.h"
     27#include <assert.h>
     28
     29
     30/** @file
     31 * Implement structures of ffmpeg <-> XvBA
     32 */
     33
     34/* Initialize and start decoding a frame with XvBA */
     35static int start_frame(AVCodecContext *avctx,
     36                                av_unused const uint8_t *buffer,
     37                                av_unused uint32_t size)
     38{
     39    VC1Context * const v = avctx->priv_data;
     40    MpegEncContext * const s = &v->s;
     41    struct xvba_render_state *render;
     42
     43    render = (struct xvba_render_state *)s->current_picture_ptr->f.data[0];
     44    assert(render);
     45   
     46    render->num_slices = 0;
     47    return 0;
     48}
     49
     50/* End a hardware decoding based frame */
     51static int end_frame(AVCodecContext *avctx)
     52{
     53    VC1Context* const v = avctx->priv_data;
     54    MpegEncContext* const s = &v->s;
     55    struct xvba_render_state *render, *last, *next;
     56    XVBAPictureDescriptor *pic_descriptor;
     57
     58    render = (struct xvba_render_state *)s->current_picture_ptr->f.data[0];
     59    assert(render);
     60
     61    if (render->picture_descriptor == 0)
     62      return -1;
     63
     64    pic_descriptor = render->picture_descriptor;
     65   
     66    av_dlog(avctx, "xvba_vc1_end_frame()\n");
     67   
     68    memset(pic_descriptor, 0, sizeof(*pic_descriptor));
     69
     70    /* Fill in Parameters - for reference see AMD sdk documentation */
     71    pic_descriptor->profile                                 = ff_xvba_translate_profile(v->profile);
     72    pic_descriptor->level                                   = v->level;
     73    //done like in va-driver and vaapi
     74    if (v->profile == PROFILE_ADVANCED) {
     75      pic_descriptor->width_in_mb                           = s->avctx->coded_width;
     76      pic_descriptor->height_in_mb                          = s->avctx->coded_height;
     77    } else {
     78      pic_descriptor->width_in_mb                           = s->mb_width;
     79      pic_descriptor->height_in_mb                          = s->mb_height;
     80    }
     81    pic_descriptor->picture_structure                       = s->picture_structure;
     82    // xvba-video set this to 1 only 4:2:0 supported
     83    // doc says: if not set, choose 1 - we try this
     84    pic_descriptor->chroma_format                           = 1;
     85    pic_descriptor->avc_intra_flag                          = s->pict_type == AV_PICTURE_TYPE_I || v->bi_type == 1;
     86    pic_descriptor->avc_reference                           = (s->current_picture_ptr->f.reference & 3) ? 1 : 0;
     87   
     88    // VC-1 explicit parameters see page 30 of sdk
     89    // sps_info
     90    pic_descriptor->sps_info.vc1.postprocflag               = v->postprocflag;
     91   
     92    // done as in vaapi
     93    pic_descriptor->sps_info.vc1.pulldown                   = v->broadcast;
     94    pic_descriptor->sps_info.vc1.interlace                  = v->interlace;
     95    pic_descriptor->sps_info.vc1.tfcntrflag                 = v->tfcntrflag;
     96    pic_descriptor->sps_info.vc1.finterpflag                = v->finterpflag;
     97    pic_descriptor->sps_info.vc1.reserved                   = 1;
     98    // eventually check if this makes sense together with interlace
     99    pic_descriptor->sps_info.vc1.psf                        = v->psf;
     100    // what about if it is a frame (page 31)
     101    // looked at xvba-driver
     102    pic_descriptor->sps_info.vc1.second_field               = !s->first_field;
     103    pic_descriptor->sps_info.vc1.xvba_vc1_sps_reserved      = 0;
     104   
     105    // VC-1 explicit parameters see page 30 of sdk
     106    // pps_info
     107    pic_descriptor->pps_info.vc1.panscan_flag               = v->panscanflag;
     108    pic_descriptor->pps_info.vc1.refdist_flag               = v->refdist_flag;
     109    pic_descriptor->pps_info.vc1.loopfilter                 = s->loop_filter;
     110    pic_descriptor->pps_info.vc1.fastuvmc                   = v->fastuvmc;
     111    pic_descriptor->pps_info.vc1.extended_mv                = v->extended_mv;
     112    pic_descriptor->pps_info.vc1.dquant                     = v->dquant;
     113    pic_descriptor->pps_info.vc1.vstransform                = v->vstransform;
     114    pic_descriptor->pps_info.vc1.overlap                    = v->overlap;
     115    pic_descriptor->pps_info.vc1.quantizer                  = v->quantizer_mode;
     116    pic_descriptor->pps_info.vc1.extended_dmv               = v->extended_dmv;   
     117    pic_descriptor->pps_info.vc1.maxbframes                 = s->avctx->max_b_frames;
     118    pic_descriptor->pps_info.vc1.rangered                   = (pic_descriptor->profile == PROFILE_SIMPLE) ? 0 : v->rangered;   
     119    pic_descriptor->pps_info.vc1.syncmarker                 = (pic_descriptor->profile == PROFILE_SIMPLE) ? 0 : s->resync_marker;
     120    pic_descriptor->pps_info.vc1.multires                   = v->multires;
     121    pic_descriptor->pps_info.vc1.reserved                   = 1;
     122    pic_descriptor->pps_info.vc1.range_mapy_flag            = v->range_mapy_flag;
     123    pic_descriptor->pps_info.vc1.range_mapy                 = v->range_mapy;
     124    pic_descriptor->pps_info.vc1.range_mapuv_flag           = v->range_mapuv_flag;
     125    pic_descriptor->pps_info.vc1.range_mapuv                = v->range_mapuv;
     126    pic_descriptor->pps_info.vc1.xvba_vc1_pps_reserved      = 0;
     127   
     128    pic_descriptor->past_surface                            = 0;
     129    pic_descriptor->future_surface                          = 0;
     130    switch (s->pict_type) {
     131    case AV_PICTURE_TYPE_B:
     132        next = (struct xvba_render_state *)s->next_picture.f.data[0];
     133        assert(next);
     134        if (next)
     135          pic_descriptor->past_surface = next->surface;
     136        // fall-through
     137    case AV_PICTURE_TYPE_P:
     138        last = (struct xvba_render_state *)s->last_picture.f.data[0];
     139        assert(last);
     140        if (last)
     141          pic_descriptor->future_surface = last->surface;
     142        break;
     143    }
     144
     145    ff_draw_horiz_band(s, 0, s->avctx->height);
     146
     147    return 0;
     148}
     149
     150static int decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
     151{
     152  VC1Context* const v = avctx->priv_data;
     153  MpegEncContext* const s = &v->s;
     154  struct xvba_render_state *render;
     155
     156  render = (struct xvba_render_state *)s->current_picture_ptr->f.data[0];
     157  assert(render);
     158
     159  if (avctx->codec_id == CODEC_ID_VC1 &&
     160      size >= 4 && IS_MARKER(AV_RB32(buffer))) {
     161      buffer += 4;
     162      size   -= 4;
     163  }
     164
     165  ff_xvba_add_slice_data(render, buffer, size);
     166
     167  return 0;
     168}
     169
     170#if CONFIG_WMV3_XVBA_HWACCEL
     171AVHWAccel ff_wmv3_xvba_hwaccel = {
     172    .name           = "wmv3_xvba",
     173    .type           = AVMEDIA_TYPE_VIDEO,
     174    .id             = CODEC_ID_WMV3,
     175    .pix_fmt        = PIX_FMT_XVBA_VLD,
     176    .start_frame    = start_frame,
     177    .end_frame      = end_frame,
     178    .decode_slice   = decode_slice,
     179};
     180#endif
     181
     182AVHWAccel ff_vc1_xvba_hwaccel = {
     183    .name           = "vc1_xvba",
     184    .type           = AVMEDIA_TYPE_VIDEO,
     185    .id             = CODEC_ID_VC1,
     186    .pix_fmt        = PIX_FMT_XVBA_VLD,
     187    .start_frame    = start_frame,
     188    .end_frame      = end_frame,
     189    .decode_slice   = decode_slice,
     190};
  • libavutil/pixdesc.c

    diff -Naur ffmpeg-1.0.4.old/libavutil/pixdesc.c ffmpeg-1.0.4/libavutil/pixdesc.c
    old new  
    902902        .log2_chroma_h = 1,
    903903        .flags = PIX_FMT_HWACCEL,
    904904    },
     905    [PIX_FMT_XVBA_VLD] = {
     906        .name = "xvba_vld",
     907        .log2_chroma_w = 1,
     908        .log2_chroma_h = 1,
     909        .flags = PIX_FMT_HWACCEL,
     910    },
    905911    [PIX_FMT_YUV420P9LE] = {
    906912        .name = "yuv420p9le",
    907913        .nb_components = 3,
  • libavutil/pixfmt.h

    diff -Naur ffmpeg-1.0.4.old/libavutil/pixfmt.h ffmpeg-1.0.4/libavutil/pixfmt.h
    old new  
    132132    PIX_FMT_YUV444P16BE,  ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
    133133    PIX_FMT_VDPAU_MPEG4,  ///< MPEG4 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
    134134    PIX_FMT_DXVA2_VLD,    ///< HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer
     135    PIX_FMT_XVBA_VLD,     ///< HW decoding through DXVA2, Picture.data[3] contains a vaapi_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
    135136
    136137    PIX_FMT_RGB444LE,  ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), little-endian, most significant bits to 0
    137138    PIX_FMT_RGB444BE,  ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0