You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-07-06 06:27:36 +02:00
Add meaningful error codes and constants.
Replace literals with named constants in several pieces of code like 'return -1' and 'case 0xab'. Change the way decoder handles absence of image data in a file: notify gif_decode_frame() caller with got_picture set to zero instead of returning -1. Signed-off-by: Vitaliy E Sugrobov <vsugrob@hotmail.com>
This commit is contained in:
committed by
Paul B Mahol
parent
034a1afbd8
commit
c5fe41c768
@ -31,6 +31,10 @@
|
|||||||
#define GCE_DISPOSAL_INPLACE 1
|
#define GCE_DISPOSAL_INPLACE 1
|
||||||
#define GCE_DISPOSAL_BACKGROUND 2
|
#define GCE_DISPOSAL_BACKGROUND 2
|
||||||
#define GCE_DISPOSAL_RESTORE 3
|
#define GCE_DISPOSAL_RESTORE 3
|
||||||
|
#define GIF_TRAILER 0x3b
|
||||||
|
#define GIF_EXTENSION_INTRODUCER 0x21
|
||||||
|
#define GIF_IMAGE_SEPARATOR 0x2c
|
||||||
|
#define GIF_GCE_EXT_LABEL 0xf9
|
||||||
|
|
||||||
typedef struct GifState {
|
typedef struct GifState {
|
||||||
AVFrame picture;
|
AVFrame picture;
|
||||||
@ -170,7 +174,7 @@ static int gif_read_extension(GifState *s)
|
|||||||
av_dlog(s->avctx, "ext_code=0x%x len=%d\n", ext_code, ext_len);
|
av_dlog(s->avctx, "ext_code=0x%x len=%d\n", ext_code, ext_len);
|
||||||
|
|
||||||
switch(ext_code) {
|
switch(ext_code) {
|
||||||
case 0xf9:
|
case GIF_GCE_EXT_LABEL:
|
||||||
if (ext_len != 4)
|
if (ext_len != 4)
|
||||||
goto discard_ext;
|
goto discard_ext;
|
||||||
s->transparent_color_index = -1;
|
s->transparent_color_index = -1;
|
||||||
@ -248,28 +252,32 @@ static int gif_read_header1(GifState *s)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gif_parse_next_image(GifState *s)
|
static int gif_parse_next_image(GifState *s, int *got_picture)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
*got_picture = sizeof(AVPicture);
|
||||||
while (s->bytestream < s->bytestream_end) {
|
while (s->bytestream < s->bytestream_end) {
|
||||||
int code = bytestream_get_byte(&s->bytestream);
|
int code = bytestream_get_byte(&s->bytestream);
|
||||||
|
|
||||||
av_dlog(s->avctx, "code=%02x '%c'\n", code, code);
|
av_dlog(s->avctx, "code=%02x '%c'\n", code, code);
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case ',':
|
case GIF_IMAGE_SEPARATOR:
|
||||||
return gif_read_image(s);
|
return gif_read_image(s);
|
||||||
case '!':
|
case GIF_EXTENSION_INTRODUCER:
|
||||||
if (gif_read_extension(s) < 0)
|
if ((ret = gif_read_extension(s)) < 0)
|
||||||
return -1;
|
return ret;
|
||||||
break;
|
break;
|
||||||
case ';':
|
case GIF_TRAILER:
|
||||||
/* end of image */
|
/* end of image */
|
||||||
|
*got_picture = 0;
|
||||||
|
return 0;
|
||||||
default:
|
default:
|
||||||
/* error or erroneous EOF */
|
/* erroneous block label */
|
||||||
return -1;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return AVERROR_EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int gif_decode_init(AVCodecContext *avctx)
|
static av_cold int gif_decode_init(AVCodecContext *avctx)
|
||||||
@ -285,7 +293,7 @@ static av_cold int gif_decode_init(AVCodecContext *avctx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gif_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
|
static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_picture, AVPacket *avpkt)
|
||||||
{
|
{
|
||||||
const uint8_t *buf = avpkt->data;
|
const uint8_t *buf = avpkt->data;
|
||||||
int buf_size = avpkt->size;
|
int buf_size = avpkt->size;
|
||||||
@ -299,8 +307,8 @@ static int gif_decode_frame(AVCodecContext *avctx, void *data, int *data_size, A
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
avctx->pix_fmt = AV_PIX_FMT_PAL8;
|
avctx->pix_fmt = AV_PIX_FMT_PAL8;
|
||||||
if (av_image_check_size(s->screen_width, s->screen_height, 0, avctx))
|
if ((ret = av_image_check_size(s->screen_width, s->screen_height, 0, avctx)) < 0)
|
||||||
return -1;
|
return ret;
|
||||||
avcodec_set_dimensions(avctx, s->screen_width, s->screen_height);
|
avcodec_set_dimensions(avctx, s->screen_width, s->screen_height);
|
||||||
|
|
||||||
if (s->picture.data[0])
|
if (s->picture.data[0])
|
||||||
@ -310,12 +318,12 @@ static int gif_decode_frame(AVCodecContext *avctx, void *data, int *data_size, A
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
s->image_palette = (uint32_t *)s->picture.data[1];
|
s->image_palette = (uint32_t *)s->picture.data[1];
|
||||||
ret = gif_parse_next_image(s);
|
ret = gif_parse_next_image(s, got_picture);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
else if (*got_picture)
|
||||||
*picture = s->picture;
|
*picture = s->picture;
|
||||||
*data_size = sizeof(AVPicture);
|
|
||||||
return s->bytestream - buf;
|
return s->bytestream - buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user