[FFmpeg-devel] [PATCH 1/1] libutvideo: Add UT Video Decoder Wrapper

Michael Niedermayer michaelni at gmx.at
Mon Oct 17 00:59:01 CEST 2011


On Sun, Oct 16, 2011 at 05:54:23PM -0400, Derek Buitenhuis wrote:
> Add a wrapper for libutvideo's decoder.
> 
> This supports decoding the following FOURCCs:
>     ULY0 - 4:2:0 YCbCr
>     ULY2 - 4:2:2 YCbCr
>     ULRG - RGB
>     ULRA - RGBA
> 
> Also, bump version.
> 
> Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
[...]> new file mode 100644
> index 0000000..bf7abaa
> --- /dev/null
> +++ b/libavcodec/libutvideo.cpp
> @@ -0,0 +1,216 @@
> +/*
> + * Copyright (c) 2011 Derek Buitenhuis
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public
> + * License as published by the Free Software Foundation;
> + * version 2 of the License.
> + *
> + * 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
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU 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
> + */
> +
> +/**
> + * @file
> + * Known FOURCCs:
> + *     'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA)
> + */
> +
> +extern "C" {
> +#include "avcodec.h"
> +}
> +
> +#include <stdlib.h>
> +#include <utvideo/utvideo.h>
> +#include <utvideo/Codec.h>
> +
> +typedef struct {
> +    uint32_t version;
> +    uint32_t original_format;
> +    uint32_t stripes;
> +    uint32_t flags;
> +} UTVideoExtra;
> +
> +typedef struct {
> +    CCodec *codec;
> +    unsigned int buf_size;
> +    uint8_t *output;
> +} UTVideoContext;
> +
> +static av_cold int utvideo_decode_init(AVCodecContext *avctx)
> +{
> +    UTVideoContext *utv = (UTVideoContext *)avctx->priv_data;

> +    UTVideoExtra *info = (UTVideoExtra *)avctx->extradata;

This does not look endian safe
the values should be read with something like AV_RL32() or
bytestream_get_le32()
also you need to check extradata_size


[...]
> +static int utvideo_decode_frame(AVCodecContext *avctx, void *data,
> +                                int *data_size, AVPacket *avpkt) 
> +{
> +    UTVideoContext *utv = (UTVideoContext *)avctx->priv_data;
> +    AVFrame *pic = avctx->coded_frame;
> +    unsigned int w = avctx->width, h = avctx->height;
> +
> +    /* Set flags */
> +    pic->reference = 0;
> +    pic->pict_type = AV_PICTURE_TYPE_I;
> +    pic->key_frame = 1;
> +
> +    /* Decode the frame */
> +    utv->codec->DecodeFrame(utv->output, avpkt->data, true);

ideally one should execute a get_buffer() before this and use the
resulting frame and set CODEC_CAP_DR1
that way the decoder can decode into buffers provided by the user
application. This would require linesize to be setable by us though
and i dont see where this could be done


> +
> +    /* Set the output data depending on the colorspace */
> +    switch(avctx->pix_fmt)
> +    {
> +        case PIX_FMT_YUV420P:
> +            pic->linesize[0] = w;
> +            pic->linesize[1] = pic->linesize[2] = w / 2;
> +            pic->data[0] = utv->output;
> +            pic->data[2] = utv->output + (w * h);
> +            pic->data[1] = pic->data[2] + (w * h / 4);
> +            break;
> +        case PIX_FMT_YUYV422:
> +        case PIX_FMT_UYVY422:
> +            pic->linesize[0] = w * 2;
> +            pic->data[0] = utv->output;
> +            break;
> +        case PIX_FMT_BGR24:
> +        case PIX_FMT_RGB32:
> +            /* Make the linesize negative, since UT Video uses bottom-up BGR */
> +            pic->linesize[0] = -1 * w * (avctx->pix_fmt == PIX_FMT_BGR24 ? 3 : 4);
> +            pic->data[0] = utv->output + utv->buf_size + pic->linesize[0];
> +            break;
> +     }
> +
> +    *data_size = sizeof(AVFrame);
> +    *(AVFrame *)data = *avctx->coded_frame;
> +
> +    return avpkt->size;
> +}
> +
> +static av_cold int utvideo_decode_close(AVCodecContext *avctx)
> +{
> +    UTVideoContext *utv = (UTVideoContext *)avctx->priv_data;
> +
> +    /* Free output */
> +    av_freep(&avctx->coded_frame);

> +    av_free(utv->output);

av_freep() is preferred as its a bit safer


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

You can kill me, but you cannot change the truth.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111017/5588bd1f/attachment.asc>


More information about the ffmpeg-devel mailing list