From 29facc1e916c4be0324b41634c1d0b8c5fd31fa8 Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Fri, 3 Aug 2012 21:41:24 -0400 Subject: zerocodec: Cosmetics Be consistent with error messages and code formatting. Signed-off-by: Derek Buitenhuis --- libavcodec/zerocodec.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/libavcodec/zerocodec.c b/libavcodec/zerocodec.c index 4f43d52a6b..8d46bfdcf8 100644 --- a/libavcodec/zerocodec.c +++ b/libavcodec/zerocodec.c @@ -23,7 +23,7 @@ typedef struct { AVFrame previous_frame; z_stream zstream; - int size; + int size; } ZeroCodecContext; static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, @@ -33,7 +33,8 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, AVFrame *pic = avctx->coded_frame; AVFrame *prev_pic = &zc->previous_frame; z_stream *zstream = &zc->zstream; - uint8_t *prev = prev_pic->data[0], *dst; + uint8_t *prev = prev_pic->data[0]; + uint8_t *dst; int i, j, zret; pic->reference = 3; @@ -43,7 +44,7 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, pic->pict_type = AV_PICTURE_TYPE_I; } else { if (!prev) { - av_log(avctx, AV_LOG_ERROR, "Missing reference frame!\n"); + av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n"); return AVERROR_INVALIDDATA; } pic->key_frame = 0; @@ -56,16 +57,15 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, } zret = inflateReset(zstream); - if (zret != Z_OK) { - av_log(avctx, AV_LOG_ERROR, "Could not reset inflate: %d\n", zret); - return AVERROR(EINVAL); + av_log(avctx, AV_LOG_ERROR, "Could not reset inflate: %d.\n", zret); + return AVERROR_INVALIDDATA; } zstream->next_in = avpkt->data; zstream->avail_in = avpkt->size; - dst = pic->data[0]; + dst = pic->data[0]; /** * ZeroCodec has very simple interframe compression. If a value @@ -79,8 +79,8 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, zret = inflate(zstream, Z_SYNC_FLUSH); if (zret != Z_OK && zret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, - "Inflate failed with return code: %d\n", zret); - return AVERROR(EINVAL); + "Inflate failed with return code: %d.\n", zret); + return AVERROR_INVALIDDATA; } if (!(avpkt->flags & AV_PKT_FLAG_KEY)) @@ -138,14 +138,12 @@ static av_cold int zerocodec_decode_init(AVCodecContext *avctx) zstream->opaque = Z_NULL; zret = inflateInit(zstream); - if (zret != Z_OK) { - av_log(avctx, AV_LOG_ERROR, "Could not initialize inflate: %d\n", zret); + av_log(avctx, AV_LOG_ERROR, "Could not initialize inflate: %d.\n", zret); return AVERROR(ENOMEM); } avctx->coded_frame = avcodec_alloc_frame(); - if (!avctx->coded_frame) { av_log(avctx, AV_LOG_ERROR, "Could not allocate frame buffer.\n"); zerocodec_decode_close(avctx); -- cgit v1.2.3 From 616fd4fe5e2985f31e2ae1aee0558e73390437a0 Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Fri, 3 Aug 2012 22:13:43 -0400 Subject: zerocodec: Fix memleak in decode_frame If there was a failure inflating, or reinitializing the zstream, the current frame's buffer would be lost. Signed-off-by: Derek Buitenhuis --- libavcodec/zerocodec.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libavcodec/zerocodec.c b/libavcodec/zerocodec.c index 8d46bfdcf8..cfbd16f147 100644 --- a/libavcodec/zerocodec.c +++ b/libavcodec/zerocodec.c @@ -51,17 +51,17 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, pic->pict_type = AV_PICTURE_TYPE_P; } - if (avctx->get_buffer(avctx, pic) < 0) { - av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n"); - return AVERROR(ENOMEM); - } - zret = inflateReset(zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Could not reset inflate: %d.\n", zret); return AVERROR_INVALIDDATA; } + if (avctx->get_buffer(avctx, pic) < 0) { + av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n"); + return AVERROR(ENOMEM); + } + zstream->next_in = avpkt->data; zstream->avail_in = avpkt->size; @@ -78,6 +78,7 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, zret = inflate(zstream, Z_SYNC_FLUSH); if (zret != Z_OK && zret != Z_STREAM_END) { + avctx->release_buffer(avctx, pic); av_log(avctx, AV_LOG_ERROR, "Inflate failed with return code: %d.\n", zret); return AVERROR_INVALIDDATA; -- cgit v1.2.3 From 8b8750e0612f0bc30fafbb767f7931158868971d Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Sat, 4 Aug 2012 15:40:35 -0400 Subject: cosmetics: Fix a few switched periods and linebreaks Based on a patch by Piotr Bandurski. Signed-off-by: Derek Buitenhuis --- libavcodec/cllc.c | 2 +- libavfilter/vf_libopencv.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/cllc.c b/libavcodec/cllc.c index aca4669fcb..a65689ab56 100644 --- a/libavcodec/cllc.c +++ b/libavcodec/cllc.c @@ -225,7 +225,7 @@ static int cllc_decode_frame(AVCodecContext *avctx, void *data, break; default: - av_log(avctx, AV_LOG_ERROR, "Unknown coding type: %d\n.", coding_type); + av_log(avctx, AV_LOG_ERROR, "Unknown coding type: %d.\n", coding_type); return AVERROR_INVALIDDATA; } diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c index e60caf2bc3..ea6ebe1b16 100644 --- a/libavfilter/vf_libopencv.c +++ b/libavfilter/vf_libopencv.c @@ -106,7 +106,7 @@ static av_cold int smooth_init(AVFilterContext *ctx, const char *args) else if (!strcmp(type_str, "gaussian" )) smooth->type = CV_GAUSSIAN; else if (!strcmp(type_str, "bilateral" )) smooth->type = CV_BILATERAL; else { - av_log(ctx, AV_LOG_ERROR, "Smoothing type '%s' unknown\n.", type_str); + av_log(ctx, AV_LOG_ERROR, "Smoothing type '%s' unknown.\n", type_str); return AVERROR(EINVAL); } @@ -220,7 +220,7 @@ static int parse_iplconvkernel(IplConvKernel **kernel, char *buf, void *log_ctx) return ret; } else { av_log(log_ctx, AV_LOG_ERROR, - "Shape unspecified or type '%s' unknown\n.", shape_str); + "Shape unspecified or type '%s' unknown.\n", shape_str); return AVERROR(EINVAL); } -- cgit v1.2.3 From 800750417ffea64cde827de08e31e6523205f8d1 Mon Sep 17 00:00:00 2001 From: Reinhard Tartler Date: Sat, 4 Aug 2012 15:24:15 +0200 Subject: lavfi: properly signal out-of-memory error in ff_filter_samples Found with a clang-scan report on http://fate.libav.org/csa/ --- libavfilter/audio.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavfilter/audio.c b/libavfilter/audio.c index d518b247a3..bd718c611d 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -172,6 +172,10 @@ int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) buf_out = ff_default_get_audio_buffer(link, dst->min_perms, samplesref->audio->nb_samples); + if (!buf_out) { + avfilter_unref_buffer(samplesref); + return AVERROR(ENOMEM); + } buf_out->pts = samplesref->pts; buf_out->audio->sample_rate = samplesref->audio->sample_rate; -- cgit v1.2.3 From 965efc1673074ac1e6c28177a4718ed84f89ac83 Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Sat, 4 Aug 2012 19:41:20 -0400 Subject: dpx: Make start offset unsigned Some corrupted files would end up with a negative offset, and segfault. Fixes bug #177. Signed-off-by: Derek Buitenhuis --- libavcodec/dpx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c index fadd5c3bae..9bce6483b5 100644 --- a/libavcodec/dpx.c +++ b/libavcodec/dpx.c @@ -62,7 +62,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *const p = &s->picture; uint8_t *ptr; - int magic_num, offset, endian; + unsigned int offset; + int magic_num, endian; int x, y; int w, h, stride, bits_per_color, descriptor, elements, target_packet_size, source_packet_size; -- cgit v1.2.3 From 82494835c4ee2adf5afc51bfd19964b82eb80da9 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sun, 29 Jul 2012 14:58:53 +0100 Subject: rational: add av_inv_q() returning the inverse of an AVRational This allows simplifying a few expressions. Signed-off-by: Mans Rullgard --- avconv.c | 6 ++---- libavutil/rational.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/avconv.c b/avconv.c index 07de66e7fc..b20dbeca62 100644 --- a/avconv.c +++ b/avconv.c @@ -797,8 +797,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterContext *first_filter = in->filter_ctx; AVFilter *filter = avfilter_get_by_name("buffer"); InputStream *ist = ifilter->ist; - AVRational tb = ist->framerate.num ? (AVRational){ist->framerate.den, - ist->framerate.num} : + AVRational tb = ist->framerate.num ? av_inv_q(ist->framerate) : ist->st->time_base; AVRational sar; char args[255], name[255]; @@ -2197,8 +2196,7 @@ static int output_packet(InputStream *ist, const AVPacket *pkt) if (avpkt.duration) ist->next_dts += av_rescale_q(avpkt.duration, ist->st->time_base, AV_TIME_BASE_Q); else if (ist->st->avg_frame_rate.num) - ist->next_dts += av_rescale_q(1, (AVRational){ist->st->avg_frame_rate.den, - ist->st->avg_frame_rate.num}, + ist->next_dts += av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), AV_TIME_BASE_Q); else if (ist->st->codec->time_base.num != 0) { int ticks = ist->st->parser ? ist->st->parser->repeat_pict + 1 : diff --git a/libavutil/rational.h b/libavutil/rational.h index 0ec18ec969..5d7dab7fd0 100644 --- a/libavutil/rational.h +++ b/libavutil/rational.h @@ -114,6 +114,17 @@ AVRational av_add_q(AVRational b, AVRational c) av_const; */ AVRational av_sub_q(AVRational b, AVRational c) av_const; +/** + * Invert a rational. + * @param q value + * @return 1 / q + */ +static av_always_inline AVRational av_inv_q(AVRational q) +{ + AVRational r = { q.den, q.num }; + return r; +} + /** * Convert a double precision floating point number to a rational. * inf is expressed as {1,0} or {-1,0} depending on the sign. -- cgit v1.2.3 From 2096857551660649dbe9a5aad7338b0872858575 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 1 Aug 2012 00:17:43 +0200 Subject: x86: h264_idct: Rename x264_add8x4_idct_sse2 --> h264_add8x4_idct_sse2 --- libavcodec/x86/h264_idct.asm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/x86/h264_idct.asm b/libavcodec/x86/h264_idct.asm index cc83806884..0bd681661d 100644 --- a/libavcodec/x86/h264_idct.asm +++ b/libavcodec/x86/h264_idct.asm @@ -704,7 +704,7 @@ h264_idct_dc_add8_mmx2: ALIGN 16 INIT_XMM ; r0 = uint8_t *dst (clobbered), r2 = int16_t *block, r3 = int stride -x264_add8x4_idct_sse2: +h264_add8x4_idct_sse2: movq m0, [r2+ 0] movq m1, [r2+ 8] movq m2, [r2+16] @@ -733,7 +733,7 @@ x264_add8x4_idct_sse2: %else add r0, r0m %endif - call x264_add8x4_idct_sse2 + call h264_add8x4_idct_sse2 .cycle%1end %if %1 < 7 add r2, 64 @@ -768,7 +768,7 @@ cglobal h264_idct_add16_8_sse2, 5, 5 + ARCH_X86_64, 8 %else add r0, r0m %endif - call x264_add8x4_idct_sse2 + call h264_add8x4_idct_sse2 jmp .cycle%1end .try%1dc movsx r0, word [r2 ] @@ -815,7 +815,7 @@ cglobal h264_idct_add16intra_8_sse2, 5, 7 + ARCH_X86_64, 8 mov r0, [r0] add r0, dword [r1+(%1&1)*8+64*(1+(%1>>1))] %endif - call x264_add8x4_idct_sse2 + call h264_add8x4_idct_sse2 jmp .cycle%1end .try%1dc movsx r0, word [r2 ] -- cgit v1.2.3