From 9b75ae05cf1554238bb103b3c3304dcba0bbc6cf Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sun, 15 Apr 2012 21:33:30 +0200 Subject: [PATCH 1/8] swscale: K&R formatting cosmetics (part III) --- libswscale/input.c | 945 ++++++++++++++++++++++++++++----------------- 1 file changed, 581 insertions(+), 364 deletions(-) diff --git a/libswscale/input.c b/libswscale/input.c index b4855093a0..afc515608d 100644 --- a/libswscale/input.c +++ b/libswscale/input.c @@ -36,66 +36,73 @@ #include "swscale_internal.h" #define RGB2YUV_SHIFT 15 -#define BY ( (int)(0.114*219/255*(1<> RGB2YUV_SHIFT; + dst[i] = (RY * r + GY * g + BY * b + (0x2001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT; } } -static av_always_inline void -rgb48ToUV_c_template(uint16_t *dstU, uint16_t *dstV, - const uint16_t *src1, const uint16_t *src2, - int width, enum PixelFormat origin) +static av_always_inline void rgb48ToUV_c_template(uint16_t *dstU, + uint16_t *dstV, + const uint16_t *src1, + const uint16_t *src2, + int width, + enum PixelFormat origin) { int i; - assert(src1==src2); + assert(src1 == src2); for (i = 0; i < width; i++) { - int r_b = input_pixel(&src1[i*3+0]); - int g = input_pixel(&src1[i*3+1]); - int b_r = input_pixel(&src1[i*3+2]); + int r_b = input_pixel(&src1[i * 3 + 0]); + int g = input_pixel(&src1[i * 3 + 1]); + int b_r = input_pixel(&src1[i * 3 + 2]); - dstU[i] = (RU*r + GU*g + BU*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; - dstV[i] = (RV*r + GV*g + BV*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; + dstU[i] = (RU * r + GU * g + BU * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT; + dstV[i] = (RV * r + GV * g + BV * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT; } } -static av_always_inline void -rgb48ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV, - const uint16_t *src1, const uint16_t *src2, - int width, enum PixelFormat origin) +static av_always_inline void rgb48ToUV_half_c_template(uint16_t *dstU, + uint16_t *dstV, + const uint16_t *src1, + const uint16_t *src2, + int width, + enum PixelFormat origin) { int i; - assert(src1==src2); + assert(src1 == src2); for (i = 0; i < width; i++) { - int r_b = (input_pixel(&src1[6 * i + 0]) + input_pixel(&src1[6 * i + 3]) + 1) >> 1; - int g = (input_pixel(&src1[6 * i + 1]) + input_pixel(&src1[6 * i + 4]) + 1) >> 1; - int b_r = (input_pixel(&src1[6 * i + 2]) + input_pixel(&src1[6 * i + 5]) + 1) >> 1; + int r_b = (input_pixel(&src1[6 * i + 0]) + + input_pixel(&src1[6 * i + 3]) + 1) >> 1; + int g = (input_pixel(&src1[6 * i + 1]) + + input_pixel(&src1[6 * i + 4]) + 1) >> 1; + int b_r = (input_pixel(&src1[6 * i + 2]) + + input_pixel(&src1[6 * i + 5]) + 1) >> 1; - dstU[i]= (RU*r + GU*g + BU*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; - dstV[i]= (RV*r + GV*g + BV*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; + dstU[i] = (RU * r + GU * g + BU * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT; + dstV[i] = (RV * r + GV * g + BV * b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT; } } @@ -103,33 +110,43 @@ rgb48ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV, #undef b #undef input_pixel -#define rgb48funcs(pattern, BE_LE, origin) \ -static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t *_src, \ - int width, uint32_t *unused) \ -{ \ - const uint16_t *src = (const uint16_t *) _src; \ - uint16_t *dst = (uint16_t *) _dst; \ - rgb48ToY_c_template(dst, src, width, origin); \ -} \ - \ -static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, uint8_t *_dstV, \ - const uint8_t *_src1, const uint8_t *_src2, \ - int width, uint32_t *unused) \ -{ \ - const uint16_t *src1 = (const uint16_t *) _src1, \ - *src2 = (const uint16_t *) _src2; \ - uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \ - rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin); \ -} \ - \ -static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, \ - const uint8_t *_src1, const uint8_t *_src2, \ - int width, uint32_t *unused) \ -{ \ - const uint16_t *src1 = (const uint16_t *) _src1, \ - *src2 = (const uint16_t *) _src2; \ - uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \ - rgb48ToUV_half_c_template(dstU, dstV, src1, src2, width, origin); \ +#define rgb48funcs(pattern, BE_LE, origin) \ +static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, \ + const uint8_t *_src, \ + int width, \ + uint32_t *unused) \ +{ \ + const uint16_t *src = (const uint16_t *)_src; \ + uint16_t *dst = (uint16_t *)_dst; \ + rgb48ToY_c_template(dst, src, width, origin); \ +} \ + \ +static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, \ + uint8_t *_dstV, \ + const uint8_t *_src1, \ + const uint8_t *_src2, \ + int width, \ + uint32_t *unused) \ +{ \ + const uint16_t *src1 = (const uint16_t *)_src1, \ + *src2 = (const uint16_t *)_src2; \ + uint16_t *dstU = (uint16_t *)_dstU, \ + *dstV = (uint16_t *)_dstV; \ + rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin); \ +} \ + \ +static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, \ + uint8_t *_dstV, \ + const uint8_t *_src1, \ + const uint8_t *_src2, \ + int width, \ + uint32_t *unused) \ +{ \ + const uint16_t *src1 = (const uint16_t *)_src1, \ + *src2 = (const uint16_t *)_src2; \ + uint16_t *dstU = (uint16_t *)_dstU, \ + *dstV = (uint16_t *)_dstV; \ + rgb48ToUV_half_c_template(dstU, dstV, src1, src2, width, origin); \ } rgb48funcs(rgb, LE, PIX_FMT_RGB48LE) @@ -137,70 +154,85 @@ rgb48funcs(rgb, BE, PIX_FMT_RGB48BE) rgb48funcs(bgr, LE, PIX_FMT_BGR48LE) rgb48funcs(bgr, BE, PIX_FMT_BGR48BE) -#define input_pixel(i) ((origin == PIX_FMT_RGBA || origin == PIX_FMT_BGRA || \ - origin == PIX_FMT_ARGB || origin == PIX_FMT_ABGR) ? AV_RN32A(&src[(i)*4]) : \ - (isBE(origin) ? AV_RB16(&src[(i)*2]) : AV_RL16(&src[(i)*2]))) +#define input_pixel(i) ((origin == PIX_FMT_RGBA || \ + origin == PIX_FMT_BGRA || \ + origin == PIX_FMT_ARGB || \ + origin == PIX_FMT_ABGR) \ + ? AV_RN32A(&src[(i) * 4]) \ + : (isBE(origin) ? AV_RB16(&src[(i) * 2]) \ + : AV_RL16(&src[(i) * 2]))) -static av_always_inline void -rgb16_32ToY_c_template(uint8_t *dst, const uint8_t *src, - int width, enum PixelFormat origin, - int shr, int shg, int shb, int shp, - int maskr, int maskg, int maskb, - int rsh, int gsh, int bsh, int S) +static av_always_inline void rgb16_32ToY_c_template(uint8_t *dst, + const uint8_t *src, + int width, + enum PixelFormat origin, + int shr, int shg, + int shb, int shp, + int maskr, int maskg, + int maskb, int rsh, + int gsh, int bsh, int S) { - const int ry = RY << rsh, gy = GY << gsh, by = BY << bsh; + const int ry = RY << rsh, gy = GY << gsh, by = BY << bsh; const unsigned rnd = 33u << (S - 1); int i; for (i = 0; i < width; i++) { int px = input_pixel(i) >> shp; - int b = (px & maskb) >> shb; - int g = (px & maskg) >> shg; - int r = (px & maskr) >> shr; + int b = (px & maskb) >> shb; + int g = (px & maskg) >> shg; + int r = (px & maskr) >> shr; dst[i] = (ry * r + gy * g + by * b + rnd) >> S; } } -static av_always_inline void -rgb16_32ToUV_c_template(uint8_t *dstU, uint8_t *dstV, - const uint8_t *src, int width, - enum PixelFormat origin, - int shr, int shg, int shb, int shp, - int maskr, int maskg, int maskb, - int rsh, int gsh, int bsh, int S) +static av_always_inline void rgb16_32ToUV_c_template(uint8_t *dstU, + uint8_t *dstV, + const uint8_t *src, + int width, + enum PixelFormat origin, + int shr, int shg, + int shb, int shp, + int maskr, int maskg, + int maskb, int rsh, + int gsh, int bsh, int S) { - const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh, - rv = RV << rsh, gv = GV << gsh, bv = BV << bsh; + const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh, + rv = RV << rsh, gv = GV << gsh, bv = BV << bsh; const unsigned rnd = 257u << (S - 1); int i; for (i = 0; i < width; i++) { int px = input_pixel(i) >> shp; - int b = (px & maskb) >> shb; - int g = (px & maskg) >> shg; - int r = (px & maskr) >> shr; + int b = (px & maskb) >> shb; + int g = (px & maskg) >> shg; + int r = (px & maskr) >> shr; dstU[i] = (ru * r + gu * g + bu * b + rnd) >> S; dstV[i] = (rv * r + gv * g + bv * b + rnd) >> S; } } -static av_always_inline void -rgb16_32ToUV_half_c_template(uint8_t *dstU, uint8_t *dstV, - const uint8_t *src, int width, - enum PixelFormat origin, - int shr, int shg, int shb, int shp, - int maskr, int maskg, int maskb, - int rsh, int gsh, int bsh, int S) +static av_always_inline void rgb16_32ToUV_half_c_template(uint8_t *dstU, + uint8_t *dstV, + const uint8_t *src, + int width, + enum PixelFormat origin, + int shr, int shg, + int shb, int shp, + int maskr, int maskg, + int maskb, int rsh, + int gsh, int bsh, int S) { - const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh, - rv = RV << rsh, gv = GV << gsh, bv = BV << bsh, - maskgx = ~(maskr | maskb); + const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh, + rv = RV << rsh, gv = GV << gsh, bv = BV << bsh, + maskgx = ~(maskr | maskb); const unsigned rnd = 257u << S; int i; - maskr |= maskr << 1; maskb |= maskb << 1; maskg |= maskg << 1; + maskr |= maskr << 1; + maskb |= maskb << 1; + maskg |= maskg << 1; for (i = 0; i < width; i++) { int px0 = input_pixel(2 * i + 0) >> shp; int px1 = input_pixel(2 * i + 1) >> shp; @@ -208,11 +240,12 @@ rgb16_32ToUV_half_c_template(uint8_t *dstU, uint8_t *dstV, int rb = px0 + px1 - g; b = (rb & maskb) >> shb; - if (shp || origin == PIX_FMT_BGR565LE || origin == PIX_FMT_BGR565BE || + if (shp || + origin == PIX_FMT_BGR565LE || origin == PIX_FMT_BGR565BE || origin == PIX_FMT_RGB565LE || origin == PIX_FMT_RGB565BE) { g >>= shg; } else { - g = (g & maskg) >> shg; + g = (g & maskg) >> shg; } r = (rb & maskr) >> shr; @@ -223,71 +256,75 @@ rgb16_32ToUV_half_c_template(uint8_t *dstU, uint8_t *dstV, #undef input_pixel -#define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, \ - maskg, maskb, rsh, gsh, bsh, S) \ -static void name ## ToY_c(uint8_t *dst, const uint8_t *src, \ - int width, uint32_t *unused) \ -{ \ - rgb16_32ToY_c_template(dst, src, width, fmt, shr, shg, shb, shp, \ - maskr, maskg, maskb, rsh, gsh, bsh, S); \ -} \ - \ -static void name ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \ - const uint8_t *src, const uint8_t *dummy, \ - int width, uint32_t *unused) \ -{ \ - rgb16_32ToUV_c_template(dstU, dstV, src, width, fmt, shr, shg, shb, shp, \ - maskr, maskg, maskb, rsh, gsh, bsh, S); \ -} \ - \ -static void name ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \ - const uint8_t *src, const uint8_t *dummy, \ - int width, uint32_t *unused) \ -{ \ - rgb16_32ToUV_half_c_template(dstU, dstV, src, width, fmt, shr, shg, shb, shp, \ - maskr, maskg, maskb, rsh, gsh, bsh, S); \ +#define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, \ + maskg, maskb, rsh, gsh, bsh, S) \ +static void name ## ToY_c(uint8_t *dst, const uint8_t *src, \ + int width, uint32_t *unused) \ +{ \ + rgb16_32ToY_c_template(dst, src, width, fmt, shr, shg, shb, shp, \ + maskr, maskg, maskb, rsh, gsh, bsh, S); \ +} \ + \ +static void name ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \ + const uint8_t *src, const uint8_t *dummy, \ + int width, uint32_t *unused) \ +{ \ + rgb16_32ToUV_c_template(dstU, dstV, src, width, fmt, \ + shr, shg, shb, shp, \ + maskr, maskg, maskb, rsh, gsh, bsh, S); \ +} \ + \ +static void name ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \ + const uint8_t *src, \ + const uint8_t *dummy, \ + int width, uint32_t *unused) \ +{ \ + rgb16_32ToUV_half_c_template(dstU, dstV, src, width, fmt, \ + shr, shg, shb, shp, \ + maskr, maskg, maskb, \ + rsh, gsh, bsh, S); \ } -rgb16_32_wrapper(PIX_FMT_BGR32, bgr32, 16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT+8) -rgb16_32_wrapper(PIX_FMT_BGR32_1, bgr321, 16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT+8) -rgb16_32_wrapper(PIX_FMT_RGB32, rgb32, 0, 0, 16, 0, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT+8) -rgb16_32_wrapper(PIX_FMT_RGB32_1, rgb321, 0, 0, 16, 8, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT+8) -rgb16_32_wrapper(PIX_FMT_BGR565LE, bgr16le, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT+8) -rgb16_32_wrapper(PIX_FMT_BGR555LE, bgr15le, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT+7) -rgb16_32_wrapper(PIX_FMT_BGR444LE, bgr12le, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT+4) -rgb16_32_wrapper(PIX_FMT_RGB565LE, rgb16le, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT+8) -rgb16_32_wrapper(PIX_FMT_RGB555LE, rgb15le, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT+7) -rgb16_32_wrapper(PIX_FMT_RGB444LE, rgb12le, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT+4) -rgb16_32_wrapper(PIX_FMT_BGR565BE, bgr16be, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT+8) -rgb16_32_wrapper(PIX_FMT_BGR555BE, bgr15be, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT+7) -rgb16_32_wrapper(PIX_FMT_BGR444BE, bgr12be, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT+4) -rgb16_32_wrapper(PIX_FMT_RGB565BE, rgb16be, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT+8) -rgb16_32_wrapper(PIX_FMT_RGB555BE, rgb15be, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT+7) -rgb16_32_wrapper(PIX_FMT_RGB444BE, rgb12be, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT+4) +rgb16_32_wrapper(PIX_FMT_BGR32, bgr32, 16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8) +rgb16_32_wrapper(PIX_FMT_BGR32_1, bgr321, 16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT + 8) +rgb16_32_wrapper(PIX_FMT_RGB32, rgb32, 0, 0, 16, 0, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8) +rgb16_32_wrapper(PIX_FMT_RGB32_1, rgb321, 0, 0, 16, 8, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT + 8) +rgb16_32_wrapper(PIX_FMT_BGR565LE, bgr16le, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8) +rgb16_32_wrapper(PIX_FMT_BGR555LE, bgr15le, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7) +rgb16_32_wrapper(PIX_FMT_BGR444LE, bgr12le, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4) +rgb16_32_wrapper(PIX_FMT_RGB565LE, rgb16le, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8) +rgb16_32_wrapper(PIX_FMT_RGB555LE, rgb15le, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7) +rgb16_32_wrapper(PIX_FMT_RGB444LE, rgb12le, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4) +rgb16_32_wrapper(PIX_FMT_BGR565BE, bgr16be, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT + 8) +rgb16_32_wrapper(PIX_FMT_BGR555BE, bgr15be, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT + 7) +rgb16_32_wrapper(PIX_FMT_BGR444BE, bgr12be, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT + 4) +rgb16_32_wrapper(PIX_FMT_RGB565BE, rgb16be, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT + 8) +rgb16_32_wrapper(PIX_FMT_RGB555BE, rgb15be, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT + 7) +rgb16_32_wrapper(PIX_FMT_RGB444BE, rgb12be, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT + 4) -static void abgrToA_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused) +static void abgrToA_c(uint8_t *dst, const uint8_t *src, int width, + uint32_t *unused) { int i; - for (i=0; i>8; - dstV[i]= p>>16; + dstU[i] = p >> 8; + dstV[i] = p >> 16; } } @@ -311,9 +348,9 @@ static void monowhite2Y_c(uint8_t *dst, const uint8_t *src, int i, j; width = (width + 7) >> 3; for (i = 0; i < width; i++) { - int d= ~src[i]; - for(j=0; j<8; j++) - dst[8*i+j]= ((d>>(7-j))&1)*255; + int d = ~src[i]; + for (j = 0; j < 8; j++) + dst[8 * i + j] = ((d >> (7 - j)) & 1) * 255; } } @@ -323,9 +360,9 @@ static void monoblack2Y_c(uint8_t *dst, const uint8_t *src, int i, j; width = (width + 7) >> 3; for (i = 0; i < width; i++) { - int d= src[i]; - for(j=0; j<8; j++) - dst[8*i+j]= ((d>>(7-j))&1)*255; + int d = src[i]; + for (j = 0; j < 8; j++) + dst[8 * i + j] = ((d >> (7 - j)) & 1) * 255; } } @@ -333,61 +370,61 @@ static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused) { int i; - for (i=0; i>RGB2YUV_SHIFT); + dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); } } @@ -435,13 +472,13 @@ static void bgr24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { int i; - for (i=0; i>RGB2YUV_SHIFT; - dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT; + dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT; + dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT; } assert(src1 == src2); } @@ -450,13 +487,13 @@ static void bgr24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { int i; - for (i=0; i>(RGB2YUV_SHIFT+1); - dstV[i]= (RV*r + GV*g + BV*b + (257<>(RGB2YUV_SHIFT+1); + dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); + dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); } assert(src1 == src2); } @@ -465,12 +502,12 @@ static void rgb24ToY_c(uint8_t *dst, const uint8_t *src, int width, uint32_t *unused) { int i; - for (i=0; i>RGB2YUV_SHIFT); + dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); } } @@ -478,14 +515,14 @@ static void rgb24ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { int i; - assert(src1==src2); - for (i=0; i>RGB2YUV_SHIFT; - dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT; + dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT; + dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT; } } @@ -493,14 +530,14 @@ static void rgb24ToUV_half_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { int i; - assert(src1==src2); - for (i=0; i>(RGB2YUV_SHIFT+1); - dstV[i]= (RV*r + GV*g + BV*b + (257<>(RGB2YUV_SHIFT+1); + dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); + dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); } } @@ -519,8 +556,8 @@ static void planar_rgb_to_y(uint8_t *dst, const uint8_t *src[4], int width) static void planar_rgb16le_to_y(uint8_t *_dst, const uint8_t *_src[4], int width) { int i; - const uint16_t **src = (const uint16_t **) _src; - uint16_t *dst = (uint16_t *) _dst; + const uint16_t **src = (const uint16_t **)_src; + uint16_t *dst = (uint16_t *)_dst; for (i = 0; i < width; i++) { int g = AV_RL16(src[0] + i); int b = AV_RL16(src[1] + i); @@ -533,8 +570,8 @@ static void planar_rgb16le_to_y(uint8_t *_dst, const uint8_t *_src[4], int width static void planar_rgb16be_to_y(uint8_t *_dst, const uint8_t *_src[4], int width) { int i; - const uint16_t **src = (const uint16_t **) _src; - uint16_t *dst = (uint16_t *) _dst; + const uint16_t **src = (const uint16_t **)_src; + uint16_t *dst = (uint16_t *)_dst; for (i = 0; i < width; i++) { int g = AV_RB16(src[0] + i); int b = AV_RB16(src[1] + i); @@ -557,12 +594,13 @@ static void planar_rgb_to_uv(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4] } } -static void planar_rgb16le_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src[4], int width) +static void planar_rgb16le_to_uv(uint8_t *_dstU, uint8_t *_dstV, + const uint8_t *_src[4], int width) { int i; - const uint16_t **src = (const uint16_t **) _src; - uint16_t *dstU = (uint16_t *) _dstU; - uint16_t *dstV = (uint16_t *) _dstV; + const uint16_t **src = (const uint16_t **)_src; + uint16_t *dstU = (uint16_t *)_dstU; + uint16_t *dstV = (uint16_t *)_dstV; for (i = 0; i < width; i++) { int g = AV_RL16(src[0] + i); int b = AV_RL16(src[1] + i); @@ -573,12 +611,13 @@ static void planar_rgb16le_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t * } } -static void planar_rgb16be_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src[4], int width) +static void planar_rgb16be_to_uv(uint8_t *_dstU, uint8_t *_dstV, + const uint8_t *_src[4], int width) { int i; - const uint16_t **src = (const uint16_t **) _src; - uint16_t *dstU = (uint16_t *) _dstU; - uint16_t *dstV = (uint16_t *) _dstV; + const uint16_t **src = (const uint16_t **)_src; + uint16_t *dstU = (uint16_t *)_dstU; + uint16_t *dstV = (uint16_t *)_dstV; for (i = 0; i < width; i++) { int g = AV_RB16(src[0] + i); int b = AV_RB16(src[1] + i); @@ -594,118 +633,51 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c) enum PixelFormat srcFormat = c->srcFormat; c->chrToYV12 = NULL; - switch(srcFormat) { - case PIX_FMT_YUYV422 : c->chrToYV12 = yuy2ToUV_c; break; - case PIX_FMT_UYVY422 : c->chrToYV12 = uyvyToUV_c; break; - case PIX_FMT_NV12 : c->chrToYV12 = nv12ToUV_c; break; - case PIX_FMT_NV21 : c->chrToYV12 = nv21ToUV_c; break; - case PIX_FMT_RGB8 : - case PIX_FMT_BGR8 : - case PIX_FMT_PAL8 : - case PIX_FMT_BGR4_BYTE: - case PIX_FMT_RGB4_BYTE: c->chrToYV12 = palToUV_c; break; - case PIX_FMT_GBRP9LE: - case PIX_FMT_GBRP10LE: - case PIX_FMT_GBRP16LE: c->readChrPlanar = planar_rgb16le_to_uv; break; - case PIX_FMT_GBRP9BE: - case PIX_FMT_GBRP10BE: - case PIX_FMT_GBRP16BE: c->readChrPlanar = planar_rgb16be_to_uv; break; - case PIX_FMT_GBRP: c->readChrPlanar = planar_rgb_to_uv; break; -#if HAVE_BIGENDIAN - case PIX_FMT_YUV444P9LE: - case PIX_FMT_YUV422P9LE: - case PIX_FMT_YUV420P9LE: - case PIX_FMT_YUV422P10LE: - case PIX_FMT_YUV444P10LE: - case PIX_FMT_YUV420P10LE: - case PIX_FMT_YUV420P16LE: - case PIX_FMT_YUV422P16LE: - case PIX_FMT_YUV444P16LE: c->chrToYV12 = bswap16UV_c; break; -#else - case PIX_FMT_YUV444P9BE: - case PIX_FMT_YUV422P9BE: - case PIX_FMT_YUV420P9BE: - case PIX_FMT_YUV444P10BE: - case PIX_FMT_YUV422P10BE: - case PIX_FMT_YUV420P10BE: - case PIX_FMT_YUV420P16BE: - case PIX_FMT_YUV422P16BE: - case PIX_FMT_YUV444P16BE: c->chrToYV12 = bswap16UV_c; break; -#endif - } - if (c->chrSrcHSubSample) { - switch(srcFormat) { - case PIX_FMT_RGB48BE : c->chrToYV12 = rgb48BEToUV_half_c; break; - case PIX_FMT_RGB48LE : c->chrToYV12 = rgb48LEToUV_half_c; break; - case PIX_FMT_BGR48BE : c->chrToYV12 = bgr48BEToUV_half_c; break; - case PIX_FMT_BGR48LE : c->chrToYV12 = bgr48LEToUV_half_c; break; - case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV_half_c; break; - case PIX_FMT_RGB32_1 : c->chrToYV12 = bgr321ToUV_half_c; break; - case PIX_FMT_BGR24 : c->chrToYV12 = bgr24ToUV_half_c; break; - case PIX_FMT_BGR565LE: c->chrToYV12 = bgr16leToUV_half_c; break; - case PIX_FMT_BGR565BE: c->chrToYV12 = bgr16beToUV_half_c; break; - case PIX_FMT_BGR555LE: c->chrToYV12 = bgr15leToUV_half_c; break; - case PIX_FMT_BGR555BE: c->chrToYV12 = bgr15beToUV_half_c; break; - case PIX_FMT_BGR444LE: c->chrToYV12 = bgr12leToUV_half_c; break; - case PIX_FMT_BGR444BE: c->chrToYV12 = bgr12beToUV_half_c; break; - case PIX_FMT_BGR32 : c->chrToYV12 = rgb32ToUV_half_c; break; - case PIX_FMT_BGR32_1 : c->chrToYV12 = rgb321ToUV_half_c; break; - case PIX_FMT_RGB24 : c->chrToYV12 = rgb24ToUV_half_c; break; - case PIX_FMT_RGB565LE: c->chrToYV12 = rgb16leToUV_half_c; break; - case PIX_FMT_RGB565BE: c->chrToYV12 = rgb16beToUV_half_c; break; - case PIX_FMT_RGB555LE: c->chrToYV12 = rgb15leToUV_half_c; break; - case PIX_FMT_RGB555BE: c->chrToYV12 = rgb15beToUV_half_c; break; - case PIX_FMT_RGB444LE: c->chrToYV12 = rgb12leToUV_half_c; break; - case PIX_FMT_RGB444BE: c->chrToYV12 = rgb12beToUV_half_c; break; - } - } else { - switch(srcFormat) { - case PIX_FMT_RGB48BE : c->chrToYV12 = rgb48BEToUV_c; break; - case PIX_FMT_RGB48LE : c->chrToYV12 = rgb48LEToUV_c; break; - case PIX_FMT_BGR48BE : c->chrToYV12 = bgr48BEToUV_c; break; - case PIX_FMT_BGR48LE : c->chrToYV12 = bgr48LEToUV_c; break; - case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV_c; break; - case PIX_FMT_RGB32_1 : c->chrToYV12 = bgr321ToUV_c; break; - case PIX_FMT_BGR24 : c->chrToYV12 = bgr24ToUV_c; break; - case PIX_FMT_BGR565LE: c->chrToYV12 = bgr16leToUV_c; break; - case PIX_FMT_BGR565BE: c->chrToYV12 = bgr16beToUV_c; break; - case PIX_FMT_BGR555LE: c->chrToYV12 = bgr15leToUV_c; break; - case PIX_FMT_BGR555BE: c->chrToYV12 = bgr15beToUV_c; break; - case PIX_FMT_BGR444LE: c->chrToYV12 = bgr12leToUV_c; break; - case PIX_FMT_BGR444BE: c->chrToYV12 = bgr12beToUV_c; break; - case PIX_FMT_BGR32 : c->chrToYV12 = rgb32ToUV_c; break; - case PIX_FMT_BGR32_1 : c->chrToYV12 = rgb321ToUV_c; break; - case PIX_FMT_RGB24 : c->chrToYV12 = rgb24ToUV_c; break; - case PIX_FMT_RGB565LE: c->chrToYV12 = rgb16leToUV_c; break; - case PIX_FMT_RGB565BE: c->chrToYV12 = rgb16beToUV_c; break; - case PIX_FMT_RGB555LE: c->chrToYV12 = rgb15leToUV_c; break; - case PIX_FMT_RGB555BE: c->chrToYV12 = rgb15beToUV_c; break; - case PIX_FMT_RGB444LE: c->chrToYV12 = rgb12leToUV_c; break; - case PIX_FMT_RGB444BE: c->chrToYV12 = rgb12beToUV_c; break; - } - } - - c->lumToYV12 = NULL; - c->alpToYV12 = NULL; switch (srcFormat) { + case PIX_FMT_YUYV422: + c->chrToYV12 = yuy2ToUV_c; + break; + case PIX_FMT_UYVY422: + c->chrToYV12 = uyvyToUV_c; + break; + case PIX_FMT_NV12: + c->chrToYV12 = nv12ToUV_c; + break; + case PIX_FMT_NV21: + c->chrToYV12 = nv21ToUV_c; + break; + case PIX_FMT_RGB8: + case PIX_FMT_BGR8: + case PIX_FMT_PAL8: + case PIX_FMT_BGR4_BYTE: + case PIX_FMT_RGB4_BYTE: + c->chrToYV12 = palToUV_c; + break; case PIX_FMT_GBRP9LE: case PIX_FMT_GBRP10LE: - case PIX_FMT_GBRP16LE: c->readLumPlanar = planar_rgb16le_to_y; break; + case PIX_FMT_GBRP16LE: + c->readChrPlanar = planar_rgb16le_to_uv; + break; case PIX_FMT_GBRP9BE: case PIX_FMT_GBRP10BE: - case PIX_FMT_GBRP16BE: c->readLumPlanar = planar_rgb16be_to_y; break; - case PIX_FMT_GBRP: c->readLumPlanar = planar_rgb_to_y; break; + case PIX_FMT_GBRP16BE: + c->readChrPlanar = planar_rgb16be_to_uv; + break; + case PIX_FMT_GBRP: + c->readChrPlanar = planar_rgb_to_uv; + break; #if HAVE_BIGENDIAN case PIX_FMT_YUV444P9LE: case PIX_FMT_YUV422P9LE: case PIX_FMT_YUV420P9LE: - case PIX_FMT_YUV444P10LE: case PIX_FMT_YUV422P10LE: + case PIX_FMT_YUV444P10LE: case PIX_FMT_YUV420P10LE: case PIX_FMT_YUV420P16LE: case PIX_FMT_YUV422P16LE: case PIX_FMT_YUV444P16LE: - case PIX_FMT_GRAY16LE: c->lumToYV12 = bswap16Y_c; break; + c->chrToYV12 = bswap16UV_c; + break; #else case PIX_FMT_YUV444P9BE: case PIX_FMT_YUV422P9BE: @@ -716,48 +688,293 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c) case PIX_FMT_YUV420P16BE: case PIX_FMT_YUV422P16BE: case PIX_FMT_YUV444P16BE: - case PIX_FMT_GRAY16BE: c->lumToYV12 = bswap16Y_c; break; + c->chrToYV12 = bswap16UV_c; + break; #endif - case PIX_FMT_YUYV422 : - case PIX_FMT_Y400A : c->lumToYV12 = yuy2ToY_c; break; - case PIX_FMT_UYVY422 : c->lumToYV12 = uyvyToY_c; break; - case PIX_FMT_BGR24 : c->lumToYV12 = bgr24ToY_c; break; - case PIX_FMT_BGR565LE : c->lumToYV12 = bgr16leToY_c; break; - case PIX_FMT_BGR565BE : c->lumToYV12 = bgr16beToY_c; break; - case PIX_FMT_BGR555LE : c->lumToYV12 = bgr15leToY_c; break; - case PIX_FMT_BGR555BE : c->lumToYV12 = bgr15beToY_c; break; - case PIX_FMT_BGR444LE : c->lumToYV12 = bgr12leToY_c; break; - case PIX_FMT_BGR444BE : c->lumToYV12 = bgr12beToY_c; break; - case PIX_FMT_RGB24 : c->lumToYV12 = rgb24ToY_c; break; - case PIX_FMT_RGB565LE : c->lumToYV12 = rgb16leToY_c; break; - case PIX_FMT_RGB565BE : c->lumToYV12 = rgb16beToY_c; break; - case PIX_FMT_RGB555LE : c->lumToYV12 = rgb15leToY_c; break; - case PIX_FMT_RGB555BE : c->lumToYV12 = rgb15beToY_c; break; - case PIX_FMT_RGB444LE : c->lumToYV12 = rgb12leToY_c; break; - case PIX_FMT_RGB444BE : c->lumToYV12 = rgb12beToY_c; break; - case PIX_FMT_RGB8 : - case PIX_FMT_BGR8 : - case PIX_FMT_PAL8 : + } + if (c->chrSrcHSubSample) { + switch (srcFormat) { + case PIX_FMT_RGB48BE: + c->chrToYV12 = rgb48BEToUV_half_c; + break; + case PIX_FMT_RGB48LE: + c->chrToYV12 = rgb48LEToUV_half_c; + break; + case PIX_FMT_BGR48BE: + c->chrToYV12 = bgr48BEToUV_half_c; + break; + case PIX_FMT_BGR48LE: + c->chrToYV12 = bgr48LEToUV_half_c; + break; + case PIX_FMT_RGB32: + c->chrToYV12 = bgr32ToUV_half_c; + break; + case PIX_FMT_RGB32_1: + c->chrToYV12 = bgr321ToUV_half_c; + break; + case PIX_FMT_BGR24: + c->chrToYV12 = bgr24ToUV_half_c; + break; + case PIX_FMT_BGR565LE: + c->chrToYV12 = bgr16leToUV_half_c; + break; + case PIX_FMT_BGR565BE: + c->chrToYV12 = bgr16beToUV_half_c; + break; + case PIX_FMT_BGR555LE: + c->chrToYV12 = bgr15leToUV_half_c; + break; + case PIX_FMT_BGR555BE: + c->chrToYV12 = bgr15beToUV_half_c; + break; + case PIX_FMT_BGR444LE: + c->chrToYV12 = bgr12leToUV_half_c; + break; + case PIX_FMT_BGR444BE: + c->chrToYV12 = bgr12beToUV_half_c; + break; + case PIX_FMT_BGR32: + c->chrToYV12 = rgb32ToUV_half_c; + break; + case PIX_FMT_BGR32_1: + c->chrToYV12 = rgb321ToUV_half_c; + break; + case PIX_FMT_RGB24: + c->chrToYV12 = rgb24ToUV_half_c; + break; + case PIX_FMT_RGB565LE: + c->chrToYV12 = rgb16leToUV_half_c; + break; + case PIX_FMT_RGB565BE: + c->chrToYV12 = rgb16beToUV_half_c; + break; + case PIX_FMT_RGB555LE: + c->chrToYV12 = rgb15leToUV_half_c; + break; + case PIX_FMT_RGB555BE: + c->chrToYV12 = rgb15beToUV_half_c; + break; + case PIX_FMT_RGB444LE: + c->chrToYV12 = rgb12leToUV_half_c; + break; + case PIX_FMT_RGB444BE: + c->chrToYV12 = rgb12beToUV_half_c; + break; + } + } else { + switch (srcFormat) { + case PIX_FMT_RGB48BE: + c->chrToYV12 = rgb48BEToUV_c; + break; + case PIX_FMT_RGB48LE: + c->chrToYV12 = rgb48LEToUV_c; + break; + case PIX_FMT_BGR48BE: + c->chrToYV12 = bgr48BEToUV_c; + break; + case PIX_FMT_BGR48LE: + c->chrToYV12 = bgr48LEToUV_c; + break; + case PIX_FMT_RGB32: + c->chrToYV12 = bgr32ToUV_c; + break; + case PIX_FMT_RGB32_1: + c->chrToYV12 = bgr321ToUV_c; + break; + case PIX_FMT_BGR24: + c->chrToYV12 = bgr24ToUV_c; + break; + case PIX_FMT_BGR565LE: + c->chrToYV12 = bgr16leToUV_c; + break; + case PIX_FMT_BGR565BE: + c->chrToYV12 = bgr16beToUV_c; + break; + case PIX_FMT_BGR555LE: + c->chrToYV12 = bgr15leToUV_c; + break; + case PIX_FMT_BGR555BE: + c->chrToYV12 = bgr15beToUV_c; + break; + case PIX_FMT_BGR444LE: + c->chrToYV12 = bgr12leToUV_c; + break; + case PIX_FMT_BGR444BE: + c->chrToYV12 = bgr12beToUV_c; + break; + case PIX_FMT_BGR32: + c->chrToYV12 = rgb32ToUV_c; + break; + case PIX_FMT_BGR32_1: + c->chrToYV12 = rgb321ToUV_c; + break; + case PIX_FMT_RGB24: + c->chrToYV12 = rgb24ToUV_c; + break; + case PIX_FMT_RGB565LE: + c->chrToYV12 = rgb16leToUV_c; + break; + case PIX_FMT_RGB565BE: + c->chrToYV12 = rgb16beToUV_c; + break; + case PIX_FMT_RGB555LE: + c->chrToYV12 = rgb15leToUV_c; + break; + case PIX_FMT_RGB555BE: + c->chrToYV12 = rgb15beToUV_c; + break; + case PIX_FMT_RGB444LE: + c->chrToYV12 = rgb12leToUV_c; + break; + case PIX_FMT_RGB444BE: + c->chrToYV12 = rgb12beToUV_c; + break; + } + } + + c->lumToYV12 = NULL; + c->alpToYV12 = NULL; + switch (srcFormat) { + case PIX_FMT_GBRP9LE: + case PIX_FMT_GBRP10LE: + case PIX_FMT_GBRP16LE: + c->readLumPlanar = planar_rgb16le_to_y; + break; + case PIX_FMT_GBRP9BE: + case PIX_FMT_GBRP10BE: + case PIX_FMT_GBRP16BE: + c->readLumPlanar = planar_rgb16be_to_y; + break; + case PIX_FMT_GBRP: + c->readLumPlanar = planar_rgb_to_y; + break; +#if HAVE_BIGENDIAN + case PIX_FMT_YUV444P9LE: + case PIX_FMT_YUV422P9LE: + case PIX_FMT_YUV420P9LE: + case PIX_FMT_YUV444P10LE: + case PIX_FMT_YUV422P10LE: + case PIX_FMT_YUV420P10LE: + case PIX_FMT_YUV420P16LE: + case PIX_FMT_YUV422P16LE: + case PIX_FMT_YUV444P16LE: + case PIX_FMT_GRAY16LE: + c->lumToYV12 = bswap16Y_c; + break; +#else + case PIX_FMT_YUV444P9BE: + case PIX_FMT_YUV422P9BE: + case PIX_FMT_YUV420P9BE: + case PIX_FMT_YUV444P10BE: + case PIX_FMT_YUV422P10BE: + case PIX_FMT_YUV420P10BE: + case PIX_FMT_YUV420P16BE: + case PIX_FMT_YUV422P16BE: + case PIX_FMT_YUV444P16BE: + case PIX_FMT_GRAY16BE: + c->lumToYV12 = bswap16Y_c; + break; +#endif + case PIX_FMT_YUYV422: + case PIX_FMT_Y400A: + c->lumToYV12 = yuy2ToY_c; + break; + case PIX_FMT_UYVY422: + c->lumToYV12 = uyvyToY_c; + break; + case PIX_FMT_BGR24: + c->lumToYV12 = bgr24ToY_c; + break; + case PIX_FMT_BGR565LE: + c->lumToYV12 = bgr16leToY_c; + break; + case PIX_FMT_BGR565BE: + c->lumToYV12 = bgr16beToY_c; + break; + case PIX_FMT_BGR555LE: + c->lumToYV12 = bgr15leToY_c; + break; + case PIX_FMT_BGR555BE: + c->lumToYV12 = bgr15beToY_c; + break; + case PIX_FMT_BGR444LE: + c->lumToYV12 = bgr12leToY_c; + break; + case PIX_FMT_BGR444BE: + c->lumToYV12 = bgr12beToY_c; + break; + case PIX_FMT_RGB24: + c->lumToYV12 = rgb24ToY_c; + break; + case PIX_FMT_RGB565LE: + c->lumToYV12 = rgb16leToY_c; + break; + case PIX_FMT_RGB565BE: + c->lumToYV12 = rgb16beToY_c; + break; + case PIX_FMT_RGB555LE: + c->lumToYV12 = rgb15leToY_c; + break; + case PIX_FMT_RGB555BE: + c->lumToYV12 = rgb15beToY_c; + break; + case PIX_FMT_RGB444LE: + c->lumToYV12 = rgb12leToY_c; + break; + case PIX_FMT_RGB444BE: + c->lumToYV12 = rgb12beToY_c; + break; + case PIX_FMT_RGB8: + case PIX_FMT_BGR8: + case PIX_FMT_PAL8: case PIX_FMT_BGR4_BYTE: - case PIX_FMT_RGB4_BYTE: c->lumToYV12 = palToY_c; break; - case PIX_FMT_MONOBLACK: c->lumToYV12 = monoblack2Y_c; break; - case PIX_FMT_MONOWHITE: c->lumToYV12 = monowhite2Y_c; break; - case PIX_FMT_RGB32 : c->lumToYV12 = bgr32ToY_c; break; - case PIX_FMT_RGB32_1: c->lumToYV12 = bgr321ToY_c; break; - case PIX_FMT_BGR32 : c->lumToYV12 = rgb32ToY_c; break; - case PIX_FMT_BGR32_1: c->lumToYV12 = rgb321ToY_c; break; - case PIX_FMT_RGB48BE: c->lumToYV12 = rgb48BEToY_c; break; - case PIX_FMT_RGB48LE: c->lumToYV12 = rgb48LEToY_c; break; - case PIX_FMT_BGR48BE: c->lumToYV12 = bgr48BEToY_c; break; - case PIX_FMT_BGR48LE: c->lumToYV12 = bgr48LEToY_c; break; + case PIX_FMT_RGB4_BYTE: + c->lumToYV12 = palToY_c; + break; + case PIX_FMT_MONOBLACK: + c->lumToYV12 = monoblack2Y_c; + break; + case PIX_FMT_MONOWHITE: + c->lumToYV12 = monowhite2Y_c; + break; + case PIX_FMT_RGB32: + c->lumToYV12 = bgr32ToY_c; + break; + case PIX_FMT_RGB32_1: + c->lumToYV12 = bgr321ToY_c; + break; + case PIX_FMT_BGR32: + c->lumToYV12 = rgb32ToY_c; + break; + case PIX_FMT_BGR32_1: + c->lumToYV12 = rgb321ToY_c; + break; + case PIX_FMT_RGB48BE: + c->lumToYV12 = rgb48BEToY_c; + break; + case PIX_FMT_RGB48LE: + c->lumToYV12 = rgb48LEToY_c; + break; + case PIX_FMT_BGR48BE: + c->lumToYV12 = bgr48BEToY_c; + break; + case PIX_FMT_BGR48LE: + c->lumToYV12 = bgr48LEToY_c; + break; } if (c->alpPixBuf) { switch (srcFormat) { case PIX_FMT_BGRA: - case PIX_FMT_RGBA: c->alpToYV12 = rgbaToA_c; break; + case PIX_FMT_RGBA: + c->alpToYV12 = rgbaToA_c; + break; case PIX_FMT_ABGR: - case PIX_FMT_ARGB: c->alpToYV12 = abgrToA_c; break; - case PIX_FMT_Y400A: c->alpToYV12 = uyvyToY_c; break; + case PIX_FMT_ARGB: + c->alpToYV12 = abgrToA_c; + break; + case PIX_FMT_Y400A: + c->alpToYV12 = uyvyToY_c; + break; } } } From 269cb6751b3fd2163253f9a8ea0d193121858677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sat, 21 Apr 2012 22:48:34 +0300 Subject: [PATCH 2/8] mpegts: Try seeking back even for nonseekable protocols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mpegts demuxer reads 5 KB at startup just for discovering the packet size. Since the default avio buffer size is 32 KB, the seek back to the start will in most cases be within the avio buffer, and will in most cases succeed even if the actual protocol isn't seekable. This makes the demuxer startup faster/with less data when reading data from a non-seekable input, by not skipping the first few KB. If it fails, don't warn if the protocol isn't seekable, making it behave as before in the failure case. Signed-off-by: Martin Storsjö --- libavformat/mpegts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index e06792763c..c853e72c3b 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1899,7 +1899,7 @@ static int mpegts_read_header(AVFormatContext *s) /* normal demux */ /* first do a scan to get all the services */ - if (pb->seekable && avio_seek(pb, pos, SEEK_SET) < 0) + if (avio_seek(pb, pos, SEEK_SET) < 0 && pb->seekable) av_log(s, AV_LOG_ERROR, "Unable to seek back to the start\n"); mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1); From 1381081cdb5999892d69f2ff010cf9371bfc7978 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Sun, 22 Apr 2012 16:37:54 -0700 Subject: [PATCH 3/8] avconv: fix off by one check in complex_filter nb_input_files is already an invalid index. --- avconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avconv.c b/avconv.c index 851d8dd7d8..e441fff855 100644 --- a/avconv.c +++ b/avconv.c @@ -725,7 +725,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) char *p; int file_idx = strtol(in->name, &p, 0); - if (file_idx < 0 || file_idx > nb_input_files) { + if (file_idx < 0 || file_idx >= nb_input_files) { av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtegraph description %s.\n", file_idx, fg->graph_desc); exit_program(1); From 8336eb6f85e4b94b9c198b16bd0ac4178f4dba86 Mon Sep 17 00:00:00 2001 From: Dale Curtis Date: Thu, 19 Apr 2012 11:12:24 -0700 Subject: [PATCH 4/8] matroska: Add incremental parsing of clusters. Reduces the amount of upfront data required for cluster parsing thus decreasing latency on seek and startup. The change in the seek-lavf_mkv FATE test is due to incremental parsing no longer reading as much data as the old parser and thus not having that additional data to generate index entries based on keyframes. Index entries are added correctly as the file is parsed. All FATE tests pass and Chrome has been using this patch for ~6 months without issue. Currently incremental parsing is not supported for files with SSA tracks since they require merging packets between clusters. In this case the code falls back to non-incremental parsing. Signed-off-by: Aaron Colwell Signed-off-by: Dale Curtis Signed-off-by: Luca Barbato --- libavformat/matroskadec.c | 113 ++++++++++++++++++++++++++++++++++++-- tests/ref/seek/lavf_mkv | 2 +- 2 files changed, 108 insertions(+), 7 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 99e0dac0ca..100b97f5dd 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -212,6 +212,11 @@ typedef struct { uint64_t length; } MatroskaLevel; +typedef struct { + uint64_t timecode; + EbmlList blocks; +} MatroskaCluster; + typedef struct { AVFormatContext *ctx; @@ -247,6 +252,13 @@ typedef struct { /* File has a CUES element, but we defer parsing until it is needed. */ int cues_parsing_deferred; + + int current_cluster_num_blocks; + int64_t current_cluster_pos; + MatroskaCluster current_cluster; + + /* File has SSA subtitles which prevent incremental cluster parsing. */ + int contains_ssa; } MatroskaDemuxContext; typedef struct { @@ -256,11 +268,6 @@ typedef struct { EbmlBin bin; } MatroskaBlock; -typedef struct { - uint64_t timecode; - EbmlList blocks; -} MatroskaCluster; - static EbmlSyntax ebml_header[] = { { EBML_ID_EBMLREADVERSION, EBML_UINT, 0, offsetof(Ebml,version), {.u=EBML_VERSION} }, { EBML_ID_EBMLMAXSIZELENGTH, EBML_UINT, 0, offsetof(Ebml,max_size), {.u=8} }, @@ -514,6 +521,38 @@ static EbmlSyntax matroska_clusters[] = { { 0 } }; +static EbmlSyntax matroska_cluster_incremental_parsing[] = { + { MATROSKA_ID_CLUSTERTIMECODE,EBML_UINT,0, offsetof(MatroskaCluster,timecode) }, + { MATROSKA_ID_BLOCKGROUP, EBML_NEST, sizeof(MatroskaBlock), offsetof(MatroskaCluster,blocks), {.n=matroska_blockgroup} }, + { MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, sizeof(MatroskaBlock), offsetof(MatroskaCluster,blocks), {.n=matroska_blockgroup} }, + { MATROSKA_ID_CLUSTERPOSITION,EBML_NONE }, + { MATROSKA_ID_CLUSTERPREVSIZE,EBML_NONE }, + { MATROSKA_ID_INFO, EBML_NONE }, + { MATROSKA_ID_CUES, EBML_NONE }, + { MATROSKA_ID_TAGS, EBML_NONE }, + { MATROSKA_ID_SEEKHEAD, EBML_NONE }, + { MATROSKA_ID_CLUSTER, EBML_STOP }, + { 0 } +}; + +static EbmlSyntax matroska_cluster_incremental[] = { + { MATROSKA_ID_CLUSTERTIMECODE,EBML_UINT,0, offsetof(MatroskaCluster,timecode) }, + { MATROSKA_ID_BLOCKGROUP, EBML_STOP }, + { MATROSKA_ID_SIMPLEBLOCK, EBML_STOP }, + { MATROSKA_ID_CLUSTERPOSITION,EBML_NONE }, + { MATROSKA_ID_CLUSTERPREVSIZE,EBML_NONE }, + { 0 } +}; + +static EbmlSyntax matroska_clusters_incremental[] = { + { MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, {.n=matroska_cluster_incremental} }, + { MATROSKA_ID_INFO, EBML_NONE }, + { MATROSKA_ID_CUES, EBML_NONE }, + { MATROSKA_ID_TAGS, EBML_NONE }, + { MATROSKA_ID_SEEKHEAD, EBML_NONE }, + { 0 } +}; + static const char *const matroska_doctypes[] = { "matroska", "webm" }; /* @@ -1563,6 +1602,8 @@ static int matroska_read_header(AVFormatContext *s) st->need_parsing = AVSTREAM_PARSE_HEADERS; } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) { st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + if (st->codec->codec_id == CODEC_ID_SSA) + matroska->contains_ssa = 1; } } @@ -1634,6 +1675,7 @@ static int matroska_deliver_packet(MatroskaDemuxContext *matroska, matroska->packets = newpackets; } else { av_freep(&matroska->packets); + matroska->prev_pkt = NULL; } matroska->num_packets--; return 0; @@ -1929,13 +1971,71 @@ end: return res; } +static int matroska_parse_cluster_incremental(MatroskaDemuxContext *matroska) +{ + EbmlList *blocks_list; + MatroskaBlock *blocks; + int i, res; + res = ebml_parse(matroska, + matroska_cluster_incremental_parsing, + &matroska->current_cluster); + if (res == 1) { + /* New Cluster */ + if (matroska->current_cluster_pos) + ebml_level_end(matroska); + ebml_free(matroska_cluster, &matroska->current_cluster); + memset(&matroska->current_cluster, 0, sizeof(MatroskaCluster)); + matroska->current_cluster_num_blocks = 0; + matroska->current_cluster_pos = avio_tell(matroska->ctx->pb); + matroska->prev_pkt = NULL; + /* sizeof the ID which was already read */ + if (matroska->current_id) + matroska->current_cluster_pos -= 4; + res = ebml_parse(matroska, + matroska_clusters_incremental, + &matroska->current_cluster); + /* Try parsing the block again. */ + if (res == 1) + res = ebml_parse(matroska, + matroska_cluster_incremental_parsing, + &matroska->current_cluster); + } + + if (!res && + matroska->current_cluster_num_blocks < + matroska->current_cluster.blocks.nb_elem) { + blocks_list = &matroska->current_cluster.blocks; + blocks = blocks_list->elem; + + matroska->current_cluster_num_blocks = blocks_list->nb_elem; + i = blocks_list->nb_elem - 1; + if (blocks[i].bin.size > 0 && blocks[i].bin.data) { + int is_keyframe = blocks[i].non_simple ? !blocks[i].reference : -1; + if (!blocks[i].non_simple) + blocks[i].duration = AV_NOPTS_VALUE; + res = matroska_parse_block(matroska, + blocks[i].bin.data, blocks[i].bin.size, + blocks[i].bin.pos, + matroska->current_cluster.timecode, + blocks[i].duration, is_keyframe, + matroska->current_cluster_pos); + } + } + + if (res < 0) matroska->done = 1; + return res; +} + static int matroska_parse_cluster(MatroskaDemuxContext *matroska) { MatroskaCluster cluster = { 0 }; EbmlList *blocks_list; MatroskaBlock *blocks; int i, res; - int64_t pos = avio_tell(matroska->ctx->pb); + int64_t pos; + if (!matroska->contains_ssa) + return matroska_parse_cluster_incremental(matroska); + pos = avio_tell(matroska->ctx->pb); matroska->prev_pkt = NULL; if (matroska->current_id) pos -= 4; /* sizeof the ID which was already read */ @@ -2040,6 +2140,7 @@ static int matroska_read_close(AVFormatContext *s) for (n=0; n < matroska->tracks.nb_elem; n++) if (tracks[n].type == MATROSKA_TRACK_TYPE_AUDIO) av_free(tracks[n].audio.buf); + ebml_free(matroska_cluster, &matroska->current_cluster); ebml_free(matroska_segment, matroska); return 0; diff --git a/tests/ref/seek/lavf_mkv b/tests/ref/seek/lavf_mkv index 0f76f344c5..e51e9c9c3b 100644 --- a/tests/ref/seek/lavf_mkv +++ b/tests/ref/seek/lavf_mkv @@ -34,7 +34,7 @@ ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292150 size: 27834 ret: 0 st: 1 flags:0 ts: 1.307000 ret:-EOF ret: 0 st: 1 flags:1 ts: 0.201000 -ret: 0 st: 1 flags:1 dts: 0.198000 pts: 0.198000 pos: 512 size: 208 +ret: 0 st: 1 flags:1 dts: 0.015000 pts: 0.015000 pos: 512 size: 208 ret: 0 st:-1 flags:0 ts:-0.904994 ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 512 size: 208 ret: 0 st:-1 flags:1 ts: 1.989173 From a229d6c2856a03654942ad8cb8a77003f688fea2 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sat, 14 Apr 2012 14:54:03 +0200 Subject: [PATCH 5/8] Remove libdirac decoder. libschroedinger is the preferred way to decode Dirac video. --- configure | 7 -- doc/general.texi | 2 +- doc/platform.texi | 5 +- libavcodec/Makefile | 2 - libavcodec/allcodecs.c | 1 - libavcodec/libdirac.h | 44 --------- libavcodec/libdiracdec.c | 208 --------------------------------------- 7 files changed, 3 insertions(+), 266 deletions(-) delete mode 100644 libavcodec/libdirac.h delete mode 100644 libavcodec/libdiracdec.c diff --git a/configure b/configure index 172e1d6ea9..a73d666967 100755 --- a/configure +++ b/configure @@ -171,7 +171,6 @@ External library support: --enable-libcdio enable audio CD grabbing with libcdio --enable-libdc1394 enable IIDC-1394 grabbing using libdc1394 and libraw1394 [no] - --enable-libdirac enable Dirac support via libdirac [no] --enable-libfaac enable FAAC support via libfaac [no] --enable-libfreetype enable libfreetype [no] --enable-libgsm enable GSM support via libgsm [no] @@ -943,7 +942,6 @@ CONFIG_LIST=" hardcoded_tables libcdio libdc1394 - libdirac libfaac libfreetype libgsm @@ -1422,7 +1420,6 @@ vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h" h264_parser_select="golomb h264dsp h264pred" # external libraries -libdirac_decoder_deps="libdirac !libschroedinger" libfaac_encoder_deps="libfaac" libgsm_decoder_deps="libgsm" libgsm_encoder_deps="libgsm" @@ -2963,9 +2960,6 @@ check_mathfunc truncf enabled avisynth && require2 vfw32 "windows.h vfw.h" AVIFileInit -lavifil32 enabled frei0r && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; } enabled gnutls && require_pkg_config gnutls gnutls/gnutls.h gnutls_global_init -enabled libdirac && require_pkg_config dirac \ - "libdirac_decoder/dirac_parser.h" \ - "dirac_decoder_init" enabled libfaac && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac enabled libfreetype && require_pkg_config freetype2 "ft2build.h freetype/freetype.h" FT_Init_FreeType enabled libgsm && require libgsm gsm/gsm.h gsm_create -lgsm @@ -3255,7 +3249,6 @@ echo "frei0r enabled ${frei0r-no}" echo "gnutls enabled ${gnutls-no}" echo "libcdio support ${libcdio-no}" echo "libdc1394 support ${libdc1394-no}" -echo "libdirac enabled ${libdirac-no}" echo "libfaac enabled ${libfaac-no}" echo "libgsm enabled ${libgsm-no}" echo "libmp3lame enabled ${libmp3lame-no}" diff --git a/doc/general.texi b/doc/general.texi index 0c14003dee..090e4c594b 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -454,7 +454,7 @@ following image formats are supported: @item DFA @tab @tab X @tab Codec used in Chronomaster game. @item Dirac @tab E @tab E - @tab supported through external libdirac/libschroedinger libraries + @tab supported through external library libschroedinger @item Deluxe Paint Animation @tab @tab X @item DNxHD @tab X @tab X @tab aka SMPTE VC3 diff --git a/doc/platform.texi b/doc/platform.texi index 7ec7cb3dd0..97e97c218c 100644 --- a/doc/platform.texi +++ b/doc/platform.texi @@ -323,9 +323,8 @@ These library packages are only available from @uref{http://sourceware.org/cygwinports/, Cygwin Ports}: @example -yasm, libSDL-devel, libdirac-devel, libfaac-devel, libgsm-devel, -libmp3lame-devel, libschroedinger1.0-devel, speex-devel, libtheora-devel, -libxvidcore-devel +yasm, libSDL-devel, libfaac-devel, libgsm-devel, libmp3lame-devel, +libschroedinger1.0-devel, speex-devel, libtheora-devel, libxvidcore-devel @end example The recommendation for libnut and x264 is to build them from source by diff --git a/libavcodec/Makefile b/libavcodec/Makefile index b3309e57cb..657f6a0708 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -582,7 +582,6 @@ OBJS-$(CONFIG_WEBM_MUXER) += xiph.o mpeg4audio.o \ OBJS-$(CONFIG_WTV_DEMUXER) += mpeg4audio.o mpegaudiodata.o # external codec libraries -OBJS-$(CONFIG_LIBDIRAC_DECODER) += libdiracdec.o OBJS-$(CONFIG_LIBFAAC_ENCODER) += libfaac.o audio_frame_queue.o OBJS-$(CONFIG_LIBGSM_DECODER) += libgsm.o OBJS-$(CONFIG_LIBGSM_ENCODER) += libgsm.o @@ -692,7 +691,6 @@ SKIPHEADERS += %_tablegen.h \ tableprint.h \ $(ARCH)/vp56_arith.h SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h -SKIPHEADERS-$(CONFIG_LIBDIRAC) += libdirac.h SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h SKIPHEADERS-$(CONFIG_MPEG_XVMC_DECODER) += xvmc.h SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_internal.h diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 0b519bbf82..a1df47af69 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -375,7 +375,6 @@ void avcodec_register_all(void) REGISTER_ENCDEC (XSUB, xsub); /* external libraries */ - REGISTER_DECODER (LIBDIRAC, libdirac); REGISTER_ENCODER (LIBFAAC, libfaac); REGISTER_ENCDEC (LIBGSM, libgsm); REGISTER_ENCDEC (LIBGSM_MS, libgsm_ms); diff --git a/libavcodec/libdirac.h b/libavcodec/libdirac.h deleted file mode 100644 index 4403fb2a39..0000000000 --- a/libavcodec/libdirac.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2008 BBC, Anuradha Suraparaju - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** -* @file -* data structures common to libdirac encoder and decoder -*/ - -#ifndef AVCODEC_LIBDIRAC_H -#define AVCODEC_LIBDIRAC_H - -#include "avcodec.h" -#include - -/** -* Table providing a Dirac chroma format to Libav pixel format mapping. -*/ -static const struct { - enum PixelFormat ff_pix_fmt; - dirac_chroma_t dirac_pix_fmt; -} dirac_pixel_format_map[] = { - { PIX_FMT_YUV420P, format420 }, - { PIX_FMT_YUV422P, format422 }, - { PIX_FMT_YUV444P, format444 }, -}; - -#endif /* AVCODEC_LIBDIRAC_H */ diff --git a/libavcodec/libdiracdec.c b/libavcodec/libdiracdec.c deleted file mode 100644 index cbd29850f3..0000000000 --- a/libavcodec/libdiracdec.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Dirac decoder support via libdirac library - * Copyright (c) 2005 BBC, Andrew Kennedy - * Copyright (c) 2006-2008 BBC, Anuradha Suraparaju - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** -* @file -* Dirac decoder support via libdirac library; more details about the Dirac -* project can be found at http://dirac.sourceforge.net/. -* The libdirac_decoder library implements Dirac specification version 2.2 -* (http://dirac.sourceforge.net/specification.html). -*/ - -#include "libavutil/imgutils.h" -#include "libdirac.h" - -#undef NDEBUG -#include - -#include - -/** contains a single frame returned from Dirac */ -typedef struct DiracDecoderParams { - /** decoder handle */ - dirac_decoder_t* p_decoder; - - /** buffer to hold decoded frame */ - unsigned char* p_out_frame_buf; -} DiracDecoderParams; - - -/** -* returns Libav chroma format -*/ -static enum PixelFormat get_chroma_format(dirac_chroma_t dirac_pix_fmt) -{ - int num_formats = sizeof(dirac_pixel_format_map) / - sizeof(dirac_pixel_format_map[0]); - int idx; - - for (idx = 0; idx < num_formats; ++idx) - if (dirac_pixel_format_map[idx].dirac_pix_fmt == dirac_pix_fmt) - return dirac_pixel_format_map[idx].ff_pix_fmt; - return PIX_FMT_NONE; -} - -static av_cold int libdirac_decode_init(AVCodecContext *avccontext) -{ - - DiracDecoderParams *p_dirac_params = avccontext->priv_data; - p_dirac_params->p_decoder = dirac_decoder_init(avccontext->debug); - - if (!p_dirac_params->p_decoder) - return -1; - - return 0; -} - -static int libdirac_decode_frame(AVCodecContext *avccontext, - void *data, int *data_size, - AVPacket *avpkt) -{ - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; - - DiracDecoderParams *p_dirac_params = avccontext->priv_data; - AVPicture *picture = data; - AVPicture pic; - int pict_size; - unsigned char *buffer[3]; - - *data_size = 0; - - if (buf_size > 0) { - /* set data to decode into buffer */ - dirac_buffer(p_dirac_params->p_decoder, buf, buf + buf_size); - if ((buf[4] & 0x08) == 0x08 && (buf[4] & 0x03)) - avccontext->has_b_frames = 1; - } - while (1) { - /* parse data and process result */ - DecoderState state = dirac_parse(p_dirac_params->p_decoder); - switch (state) { - case STATE_BUFFER: - return buf_size; - - case STATE_SEQUENCE: - { - /* tell Libav about sequence details */ - dirac_sourceparams_t *src_params = &p_dirac_params->p_decoder->src_params; - - if (av_image_check_size(src_params->width, src_params->height, - 0, avccontext) < 0) { - av_log(avccontext, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", - src_params->width, src_params->height); - avccontext->height = avccontext->width = 0; - return -1; - } - - avccontext->height = src_params->height; - avccontext->width = src_params->width; - - avccontext->pix_fmt = get_chroma_format(src_params->chroma); - if (avccontext->pix_fmt == PIX_FMT_NONE) { - av_log(avccontext, AV_LOG_ERROR, - "Dirac chroma format %d not supported currently\n", - src_params->chroma); - return -1; - } - - avccontext->time_base.den = src_params->frame_rate.numerator; - avccontext->time_base.num = src_params->frame_rate.denominator; - - /* calculate output dimensions */ - avpicture_fill(&pic, NULL, avccontext->pix_fmt, - avccontext->width, avccontext->height); - - pict_size = avpicture_get_size(avccontext->pix_fmt, - avccontext->width, - avccontext->height); - - /* allocate output buffer */ - if (!p_dirac_params->p_out_frame_buf) - p_dirac_params->p_out_frame_buf = av_malloc(pict_size); - buffer[0] = p_dirac_params->p_out_frame_buf; - buffer[1] = p_dirac_params->p_out_frame_buf + - pic.linesize[0] * avccontext->height; - buffer[2] = buffer[1] + - pic.linesize[1] * src_params->chroma_height; - - /* tell Dirac about output destination */ - dirac_set_buf(p_dirac_params->p_decoder, buffer, NULL); - break; - } - case STATE_SEQUENCE_END: - break; - - case STATE_PICTURE_AVAIL: - /* fill picture with current buffer data from Dirac */ - avpicture_fill(picture, p_dirac_params->p_out_frame_buf, - avccontext->pix_fmt, - avccontext->width, avccontext->height); - *data_size = sizeof(AVPicture); - return buf_size; - - case STATE_INVALID: - return -1; - - default: - break; - } - } - - return buf_size; -} - - -static av_cold int libdirac_decode_close(AVCodecContext *avccontext) -{ - DiracDecoderParams *p_dirac_params = avccontext->priv_data; - dirac_decoder_close(p_dirac_params->p_decoder); - - av_freep(&p_dirac_params->p_out_frame_buf); - - return 0; -} - -static void libdirac_flush(AVCodecContext *avccontext) -{ - /* Got a seek request. We will need free memory held in the private - * context and free the current Dirac decoder handle and then open - * a new decoder handle. */ - libdirac_decode_close(avccontext); - libdirac_decode_init(avccontext); - return; -} - - - -AVCodec ff_libdirac_decoder = { - .name = "libdirac", - .type = AVMEDIA_TYPE_VIDEO, - .id = CODEC_ID_DIRAC, - .priv_data_size = sizeof(DiracDecoderParams), - .init = libdirac_decode_init, - .close = libdirac_decode_close, - .decode = libdirac_decode_frame, - .capabilities = CODEC_CAP_DELAY, - .flush = libdirac_flush, - .long_name = NULL_IF_CONFIG_SMALL("libdirac Dirac 2.2"), -}; From 0ca4414d0f3eeb39bbad504eaaae76d40b7189cc Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 23 Apr 2012 10:33:55 +0300 Subject: [PATCH 6/8] audemux: Add a sanity check for the number of channels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes a division by 0. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind Signed-off-by: Martin Storsjö --- libavformat/au.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavformat/au.c b/libavformat/au.c index 3a83d283bb..bb9d5d5b56 100644 --- a/libavformat/au.c +++ b/libavformat/au.c @@ -145,6 +145,11 @@ static int au_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } + if (channels == 0 || channels > 64) { + av_log(s, AV_LOG_ERROR, "Invalid number of channels %d\n", channels); + return AVERROR_INVALIDDATA; + } + if (size >= 24) { /* skip unused data */ avio_skip(pb, size - 24); From 83b26046fcce5f497042fd7c5d7ae6904d7b76e1 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 10 Apr 2012 10:53:55 -0400 Subject: [PATCH 7/8] avutil: change default buffer size alignment for sample buffer functions Aligning nb_samples will give both correct plane pointer alignment and enough padding for SIMD-optimized functions. --- libavutil/samplefmt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c index 2e0aa98f58..0a2ffa0387 100644 --- a/libavutil/samplefmt.c +++ b/libavutil/samplefmt.c @@ -124,8 +124,10 @@ int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, return AVERROR(EINVAL); /* auto-select alignment if not specified */ - if (!align) - align = 32; + if (!align) { + align = 1; + nb_samples = FFALIGN(nb_samples, 32); + } /* check for integer overflow */ if (nb_channels > INT_MAX / align || From 7521c4bab28ff3a622171be5b39a6b210f4263f0 Mon Sep 17 00:00:00 2001 From: Dale Curtis Date: Mon, 23 Apr 2012 16:15:31 +0000 Subject: [PATCH 8/8] matroska: Clear prev_pkt between seeks. The new incremental parser doesn't always clear prev_pkt, however the packet queue is cleared when seeking. Which leads to a use-after-free. Verified using Valgrind. Signed-off-by: Dale Curtis Signed-off-by: Justin Ruggles --- libavformat/matroskadec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 100b97f5dd..e45cfb02c9 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2094,6 +2094,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET); matroska->current_id = 0; while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) { + matroska->prev_pkt = NULL; matroska_clear_queue(matroska); if (matroska_parse_cluster(matroska) < 0) break;