From a34a609fc1c21f6ab07ce0469e38c76a2ae077d1 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Wed, 19 Sep 2012 22:30:06 +0100 Subject: [PATCH 01/10] motion_est: fix use of inline on extern functions Inline functions declared without extern do not provide an external definition in standard C99. This code only works because most compilers do not implement the inline semantics correctly. With a stricter compiler, linking fails with unresolved references to these functions. Declaring the functions extern inline works correctly with some compilers while some others still fail to create external definitions. For maximum portability, create a static inline version with an externally visible wrapper for ff_get_mb_score. ff_epzs_motion_search is so large that no sane compiler inlines it anyway, so there the inline keyword can simply be dropped with no effect. Signed-off-by: Mans Rullgard --- libavcodec/motion_est.c | 6 +++--- libavcodec/motion_est_template.c | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index 4cf8a68df7..12e12571b1 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -1140,7 +1140,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) - dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1); + dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1); if((s->flags&CODEC_FLAG_4MV) && !c->skip && varc>50<<8 && vard>10<<8){ @@ -1312,7 +1312,7 @@ static int ff_estimate_motion_b(MpegEncContext * s, dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16); if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) - dmin= ff_get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1); + dmin= get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1); //printf("%d %d %d %d//", s->mb_x, s->mb_y, mx, my); // s->mb_type[mb_y*s->mb_width + mb_x]= mb_type; @@ -1624,7 +1624,7 @@ static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y) dmin = hpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) - dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1); + dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1); get_limits(s, 16*mb_x, 16*mb_y); //restore c->?min/max, maybe not needed diff --git a/libavcodec/motion_est_template.c b/libavcodec/motion_est_template.c index d0d4b4107a..136d8b8494 100644 --- a/libavcodec/motion_est_template.c +++ b/libavcodec/motion_est_template.c @@ -160,8 +160,9 @@ static int no_sub_motion_search(MpegEncContext * s, return dmin; } -inline int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index, - int ref_index, int size, int h, int add_rate) +static inline int get_mb_score(MpegEncContext *s, int mx, int my, + int src_index, int ref_index, int size, + int h, int add_rate) { // const int check_luma= s->dsp.me_sub_cmp != s->dsp.mb_cmp; MotionEstContext * const c= &s->me; @@ -190,6 +191,12 @@ inline int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index, return d; } +int ff_get_mb_score(MpegEncContext *s, int mx, int my, int src_index, + int ref_index, int size, int h, int add_rate) +{ + return get_mb_score(s, mx, my, src_index, ref_index, size, h, add_rate); +} + #define CHECK_QUARTER_MV(dx, dy, x, y)\ {\ const int hx= 4*(x)+(dx);\ @@ -972,9 +979,10 @@ static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int } //this function is dedicated to the braindamaged gcc -inline int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr, - int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2], - int ref_mv_scale, int size, int h) +int ff_epzs_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr, + int P[10][2], int src_index, int ref_index, + int16_t (*last_mv)[2], int ref_mv_scale, + int size, int h) { MotionEstContext * const c= &s->me; //FIXME convert other functions in the same way if faster From 6746cd7f61964f94f949606f839598861472dcff Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Fri, 7 Sep 2012 16:27:21 +0200 Subject: [PATCH 02/10] lavf probe: prevent codec probe with no data at all seen This occurs with fuzzed mpeg-ts files. set_codec_from_probe_data() is called with a zeroed AVProbeData since no packet made through for specific stream. --- libavformat/utils.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavformat/utils.c b/libavformat/utils.c index e4e4a8b445..64be7c8700 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -625,6 +625,11 @@ static void probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE); } else { st->probe_packets = 0; + if (!pd->buf_size) { + av_log(s, AV_LOG_ERROR, "nothing to probe for stream %d\n", + st->index); + return; + } } if (!st->probe_packets || From 0122118ec32087cf3522bf14a1c4e34cb7d95a67 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 15 Sep 2012 15:36:22 +0100 Subject: [PATCH 03/10] configure: update tms470 detection for latest version v5.0 of the TI ARM compiler changes the version string. This updates the detection to check for both the old and the new strings. Signed-off-by: Mans Rullgard --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 49e9ecf040..4461bdeca2 100755 --- a/configure +++ b/configure @@ -2275,7 +2275,7 @@ probe_cc(){ _depflags='-MMD' _cflags_speed='-O3' _cflags_size='-Os' - elif $_cc -version 2>/dev/null | grep -q TMS470; then + elif $_cc -version 2>/dev/null | grep -Eq 'TMS470|TI ARM'; then _type=tms470 _ident=$($_cc -version | head -n1 | tr -s ' ') _flags='--gcc --abi=eabi -me' From a27a690fac6d9f42464039702f8cde6777778a53 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Thu, 2 Aug 2012 19:17:16 +0100 Subject: [PATCH 04/10] ARM: swap source operands in some add instructions This allows using a 16-bit opcode when generating Thumb2 code. Signed-off-by: Mans Rullgard --- libavcodec/arm/ac3dsp_armv6.S | 2 +- libavcodec/arm/dsputil_arm.S | 4 ++-- libavcodec/arm/vp8_armv6.S | 6 +++--- libavutil/arm/asm.S | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/arm/ac3dsp_armv6.S b/libavcodec/arm/ac3dsp_armv6.S index f6f297a532..2028d0b89f 100644 --- a/libavcodec/arm/ac3dsp_armv6.S +++ b/libavcodec/arm/ac3dsp_armv6.S @@ -32,7 +32,7 @@ function ff_ac3_bit_alloc_calc_bap_armv6, export=1 ldrb r4, [r4, r2] add r1, r1, r2, lsl #1 @ psd + start add r0, r0, r4, lsl #1 @ mask + band - add r4, lr, r4 + add r4, r4, lr add r7, r7, r2 @ bap + start 1: ldrsh r9, [r0], #2 @ mask[band] diff --git a/libavcodec/arm/dsputil_arm.S b/libavcodec/arm/dsputil_arm.S index dd65f705a7..3686befec1 100644 --- a/libavcodec/arm/dsputil_arm.S +++ b/libavcodec/arm/dsputil_arm.S @@ -632,7 +632,7 @@ function ff_add_pixels_clamped_arm, export=1 ldrsh r7, [r0, #2] and r6, r4, #0xFF and r8, r4, #0xFF00 - add r6, r5, r6 + add r6, r6, r5 add r8, r7, r8, lsr #8 mvn r5, r5 mvn r7, r7 @@ -674,7 +674,7 @@ function ff_add_pixels_clamped_arm, export=1 ldrsh r7, [r0, #10] and r6, r4, #0xFF and r8, r4, #0xFF00 - add r6, r5, r6 + add r6, r6, r5 add r8, r7, r8, lsr #8 mvn r5, r5 mvn r7, r7 diff --git a/libavcodec/arm/vp8_armv6.S b/libavcodec/arm/vp8_armv6.S index 1b668bcd2a..3863dc31a5 100644 --- a/libavcodec/arm/vp8_armv6.S +++ b/libavcodec/arm/vp8_armv6.S @@ -88,7 +88,7 @@ function ff_decode_block_coeffs_armv6, export=1 add r4, r3, r3, lsl #5 sxth r12, r11 - add r4, r2, r4 + add r4, r4, r2 adds r6, r6, r9 add r4, r4, #11 lsl r8, r8, r9 @@ -138,7 +138,7 @@ A orrcs r8, r8, r10, lsl r6 2: add r4, r3, r3, lsl #5 cmp r3, #16 - add r4, r2, r4 + add r4, r4, r2 pkhtb r11, r11, r11, asr #16 bne 0b b 6b @@ -226,7 +226,7 @@ A orrcs r8, r8, r10, lsl r6 ldr r1, [sp, #4] 4: add r4, r3, r3, lsl #5 - add r4, r2, r4 + add r4, r4, r2 add r4, r4, #22 rac_get_128 r5, r6, r7, r8, r9, r10 it ge diff --git a/libavutil/arm/asm.S b/libavutil/arm/asm.S index 7b3832a28a..45e4aab77e 100644 --- a/libavutil/arm/asm.S +++ b/libavutil/arm/asm.S @@ -142,7 +142,7 @@ ELF .size \name, . - \name .if \indir ldr \rd, [pc, \rd] .else - add \rd, pc, \rd + add \rd, \rd, pc .endif def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@ .endm From cdb7db5acdefbb976e3004e87b8f0078d40d068f Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Thu, 20 Sep 2012 22:53:41 +0100 Subject: [PATCH 05/10] ARM: align PIC offset pools to 4 bytes When building Thumb2 code, the end of a function, where the PIC offsets are placed, need not be aligned. Although the values are only accessed with instructions allowing unaligned addresses, keeping them aligned is preferable. Signed-off-by: Mans Rullgard --- libavutil/arm/asm.S | 1 + 1 file changed, 1 insertion(+) diff --git a/libavutil/arm/asm.S b/libavutil/arm/asm.S index 45e4aab77e..b30f9b1bbb 100644 --- a/libavutil/arm/asm.S +++ b/libavutil/arm/asm.S @@ -66,6 +66,7 @@ ELF .eabi_attribute 25, \val .set .Lpic_gp, 0 .macro endfunc .if .Lpic_idx + .align 2 .altmacro put_pic %(.Lpic_idx - 1) .noaltmacro From 8995d34972dc1092a5576c8d26e9b583f9dc2040 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Thu, 20 Sep 2012 22:55:11 +0100 Subject: [PATCH 06/10] ARM: use 2-operand syntax for ADD Rd, PC in Apple PIC code The Apple assembler refuses to assemble the 3-operand form in Thumb2 even though it is valid syntax. Signed-off-by: Mans Rullgard --- libavutil/arm/asm.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavutil/arm/asm.S b/libavutil/arm/asm.S index b30f9b1bbb..ce7f46d807 100644 --- a/libavutil/arm/asm.S +++ b/libavutil/arm/asm.S @@ -143,7 +143,7 @@ ELF .size \name, . - \name .if \indir ldr \rd, [pc, \rd] .else - add \rd, \rd, pc + add \rd, pc .endif def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@ .endm From 1cc569dddadfedabe970ce7408dba7ddf381e98b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 20 Sep 2012 20:00:39 +0200 Subject: [PATCH 07/10] lavf: zero data/size of the packet passed to read_packet(). --- libavformat/utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/utils.c b/libavformat/utils.c index 64be7c8700..9dd58cc152 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -671,6 +671,8 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) } } + pkt->data = NULL; + pkt->size = 0; av_init_packet(pkt); ret= s->iformat->read_packet(s, pkt); if (ret < 0) { From bdb939ad730f1170ef0f57fb7a3c5686435af2d1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 20 Sep 2012 20:01:43 +0200 Subject: [PATCH 08/10] matroskadec: only return corrupt packets that actually contain data Fixes bug 372. --- libavformat/matroskadec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 0a35a875c1..442db23c0b 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2195,7 +2195,7 @@ static int matroska_read_packet(AVFormatContext *s, AVPacket *pkt) ret = matroska_parse_cluster(matroska); } - if (ret == AVERROR_INVALIDDATA) { + if (ret == AVERROR_INVALIDDATA && pkt->data) { pkt->flags |= AV_PKT_FLAG_CORRUPT; return 0; } From 87b017a298c12b9a2451276649f3932358b943fc Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 20 Sep 2012 20:04:56 +0200 Subject: [PATCH 09/10] matroskadec: fix a sanity check. --- libavformat/matroskadec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 442db23c0b..094b0558f7 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1804,7 +1804,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, } case 0x2: /* fixed-size lacing */ - if (size != (size / *laces) * size) { + if (size % (*laces)) { res = AVERROR_INVALIDDATA; break; } From e52e4fe10d96da4ed26e2acbe3c1ab69485ed75d Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 21 Sep 2012 09:20:09 +0200 Subject: [PATCH 10/10] libx264: add forgotten ; --- libavcodec/libx264.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 62815ced92..0db859419f 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -69,7 +69,7 @@ typedef struct X264Context { int direct_pred; int slice_max_size; char *stats; - int nal_hrd + int nal_hrd; } X264Context; static void X264_log(void *p, int level, const char *fmt, va_list args)