From b1bcddfb6d06535df59bd212904c725850b36ece Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Tue, 20 Dec 2011 18:31:43 +0000 Subject: [PATCH 01/27] postproc: altivec: fix trivial cases of mixed declarations and code This moves declarations without initialisers or with constant initialisers to the start of a block, and adds do {} while(0) around some macros, thus allowing declarations within them. Signed-off-by: Mans Rullgard --- libpostproc/postprocess_altivec_template.c | 123 +++++++++++---------- libpostproc/postprocess_template.c | 3 +- 2 files changed, 67 insertions(+), 59 deletions(-) diff --git a/libpostproc/postprocess_altivec_template.c b/libpostproc/postprocess_altivec_template.c index 56d7b1660a..68f397f0d3 100644 --- a/libpostproc/postprocess_altivec_template.c +++ b/libpostproc/postprocess_altivec_template.c @@ -530,6 +530,39 @@ static inline void doVertDefFilter_altivec(uint8_t src[], int stride, PPContext } static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { + const vector signed int vsint32_8 = vec_splat_s32(8); + const vector unsigned int vuint32_4 = vec_splat_u32(4); + const vector signed char neg1 = vec_splat_s8(-1); + + const vector unsigned char permA1 = (vector unsigned char) + {0x00, 0x01, 0x02, 0x10, 0x11, 0x12, 0x1F, 0x1F, + 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}; + const vector unsigned char permA2 = (vector unsigned char) + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x10, 0x11, + 0x12, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}; + const vector unsigned char permA1inc = (vector unsigned char) + {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + const vector unsigned char permA2inc = (vector unsigned char) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + const vector unsigned char magic = (vector unsigned char) + {0x01, 0x02, 0x01, 0x02, 0x04, 0x02, 0x01, 0x02, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + const vector unsigned char extractPerm = (vector unsigned char) + {0x10, 0x10, 0x10, 0x01, 0x10, 0x10, 0x10, 0x01, + 0x10, 0x10, 0x10, 0x01, 0x10, 0x10, 0x10, 0x01}; + const vector unsigned char extractPermInc = (vector unsigned char) + {0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01}; + const vector unsigned char identity = vec_lvsl(0,(unsigned char *)0); + const vector unsigned char tenRight = (vector unsigned char) + {0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + const vector unsigned char eightLeft = (vector unsigned char) + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08}; + /* this code makes no assumption on src or stride. One could remove the recomputation of the perm @@ -565,6 +598,7 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { #undef LOAD_LINE vector unsigned char v_avg; + DECLARE_ALIGNED(16, signed int, S)[8]; { const vector unsigned char trunc_perm = (vector unsigned char) {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, @@ -603,7 +637,6 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { v_avg = vec_avg(v_min, v_max); } - DECLARE_ALIGNED(16, signed int, S)[8]; { const vector unsigned short mask1 = (vector unsigned short) {0x0001, 0x0002, 0x0004, 0x0008, @@ -615,8 +648,12 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { const vector unsigned int vuint32_16 = vec_sl(vec_splat_u32(1), vec_splat_u32(4)); const vector unsigned int vuint32_1 = vec_splat_u32(1); + vector signed int sumA2; + vector signed int sumB2; + vector signed int sum0, sum1, sum2, sum3, sum4; + vector signed int sum5, sum6, sum7, sum8, sum9; + #define COMPARE(i) \ - vector signed int sum##i; \ do { \ const vector unsigned char cmp##i = \ (vector unsigned char)vec_cmpgt(src##i, v_avg); \ @@ -644,8 +681,6 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { COMPARE(9); #undef COMPARE - vector signed int sumA2; - vector signed int sumB2; { const vector signed int sump02 = vec_mergel(sum0, sum2); const vector signed int sump13 = vec_mergel(sum1, sum3); @@ -703,39 +738,6 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { tQP2[0]= c->QP/2 + 1; vector signed int vQP2 = vec_ld(0, tQP2); vQP2 = vec_splat(vQP2, 0); - const vector signed int vsint32_8 = vec_splat_s32(8); - const vector unsigned int vuint32_4 = vec_splat_u32(4); - - const vector unsigned char permA1 = (vector unsigned char) - {0x00, 0x01, 0x02, 0x10, 0x11, 0x12, 0x1F, 0x1F, - 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}; - const vector unsigned char permA2 = (vector unsigned char) - {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x10, 0x11, - 0x12, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}; - const vector unsigned char permA1inc = (vector unsigned char) - {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - const vector unsigned char permA2inc = (vector unsigned char) - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - const vector unsigned char magic = (vector unsigned char) - {0x01, 0x02, 0x01, 0x02, 0x04, 0x02, 0x01, 0x02, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - const vector unsigned char extractPerm = (vector unsigned char) - {0x10, 0x10, 0x10, 0x01, 0x10, 0x10, 0x10, 0x01, - 0x10, 0x10, 0x10, 0x01, 0x10, 0x10, 0x10, 0x01}; - const vector unsigned char extractPermInc = (vector unsigned char) - {0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01}; - const vector unsigned char identity = vec_lvsl(0,(unsigned char *)0); - const vector unsigned char tenRight = (vector unsigned char) - {0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - const vector unsigned char eightLeft = (vector unsigned char) - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08}; - - #define F_INIT(i) \ vector unsigned char tenRightM##i = tenRight; \ vector unsigned char permA1M##i = permA1; \ @@ -777,7 +779,7 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { tenRightM##i = vec_sro(tenRightM##i, eightLeft); \ extractPermM##i = vec_add(extractPermM##i, extractPermInc) -#define ITER(i, j, k) \ +#define ITER(i, j, k) do { \ F_INIT(i); \ F2(i, j, k, 0); \ F2(i, j, k, 1); \ @@ -786,7 +788,8 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { F2(i, j, k, 4); \ F2(i, j, k, 5); \ F2(i, j, k, 6); \ - F2(i, j, k, 7) + F2(i, j, k, 7); \ +} while (0) ITER(0, 1, 2); ITER(1, 2, 3); @@ -797,9 +800,7 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { ITER(6, 7, 8); ITER(7, 8, 9); - const vector signed char neg1 = vec_splat_s8(-1); - -#define STORE_LINE(i) \ +#define STORE_LINE(i) do { \ const vector unsigned char permST##i = \ vec_lvsr(i * stride, srcCopy); \ const vector unsigned char maskST##i = \ @@ -809,7 +810,8 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { sA##i= vec_sel(sA##i, src##i, maskST##i); \ sB##i= vec_sel(src##i, sB##i, maskST##i); \ vec_st(sA##i, i * stride, srcCopy); \ - vec_st(sB##i, i * stride + 16, srcCopy) + vec_st(sB##i, i * stride + 16, srcCopy); \ +} while (0) STORE_LINE(1); STORE_LINE(2); @@ -832,6 +834,10 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, uint8_t *tempBlurred, uint32_t *tempBlurredPast, int *maxNoise) { + const vector signed char neg1 = vec_splat_s8(-1); + const vector unsigned char permHH = (const vector unsigned char){0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F}; + const vector signed int zero = vec_splat_s32(0); const vector signed short vsint16_1 = vec_splat_s16(1); vector signed int v_dp = zero; @@ -872,11 +878,12 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, LOAD_LINE(tempBlurred, 7); #undef LOAD_LINE -#define ACCUMULATE_DIFFS(i) \ +#define ACCUMULATE_DIFFS(i) do { \ vector signed short v_d##i = vec_sub(v_tempBlurredAss##i, \ v_srcAss##i); \ v_dp = vec_msums(v_d##i, v_d##i, v_dp); \ - v_sysdp = vec_msums(v_d##i, vsint16_1, v_sysdp) + v_sysdp = vec_msums(v_d##i, vsint16_1, v_sysdp); \ +} while (0) ACCUMULATE_DIFFS(0); ACCUMULATE_DIFFS(1); @@ -938,13 +945,14 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, const vector signed short vsint16_4 = vec_splat_s16(4); const vector unsigned short vuint16_3 = vec_splat_u16(3); -#define OP(i) \ +#define OP(i) do { \ const vector signed short v_temp##i = \ vec_mladd(v_tempBlurredAss##i, \ vsint16_7, v_srcAss##i); \ const vector signed short v_temp2##i = \ vec_add(v_temp##i, vsint16_4); \ - v_tempBlurredAss##i = vec_sr(v_temp2##i, vuint16_3) + v_tempBlurredAss##i = vec_sr(v_temp2##i, vuint16_3);\ + } while (0) OP(0); OP(1); @@ -959,13 +967,14 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, const vector signed short vsint16_3 = vec_splat_s16(3); const vector signed short vsint16_2 = vec_splat_s16(2); -#define OP(i) \ +#define OP(i) do { \ const vector signed short v_temp##i = \ vec_mladd(v_tempBlurredAss##i, \ vsint16_3, v_srcAss##i); \ const vector signed short v_temp2##i = \ vec_add(v_temp##i, vsint16_2); \ - v_tempBlurredAss##i = vec_sr(v_temp2##i, (vector unsigned short)vsint16_2) + v_tempBlurredAss##i = vec_sr(v_temp2##i, (vector unsigned short)vsint16_2); \ + } while (0) OP(0); OP(1); @@ -979,11 +988,7 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, } } - const vector signed char neg1 = vec_splat_s8(-1); - const vector unsigned char permHH = (const vector unsigned char){0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F}; - -#define PACK_AND_STORE(src, i) \ +#define PACK_AND_STORE(src, i) do { \ const vector unsigned char perms##src##i = \ vec_lvsr(i * stride, src); \ const vector unsigned char vf##src##i = \ @@ -999,7 +1004,8 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, const vector unsigned char svB##src##i = \ vec_sel(vg2##src##i, v_##src##A2##i, mask##src##i); \ vec_st(svA##src##i, i * stride, src); \ - vec_st(svB##src##i, i * stride + 16, src) + vec_st(svB##src##i, i * stride + 16, src); \ +} while (0) PACK_AND_STORE(src, 0); PACK_AND_STORE(src, 1); @@ -1127,6 +1133,7 @@ static inline void transpose_16x8_char_toPackedAlign_altivec(unsigned char* dst, static inline void transpose_8x16_char_fromPackedAlign_altivec(unsigned char* dst, unsigned char* src, int stride) { const vector unsigned char zero = vec_splat_u8(0); + const vector signed char neg1 = vec_splat_s8(-1); #define LOAD_DOUBLE_LINE(i, j) \ vector unsigned char src##i = vec_ld(i * 16, src); \ @@ -1187,8 +1194,7 @@ static inline void transpose_8x16_char_fromPackedAlign_altivec(unsigned char* ds temp7 = vec_mergel(tempD, tempL); - const vector signed char neg1 = vec_splat_s8(-1); -#define STORE_DOUBLE_LINE(i, j) \ +#define STORE_DOUBLE_LINE(i, j) do { \ vector unsigned char dstA##i = vec_ld(i * stride, dst); \ vector unsigned char dstB##i = vec_ld(i * stride + 16, dst); \ vector unsigned char dstA##j = vec_ld(j * stride, dst); \ @@ -1206,7 +1212,8 @@ static inline void transpose_8x16_char_fromPackedAlign_altivec(unsigned char* ds vec_st(dstAF##i, i * stride, dst); \ vec_st(dstBF##i, i * stride + 16, dst); \ vec_st(dstAF##j, j * stride, dst); \ - vec_st(dstBF##j, j * stride + 16, dst) + vec_st(dstBF##j, j * stride + 16, dst); \ +} while (0) STORE_DOUBLE_LINE(0,1); STORE_DOUBLE_LINE(2,3); diff --git a/libpostproc/postprocess_template.c b/libpostproc/postprocess_template.c index 471b2524d7..dd4c7a0a48 100644 --- a/libpostproc/postprocess_template.c +++ b/libpostproc/postprocess_template.c @@ -3518,9 +3518,10 @@ static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[ else if(mode & H_DEBLOCK){ #if HAVE_ALTIVEC DECLARE_ALIGNED(16, unsigned char, tempBlock)[272]; + int t; transpose_16x8_char_toPackedAlign_altivec(tempBlock, dstBlock - (4 + 1), stride); - const int t=vertClassify_altivec(tempBlock-48, 16, &c); + t = vertClassify_altivec(tempBlock-48, 16, &c); if(t==1) { doVertLowPass_altivec(tempBlock-48, 16, &c); transpose_8x16_char_fromPackedAlign_altivec(dstBlock - (4 + 1), tempBlock, stride); From b49b836f3a0f5853bc084afece1d2ac5b341f103 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Tue, 20 Dec 2011 19:03:25 +0000 Subject: [PATCH 02/27] postproc: altivec: untemplate some variable names These variables are now in separate scopes and thus do not need unique names. Signed-off-by: Mans Rullgard --- libpostproc/postprocess_altivec_template.c | 236 ++++++++++----------- 1 file changed, 113 insertions(+), 123 deletions(-) diff --git a/libpostproc/postprocess_altivec_template.c b/libpostproc/postprocess_altivec_template.c index 68f397f0d3..16b6e6910d 100644 --- a/libpostproc/postprocess_altivec_template.c +++ b/libpostproc/postprocess_altivec_template.c @@ -609,21 +609,22 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { const vector unsigned char trunc_src78 = vec_perm(src7, src8, trunc_perm); #define EXTRACT(op) do { \ - const vector unsigned char s##op##_1 = vec_##op(trunc_src12, trunc_src34); \ - const vector unsigned char s##op##_2 = vec_##op(trunc_src56, trunc_src78); \ - const vector unsigned char s##op##_6 = vec_##op(s##op##_1, s##op##_2); \ - const vector unsigned char s##op##_8h = vec_mergeh(s##op##_6, s##op##_6); \ - const vector unsigned char s##op##_8l = vec_mergel(s##op##_6, s##op##_6); \ - const vector unsigned char s##op##_9 = vec_##op(s##op##_8h, s##op##_8l); \ - const vector unsigned char s##op##_9h = vec_mergeh(s##op##_9, s##op##_9); \ - const vector unsigned char s##op##_9l = vec_mergel(s##op##_9, s##op##_9); \ - const vector unsigned char s##op##_10 = vec_##op(s##op##_9h, s##op##_9l); \ - const vector unsigned char s##op##_10h = vec_mergeh(s##op##_10, s##op##_10); \ - const vector unsigned char s##op##_10l = vec_mergel(s##op##_10, s##op##_10); \ - const vector unsigned char s##op##_11 = vec_##op(s##op##_10h, s##op##_10l); \ - const vector unsigned char s##op##_11h = vec_mergeh(s##op##_11, s##op##_11); \ - const vector unsigned char s##op##_11l = vec_mergel(s##op##_11, s##op##_11); \ - v_##op = vec_##op(s##op##_11h, s##op##_11l); } while (0) + const vector unsigned char s_1 = vec_##op(trunc_src12, trunc_src34); \ + const vector unsigned char s_2 = vec_##op(trunc_src56, trunc_src78); \ + const vector unsigned char s_6 = vec_##op(s_1, s_2); \ + const vector unsigned char s_8h = vec_mergeh(s_6, s_6); \ + const vector unsigned char s_8l = vec_mergel(s_6, s_6); \ + const vector unsigned char s_9 = vec_##op(s_8h, s_8l); \ + const vector unsigned char s_9h = vec_mergeh(s_9, s_9); \ + const vector unsigned char s_9l = vec_mergel(s_9, s_9); \ + const vector unsigned char s_10 = vec_##op(s_9h, s_9l); \ + const vector unsigned char s_10h = vec_mergeh(s_10, s_10); \ + const vector unsigned char s_10l = vec_mergel(s_10, s_10); \ + const vector unsigned char s_11 = vec_##op(s_10h, s_10l); \ + const vector unsigned char s_11h = vec_mergeh(s_11, s_11); \ + const vector unsigned char s_11l = vec_mergel(s_11, s_11); \ + v_##op = vec_##op(s_11h, s_11l); \ +} while (0) vector unsigned char v_min; vector unsigned char v_max; @@ -655,19 +656,20 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { #define COMPARE(i) \ do { \ - const vector unsigned char cmp##i = \ + const vector unsigned char cmp = \ (vector unsigned char)vec_cmpgt(src##i, v_avg); \ - const vector unsigned short cmpHi##i = \ - (vector unsigned short)vec_mergeh(cmp##i, cmp##i); \ - const vector unsigned short cmpLi##i = \ - (vector unsigned short)vec_mergel(cmp##i, cmp##i); \ - const vector signed short cmpHf##i = \ - (vector signed short)vec_and(cmpHi##i, mask1); \ - const vector signed short cmpLf##i = \ - (vector signed short)vec_and(cmpLi##i, mask2); \ - const vector signed int sump##i = vec_sum4s(cmpHf##i, zero); \ - const vector signed int sumq##i = vec_sum4s(cmpLf##i, sump##i); \ - sum##i = vec_sums(sumq##i, zero); } while (0) + const vector unsigned short cmpHi = \ + (vector unsigned short)vec_mergeh(cmp, cmp); \ + const vector unsigned short cmpLi = \ + (vector unsigned short)vec_mergel(cmp, cmp); \ + const vector signed short cmpHf = \ + (vector signed short)vec_and(cmpHi, mask1); \ + const vector signed short cmpLf = \ + (vector signed short)vec_and(cmpLi, mask2); \ + const vector signed int sump = vec_sum4s(cmpHf, zero); \ + const vector signed int sumq = vec_sum4s(cmpLf, sump); \ + sum##i = vec_sums(sumq, zero); \ + } while (0) COMPARE(0); COMPARE(1); @@ -738,49 +740,43 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { tQP2[0]= c->QP/2 + 1; vector signed int vQP2 = vec_ld(0, tQP2); vQP2 = vec_splat(vQP2, 0); -#define F_INIT(i) \ - vector unsigned char tenRightM##i = tenRight; \ - vector unsigned char permA1M##i = permA1; \ - vector unsigned char permA2M##i = permA2; \ - vector unsigned char extractPermM##i = extractPerm +#define F_INIT() \ + vector unsigned char tenRightM = tenRight; \ + vector unsigned char permA1M = permA1; \ + vector unsigned char permA2M = permA2; \ + vector unsigned char extractPermM = extractPerm #define F2(i, j, k, l) \ if (S[i] & (1 << (l+1))) { \ - const vector unsigned char a_##j##_A##l = \ - vec_perm(src##i, src##j, permA1M##i); \ - const vector unsigned char a_##j##_B##l = \ - vec_perm(a_##j##_A##l, src##k, permA2M##i); \ - const vector signed int a_##j##_sump##l = \ - (vector signed int)vec_msum(a_##j##_B##l, magic, \ - (vector unsigned int)zero); \ - vector signed int F_##j##_##l = \ - vec_sr(vec_sums(a_##j##_sump##l, vsint32_8), vuint32_4); \ - F_##j##_##l = vec_splat(F_##j##_##l, 3); \ - const vector signed int p_##j##_##l = \ - (vector signed int)vec_perm(src##j, \ - (vector unsigned char)zero, \ - extractPermM##i); \ - const vector signed int sum_##j##_##l = vec_add( p_##j##_##l, vQP2);\ - const vector signed int diff_##j##_##l = vec_sub( p_##j##_##l, vQP2);\ - vector signed int newpm_##j##_##l; \ - if (vec_all_lt(sum_##j##_##l, F_##j##_##l)) \ - newpm_##j##_##l = sum_##j##_##l; \ - else if (vec_all_gt(diff_##j##_##l, F_##j##_##l)) \ - newpm_##j##_##l = diff_##j##_##l; \ - else newpm_##j##_##l = F_##j##_##l; \ - const vector unsigned char newpm2_##j##_##l = \ - vec_splat((vector unsigned char)newpm_##j##_##l, 15); \ - const vector unsigned char mask##j##l = vec_add(identity, \ - tenRightM##i); \ - src##j = vec_perm(src##j, newpm2_##j##_##l, mask##j##l); \ + const vector unsigned char a_A = vec_perm(src##i, src##j, permA1M); \ + const vector unsigned char a_B = vec_perm(a_A, src##k, permA2M); \ + const vector signed int a_sump = \ + (vector signed int)vec_msum(a_B, magic, (vector unsigned int)zero);\ + vector signed int F = vec_sr(vec_sums(a_sump, vsint32_8), vuint32_4); \ + F = vec_splat(F, 3); \ + const vector signed int p = \ + (vector signed int)vec_perm(src##j, (vector unsigned char)zero, \ + extractPermM); \ + const vector signed int sum = vec_add(p, vQP2); \ + const vector signed int diff = vec_sub(p, vQP2); \ + vector signed int newpm; \ + if (vec_all_lt(sum, F)) \ + newpm = sum; \ + else if (vec_all_gt(diff, F)) \ + newpm = diff; \ + else newpm = F; \ + const vector unsigned char newpm2 = \ + vec_splat((vector unsigned char)newpm, 15); \ + const vector unsigned char mask = vec_add(identity, tenRightM); \ + src##j = vec_perm(src##j, newpm2, mask); \ } \ - permA1M##i = vec_add(permA1M##i, permA1inc); \ - permA2M##i = vec_add(permA2M##i, permA2inc); \ - tenRightM##i = vec_sro(tenRightM##i, eightLeft); \ - extractPermM##i = vec_add(extractPermM##i, extractPermInc) + permA1M = vec_add(permA1M, permA1inc); \ + permA2M = vec_add(permA2M, permA2inc); \ + tenRightM = vec_sro(tenRightM, eightLeft); \ + extractPermM = vec_add(extractPermM, extractPermInc) #define ITER(i, j, k) do { \ - F_INIT(i); \ + F_INIT(); \ F2(i, j, k, 0); \ F2(i, j, k, 1); \ F2(i, j, k, 2); \ @@ -801,14 +797,14 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { ITER(7, 8, 9); #define STORE_LINE(i) do { \ - const vector unsigned char permST##i = \ + const vector unsigned char permST = \ vec_lvsr(i * stride, srcCopy); \ - const vector unsigned char maskST##i = \ + const vector unsigned char maskST = \ vec_perm((vector unsigned char)zero, \ - (vector unsigned char)neg1, permST##i);\ - src##i = vec_perm(src##i ,src##i, permST##i); \ - sA##i= vec_sel(sA##i, src##i, maskST##i); \ - sB##i= vec_sel(src##i, sB##i, maskST##i); \ + (vector unsigned char)neg1, permST); \ + src##i = vec_perm(src##i ,src##i, permST); \ + sA##i= vec_sel(sA##i, src##i, maskST); \ + sB##i= vec_sel(src##i, sB##i, maskST); \ vec_st(sA##i, i * stride, srcCopy); \ vec_st(sB##i, i * stride + 16, srcCopy); \ } while (0) @@ -879,11 +875,11 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, #undef LOAD_LINE #define ACCUMULATE_DIFFS(i) do { \ - vector signed short v_d##i = vec_sub(v_tempBlurredAss##i, \ - v_srcAss##i); \ - v_dp = vec_msums(v_d##i, v_d##i, v_dp); \ - v_sysdp = vec_msums(v_d##i, vsint16_1, v_sysdp); \ -} while (0) + vector signed short v_d = vec_sub(v_tempBlurredAss##i, \ + v_srcAss##i); \ + v_dp = vec_msums(v_d, v_d, v_dp); \ + v_sysdp = vec_msums(v_d, vsint16_1, v_sysdp); \ + } while (0) ACCUMULATE_DIFFS(0); ACCUMULATE_DIFFS(1); @@ -945,13 +941,11 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, const vector signed short vsint16_4 = vec_splat_s16(4); const vector unsigned short vuint16_3 = vec_splat_u16(3); -#define OP(i) do { \ - const vector signed short v_temp##i = \ - vec_mladd(v_tempBlurredAss##i, \ - vsint16_7, v_srcAss##i); \ - const vector signed short v_temp2##i = \ - vec_add(v_temp##i, vsint16_4); \ - v_tempBlurredAss##i = vec_sr(v_temp2##i, vuint16_3);\ +#define OP(i) do { \ + const vector signed short v_temp = \ + vec_mladd(v_tempBlurredAss##i, vsint16_7, v_srcAss##i); \ + const vector signed short v_temp2 = vec_add(v_temp, vsint16_4); \ + v_tempBlurredAss##i = vec_sr(v_temp2, vuint16_3); \ } while (0) OP(0); @@ -968,12 +962,11 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, const vector signed short vsint16_2 = vec_splat_s16(2); #define OP(i) do { \ - const vector signed short v_temp##i = \ - vec_mladd(v_tempBlurredAss##i, \ - vsint16_3, v_srcAss##i); \ - const vector signed short v_temp2##i = \ - vec_add(v_temp##i, vsint16_2); \ - v_tempBlurredAss##i = vec_sr(v_temp2##i, (vector unsigned short)vsint16_2); \ + const vector signed short v_temp = \ + vec_mladd(v_tempBlurredAss##i, vsint16_3, v_srcAss##i); \ + const vector signed short v_temp2 = vec_add(v_temp, vsint16_2); \ + v_tempBlurredAss##i = \ + vec_sr(v_temp2, (vector unsigned short)vsint16_2); \ } while (0) OP(0); @@ -988,23 +981,18 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, } } -#define PACK_AND_STORE(src, i) do { \ - const vector unsigned char perms##src##i = \ - vec_lvsr(i * stride, src); \ - const vector unsigned char vf##src##i = \ - vec_packsu(v_tempBlurredAss##i, (vector signed short)zero); \ - const vector unsigned char vg##src##i = \ - vec_perm(vf##src##i, v_##src##A##i, permHH); \ - const vector unsigned char mask##src##i = \ - vec_perm((vector unsigned char)zero, (vector unsigned char)neg1, perms##src##i); \ - const vector unsigned char vg2##src##i = \ - vec_perm(vg##src##i, vg##src##i, perms##src##i); \ - const vector unsigned char svA##src##i = \ - vec_sel(v_##src##A1##i, vg2##src##i, mask##src##i); \ - const vector unsigned char svB##src##i = \ - vec_sel(vg2##src##i, v_##src##A2##i, mask##src##i); \ - vec_st(svA##src##i, i * stride, src); \ - vec_st(svB##src##i, i * stride + 16, src); \ +#define PACK_AND_STORE(src, i) do { \ + const vector unsigned char perms = vec_lvsr(i * stride, src); \ + const vector unsigned char vf = \ + vec_packsu(v_tempBlurredAss##1, (vector signed short)zero); \ + const vector unsigned char vg = vec_perm(vf, v_##src##A##i, permHH); \ + const vector unsigned char mask = \ + vec_perm((vector unsigned char)zero, (vector unsigned char)neg1, perms); \ + const vector unsigned char vg2 = vec_perm(vg, vg, perms); \ + const vector unsigned char svA = vec_sel(v_##src##A1##i, vg2, mask); \ + const vector unsigned char svB = vec_sel(vg2, v_##src##A2##i, mask); \ + vec_st(svA, i * stride, src); \ + vec_st(svB, i * stride + 16, src); \ } while (0) PACK_AND_STORE(src, 0); @@ -1195,24 +1183,26 @@ static inline void transpose_8x16_char_fromPackedAlign_altivec(unsigned char* ds #define STORE_DOUBLE_LINE(i, j) do { \ - vector unsigned char dstA##i = vec_ld(i * stride, dst); \ - vector unsigned char dstB##i = vec_ld(i * stride + 16, dst); \ - vector unsigned char dstA##j = vec_ld(j * stride, dst); \ - vector unsigned char dstB##j = vec_ld(j * stride+ 16, dst); \ - vector unsigned char align##i = vec_lvsr(i * stride, dst); \ - vector unsigned char align##j = vec_lvsr(j * stride, dst); \ - vector unsigned char mask##i = vec_perm(zero, (vector unsigned char)neg1, align##i); \ - vector unsigned char mask##j = vec_perm(zero, (vector unsigned char)neg1, align##j); \ - vector unsigned char dstR##i = vec_perm(temp##i, temp##i, align##i);\ - vector unsigned char dstR##j = vec_perm(temp##j, temp##j, align##j);\ - vector unsigned char dstAF##i = vec_sel(dstA##i, dstR##i, mask##i); \ - vector unsigned char dstBF##i = vec_sel(dstR##i, dstB##i, mask##i); \ - vector unsigned char dstAF##j = vec_sel(dstA##j, dstR##j, mask##j); \ - vector unsigned char dstBF##j = vec_sel(dstR##j, dstB##j, mask##j); \ - vec_st(dstAF##i, i * stride, dst); \ - vec_st(dstBF##i, i * stride + 16, dst); \ - vec_st(dstAF##j, j * stride, dst); \ - vec_st(dstBF##j, j * stride + 16, dst); \ + vector unsigned char dstAi = vec_ld(i * stride, dst); \ + vector unsigned char dstBi = vec_ld(i * stride + 16, dst); \ + vector unsigned char dstAj = vec_ld(j * stride, dst); \ + vector unsigned char dstBj = vec_ld(j * stride+ 16, dst); \ + vector unsigned char aligni = vec_lvsr(i * stride, dst); \ + vector unsigned char alignj = vec_lvsr(j * stride, dst); \ + vector unsigned char maski = \ + vec_perm(zero, (vector unsigned char)neg1, aligni); \ + vector unsigned char maskj = \ + vec_perm(zero, (vector unsigned char)neg1, alignj); \ + vector unsigned char dstRi = vec_perm(temp##i, temp##i, aligni); \ + vector unsigned char dstRj = vec_perm(temp##j, temp##j, alignj); \ + vector unsigned char dstAFi = vec_sel(dstAi, dstRi, maski); \ + vector unsigned char dstBFi = vec_sel(dstRi, dstBi, maski); \ + vector unsigned char dstAFj = vec_sel(dstAj, dstRj, maskj); \ + vector unsigned char dstBFj = vec_sel(dstRj, dstBj, maskj); \ + vec_st(dstAFi, i * stride, dst); \ + vec_st(dstBFi, i * stride + 16, dst); \ + vec_st(dstAFj, j * stride, dst); \ + vec_st(dstBFj, j * stride + 16, dst); \ } while (0) STORE_DOUBLE_LINE(0,1); From 514294e8cab7ab70e69f686a84e7cc6f1192961c Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Tue, 20 Dec 2011 19:07:49 +0000 Subject: [PATCH 03/27] postproc: altivec: fix remaining mixed declarations and code Signed-off-by: Mans Rullgard --- libpostproc/postprocess_altivec_template.c | 30 ++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/libpostproc/postprocess_altivec_template.c b/libpostproc/postprocess_altivec_template.c index 16b6e6910d..ac65df897b 100644 --- a/libpostproc/postprocess_altivec_template.c +++ b/libpostproc/postprocess_altivec_template.c @@ -572,11 +572,9 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { src & stride :-( */ uint8_t *srcCopy = src; - DECLARE_ALIGNED(16, uint8_t, dt)[16]; + DECLARE_ALIGNED(16, uint8_t, dt)[16] = { deringThreshold }; const vector signed int zero = vec_splat_s32(0); - vector unsigned char v_dt; - dt[0] = deringThreshold; - v_dt = vec_splat(vec_ld(0, dt), 0); + vector unsigned char v_dt = vec_splat(vec_ld(0, dt), 0); #define LOAD_LINE(i) \ const vector unsigned char perm##i = \ @@ -599,6 +597,10 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { vector unsigned char v_avg; DECLARE_ALIGNED(16, signed int, S)[8]; + DECLARE_ALIGNED(16, int, tQP2)[4] = { c->QP/2 + 1 }; + vector signed int vQP2 = vec_ld(0, tQP2); + vQP2 = vec_splat(vQP2, 0); + { const vector unsigned char trunc_perm = (vector unsigned char) {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, @@ -736,10 +738,6 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { /* I'm not sure the following is actually faster than straight, unvectorized C code :-( */ - DECLARE_ALIGNED(16, int, tQP2)[4]; - tQP2[0]= c->QP/2 + 1; - vector signed int vQP2 = vec_ld(0, tQP2); - vQP2 = vec_splat(vQP2, 0); #define F_INIT() \ vector unsigned char tenRightM = tenRight; \ vector unsigned char permA1M = permA1; \ @@ -753,21 +751,21 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { const vector signed int a_sump = \ (vector signed int)vec_msum(a_B, magic, (vector unsigned int)zero);\ vector signed int F = vec_sr(vec_sums(a_sump, vsint32_8), vuint32_4); \ - F = vec_splat(F, 3); \ const vector signed int p = \ (vector signed int)vec_perm(src##j, (vector unsigned char)zero, \ extractPermM); \ const vector signed int sum = vec_add(p, vQP2); \ const vector signed int diff = vec_sub(p, vQP2); \ vector signed int newpm; \ + vector unsigned char newpm2, mask; \ + F = vec_splat(F, 3); \ if (vec_all_lt(sum, F)) \ newpm = sum; \ else if (vec_all_gt(diff, F)) \ newpm = diff; \ else newpm = F; \ - const vector unsigned char newpm2 = \ - vec_splat((vector unsigned char)newpm, 15); \ - const vector unsigned char mask = vec_add(identity, tenRightM); \ + newpm2 = vec_splat((vector unsigned char)newpm, 15); \ + mask = vec_add(identity, tenRightM); \ src##j = vec_perm(src##j, newpm2, mask); \ } \ permA1M = vec_add(permA1M, permA1inc); \ @@ -840,10 +838,6 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, vector signed int v_sysdp = zero; int d, sysd, i; - tempBlurredPast[127]= maxNoise[0]; - tempBlurredPast[128]= maxNoise[1]; - tempBlurredPast[129]= maxNoise[2]; - #define LOAD_LINE(src, i) \ register int j##src##i = i * stride; \ vector unsigned char perm##src##i = vec_lvsl(j##src##i, src); \ @@ -891,6 +885,10 @@ static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, ACCUMULATE_DIFFS(7); #undef ACCUMULATE_DIFFS + tempBlurredPast[127]= maxNoise[0]; + tempBlurredPast[128]= maxNoise[1]; + tempBlurredPast[129]= maxNoise[2]; + v_dp = vec_sums(v_dp, zero); v_sysdp = vec_sums(v_sysdp, zero); From 9d6b2077b27980936efdc616e2f9c92a56b443fc Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Tue, 20 Dec 2011 16:32:06 +0000 Subject: [PATCH 04/27] build: error on mixed declarations and code Signed-off-by: Mans Rullgard --- configure | 1 + 1 file changed, 1 insertion(+) diff --git a/configure b/configure index 180578db7e..5cb2d1c0ae 100755 --- a/configure +++ b/configure @@ -3118,6 +3118,7 @@ elif enabled gcc; then check_cflags -fno-tree-vectorize check_cflags -Werror=implicit-function-declaration check_cflags -Werror=missing-prototypes + check_cflags -Werror=declaration-after-statement elif enabled llvm_gcc; then check_cflags -mllvm -stack-alignment=16 elif enabled clang; then From 9f3c77dd2a4fa4accf102c2af1f22567652b8e0f Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 21 Dec 2011 02:50:57 +0100 Subject: [PATCH 05/27] fate: account for NUT 10bit support Some libavifilter tests use NUT as output even if the produced files were not decodable. The support for 10bit introduced in 432f0e5b7d and 91b1e6f0c changed the hashes. --- tests/ref/lavfi/pixdesc | 12 ++++++------ tests/ref/lavfi/pixfmts_copy | 12 ++++++------ tests/ref/lavfi/pixfmts_null | 12 ++++++------ tests/ref/lavfi/pixfmts_scale | 12 ++++++------ tests/ref/lavfi/pixfmts_vflip | 12 ++++++------ 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/ref/lavfi/pixdesc b/tests/ref/lavfi/pixdesc index 90dcbf56bc..a5016eeb22 100644 --- a/tests/ref/lavfi/pixdesc +++ b/tests/ref/lavfi/pixdesc @@ -31,23 +31,23 @@ uyvy422 adcf64516a19fce44df77082bdb16291 yuv410p 2d9225153c83ee1132397d619d94d1b3 yuv411p 8b298af3e43348ca1b11eb8a3252ac6c yuv420p eba2f135a08829387e2f698ff72a2939 -yuv420p10be 7605e266c088d0fcf68c7b27c3ceff5f -yuv420p10le 4228ee628c6deec123a13b9784516cc7 +yuv420p10be 299fe1d785a3d3dd5e70778700d7fb06 +yuv420p10le 8aee004e765a5383be0954f5e916b72f yuv420p16be 16c009a235cd52b74791a895423152a3 yuv420p16le 2d59c4f1d0314a5a957a7cfc4b6fabcc yuv420p9be ce880fa07830e5297c22acf6e20555ce yuv420p9le 16543fda8f87d94a6cf857d2e8d4461a yuv422p c9bba4529821d796a6ab09f6a5fd355a -yuv422p10be bdc13b630fd668b34c6fe1aae28dfc71 -yuv422p10le d0607c260a45c973e6639f4e449730ad +yuv422p10be 11af7dfafe8bc025c7e3bd82b830fe8a +yuv422p10le ec04efb76efa79bf0d02b21572371a56 yuv422p16be 5499502e1c29534a158a1fe60e889f60 yuv422p16le e3d61fde6978591596bc36b914386623 yuv422p9be 29b71579946940a8c00fa844c9dff507 yuv422p9le 062b7f9cbb972bf36b5bdb1a7623701a yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf yuv444p 0a98447b78fd476aa39686da6a74fa2e -yuv444p10be e65cbae7e4f1892c23defbc8e8052cf6 -yuv444p10le 767179dd82846cf00ee4c340c9c1ab74 +yuv444p10be 71be185a2fb7a353eb024df9bc63212d +yuv444p10le c1c6b30a12065c7901c0a267e4861a0f yuv444p16be 1c6ea2c2f5e539006112ceec3d4e7d90 yuv444p16le 20f86bc2f68d2b3f1f2b48b97b2189f4 yuv444p9be 6ab31f4c12b533ce318ecdff83cdd054 diff --git a/tests/ref/lavfi/pixfmts_copy b/tests/ref/lavfi/pixfmts_copy index 90dcbf56bc..a5016eeb22 100644 --- a/tests/ref/lavfi/pixfmts_copy +++ b/tests/ref/lavfi/pixfmts_copy @@ -31,23 +31,23 @@ uyvy422 adcf64516a19fce44df77082bdb16291 yuv410p 2d9225153c83ee1132397d619d94d1b3 yuv411p 8b298af3e43348ca1b11eb8a3252ac6c yuv420p eba2f135a08829387e2f698ff72a2939 -yuv420p10be 7605e266c088d0fcf68c7b27c3ceff5f -yuv420p10le 4228ee628c6deec123a13b9784516cc7 +yuv420p10be 299fe1d785a3d3dd5e70778700d7fb06 +yuv420p10le 8aee004e765a5383be0954f5e916b72f yuv420p16be 16c009a235cd52b74791a895423152a3 yuv420p16le 2d59c4f1d0314a5a957a7cfc4b6fabcc yuv420p9be ce880fa07830e5297c22acf6e20555ce yuv420p9le 16543fda8f87d94a6cf857d2e8d4461a yuv422p c9bba4529821d796a6ab09f6a5fd355a -yuv422p10be bdc13b630fd668b34c6fe1aae28dfc71 -yuv422p10le d0607c260a45c973e6639f4e449730ad +yuv422p10be 11af7dfafe8bc025c7e3bd82b830fe8a +yuv422p10le ec04efb76efa79bf0d02b21572371a56 yuv422p16be 5499502e1c29534a158a1fe60e889f60 yuv422p16le e3d61fde6978591596bc36b914386623 yuv422p9be 29b71579946940a8c00fa844c9dff507 yuv422p9le 062b7f9cbb972bf36b5bdb1a7623701a yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf yuv444p 0a98447b78fd476aa39686da6a74fa2e -yuv444p10be e65cbae7e4f1892c23defbc8e8052cf6 -yuv444p10le 767179dd82846cf00ee4c340c9c1ab74 +yuv444p10be 71be185a2fb7a353eb024df9bc63212d +yuv444p10le c1c6b30a12065c7901c0a267e4861a0f yuv444p16be 1c6ea2c2f5e539006112ceec3d4e7d90 yuv444p16le 20f86bc2f68d2b3f1f2b48b97b2189f4 yuv444p9be 6ab31f4c12b533ce318ecdff83cdd054 diff --git a/tests/ref/lavfi/pixfmts_null b/tests/ref/lavfi/pixfmts_null index 90dcbf56bc..a5016eeb22 100644 --- a/tests/ref/lavfi/pixfmts_null +++ b/tests/ref/lavfi/pixfmts_null @@ -31,23 +31,23 @@ uyvy422 adcf64516a19fce44df77082bdb16291 yuv410p 2d9225153c83ee1132397d619d94d1b3 yuv411p 8b298af3e43348ca1b11eb8a3252ac6c yuv420p eba2f135a08829387e2f698ff72a2939 -yuv420p10be 7605e266c088d0fcf68c7b27c3ceff5f -yuv420p10le 4228ee628c6deec123a13b9784516cc7 +yuv420p10be 299fe1d785a3d3dd5e70778700d7fb06 +yuv420p10le 8aee004e765a5383be0954f5e916b72f yuv420p16be 16c009a235cd52b74791a895423152a3 yuv420p16le 2d59c4f1d0314a5a957a7cfc4b6fabcc yuv420p9be ce880fa07830e5297c22acf6e20555ce yuv420p9le 16543fda8f87d94a6cf857d2e8d4461a yuv422p c9bba4529821d796a6ab09f6a5fd355a -yuv422p10be bdc13b630fd668b34c6fe1aae28dfc71 -yuv422p10le d0607c260a45c973e6639f4e449730ad +yuv422p10be 11af7dfafe8bc025c7e3bd82b830fe8a +yuv422p10le ec04efb76efa79bf0d02b21572371a56 yuv422p16be 5499502e1c29534a158a1fe60e889f60 yuv422p16le e3d61fde6978591596bc36b914386623 yuv422p9be 29b71579946940a8c00fa844c9dff507 yuv422p9le 062b7f9cbb972bf36b5bdb1a7623701a yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf yuv444p 0a98447b78fd476aa39686da6a74fa2e -yuv444p10be e65cbae7e4f1892c23defbc8e8052cf6 -yuv444p10le 767179dd82846cf00ee4c340c9c1ab74 +yuv444p10be 71be185a2fb7a353eb024df9bc63212d +yuv444p10le c1c6b30a12065c7901c0a267e4861a0f yuv444p16be 1c6ea2c2f5e539006112ceec3d4e7d90 yuv444p16le 20f86bc2f68d2b3f1f2b48b97b2189f4 yuv444p9be 6ab31f4c12b533ce318ecdff83cdd054 diff --git a/tests/ref/lavfi/pixfmts_scale b/tests/ref/lavfi/pixfmts_scale index 8ca9cbf78d..7abe0d723d 100644 --- a/tests/ref/lavfi/pixfmts_scale +++ b/tests/ref/lavfi/pixfmts_scale @@ -31,23 +31,23 @@ uyvy422 314bd486277111a95d9369b944fa0400 yuv410p 7df8f6d69b56a8dcb6c7ee908e5018b5 yuv411p 1143e7c5cc28fe0922b051b17733bc4c yuv420p fdad2d8df8985e3d17e73c71f713cb14 -yuv420p10be c143e77e97d2f7d62c3b518857ba9f9b -yuv420p10le 72d90eccf5c34691ff057dafb7447aa2 +yuv420p10be 27f28a6e09b1c04d0f755035a5db1f43 +yuv420p10le a5a1692e026590ba2eddb46b9b827529 yuv420p16be d7270efce54eb59c7b01c14157a1b890 yuv420p16le e85abf00bad940a922b623c91c9026d7 yuv420p9be bb87fddca65d1742412c8d2b1caf96c6 yuv420p9le 828eec50014a41258a5423c1fe56ac97 yuv422p 918e37701ee7377d16a8a6c119c56a40 -yuv422p10be cea7ca6b0e66d6f29539885896c88603 -yuv422p10le a10c4a5837547716f13cd61918b145f9 +yuv422p10be 315654908d50718e175aae018c484732 +yuv422p10le 91bbc78a9a56f659b55abc17722dcc09 yuv422p16be e7e34fe9264784763ab6cb406524c0f3 yuv422p16le c435b76b08204dda6908640fb5fd4621 yuv422p9be 82494823944912f73cebc58ad2979bbd yuv422p9le fc69c8a21f473916a4b4225636b97e06 yuv440p 461503fdb9b90451020aa3b25ddf041c yuv444p 81b2eba962d12e8d64f003ac56f6faf2 -yuv444p10be e9d3c8e744b8b0d8187ca092fa203fc9 -yuv444p10le 02f0a336e9da062a64df1ba487e102c5 +yuv444p10be fb304d77c6d2e18df5938662a22176f0 +yuv444p10le b17136913eb066dca6be6af645b9f7e8 yuv444p16be 0da9bed80f5542682ab286f3261cf24c yuv444p16le a0c5d3c7bf3f181db503cf8e450d1335 yuv444p9be 9ac2643ce7f7e5c4e17c8c9fd8494d4a diff --git a/tests/ref/lavfi/pixfmts_vflip b/tests/ref/lavfi/pixfmts_vflip index 4aaef16b5a..e834394a71 100644 --- a/tests/ref/lavfi/pixfmts_vflip +++ b/tests/ref/lavfi/pixfmts_vflip @@ -31,23 +31,23 @@ uyvy422 ffbd36720c77398d9a0d03ce2625928f yuv410p 7bfb39d7afb49d6a6173e6b23ae321eb yuv411p 4a90048cc3a65fac150e53289700efe1 yuv420p 2e6d6062e8cad37fb3ab2c433b55f382 -yuv420p10be df97d20b3b4a10c174d4360552c4160d -yuv420p10le 4b5249208602b941332945c926f80ae9 +yuv420p10be fb0772f5e2b9da20ff826e64c3893137 +yuv420p10le e95879e14c4a6805f39643964baf41f7 yuv420p16be 539076782902664a8acf381bf4f713e8 yuv420p16le 0f609e588e5a258644ef85170d70e030 yuv420p9be be40ec975fb2873891643cbbbddbc3b0 yuv420p9le 7e606310d3f5ff12badf911e8f333471 yuv422p d7f5cb44d9b0210d66d6a8762640ab34 -yuv422p10be 588fe319b96513c32e21d3e32b45447f -yuv422p10le 11b57f2bd9661024153f3973b9090cdb +yuv422p10be 0be8378c3773e1c0b394315ef4994351 +yuv422p10le 6518094fe8de6bee95af21af1e5dc1e1 yuv422p16be 9bd8f8c961822b586fa4cf992be54acc yuv422p16le 9c4a1239605c7952b736ac3130163f14 yuv422p9be 7c6f1e140b3999ee7d923854e507752a yuv422p9le 51f10d79c07989060dd06e767e6d7d60 yuv440p 876385e96165acf51271b20e5d85a416 yuv444p 9c3c667d1613b72d15bc6d851c5eb8f7 -yuv444p10be 944a4997c4edb3a8dd0f0493cfd5a1fd -yuv444p10le 2d0947ae89ecc6a501eee6832cb27e06 +yuv444p10be ee069cc6db48975eb029d72f889a7fe6 +yuv444p10le 645b3335248113cafe3c29edb1d7f3be yuv444p16be de2dedfc6f12073ffead113f86e07ecf yuv444p16le 8e83323cf102d6c823a03ae8a7b7e033 yuv444p9be 6ac92b7dc9ab2fc59bee99204886899a From 139cef8e29bd14de66e29e37722fb09ab2b7e9c5 Mon Sep 17 00:00:00 2001 From: Sergey Radionov Date: Wed, 21 Dec 2011 09:19:10 +0700 Subject: [PATCH 06/27] network: properly declare WSADATA in windows Fixed "ISO C90 forbids mixed declarations and code" in ff_network_init Signed-off-by: Luca Barbato --- libavformat/network.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavformat/network.c b/libavformat/network.c index f8403aef83..bfc34c72a7 100644 --- a/libavformat/network.c +++ b/libavformat/network.c @@ -123,13 +123,16 @@ int ff_network_inited_globally; int ff_network_init(void) { +#if HAVE_WINSOCK2_H + WSADATA wsaData; +#endif + if (!ff_network_inited_globally) av_log(NULL, AV_LOG_WARNING, "Using network protocols without global " "network initialization. Please use " "avformat_network_init(), this will " "become mandatory later.\n"); #if HAVE_WINSOCK2_H - WSADATA wsaData; if (WSAStartup(MAKEWORD(1,1), &wsaData)) return 0; #endif From 021914e27fe943649e26ea82b2bbd67c89c7c324 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 20 Dec 2011 10:36:27 -0800 Subject: [PATCH 07/27] aacdec: Cleanup decode_ics_info. Remove unused function argument. Return an AVERROR. Don't zero out ICS on failure. --- libavcodec/aacdec.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index 70396b63fa..4d002edf6a 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -703,16 +703,13 @@ static void decode_ltp(AACContext *ac, LongTermPrediction *ltp, /** * Decode Individual Channel Stream info; reference: table 4.6. - * - * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information. */ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, - GetBitContext *gb, int common_window) + GetBitContext *gb) { if (get_bits1(gb)) { av_log(ac->avctx, AV_LOG_ERROR, "Reserved bit set.\n"); - memset(ics, 0, sizeof(IndividualChannelStream)); - return -1; + return AVERROR_INVALIDDATA; } ics->window_sequence[1] = ics->window_sequence[0]; ics->window_sequence[0] = get_bits(gb, 2); @@ -747,13 +744,11 @@ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, if (ics->predictor_present) { if (ac->m4ac.object_type == AOT_AAC_MAIN) { if (decode_prediction(ac, ics, gb)) { - memset(ics, 0, sizeof(IndividualChannelStream)); - return -1; + return AVERROR_INVALIDDATA; } } else if (ac->m4ac.object_type == AOT_AAC_LC) { av_log(ac->avctx, AV_LOG_ERROR, "Prediction is not allowed in AAC-LC.\n"); - memset(ics, 0, sizeof(IndividualChannelStream)); - return -1; + return AVERROR_INVALIDDATA; } else { if ((ics->ltp.present = get_bits(gb, 1))) decode_ltp(ac, &ics->ltp, gb, ics->max_sfb); @@ -765,8 +760,7 @@ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, av_log(ac->avctx, AV_LOG_ERROR, "Number of scalefactor bands in group (%d) exceeds limit (%d).\n", ics->max_sfb, ics->num_swb); - memset(ics, 0, sizeof(IndividualChannelStream)); - return -1; + return AVERROR_INVALIDDATA; } return 0; @@ -1371,8 +1365,8 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce, global_gain = get_bits(gb, 8); if (!common_window && !scale_flag) { - if (decode_ics_info(ac, ics, gb, 0) < 0) - return -1; + if (decode_ics_info(ac, ics, gb) < 0) + return AVERROR_INVALIDDATA; } if (decode_band_types(ac, sce->band_type, sce->band_type_run_end, gb, ics) < 0) @@ -1488,8 +1482,8 @@ static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe) common_window = get_bits1(gb); if (common_window) { - if (decode_ics_info(ac, &cpe->ch[0].ics, gb, 1)) - return -1; + if (decode_ics_info(ac, &cpe->ch[0].ics, gb)) + return AVERROR_INVALIDDATA; i = cpe->ch[1].ics.use_kb_window[0]; cpe->ch[1].ics = cpe->ch[0].ics; cpe->ch[1].ics.use_kb_window[1] = i; From 2003a29284660255016b1ec4bd5dfb8d53e6a852 Mon Sep 17 00:00:00 2001 From: Sergey Radionov Date: Wed, 21 Dec 2011 09:08:56 +0700 Subject: [PATCH 08/27] w32threads: wait for the waked thread in pthread_cond_signal. This fixes a deadlock VLC triggered with multithreaded decoding. The wait forces one of the current waiters to wake and not the thread which calls pthread_cond_signal() itself. Signed-off-by: Ronald S. Bultje --- libavcodec/w32pthreads.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libavcodec/w32pthreads.h b/libavcodec/w32pthreads.h index 2d1470c5ee..3cdbc2c343 100644 --- a/libavcodec/w32pthreads.h +++ b/libavcodec/w32pthreads.h @@ -139,7 +139,7 @@ static void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr) win32_cond->semaphore = CreateSemaphore(NULL, 0, 0x7fffffff, NULL); if (!win32_cond->semaphore) return; - win32_cond->waiters_done = CreateEvent(NULL, FALSE, FALSE, NULL); + win32_cond->waiters_done = CreateEvent(NULL, TRUE, FALSE, NULL); if (!win32_cond->waiters_done) return; @@ -204,11 +204,10 @@ static void pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) /* non native condition variables */ pthread_mutex_lock(&win32_cond->mtx_broadcast); - pthread_mutex_unlock(&win32_cond->mtx_broadcast); - pthread_mutex_lock(&win32_cond->mtx_waiter_count); win32_cond->waiter_count++; pthread_mutex_unlock(&win32_cond->mtx_waiter_count); + pthread_mutex_unlock(&win32_cond->mtx_broadcast); // unlock the external mutex pthread_mutex_unlock(mutex); @@ -216,7 +215,7 @@ static void pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) pthread_mutex_lock(&win32_cond->mtx_waiter_count); win32_cond->waiter_count--; - last_waiter = !win32_cond->waiter_count && win32_cond->is_broadcast; + last_waiter = !win32_cond->waiter_count || !win32_cond->is_broadcast; pthread_mutex_unlock(&win32_cond->mtx_waiter_count); if (last_waiter) @@ -235,13 +234,20 @@ static void pthread_cond_signal(pthread_cond_t *cond) return; } + pthread_mutex_lock(&win32_cond->mtx_broadcast); + /* non-native condition variables */ pthread_mutex_lock(&win32_cond->mtx_waiter_count); have_waiter = win32_cond->waiter_count; pthread_mutex_unlock(&win32_cond->mtx_waiter_count); - if (have_waiter) + if (have_waiter) { ReleaseSemaphore(win32_cond->semaphore, 1, NULL); + WaitForSingleObject(win32_cond->waiters_done, INFINITE); + ResetEvent(win32_cond->waiters_done); + } + + pthread_mutex_unlock(&win32_cond->mtx_broadcast); } static void w32thread_init(void) From 8742a4ff87b5d6ff9f8b5095a29f2e7e7147b5d8 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Tue, 20 Dec 2011 18:57:30 +0100 Subject: [PATCH 09/27] h264_cabac: synchronize decode_significance_*_x86 conditionals The definition and the call site where under different #ifdefs. --- libavcodec/h264_cabac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c index bb0a0ee732..fdeb1ba470 100644 --- a/libavcodec/h264_cabac.c +++ b/libavcodec/h264_cabac.c @@ -1656,7 +1656,7 @@ decode_cabac_residual_internal(H264Context *h, DCTELEM *block, index[coeff_count++] = last;\ } const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD]; -#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) +#if ARCH_X86 && HAVE_6REGS && !defined(BROKEN_RELOCATIONS) coeff_count= decode_significance_8x8_x86(CC, significant_coeff_ctx_base, index, last_coeff_ctx_base, sig_off); } else { From c18365402bbb6fbfa7854b47c3288f9e31f39f44 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Tue, 20 Dec 2011 23:51:55 +0100 Subject: [PATCH 10/27] Replace Subversion revisions in comments by Git hashes. --- libavcodec/lpc.c | 5 +++-- libavutil/aes.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libavcodec/lpc.c b/libavcodec/lpc.c index 874af0513e..d1833cbed7 100644 --- a/libavcodec/lpc.c +++ b/libavcodec/lpc.c @@ -35,8 +35,9 @@ static void lpc_apply_welch_window_c(const int32_t *data, int len, double w; double c; - assert(!(len&1)); //the optimization in r11881 does not support odd len - //if someone wants odd len extend the change in r11881 + /* The optimization in commit fa4ed8c does not support odd len. + * If someone wants odd len extend that change. */ + assert(!(len & 1)); n2 = (len >> 1); c = 2.0 / (len - 1.0); diff --git a/libavutil/aes.c b/libavutil/aes.c index 0301e0395c..6803c7190d 100644 --- a/libavutil/aes.c +++ b/libavutil/aes.c @@ -33,7 +33,7 @@ typedef union { typedef struct AVAES { // Note: round_key[16] is accessed in the init code, but this only - // overwrites state, which does not matter (see also r7471). + // overwrites state, which does not matter (see also commit ba554c0). av_aes_block round_key[15]; av_aes_block state[2]; int rounds; From 6fdb2ce34a765de95c0fe341cbcbfa0b1a21a82d Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 21 Dec 2011 11:39:39 +0100 Subject: [PATCH 11/27] x86: Tighten register constraints for decode_significance*_x86. On 32-bit OS X with gcc 4.0/4.2 and shared libraries enabled, the ebx register is not available, but required to assemble the functions. This reverts commit 8742a4f to a simplified version of the original constraints. --- libavcodec/h264_cabac.c | 2 +- libavcodec/x86/h264_i386.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c index fdeb1ba470..a96f52e004 100644 --- a/libavcodec/h264_cabac.c +++ b/libavcodec/h264_cabac.c @@ -1656,7 +1656,7 @@ decode_cabac_residual_internal(H264Context *h, DCTELEM *block, index[coeff_count++] = last;\ } const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD]; -#if ARCH_X86 && HAVE_6REGS && !defined(BROKEN_RELOCATIONS) +#if ARCH_X86 && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) coeff_count= decode_significance_8x8_x86(CC, significant_coeff_ctx_base, index, last_coeff_ctx_base, sig_off); } else { diff --git a/libavcodec/x86/h264_i386.h b/libavcodec/x86/h264_i386.h index 50e80d0f7a..6cd81feae0 100644 --- a/libavcodec/x86/h264_i386.h +++ b/libavcodec/x86/h264_i386.h @@ -36,7 +36,7 @@ //FIXME use some macros to avoid duplicating get_cabac (cannot be done yet //as that would make optimization work hard) -#if HAVE_6REGS && !defined(BROKEN_RELOCATIONS) +#if HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) static int decode_significance_x86(CABACContext *c, int max_coeff, uint8_t *significant_coeff_ctx_base, int *index, x86_reg last_off){ @@ -144,6 +144,6 @@ static int decode_significance_8x8_x86(CABACContext *c, ); return coeff_count; } -#endif /* HAVE_6REGS && !defined(BROKEN_RELOCATIONS) */ +#endif /* HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) */ #endif /* AVCODEC_X86_H264_I386_H */ From 9c984b1bd726997ea48a1441a3a84ce97648706d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 21 Dec 2011 15:32:39 +0200 Subject: [PATCH 12/27] configure: Show whether the safe bitstream reader is enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- configure | 1 + 1 file changed, 1 insertion(+) diff --git a/configure b/configure index 5cb2d1c0ae..1c7fb3b7ec 100755 --- a/configure +++ b/configure @@ -3205,6 +3205,7 @@ echo "postprocessing support ${postproc-no}" echo "new filter support ${avfilter-no}" echo "network support ${network-no}" echo "threading support ${thread_type-no}" +echo "safe bitstream reader ${safe_bitstream_reader-no}" echo "SDL support ${sdl-no}" echo "Sun medialib support ${mlib-no}" echo "libdxva2 enabled ${dxva2-no}" From 4ee04247f0aaf8e40b3bc4ab2c4b3b7dc97eb8bd Mon Sep 17 00:00:00 2001 From: Baptiste Coudurier Date: Mon, 15 Aug 2011 00:40:54 +0200 Subject: [PATCH 13/27] mxf: H.264/MPEG-4 AVC Intra support Signed-off-by: Janne Grunau --- libavformat/mxf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/mxf.c b/libavformat/mxf.c index 029486f6d8..44d0d65251 100644 --- a/libavformat/mxf.c +++ b/libavformat/mxf.c @@ -42,6 +42,7 @@ const MXFCodecUL ff_mxf_codec_uls[] = { { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 }, 14, CODEC_ID_JPEG2000 }, /* JPEG2000 Codestream */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x01,0x7F,0x00,0x00,0x00 }, 13, CODEC_ID_RAWVIDEO }, /* Uncompressed */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x03,0x02,0x00,0x00 }, 14, CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x00,0x00 }, 14, CODEC_ID_H264 }, /* H.264/MPEG-4 AVC Intra */ /* SoundEssenceCompression */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, 13, CODEC_ID_PCM_S16LE }, /* Uncompressed */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x7F,0x00,0x00,0x00 }, 13, CODEC_ID_PCM_S16LE }, From adff77f28cebfce6eedad17a6ab046bfbc0b99f7 Mon Sep 17 00:00:00 2001 From: Daniel Kristjansson Date: Fri, 16 Sep 2011 18:16:30 +0200 Subject: [PATCH 14/27] mxfenc: Add support for MPEG-2 MP@HL-14 in mxf container. Support Main Profile at High 1440 Level in MXF container, using essence coding label from SMPTE RDD 9, table 6. Signed-off-by: Janne Grunau --- libavformat/mxfenc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 78d3650e03..65935ab8ff 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -1285,6 +1285,8 @@ static const UID mxf_mpeg2_codec_uls[] = { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, // MP-HL Long GOP { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, // 422P-HL I-Frame { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, // 422P-HL Long GOP + { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x02,0x00 }, // MP@H-14 I-Frame + { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x03,0x00 }, // MP@H-14 Long GOP }; static const UID *mxf_get_mpeg2_codec_ul(AVCodecContext *avctx) @@ -1296,6 +1298,8 @@ static const UID *mxf_get_mpeg2_codec_ul(AVCodecContext *avctx) return &mxf_mpeg2_codec_uls[0+long_gop]; else if (avctx->level == 4) // High return &mxf_mpeg2_codec_uls[4+long_gop]; + else if (avctx->level == 6) // High 14 + return &mxf_mpeg2_codec_uls[8+long_gop]; } else if (avctx->profile == 0) { // 422 if (avctx->level == 5) // Main return &mxf_mpeg2_codec_uls[2+long_gop]; From 6547fd92647119c0ce526d4e0a2d3d4a7dcfd3bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= Date: Tue, 27 Sep 2011 11:14:59 +0200 Subject: [PATCH 15/27] mxfdec: consider QuantizationBits between 17 and 24 to be pcm_s24* This fixes playback of BRD38772509.mxf. Signed-off-by: Janne Grunau --- libavformat/mxfdec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 2a455d7d51..c4c3f59287 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -831,12 +831,12 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) st->codec->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den; /* TODO: implement CODEC_ID_RAWAUDIO */ if (st->codec->codec_id == CODEC_ID_PCM_S16LE) { - if (descriptor->bits_per_sample == 24) + if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24) st->codec->codec_id = CODEC_ID_PCM_S24LE; else if (descriptor->bits_per_sample == 32) st->codec->codec_id = CODEC_ID_PCM_S32LE; } else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) { - if (descriptor->bits_per_sample == 24) + if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24) st->codec->codec_id = CODEC_ID_PCM_S24BE; else if (descriptor->bits_per_sample == 32) st->codec->codec_id = CODEC_ID_PCM_S32BE; From c15da5941d55eadf7cc4a4e0207ef1b8a4bf9c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= Date: Mon, 26 Sep 2011 11:24:11 +0200 Subject: [PATCH 16/27] mxf: Add PictureEssenceCoding UL for V210. Signed-off-by: Janne Grunau --- libavformat/mxf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/mxf.c b/libavformat/mxf.c index 44d0d65251..e4d9fbd542 100644 --- a/libavformat/mxf.c +++ b/libavformat/mxf.c @@ -43,6 +43,7 @@ const MXFCodecUL ff_mxf_codec_uls[] = { { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x01,0x7F,0x00,0x00,0x00 }, 13, CODEC_ID_RAWVIDEO }, /* Uncompressed */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x03,0x02,0x00,0x00 }, 14, CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x00,0x00 }, 14, CODEC_ID_H264 }, /* H.264/MPEG-4 AVC Intra */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x02,0x00 }, 15, CODEC_ID_V210 }, /* V210 */ /* SoundEssenceCompression */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, 13, CODEC_ID_PCM_S16LE }, /* Uncompressed */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x7F,0x00,0x00,0x00 }, 13, CODEC_ID_PCM_S16LE }, From 17c84f4ed2dcc617b45a0e305725bfca7bc0bfd1 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sat, 10 Dec 2011 14:42:46 -0500 Subject: [PATCH 17/27] flacdec: skip all track indices at once instead of looping. Signed-off-by: Justin Ruggles --- libavformat/flacdec.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index f3831c19ba..9e083d116c 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -102,7 +102,7 @@ static int flac_read_header(AVFormatContext *s, uint8_t isrc[13]; uint64_t start; const uint8_t *offset; - int i, j, chapters, track, ti; + int i, chapters, track, ti; if (metadata_size < 431) return AVERROR_INVALIDDATA; offset = buffer + 395; @@ -119,8 +119,7 @@ static int flac_read_header(AVFormatContext *s, offset += 14; ti = bytestream_get_byte(&offset); if (ti <= 0) return AVERROR_INVALIDDATA; - for (j = 0; j < ti; j++) - offset += 12; + offset += ti * 12; avpriv_new_chapter(s, track, st->time_base, start, AV_NOPTS_VALUE, isrc); } } else { From 195c123cc87bb46efbadb48b2f756ae49bdb6774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 15 Dec 2011 16:11:49 +0200 Subject: [PATCH 18/27] libavcodec: Define a side data type for new extradata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/avcodec.h | 1 + libavcodec/version.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 7f4651b80f..f78a7a61ff 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -855,6 +855,7 @@ typedef struct AVPanScan{ enum AVPacketSideDataType { AV_PKT_DATA_PALETTE, + AV_PKT_DATA_NEW_EXTRADATA, }; typedef struct AVPacket { diff --git a/libavcodec/version.h b/libavcodec/version.h index e95825139d..f570ef779f 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -21,8 +21,8 @@ #define AVCODEC_VERSION_H #define LIBAVCODEC_VERSION_MAJOR 53 -#define LIBAVCODEC_VERSION_MINOR 28 -#define LIBAVCODEC_VERSION_MICRO 1 +#define LIBAVCODEC_VERSION_MINOR 29 +#define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ From 251f320f7deeae22d25c013fb29d162517dd3c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 15 Dec 2011 16:29:55 +0200 Subject: [PATCH 19/27] flvdec: Export new AAC/H.264 extradata as side data on the next packet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compared to just overwriting the old extradata, this has the advantage of letting the decoder know exactly when the extradata changed (otherwise it is changed immediately when the new extradata packet is demuxed, even if there's old queued packets awaiting to be decoded). This makes it easier for decoders to actually react to the change, so they won't have to inspect the extradata for each packet to see if it might have changed. This works when sequentially playing a file with sample rate changes, but if seeking past a new extradata packet in the file, it obviously doesn't work properly. That case doesn't work in flash player either, so it's probably ok not to handle it. Signed-off-by: Martin Storsjö --- libavformat/flvdec.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 4fc5a4949e..22480615bb 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -41,6 +41,8 @@ typedef struct { int wrong_dts; ///< wrong dts due to negative cts + uint8_t *new_extradata[2]; + int new_extradata_size[2]; } FLVContext; static int flv_probe(AVProbeData *p) @@ -401,6 +403,14 @@ static int flv_read_header(AVFormatContext *s, return 0; } +static int flv_read_close(AVFormatContext *s) +{ + FLVContext *flv = s->priv_data; + av_freep(&flv->new_extradata[0]); + av_freep(&flv->new_extradata[1]); + return 0; +} + static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size) { av_free(st->codec->extradata); @@ -412,6 +422,18 @@ static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size) return 0; } +static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream, + int size) +{ + av_free(flv->new_extradata[stream]); + flv->new_extradata[stream] = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!flv->new_extradata[stream]) + return AVERROR(ENOMEM); + flv->new_extradata_size[stream] = size; + avio_read(pb, flv->new_extradata[stream], size); + return 0; +} + static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) { FLVContext *flv = s->priv_data; @@ -529,6 +551,12 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) dts = AV_NOPTS_VALUE; } if (type == 0) { + if (st->codec->extradata) { + if ((ret = flv_queue_extradata(flv, s->pb, is_audio, size)) < 0) + return ret; + ret = AVERROR(EAGAIN); + goto leave; + } if ((ret = flv_get_extradata(s, st, size)) < 0) return ret; if (st->codec->codec_id == CODEC_ID_AAC) { @@ -565,6 +593,16 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->dts = dts; pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts; pkt->stream_index = st->index; + if (flv->new_extradata[is_audio]) { + uint8_t *side = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, + flv->new_extradata_size[is_audio]); + if (side) { + memcpy(side, flv->new_extradata[is_audio], + flv->new_extradata_size[is_audio]); + av_freep(&flv->new_extradata[is_audio]); + flv->new_extradata_size[is_audio] = 0; + } + } if (is_audio || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY)) pkt->flags |= AV_PKT_FLAG_KEY; @@ -618,6 +656,7 @@ AVInputFormat ff_flv_demuxer = { #if 0 .read_seek2 = flv_read_seek2, #endif + .read_close = flv_read_close, .extensions = "flv", .value = CODEC_ID_FLV1, }; From 132846b0c86303ec99a1c9288ef74384a7ebd669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 15 Dec 2011 16:53:19 +0200 Subject: [PATCH 20/27] aacdec: Handle new extradata passed as side data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/aacdec.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index 4d002edf6a..4d3f1ff0d0 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -2247,12 +2247,31 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, static int aac_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { + AACContext *ac = avctx->priv_data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; GetBitContext gb; int buf_consumed; int buf_offset; int err; + int new_extradata_size; + const uint8_t *new_extradata = av_packet_get_side_data(avpkt, + AV_PKT_DATA_NEW_EXTRADATA, + &new_extradata_size); + + if (new_extradata) { + av_free(avctx->extradata); + avctx->extradata = av_mallocz(new_extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + if (!avctx->extradata) + return AVERROR(ENOMEM); + avctx->extradata_size = new_extradata_size; + memcpy(avctx->extradata, new_extradata, new_extradata_size); + if (decode_audio_specific_config(ac, ac->avctx, &ac->m4ac, + avctx->extradata, + avctx->extradata_size*8, 1) < 0) + return AVERROR_INVALIDDATA; + } init_get_bits(&gb, buf, buf_size * 8); From fe75dc8583b65612f3a94144ee090e741dc926d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 15 Dec 2011 18:30:03 +0200 Subject: [PATCH 21/27] libavcodec: Define a side data type for parameter changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also define a codec capability for codecs that can handle parameters changed externally between decoded packets. Signed-off-by: Martin Storsjö --- libavcodec/avcodec.h | 26 ++++++++++++++++++++++++++ libavcodec/version.h | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index f78a7a61ff..6ce3224bfb 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -773,6 +773,10 @@ typedef struct RcOverride{ * Codec supports slice-based (or partition-based) multithreading. */ #define CODEC_CAP_SLICE_THREADS 0x2000 +/** + * Codec supports changed parameters at any point. + */ +#define CODEC_CAP_PARAM_CHANGE 0x4000 //The following defines may change, don't expect compatibility if you use them. #define MB_TYPE_INTRA4x4 0x0001 @@ -856,6 +860,7 @@ typedef struct AVPanScan{ enum AVPacketSideDataType { AV_PKT_DATA_PALETTE, AV_PKT_DATA_NEW_EXTRADATA, + AV_PKT_DATA_PARAM_CHANGE, }; typedef struct AVPacket { @@ -924,6 +929,27 @@ typedef struct AVPacket { #define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted +/** + * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows: + * u32le param_flags + * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) + * s32le channel_count + * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) + * u64le channel_layout + * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) + * s32le sample_rate + * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) + * s32le width + * s32le height + */ + +enum AVSideDataParamChangeFlags { + AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT = 0x0001, + AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002, + AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004, + AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008, +}; + /** * Audio Video Frame. * New fields can be added to the end of AVFRAME with minor version diff --git a/libavcodec/version.h b/libavcodec/version.h index f570ef779f..80e12c14ea 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -21,7 +21,7 @@ #define AVCODEC_VERSION_H #define LIBAVCODEC_VERSION_MAJOR 53 -#define LIBAVCODEC_VERSION_MINOR 29 +#define LIBAVCODEC_VERSION_MINOR 30 #define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ From 3e79c2adb16e4085ffdcac6055ef8379b70224c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 16 Dec 2011 12:48:09 +0200 Subject: [PATCH 22/27] libavformat: Add a utility function for adding parameter change side data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/internal.h | 8 ++++++++ libavformat/utils.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/libavformat/internal.h b/libavformat/internal.h index 45736687d3..559e710014 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -299,4 +299,12 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index, void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den); +/** + * Add side data to a packet for changing parameters to the given values. + * Parameters set to 0 aren't included in the change. + */ +int ff_add_param_change(AVPacket *pkt, int32_t channels, + uint64_t channel_layout, int32_t sample_rate, + int32_t width, int32_t height); + #endif /* AVFORMAT_INTERNAL_H */ diff --git a/libavformat/utils.c b/libavformat/utils.c index bc5b7e02da..aa2c276b90 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -25,6 +25,7 @@ #include "avio_internal.h" #include "internal.h" #include "libavcodec/internal.h" +#include "libavcodec/bytestream.h" #include "libavutil/opt.h" #include "libavutil/dict.h" #include "libavutil/pixdesc.h" @@ -4017,3 +4018,45 @@ int avformat_network_deinit(void) #endif return 0; } + +int ff_add_param_change(AVPacket *pkt, int32_t channels, + uint64_t channel_layout, int32_t sample_rate, + int32_t width, int32_t height) +{ + uint32_t flags = 0; + int size = 4; + uint8_t *data; + if (!pkt) + return AVERROR(EINVAL); + if (channels) { + size += 4; + flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT; + } + if (channel_layout) { + size += 8; + flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT; + } + if (sample_rate) { + size += 4; + flags |= AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE; + } + if (width || height) { + size += 8; + flags |= AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS; + } + data = av_packet_new_side_data(pkt, AV_PKT_DATA_PARAM_CHANGE, size); + if (!data) + return AVERROR(ENOMEM); + bytestream_put_le32(&data, flags); + if (channels) + bytestream_put_le32(&data, channels); + if (channel_layout) + bytestream_put_le64(&data, channel_layout); + if (sample_rate) + bytestream_put_le32(&data, sample_rate); + if (width || height) { + bytestream_put_le32(&data, width); + bytestream_put_le32(&data, height); + } + return 0; +} From 2215c39e94e01f57b3191a29e0e51d7e230daf49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 16 Dec 2011 12:48:24 +0200 Subject: [PATCH 23/27] flvdec: Add param change side data if the sample rate or channels have changed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/flvdec.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 22480615bb..4f1c805c81 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -43,6 +43,8 @@ typedef struct { int wrong_dts; ///< wrong dts due to negative cts uint8_t *new_extradata[2]; int new_extradata_size[2]; + int last_sample_rate; + int last_channels; } FLVContext; static int flv_probe(AVProbeData *p) @@ -56,8 +58,7 @@ static int flv_probe(AVProbeData *p) return 0; } -static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, int flv_codecid) { - AVCodecContext *acodec = astream->codec; +static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, AVCodecContext *acodec, int flv_codecid) { switch(flv_codecid) { //no distinction between S16 and S8 PCM codec flags case FLV_CODECID_PCM: @@ -440,6 +441,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) int ret, i, type, size, flags, is_audio; int64_t next, pos; int64_t dts, pts = AV_NOPTS_VALUE; + int sample_rate, channels; AVStream *st = NULL; for(;;avio_skip(s->pb, 4)){ /* pkt size is repeated at end. skip it */ @@ -524,13 +526,24 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) } if(is_audio){ + int bits_per_coded_sample; + channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1; + sample_rate = (44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3); + bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8; if(!st->codec->channels || !st->codec->sample_rate || !st->codec->bits_per_coded_sample) { - st->codec->channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1; - st->codec->sample_rate = (44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3); - st->codec->bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8; + st->codec->channels = channels; + st->codec->sample_rate = sample_rate; + st->codec->bits_per_coded_sample = bits_per_coded_sample; } if(!st->codec->codec_id){ - flv_set_audio_codec(s, st, flags & FLV_AUDIO_CODECID_MASK); + flv_set_audio_codec(s, st, st->codec, flags & FLV_AUDIO_CODECID_MASK); + flv->last_sample_rate = st->codec->sample_rate; + flv->last_channels = st->codec->channels; + } else { + AVCodecContext ctx; + ctx.sample_rate = sample_rate; + flv_set_audio_codec(s, st, &ctx, flags & FLV_AUDIO_CODECID_MASK); + sample_rate = ctx.sample_rate; } }else{ size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK); @@ -603,6 +616,12 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) flv->new_extradata_size[is_audio] = 0; } } + if (is_audio && (sample_rate != flv->last_sample_rate || + channels != flv->last_channels)) { + flv->last_sample_rate = sample_rate; + flv->last_channels = channels; + ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0); + } if (is_audio || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY)) pkt->flags |= AV_PKT_FLAG_KEY; From f13db94d0aadc4f27aea715383a18df461ed9b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 16 Dec 2011 12:59:26 +0200 Subject: [PATCH 24/27] libavcodec: Apply parameter change side data when decoding audio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/utils.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 20b01f5df4..7e9ddb2e35 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -40,6 +40,7 @@ #include "thread.h" #include "audioconvert.h" #include "internal.h" +#include "bytestream.h" #include #include #include @@ -914,6 +915,47 @@ int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *sa } #endif +static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt) +{ + int size = 0; + const uint8_t *data; + uint32_t flags; + + if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE)) + return; + + data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size); + if (!data || size < 4) + return; + flags = bytestream_get_le32(&data); + size -= 4; + if (size < 4) /* Required for any of the changes */ + return; + if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) { + avctx->channels = bytestream_get_le32(&data); + size -= 4; + } + if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) { + if (size < 8) + return; + avctx->channel_layout = bytestream_get_le64(&data); + size -= 8; + } + if (size < 4) + return; + if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) { + avctx->sample_rate = bytestream_get_le32(&data); + size -= 4; + } + if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) { + if (size < 8) + return; + avctx->width = bytestream_get_le32(&data); + avctx->height = bytestream_get_le32(&data); + size -= 8; + } +} + int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, @@ -930,6 +972,8 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, return AVERROR(EINVAL); } + apply_param_change(avctx, avpkt); + if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) { ret = avctx->codec->decode(avctx, frame, got_frame_ptr, avpkt); if (ret >= 0 && *got_frame_ptr) { From ce94948198f3d22fd1ed53b99ee31e0a3f791f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 16 Dec 2011 16:10:02 +0200 Subject: [PATCH 25/27] nellymoserdec: Indicate that the decoder can handle changed parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/nellymoserdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c index 7723c5827b..af286fbf87 100644 --- a/libavcodec/nellymoserdec.c +++ b/libavcodec/nellymoserdec.c @@ -221,7 +221,7 @@ AVCodec ff_nellymoser_decoder = { .init = decode_init, .close = decode_end, .decode = decode_tag, - .capabilities = CODEC_CAP_DR1, + .capabilities = CODEC_CAP_DR1 | CODEC_CAP_PARAM_CHANGE, .long_name = NULL_IF_CONFIG_SMALL("Nellymoser Asao"), .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, From 3f9257c5a5b08bc9aa6f7b3e3535e1c5b086ec50 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 19 Dec 2011 23:53:04 -0500 Subject: [PATCH 26/27] idroqdec: set AVFMTCTX_NOHEADER and create streams as they occur. This fixes demuxing of file where the first packet is not audio. Such files are generated by our idroq muxer. It also fixes demuxing of audio only idroq files. --- libavformat/idroqdec.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/libavformat/idroqdec.c b/libavformat/idroqdec.c index 5e347b18ab..d63c395b79 100644 --- a/libavformat/idroqdec.c +++ b/libavformat/idroqdec.c @@ -44,6 +44,7 @@ typedef struct RoqDemuxContext { + int frame_rate; int width; int height; int audio_channels; @@ -70,29 +71,21 @@ static int roq_read_header(AVFormatContext *s, { RoqDemuxContext *roq = s->priv_data; AVIOContext *pb = s->pb; - int framerate; - AVStream *st; unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE]; /* get the main header */ if (avio_read(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) return AVERROR(EIO); - framerate = AV_RL16(&preamble[6]); + roq->frame_rate = AV_RL16(&preamble[6]); /* init private context parameters */ roq->width = roq->height = roq->audio_channels = roq->video_pts = roq->audio_frame_count = 0; roq->audio_stream_index = -1; + roq->video_stream_index = -1; - st = avformat_new_stream(s, NULL); - if (!st) - return AVERROR(ENOMEM); - avpriv_set_pts_info(st, 63, 1, framerate); - roq->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = CODEC_ID_ROQ; - st->codec->codec_tag = 0; /* no fourcc */ + s->ctx_flags |= AVFMTCTX_NOHEADER; return 0; } @@ -128,8 +121,16 @@ static int roq_read_packet(AVFormatContext *s, switch (chunk_type) { case RoQ_INFO: - if (!roq->width || !roq->height) { - AVStream *st = s->streams[roq->video_stream_index]; + if (roq->video_stream_index == -1) { + AVStream *st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + avpriv_set_pts_info(st, 63, 1, roq->frame_rate); + roq->video_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_ROQ; + st->codec->codec_tag = 0; /* no fourcc */ + if (avio_read(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) return AVERROR(EIO); st->codec->width = roq->width = AV_RL16(preamble); From e9dc92012773aab5f51d8d37eb14564988c5f217 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 19 Dec 2011 23:16:51 -0500 Subject: [PATCH 27/27] asfdec: add side data to ASFStream packet instead of output packet. fixes memleak of side data --- libavformat/asfdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c index 1246cc1b65..91d285e8b5 100644 --- a/libavformat/asfdec.c +++ b/libavformat/asfdec.c @@ -979,7 +979,7 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk asf_st->packet_pos= asf->packet_pos; if (asf_st->pkt.data && asf_st->palette_changed) { uint8_t *pal; - pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, + pal = av_packet_new_side_data(&asf_st->pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); if (!pal) { av_log(s, AV_LOG_ERROR, "Cannot append palette to packet\n");