On 03/06/16 21:51, Vittorio Giovara wrote:
> From: Paul B Mahol <one...@gmail.com>
> 
> Signed-off-by: Paul B Mahol <one...@gmail.com>
> Signed-off-by: Vittorio Giovara <vittorio.giov...@gmail.com>
> ---
> Needs version bump.
> Vittorio
> 
>  Changelog                  |   1 +
>  doc/general.texi           |   2 +
>  libavcodec/Makefile        |   1 +
>  libavcodec/allcodecs.c     |   1 +
>  libavcodec/avcodec.h       |   1 +
>  libavcodec/codec_desc.c    |   7 ++
>  libavcodec/truemotion2rt.c | 227 
> +++++++++++++++++++++++++++++++++++++++++++++
>  libavformat/riff.c         |   1 +
>  8 files changed, 241 insertions(+)
>  create mode 100644 libavcodec/truemotion2rt.c
> 
> diff --git a/Changelog b/Changelog
> index a3f5376..ac4c725 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -58,6 +58,7 @@ version <next>:
>  - MMAL-accelerated MPEG-2 and VC-1 decoding
>  - G.729 raw demuxer
>  - MagicYUV decoder
> +- Duck TrueMotion 2.0 Real Time decoder
>  
>  
>  version 11:
> diff --git a/doc/general.texi b/doc/general.texi
> index a6a6db6..0590c23 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -607,6 +607,8 @@ following image formats are supported:
>      @tab fourcc: DUCK
>  @item Duck TrueMotion 2.0    @tab     @tab  X
>      @tab fourcc: TM20
> +@item Duck TrueMotion 2.0 RT @tab     @tab  X
> +    @tab fourcc: TR20
>  @item DV (Digital Video)     @tab  X  @tab  X
>  @item Dxtory capture format  @tab     @tab  X
>  @item Feeble Files/ScummVM DXA  @tab     @tab  X
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 8352c97..1f2096c 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -438,6 +438,7 @@ OBJS-$(CONFIG_TIFF_ENCODER)            += tiffenc.o rle.o 
> lzwenc.o
>  OBJS-$(CONFIG_TMV_DECODER)             += tmv.o cga_data.o
>  OBJS-$(CONFIG_TRUEMOTION1_DECODER)     += truemotion1.o
>  OBJS-$(CONFIG_TRUEMOTION2_DECODER)     += truemotion2.o
> +OBJS-$(CONFIG_TRUEMOTION2RT_DECODER)   += truemotion2rt.o
>  OBJS-$(CONFIG_TRUESPEECH_DECODER)      += truespeech.o
>  OBJS-$(CONFIG_TSCC_DECODER)            += tscc.o msrledec.o
>  OBJS-$(CONFIG_TSCC2_DECODER)           += tscc2.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index bb90627..6fa1617 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -265,6 +265,7 @@ void avcodec_register_all(void)
>      REGISTER_DECODER(TMV,               tmv);
>      REGISTER_DECODER(TRUEMOTION1,       truemotion1);
>      REGISTER_DECODER(TRUEMOTION2,       truemotion2);
> +    REGISTER_DECODER(TRUEMOTION2RT,     truemotion2rt);
>      REGISTER_DECODER(TSCC,              tscc);
>      REGISTER_DECODER(TSCC2,             tscc2);
>      REGISTER_DECODER(TXD,               txd);
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 00cf4af..aebdc0f 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -390,6 +390,7 @@ enum AVCodecID {
>      AV_CODEC_ID_SCREENPRESSO,
>      AV_CODEC_ID_RSCC,
>      AV_CODEC_ID_MAGICYUV,
> +    AV_CODEC_ID_TRUEMOTION2RT,
>  
>      /* various PCM "codecs" */
>      AV_CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the 
> start of audio codecs
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index d328ba3..bb5ecef 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -1198,6 +1198,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
>          .long_name = NULL_IF_CONFIG_SMALL("MagicYUV Lossless Video"),
>          .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
>      },
> +    {
> +        .id        = AV_CODEC_ID_TRUEMOTION2RT,
> +        .type      = AVMEDIA_TYPE_VIDEO,
> +        .name      = "truemotion2rt",
> +        .long_name = NULL_IF_CONFIG_SMALL("Duck TrueMotion 2.0 Real Time"),
> +        .props     = AV_CODEC_PROP_LOSSY,
> +    },
>  
>      /* image codecs */
>      {
> diff --git a/libavcodec/truemotion2rt.c b/libavcodec/truemotion2rt.c
> new file mode 100644
> index 0000000..083a7df
> --- /dev/null
> +++ b/libavcodec/truemotion2rt.c
> @@ -0,0 +1,227 @@
> +/*
> + * Duck TrueMotion 2.0 Real Time Decoder
> + *
> + * This file is part of Libav.
> + *
> + * Libav is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * Libav 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
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with Libav; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +
> +#include "libavutil/imgutils.h"
> +#include "libavutil/internal.h"
> +#include "libavutil/intreadwrite.h"
> +#include "libavutil/mem.h"
> +
> +#include "avcodec.h"
> +#define BITSTREAM_READER_LE
> +#include "get_bits.h"
> +#include "internal.h"
> +
> +typedef struct TrueMotion2RTContext {
> +    GetBitContext gb;
> +    const uint8_t *buf;
> +    int size;
> +    int delta_size;
> +    int hscale;
> +} TrueMotion2RTContext;
> +
> +static const int16_t delta_tab2[] = {
> +    5, -7, 36, -36,
> +};
> +
> +static const int16_t delta_tab3[] = {
> +    2, -3, 8, -8, 18, -18, 36, -36,
> +};
> +
> +static const int16_t delta_tab4[] = {
> +    1, -1, 2, -3, 8, -8, 18, -18, 36, -36, 54, -54, 96, -96, 144, -144,
> +};
> +
> +static const int16_t *const delta_tabs[] = {
> +    delta_tab2, delta_tab3, delta_tab4,
> +};
> +
> +/* Returns the number of bytes consumed from the bytestream. Returns -1 if
> + * there was an error while decoding the header */
> +static int truemotion2rt_decode_header(AVCodecContext *avctx)
> +{
> +    TrueMotion2RTContext *s = avctx->priv_data;
> +    uint8_t header_buffer[128] = { 0 };  /* logical maximum header size */
> +    int i, header_size;
> +
> +    if (s->size < 1) {
> +        av_log(avctx, AV_LOG_ERROR, "input packet too small (%d)\n", 
> s->size);
> +        return AVERROR_INVALIDDATA;
> +    }
> +
> +    header_size = ((s->buf[0] >> 5) | (s->buf[0] << 3)) & 0x7f;
> +    if (header_size < 10) {
> +        av_log(avctx, AV_LOG_ERROR, "invalid header size (%d)\n", 
> header_size);
> +        return AVERROR_INVALIDDATA;
> +    }
> +
> +    if (header_size + 1 > s->size) {
> +        av_log(avctx, AV_LOG_ERROR, "input packet too small (%d)\n", 
> s->size);
> +        return AVERROR_INVALIDDATA;
> +    }
> +
> +    /* unscramble the header bytes with a XOR operation */
> +    for (i = 1; i < header_size; i++)
> +        header_buffer[i - 1] = s->buf[i] ^ s->buf[i + 1];
> +
> +    s->delta_size = header_buffer[1];
> +    s->hscale = 1 + !!header_buffer[3];
> +    if (s->delta_size < 2 || s->delta_size > 4)
> +        return AVERROR_INVALIDDATA;
> +
> +    avctx->height = AV_RL16(header_buffer + 5);
> +    avctx->width  = AV_RL16(header_buffer + 7);
> +
> +    av_log(avctx, AV_LOG_DEBUG, "Header size: %d\n", header_size);
> +    return header_size;
> +}
> +
> +static int truemotion2rt_decode_frame(AVCodecContext *avctx, void *data,
> +                                      int *got_frame, AVPacket *avpkt)
> +{
> +    TrueMotion2RTContext *s = avctx->priv_data;
> +    AVFrame * const p = data;
> +    GetBitContext *gb = &s->gb;
> +    uint8_t *dst;
> +    int x, y, delta_mode;
> +    int ret;
> +
> +    s->buf  = avpkt->data;
> +    s->size = avpkt->size;

Those could be dropped for local variables I guess.

The rest seems fine to me.

lu
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to