[FFmpeg-devel] [PATCH] mpeg12.c: add HW acceleration hooks

Michael Niedermayer michaelni
Wed Feb 25 20:17:05 CET 2009


On Wed, Feb 25, 2009 at 05:54:11PM +0100, Gwenole Beauchesne wrote:
> Hi,
>
> This patch adds HW accelerations hooks to the MPEG-1/2 codecs.
>
> Regards,
> Gwenole.

> diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
> index 0ef83b1..c984e1c 100644
> --- a/libavcodec/mpeg12.c
> +++ b/libavcodec/mpeg12.c
> @@ -1216,7 +1216,7 @@ static enum PixelFormat mpeg_get_pixelformat(AVCodecContext *avctx){
>              return PIX_FMT_VDPAU_MPEG2;
>      }else{
>          if(s->chroma_format <  2)
> -            return PIX_FMT_YUV420P;
> +            return avctx->get_format(avctx,ff_pixfmt_list_420);
>          else if(s->chroma_format == 2)
>              return PIX_FMT_YUV422P;
>          else
> @@ -1605,7 +1605,7 @@ static void exchange_uv(MpegEncContext *s){
>      s->pblocks[5] = tmp;
>  }
>  
> -static int mpeg_field_start(MpegEncContext *s){
> +static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size){
>      AVCodecContext *avctx= s->avctx;
>      Mpeg1Context *s1 = (Mpeg1Context*)s;
>  
> @@ -1645,6 +1645,12 @@ static int mpeg_field_start(MpegEncContext *s){
>                  }
>              }
>      }
> +
> +    if (avctx->hwaccel) {
> +        if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0)
> +            return -1;
> +    }
> +
>  // MPV_frame_start will call this function too,
>  // but we need to call it on every field
>      if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)

applied


> @@ -1697,6 +1703,20 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
>  
>      s->mb_x=0;
>  
> +    if (avctx->hwaccel) {
> +        const uint8_t *buf_end, *buf_start = *buf - 4; /* include start_code */
> +        int start_code = -1;
> +        buf_end = ff_find_start_code(buf_start + 2, *buf + buf_size, &start_code);
> +        if (buf_end < *buf + buf_size)
> +            buf_end -= 4;
> +        s->resync_mb_x = s->mb_x;
> +        s->resync_mb_y = s->mb_y = mb_y;
> +        if (avctx->hwaccel->decode_slice(avctx, buf_start, buf_end - buf_start) < 0)
> +            return DECODE_SLICE_ERROR;
> +        *buf = buf_end;
> +        return DECODE_SLICE_OK;
> +    }
> +
>      for(;;) {
>          int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
>          if (code < 0){

iam still investigating the need for this mess


> @@ -1912,6 +1932,11 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
>      Mpeg1Context *s1 = avctx->priv_data;
>      MpegEncContext *s = &s1->mpeg_enc_ctx;
>  
> +    if (s->avctx->hwaccel) {
> +        if (s->avctx->hwaccel->end_frame(s->avctx) < 0)
> +            av_log(avctx, AV_LOG_ERROR, "hardware accelerator failed to decode picture\n");
> +    }
> +
>      if (!s1->mpeg_enc_ctx_allocated || !s->current_picture_ptr)
>          return 0;
>  

this looks misplaced



> @@ -2074,7 +2099,7 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
>      avctx->pix_fmt = mpeg_get_pixelformat(avctx);
>      avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
>  
> -    if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ||
> +    if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel ||
>          s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU )
>          if( avctx->idct_algo == FF_IDCT_AUTO )
>              avctx->idct_algo = FF_IDCT_SIMPLE;
> @@ -2384,7 +2409,7 @@ static int decode_chunks(AVCodecContext *avctx,
>  
>                  if(s2->first_slice){
>                      s2->first_slice=0;
> -                    if(mpeg_field_start(s2) < 0)
> +                    if(mpeg_field_start(s2, buf, buf_size) < 0)
>                          return -1;
>                  }
>                  if(!s2->current_picture_ptr){

applied

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090225/c01314b5/attachment.pgp>



More information about the ffmpeg-devel mailing list