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

James Almer jamrial at gmail.com
Thu Aug 16 18:48:38 EEST 2018


On 8/16/2018 12:23 PM, Paul B Mahol wrote:
> On 8/16/18, James Almer <jamrial at gmail.com> wrote:
>> 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.
> 
> Why?, not mandatory.

It's not, but it's a better practice. Changing old lines is pointless,
but lets try to not add new ones.

> 
>>
>>> +        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()?
> 
> These are hardcoded values, always sane.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 



More information about the ffmpeg-devel mailing list