summaryrefslogtreecommitdiff
path: root/libavformat/gifdec.c
diff options
context:
space:
mode:
authorClément Bœsch <ubitux@gmail.com>2013-04-18 22:21:58 +0200
committerClément Bœsch <ubitux@gmail.com>2013-04-20 00:05:35 +0200
commita16c20569db6cecceb988b5b6ecac451af84e15d (patch)
tree876980fcde77b9e19570d84fd7576d6a8713dfe0 /libavformat/gifdec.c
parentf5ede48fbb41d37e13a8ffd04eee1fdc78e44ec3 (diff)
lavf/gifdec: add loop support.
Loop is ignored by default.
Diffstat (limited to 'libavformat/gifdec.c')
-rw-r--r--libavformat/gifdec.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/libavformat/gifdec.c b/libavformat/gifdec.c
index 1122849abd..e05dc419c7 100644
--- a/libavformat/gifdec.c
+++ b/libavformat/gifdec.c
@@ -44,6 +44,13 @@ typedef struct GIFDemuxContext {
*/
int min_delay;
int default_delay;
+
+ /**
+ * loop options
+ */
+ int total_iter;
+ int iter_count;
+ int ignore_loop;
} GIFDemuxContext;
/**
@@ -156,6 +163,17 @@ static int gif_read_ext(AVFormatContext *s)
/* skip the rest of the Graphic Control Extension block */
if ((ret = avio_skip(pb, sb_size - 3)) < 0 )
return ret;
+ } else if (ext_label == GIF_APP_EXT_LABEL) {
+ uint8_t netscape_ext[sizeof(NETSCAPE_EXT_STR)-1 + 2];
+
+ if ((sb_size = avio_r8(pb)) != strlen(NETSCAPE_EXT_STR))
+ return 0;
+ ret = avio_read(pb, netscape_ext, sizeof(netscape_ext));
+ if (ret < sizeof(netscape_ext))
+ return ret;
+ gdc->total_iter = avio_rl16(pb);
+ if (gdc->total_iter == 0)
+ gdc->total_iter = -1;
}
if ((ret = gif_skip_subblocks(pb)) < 0)
@@ -268,9 +286,12 @@ resync:
}
}
- if (ret >= 0 && !frame_parsed) {
+ if ((ret >= 0 && !frame_parsed) || ret == AVERROR_EOF) {
/* This might happen when there is no image block
* between extension blocks and GIF_TRAILER or EOF */
+ if (!gdc->ignore_loop && (block_label == GIF_TRAILER || url_feof(pb))
+ && (gdc->total_iter < 0 || ++gdc->iter_count < gdc->total_iter))
+ return avio_seek(pb, 0, SEEK_SET);
return AVERROR_EOF;
} else
return ret;
@@ -279,6 +300,7 @@ resync:
static const AVOption options[] = {
{ "min_delay" , "minimum valid delay between frames (in hundredths of second)", offsetof(GIFDemuxContext, min_delay) , AV_OPT_TYPE_INT, {.i64 = GIF_MIN_DELAY} , 0, 100 * 60, AV_OPT_FLAG_DECODING_PARAM },
{ "default_delay", "default delay between frames (in hundredths of second)" , offsetof(GIFDemuxContext, default_delay), AV_OPT_TYPE_INT, {.i64 = GIF_DEFAULT_DELAY}, 0, 100 * 60, AV_OPT_FLAG_DECODING_PARAM },
+ { "ignore_loop" , "ignore loop setting (netscape extension)" , offsetof(GIFDemuxContext, ignore_loop) , AV_OPT_TYPE_INT, {.i64 = 1} , 0, 1, AV_OPT_FLAG_DECODING_PARAM },
{ NULL },
};