diff options
-rw-r--r-- | libavcodec/avcodec.h | 5 | ||||
-rw-r--r-- | libavcodec/utils.c | 6 | ||||
-rw-r--r-- | libavcodec/vb.c | 77 | ||||
-rw-r--r-- | libavcodec/wavpack.c | 27 | ||||
-rw-r--r-- | libavformat/mov.c | 93 | ||||
-rw-r--r-- | libavformat/mxfdec.c | 79 | ||||
-rw-r--r-- | tests/Makefile | 1 | ||||
-rw-r--r-- | tests/fate/adpcm.mak | 35 | ||||
-rw-r--r-- | tests/fate/dpcm.mak | 36 |
9 files changed, 182 insertions, 177 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 9a8ca81db9..4e55e0e12b 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -4188,6 +4188,11 @@ int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options) * @warning The end of the input buffer avpkt->data should be set to 0 to ensure that * no overreading happens for damaged MPEG streams. * + * @warning You must not provide a custom get_buffer() when using + * avcodec_decode_audio3(). Doing so will override it with + * avcodec_default_get_buffer. Use avcodec_decode_audio4() instead, + * which does allow the application to provide a custom get_buffer(). + * * @note You might have to align the input buffer avpkt->data and output buffer * samples. The alignment requirements depend on the CPU: On some CPUs it isn't * necessary at all, on others it won't work at all if not aligned and on others diff --git a/libavcodec/utils.c b/libavcodec/utils.c index e25f1dfb41..462288446b 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1057,8 +1057,10 @@ int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *sa int ret, got_frame = 0; if (avctx->get_buffer != avcodec_default_get_buffer) { - av_log(avctx, AV_LOG_ERROR, "Overriding custom get_buffer() for " - "avcodec_decode_audio3()\n"); + av_log(avctx, AV_LOG_ERROR, "Custom get_buffer() for use with" + "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n"); + av_log(avctx, AV_LOG_ERROR, "Please port your application to " + "avcodec_decode_audio4()\n"); avctx->get_buffer = avcodec_default_get_buffer; avctx->release_buffer = avcodec_default_release_buffer; } diff --git a/libavcodec/vb.c b/libavcodec/vb.c index 26967db7b2..50e5d0b1a4 100644 --- a/libavcodec/vb.c +++ b/libavcodec/vb.c @@ -44,7 +44,7 @@ typedef struct VBDecContext { uint8_t *frame, *prev_frame; uint32_t pal[AVPALETTE_COUNT]; - const uint8_t *stream; + GetByteContext stream; } VBDecContext; static const uint16_t vb_patterns[64] = { @@ -62,8 +62,8 @@ static void vb_decode_palette(VBDecContext *c, int data_size) { int start, size, i; - start = bytestream_get_byte(&c->stream); - size = (bytestream_get_byte(&c->stream) - 1) & 0xFF; + start = bytestream2_get_byte(&c->stream); + size = (bytestream2_get_byte(&c->stream) - 1) & 0xFF; if(start + size > 255){ av_log(c->avctx, AV_LOG_ERROR, "Palette change runs beyond entry 256\n"); return; @@ -73,7 +73,7 @@ static void vb_decode_palette(VBDecContext *c, int data_size) return; } for(i = start; i <= start + size; i++) - c->pal[i] = 0xFF << 24 | bytestream_get_be24(&c->stream); + c->pal[i] = 0xFFU << 24 | bytestream2_get_be24(&c->stream); } static inline int check_pixel(uint8_t *buf, uint8_t *start, uint8_t *end) @@ -86,10 +86,10 @@ static inline int check_line(uint8_t *buf, uint8_t *start, uint8_t *end) return buf >= start && (buf + 4) <= end; } -static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int data_size, int offset) +static int vb_decode_framedata(VBDecContext *c, int offset) { + GetByteContext g; uint8_t *prev, *cur; - const uint8_t* data_end = buf + data_size; int blk, blocks, t, blk2; int blocktypes = 0; int x, y, a, b; @@ -98,6 +98,8 @@ static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int data_siz uint8_t *pstart = c->prev_frame; uint8_t *pend = c->prev_frame + width*c->avctx->height; + g = c->stream; + prev = c->prev_frame + offset; cur = c->frame; @@ -105,11 +107,7 @@ static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int data_siz blk2 = 0; for(blk = 0; blk < blocks; blk++){ if(!(blk & 3)) { - if(buf >= data_end){ - av_log(c->avctx, AV_LOG_ERROR, "Data pointer out of bounds\n"); - return -1; - } - blocktypes = bytestream_get_byte(&buf); + blocktypes = bytestream2_get_byte(&g); } switch(blocktypes & 0xC0){ case 0x00: //skip @@ -120,15 +118,14 @@ static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int data_siz memset(cur + y*width, 0, 4); break; case 0x40: - t = bytestream_get_byte(&buf); + t = bytestream2_get_byte(&g); if(!t){ //raw block - if(buf + 16 > data_end){ + if (bytestream2_get_bytes_left(&g) < 16) { av_log(c->avctx, AV_LOG_ERROR, "Insufficient data\n"); return -1; } for(y = 0; y < 4; y++) - memcpy(cur + y*width, buf + y*4, 4); - buf += 16; + bytestream2_get_buffer(&g, cur + y * width, 4); }else{ // motion compensation x = ((t & 0xF)^8) - 8; y = ((t >> 4) ^8) - 8; @@ -141,22 +138,18 @@ static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int data_siz } break; case 0x80: // fill - t = bytestream_get_byte(&buf); + t = bytestream2_get_byte(&g); for(y = 0; y < 4; y++) memset(cur + y*width, t, 4); break; case 0xC0: // pattern fill - if(buf + 2 > data_end){ - av_log(c->avctx, AV_LOG_ERROR, "Insufficient data\n"); - return -1; - } - t = bytestream_get_byte(&buf); + t = bytestream2_get_byte(&g); pattype = t >> 6; pattern = vb_patterns[t & 0x3F]; switch(pattype){ case 0: - a = bytestream_get_byte(&buf); - b = bytestream_get_byte(&buf); + a = bytestream2_get_byte(&g); + b = bytestream2_get_byte(&g); for(y = 0; y < 4; y++) for(x = 0; x < 4; x++, pattern >>= 1) cur[x + y*width] = (pattern & 1) ? b : a; @@ -164,7 +157,7 @@ static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int data_siz case 1: pattern = ~pattern; case 2: - a = bytestream_get_byte(&buf); + a = bytestream2_get_byte(&g); for(y = 0; y < 4; y++) for(x = 0; x < 4; x++, pattern >>= 1) if(pattern & 1 && check_pixel(prev + x + y*width, pstart, pend)) @@ -193,16 +186,15 @@ static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int data_siz static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; VBDecContext * const c = avctx->priv_data; uint8_t *outptr, *srcptr; int i, j; int flags; uint32_t size; - int rest = buf_size; int offset = 0; + bytestream2_init(&c->stream, avpkt->data, avpkt->size); + if(c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); c->pic.reference = 3; @@ -211,38 +203,25 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac return -1; } - c->stream = buf; - flags = bytestream_get_le16(&c->stream); - rest -= 2; + flags = bytestream2_get_le16(&c->stream); if(flags & VB_HAS_GMC){ - i = (int16_t)bytestream_get_le16(&c->stream); - j = (int16_t)bytestream_get_le16(&c->stream); + i = (int16_t)bytestream2_get_le16(&c->stream); + j = (int16_t)bytestream2_get_le16(&c->stream); offset = i + j * avctx->width; - rest -= 4; - } - if(rest < 0){ - av_log(avctx, AV_LOG_ERROR, "not enough data\n"); - return -1; } if(flags & VB_HAS_VIDEO){ - size = bytestream_get_le32(&c->stream); - if(size > rest || size<4){ + size = bytestream2_get_le32(&c->stream); + if(size > bytestream2_get_bytes_left(&c->stream)+4 || size<4){ av_log(avctx, AV_LOG_ERROR, "Frame size invalid\n"); return -1; } - vb_decode_framedata(c, c->stream, size, offset); - c->stream += size - 4; - rest -= size; + vb_decode_framedata(c, offset); + bytestream2_skip(&c->stream, size - 4); } if(flags & VB_HAS_PALETTE){ - size = bytestream_get_le32(&c->stream); - if(size > rest){ - av_log(avctx, AV_LOG_ERROR, "Palette size is too big\n"); - return -1; - } + size = bytestream2_get_le32(&c->stream); vb_decode_palette(c, size); - rest -= size; } memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE); @@ -263,7 +242,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac *(AVFrame*)data = c->pic; /* always report that the buffer was completely consumed */ - return buf_size; + return avpkt->size; } static av_cold int decode_init(AVCodecContext *avctx) diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c index 7d358238b2..9adfc968db 100644 --- a/libavcodec/wavpack.c +++ b/libavcodec/wavpack.c @@ -112,7 +112,8 @@ typedef struct WavpackFrameContext { int extra_bits; int and, or, shift; int post_shift; - int hybrid, hybrid_bitrate, hybrid_maxclip; + int hybrid, hybrid_bitrate; + int hybrid_maxclip, hybrid_minclip; int float_flag; int float_shift; int float_max_exp; @@ -412,12 +413,12 @@ static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, } bit = (S & s->and) | s->or; - bit = (((S + bit) << s->shift) - bit) << s->post_shift; + bit = ((S + bit) << s->shift) - bit; if (s->hybrid) - bit = av_clip(bit, -s->hybrid_maxclip - 1, s->hybrid_maxclip); + bit = av_clip(bit, s->hybrid_minclip, s->hybrid_maxclip); - return bit; + return bit << s->post_shift; } static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S) @@ -763,7 +764,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no, const uint8_t *orig_buf = buf; const uint8_t *buf_end = buf + buf_size; int i, j, id, size, ssize, weights, t; - int bpp, chan, chmask; + int bpp, chan, chmask, orig_bpp; if (buf_size == 0) { *got_frame_ptr = 0; @@ -799,15 +800,16 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no, s->frame_flags = AV_RL32(buf); buf += 4; bpp = av_get_bytes_per_sample(avctx->sample_fmt); samples = (uint8_t*)samples + bpp * wc->ch_offset; + orig_bpp = ((s->frame_flags & 0x03) + 1) << 3; s->stereo = !(s->frame_flags & WV_MONO); s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo; s->joint = s->frame_flags & WV_JOINT_STEREO; s->hybrid = s->frame_flags & WV_HYBRID_MODE; s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE; - s->hybrid_maxclip = (1LL << ((((s->frame_flags & 0x03) + 1) << 3) - 1)) - 1; - s->post_shift = 8 * (bpp - 1 - (s->frame_flags & 0x03)) + - ((s->frame_flags >> 13) & 0x1f); + s->post_shift = bpp * 8 - orig_bpp + ((s->frame_flags >> 13) & 0x1f); + s->hybrid_maxclip = (( 1LL << (orig_bpp - 1)) - 1) >> s->post_shift; + s->hybrid_minclip = ((-1LL << (orig_bpp - 1))) >> s->post_shift; s->CRC = AV_RL32(buf); buf += 4; if (wc->mkv_mode) buf += 4; //skip block size; @@ -968,6 +970,15 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no, s->and = 1; s->shift = buf[3]; } + /* original WavPack decoder forces 32-bit lossy sound to be treated + * as 24-bit one in order to have proper clipping + */ + if (s->hybrid && bpp == 4 && s->post_shift < 8 && s->shift > 8) { + s->post_shift += 8; + s->shift -= 8; + s->hybrid_maxclip >>= 8; + s->hybrid_minclip >>= 8; + } buf += 4; break; case WP_ID_FLOATINFO: diff --git a/libavformat/mov.c b/libavformat/mov.c index df30ed3523..bc58254dc4 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -243,7 +243,7 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (!key) return 0; if (atom.size < 0) - return -1; + return AVERROR_INVALIDDATA; str_size = FFMIN3(sizeof(str)-1, str_size, atom.size); @@ -382,7 +382,7 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom) avio_rb32(pb); // version + flags entries = avio_rb32(pb); if (entries >= UINT_MAX / sizeof(*sc->drefs)) - return -1; + return AVERROR_INVALIDDATA; sc->drefs = av_mallocz(entries * sizeof(*sc->drefs)); if (!sc->drefs) return AVERROR(ENOMEM); @@ -394,7 +394,7 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom) int64_t next = avio_tell(pb) + size - 4; if (size < 12) - return -1; + return AVERROR_INVALIDDATA; dref->type = avio_rl32(pb); avio_rb32(pb); // version + flags @@ -690,7 +690,7 @@ static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom) comp_brand_size = atom.size - 8; if (comp_brand_size < 0) - return -1; + return AVERROR_INVALIDDATA; comp_brands_str = av_malloc(comp_brand_size + 1); /* Add null terminator */ if (!comp_brands_str) return AVERROR(ENOMEM); @@ -705,8 +705,10 @@ static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom) /* this atom should contain all header atoms */ static int mov_read_moov(MOVContext *c, AVIOContext *pb, MOVAtom atom) { - if (mov_read_default(c, pb, atom) < 0) - return -1; + int ret; + + if ((ret = mov_read_default(c, pb, atom)) < 0) + return ret; /* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */ /* so we don't parse the whole file if over a network */ c->found_moov=1; @@ -748,9 +750,10 @@ static int mov_read_mdhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc = st->priv_data; version = avio_r8(pb); - if (version > 1) - return -1; /* unsupported */ - + if (version > 1) { + av_log_ask_for_sample(c, "unsupported version %d\n", version); + return AVERROR_PATCHWELCOME; + } avio_rb24(pb); /* flags */ if (version == 1) { creation_time = avio_rb64(pb); @@ -820,7 +823,7 @@ static int mov_read_smi(MOVContext *c, AVIOContext *pb, MOVAtom atom) st = c->fc->streams[c->fc->nb_streams-1]; if ((uint64_t)atom.size > (1<<30)) - return -1; + return AVERROR_INVALIDDATA; // currently SVQ3 decoder expect full STSD header - so let's fake it // this should be fixed and just SMI header should be passed @@ -918,10 +921,10 @@ static int mov_read_extradata(MOVContext *c, AVIOContext *pb, MOVAtom atom, size= (uint64_t)st->codec->extradata_size + atom.size + 8 + FF_INPUT_BUFFER_PADDING_SIZE; if (size > INT_MAX || (uint64_t)atom.size > INT_MAX) - return -1; + return AVERROR_INVALIDDATA; buf= av_realloc(st->codec->extradata, size); if (!buf) - return -1; + return AVERROR(ENOMEM); st->codec->extradata= buf; buf+= st->codec->extradata_size; st->codec->extradata_size= size - FF_INPUT_BUFFER_PADDING_SIZE; @@ -956,7 +959,7 @@ static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom) st = c->fc->streams[c->fc->nb_streams-1]; if ((uint64_t)atom.size > (1<<30)) - return -1; + return AVERROR_INVALIDDATA; if (st->codec->codec_id == CODEC_ID_QDM2 || st->codec->codec_id == CODEC_ID_QDMC) { // pass all frma atom to codec, needed at least for QDMC and QDM2 @@ -967,8 +970,9 @@ static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom) st->codec->extradata_size = atom.size; avio_read(pb, st->codec->extradata, atom.size); } else if (atom.size > 8) { /* to read frma, esds atoms */ - if (mov_read_default(c, pb, atom) < 0) - return -1; + int ret; + if ((ret = mov_read_default(c, pb, atom)) < 0) + return ret; } else avio_skip(pb, atom.size); return 0; @@ -987,7 +991,7 @@ static int mov_read_glbl(MOVContext *c, AVIOContext *pb, MOVAtom atom) st = c->fc->streams[c->fc->nb_streams-1]; if ((uint64_t)atom.size > (1<<30)) - return -1; + return AVERROR_INVALIDDATA; if (atom.size >= 10) { // Broken files created by legacy versions of Libav and FFmpeg will @@ -1023,7 +1027,7 @@ static int mov_read_strf(MOVContext *c, AVIOContext *pb, MOVAtom atom) st = c->fc->streams[c->fc->nb_streams-1]; if ((uint64_t)atom.size > (1<<30)) - return -1; + return AVERROR_INVALIDDATA; av_free(st->codec->extradata); st->codec->extradata = av_mallocz(atom.size - 40 + FF_INPUT_BUFFER_PADDING_SIZE); @@ -1054,7 +1058,7 @@ static int mov_read_stco(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (!entries) return 0; if (entries >= UINT_MAX/sizeof(int64_t)) - return -1; + return AVERROR_INVALIDDATA; sc->chunk_offsets = av_malloc(entries * sizeof(int64_t)); if (!sc->chunk_offsets) @@ -1068,7 +1072,7 @@ static int mov_read_stco(MOVContext *c, AVIOContext *pb, MOVAtom atom) for (i=0; i<entries; i++) sc->chunk_offsets[i] = avio_rb64(pb); else - return -1; + return AVERROR_INVALIDDATA; return 0; } @@ -1393,8 +1397,9 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) /* this will read extra atoms at the end (wave, alac, damr, avcC, SMI ...) */ a.size = size - (avio_tell(pb) - start_pos); if (a.size > 8) { - if (mov_read_default(c, pb, a) < 0) - return -1; + int ret; + if ((ret = mov_read_default(c, pb, a)) < 0) + return ret; } else if (a.size > 0) avio_skip(pb, a.size); } @@ -1410,7 +1415,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) c->dv_demux = avpriv_dv_init_demux(c->dv_fctx); if (!c->dv_demux) { av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n"); - return -1; + return AVERROR(ENOMEM); } sc->dv_audio_container = 1; st->codec->codec_id = CODEC_ID_PCM_S16LE; @@ -1499,7 +1504,7 @@ static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (!entries) return 0; if (entries >= UINT_MAX / sizeof(*sc->stsc_data)) - return -1; + return AVERROR_INVALIDDATA; sc->stsc_data = av_malloc(entries * sizeof(*sc->stsc_data)); if (!sc->stsc_data) return AVERROR(ENOMEM); @@ -1528,7 +1533,7 @@ static int mov_read_stps(MOVContext *c, AVIOContext *pb, MOVAtom atom) entries = avio_rb32(pb); if (entries >= UINT_MAX / sizeof(*sc->stps_data)) - return -1; + return AVERROR_INVALIDDATA; sc->stps_data = av_malloc(entries * sizeof(*sc->stps_data)); if (!sc->stps_data) return AVERROR(ENOMEM); @@ -1561,7 +1566,7 @@ static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_dlog(c->fc, "keyframe_count = %d\n", entries); if (entries >= UINT_MAX / sizeof(int)) - return -1; + return AVERROR_INVALIDDATA; sc->keyframes = av_malloc(entries * sizeof(int)); if (!sc->keyframes) return AVERROR(ENOMEM); @@ -1610,13 +1615,13 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) { av_log(c->fc, AV_LOG_ERROR, "Invalid sample field size %d\n", field_size); - return -1; + return AVERROR_INVALIDDATA; } if (!entries) return 0; if (entries >= UINT_MAX / sizeof(int) || entries >= (UINT_MAX - 4) / field_size) - return -1; + return AVERROR_INVALIDDATA; sc->sample_sizes = av_malloc(entries * sizeof(int)); if (!sc->sample_sizes) return AVERROR(ENOMEM); @@ -1632,7 +1637,7 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (avio_read(pb, buf, num_bytes) < num_bytes) { av_freep(&sc->sample_sizes); av_free(buf); - return -1; + return AVERROR_INVALIDDATA; } init_get_bits(&gb, buf, 8*num_bytes); @@ -1720,7 +1725,7 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (!entries) return 0; if (entries >= UINT_MAX / sizeof(*sc->ctts_data)) - return -1; + return AVERROR_INVALIDDATA; sc->ctts_data = av_malloc(entries * sizeof(*sc->ctts_data)); if (!sc->ctts_data) return AVERROR(ENOMEM); @@ -2190,7 +2195,7 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) track_id = avio_rb32(pb); if (!track_id) - return -1; + return AVERROR_INVALIDDATA; frag->track_id = track_id; for (i = 0; i < c->trex_count; i++) if (c->trex_data[i].track_id == frag->track_id) { @@ -2199,7 +2204,7 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) } if (!trex) { av_log(c->fc, AV_LOG_ERROR, "could not find corresponding trex\n"); - return -1; + return AVERROR_INVALIDDATA; } if (flags & 0x01) frag->base_data_offset = avio_rb64(pb); @@ -2225,7 +2230,7 @@ static int mov_read_trex(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVTrackExt *trex; if ((uint64_t)c->trex_count+1 >= UINT_MAX / sizeof(*c->trex_data)) - return -1; + return AVERROR_INVALIDDATA; trex = av_realloc(c->trex_data, (c->trex_count+1)*sizeof(*c->trex_data)); if (!trex) return AVERROR(ENOMEM); @@ -2261,7 +2266,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) } if (!st) { av_log(c->fc, AV_LOG_ERROR, "could not find corresponding track id %d\n", frag->track_id); - return -1; + return AVERROR_INVALIDDATA; } sc = st->priv_data; if (sc->pseudo_stream_id+1 != frag->stsd_id) @@ -2288,7 +2293,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->ctts_count++; } if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data)) - return -1; + return AVERROR_INVALIDDATA; ctts_data = av_realloc(sc->ctts_data, (entries+sc->ctts_count)*sizeof(*sc->ctts_data)); if (!ctts_data) @@ -2364,14 +2369,14 @@ static int mov_read_cmov(MOVContext *c, AVIOContext *pb, MOVAtom atom) avio_rb32(pb); /* dcom atom */ if (avio_rl32(pb) != MKTAG('d','c','o','m')) - return -1; + return AVERROR_INVALIDDATA; if (avio_rl32(pb) != MKTAG('z','l','i','b')) { av_log(c->fc, AV_LOG_ERROR, "unknown compression for cmov atom !"); - return -1; + return AVERROR_INVALIDDATA; } avio_rb32(pb); /* cmvd atom */ if (avio_rl32(pb) != MKTAG('c','m','v','d')) - return -1; + return AVERROR_INVALIDDATA; moov_len = avio_rb32(pb); /* uncompressed size */ cmov_len = atom.size - 6 * 4; @@ -2397,7 +2402,7 @@ free_and_return: return ret; #else av_log(c->fc, AV_LOG_ERROR, "this file requires zlib support compiled in\n"); - return -1; + return AVERROR(ENOSYS); #endif } @@ -2416,7 +2421,7 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom) edit_count = avio_rb32(pb); /* entries */ if ((uint64_t)edit_count*12+8 > atom.size) - return -1; + return AVERROR_INVALIDDATA; for (i=0; i<edit_count; i++){ int64_t time; @@ -2686,7 +2691,7 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) } if (!mov->found_moov) { av_log(s, AV_LOG_ERROR, "moov atom not found\n"); - return -1; + return AVERROR_INVALIDDATA; } av_dlog(mov->fc, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb)); @@ -2754,7 +2759,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n", sc->ffindex, sample->pos); - return -1; + return AVERROR_INVALIDDATA; } ret = av_get_packet(sc->pb, pkt, sample->size); if (ret < 0) @@ -2821,7 +2826,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp) sample = 0; if (sample < 0) /* not sure what to do */ - return -1; + return AVERROR_INVALIDDATA; sc->current_sample = sample; av_dlog(s, "stream %d, found sample %d\n", st->index, sc->current_sample); /* adjust ctts index */ @@ -2848,14 +2853,14 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti int i; if (stream_index >= s->nb_streams) - return -1; + return AVERROR_INVALIDDATA; if (sample_time < 0) sample_time = 0; st = s->streams[stream_index]; sample = mov_seek_stream(s, st, sample_time, flags); if (sample < 0) - return -1; + return sample; /* adjust seek timestamp to found sample timestamp */ seek_timestamp = st->index_entries[sample].timestamp; diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 10512efce3..216273701e 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -245,7 +245,7 @@ static int64_t klv_decode_ber_length(AVIOContext *pb) int bytes_num = size & 0x7f; /* SMPTE 379M 5.3.4 guarantee that bytes_num must not exceed 8 bytes */ if (bytes_num > 8) - return -1; + return AVERROR_INVALIDDATA; size = 0; while (bytes_num--) size = size << 8 | avio_r8(pb); @@ -269,7 +269,7 @@ static int mxf_read_sync(AVIOContext *pb, const uint8_t *key, unsigned size) static int klv_read_packet(KLVPacket *klv, AVIOContext *pb) { if (!mxf_read_sync(pb, mxf_klv_key, 4)) - return -1; + return AVERROR_INVALIDDATA; klv->offset = avio_tell(pb) - 4; memcpy(klv->key, mxf_klv_key, 4); avio_read(pb, klv->key + 4, 12); @@ -299,7 +299,7 @@ static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket *pkt, int i; if (length > 61444) /* worst case PAL 1920 samples 8 channels */ - return -1; + return AVERROR_INVALIDDATA; length = av_get_packet(pb, pkt, length); if (length < 0) return length; @@ -336,7 +336,7 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv if (!mxf->aesc && s->key && s->keylen == 16) { mxf->aesc = av_malloc(av_aes_size); if (!mxf->aesc) - return -1; + return AVERROR(ENOMEM); av_aes_init(mxf->aesc, s->key, 128, 1); } // crypto context @@ -348,19 +348,19 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv klv_decode_ber_length(pb); avio_read(pb, klv->key, 16); if (!IS_KLV_KEY(klv, mxf_essence_element_key)) - return -1; + return AVERROR_INVALIDDATA; index = mxf_get_stream_index(s, klv); if (index < 0) - return -1; + return AVERROR_INVALIDDATA; // source size klv_decode_ber_length(pb); orig_size = avio_rb64(pb); if (orig_size < plaintext_size) - return -1; + return AVERROR_INVALIDDATA; // enc. code size = klv_decode_ber_length(pb); if (size < 32 || size - 32 < orig_size) - return -1; + return AVERROR_INVALIDDATA; avio_read(pb, ivec, 16); avio_read(pb, tmpbuf, 16); if (mxf->aesc) @@ -390,15 +390,16 @@ static int mxf_read_primer_pack(void *arg, AVIOContext *pb, int tag, int size, U int item_len = avio_rb32(pb); if (item_len != 18) { - av_log(mxf->fc, AV_LOG_ERROR, "unsupported primer pack item length\n"); - return -1; + av_log_ask_for_sample(pb, "unsupported primer pack item length %d\n", + item_len); + return AVERROR_PATCHWELCOME; } if (item_num > UINT_MAX / item_len) - return -1; + return AVERROR_INVALIDDATA; mxf->local_tags_count = item_num; mxf->local_tags = av_malloc(item_num*item_len); if (!mxf->local_tags) - return -1; + return AVERROR(ENOMEM); avio_read(pb, mxf->local_tags, item_num*item_len); return 0; } @@ -522,7 +523,7 @@ static int mxf_add_metadata_set(MXFContext *mxf, void *metadata_set) return AVERROR(ENOMEM); mxf->metadata_sets = av_realloc(mxf->metadata_sets, (mxf->metadata_sets_count + 1) * sizeof(*mxf->metadata_sets)); if (!mxf->metadata_sets) - return -1; + return AVERROR(ENOMEM); mxf->metadata_sets[mxf->metadata_sets_count] = metadata_set; mxf->metadata_sets_count++; return 0; @@ -532,7 +533,7 @@ static int mxf_read_cryptographic_context(void *arg, AVIOContext *pb, int tag, i { MXFCryptoContext *cryptocontext = arg; if (size != 16) - return -1; + return AVERROR_INVALIDDATA; if (IS_KLV_KEY(uid, mxf_crypto_source_container_ul)) avio_read(pb, cryptocontext->source_container_ul, 16); return 0; @@ -545,10 +546,10 @@ static int mxf_read_content_storage(void *arg, AVIOContext *pb, int tag, int siz case 0x1901: mxf->packages_count = avio_rb32(pb); if (mxf->packages_count >= UINT_MAX / sizeof(UID)) - return -1; + return AVERROR_INVALIDDATA; mxf->packages_refs = av_malloc(mxf->packages_count * sizeof(UID)); if (!mxf->packages_refs) - return -1; + return AVERROR(ENOMEM); avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ avio_read(pb, (uint8_t *)mxf->packages_refs, mxf->packages_count * sizeof(UID)); break; @@ -585,10 +586,10 @@ static int mxf_read_material_package(void *arg, AVIOContext *pb, int tag, int si case 0x4403: package->tracks_count = avio_rb32(pb); if (package->tracks_count >= UINT_MAX / sizeof(UID)) - return -1; + return AVERROR_INVALIDDATA; package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID)); if (!package->tracks_refs) - return -1; + return AVERROR(ENOMEM); avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID)); break; @@ -630,10 +631,10 @@ static int mxf_read_sequence(void *arg, AVIOContext *pb, int tag, int size, UID case 0x1001: sequence->structural_components_count = avio_rb32(pb); if (sequence->structural_components_count >= UINT_MAX / sizeof(UID)) - return -1; + return AVERROR_INVALIDDATA; sequence->structural_components_refs = av_malloc(sequence->structural_components_count * sizeof(UID)); if (!sequence->structural_components_refs) - return -1; + return AVERROR(ENOMEM); avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ avio_read(pb, (uint8_t *)sequence->structural_components_refs, sequence->structural_components_count * sizeof(UID)); break; @@ -648,10 +649,10 @@ static int mxf_read_source_package(void *arg, AVIOContext *pb, int tag, int size case 0x4403: package->tracks_count = avio_rb32(pb); if (package->tracks_count >= UINT_MAX / sizeof(UID)) - return -1; + return AVERROR_INVALIDDATA; package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID)); if (!package->tracks_refs) - return -1; + return AVERROR(ENOMEM); avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID)); break; @@ -752,10 +753,10 @@ static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int case 0x3F01: descriptor->sub_descriptors_count = avio_rb32(pb); if (descriptor->sub_descriptors_count >= UINT_MAX / sizeof(UID)) - return -1; + return AVERROR_INVALIDDATA; descriptor->sub_descriptors_refs = av_malloc(descriptor->sub_descriptors_count * sizeof(UID)); if (!descriptor->sub_descriptors_refs) - return -1; + return AVERROR(ENOMEM); avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ avio_read(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID)); break; @@ -799,7 +800,7 @@ static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int if (IS_KLV_KEY(uid, mxf_sony_mpeg4_extradata)) { descriptor->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); if (!descriptor->extradata) - return -1; + return AVERROR(ENOMEM); descriptor->extradata_size = size; avio_read(pb, descriptor->extradata, size); } @@ -1224,7 +1225,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } if (!material_package) { av_log(mxf->fc, AV_LOG_ERROR, "no material package found\n"); - return -1; + return AVERROR_INVALIDDATA; } for (i = 0; i < material_package->tracks_count; i++) { @@ -1272,7 +1273,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) for (k = 0; k < source_package->tracks_count; k++) { if (!(temp_track = mxf_resolve_strong_ref(mxf, &source_package->tracks_refs[k], Track))) { av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track strong ref\n"); - ret = -1; + ret = AVERROR_INVALIDDATA; goto fail_and_free; } if (temp_track->track_id == component->source_track_id) { @@ -1445,8 +1446,9 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF uint64_t klv_end = avio_tell(pb) + klv->length; if (!ctx) - return -1; + return AVERROR(ENOMEM); while (avio_tell(pb) + 4 < klv_end && !url_feof(pb)) { + int ret; int tag = avio_rb16(pb); int size = avio_rb16(pb); /* KLV specified by 0x53 */ uint64_t next = avio_tell(pb) + size; @@ -1470,8 +1472,8 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF } if (ctx_size && tag == 0x3C0A) avio_read(pb, ctx->uid, 16); - else if (read_child(ctx, pb, tag, size, uid, -1) < 0) - return -1; + else if ((ret = read_child(ctx, pb, tag, size, uid, -1)) < 0) + return ret; /* accept the 64k local set limit being exceeded (Avid) * don't accept it extending past the end of the KLV though (zzuf5.mxf) */ @@ -1608,7 +1610,7 @@ static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap) if (!mxf_read_sync(s->pb, mxf_header_partition_pack_key, 14)) { av_log(s, AV_LOG_ERROR, "could not find header partition pack key\n"); - return -1; + return AVERROR_INVALIDDATA; } avio_seek(s->pb, -14, SEEK_CUR); mxf->fc = s; @@ -1695,7 +1697,7 @@ static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap) } if (res < 0) { av_log(s, AV_LOG_ERROR, "error reading header metadata\n"); - return -1; + return res; } break; } @@ -1775,15 +1777,16 @@ static int mxf_read_packet_old(AVFormatContext *s, AVPacket *pkt) KLVPacket klv; while (!url_feof(s->pb)) { + int ret; if (klv_read_packet(&klv, s->pb) < 0) return -1; PRINT_KEY(s, "read packet", klv.key); av_dlog(s, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset); if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) { - int res = mxf_decrypt_triplet(s, pkt, &klv); - if (res < 0) { + ret = mxf_decrypt_triplet(s, pkt, &klv); + if (ret < 0) { av_log(s, AV_LOG_ERROR, "invalid encoded triplet\n"); - return -1; + return AVERROR_INVALIDDATA; } return 0; } @@ -1800,10 +1803,10 @@ static int mxf_read_packet_old(AVFormatContext *s, AVPacket *pkt) if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 0x10) { if (mxf_get_d10_aes3_packet(s->pb, s->streams[index], pkt, klv.length) < 0) { av_log(s, AV_LOG_ERROR, "error reading D-10 aes3 frame\n"); - return -1; + return AVERROR_INVALIDDATA; } } else { - int ret = av_get_packet(s->pb, pkt, klv.length); + ret = av_get_packet(s->pb, pkt, klv.length); if (ret < 0) return ret; } @@ -1951,7 +1954,7 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti if (mxf->index_tables <= 0) { if (!s->bit_rate) - return -1; + return AVERROR_INVALIDDATA; if (sample_time < 0) sample_time = 0; seconds = av_rescale(sample_time, st->time_base.num, st->time_base.den); diff --git a/tests/Makefile b/tests/Makefile index 51ff9182b7..6ee408ab14 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -42,6 +42,7 @@ tests/data/asynth%.sw tests/vsynth%/00.pgm: TAG = GEN include $(SRC_PATH)/tests/fate/aac.mak include $(SRC_PATH)/tests/fate/ac3.mak +include $(SRC_PATH)/tests/fate/adpcm.mak include $(SRC_PATH)/tests/fate/als.mak include $(SRC_PATH)/tests/fate/amrnb.mak include $(SRC_PATH)/tests/fate/amrwb.mak diff --git a/tests/fate/adpcm.mak b/tests/fate/adpcm.mak new file mode 100644 index 0000000000..2a12d57369 --- /dev/null +++ b/tests/fate/adpcm.mak @@ -0,0 +1,35 @@ +FATE_TESTS += fate-adpcm-ea-r2 +fate-adpcm-ea-r2: CMD = crc -i $(SAMPLES)/ea-mpc/THX_logo.mpc -vn + +FATE_TESTS += fate-adpcm-ea-r3 +fate-adpcm-ea-r3: CMD = crc -i $(SAMPLES)/ea-vp6/THX_logo.vp6 -vn + +FATE_TESTS += fate-creative-adpcm +fate-creative-adpcm: CMD = md5 -i $(SAMPLES)/creative/intro-partial.wav -f s16le + +FATE_TESTS += fate-creative-adpcm-8-2bit +fate-creative-adpcm-8-2bit: CMD = md5 -i $(SAMPLES)/creative/BBC_2BIT.VOC -f s16le + +FATE_TESTS += fate-creative-adpcm-8-2.6bit +fate-creative-adpcm-8-2.6bit: CMD = md5 -i $(SAMPLES)/creative/BBC_3BIT.VOC -f s16le + +FATE_TESTS += fate-creative-adpcm-8-4bit +fate-creative-adpcm-8-4bit: CMD = md5 -i $(SAMPLES)/creative/BBC_4BIT.VOC -f s16le + +FATE_TESTS += fate-ea-mad-adpcm-ea-r1 +fate-ea-mad-adpcm-ea-r1: CMD = framecrc -i $(SAMPLES)/ea-mad/NFS6LogoE.mad + +FATE_TESTS += fate-ea-tqi-adpcm +fate-ea-tqi-adpcm: CMD = framecrc -i $(SAMPLES)/ea-wve/networkBackbone-partial.wve -frames:v 26 + +FATE_TESTS += fate-psx-str-v3-adpcm_xa +fate-psx-str-v3-adpcm_xa: CMD = framecrc -i $(SAMPLES)/psx-str/abc000_cut.str -vn + +FATE_TESTS += fate-qt-msadpcm-stereo +fate-qt-msadpcm-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-L-ms02.mov -f s16le + +FATE_TESTS += fate-qt-msimaadpcm-stereo +fate-qt-msimaadpcm-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-L-ms11.mov -f s16le + +FATE_TESTS += fate-thp-mjpeg-adpcm +fate-thp-mjpeg-adpcm: CMD = framecrc -idct simple -i $(SAMPLES)/thp/pikmin2-opening1-partial.thp diff --git a/tests/fate/dpcm.mak b/tests/fate/dpcm.mak index 119bdadc82..ad921fd0f7 100644 --- a/tests/fate/dpcm.mak +++ b/tests/fate/dpcm.mak @@ -1,42 +1,6 @@ -FATE_DPCM += fate-adpcm-ea-r2 -fate-adpcm-ea-r2: CMD = crc -i $(SAMPLES)/ea-mpc/THX_logo.mpc -vn - -FATE_DPCM += fate-adpcm-ea-r3 -fate-adpcm-ea-r3: CMD = crc -i $(SAMPLES)/ea-vp6/THX_logo.vp6 -vn - -FATE_DPCM += fate-creative-adpcm -fate-creative-adpcm: CMD = md5 -i $(SAMPLES)/creative/intro-partial.wav -f s16le - -FATE_DPCM += fate-creative-adpcm-8-2bit -fate-creative-adpcm-8-2bit: CMD = md5 -i $(SAMPLES)/creative/BBC_2BIT.VOC -f s16le - -FATE_DPCM += fate-creative-adpcm-8-2.6bit -fate-creative-adpcm-8-2.6bit: CMD = md5 -i $(SAMPLES)/creative/BBC_3BIT.VOC -f s16le - -FATE_DPCM += fate-creative-adpcm-8-4bit -fate-creative-adpcm-8-4bit: CMD = md5 -i $(SAMPLES)/creative/BBC_4BIT.VOC -f s16le - -FATE_DPCM += fate-ea-mad-adpcm-ea-r1 -fate-ea-mad-adpcm-ea-r1: CMD = framecrc -i $(SAMPLES)/ea-mad/NFS6LogoE.mad - -FATE_DPCM += fate-ea-tqi-adpcm -fate-ea-tqi-adpcm: CMD = framecrc -i $(SAMPLES)/ea-wve/networkBackbone-partial.wve -frames:v 26 - FATE_DPCM += fate-idroq-video-dpcm fate-idroq-video-dpcm: CMD = framecrc -i $(SAMPLES)/idroq/idlogo.roq -FATE_DPCM += fate-psx-str-v3-adpcm_xa -fate-psx-str-v3-adpcm_xa: CMD = framecrc -i $(SAMPLES)/psx-str/abc000_cut.str -vn - -FATE_DPCM += fate-qt-msadpcm-stereo -fate-qt-msadpcm-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-L-ms02.mov -f s16le - -FATE_DPCM += fate-qt-msimaadpcm-stereo -fate-qt-msimaadpcm-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-L-ms11.mov -f s16le - -FATE_DPCM += fate-thp-mjpeg-adpcm -fate-thp-mjpeg-adpcm: CMD = framecrc -idct simple -i $(SAMPLES)/thp/pikmin2-opening1-partial.thp - FATE_DPCM += fate-dpcm-xan fate-dpcm-xan: CMD = md5 -i $(SAMPLES)/wc4-xan/wc4_2.avi -vn -f s16le |