[FFmpeg-devel] [PATCH] HWAccel infrastructure (take 7.3)
Michael Niedermayer
michaelni
Tue Feb 24 19:40:25 CET 2009
On Tue, Feb 24, 2009 at 06:09:25PM +0100, Gwenole Beauchesne wrote:
> On Tue, 24 Feb 2009, Michael Niedermayer wrote:
>
>> after seeing your patch, i think per codec pix_fmts really should be
>> removed.
>> This would make the code much simpler and cleaner. It also would greatly
>> simplify get_format() for user apps,having to test just for one pix_fmt
>> er hwaccel API instead of for one per codec X API
>
> New patch attached:
[...]
> diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
> index d2c8fd1..45aae47 100644
> --- a/libavcodec/h263dec.c
> +++ b/libavcodec/h263dec.c
> @@ -36,6 +36,15 @@
> //#define DEBUG
> //#define PRINT_FRAME_TIME
>
> +/**
> + * Allowed pixel formats for MPEG-4 / H.263 codec (4:2:0 chroma format)
> + * Note: HW accelerated formats shall come first
> + */
> +static const enum PixelFormat pixfmt_list_420[] = {
> + PIX_FMT_YUV420P,
> + PIX_FMT_NONE
> +};
> +
> av_cold int ff_h263_decode_init(AVCodecContext *avctx)
> {
> MpegEncContext *s = avctx->priv_data;
> @@ -52,7 +61,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
> s->quant_precision=5;
> s->decode_mb= ff_h263_decode_mb;
> s->low_delay= 1;
> - avctx->pix_fmt= PIX_FMT_YUV420P;
> + avctx->pix_fmt= avctx->get_format(avctx, pixfmt_list_420);
> s->unrestricted_mv= 1;
>
> /* select sub codec */
implemented differently
> @@ -106,6 +115,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
> return -1;
> }
> s->codec_id= avctx->codec->id;
> + avctx->hwaccel= ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
>
> /* for h263, we allocate the images after having read the header */
> if (avctx->codec->id != CODEC_ID_H263 && avctx->codec->id != CODEC_ID_MPEG4)
hunk ok
> @@ -134,7 +144,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){
applied
> @@ -160,8 +170,12 @@ static int decode_slice(MpegEncContext *s){
>
> ff_set_qscale(s, s->qscale);
>
> - if (s->avctx->hwaccel)
> - return 0;
> + if (s->avctx->hwaccel) {
> + const uint8_t *start, *end;
> + start = s->gb.buffer + get_bits_count(&s->gb)/8;
> + end = ff_h263_find_resync_marker(start + 1, s->gb.buffer_end);
> + return s->avctx->hwaccel->decode_slice(s->avctx, start, end - start);
> + }
>
> if(s->partitioned_frame){
> const int qscale= s->qscale;
rejected, this does a useless double scan also its more messy than needed.
> @@ -616,6 +630,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
its buf/buf_size
> @@ -687,6 +706,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);
applied
> diff --git a/libavcodec/h264.c b/libavcodec/h264.c
> index 6ea09b0..be2bf84 100644
> --- a/libavcodec/h264.c
> +++ b/libavcodec/h264.c
> @@ -104,6 +104,15 @@ static const uint8_t left_block_options[4][8]={
> {0,2,0,2,7,10,7,10}
> };
>
> +/**
> + * Allowed pixel formats for H.264 codec (4:2:0 chroma format)
> + * Note: HW accelerated formats shall come first
> + */
> +static const enum PixelFormat pixfmt_list_420[] = {
> + PIX_FMT_YUV420P,
> + PIX_FMT_NONE
> +};
> +
> #define LEVEL_TAB_BITS 8
> static int8_t cavlc_level_tab[7][1<<LEVEL_TAB_BITS][2];
>
> @@ -2183,7 +2192,8 @@ static av_cold int decode_init(AVCodecContext *avctx){
> else if(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
> avctx->pix_fmt= PIX_FMT_VDPAU_H264;
> else
> - avctx->pix_fmt= PIX_FMT_YUV420P;
> + avctx->pix_fmt= avctx->get_format(avctx, pixfmt_list_420);
> + avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
>
> decode_init_vlc();
>
implemented differently
[...]
> @@ -1644,6 +1654,12 @@ static int mpeg_field_start(MpegEncContext *s){
> }
> }
> }
> +
> + if (avctx->hwaccel) {
> + if (avctx->hwaccel->start_frame(avctx, NULL, 0) < 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)
NULL, 0 looks wrong
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus
-------------- 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/20090224/5096aea5/attachment.pgp>
More information about the ffmpeg-devel
mailing list