[FFmpeg-devel] [PATCH] avcodec: add IMM4 decoder

James Almer jamrial at gmail.com
Thu Aug 16 18:07:27 EEST 2018


On 8/16/2018 8:00 AM, Paul B Mahol wrote:
> Hi,
> 
> another patch attached, please review.

> +static int decode_frame(AVCodecContext *avctx, void *data,
> +                        int *got_frame, AVPacket *avpkt)
> +{
> +    IMM4Context *s = avctx->priv_data;
> +    GetBitContext *gb = &s->gb;
> +    AVFrame *frame = data;
> +    unsigned type;
> +    int ret, scaled;
> +
> +    if (avpkt->size <= 32)
> +        return AVERROR_INVALIDDATA;
> +
> +    av_fast_padded_malloc(&s->bitstream, &s->bitstream_size,
> +                          FFALIGN(avpkt->size, 4));
> +    if (!s->bitstream)
> +        return AVERROR(ENOMEM);
> +
> +    s->bdsp.bswap_buf((uint32_t *)s->bitstream,
> +                      (uint32_t *)avpkt->data,
> +                      (avpkt->size + 3) >> 2);
> +
> +    if ((ret = init_get_bits8(gb, s->bitstream, FFALIGN(avpkt->size, 4))) < 0)

Split this in two, just to be safe.

> +        return ret;
> +
> +    avctx->pix_fmt = AV_PIX_FMT_YUV420P;
> +    avctx->color_range = AVCOL_RANGE_JPEG;
> +
> +    scaled = avpkt->data[8];
> +    if (scaled < 2) {
> +        int width, height;
> +        int mode = avpkt->data[10];
> +
> +        switch (mode) {
> +        case 1:
> +            width = 352;
> +            height = 240;
> +            break;
> +        case 2:
> +            width = 704;
> +            height = 240;
> +            break;
> +        case 4:
> +            width = 480;
> +            height = 704;
> +            break;
> +        case 17:
> +            width = 352;
> +            height = 288;
> +            break;
> +        case 18:
> +            width = 704;
> +            height = 288;
> +            break;
> +        default:
> +            width = 704;
> +            height = 576;
> +            break;
> +        }
> +
> +        if (s->changed_size == 1 &&
> +            (avctx->width != width || avctx->height != height)) {
> +            av_log(avctx, AV_LOG_ERROR, "Frame size change is unsupported.\n");
> +            return AVERROR_INVALIDDATA;
> +        }
> +        avctx->width = width;
> +        avctx->height = height;

ff_set_dimensions()?


More information about the ffmpeg-devel mailing list