[FFmpeg-devel] [PATCH] HWAccel infrastructure (take 7.1)

Michael Niedermayer michaelni
Mon Feb 23 18:59:08 CET 2009


On Mon, Feb 23, 2009 at 05:08:03PM +0100, Gwenole Beauchesne wrote:
> On Mon, 23 Feb 2009, Michael Niedermayer wrote:
>
>> please resend what remains against svn
>
> Attached, also depends on "[PATCH] Add ff_h263_find_resync_marker() 
> function" to simplify h263dec.c.

[...]

> @@ -134,7 +136,7 @@ av_cold int ff_h263_decode_end(AVCodecContext *avctx)
>  static int get_consumed_bytes(MpegEncContext *s, int buf_size){
>      int pos= (get_bits_count(&s->gb)+7)>>3;
>  
> -    if(s->divx_packed){
> +    if(s->divx_packed || s->avctx->hwaccel){
>          //we would have to scan through the whole buf to handle the weird reordering ...
>          return buf_size;
>      }else if(s->flags&CODEC_FLAG_TRUNCATED){

hunks ok


[...]

> @@ -616,6 +626,11 @@ retry:
>      if(MPV_frame_start(s, avctx) < 0)
>          return -1;
>  
> +    if (avctx->hwaccel) {
> +        if (avctx->hwaccel->start_frame(avctx, s->gb.buffer, s->gb.size_in_bits/8) < 0)
> +            return -1;
> +    }
> +
>  #ifdef DEBUG
>      av_log(avctx, AV_LOG_DEBUG, "qscale=%d\n", s->qscale);
>  #endif
> @@ -687,6 +702,11 @@ retry:
>  intrax8_decoded:
>      ff_er_frame_end(s);
>  
> +    if (avctx->hwaccel) {
> +        if (avctx->hwaccel->end_frame(avctx) < 0)
> +            return -1;
> +    }
> +
>      MPV_frame_end(s);
>  
>  assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);

what do you and others think about doing instead:

+    if (CONFIG_HWACCEL && avctx->hwaccel) {
+        if (avctx->hwaccel->end_frame(avctx) < 0)
+            return -1;
+    }

?
its not speed relevant but it would safe a few bytes on embeded systems ...


[...]
> diff --git a/libavcodec/internal.h b/libavcodec/internal.h
> index a8bed35..ce777f2 100644
> --- a/libavcodec/internal.h
> +++ b/libavcodec/internal.h
> @@ -24,6 +24,9 @@
>  #ifndef AVCODEC_INTERNAL_H
>  #define AVCODEC_INTERNAL_H
>  
> +#include <stdint.h>
> +#include "avcodec.h"
> +
>  /**
>   * Logs a generic warning message about a missing feature.
>   * @param[in] avc a pointer to an arbitrary struct of which the first field is

hunk ok


[...]
> @@ -1302,6 +1309,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx){
>          }//MPEG-2
>  
>          avctx->pix_fmt = mpeg_get_pixelformat(avctx);
> +        avctx->hwaccel = ff_pixfmt_to_hwaccel(avctx->pix_fmt);
>          //until then pix_fmt may be changed right after codec init
>          if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ||
>              avctx->hwaccel ||

hunk ok

[...]
> @@ -2071,8 +2104,10 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
>      s->low_delay= 1;
>  
>      avctx->pix_fmt = mpeg_get_pixelformat(avctx);
> +    avctx->hwaccel = ff_pixfmt_to_hwaccel(avctx->pix_fmt);
>  
>      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;

hunk ok


[...]
> +enum PixelFormat ff_query_pixfmt(AVCodecContext *avctx, enum CodecID codec_id)
> +{
> +    AVCodec *c;
> +    AVHWAccel *hwaccel;
> +    enum PixelFormat pix_fmts[PIX_FMT_NB + 1];
> +    int i, n_pix_fmts = 0;
> +
> +    /* 1. Finds hardware accelerated formats */
> +    for (hwaccel = first_hwaccel; hwaccel; hwaccel = hwaccel->next) {
> +        if (hwaccel->id == codec_id)
> +            pix_fmts[n_pix_fmts++] = hwaccel->pix_fmt;
> +    }
> +
> +    /* 2. Append default codec formats, or YUV420P */
> +    for (c = first_avcodec; c; c = c->next) {
> +        if (c->id == codec_id) {
> +            if (c->pix_fmts) {
> +                for (i = 0; c->pix_fmts[i] != PIX_FMT_NONE; i++)
> +                    pix_fmts[n_pix_fmts++] = c->pix_fmts[i];
> +            }
> +            else
> +                pix_fmts[n_pix_fmts++] = PIX_FMT_YUV420P;
> +            break;
> +        }
> +    }
> +
> +    pix_fmts[n_pix_fmts] = PIX_FMT_NONE;
> +    return avctx->get_format(avctx, pix_fmts);
> +}

this is broken actually, and ive not realized this until now ....
AVCodec.pix_fmts is the full and authrative list of suported pix_fmts

thus all calls to this function can be replaced by
return avctx->get_format(avctx, avctx->codec->pix_fmts);

and ff_query_pixfmt() droped


[...]
> @@ -4142,7 +4143,7 @@ static int vc1_decode_frame(AVCodecContext *avctx,
>      MpegEncContext *s = &v->s;
>      AVFrame *pict = data;
>      uint8_t *buf2 = NULL;
> -    const uint8_t *buf_vdpau = buf;
> +    const uint8_t *buf_start = buf;
>  
>      /* no supplementary picture */
>      if (buf_size == 0) {

renaming variables is a cosmetic change even if i fully agree that the
name buf_vdpau is poorly choosen, and should thus be in a seperate patch.

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

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu
-------------- 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/20090223/17b8f04e/attachment.pgp>



More information about the ffmpeg-devel mailing list