From 87818103a0d8e5021b950ea5906031a20d0d193b Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Wed, 21 Mar 2012 19:10:43 +0100 Subject: [PATCH 1/8] wmall: output packet only if we have decoded some samples Also set CODEC_CAP_DELAY to indicate that decoder may still have some undecoded data left in internal buffer. --- libavcodec/wmalosslessdec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c index 6bd8bfbc0a..795642e271 100644 --- a/libavcodec/wmalosslessdec.c +++ b/libavcodec/wmalosslessdec.c @@ -1229,7 +1229,7 @@ static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr, } *(AVFrame *)data = s->frame; - *got_frame_ptr = 1; + *got_frame_ptr = s->frame.nb_samples > 0; s->packet_offset = get_bits_count(gb) & 7; return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3; @@ -1243,6 +1243,6 @@ AVCodec ff_wmalossless_decoder = { .priv_data_size = sizeof(WmallDecodeCtx), .init = decode_init, .decode = decode_packet, - .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1, + .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1 | CODEC_CAP_DELAY, .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Lossless"), }; From 02f88eec1d9069ab6bb6c4177471226186647a8f Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 21 Mar 2012 14:30:33 -0400 Subject: [PATCH 2/8] aiffdec: do not set bit rate if block duration is unknown CC: libav-stable@libav.org --- libavformat/aiffdec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c index 11bbcac775..bbac1ab30e 100644 --- a/libavformat/aiffdec.c +++ b/libavformat/aiffdec.c @@ -157,8 +157,10 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size, if (!codec->block_align) codec->block_align = (codec->bits_per_coded_sample * codec->channels) >> 3; - codec->bit_rate = codec->sample_rate * (codec->block_align << 3) / - aiff->block_duration; + if (aiff->block_duration) { + codec->bit_rate = codec->sample_rate * (codec->block_align << 3) / + aiff->block_duration; + } /* Chunk is over */ if (size) From 2c07c1804831fa0ae6d494a63fdd10facfd6074b Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 21 Mar 2012 14:36:33 -0400 Subject: [PATCH 3/8] aiffdec: use av_get_audio_frame_duration() to set block_duration for AIFF-C --- libavformat/aiffdec.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c index bbac1ab30e..a48d946880 100644 --- a/libavformat/aiffdec.c +++ b/libavformat/aiffdec.c @@ -123,28 +123,27 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size, break; case CODEC_ID_ADPCM_IMA_QT: codec->block_align = 34*codec->channels; - aiff->block_duration = 64; break; case CODEC_ID_MACE3: codec->block_align = 2*codec->channels; - aiff->block_duration = 6; break; case CODEC_ID_MACE6: codec->block_align = 1*codec->channels; - aiff->block_duration = 6; break; case CODEC_ID_GSM: codec->block_align = 33; - aiff->block_duration = 160; break; case CODEC_ID_QCELP: codec->block_align = 35; - aiff->block_duration = 160; break; default: break; } size -= 4; + + if (codec->block_align > 0) + aiff->block_duration = av_get_audio_frame_duration(codec, + codec->block_align); } else { /* Need the codec type */ codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample); From b38b7cc39232b545086f69583967e696fee44ab8 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 21 Mar 2012 14:48:35 -0400 Subject: [PATCH 4/8] aiffdec: factor out handling of integer PCM for AIFF-C and plain AIFF --- libavformat/aiffdec.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c index a48d946880..70ce017488 100644 --- a/libavformat/aiffdec.c +++ b/libavformat/aiffdec.c @@ -110,17 +110,19 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size, codec->sample_rate = sample_rate; size -= 18; - /* Got an AIFF-C? */ + /* get codec id for AIFF-C */ if (version == AIFF_C_VERSION1) { codec->codec_tag = avio_rl32(pb); codec->codec_id = ff_codec_get_id(ff_codec_aiff_tags, codec->codec_tag); + size -= 4; + } + if (version != AIFF_C_VERSION1 || codec->codec_id == CODEC_ID_PCM_S16BE) { + codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample); + codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id); + aiff->block_duration = 1; + } else { switch (codec->codec_id) { - case CODEC_ID_PCM_S16BE: - codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample); - codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id); - aiff->block_duration = 1; - break; case CODEC_ID_ADPCM_IMA_QT: codec->block_align = 34*codec->channels; break; @@ -139,16 +141,9 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size, default: break; } - size -= 4; - if (codec->block_align > 0) aiff->block_duration = av_get_audio_frame_duration(codec, codec->block_align); - } else { - /* Need the codec type */ - codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample); - codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id); - aiff->block_duration = 1; } /* Block align needs to be computed in all cases, as the definition From f036342b4b24458432be20d4faa45a065c94fb69 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 21 Mar 2012 14:51:50 -0400 Subject: [PATCH 5/8] aiffdec: set block_duration to 1 for PCM codecs that are supported in AIFF-C --- libavformat/aiffdec.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c index 70ce017488..27d42ea4d0 100644 --- a/libavformat/aiffdec.c +++ b/libavformat/aiffdec.c @@ -123,6 +123,13 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size, aiff->block_duration = 1; } else { switch (codec->codec_id) { + case CODEC_ID_PCM_F32BE: + case CODEC_ID_PCM_F64BE: + case CODEC_ID_PCM_S16LE: + case CODEC_ID_PCM_ALAW: + case CODEC_ID_PCM_MULAW: + aiff->block_duration = 1; + break; case CODEC_ID_ADPCM_IMA_QT: codec->block_align = 34*codec->channels; break; From 677df4d2ef2ccdf005e4c36d1a26a1afeb3e88fe Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 21 Mar 2012 09:48:26 +0100 Subject: [PATCH 6/8] pngenc: better upper bound for encoded frame size. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes encoding very large pictures. Thanks to Костя for providing the formula. --- libavcodec/pngenc.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index bf7dd1a14b..d79c800867 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -235,7 +235,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, PNGEncContext *s = avctx->priv_data; AVFrame * const p= &s->picture; int bit_depth, color_type, y, len, row_size, ret, is_progressive; - int bits_per_pixel, pass_row_size, max_packet_size; + int bits_per_pixel, pass_row_size, enc_row_size, max_packet_size; int compression_level; uint8_t *ptr, *top; uint8_t *crow_base = NULL, *crow_buf, *crow; @@ -247,18 +247,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, p->pict_type= AV_PICTURE_TYPE_I; p->key_frame= 1; - max_packet_size = IOBUF_SIZE*avctx->height + FF_MIN_BUFFER_SIZE; - if (!pkt->data && - (ret = av_new_packet(pkt, max_packet_size)) < 0) { - av_log(avctx, AV_LOG_ERROR, "Could not allocate output packet of size %d.\n", - max_packet_size); - return ret; - } - - s->bytestream_start = - s->bytestream = pkt->data; - s->bytestream_end = pkt->data + pkt->size; - is_progressive = !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT); switch(avctx->pix_fmt) { case PIX_FMT_RGB32: @@ -297,6 +285,22 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY); if (ret != Z_OK) return -1; + + enc_row_size = deflateBound(&s->zstream, row_size); + max_packet_size = avctx->height * (enc_row_size + + ((enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) * 12) + + FF_MIN_BUFFER_SIZE; + if (!pkt->data && + (ret = av_new_packet(pkt, max_packet_size)) < 0) { + av_log(avctx, AV_LOG_ERROR, "Could not allocate output packet of size %d.\n", + max_packet_size); + return ret; + } + + s->bytestream_start = + s->bytestream = pkt->data; + s->bytestream_end = pkt->data + pkt->size; + crow_base = av_malloc((row_size + 32) << (s->filter_type == PNG_FILTER_VALUE_MIXED)); if (!crow_base) goto fail; From f0b4a505d8132d7e62cfec7b0a14c7594ec9c9f6 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 8 Mar 2012 21:11:37 +0100 Subject: [PATCH 7/8] oggparseogm: fix order of arguments of avpriv_set_pts_info(). Signed-off-by: Anton Khirnov --- libavformat/oggparseogm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c index f16eb13039..d7fc426e6c 100644 --- a/libavformat/oggparseogm.c +++ b/libavformat/oggparseogm.c @@ -80,7 +80,7 @@ ogm_header(AVFormatContext *s, int idx) if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){ st->codec->width = bytestream_get_le32(&p); st->codec->height = bytestream_get_le32(&p); - avpriv_set_pts_info(st, 64, spu * 10000000, time_unit); + avpriv_set_pts_info(st, 64, time_unit, spu * 10000000); } else { st->codec->channels = bytestream_get_le16(&p); p += 2; /* block_align */ From e9c0b12c2e6dd81d047669178719f68f18741f9c Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Mon, 19 Mar 2012 18:23:42 -0400 Subject: [PATCH 8/8] FATE: Add ZeroCodec test Signed-off-by: Derek Buitenhuis Signed-off-by: Anton Khirnov --- tests/fate/lossless-video.mak | 3 +++ tests/ref/fate/zerocodec | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 tests/ref/fate/zerocodec diff --git a/tests/fate/lossless-video.mak b/tests/fate/lossless-video.mak index d87abc522a..e0f097e6ab 100644 --- a/tests/fate/lossless-video.mak +++ b/tests/fate/lossless-video.mak @@ -18,3 +18,6 @@ fate-vble: CMD = framecrc -i $(SAMPLES)/vble/flowers-partial-2MB.avi FATE_TESTS += fate-zlib fate-zlib: CMD = framecrc -i $(SAMPLES)/lcl/zlib-1frame.avi + +FATE_TESTS += fate-zerocodec +fate-zerocodec: CMD = framecrc -i $(SAMPLES)/zerocodec/sample-zeco.avi diff --git a/tests/ref/fate/zerocodec b/tests/ref/fate/zerocodec new file mode 100644 index 0000000000..4d358ca8a8 --- /dev/null +++ b/tests/ref/fate/zerocodec @@ -0,0 +1,39 @@ +#tb 0: 417083/10000000 +0, 0, 0, 1, 1843200, 0x09f24bd5 +0, 1, 1, 1, 1843200, 0x8c932d04 +0, 2, 2, 1, 1843200, 0xe04904a0 +0, 3, 3, 1, 1843200, 0x1969f383 +0, 4, 4, 1, 1843200, 0x70781331 +0, 5, 5, 1, 1843200, 0xf494496b +0, 6, 6, 1, 1843200, 0xf6226da2 +0, 7, 7, 1, 1843200, 0x5d657925 +0, 8, 8, 1, 1843200, 0xde15820d +0, 9, 9, 1, 1843200, 0xb6768df1 +0, 10, 10, 1, 1843200, 0xc4318e08 +0, 11, 11, 1, 1843200, 0x8530a7d5 +0, 12, 12, 1, 1843200, 0x0ee29f10 +0, 13, 13, 1, 1843200, 0xcbb6b185 +0, 14, 14, 1, 1843200, 0x085aac47 +0, 15, 15, 1, 1843200, 0xb42e7b1b +0, 16, 16, 1, 1843200, 0xea3a2cd6 +0, 17, 17, 1, 1843200, 0x7600ee09 +0, 18, 18, 1, 1843200, 0xe39fc9d4 +0, 19, 19, 1, 1843200, 0xc122cd4c +0, 20, 20, 1, 1843200, 0x5fb4c1cb +0, 21, 21, 1, 1843200, 0x1552cb6c +0, 22, 22, 1, 1843200, 0x5b66ce2f +0, 23, 23, 1, 1843200, 0x70a8c318 +0, 24, 24, 1, 1843200, 0x8b86af2d +0, 25, 25, 1, 1843200, 0x94886a49 +0, 26, 26, 1, 1843200, 0xda05684f +0, 27, 27, 1, 1843200, 0xe57c8f33 +0, 28, 28, 1, 1843200, 0x39ef9c7e +0, 29, 29, 1, 1843200, 0xe7a0cab8 +0, 30, 30, 1, 1843200, 0x43f0d766 +0, 31, 31, 1, 1843200, 0x733d3c7b +0, 32, 32, 1, 1843200, 0x42713cea +0, 33, 33, 1, 1843200, 0xdd844e53 +0, 34, 34, 1, 1843200, 0xa0875ba8 +0, 35, 35, 1, 1843200, 0x318b6114 +0, 36, 36, 1, 1843200, 0xcc986275 +0, 37, 37, 1, 1843200, 0x14eb6704