From 12cbbbb4abda2de0ea123282ccf7ebee61517f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20Brau=C3=9Fe?= Date: Fri, 30 Mar 2012 14:40:14 -0400 Subject: [PATCH 1/6] smacker audio: sign-extend the initial 16-bit predicted value Fixes Bug #265 Signed-off-by: Justin Ruggles --- libavcodec/smacker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c index d4253873c5..46027306a8 100644 --- a/libavcodec/smacker.c +++ b/libavcodec/smacker.c @@ -655,7 +655,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, } if(bits) { //decode 16-bit data for(i = stereo; i >= 0; i--) - pred[i] = av_bswap16(get_bits(&gb, 16)); + pred[i] = sign_extend(av_bswap16(get_bits(&gb, 16)), 16); for(i = 0; i <= stereo; i++) *samples++ = pred[i]; for(; i < unp_size / 2; i++) { From 67aec401d86c3b7c55ce6f97ea753dcb1ca04c95 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 29 Mar 2012 12:01:42 -0400 Subject: [PATCH 2/6] libspeexdec: set frame size in libspeex_decode_init() This fixes speex decoding, which was broken in 85469f1c. --- libavcodec/libspeexdec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c index 7bff4255be..686c9e8142 100644 --- a/libavcodec/libspeexdec.c +++ b/libavcodec/libspeexdec.c @@ -54,6 +54,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx) if (s->header) { avctx->sample_rate = s->header->rate; avctx->channels = s->header->nb_channels; + s->frame_size = s->header->frame_size; mode = speex_lib_get_mode(s->header->mode); if (!mode) { From ed3e1b485acfba72ac9741407836c6125559d567 Mon Sep 17 00:00:00 2001 From: Andres Gonzalez Date: Thu, 27 Jan 2011 10:14:21 +0100 Subject: [PATCH 3/6] oggenc: add pagesize option to set preferred page size When set, if an Ogg stream buffer has enough data, a page is made instead of filling maximum-size pages. Using smaller pages results smaller seek intervals at the expense of higher container overhead. Signed-off-by: Justin Ruggles --- libavformat/oggenc.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index f9472693f0..1c040a7d3e 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -21,6 +21,7 @@ #include "libavutil/crc.h" #include "libavutil/mathematics.h" +#include "libavutil/opt.h" #include "libavutil/random_seed.h" #include "libavcodec/xiph.h" #include "libavcodec/bytestream.h" @@ -63,9 +64,28 @@ typedef struct OGGPageList { } OGGPageList; typedef struct { + const AVClass *class; OGGPageList *page_list; + int pref_size; ///< preferred page size (0 => fill all segments) } OGGContext; +#define OFFSET(x) offsetof(OGGContext, x) +#define PARAM AV_OPT_FLAG_ENCODING_PARAM + +static const AVOption options[] = { + { "pagesize", "preferred page size in bytes", + OFFSET(pref_size), AV_OPT_TYPE_INT, { 0 }, 0, MAX_PAGE_SIZE, PARAM }, + { NULL }, +}; + +static const AVClass ogg_muxer_class = { + .class_name = "Ogg muxer", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + + static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset) { int64_t pos = avio_tell(pb); @@ -175,6 +195,7 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st, uint8_t *data, unsigned size, int64_t granule) { OGGStreamContext *oggstream = st->priv_data; + OGGContext *ogg = s->priv_data; int total_segments = size / 255 + 1; uint8_t *p = data; int i, segments, len, flush = 0; @@ -210,8 +231,9 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st, if (i == total_segments) page->granule = granule; - if (page->segments_count == 255) { - ogg_buffer_page(s, oggstream); + if (page->segments_count == 255 || + (ogg->pref_size > 0 && page->size >= ogg->pref_size)) { + ogg_buffer_page(s, oggstream); } } @@ -515,4 +537,5 @@ AVOutputFormat ff_ogg_muxer = { .write_header = ogg_write_header, .write_packet = ogg_write_packet, .write_trailer = ogg_write_trailer, + .priv_class = &ogg_muxer_class, }; From 10b1c060f9d2b6028ce4d3fc544a60ee6d7acc06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Sat, 18 Feb 2012 21:21:20 +0100 Subject: [PATCH 4/6] oggenc: fix condition when not to flush due to keyframe granule. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous condition of 0 page size was wrong, that would disable the mechanism for all frames at a start of a page, thus some keyframes still would not get their own granule. The real problem is that header packets must not be flushed, but they have (and must have) 0 granule and thus would be detected as keyframes. Add a separate parameter to mark header packets. Signed-off-by: Reimar Döffinger Signed-off-by: Justin Ruggles --- libavformat/oggenc.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index 1c040a7d3e..6ccbd58b17 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -192,7 +192,8 @@ static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream) } static int ogg_buffer_data(AVFormatContext *s, AVStream *st, - uint8_t *data, unsigned size, int64_t granule) + uint8_t *data, unsigned size, int64_t granule, + int header) { OGGStreamContext *oggstream = st->priv_data; OGGContext *ogg = s->priv_data; @@ -201,7 +202,7 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st, int i, segments, len, flush = 0; // Handles VFR by flushing page because this frame needs to have a timestamp - if (st->codec->codec_id == CODEC_ID_THEORA && + if (st->codec->codec_id == CODEC_ID_THEORA && !header && ogg_granule_to_timestamp(oggstream, granule) > ogg_granule_to_timestamp(oggstream, oggstream->last_granule) + 1) { if (oggstream->page.granule != -1) @@ -231,8 +232,8 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st, if (i == total_segments) page->granule = granule; - if (page->segments_count == 255 || - (ogg->pref_size > 0 && page->size >= ogg->pref_size)) { + if (!header && (page->segments_count == 255 || + (ogg->pref_size > 0 && page->size >= ogg->pref_size))) { ogg_buffer_page(s, oggstream); } } @@ -431,7 +432,7 @@ static int ogg_write_header(AVFormatContext *s) for (j = 0; j < s->nb_streams; j++) { OGGStreamContext *oggstream = s->streams[j]->priv_data; ogg_buffer_data(s, s->streams[j], oggstream->header[0], - oggstream->header_len[0], 0); + oggstream->header_len[0], 0, 1); oggstream->page.flags |= 2; // bos ogg_buffer_page(s, oggstream); } @@ -441,7 +442,7 @@ static int ogg_write_header(AVFormatContext *s) for (i = 1; i < 3; i++) { if (oggstream && oggstream->header_len[i]) ogg_buffer_data(s, st, oggstream->header[i], - oggstream->header_len[i], 0); + oggstream->header_len[i], 0, 1); } ogg_buffer_page(s, oggstream); } @@ -492,7 +493,7 @@ static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt) } else granule = pkt->pts + pkt->duration; - ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule); + ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule, 0); if (ret < 0) return ret; From c265b77b115885fd5f1b7a3eeae49dcc95718edc Mon Sep 17 00:00:00 2001 From: Aneesh Dogra Date: Fri, 30 Mar 2012 23:44:06 +0530 Subject: [PATCH 5/6] cavs: Remove unused code. The square is always passed as 1 whenever the function is called and thus the if block never gets executed. Signed-off-by: Ronald S. Bultje --- libavcodec/cavs.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c index 96ff2e87a8..42922e08dd 100644 --- a/libavcodec/cavs.c +++ b/libavcodec/cavs.c @@ -324,11 +324,12 @@ void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv) { * ****************************************************************************/ -static inline void mc_dir_part(AVSContext *h,Picture *pic,int square, - int chroma_height,int delta,int list,uint8_t *dest_y, - uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset, - int src_y_offset,qpel_mc_func *qpix_op, - h264_chroma_mc_func chroma_op,cavs_vector *mv){ +static inline void mc_dir_part(AVSContext *h,Picture *pic, + int chroma_height,int delta,int list,uint8_t *dest_y, + uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset, + int src_y_offset,qpel_mc_func *qpix_op, + h264_chroma_mc_func chroma_op,cavs_vector *mv) +{ MpegEncContext * const s = &h->s; const int mx= mv->x + src_x_offset*8; const int my= mv->y + src_y_offset*8; @@ -360,9 +361,6 @@ static inline void mc_dir_part(AVSContext *h,Picture *pic,int square, } qpix_op[luma_xy](dest_y, src_y, h->l_stride); //FIXME try variable height perhaps? - if(!square){ - qpix_op[luma_xy](dest_y + delta, src_y + delta, h->l_stride); - } if(emu){ s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cb, h->c_stride, @@ -379,11 +377,12 @@ static inline void mc_dir_part(AVSContext *h,Picture *pic,int square, chroma_op(dest_cr, src_cr, h->c_stride, chroma_height, mx&7, my&7); } -static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int delta, - uint8_t *dest_y,uint8_t *dest_cb,uint8_t *dest_cr, - int x_offset, int y_offset,qpel_mc_func *qpix_put, - h264_chroma_mc_func chroma_put,qpel_mc_func *qpix_avg, - h264_chroma_mc_func chroma_avg, cavs_vector *mv){ +static inline void mc_part_std(AVSContext *h,int chroma_height,int delta, + uint8_t *dest_y,uint8_t *dest_cb,uint8_t *dest_cr, + int x_offset, int y_offset,qpel_mc_func *qpix_put, + h264_chroma_mc_func chroma_put,qpel_mc_func *qpix_avg, + h264_chroma_mc_func chroma_avg, cavs_vector *mv) +{ qpel_mc_func *qpix_op= qpix_put; h264_chroma_mc_func chroma_op= chroma_put; @@ -395,7 +394,7 @@ static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int de if(mv->ref >= 0){ Picture *ref= &h->DPB[mv->ref]; - mc_dir_part(h, ref, square, chroma_height, delta, 0, + mc_dir_part(h, ref, chroma_height, delta, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset, qpix_op, chroma_op, mv); @@ -405,7 +404,7 @@ static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int de if((mv+MV_BWD_OFFS)->ref >= 0){ Picture *ref= &h->DPB[0]; - mc_dir_part(h, ref, square, chroma_height, delta, 1, + mc_dir_part(h, ref, chroma_height, delta, 1, dest_y, dest_cb, dest_cr, x_offset, y_offset, qpix_op, chroma_op, mv+MV_BWD_OFFS); } @@ -413,28 +412,28 @@ static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int de void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type) { if(ff_cavs_partition_flags[mb_type] == 0){ // 16x16 - mc_part_std(h, 1, 8, 0, h->cy, h->cu, h->cv, 0, 0, + mc_part_std(h, 8, 0, h->cy, h->cu, h->cv, 0, 0, h->cdsp.put_cavs_qpel_pixels_tab[0], h->s.dsp.put_h264_chroma_pixels_tab[0], h->cdsp.avg_cavs_qpel_pixels_tab[0], h->s.dsp.avg_h264_chroma_pixels_tab[0],&h->mv[MV_FWD_X0]); }else{ - mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 0, + mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 0, 0, h->cdsp.put_cavs_qpel_pixels_tab[1], h->s.dsp.put_h264_chroma_pixels_tab[1], h->cdsp.avg_cavs_qpel_pixels_tab[1], h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X0]); - mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 0, + mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 4, 0, h->cdsp.put_cavs_qpel_pixels_tab[1], h->s.dsp.put_h264_chroma_pixels_tab[1], h->cdsp.avg_cavs_qpel_pixels_tab[1], h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X1]); - mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 4, + mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 0, 4, h->cdsp.put_cavs_qpel_pixels_tab[1], h->s.dsp.put_h264_chroma_pixels_tab[1], h->cdsp.avg_cavs_qpel_pixels_tab[1], h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X2]); - mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 4, + mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 4, 4, h->cdsp.put_cavs_qpel_pixels_tab[1], h->s.dsp.put_h264_chroma_pixels_tab[1], h->cdsp.avg_cavs_qpel_pixels_tab[1], From 420d1df2e2a857eae45fa947e16eae7494793d57 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 29 Mar 2012 17:52:21 +0000 Subject: [PATCH 6/6] apedec: check bits <= 32. Fixes a floating-point exception further down. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind CC: libav-stable@libav.org Signed-off-by: Michael Niedermayer Signed-off-by: Ronald S. Bultje Signed-off-by: Derek Buitenhuis --- libavcodec/apedec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c index a9953e1b31..1f982670f4 100644 --- a/libavcodec/apedec.c +++ b/libavcodec/apedec.c @@ -421,9 +421,12 @@ static inline int ape_decode_value(APEContext *ctx, APERice *rice) if (tmpk <= 16) x = range_decode_bits(ctx, tmpk); - else { + else if (tmpk <= 32) { x = range_decode_bits(ctx, 16); x |= (range_decode_bits(ctx, tmpk - 16) << 16); + } else { + av_log(ctx->avctx, AV_LOG_ERROR, "Too many bits: %d\n", tmpk); + return AVERROR_INVALIDDATA; } x += overflow << tmpk; } else {