[FFmpeg-devel] [PATCH 1/2] avcodec: add mvdv video decoder
James Almer
jamrial at gmail.com
Tue Nov 26 21:06:41 EET 2019
On 11/25/2019 6:09 PM, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
> libavcodec/Makefile | 1 +
> libavcodec/allcodecs.c | 1 +
> libavcodec/avcodec.h | 1 +
> libavcodec/codec_desc.c | 7 ++
> libavcodec/midivid.c | 272 ++++++++++++++++++++++++++++++++++++++++
> libavformat/riff.c | 1 +
> 6 files changed, 283 insertions(+)
> create mode 100644 libavcodec/midivid.c
[...]
> diff --git a/libavcodec/midivid.c b/libavcodec/midivid.c
> new file mode 100644
> index 0000000000..36ed4b83bd
> --- /dev/null
> +++ b/libavcodec/midivid.c
> @@ -0,0 +1,272 @@
> +/*
> + * MidiVid decoder
> + * Copyright (c) 2019 Paul B Mahol
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg 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.
> + *
> + * 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
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser 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
> + */
> +
> +#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"
> +
> +#define BITSTREAM_READER_LE
> +#include "avcodec.h"
> +#include "get_bits.h"
> +#include "bytestream.h"
> +#include "internal.h"
> +
> +typedef struct MidiVidContext {
> + GetByteContext gb;
> +
> + uint8_t *uncompressed;
> + int uncompressed_size;
Should be unsigned int, seeing it's used as argument for
av_fast_padded_malloc().
> + uint8_t *skip;
> +
> + AVFrame *frame;
> +} MidiVidContext;
> +
> +static int decode_mvdv(MidiVidContext *s, AVCodecContext *avctx, AVFrame *frame)
> +{
> + GetByteContext *gb = &s->gb;
> + GetBitContext mask;
> + GetByteContext idx9;
> + uint16_t nb_vectors, intra_flag;
> + const uint8_t *vec;
> + const uint8_t *mask_start;
> + uint8_t *skip;
> + int mask_size;
> + int idx9bits = 0;
> + int idx9val = 0;
> + int num_blocks;
> +
> + nb_vectors = bytestream2_get_le16(gb);
> + intra_flag = bytestream2_get_le16(gb);
> + if (intra_flag) {
> + num_blocks = (avctx->width / 2) * (avctx->height / 2);
> + } else {
> + int skip_linesize;
> +
> + num_blocks = bytestream2_get_le32(gb);
> + skip_linesize = avctx->width >> 1;
> + mask_start = gb->buffer_start + bytestream2_tell(gb);
> + mask_size = (avctx->width >> 5) * (avctx->height >> 2);
> + init_get_bits8(&mask, mask_start, mask_size);
> + bytestream2_skip(gb, mask_size);
> + skip = s->skip;
> +
> + for (int y = 0; y < avctx->height >> 2; y++) {
> + for (int x = 0; x < avctx->width >> 2; x++) {
> + int flag = !get_bits1(&mask);
> +
> + skip[(y*2) *skip_linesize + x*2 ] = flag;
> + skip[(y*2) *skip_linesize + x*2+1] = flag;
> + skip[(y*2+1)*skip_linesize + x*2 ] = flag;
> + skip[(y*2+1)*skip_linesize + x*2+1] = flag;
> + }
> + }
> + }
> +
> + vec = gb->buffer_start + bytestream2_tell(gb);
Isn't this the same as doing vec = g->buffer?
> + if (bytestream2_get_bytes_left(gb) < nb_vectors * 12)
> + return AVERROR_INVALIDDATA;
> + bytestream2_skip(gb, nb_vectors * 12);
> + if (nb_vectors > 256) {
> + if (bytestream2_get_bytes_left(gb) < (num_blocks + 7) / 8)
> + return AVERROR_INVALIDDATA;
> + bytestream2_init(&idx9, gb->buffer_start + bytestream2_tell(gb), (num_blocks + 7) / 8);
Ditto.
More information about the ffmpeg-devel
mailing list