diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-01-12 16:01:50 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-01-12 16:08:27 +0100 |
commit | 7e343798976991f4320c1c90b8d4fac4c2f9e355 (patch) | |
tree | 4ffd20dd9efa6411a71f46c4eec21819af6ee3dc | |
parent | ce795ac0f53e4c2e50667ac1bef38b82e945e96d (diff) | |
parent | 0e8ae6d10c609bb968c141aa2436413a55852590 (diff) | |
download | ffmpeg-7e343798976991f4320c1c90b8d4fac4c2f9e355.tar.gz |
Merge commit '0e8ae6d10c609bb968c141aa2436413a55852590' into release/1.1
* commit '0e8ae6d10c609bb968c141aa2436413a55852590':
mpegvideo: Drop a faulty assert
lavr: check that current_buffer is not NULL before using it
pmpdec: check that there is at least one audio packet.
lzw: switch to bytestream2
gifdec: convert to bytestream2
Conflicts:
libavcodec/gifdec.c
libavcodec/lzw.c
libavcodec/lzw.h
libavformat/pmpdec.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavcodec/gifdec.c | 24 | ||||
-rw-r--r-- | libavcodec/lzw.c | 29 | ||||
-rw-r--r-- | libavformat/pmpdec.c | 5 | ||||
-rw-r--r-- | libavresample/utils.c | 3 |
4 files changed, 27 insertions, 34 deletions
diff --git a/libavcodec/gifdec.c b/libavcodec/gifdec.c index 6c9c751054..09a6d74075 100644 --- a/libavcodec/gifdec.c +++ b/libavcodec/gifdec.c @@ -65,8 +65,8 @@ typedef struct GifState { int stored_img_size; int stored_bg_color; - GetByteContext gb; /* LZW compatible decoder */ + GetByteContext gb; LZWState *lzw; /* aux buffers */ @@ -144,11 +144,11 @@ static int gif_read_image(GifState *s) if (bytestream2_get_bytes_left(&s->gb) < 9) return AVERROR_INVALIDDATA; - left = bytestream2_get_le16u(&s->gb); - top = bytestream2_get_le16u(&s->gb); - width = bytestream2_get_le16u(&s->gb); + left = bytestream2_get_le16u(&s->gb); + top = bytestream2_get_le16u(&s->gb); + width = bytestream2_get_le16u(&s->gb); height = bytestream2_get_le16u(&s->gb); - flags = bytestream2_get_byteu(&s->gb); + flags = bytestream2_get_byteu(&s->gb); is_interleaved = flags & 0x40; has_local_palette = flags & 0x80; bits_per_pixel = (flags & 0x07) + 1; @@ -317,7 +317,7 @@ static int gif_read_extension(GifState *s) if (bytestream2_get_bytes_left(&s->gb) < 5) return AVERROR_INVALIDDATA; - gce_flags = bytestream2_get_byteu(&s->gb); + gce_flags = bytestream2_get_byteu(&s->gb); bytestream2_skipu(&s->gb, 2); // delay during which the frame is shown gce_transparent_index = bytestream2_get_byteu(&s->gb); if (gce_flags & 0x01) @@ -371,7 +371,7 @@ static int gif_read_header1(GifState *s) /* read screen header */ s->transparent_color_index = -1; - s->screen_width = bytestream2_get_le16u(&s->gb); + s->screen_width = bytestream2_get_le16u(&s->gb); s->screen_height = bytestream2_get_le16u(&s->gb); if( (unsigned)s->screen_width > 32767 || (unsigned)s->screen_height > 32767){ @@ -415,7 +415,7 @@ static int gif_read_header1(GifState *s) static int gif_parse_next_image(GifState *s, int *got_picture) { *got_picture = 1; - while (bytestream2_get_bytes_left(&s->gb)) { + while (bytestream2_get_bytes_left(&s->gb) > 0) { int code = bytestream2_get_byte(&s->gb); int ret; @@ -462,9 +462,9 @@ static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, A bytestream2_init(&s->gb, avpkt->data, avpkt->size); - s->picture.pts = avpkt->pts; - s->picture.pkt_pts = avpkt->pts; - s->picture.pkt_dts = avpkt->dts; + s->picture.pts = avpkt->pts; + s->picture.pkt_pts = avpkt->pts; + s->picture.pkt_dts = avpkt->dts; s->picture.pkt_duration = avpkt->duration; if (avpkt->size >= 6) { @@ -516,7 +516,7 @@ static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, A else if (*got_frame) *picture = s->picture; - return avpkt->size; + return bytestream2_tell(&s->gb); } static av_cold int gif_decode_close(AVCodecContext *avctx) diff --git a/libavcodec/lzw.c b/libavcodec/lzw.c index 43e3e055c2..6832c122a2 100644 --- a/libavcodec/lzw.c +++ b/libavcodec/lzw.c @@ -28,6 +28,7 @@ */ #include "avcodec.h" +#include "bytestream.h" #include "lzw.h" #include "libavutil/mem.h" @@ -43,7 +44,7 @@ static const uint16_t mask[17] = }; struct LZWState { - const uint8_t *pbuf, *ebuf; + GetByteContext gb; int bbits; unsigned int bbuf; @@ -73,9 +74,9 @@ static int lzw_get_code(struct LZWState * s) if(s->mode == FF_LZW_GIF) { while (s->bbits < s->cursize) { if (!s->bs) { - s->bs = *s->pbuf++; + s->bs = bytestream2_get_byte(&s->gb); } - s->bbuf |= (*s->pbuf++) << s->bbits; + s->bbuf |= bytestream2_get_byte(&s->gb) << s->bbits; s->bbits += 8; s->bs--; } @@ -83,7 +84,7 @@ static int lzw_get_code(struct LZWState * s) s->bbuf >>= s->cursize; } else { // TIFF while (s->bbits < s->cursize) { - s->bbuf = (s->bbuf << 8) | (*s->pbuf++); + s->bbuf = (s->bbuf << 8) | bytestream2_get_byte(&s->gb); s->bbits += 8; } c = s->bbuf >> (s->bbits - s->cursize); @@ -97,17 +98,12 @@ void ff_lzw_decode_tail(LZWState *p) struct LZWState *s = (struct LZWState *)p; if(s->mode == FF_LZW_GIF) { - while (s->bs > 0) { - if (s->bs >= s->ebuf - s->pbuf) { - s->pbuf = s->ebuf; - break; - } else { - s->pbuf += s->bs; - s->bs = *s->pbuf++; - } + while (s->bs > 0 && bytestream2_get_bytes_left(&s->gb)) { + bytestream2_skip(&s->gb, s->bs); + s->bs = bytestream2_get_byte(&s->gb); } }else - s->pbuf= s->ebuf; + bytestream2_skip(&s->gb, bytestream2_get_bytes_left(&s->gb)); } av_cold void ff_lzw_decode_open(LZWState **p) @@ -135,8 +131,7 @@ int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, if(csize < 1 || csize >= LZW_MAXBITS) return -1; /* read buffer */ - s->pbuf = buf; - s->ebuf = s->pbuf + buf_size; + bytestream2_init(&s->gb, buf, buf_size); s->bbuf = 0; s->bbits = 0; s->bs = 0; @@ -186,10 +181,6 @@ int ff_lzw_decode(LZWState *p, uint8_t *buf, int len){ if ((--l) == 0) goto the_end; } - if (s->ebuf < s->pbuf) { - av_log(NULL, AV_LOG_ERROR, "lzw overread\n"); - goto the_end; - } c = lzw_get_code(s); if (c == s->end_code) { break; diff --git a/libavformat/pmpdec.c b/libavformat/pmpdec.c index 2ea37ef030..cfac3344c4 100644 --- a/libavformat/pmpdec.c +++ b/libavformat/pmpdec.c @@ -125,9 +125,10 @@ static int pmp_packet(AVFormatContext *s, AVPacket *pkt) int num_packets; pmp->audio_packets = avio_r8(pb); if (!pmp->audio_packets) { - av_log_ask_for_sample(s, "0 audio packets\n"); - return AVERROR_PATCHWELCOME; + av_log(s, AV_LOG_ERROR, "No audio packets.\n"); + return AVERROR_INVALIDDATA; } + num_packets = (pmp->num_streams - 1) * pmp->audio_packets + 1; avio_skip(pb, 8); pmp->current_packet = 0; diff --git a/libavresample/utils.c b/libavresample/utils.c index 8f6583d6e8..7878cd2374 100644 --- a/libavresample/utils.c +++ b/libavresample/utils.c @@ -350,7 +350,8 @@ int attribute_align_arg avresample_convert(AVAudioResampleContext *avr, resample_out = &output_buffer; else resample_out = avr->resample_out_buffer; - av_dlog(avr, "[resample] %s to %s\n", current_buffer->name, + av_dlog(avr, "[resample] %s to %s\n", + current_buffer ? current_buffer->name : "null", resample_out->name); ret = ff_audio_resample(avr->resample, resample_out, current_buffer); |