FFmpeg-soc
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
July 2007
- 23 participants
- 293 discussions
Author: kostya
Date: Fri Jul 6 16:15:19 2007
New Revision: 324
Log:
Drop redundant assignment and variable
Modified:
rv40/rv40.c
Modified: rv40/rv40.c
==============================================================================
--- rv40/rv40.c (original)
+++ rv40/rv40.c Fri Jul 6 16:15:19 2007
@@ -376,9 +376,7 @@ static inline void rv40_decode_block(DCT
*/
static inline int decode210(GetBitContext *gb){
- int n;
- n = get_bits1(gb);
- if (n == 1)
+ if (get_bits1(gb))
return 0;
else
return 2 - get_bits1(gb);
1
0
Author: kostya
Date: Fri Jul 6 08:37:06 2007
New Revision: 323
Log:
Add more decoding functions (and tables needed by them)
Added:
rv40/rv40vlc2.h
Modified:
rv40/rv40.c
rv40/rv40data.h
Modified: rv40/rv40.c
==============================================================================
--- rv40/rv40.c (original)
+++ rv40/rv40.c Fri Jul 6 08:37:06 2007
@@ -29,6 +29,7 @@
#include "mpegvideo.h"
#include "rv40vlc.h"
+#include "rv40vlc2.h"
#include "rv40data.h"
//#define DEBUG
@@ -55,6 +56,8 @@ typedef struct RV40VLC{
}RV40VLC;
static RV40VLC intra_vlcs[NUM_INTRA_TABLES], inter_vlcs[NUM_INTER_TABLES];
+static VLC aic_top_vlc;
+static VLC aic_mode1_vlc[AIC_MODE1_NUM], aic_mode2_vlc[AIC_MODE2_NUM];
/**
* @defgroup vlc RV40 VLC generating functions
@@ -143,6 +146,24 @@ static void rv40_init_tables()
rv40_gen_vlc(rv40_inter_thirdpatvlc_pointers[i][j], OTHERBLK_VLC_SIZE, &inter_vlcs[i].third_pattern[j]);
rv40_gen_vlc(rv40_inter_coeffvlc_pointers[i], COEFF_VLC_SIZE, &inter_vlcs[i].coefficient);
}
+
+ init_vlc(&aic_top_vlc, AIC_TOP_BITS, AIC_TOP_SIZE,
+ rv40_aic_top_vlc_bits, 1, 1,
+ rv40_aic_top_vlc_codes, 1, 1, INIT_VLC_USE_STATIC);
+ for(i = 0; i < AIC_MODE1_NUM; i++){
+ // For some reason every tenth VLC table is empty
+ // So skip it for consistency
+ // XXX: redo without this hack
+ if((i % 10) == 9) continue;
+ init_vlc(&aic_mode1_vlc[i], AIC_MODE1_BITS, AIC_MODE1_SIZE,
+ aic_mode1_vlc_bits[i], 1, 1,
+ aic_mode1_vlc_codes[i], 1, 1, INIT_VLC_USE_STATIC);
+ }
+ for(i = 0; i < AIC_MODE2_NUM; i++){
+ init_vlc(&aic_mode2_vlc[i], AIC_MODE2_BITS, AIC_MODE2_SIZE,
+ aic_mode2_vlc_bits[i], 1, 1,
+ aic_mode2_vlc_codes[i], 2, 2, INIT_VLC_USE_STATIC);
+ }
}
/** @} */ // vlc group
@@ -354,6 +375,15 @@ static inline void rv40_decode_block(DCT
* @{
*/
+static inline int decode210(GetBitContext *gb){
+ int n;
+ n = get_bits1(gb);
+ if (n == 1)
+ return 0;
+ else
+ return 2 - get_bits1(gb);
+}
+
/**
* Get stored dimension from bitstream
*
@@ -404,7 +434,122 @@ static int rv40_parse_slice_header(RV40D
mb_start = get_bits(gb, mb_bits);
return 0;
}
-/** @} */ //block functions
+
+/**
+ * Decode 4x4 intra types array
+ *
+ * This function expects old array passed as reference, filled with -1 is absent
+ * XXX: Corner cases may be not handled
+ */
+static int rv40_decode_intra_types(RV40DecContext *r, GetBitContext *gb, int dst[16])
+{
+ MpegEncContext *s = &r->s;
+ int i, j, k, v;
+ int A, B, C;
+ int pattern;
+ int *ptr;
+
+ for(i = 0; i < 4; i++){
+ if(!i && s->first_slice_line){
+ pattern = get_vlc2(gb, aic_top_vlc.table, AIC_TOP_BITS, 1);
+ dst[0] = (pattern >> 2) & 2;
+ dst[1] = (pattern >> 1) & 2;
+ dst[2] = pattern & 2;
+ dst[3] = (pattern << 1) & 2;
+ continue;
+ }
+ ptr = dst + i*4;
+ for(j = 0; j < 4; j++){
+ /* Coefficients are read using VLC chosen by prediction pattern
+ * First one (used for retrieving a pair of coefficients) is
+ * (top right) + 10 * top + 100 * left
+ * Second one (used for retrieving only one coefficient) is
+ * top + 10 * left
+ */
+ A = i ? ptr[-3] : dst[j+1]; // it won't be used for the last coefficient in a row
+ B = i ? ptr[-4] : dst[j];
+ C = j ? ptr[-1] : ptr[3];
+ pattern = A + B*10 + C*100;
+ for(k = 0; k < MODE2_PATTERNS_NUM; k++)
+ if(pattern == rv40_aic_table_index[k])
+ break;
+ if(j < 3 && k < MODE2_PATTERNS_NUM){ //pattern is found, decoding 2 coefficients
+ v = get_vlc2(gb, aic_mode2_vlc[k].table, AIC_MODE2_BITS, 2);
+ *ptr++ = v/9;
+ *ptr++ = v%9;
+ j++;
+ }else{
+ if(B != -1 && C != -1)
+ v = get_vlc2(gb, aic_mode1_vlc[B + C*10].table, AIC_MODE1_BITS, 1);
+ else{ // tricky decoding
+ v = 0;
+ switch(C){
+ case -1: // code 0 -> 1, 1 -> 0
+ if(B == -1 || B == 0 || B == 1)
+ v = get_bits1(gb) ^ 1;
+ break;
+ case 0:
+ case 2: // code 0 -> 2, 1 -> 0
+ v = (get_bits1(gb) ^ 1) << 1;
+ break;
+ }
+ }
+ *ptr++ = v;
+ }
+ }
+ }
+ return 0;
+}
+
+static int rv40_decode_macroblock(RV40DecContext *r)
+{
+ MpegEncContext *s = &r->s;
+ GetBitContext *gb = &s->gb;
+ int q, cbp;
+ int i;
+
+ q = decode210(gb);
+ switch(q){
+ case 0:
+ break;
+ case 1:
+ break;
+ case 2:
+ // q = decode_dquant(gb);
+ break;
+ }
+ //rv40_decode_intra_types(r, gb);
+ cbp = rv40_decode_cbp(gb, &intra_vlcs[2], 0);
+
+ // decode 24 4x4 blocks to fill one macroblock
+ for(i = 0; i < 24; i++, cbp >>= 1){
+ if(!(cbp & 1)) continue;
+ rv40_decode_block(s->block[i>>2] + (i&1)*2 + (i&2)*4, gb, &intra_vlcs[2], 2, 0);
+ }
+ return 0;
+}
+
+static int rv40_decode_slice(RV40DecContext *r, int slice_start, int slice_end)
+{
+ MpegEncContext *s = &r->s;
+
+ ff_er_add_slice(s, 0, slice_start, s->mb_width - 1, slice_end - 1, (AC_END|DC_END|MV_END));
+ s->first_slice_line = 1;
+ for(s->mb_y = slice_start; s->mb_y < slice_end; s->mb_y++) {
+ for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
+ ff_init_block_index(s);
+ ff_update_block_index(s);
+ s->dsp.clear_blocks(s->block[0]);
+
+ rv40_decode_macroblock(r);
+ }
+ ff_draw_horiz_band(s, s->mb_y * 16, 16);
+ s->first_slice_line = 0;
+ }
+ return 0;
+}
+
+/** @} */ //bitstream functions
/**
Modified: rv40/rv40data.h
==============================================================================
--- rv40/rv40data.h (original)
+++ rv40/rv40data.h Fri Jul 6 08:37:06 2007
@@ -89,4 +89,20 @@ static const uint8_t modulo_three_table[
{ 3, 2, 1, 2 }, { 3, 2, 2, 0 }, { 3, 2, 2, 1 }, { 3, 2, 2, 2 },
};
+#define MODE2_PATTERNS_NUM 20
+/**
+ * Intra types table
+ *
+ * These values are actually base 10 coded 3-tuples
+ * used for detecting standard block configurations
+ */
+static const uint16_t rv40_aic_table_index[MODE2_PATTERNS_NUM] = {
+ 0, 100, 200,
+ 11, 111, 211, 511, 611,
+ 22, 122, 222, 722,
+ 272, 227,
+ 822, 282, 228,
+ 112, 116, 221
+};
+
#endif /* RV40DATA_H */
Added: rv40/rv40vlc2.h
==============================================================================
--- (empty file)
+++ rv40/rv40vlc2.h Fri Jul 6 08:37:06 2007
@@ -0,0 +1,635 @@
+/*
+ * RealVideo 4 decoder
+ * copyright (c) 2007 Konstantin Shishkov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file rv40vlc2.h
+ * RV40 VLC tables used for macroblock information decoding.
+ */
+
+#ifndef RV40VLC2_H
+#define RV40VLC2_H
+
+#include <stdint.h>
+
+/**
+ * Codes used for the first four block types
+ */
+//@{
+#define AIC_TOP_BITS 8
+#define AIC_TOP_SIZE 16
+static const uint8_t rv40_aic_top_vlc_codes[AIC_TOP_SIZE] = {
+ 0x01, 0x05, 0x01, 0x00, 0x03, 0x3D, 0x1D, 0x02,
+ 0x04, 0x3C, 0x3F, 0x1C, 0x0D, 0x3E, 0x0C, 0x01
+};
+
+static const uint8_t rv40_aic_top_vlc_bits[AIC_TOP_SIZE] = {
+ 1, 4, 5, 5, 5, 7, 6, 5, 4, 7, 7, 6, 5, 7, 5, 3
+};
+//@}
+
+/**
+ * Codes used for determining pair of block types
+ */
+//@{
+#define AIC_MODE2_NUM 20
+#define AIC_MODE2_SIZE 81
+#define AIC_MODE2_BITS 9
+
+static const uint16_t aic_mode2_vlc_codes[AIC_MODE2_NUM][AIC_MODE2_SIZE] = {
+{ 0x0001, 0x0001, 0x0005, 0x01F5, 0x0011, 0x0049, 0x0000, 0x0048, 0x004B,
+ 0x0035, 0x0003, 0x0034, 0x03C9, 0x01F4, 0x00C9, 0x004A, 0x0FD9, 0x03C8,
+ 0x0010, 0x0037, 0x0001, 0x00C8, 0x0075, 0x01F7, 0x00CB, 0x0074, 0x0002,
+ 0x01F6, 0x00CA, 0x01F1, 0x01F0, 0x1F81, 0x07F9, 0x1F80, 0x1F83, 0x07F8,
+ 0x0077, 0x00F5, 0x0036, 0x07FB, 0x0076, 0x1F82, 0x00F4, 0x00F7, 0x07FA,
+ 0x0071, 0x00F6, 0x03CB, 0x03CA, 0x0FD8, 0x00F1, 0x03F5, 0x1F8D, 0x07E5,
+ 0x0013, 0x0031, 0x00F0, 0x0FDB, 0x00F3, 0x07E4, 0x0030, 0x01F3, 0x07E7,
+ 0x03F4, 0x07E6, 0x0070, 0x3F19, 0x01F2, 0x3F18, 0x0FDA, 0x0033, 0x07E1,
+ 0x01FD, 0x01FC, 0x0073, 0x01FF, 0x0FC5, 0x0FC4, 0x0FC7, 0x03F7, 0x0072, },
+{ 0x0005, 0x0005, 0x0005, 0x0079, 0x0005, 0x000D, 0x001D, 0x0078, 0x0069,
+ 0x0004, 0x0001, 0x0007, 0x0068, 0x001C, 0x001F, 0x0004, 0x006B, 0x000C,
+ 0x0004, 0x001E, 0x0006, 0x006A, 0x0015, 0x000F, 0x0014, 0x0017, 0x0007,
+ 0x0016, 0x000E, 0x0011, 0x0009, 0x00D1, 0x00D0, 0x0181, 0x00D3, 0x007B,
+ 0x0010, 0x0013, 0x0004, 0x00D2, 0x0007, 0x0319, 0x0008, 0x007A, 0x00DD,
+ 0x0019, 0x0006, 0x000B, 0x0065, 0x00DC, 0x0012, 0x0064, 0x0180, 0x00DF,
+ 0x0006, 0x0018, 0x0001, 0x00DE, 0x001D, 0x00D9, 0x001B, 0x0067, 0x000A,
+ 0x00D8, 0x00DB, 0x001C, 0x0318, 0x00DA, 0x0635, 0x0183, 0x0000, 0x00C5,
+ 0x0066, 0x0061, 0x0035, 0x00C4, 0x0182, 0x0634, 0x031B, 0x00C7, 0x001F, },
+{ 0x0005, 0x0001, 0x001D, 0x01C1, 0x0035, 0x00F1, 0x006D, 0x00F0, 0x0049,
+ 0x0000, 0x0004, 0x0003, 0x00F3, 0x0048, 0x0034, 0x006C, 0x01C0, 0x01C3,
+ 0x0007, 0x0006, 0x0001, 0x006F, 0x0002, 0x004B, 0x006E, 0x001C, 0x0005,
+ 0x0069, 0x0068, 0x006B, 0x0037, 0x01C2, 0x00F2, 0x0395, 0x01CD, 0x00FD,
+ 0x006A, 0x0036, 0x0015, 0x01CC, 0x0014, 0x0394, 0x004A, 0x00FC, 0x00FF,
+ 0x0017, 0x0031, 0x00FE, 0x01CF, 0x0397, 0x00F9, 0x01CE, 0x0725, 0x0396,
+ 0x0016, 0x0030, 0x0075, 0x0724, 0x00F8, 0x0727, 0x0033, 0x0391, 0x0390,
+ 0x0011, 0x0032, 0x001F, 0x00FB, 0x0074, 0x0726, 0x00FA, 0x001E, 0x0077,
+ 0x0019, 0x0018, 0x0004, 0x0010, 0x003D, 0x0076, 0x0071, 0x0013, 0x0001, },
+{ 0x000D, 0x0019, 0x0011, 0x0015, 0x0061, 0x0019, 0x0014, 0x01AD, 0x0060,
+ 0x0018, 0x0001, 0x0005, 0x001B, 0x0010, 0x0019, 0x0005, 0x0017, 0x0018,
+ 0x0016, 0x0004, 0x0004, 0x0013, 0x000C, 0x0012, 0x001A, 0x0018, 0x0005,
+ 0x000F, 0x001B, 0x0004, 0x001D, 0x0011, 0x001C, 0x0010, 0x000E, 0x001B,
+ 0x0013, 0x001F, 0x001A, 0x0029, 0x0005, 0x0063, 0x001E, 0x0009, 0x0062,
+ 0x0008, 0x0007, 0x0007, 0x0019, 0x0004, 0x001A, 0x0018, 0x006D, 0x0007,
+ 0x001B, 0x0007, 0x001A, 0x006C, 0x0006, 0x0012, 0x0005, 0x006F, 0x000B,
+ 0x006E, 0x0069, 0x001D, 0x0359, 0x0028, 0x002B, 0x002A, 0x001C, 0x00D5,
+ 0x0358, 0x001F, 0x0001, 0x001E, 0x0068, 0x00D4, 0x00D7, 0x0019, 0x0000, },
+{ 0x00B9, 0x0061, 0x0060, 0x00B8, 0x02B5, 0x01AD, 0x00BB, 0x0AF5, 0x0151,
+ 0x0001, 0x0001, 0x0005, 0x0000, 0x0003, 0x0005, 0x0004, 0x0063, 0x0025,
+ 0x00BA, 0x0004, 0x0007, 0x0062, 0x00A5, 0x0024, 0x006D, 0x0002, 0x006C,
+ 0x02B4, 0x000D, 0x006F, 0x0027, 0x00A4, 0x0026, 0x01AC, 0x0150, 0x01AF,
+ 0x01AE, 0x0021, 0x006E, 0x02B7, 0x0020, 0x0153, 0x0023, 0x00A7, 0x0152,
+ 0x00A6, 0x0006, 0x000C, 0x0022, 0x01A9, 0x0019, 0x002D, 0x02B6, 0x01A8,
+ 0x000F, 0x0007, 0x000E, 0x00A1, 0x0069, 0x002C, 0x0001, 0x01AB, 0x00A0,
+ 0x02B1, 0x00A3, 0x002F, 0x0AF4, 0x02B0, 0x0AF7, 0x02B3, 0x0068, 0x015D,
+ 0x0AF6, 0x01AA, 0x0055, 0x015C, 0x02B2, 0x0579, 0x0578, 0x015F, 0x00A2, },
+{ 0x0905, 0x013D, 0x013C, 0x0904, 0x121D, 0x049D, 0x049C, 0x243D, 0x0907,
+ 0x00ED, 0x0001, 0x0015, 0x0041, 0x013F, 0x0031, 0x0014, 0x025D, 0x025C,
+ 0x013E, 0x000D, 0x0000, 0x0040, 0x0139, 0x0043, 0x0030, 0x0017, 0x0033,
+ 0x0906, 0x0032, 0x0042, 0x00EC, 0x025F, 0x00EF, 0x025E, 0x049F, 0x0138,
+ 0x0901, 0x013B, 0x0259, 0x121C, 0x049E, 0x0900, 0x0258, 0x243C, 0x121F,
+ 0x0903, 0x003D, 0x00EE, 0x025B, 0x025A, 0x004D, 0x013A, 0x0902, 0x0245,
+ 0x00E9, 0x0016, 0x00E8, 0x0499, 0x0125, 0x0244, 0x004C, 0x0498, 0x090D,
+ 0x00EB, 0x003C, 0x0011, 0x049B, 0x049A, 0x0485, 0x00EA, 0x003F, 0x0124,
+ 0x090C, 0x003E, 0x0039, 0x0095, 0x0247, 0x0246, 0x0484, 0x0094, 0x0038, },
+{ 0x0F09, 0x00CD, 0x01FD, 0x0791, 0x1E6D, 0x0790, 0x03D9, 0x3CD1, 0x3CD0,
+ 0x0075, 0x0001, 0x0001, 0x0035, 0x00CC, 0x0011, 0x0000, 0x03D8, 0x01FC,
+ 0x03DB, 0x0010, 0x0003, 0x00CF, 0x03DA, 0x00CE, 0x0074, 0x0034, 0x0077,
+ 0x0793, 0x0013, 0x0076, 0x0071, 0x03C5, 0x0070, 0x01FF, 0x0792, 0x01FE,
+ 0x01F9, 0x0037, 0x00C9, 0x0F08, 0x01F8, 0x03C4, 0x00C8, 0x0F0B, 0x079D,
+ 0x03C7, 0x0001, 0x0012, 0x0073, 0x00CB, 0x0005, 0x0036, 0x03C6, 0x0072,
+ 0x007D, 0x0002, 0x00CA, 0x079C, 0x01FB, 0x00F5, 0x0031, 0x079F, 0x0F0A,
+ 0x0F35, 0x079E, 0x01FA, 0x1E6C, 0x1E6F, 0x3CD3, 0x0799, 0x03C1, 0x1E6E,
+ 0x3CD2, 0x0030, 0x00F4, 0x007C, 0x03C0, 0x03C3, 0x0798, 0x01E5, 0x00F7, },
+{ 0x01A5, 0x0001, 0x001D, 0x0021, 0x00A1, 0x000D, 0x0061, 0x06B9, 0x00A0,
+ 0x0060, 0x0001, 0x0005, 0x000C, 0x0020, 0x001C, 0x0004, 0x01A4, 0x01A7,
+ 0x00A3, 0x001F, 0x001E, 0x0023, 0x0022, 0x002D, 0x002C, 0x0063, 0x0062,
+ 0x1A81, 0x01A6, 0x01A1, 0x06B8, 0x06BB, 0x00A2, 0x06BA, 0x0D59, 0x06A5,
+ 0x01A0, 0x000F, 0x006D, 0x06A4, 0x002F, 0x00AD, 0x006C, 0x06A7, 0x00AC,
+ 0x0D58, 0x000E, 0x01A3, 0x00AF, 0x00AE, 0x006F, 0x01A2, 0x0D5B, 0x00A9,
+ 0x0019, 0x0001, 0x0009, 0x00A8, 0x006E, 0x002E, 0x0000, 0x01AD, 0x00AB,
+ 0x00AA, 0x0355, 0x0029, 0x1A80, 0x1A83, 0x1A82, 0x0354, 0x01AC, 0x0D5A,
+ 0x1A8D, 0x01AF, 0x0357, 0x0D45, 0x0D44, 0x0D47, 0x1A8C, 0x06A6, 0x06A1, },
+{ 0x0001, 0x0011, 0x0005, 0x0775, 0x00F9, 0x00F8, 0x0031, 0x0030, 0x0049,
+ 0x00FB, 0x0010, 0x0033, 0x0EC9, 0x038D, 0x038C, 0x00FA, 0x038F, 0x0774,
+ 0x0048, 0x0032, 0x0000, 0x01D5, 0x00E5, 0x038E, 0x00E4, 0x0013, 0x000D,
+ 0x0389, 0x0777, 0x0388, 0x038B, 0x1DF9, 0x0EC8, 0x3BC9, 0x1DF8, 0x038A,
+ 0x03B5, 0x0776, 0x00E7, 0x3BC8, 0x01D4, 0x3BCB, 0x0ECB, 0x0771, 0x0ECA,
+ 0x01D7, 0x03B4, 0x01D6, 0x1DFB, 0x0EF5, 0x0770, 0x0EF4, 0x3BCA, 0x0773,
+ 0x00E6, 0x03B7, 0x004B, 0x1DFA, 0x03B6, 0x0EF7, 0x00E1, 0x0EF6, 0x0EF1,
+ 0x03B1, 0x01D1, 0x003D, 0x0EF0, 0x0772, 0x077D, 0x077C, 0x003C, 0x01D0,
+ 0x03B0, 0x01D3, 0x003F, 0x03B3, 0x01D2, 0x0EF3, 0x077F, 0x00E0, 0x004A, },
+{ 0x0015, 0x0049, 0x0014, 0x07D1, 0x03FD, 0x03FC, 0x01C1, 0x01C0, 0x00F1,
+ 0x0017, 0x0001, 0x0001, 0x01C3, 0x0048, 0x004B, 0x0016, 0x0031, 0x01C2,
+ 0x004A, 0x0011, 0x0000, 0x01CD, 0x00F0, 0x01CC, 0x0075, 0x0010, 0x000D,
+ 0x03FF, 0x01CF, 0x01CE, 0x07D0, 0x0F81, 0x07D3, 0x1F1D, 0x0F80, 0x07D2,
+ 0x01C9, 0x03FE, 0x0074, 0x07DD, 0x00F3, 0x1F1C, 0x07DC, 0x03F9, 0x07DF,
+ 0x00F2, 0x00FD, 0x0077, 0x07DE, 0x07D9, 0x01C8, 0x07D8, 0x0F83, 0x03F8,
+ 0x0030, 0x0076, 0x0013, 0x0F82, 0x00FC, 0x03FB, 0x0033, 0x03FA, 0x03E5,
+ 0x03E4, 0x01CB, 0x0032, 0x1F1F, 0x03E7, 0x07DB, 0x07DA, 0x003D, 0x01CA,
+ 0x07C5, 0x03E6, 0x0071, 0x0F8D, 0x07C4, 0x1F1E, 0x0F8C, 0x03E1, 0x01F5, },
+{ 0x0019, 0x0065, 0x0018, 0x0351, 0x0350, 0x0353, 0x0021, 0x0020, 0x0064,
+ 0x001D, 0x0005, 0x0005, 0x01A5, 0x0023, 0x0067, 0x0005, 0x0066, 0x0022,
+ 0x001B, 0x0004, 0x0001, 0x0004, 0x001C, 0x0061, 0x001A, 0x0005, 0x0004,
+ 0x0007, 0x002D, 0x0006, 0x002C, 0x01A4, 0x002F, 0x0352, 0x035D, 0x0060,
+ 0x0001, 0x002E, 0x001F, 0x035C, 0x0000, 0x06B1, 0x01A7, 0x0029, 0x01A6,
+ 0x0028, 0x0063, 0x0062, 0x035F, 0x01A1, 0x002B, 0x06B0, 0x06B3, 0x01A0,
+ 0x0003, 0x006D, 0x001E, 0x035E, 0x006C, 0x06B2, 0x0002, 0x01A3, 0x01A2,
+ 0x000D, 0x0005, 0x0007, 0x01AD, 0x006F, 0x002A, 0x006E, 0x0004, 0x0004,
+ 0x000C, 0x0007, 0x0006, 0x000F, 0x000E, 0x00D5, 0x0009, 0x0006, 0x0007, },
+{ 0x0065, 0x0181, 0x0064, 0x36C9, 0x06D5, 0x0DB5, 0x0379, 0x0180, 0x0183,
+ 0x00D5, 0x001D, 0x001C, 0x0DB4, 0x0182, 0x0378, 0x00D4, 0x00D7, 0x06D4,
+ 0x0067, 0x001F, 0x0001, 0x00D6, 0x00D1, 0x018D, 0x0066, 0x0001, 0x0000,
+ 0x037B, 0x06D7, 0x037A, 0x0DB7, 0x36C8, 0x06D6, 0x0DB6, 0x1B79, 0x0DB1,
+ 0x018C, 0x0365, 0x00D0, 0x1B78, 0x00D3, 0x1B7B, 0x0364, 0x06D1, 0x06D0,
+ 0x018F, 0x018E, 0x00D2, 0x36CB, 0x0367, 0x0366, 0x06D3, 0x0DB0, 0x06D2,
+ 0x0361, 0x06DD, 0x0189, 0x36CA, 0x0360, 0x36F5, 0x0188, 0x0DB3, 0x36F4,
+ 0x0009, 0x0008, 0x0005, 0x06DC, 0x00DD, 0x018B, 0x00DC, 0x0004, 0x000B,
+ 0x018A, 0x0061, 0x0003, 0x0363, 0x00DF, 0x06DF, 0x0362, 0x000A, 0x001E, },
+{ 0x001D, 0x0061, 0x000D, 0x0D55, 0x06B9, 0x06B8, 0x01A5, 0x0021, 0x0020,
+ 0x0023, 0x000C, 0x0060, 0x0D54, 0x00AD, 0x00AC, 0x0022, 0x00AF, 0x06BB,
+ 0x000F, 0x001C, 0x0001, 0x002D, 0x0063, 0x01A4, 0x000E, 0x0001, 0x0005,
+ 0x01A7, 0x06BA, 0x01A6, 0x06A5, 0x0D57, 0x0D56, 0x1ABD, 0x0D51, 0x00AE,
+ 0x002C, 0x00A9, 0x002F, 0x0D50, 0x01A1, 0x1ABC, 0x06A4, 0x06A7, 0x06A6,
+ 0x00A8, 0x06A1, 0x01A0, 0x1ABF, 0x0D53, 0x06A0, 0x0D52, 0x1ABE, 0x06A3,
+ 0x0062, 0x002E, 0x0009, 0x0D5D, 0x01A3, 0x0D5C, 0x006D, 0x00AB, 0x06A2,
+ 0x006C, 0x001F, 0x0001, 0x06AD, 0x0029, 0x01A2, 0x0028, 0x0004, 0x001E,
+ 0x01AD, 0x006F, 0x0000, 0x01AC, 0x01AF, 0x06AC, 0x00AA, 0x006E, 0x0019, },
+{ 0x0019, 0x007D, 0x0018, 0x01B5, 0x000D, 0x01B4, 0x007C, 0x007F, 0x01B7,
+ 0x000C, 0x001B, 0x001A, 0x01B6, 0x000F, 0x00D5, 0x0019, 0x007E, 0x00D4,
+ 0x0018, 0x001B, 0x0001, 0x000E, 0x0011, 0x0009, 0x0005, 0x0005, 0x0005,
+ 0x00D7, 0x01B1, 0x0008, 0x01B0, 0x0079, 0x06FD, 0x0371, 0x0370, 0x00D6,
+ 0x0078, 0x01B3, 0x0010, 0x0373, 0x0013, 0x06FC, 0x007B, 0x007A, 0x00D1,
+ 0x00D0, 0x00D3, 0x0065, 0x0372, 0x06FF, 0x0064, 0x06FE, 0x037D, 0x00D2,
+ 0x00DD, 0x0067, 0x0004, 0x037C, 0x0012, 0x01B2, 0x0007, 0x0066, 0x01BD,
+ 0x0006, 0x0061, 0x0004, 0x01BC, 0x001A, 0x0060, 0x001D, 0x0004, 0x001C,
+ 0x0063, 0x0001, 0x0007, 0x000B, 0x0000, 0x0062, 0x000A, 0x0005, 0x0007, },
+{ 0x0069, 0x0045, 0x0068, 0x04BD, 0x0255, 0x04BC, 0x00E5, 0x00E4, 0x0031,
+ 0x0030, 0x0019, 0x0001, 0x0121, 0x00E7, 0x00E6, 0x0033, 0x00E1, 0x00E0,
+ 0x006B, 0x0018, 0x0001, 0x0044, 0x0032, 0x0047, 0x006A, 0x001B, 0x0005,
+ 0x003D, 0x0046, 0x0015, 0x0041, 0x0120, 0x0123, 0x04BF, 0x0122, 0x0040,
+ 0x003C, 0x00E3, 0x0014, 0x0254, 0x0043, 0x0975, 0x012D, 0x00E2, 0x00ED,
+ 0x0042, 0x00EC, 0x004D, 0x0257, 0x0256, 0x0251, 0x04BE, 0x0974, 0x0250,
+ 0x00EF, 0x00EE, 0x004C, 0x04B9, 0x012C, 0x04B8, 0x004F, 0x04BB, 0x0253,
+ 0x003F, 0x0017, 0x0001, 0x0252, 0x00E9, 0x00E8, 0x00EB, 0x0000, 0x0003,
+ 0x0016, 0x0002, 0x0004, 0x004E, 0x003E, 0x00EA, 0x0049, 0x000D, 0x0007, },
+{ 0x000D, 0x01BD, 0x000C, 0x0D31, 0x0D30, 0x0D33, 0x0359, 0x0358, 0x002D,
+ 0x0065, 0x001D, 0x001C, 0x0D32, 0x035B, 0x035A, 0x002C, 0x01BC, 0x0345,
+ 0x000F, 0x001F, 0x0001, 0x002F, 0x0064, 0x01BF, 0x0067, 0x0001, 0x0005,
+ 0x0066, 0x002E, 0x0061, 0x0029, 0x0695, 0x0694, 0x0697, 0x0696, 0x0060,
+ 0x01BE, 0x0D3D, 0x0028, 0x1A49, 0x0344, 0x1A48, 0x1A4B, 0x0D3C, 0x0691,
+ 0x002B, 0x01B9, 0x002A, 0x0D3F, 0x0690, 0x0347, 0x0D3E, 0x1A4A, 0x0346,
+ 0x00D5, 0x0341, 0x0063, 0x0D39, 0x0340, 0x0D38, 0x01B8, 0x0D3B, 0x0D3A,
+ 0x00D4, 0x0062, 0x0000, 0x0693, 0x01BB, 0x0343, 0x0342, 0x001E, 0x000E,
+ 0x006D, 0x0009, 0x0001, 0x006C, 0x00D7, 0x034D, 0x01BA, 0x0008, 0x0004, },
+{ 0x0075, 0x00CD, 0x0035, 0x03C1, 0x03C0, 0x07F9, 0x03C3, 0x1F8D, 0x00CC,
+ 0x0074, 0x0011, 0x0010, 0x03C2, 0x0FD9, 0x01F1, 0x00CF, 0x03CD, 0x00CE,
+ 0x0034, 0x0001, 0x0001, 0x0037, 0x00C9, 0x00C8, 0x0036, 0x0000, 0x0001,
+ 0x0FD8, 0x03CC, 0x00CB, 0x01F0, 0x07F8, 0x03CF, 0x07FB, 0x07FA, 0x00CA,
+ 0x01F3, 0x03CE, 0x00F5, 0x0FDB, 0x00F4, 0x07E5, 0x07E4, 0x07E7, 0x01F2,
+ 0x07E6, 0x03C9, 0x01FD, 0x0FDA, 0x1F8C, 0x07E1, 0x1F8F, 0x1F8E, 0x03C8,
+ 0x03CB, 0x0077, 0x0076, 0x0FC5, 0x03CA, 0x07E0, 0x00F7, 0x0FC4, 0x03F5,
+ 0x00F6, 0x01FC, 0x0003, 0x03F4, 0x0071, 0x03F7, 0x00F1, 0x0013, 0x0031,
+ 0x0030, 0x0070, 0x0005, 0x0012, 0x0073, 0x01FF, 0x0072, 0x007D, 0x0002, },
+{ 0x0061, 0x0055, 0x0060, 0x02C9, 0x02C8, 0x02CB, 0x0171, 0x00B5, 0x0054,
+ 0x0001, 0x0001, 0x0001, 0x0057, 0x0001, 0x0063, 0x001D, 0x0062, 0x0039,
+ 0x006D, 0x0000, 0x0005, 0x0038, 0x0056, 0x00B4, 0x006C, 0x0003, 0x001C,
+ 0x006F, 0x003B, 0x0002, 0x003A, 0x0170, 0x00B7, 0x0173, 0x0051, 0x006E,
+ 0x0025, 0x0050, 0x0069, 0x02CA, 0x0024, 0x0027, 0x0172, 0x00B6, 0x00B1,
+ 0x000D, 0x000C, 0x001F, 0x017D, 0x0026, 0x0068, 0x0053, 0x017C, 0x006B,
+ 0x001E, 0x000F, 0x0004, 0x017F, 0x006A, 0x02F5, 0x0019, 0x0021, 0x0052,
+ 0x02F4, 0x02F7, 0x0020, 0x0BCD, 0x05E5, 0x05E4, 0x0BCC, 0x0023, 0x00B0,
+ 0x02F6, 0x00B3, 0x0022, 0x02F1, 0x02F0, 0x0BCF, 0x0BCE, 0x017E, 0x005D, },
+{ 0x00BD, 0x0025, 0x01A1, 0x0159, 0x0299, 0x00BC, 0x0024, 0x0505, 0x0504,
+ 0x01A0, 0x0001, 0x001D, 0x006D, 0x001C, 0x0001, 0x0005, 0x0027, 0x01A3,
+ 0x0158, 0x001F, 0x001E, 0x01A2, 0x0026, 0x0021, 0x000D, 0x0020, 0x0023,
+ 0x0298, 0x006C, 0x0022, 0x00BF, 0x00BE, 0x01AD, 0x002D, 0x029B, 0x00B9,
+ 0x01AC, 0x00B8, 0x01AF, 0x029A, 0x006F, 0x015B, 0x006E, 0x0285, 0x0284,
+ 0x01AE, 0x0019, 0x002C, 0x01A9, 0x01A8, 0x000C, 0x000F, 0x015A, 0x00BB,
+ 0x000E, 0x0000, 0x0069, 0x01AB, 0x0018, 0x01AA, 0x0004, 0x0055, 0x00BA,
+ 0x0507, 0x0145, 0x0054, 0x0506, 0x00A5, 0x0501, 0x00A4, 0x0057, 0x0500,
+ 0x0A05, 0x0144, 0x00A7, 0x0287, 0x0286, 0x0503, 0x0147, 0x0A04, 0x0146, },
+{ 0x0759, 0x0041, 0x00E5, 0x03BD, 0x0E9D, 0x012D, 0x012C, 0x3A1D, 0x03BC,
+ 0x012F, 0x000D, 0x0040, 0x00E4, 0x03BF, 0x0043, 0x0042, 0x0758, 0x03BE,
+ 0x00E7, 0x0001, 0x0000, 0x003D, 0x00E6, 0x0015, 0x0014, 0x0017, 0x003C,
+ 0x743D, 0x012E, 0x03B9, 0x03B8, 0x0E9C, 0x03BB, 0x075B, 0x3A1C, 0x0E9F,
+ 0x0129, 0x00E1, 0x0128, 0x0E9E, 0x012B, 0x075A, 0x00E0, 0x0E99, 0x0745,
+ 0x3A1F, 0x03BA, 0x0744, 0x0E98, 0x1D0D, 0x03A5, 0x0E9B, 0x743C, 0x0E9A,
+ 0x012A, 0x004D, 0x00E3, 0x0E85, 0x01D5, 0x0E84, 0x004C, 0x0747, 0x1D0C,
+ 0x01D4, 0x003F, 0x0016, 0x0746, 0x03A4, 0x0741, 0x004F, 0x003E, 0x01D7,
+ 0x0740, 0x000C, 0x0011, 0x004E, 0x00E2, 0x00ED, 0x00EC, 0x0049, 0x0048, },
+};
+
+static const uint8_t aic_mode2_vlc_bits[AIC_MODE2_NUM][AIC_MODE2_SIZE] = {
+{ 1, 5, 4, 10, 6, 8, 5, 8, 8,
+ 7, 5, 7, 11, 10, 9, 8, 13, 11,
+ 6, 7, 3, 9, 8, 10, 9, 8, 5,
+ 10, 9, 10, 10, 14, 12, 14, 14, 12,
+ 8, 9, 7, 12, 8, 14, 9, 9, 12,
+ 8, 9, 11, 11, 13, 9, 11, 14, 12,
+ 6, 7, 9, 13, 9, 12, 7, 10, 12,
+ 11, 12, 8, 15, 10, 15, 13, 7, 12,
+ 10, 10, 8, 10, 13, 13, 13, 11, 8, },
+{ 4, 6, 5, 11, 8, 10, 7, 11, 9,
+ 4, 1, 4, 9, 7, 7, 5, 9, 10,
+ 6, 7, 4, 9, 9, 10, 9, 9, 6,
+ 9, 10, 9, 10, 12, 12, 13, 12, 11,
+ 9, 9, 8, 12, 8, 14, 10, 11, 12,
+ 7, 8, 10, 11, 12, 9, 11, 13, 12,
+ 6, 7, 8, 12, 9, 12, 7, 11, 10,
+ 12, 12, 9, 14, 12, 15, 13, 8, 12,
+ 11, 11, 10, 12, 13, 15, 14, 12, 9, },
+{ 5, 7, 6, 12, 9, 11, 8, 11, 10,
+ 7, 5, 7, 11, 10, 9, 8, 12, 12,
+ 5, 5, 1, 8, 7, 10, 8, 6, 4,
+ 8, 8, 8, 9, 12, 11, 13, 12, 11,
+ 8, 9, 8, 12, 8, 13, 10, 11, 11,
+ 8, 9, 11, 12, 13, 11, 12, 14, 13,
+ 8, 9, 10, 14, 11, 14, 9, 13, 13,
+ 8, 9, 6, 11, 10, 14, 11, 6, 10,
+ 6, 6, 4, 8, 9, 10, 10, 8, 5, },
+{ 11, 7, 8, 10, 12, 9, 10, 14, 12,
+ 7, 1, 5, 7, 8, 6, 4, 10, 9,
+ 10, 5, 4, 8, 11, 8, 7, 6, 7,
+ 11, 6, 7, 8, 10, 8, 10, 11, 9,
+ 10, 8, 9, 13, 9, 12, 8, 11, 12,
+ 11, 4, 7, 8, 9, 6, 8, 12, 9,
+ 8, 5, 8, 12, 9, 10, 6, 12, 11,
+ 12, 12, 10, 15, 13, 13, 13, 10, 13,
+ 15, 10, 9, 10, 12, 13, 13, 10, 9, },
+{ 11, 8, 8, 11, 13, 10, 11, 15, 12,
+ 7, 1, 4, 7, 7, 5, 4, 8, 9,
+ 11, 5, 5, 8, 11, 9, 8, 7, 8,
+ 13, 7, 8, 9, 11, 9, 10, 12, 10,
+ 10, 9, 8, 13, 9, 12, 9, 11, 12,
+ 11, 5, 7, 9, 10, 6, 9, 13, 10,
+ 7, 4, 7, 11, 8, 9, 5, 10, 11,
+ 13, 11, 9, 15, 13, 15, 13, 8, 12,
+ 15, 10, 10, 12, 13, 14, 14, 12, 11, },
+{ 12, 9, 9, 12, 13, 11, 11, 14, 12,
+ 8, 2, 5, 7, 9, 6, 5, 10, 10,
+ 9, 4, 2, 7, 9, 7, 6, 5, 6,
+ 12, 6, 7, 8, 10, 8, 10, 11, 9,
+ 12, 9, 10, 13, 11, 12, 10, 14, 13,
+ 12, 6, 8, 10, 10, 7, 9, 12, 10,
+ 8, 5, 8, 11, 9, 10, 7, 11, 12,
+ 8, 6, 5, 11, 11, 11, 8, 6, 9,
+ 12, 6, 6, 8, 10, 10, 11, 8, 6, },
+{ 13, 9, 10, 12, 14, 12, 11, 15, 15,
+ 8, 1, 5, 7, 9, 6, 5, 11, 10,
+ 11, 6, 5, 9, 11, 9, 8, 7, 8,
+ 12, 6, 8, 8, 11, 8, 10, 12, 10,
+ 10, 7, 9, 13, 10, 11, 9, 13, 12,
+ 11, 3, 6, 8, 9, 4, 7, 11, 8,
+ 8, 5, 9, 12, 10, 9, 7, 12, 13,
+ 13, 12, 10, 14, 14, 15, 12, 11, 14,
+ 15, 7, 9, 8, 11, 11, 12, 10, 9, },
+{ 10, 5, 6, 9, 11, 7, 8, 12, 11,
+ 8, 1, 4, 7, 9, 6, 4, 10, 10,
+ 11, 6, 6, 9, 9, 9, 9, 8, 8,
+ 14, 10, 10, 12, 12, 11, 12, 13, 12,
+ 10, 7, 8, 12, 9, 11, 8, 12, 11,
+ 13, 7, 10, 11, 11, 8, 10, 13, 11,
+ 6, 3, 7, 11, 8, 9, 5, 10, 11,
+ 11, 11, 9, 14, 14, 14, 11, 10, 13,
+ 14, 10, 11, 13, 13, 13, 14, 12, 12, },
+{ 2, 5, 3, 11, 8, 8, 6, 6, 7,
+ 8, 5, 6, 12, 10, 10, 8, 10, 11,
+ 7, 6, 2, 9, 8, 10, 8, 5, 4,
+ 10, 11, 10, 10, 13, 12, 14, 13, 10,
+ 10, 11, 8, 14, 9, 14, 12, 11, 12,
+ 9, 10, 9, 13, 12, 11, 12, 14, 11,
+ 8, 10, 7, 13, 10, 12, 8, 12, 12,
+ 10, 9, 6, 12, 11, 11, 11, 6, 9,
+ 10, 9, 6, 10, 9, 12, 11, 8, 7, },
+{ 6, 8, 6, 12, 11, 11, 10, 10, 9,
+ 6, 1, 3, 10, 8, 8, 6, 7, 10,
+ 8, 6, 3, 10, 9, 10, 8, 6, 5,
+ 11, 10, 10, 12, 13, 12, 14, 13, 12,
+ 10, 11, 8, 12, 9, 14, 12, 11, 12,
+ 9, 9, 8, 12, 12, 10, 12, 13, 11,
+ 7, 8, 6, 13, 9, 11, 7, 11, 11,
+ 11, 10, 7, 14, 11, 12, 12, 7, 10,
+ 12, 11, 8, 13, 12, 14, 13, 11, 10, },
+{ 7, 10, 7, 13, 13, 13, 11, 11, 10,
+ 8, 5, 6, 12, 11, 10, 9, 10, 11,
+ 7, 5, 1, 9, 8, 10, 7, 4, 4,
+ 9, 11, 9, 11, 12, 11, 13, 13, 10,
+ 9, 11, 8, 13, 9, 14, 12, 11, 12,
+ 11, 10, 10, 13, 12, 11, 14, 14, 12,
+ 9, 10, 8, 13, 10, 14, 9, 12, 12,
+ 9, 7, 4, 12, 10, 11, 10, 6, 7,
+ 9, 7, 4, 9, 9, 11, 9, 7, 5, },
+{ 7, 9, 7, 14, 11, 12, 10, 9, 9,
+ 8, 5, 5, 12, 9, 10, 8, 8, 11,
+ 7, 5, 2, 8, 8, 9, 7, 4, 4,
+ 10, 11, 10, 12, 14, 11, 12, 13, 12,
+ 9, 10, 8, 13, 8, 13, 10, 11, 11,
+ 9, 9, 8, 14, 10, 10, 11, 12, 11,
+ 10, 11, 9, 14, 10, 14, 9, 12, 14,
+ 6, 6, 3, 11, 8, 9, 8, 3, 6,
+ 9, 7, 4, 10, 8, 11, 10, 6, 5, },
+{ 6, 8, 7, 13, 12, 12, 10, 9, 9,
+ 9, 7, 8, 13, 11, 11, 9, 11, 12,
+ 7, 6, 1, 9, 8, 10, 7, 5, 4,
+ 10, 12, 10, 12, 13, 13, 14, 13, 11,
+ 9, 11, 9, 13, 10, 14, 12, 12, 12,
+ 11, 12, 10, 14, 13, 12, 13, 14, 12,
+ 8, 9, 7, 13, 10, 13, 8, 11, 12,
+ 8, 6, 3, 12, 9, 10, 9, 4, 6,
+ 10, 8, 5, 10, 10, 12, 11, 8, 6, },
+{ 7, 10, 7, 12, 9, 12, 10, 10, 12,
+ 9, 7, 7, 12, 9, 11, 6, 10, 11,
+ 6, 6, 1, 9, 8, 9, 7, 4, 5,
+ 11, 12, 9, 12, 10, 14, 13, 13, 11,
+ 10, 12, 8, 13, 8, 14, 10, 10, 11,
+ 11, 11, 10, 13, 14, 10, 14, 13, 11,
+ 11, 10, 7, 13, 8, 12, 7, 10, 12,
+ 7, 10, 4, 12, 6, 10, 8, 5, 8,
+ 10, 7, 4, 9, 7, 10, 9, 6, 5, },
+{ 7, 9, 7, 13, 12, 13, 10, 10, 8,
+ 8, 5, 6, 11, 10, 10, 8, 10, 10,
+ 7, 5, 2, 9, 8, 9, 7, 5, 3,
+ 8, 9, 7, 9, 11, 11, 13, 11, 9,
+ 8, 10, 7, 12, 9, 14, 11, 10, 10,
+ 9, 10, 9, 12, 12, 12, 13, 14, 12,
+ 10, 10, 9, 13, 11, 13, 9, 13, 12,
+ 8, 7, 4, 12, 10, 10, 10, 6, 6,
+ 7, 6, 3, 9, 8, 10, 9, 6, 3, },
+{ 7, 10, 7, 13, 13, 13, 11, 11, 9,
+ 8, 6, 6, 13, 11, 11, 9, 10, 11,
+ 7, 6, 1, 9, 8, 10, 8, 5, 4,
+ 8, 9, 8, 9, 12, 12, 12, 12, 8,
+ 10, 13, 9, 14, 11, 14, 14, 13, 12,
+ 9, 10, 9, 13, 12, 11, 13, 14, 11,
+ 9, 11, 8, 13, 11, 13, 10, 13, 13,
+ 9, 8, 5, 12, 10, 11, 11, 6, 7,
+ 8, 7, 3, 8, 9, 11, 10, 7, 4, },
+{ 8, 9, 7, 11, 11, 12, 11, 14, 9,
+ 8, 6, 6, 11, 13, 10, 9, 11, 9,
+ 7, 5, 1, 7, 9, 9, 7, 5, 3,
+ 13, 11, 9, 10, 12, 11, 12, 12, 9,
+ 10, 11, 9, 13, 9, 12, 12, 12, 10,
+ 12, 11, 10, 13, 14, 12, 14, 14, 11,
+ 11, 8, 8, 13, 11, 12, 9, 13, 11,
+ 9, 10, 5, 11, 8, 11, 9, 6, 7,
+ 7, 8, 4, 6, 8, 10, 8, 8, 5, },
+{ 8, 10, 8, 13, 13, 13, 12, 11, 10,
+ 5, 1, 3, 10, 7, 8, 6, 8, 9,
+ 8, 7, 4, 9, 10, 11, 8, 7, 6,
+ 8, 9, 7, 9, 12, 11, 12, 10, 8,
+ 9, 10, 8, 13, 9, 9, 12, 11, 11,
+ 7, 7, 6, 12, 9, 8, 10, 12, 8,
+ 6, 7, 4, 12, 8, 13, 6, 9, 10,
+ 13, 13, 9, 15, 14, 14, 15, 9, 11,
+ 13, 11, 9, 13, 13, 15, 15, 12, 10, },
+{ 10, 8, 9, 11, 12, 10, 8, 13, 13,
+ 9, 2, 5, 7, 5, 4, 3, 8, 9,
+ 11, 5, 5, 9, 8, 8, 6, 8, 8,
+ 12, 7, 8, 10, 10, 9, 8, 12, 10,
+ 9, 10, 9, 12, 7, 11, 7, 12, 12,
+ 9, 5, 8, 9, 9, 6, 6, 11, 10,
+ 6, 4, 7, 9, 5, 9, 3, 9, 10,
+ 13, 11, 9, 13, 10, 13, 10, 9, 13,
+ 14, 11, 10, 12, 12, 13, 11, 14, 11, },
+{ 11, 7, 8, 10, 12, 9, 9, 14, 10,
+ 9, 4, 7, 8, 10, 7, 7, 11, 10,
+ 8, 2, 2, 6, 8, 5, 5, 5, 6,
+ 15, 9, 10, 10, 12, 10, 11, 14, 12,
+ 9, 8, 9, 12, 9, 11, 8, 12, 11,
+ 14, 10, 11, 12, 13, 10, 12, 15, 12,
+ 9, 7, 8, 12, 9, 12, 7, 11, 13,
+ 9, 6, 5, 11, 10, 11, 7, 6, 9,
+ 11, 4, 5, 7, 8, 8, 8, 7, 7, },
+};
+//@}
+
+/**
+ * Codes used for determining block type
+ */
+//@{
+#define AIC_MODE1_NUM 90
+#define AIC_MODE1_SIZE 9
+#define AIC_MODE1_BITS 7
+
+static const uint8_t aic_mode1_vlc_codes[AIC_MODE1_NUM][AIC_MODE1_SIZE] = {
+ { 0x01, 0x01, 0x01, 0x11, 0x00, 0x09, 0x03, 0x10, 0x05,},
+ { 0x09, 0x01, 0x01, 0x05, 0x11, 0x00, 0x03, 0x21, 0x20,},
+ { 0x01, 0x01, 0x01, 0x11, 0x09, 0x10, 0x05, 0x00, 0x03,},
+ { 0x01, 0x01, 0x00, 0x03, 0x21, 0x05, 0x09, 0x20, 0x11,},
+ { 0x01, 0x09, 0x00, 0x29, 0x08, 0x15, 0x03, 0x0B, 0x28,},
+ { 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x03, 0x02,},
+ { 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x01, 0x09, 0x08,},
+ { 0x01, 0x01, 0x01, 0x09, 0x01, 0x08, 0x00, 0x03, 0x05,},
+ { 0x01, 0x01, 0x01, 0x00, 0x05, 0x11, 0x09, 0x10, 0x03,},
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},
+
+ { 0x01, 0x01, 0x01, 0x05, 0x01, 0x00, 0x03, 0x09, 0x08,},
+ { 0x09, 0x01, 0x01, 0x05, 0x11, 0x00, 0x03, 0x21, 0x20,},
+ { 0x01, 0x01, 0x01, 0x0D, 0x05, 0x04, 0x00, 0x07, 0x0C,},
+ { 0x01, 0x01, 0x00, 0x05, 0x11, 0x03, 0x09, 0x21, 0x20,},
+ { 0x05, 0x01, 0x01, 0x11, 0x00, 0x09, 0x03, 0x21, 0x20,},
+ { 0x09, 0x01, 0x01, 0x00, 0x05, 0x01, 0x03, 0x11, 0x10,},
+ { 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x02,},
+ { 0x01, 0x01, 0x01, 0x09, 0x00, 0x05, 0x01, 0x03, 0x08,},
+ { 0x01, 0x01, 0x01, 0x09, 0x11, 0x05, 0x00, 0x10, 0x03,},
+ { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},
+
+ { 0x01, 0x00, 0x01, 0x09, 0x08, 0x15, 0x14, 0x0B, 0x03,},
+ { 0x0D, 0x01, 0x01, 0x05, 0x0C, 0x04, 0x01, 0x00, 0x07,},
+ { 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x03, 0x01, 0x01,},
+ { 0x05, 0x01, 0x01, 0x04, 0x19, 0x07, 0x18, 0x0D, 0x00,},
+ { 0x11, 0x09, 0x01, 0x21, 0x05, 0x20, 0x01, 0x00, 0x03,},
+ { 0x41, 0x01, 0x00, 0x05, 0x40, 0x03, 0x09, 0x21, 0x11,},
+ { 0x29, 0x01, 0x00, 0x28, 0x09, 0x15, 0x03, 0x08, 0x0B,},
+ { 0x01, 0x00, 0x01, 0x11, 0x09, 0x10, 0x05, 0x01, 0x03,},
+ { 0x05, 0x01, 0x01, 0x04, 0x0D, 0x0C, 0x07, 0x00, 0x01,},
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},
+
+ { 0x01, 0x00, 0x03, 0x05, 0x11, 0x10, 0x25, 0x24, 0x13,},
+ { 0x21, 0x01, 0x01, 0x00, 0x11, 0x03, 0x05, 0x20, 0x09,},
+ { 0x01, 0x01, 0x01, 0x00, 0x09, 0x11, 0x10, 0x05, 0x03,},
+ { 0x21, 0x05, 0x01, 0x01, 0x09, 0x00, 0x11, 0x20, 0x03,},
+ { 0x05, 0x01, 0x00, 0x04, 0x01, 0x19, 0x07, 0x18, 0x0D,},
+ { 0x11, 0x01, 0x00, 0x01, 0x09, 0x01, 0x03, 0x10, 0x05,},
+ { 0x1D, 0x01, 0x05, 0x0D, 0x0C, 0x04, 0x00, 0x1C, 0x0F,},
+ { 0x05, 0x19, 0x01, 0x04, 0x00, 0x18, 0x1B, 0x1A, 0x07,},
+ { 0x09, 0x01, 0x00, 0x01, 0x05, 0x03, 0x11, 0x10, 0x01,},
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},
+
+ { 0x01, 0x00, 0x03, 0x41, 0x05, 0x40, 0x09, 0x11, 0x21,},
+ { 0x05, 0x01, 0x01, 0x19, 0x04, 0x07, 0x00, 0x18, 0x0D,},
+ { 0x01, 0x01, 0x01, 0x05, 0x01, 0x04, 0x01, 0x00, 0x03,},
+ { 0x01, 0x05, 0x00, 0x0D, 0x01, 0x04, 0x07, 0x19, 0x18,},
+ { 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x02,},
+ { 0x31, 0x01, 0x05, 0x19, 0x04, 0x07, 0x00, 0x30, 0x0D,},
+ { 0x01, 0x00, 0x03, 0x11, 0x01, 0x05, 0x01, 0x09, 0x10,},
+ { 0x01, 0x05, 0x01, 0x11, 0x01, 0x10, 0x00, 0x03, 0x09,},
+ { 0x01, 0x09, 0x00, 0x29, 0x03, 0x08, 0x28, 0x15, 0x0B,},
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},
+
+ { 0x01, 0x01, 0x00, 0x09, 0x15, 0x03, 0x08, 0x14, 0x0B,},
+ { 0x11, 0x01, 0x01, 0x00, 0x09, 0x01, 0x03, 0x10, 0x05,},
+ { 0x01, 0x00, 0x03, 0x25, 0x11, 0x05, 0x10, 0x24, 0x13,},
+ { 0x11, 0x01, 0x00, 0x01, 0x09, 0x01, 0x05, 0x10, 0x03,},
+ { 0x05, 0x01, 0x00, 0x0D, 0x0C, 0x04, 0x0F, 0x1D, 0x1C,},
+ { 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x03, 0x02,},
+ { 0x21, 0x01, 0x05, 0x09, 0x11, 0x00, 0x03, 0x41, 0x40,},
+ { 0x05, 0x01, 0x00, 0x1D, 0x1C, 0x0D, 0x0C, 0x0F, 0x04,},
+ { 0x05, 0x01, 0x00, 0x0D, 0x31, 0x04, 0x19, 0x30, 0x07,},
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},
+
+ { 0x01, 0x01, 0x00, 0x21, 0x05, 0x11, 0x03, 0x09, 0x20,},
+ { 0x01, 0x01, 0x00, 0x11, 0x03, 0x05, 0x01, 0x09, 0x10,},
+ { 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x02,},
+ { 0x05, 0x01, 0x04, 0x19, 0x07, 0x0D, 0x00, 0x31, 0x30,},
+ { 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x02,},
+ { 0x05, 0x01, 0x01, 0x11, 0x09, 0x00, 0x03, 0x21, 0x20,},
+ { 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x02,},
+ { 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x01, 0x01, 0x02,},
+ { 0x09, 0x01, 0x00, 0x29, 0x08, 0x15, 0x03, 0x28, 0x0B,},
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},
+
+ { 0x01, 0x01, 0x01, 0x05, 0x01, 0x04, 0x00, 0x01, 0x03,},
+ { 0x09, 0x01, 0x00, 0x29, 0x28, 0x15, 0x08, 0x03, 0x0B,},
+ { 0x01, 0x00, 0x01, 0x11, 0x05, 0x10, 0x09, 0x01, 0x03,},
+ { 0x05, 0x04, 0x01, 0x1D, 0x0D, 0x0C, 0x1C, 0x00, 0x0F,},
+ { 0x09, 0x11, 0x01, 0x41, 0x00, 0x40, 0x05, 0x03, 0x21,},
+ { 0x0D, 0x05, 0x01, 0x1D, 0x1C, 0x0C, 0x04, 0x00, 0x0F,},
+ { 0x41, 0x09, 0x01, 0x40, 0x00, 0x11, 0x05, 0x03, 0x21,},
+ { 0x01, 0x01, 0x01, 0x05, 0x01, 0x04, 0x00, 0x01, 0x03,},
+ { 0x05, 0x04, 0x01, 0x0D, 0x01, 0x0C, 0x07, 0x01, 0x00,},
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},
+
+ { 0x05, 0x04, 0x01, 0x07, 0x19, 0x31, 0x30, 0x0D, 0x00,},
+ { 0x21, 0x01, 0x01, 0x00, 0x11, 0x09, 0x20, 0x05, 0x03,},
+ { 0x05, 0x01, 0x01, 0x04, 0x07, 0x0D, 0x0C, 0x00, 0x01,},
+ { 0x21, 0x09, 0x01, 0x00, 0x20, 0x05, 0x23, 0x22, 0x03,},
+ { 0x31, 0x0D, 0x01, 0x19, 0x05, 0x30, 0x04, 0x07, 0x00,},
+ { 0x31, 0x05, 0x01, 0x04, 0x19, 0x00, 0x0D, 0x30, 0x07,},
+ { 0x31, 0x01, 0x00, 0x0D, 0x05, 0x19, 0x04, 0x30, 0x07,},
+ { 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x02, 0x01, 0x01,},
+ { 0x01, 0x00, 0x01, 0x01, 0x05, 0x09, 0x08, 0x03, 0x01,},
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},
+};
+
+static const uint8_t aic_mode1_vlc_bits[AIC_MODE1_NUM][AIC_MODE1_SIZE] = {
+ { 1, 4, 2, 7, 4, 6, 4, 7, 5,},
+ { 5, 1, 3, 4, 6, 3, 3, 7, 7,},
+ { 1, 4, 2, 7, 6, 7, 5, 4, 4,},
+ { 1, 3, 3, 3, 7, 4, 5, 7, 6,},
+ { 2, 4, 2, 6, 4, 5, 2, 4, 6,},
+ { 7, 2, 3, 4, 7, 1, 5, 7, 7,},
+ { 5, 1, 3, 6, 5, 5, 2, 7, 7,},
+ { 2, 5, 1, 7, 3, 7, 5, 5, 6,},
+ { 2, 4, 1, 4, 5, 7, 6, 7, 4,},
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0,},
+
+ { 2, 1, 3, 6, 5, 5, 5, 7, 7,},
+ { 5, 1, 3, 4, 6, 3, 3, 7, 7,},
+ { 4, 1, 2, 6, 5, 5, 4, 5, 6,},
+ { 3, 1, 3, 4, 6, 3, 5, 7, 7,},
+ { 4, 1, 3, 6, 3, 5, 3, 7, 7,},
+ { 6, 1, 4, 4, 5, 2, 4, 7, 7,},
+ { 7, 1, 5, 7, 4, 3, 2, 7, 7,},
+ { 5, 3, 2, 7, 5, 6, 1, 5, 7,},
+ { 4, 1, 2, 6, 7, 5, 4, 7, 4,},
+ { 1, 0, 1, 0, 0, 0, 0, 0, 0,},
+
+ { 3, 3, 1, 5, 5, 6, 6, 5, 3,},
+ { 6, 2, 1, 5, 6, 5, 4, 4, 5,},
+ { 6, 4, 1, 7, 6, 7, 6, 3, 2,},
+ { 4, 3, 1, 4, 6, 4, 6, 5, 3,},
+ { 6, 5, 1, 7, 4, 7, 3, 3, 3,},
+ { 7, 2, 2, 3, 7, 2, 4, 6, 5,},
+ { 6, 2, 2, 6, 4, 5, 2, 4, 4,},
+ { 4, 4, 1, 7, 6, 7, 5, 2, 4,},
+ { 5, 4, 1, 5, 6, 6, 5, 4, 2,},
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0,},
+
+ { 2, 2, 2, 3, 5, 5, 6, 6, 5,},
+ { 7, 1, 3, 3, 6, 3, 4, 7, 5,},
+ { 2, 4, 1, 4, 6, 7, 7, 5, 4,},
+ { 7, 4, 3, 1, 5, 3, 6, 7, 3,},
+ { 4, 3, 3, 4, 1, 6, 4, 6, 5,},
+ { 7, 4, 4, 2, 6, 1, 4, 7, 5,},
+ { 5, 2, 3, 4, 4, 3, 2, 5, 4,},
+ { 3, 5, 2, 3, 2, 5, 5, 5, 3,},
+ { 6, 4, 4, 2, 5, 4, 7, 7, 1,},
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0,},
+
+ { 2, 2, 2, 7, 3, 7, 4, 5, 6,},
+ { 4, 1, 3, 6, 4, 4, 3, 6, 5,},
+ { 2, 4, 1, 7, 3, 7, 6, 6, 6,},
+ { 3, 4, 3, 5, 1, 4, 4, 6, 6,},
+ { 4, 5, 2, 7, 1, 7, 3, 7, 7,},
+ { 6, 2, 3, 5, 3, 3, 2, 6, 4,},
+ { 4, 4, 4, 7, 2, 5, 1, 6, 7,},
+ { 4, 5, 2, 7, 1, 7, 4, 4, 6,},
+ { 2, 4, 2, 6, 2, 4, 6, 5, 4,},
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0,},
+
+ { 1, 3, 3, 5, 6, 3, 5, 6, 5,},
+ { 7, 1, 4, 4, 6, 2, 4, 7, 5,},
+ { 2, 2, 2, 6, 5, 3, 5, 6, 5,},
+ { 7, 4, 4, 2, 6, 1, 5, 7, 4,},
+ { 3, 2, 2, 4, 4, 3, 4, 5, 5,},
+ { 7, 2, 5, 3, 7, 1, 4, 7, 7,},
+ { 6, 2, 3, 4, 5, 2, 2, 7, 7,},
+ { 3, 2, 2, 5, 5, 4, 4, 4, 3,},
+ { 3, 2, 2, 4, 6, 3, 5, 6, 3,},
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0,},
+
+ { 1, 3, 3, 7, 4, 6, 3, 5, 7,},
+ { 4, 1, 4, 7, 4, 5, 2, 6, 7,},
+ { 2, 4, 1, 7, 5, 7, 3, 7, 7,},
+ { 3, 2, 3, 5, 3, 4, 2, 6, 6,},
+ { 3, 5, 4, 7, 2, 7, 1, 7, 7,},
+ { 4, 1, 3, 6, 5, 3, 3, 7, 7,},
+ { 4, 2, 5, 7, 3, 7, 1, 7, 7,},
+ { 7, 4, 1, 7, 3, 7, 2, 5, 7,},
+ { 4, 2, 2, 6, 4, 5, 2, 6, 4,},
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0,},
+
+ { 3, 4, 1, 7, 6, 7, 6, 2, 6,},
+ { 4, 2, 2, 6, 6, 5, 4, 2, 4,},
+ { 4, 4, 1, 7, 5, 7, 6, 2, 4,},
+ { 3, 3, 2, 5, 4, 4, 5, 2, 4,},
+ { 4, 5, 2, 7, 2, 7, 3, 2, 6,},
+ { 4, 3, 2, 5, 5, 4, 3, 2, 4,},
+ { 7, 4, 2, 7, 2, 5, 3, 2, 6,},
+ { 4, 6, 2, 7, 3, 7, 6, 1, 6,},
+ { 5, 5, 1, 6, 4, 6, 5, 2, 4,},
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0,},
+
+ { 3, 3, 2, 3, 5, 6, 6, 4, 2,},
+ { 7, 1, 3, 3, 6, 5, 7, 4, 3,},
+ { 5, 4, 1, 5, 5, 6, 6, 4, 2,},
+ { 6, 4, 2, 2, 6, 3, 6, 6, 2,},
+ { 6, 4, 2, 5, 3, 6, 3, 3, 2,},
+ { 6, 3, 2, 3, 5, 2, 4, 6, 3,},
+ { 6, 2, 2, 4, 3, 5, 3, 6, 3,},
+ { 7, 5, 1, 7, 4, 7, 7, 3, 2,},
+ { 5, 5, 2, 3, 6, 7, 7, 5, 1,},
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0,},
+};
+
+//@}
+
+#endif /* RV40VLC2_H */
3
4
Author: kostya
Date: Fri Jul 6 08:33:44 2007
New Revision: 322
Log:
Remove test code
Modified:
rv40/rv40.c
Modified: rv40/rv40.c
==============================================================================
--- rv40/rv40.c (original)
+++ rv40/rv40.c Fri Jul 6 08:33:44 2007
@@ -436,35 +436,6 @@ static int rv40_decode_init(AVCodecConte
if(!tables_done){
rv40_init_tables();
tables_done = 1;
-
- if(0){
- uint8_t bits[] = {0xD1, 0xB7, 0x37, 0x6A};
- GetBitContext gb;
- int r;
-
- init_get_bits(&gb, bits, sizeof(bits)*8);
- r = rv40_decode_cbp(&gb, &intra_vlcs[2], 0);
- av_log(NULL,0,"CBP=%04X, %d bits\n",r,get_bits_count(&gb));
- }
- if(0){
- uint8_t bits[] = {0x6A,0xBF,0xFF,0x87,0xDA,0xBE,0x74,0x94,0xE0,0x29,0x0A,0xAB,0x30,0x4B,0x35,0x80,0x8D };
- GetBitContext gb;
- DCTELEM block[64];
- int i,j,k;
-
- init_get_bits(&gb, bits, sizeof(bits)*8);
- get_bits1(&gb);
- for(k=0;k<11;k++){
- memset(block,0,64*sizeof(DCTELEM));
- rv40_decode_block(block,&gb,&intra_vlcs[2],k<8,0);
-
- for(j=0;j<4;j++){
- for(i=0;i<4;i++)av_log(NULL,0," %3d",block[i+j*8]);
- av_log(NULL,0,"\n");
- }
- av_log(NULL,0,"Used %d bits\n",get_bits_count(&gb));
- }
- }
}
return 0;
}
1
0
Author: reynaldo
Date: Fri Jul 6 00:18:10 2007
New Revision: 321
Log:
COSMETICS - Doxygenization of some comments
Modified:
qcelp/qcelpdec.c
Modified: qcelp/qcelpdec.c
==============================================================================
--- qcelp/qcelpdec.c (original)
+++ qcelp/qcelpdec.c Fri Jul 6 00:18:10 2007
@@ -38,7 +38,7 @@
typedef struct
{
qcelp_packet_rate rate;
- uint8_t data[76]; /* data from a _parsed_ frame */
+ uint8_t data[76]; /*!< data from a _parsed_ frame */
uint8_t bits;
} QCELPFrame;
@@ -80,12 +80,12 @@ static int qcelp_decode_frame(AVCodecCon
int16_t *outbuffer = data;
int8_t samples;
int n;
- uint16_t first16 = 0; /* needed for rate 1/8 peculiarities */
+ uint16_t first16 = 0; /*!< needed for rate 1/8 peculiarities */
int is_ifq = 0;
init_get_bits(&q->gb, buf, buf_size*8);
- /*
+ /**
* figure out frame's rate by its size, set up a few utility vars
* and point 'order' to the rate's reference _slice_ inside the
* big REFERENCE_FRAME array.
@@ -126,7 +126,7 @@ static int qcelp_decode_frame(AVCodecCon
break;
}
- /*
+ /**
* reordering loop
*/
@@ -144,7 +144,9 @@ static int qcelp_decode_frame(AVCodecCon
/* DONE REORDERING */
- /* check for erasures/blanks on rates 1, 1/4 and 1/8 */
+ /**
+ * check for erasures/blanks on rates 1, 1/4 and 1/8
+ */
if(q->frame->rate != RATE_HALF && !q->frame->data[QCELP_RSRVD_POS])
is_ifq=1;
1
0
05 Jul '07
Author: reynaldo
Date: Thu Jul 5 22:18:38 2007
New Revision: 313
Log:
Should address most of your comments
Modified:
qcelp/doc/NOTES
qcelp/qcelp.h
qcelp/qcelp_glue.diff
qcelp/qcelpdec.c
Modified: qcelp/doc/NOTES
==============================================================================
--- qcelp/doc/NOTES (original)
+++ qcelp/doc/NOTES Thu Jul 5 22:18:38 2007
@@ -1,5 +1,5 @@
-This notes are abstracts from the standard that might
-be usesfull in understanding whats going on.
+These notes are abstracts from the standard that might
+be useful in understanding what's going on.
How stuff works
@@ -13,7 +13,7 @@ The number of bits used to encode the LP
function of the selected rate (1, 1/2, 1/4, 1/8).
-Parameters codes transmited for each rate packet (Page 25)
+Parameter codes transmitted for each rate packet (Page 25)
------------------------------------------------
LSPi | Line Spectral Pair frequency i.
Modified: qcelp/qcelp.h
==============================================================================
--- qcelp/qcelp.h (original)
+++ qcelp/qcelp.h Thu Jul 5 22:18:38 2007
@@ -1,5 +1,5 @@
/*
- * QCELP Decoder
+ * QCELP decoder
* Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
*
* This file is part of FFmpeg.
@@ -21,7 +21,7 @@
/**
* @file qcelp.h
- * QCELP decoder.
+ * QCELP decoder
*/
typedef enum
@@ -30,20 +30,20 @@ typedef enum
RATE_HALF = 1,
RATE_QUARTER= 2,
RATE_OCTAVE = 3,
- I_F_Q, /* insuficient frame quality */
+ I_F_Q, /*!< insufficient frame quality */
BLANK,
RATE_UNKNOWN
-} qcelp_packet_type;
+} qcelp_packet_rate;
-static uint16_t qcelp_bits_per_type[]={266,124,54,20};
+static const uint16_t qcelp_bits_per_rate[]={266,124,54,20};
typedef struct {
- uint8_t index; /* index into the reference frame */
- uint8_t bitpos; /* bit position in the value's byte */
+ uint8_t index; /*!< index into the reference frame */
+ uint8_t bitpos; /*!< bit position in the value's byte */
} QCELPBitmap;
-/*
+/**
* WARNING
*
* YOU WONT SEE ANY mention of a REFERENCE nor an UNIVERSAL frame
@@ -51,18 +51,37 @@ typedef struct {
* reordering needed to unify the decoding process _inside_ this
* code, nothing more.
*
- */
-
-/*
+ *
+ * UNIVERSAL FRAME
+ * ---------------
+ *
+ * Format of QCELPFrame.data
+ *
+ * QCELP_X0_POS
+ * |
+ * CBSIGNs 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
+ * CBGAINs 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
+ * CINDEXs 32 33 34 35 36 37 38 39 40 41 43 43 44 45 46 47
+ * PLAGs 48 49 50 51
+ * PFRACs 52 53 54 55
+ * PGAINs 56 57 58 59
+ * LSPVs 60 61 62 63 64
+ * RSVD 65
+ * LSP 66 67 68 69 70 71 72 73 74 75
+ * CBSEED 76
+ *
+ *
* REFERENCE FRAME
+ * ---------------
*
- * This are the reference frame slices. Each touple will be mapped to a
- * QCELPBitmap showing the location of each bit in the input * with
- * respect to a transmision code in the 'universal frame'.
+ *
+ * What follows are the reference frame slices. Each tuple will be mapped
+ * to a QCELPBitmap showing the location of each bit in the input with respect
+ * to a transmission code in the 'universal frame'.
*
* FIXME
- * it would be really nice if someone reviewed this numbers :)
- *------------------------------------------------------------------*/
+ * it would be really nice if someone reviewed these numbers :)
+ *---------------------------------------------------------------------------*/
#define QCELP_RATE_FULL_BITMAP \
{15,0},{47,0},{47,1},{47,2},{47,3},{47,4},{47,5},{47,6},\
@@ -133,10 +152,9 @@ typedef struct {
{65,3},{65,2},{65,1},{65,0}
-/*
+/**
* Position of the bitmapping data for each pkt type in
* the big REFERENCE FRAME array
- *
*/
#define QCELP_FULLPKT_REFERENCE_POS 0
@@ -144,48 +162,13 @@ typedef struct {
#define QCELP_4THRPKT_REFERENCE_POS 390
#define QCELP_8THRPKT_REFERENCE_POS 444
-/*
- * Reference frame, finally :-)
- *
- */
-
-static QCELPBitmap QCELP_REFERENCE_FRAME[]={QCELP_RATE_FULL_BITMAP,
- QCELP_RATE_HALF_BITMAP,
- QCELP_RATE_4THR_BITMAP,
- QCELP_RATE_8THR_BITMAP};
-
-/*
- * UNIVERSAL FRAME
- *
- *
- * Oce frame is parsed all data gets stored in QCELPFrame.data acording
- * to this structure:
- *
- * QCELP_X0_POS
- * |
- * CBSIGNs 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- * CBGAINs 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- * CINDEXs 32 33 34 35 36 37 38 39 40 41 43 43 44 45 46 47
- * PLAGs 48 49 50 51
- * PFRACs 52 53 54 55
- * PGAINs 56 57 58 59
- * LSPVs 60 61 62 63 64
- * RSVD 65
- * LSP 66 67 68 69 70 71 72 73 74 75
- * CBSEED 76
- *
- *-------------------------------------------------------------------------*/
-
-typedef struct
-{
- qcelp_packet_type type;
- uint8_t data[76]; /* holds all data from a frame (_once_ parsed) */
- uint8_t bits;
-} QCELPFrame;
+static const QCELPBitmap QCELP_REFERENCE_FRAME[]={QCELP_RATE_FULL_BITMAP,
+ QCELP_RATE_HALF_BITMAP,
+ QCELP_RATE_4THR_BITMAP,
+ QCELP_RATE_8THR_BITMAP};
-/*
- * Position of the transmision codes inside the universal frame.
- *
+/**
+ * Position of the transmission codes inside the universal frame.
*/
#define QCELP_CBSIGN0_POS 0
@@ -195,13 +178,16 @@ typedef struct
#define QCELP_PFRAC0_POS 52
#define QCELP_PGAIN0_POS 56
#define QCELP_LSPV0_POS 60
-#define QCELP_RSRVD_POS 65 /* on all but rate 1/2 packets */
-#define QCELP_LSP0_POS 66 /* only in rate 1/8 packets */
-#define QCELP_CBSEED_POS 76 /* only in rate 1/8 packets */
+#define QCELP_RSRVD_POS 65 /*!< on all but rate 1/2 packets */
+#define QCELP_LSP0_POS 66 /*!< only in rate 1/8 packets */
+#define QCELP_CBSEED_POS 76 /*!< only in rate 1/8 packets */
-/* rest its currently unused */
+/* rest is currently unused */
-static float qcelp_fullrate_ccodebook[]=
+static const int qcelp_cumulative_gainloss[]={0,1,2,6};
+static const float qcelp_cumulative_pitchsaturation[]={0.9,0.6,0.3,0.0};
+
+static const float qcelp_fullrate_ccodebook[]=
{
0.10,-0.65,-0.59, 0.12, 1.10, 0.34,-1.34, 1.57,
1.04,-0.84,-0.34,-1.15, 0.23,-1.01, 0.03, 0.45,
@@ -221,7 +207,7 @@ static float qcelp_fullrate_ccodebook[]=
-1.84,-1.97, 0.52,-0.03, 0.78,-1.89, 0.08,-0.65
};
-static float qcelp_halfrate_ccodebook[]=
+static const float qcelp_halfrate_ccodebook[]=
{
0.0, -2.0, 0.0, -1.5, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
Modified: qcelp/qcelp_glue.diff
==============================================================================
--- qcelp/qcelp_glue.diff (original)
+++ qcelp/qcelp_glue.diff Thu Jul 5 22:18:38 2007
@@ -2,38 +2,38 @@ Index: libavcodec/Makefile
===================================================================
--- libavcodec/Makefile (revision 9314)
+++ libavcodec/Makefile (working copy)
-@@ -147,6 +147,7 @@
- OBJS-$(CONFIG_SHORTEN_DECODER) += shorten.o golomb.o
- OBJS-$(CONFIG_SMACKAUD_DECODER) += smacker.o
- OBJS-$(CONFIG_SMACKER_DECODER) += smacker.o
+@@ -128,6 +128,7 @@
+ OBJS-$(CONFIG_PNG_ENCODER) += png.o
+ OBJS-$(CONFIG_PPM_ENCODER) += pnmenc.o pnm.o
+ OBJS-$(CONFIG_PTX_DECODER) += ptx.o
+OBJS-$(CONFIG_QCELP_DECODER) += qcelpdec.o
- OBJS-$(CONFIG_SMC_DECODER) += smc.o
- OBJS-$(CONFIG_SNOW_DECODER) += snow.o
- OBJS-$(CONFIG_SNOW_ENCODER) += snow.o
+ OBJS-$(CONFIG_QDM2_DECODER) += qdm2.o mdct.o fft.o mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o
+ OBJS-$(CONFIG_QDRAW_DECODER) += qdrw.o
+ OBJS-$(CONFIG_QPEG_DECODER) += qpeg.o
Index: libavcodec/allcodecs.c
===================================================================
--- libavcodec/allcodecs.c (revision 9314)
+++ libavcodec/allcodecs.c (working copy)
-@@ -196,6 +196,7 @@
- REGISTER_DECODER(RA_288, ra_288);
- REGISTER_DECODER(SHORTEN, shorten);
- REGISTER_DECODER(SMACKAUD, smackaud);
+@@ -191,6 +191,7 @@
+ REGISTER_DECODER(MP3ADU, mp3adu);
+ REGISTER_DECODER(MP3ON4, mp3on4);
+ REGISTER_DECODER(MPC7, mpc7);
+ REGISTER_DECODER(QCELP, qcelp);
- REGISTER_ENCDEC (SONIC, sonic);
- REGISTER_ENCODER(SONIC_LS, sonic_ls);
- REGISTER_DECODER(TRUESPEECH, truespeech);
+ REGISTER_DECODER(QDM2, qdm2);
+ REGISTER_DECODER(RA_144, ra_144);
+ REGISTER_DECODER(RA_288, ra_288);
Index: libavcodec/allcodecs.h
===================================================================
--- libavcodec/allcodecs.h (revision 9314)
+++ libavcodec/allcodecs.h (working copy)
-@@ -161,6 +161,7 @@
- extern AVCodec shorten_decoder;
- extern AVCodec smackaud_decoder;
- extern AVCodec smacker_decoder;
+@@ -144,6 +144,7 @@
+ extern AVCodec nuv_decoder;
+ extern AVCodec png_decoder;
+ extern AVCodec ptx_decoder;
+extern AVCodec qcelp_decoder;
- extern AVCodec smc_decoder;
- extern AVCodec snow_decoder;
- extern AVCodec sol_dpcm_decoder;
+ extern AVCodec qdm2_decoder;
+ extern AVCodec qdraw_decoder;
+ extern AVCodec qpeg_decoder;
Index: libavformat/mov.c
===================================================================
--- libavformat/mov.c (revision 9314)
Modified: qcelp/qcelpdec.c
==============================================================================
--- qcelp/qcelpdec.c (original)
+++ qcelp/qcelpdec.c Thu Jul 5 22:18:38 2007
@@ -1,5 +1,5 @@
/*
- * QCELP Decoder
+ * QCELP decoder
* Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
*
* This file is part of FFmpeg.
@@ -21,16 +21,12 @@
/**
* @file qcelpdec.c
- * QCELP decoder.
+ * QCELP decoder
*/
-/* First we include some default includes */
#include <math.h>
#include <stddef.h>
-#include <stdio.h>
-/* The following includes have the bitstream reader, various dsp functions and the various defaults */
-#define ALT_BITSTREAM_READER
#include "avcodec.h"
#include "bitstream.h"
#include "dsputil.h"
@@ -39,6 +35,13 @@
#define DEBUG 1
+typedef struct
+{
+ qcelp_packet_rate rate;
+ uint8_t data[76]; /* data from a _parsed_ frame */
+ uint8_t bits;
+} QCELPFrame;
+
typedef struct {
GetBitContext gb;
QCELPFrame *frame;
@@ -68,65 +71,58 @@ static int qcelp_decode_init(AVCodecCont
return 0;
}
-static int qcelp_parse_pkt_full(uint8_t *buf, QCELPFrame *frame)
-{
- return 0;
-}
static int qcelp_decode_frame(AVCodecContext *avctx, void *data,
int *data_size, uint8_t *buf, int buf_size)
{
- QCELPContext *q = avctx->priv_data;
- int16_t *outbuffer = data;
- int8_t samples;
- int8_t bitcount;
- int16_t first16 = 0; /* needed for rate 1/8 particularities */
-
- QCELPBitmap *order;
-
- order = NULL;
+ QCELPContext *q = avctx->priv_data;
+ QCELPBitmap *order = NULL;
+ int16_t *outbuffer = data;
+ int8_t samples;
+ int n;
+ uint16_t first16 = 0; /* needed for rate 1/8 peculiarities */
+ int is_ifq = 0;
init_get_bits(&q->gb, buf, buf_size*8);
/*
- * FIXME this comment should actually make some sence ..
- *
- * Here we try to identify each frame's rate by its byte size,
- * then, after setting a few utility vars we point 'order'
- * to start at the location of the rate's reference _slice_
- * inside the big REFERECE_FRAME array. We then proceed with
- * the bit reordering that will leave a full raw frame's data
- * ordered in our 'universal frame'
+ * figure out frame's rate by its size, set up a few utility vars
+ * and point 'order' to the rate's reference _slice_ inside the
+ * big REFERENCE_FRAME array.
*/
switch(buf_size)
{
case 34:
- q->frame->type = RATE_FULL;
- q->frame->bits = qcelp_bits_per_type[RATE_FULL];
- order = QCELP_REFERENCE_FRAME + QCELP_FULLPKT_REFERENCE_POS;
+ q->frame->rate = RATE_FULL;
+ q->frame->bits = qcelp_bits_per_rate[RATE_FULL];
+ order =
+ (QCELPBitmap*)(QCELP_REFERENCE_FRAME + QCELP_FULLPKT_REFERENCE_POS);
break;
case 16:
- q->frame->type = RATE_HALF;
- q->frame->bits = qcelp_bits_per_type[RATE_HALF];
- order = QCELP_REFERENCE_FRAME + QCELP_HALFPKT_REFERENCE_POS;
+ q->frame->rate = RATE_HALF;
+ q->frame->bits = qcelp_bits_per_rate[RATE_HALF];
+ order =
+ (QCELPBitmap*)(QCELP_REFERENCE_FRAME + QCELP_HALFPKT_REFERENCE_POS);
break;
case 7:
- q->frame->type = RATE_QUARTER;
- q->frame->bits = qcelp_bits_per_type[RATE_QUARTER];
- order = QCELP_REFERENCE_FRAME + QCELP_4THRPKT_REFERENCE_POS;
+ q->frame->rate = RATE_QUARTER;
+ q->frame->bits = qcelp_bits_per_rate[RATE_QUARTER];
+ order =
+ (QCELPBitmap*)(QCELP_REFERENCE_FRAME + QCELP_4THRPKT_REFERENCE_POS);
break;
case 3:
- q->frame->type = RATE_OCTAVE;
- q->frame->bits = qcelp_bits_per_type[RATE_OCTAVE];
- order = QCELP_REFERENCE_FRAME + QCELP_8THRPKT_REFERENCE_POS;
+ q->frame->rate = RATE_OCTAVE;
+ q->frame->bits = qcelp_bits_per_rate[RATE_OCTAVE];
+ order =
+ (QCELPBitmap*)(QCELP_REFERENCE_FRAME + QCELP_8THRPKT_REFERENCE_POS);
break;
case 0: /* FIXME */
- q->frame->type = BLANK;
+ q->frame->rate = BLANK;
q->frame->bits = 0;
break;
default:
- q->frame->type = RATE_UNKNOWN;
+ q->frame->rate = RATE_UNKNOWN;
q->frame->bits = 0;
/*
printf("UNKNOWN PACKET RATE\n");
@@ -138,100 +134,56 @@ static int qcelp_decode_frame(AVCodecCon
* reordering loop
*/
- bitcount=0;
- while(bitcount < q->frame->bits)
+ for(n=0; n < q->frame->bits; n++)
{
- /*
- * order[bitcount]->index holds the placement of this
- * input stream bit in the universal frame.
- *
- * order[bitcount]->pos holds the bit pos inside this value
- * byte.
- *
- */
-
- q->frame->data[ order[bitcount].index ] |=
- get_bits1(&q->gb)>>(order[bitcount].bitpos);
-
- /*
- * viral sample! :D
- *
- * just needed for rate 1/8 packets
- *
- */
+ q->frame->data[ order[n].index ] |=
+ get_bits1(&q->gb)<<order[n].bitpos;
- if(bitcount<16)
+ if(n<16)
{
- first16 |= q->frame->data[ order[bitcount].index ]>>bitcount
+ first16 |= q->frame->data[ order[n].index ]>>n;
}
- bitcount++;
}
/* DONE REORDERING */
- /*
- * check for erasures/blanks on rates 1, 1/4 and 1/8
- *
- */
+ /* check for erasures/blanks on rates 1, 1/4 and 1/8 */
- if(q->frame->type != RATE_HALF)
- {
- if(!q->frame->data[QCELP_RSRVD_POS])
- {
- /*
- * flag aproach: set flag for ifq/blank/incorrect
- * decoding
- */
- }
- }
+ if(q->frame->rate != RATE_HALF && !q->frame->data[QCELP_RSRVD_POS])
+ is_ifq=1;
- /* particularities for rate 1/8 */
- if(q->frame->type == RATE_OCTAVE)
- {
- if(first16==0xFFFF)
- {
- /*
- * flag aproach: set flag for ifq/blank/incorrect
- * decoding
- */
- }
- }
+ if(q->frame->rate == RATE_OCTAVE && first16==0xFFFF)
+ is_ifq=1;
- /*
- * check for badly received packets
- * for rate 1, 1/2 and 1/4
- */
+ /* check for badly received packets */
- if(q->frame->type != RATE_OCTAVE)
+ if(q->frame->rate != RATE_OCTAVE)
{
- /*
- * flag aproach: set flag for ifq/blank/incorrect
- * decoding
- */
+ /* check for outbound LSP freqs and codebook gain params */
+ if(q->frame->rate != RATE_QUARTER)
+ {
+ /* magic here */
+ }
}
-
-
/*
* decode loop
*
*/
-
-
return 1;
}
AVCodec qcelp_decoder =
{
- .name = "qcelp",
- .type = CODEC_TYPE_AUDIO,
- .id = CODEC_ID_QCELP,
- .priv_data_size = sizeof(QCELPContext),
- .init = qcelp_decode_init,
- .close = qcelp_decode_close,
+ .name = "qcelp",
+ .type = CODEC_TYPE_AUDIO,
+ .id = CODEC_ID_QCELP,
+ .init = qcelp_decode_init,
+ .close = qcelp_decode_close,
.decode = qcelp_decode_frame,
+ .priv_data_size = sizeof(QCELPContext),
};
3
6
Author: koorogi
Date: Thu Jul 5 23:39:33 2007
New Revision: 320
Log:
cosmetic: more vertical alignment
Modified:
libavfilter/avfilter.c
Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c (original)
+++ libavfilter/avfilter.c Thu Jul 5 23:39:33 2007
@@ -108,7 +108,7 @@ int avfilter_link(AVFilterContext *src,
/* find a format both filters support - TODO: auto-insert conversion filter */
fmts[0] = src->filter->outputs[srcpad].query_formats(link);
- fmts[1] = dst->filter->inputs[dstpad].query_formats(link);
+ fmts[1] = dst->filter-> inputs[dstpad].query_formats(link);
for(i = 0; fmts[0][i] != -1; i ++)
for(j = 0; fmts[1][j] != -1; j ++)
if(fmts[0][i] == fmts[1][j]) {
@@ -128,7 +128,7 @@ format_done:
}
src->filter->outputs[srcpad].config_props(link);
- dst->filter->inputs[dstpad].config_props(link);
+ dst->filter-> inputs[dstpad].config_props(link);
return 0;
}
1
0
Author: reynaldo
Date: Thu Jul 5 23:39:25 2007
New Revision: 319
Log:
- Dont hide but solve possibly naughty pointer to const
issue spotted by gcc and Michael.
Modified:
qcelp/qcelpdec.c
Modified: qcelp/qcelpdec.c
==============================================================================
--- qcelp/qcelpdec.c (original)
+++ qcelp/qcelpdec.c Thu Jul 5 23:39:25 2007
@@ -76,7 +76,7 @@ static int qcelp_decode_frame(AVCodecCon
int *data_size, uint8_t *buf, int buf_size)
{
QCELPContext *q = avctx->priv_data;
- QCELPBitmap *order = NULL;
+ const QCELPBitmap *order = NULL;
int16_t *outbuffer = data;
int8_t samples;
int n;
@@ -96,26 +96,22 @@ static int qcelp_decode_frame(AVCodecCon
case 34:
q->frame->rate = RATE_FULL;
q->frame->bits = qcelp_bits_per_rate[RATE_FULL];
- order =
- (QCELPBitmap*)(QCELP_REFERENCE_FRAME + QCELP_FULLPKT_REFERENCE_POS);
+ order = QCELP_REFERENCE_FRAME + QCELP_FULLPKT_REFERENCE_POS;
break;
case 16:
q->frame->rate = RATE_HALF;
q->frame->bits = qcelp_bits_per_rate[RATE_HALF];
- order =
- (QCELPBitmap*)(QCELP_REFERENCE_FRAME + QCELP_HALFPKT_REFERENCE_POS);
+ order = QCELP_REFERENCE_FRAME + QCELP_HALFPKT_REFERENCE_POS;
break;
case 7:
q->frame->rate = RATE_QUARTER;
q->frame->bits = qcelp_bits_per_rate[RATE_QUARTER];
- order =
- (QCELPBitmap*)(QCELP_REFERENCE_FRAME + QCELP_4THRPKT_REFERENCE_POS);
+ order = QCELP_REFERENCE_FRAME + QCELP_4THRPKT_REFERENCE_POS;
break;
case 3:
q->frame->rate = RATE_OCTAVE;
q->frame->bits = qcelp_bits_per_rate[RATE_OCTAVE];
- order =
- (QCELPBitmap*)(QCELP_REFERENCE_FRAME + QCELP_8THRPKT_REFERENCE_POS);
+ order = QCELP_REFERENCE_FRAME + QCELP_8THRPKT_REFERENCE_POS;
break;
case 0: /* FIXME */
q->frame->rate = BLANK;
1
0
[soc]: r316 - in libavfilter: avfilter.c avfilter.h filter_test.c vf_crop.c vo_sdl.c vsrc_dummy.c
by koorogi 05 Jul '07
by koorogi 05 Jul '07
05 Jul '07
Author: koorogi
Date: Thu Jul 5 22:48:48 2007
New Revision: 316
Log:
Rework filter initialization sequence. Now supports passing user parameters,
querying supported colorspaces, etc.
Modified:
libavfilter/avfilter.c
libavfilter/avfilter.h
libavfilter/filter_test.c
libavfilter/vf_crop.c
libavfilter/vo_sdl.c
libavfilter/vsrc_dummy.c
Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c (original)
+++ libavfilter/avfilter.c Thu Jul 5 22:48:48 2007
@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -91,6 +92,7 @@ int avfilter_link(AVFilterContext *src,
AVFilterContext *dst, unsigned dstpad)
{
AVFilterLink *link;
+ int *fmts[2], i, j;
if(src->outputs[srcpad] || dst->inputs[dstpad])
return -1;
@@ -104,7 +106,29 @@ int avfilter_link(AVFilterContext *src,
link->dstpad = dstpad;
link->cur_pic = NULL;
- src->filter->outputs[dstpad].set_video_props(link);
+ /* find a format both filters support - TODO: auto-insert conversion filter */
+ fmts[0] = src->filter->outputs[srcpad].query_formats(link);
+ fmts[1] = dst->filter->inputs[dstpad].query_formats(link);
+ for(i = 0; fmts[0][i] != -1; i ++)
+ for(j = 0; fmts[1][j] != -1; j ++)
+ if(fmts[0][i] == fmts[1][j]) {
+ link->format = fmts[0][i];
+ goto format_done;
+ }
+
+format_done:
+ av_free(fmts[0]);
+ av_free(fmts[1]);
+ if(link->format == -1) {
+ /* failed to find a format. fail at creating the link */
+ av_free(link);
+ src->outputs[srcpad] = NULL;
+ dst->inputs[dstpad] = NULL;
+ return -1;
+ }
+
+ src->filter->outputs[srcpad].config_props(link);
+ dst->filter->inputs[dstpad].config_props(link);
return 0;
}
@@ -263,9 +287,21 @@ int avfilter_init_filter(AVFilterContext
if(filter->filter->init)
if((ret = filter->filter->init(filter, args))) return ret;
- for(i = 0; i < pad_count(filter->filter->outputs); i ++)
- if(filter->outputs[i])
- filter->filter->outputs[i].set_video_props(filter->outputs[i]);
return 0;
}
+int *avfilter_make_format_list(int len, ...)
+{
+ int *ret, i;
+ va_list vl;
+
+ ret = av_malloc(sizeof(int) * (len + 1));
+ va_start(vl, len);
+ for(i = 0; i < len; i ++)
+ ret[i] = va_arg(vl, int);
+ va_end(vl);
+ ret[len] = -1;
+
+ return ret;
+}
+
Modified: libavfilter/avfilter.h
==============================================================================
--- libavfilter/avfilter.h (original)
+++ libavfilter/avfilter.h Thu Jul 5 22:48:48 2007
@@ -99,6 +99,13 @@ struct AVFilterPad
#define AV_PAD_VIDEO 0
/**
+ * Callback to get a list of supported formats. The returned list should
+ * be terminated by -1. This is used for both input and output pads and
+ * is required for both.
+ */
+ int *(*query_formats)(AVFilterLink *link);
+
+ /**
* Callback called before passing the first slice of a new frame. If
* NULL, the filter layer will default to storing a reference to the
* picture inside the link structure.
@@ -131,11 +138,15 @@ struct AVFilterPad
void (*request_frame)(AVFilterLink *link);
/**
- * Callback to set properties of the link. Only for video output pads.
- * XXX: this is not acceptable as is. it needs reworked to allow for
- * negotiation of colorspace, etc.
+ * Link configuration callback. For output pads, this should set the link
+ * properties such as width/height. NOTE: this should not set the format
+ * property - that is negotiated between filters by the filter system using
+ * the query_formats() callback.
+ *
+ * For input pads, this should check the properties of the link, and update
+ * the filter's internal state as necessary.
*/
- int (*set_video_props)(AVFilterLink *link);
+ int (*config_props)(AVFilterLink *link);
};
/* the default implementations of start_frame() and end_frame() */
@@ -206,4 +217,6 @@ AVFilterContext *avfilter_create_by_name
int avfilter_init_filter(AVFilterContext *filter, const char *args);
void avfilter_destroy(AVFilterContext *filter);
+int *avfilter_make_format_list(int len, ...);
+
#endif /* FFMPEG_AVFILTER_H */
Modified: libavfilter/filter_test.c
==============================================================================
--- libavfilter/filter_test.c (original)
+++ libavfilter/filter_test.c Thu Jul 5 22:48:48 2007
@@ -36,12 +36,13 @@ int main()
crop = avfilter_create_by_name("crop");
out = avfilter_create_by_name("sdl");
- avfilter_link(src, 0, crop, 0);
- avfilter_link(crop, 0, out, 0);
avfilter_init_filter(src, NULL);
avfilter_init_filter(crop, "20:40:320:240");
avfilter_init_filter(out, NULL);
+ avfilter_link(src, 0, crop, 0);
+ avfilter_link(crop, 0, out, 0);
+
for(i = 0; i < 10; i ++) {
sdl_display(out);
sleep(1);
Modified: libavfilter/vf_crop.c
==============================================================================
--- libavfilter/vf_crop.c (original)
+++ libavfilter/vf_crop.c Thu Jul 5 22:48:48 2007
@@ -27,22 +27,18 @@
typedef struct
{
int x, y, w, h;
+ int cx, cy, cw, ch;
} CropContext;
static int init(AVFilterContext *ctx, const char *args)
{
CropContext *crop = ctx->priv;
- if(ctx->inputs[0]->format != PIX_FMT_RGB24) {
- av_log(ctx, AV_LOG_FATAL, "unsupported input format\n");
- return -1;
- }
-
/* default parameters */
crop->x = 0;
crop->y = 0;
- crop->w = 640;
- crop->h = 480;
+ crop->w = -1;
+ crop->h = -1;
if(args)
sscanf(args, "%d:%d:%d:%d", &crop->x, &crop->y, &crop->w, &crop->h);
@@ -50,13 +46,37 @@ static int init(AVFilterContext *ctx, co
return 0;
}
-static int set_video_props(AVFilterLink *link)
+static int *query_in_formats(AVFilterLink *link)
+{
+ return avfilter_make_format_list(1, PIX_FMT_RGB24);
+}
+
+static int *query_out_formats(AVFilterLink *link)
+{
+ return avfilter_make_format_list(1, link->src->inputs[0]->format);
+}
+
+static int config_input(AVFilterLink *link)
+{
+ CropContext *crop = link->dst->priv;
+
+ crop->cx = FFMIN(crop->x, link->w - 1);
+ crop->cy = FFMIN(crop->y, link->h - 1);
+ crop->cw = FFMIN(crop->w, link->w - crop->cx);
+ crop->ch = FFMIN(crop->h, link->h - crop->cy);
+
+ if(crop->cw <= 0) crop->cw = link->w - crop->cx;
+ if(crop->ch <= 0) crop->ch = link->h - crop->cy;
+
+ return 0;
+}
+
+static int config_output(AVFilterLink *link)
{
CropContext *crop = link->src->priv;
- link->w = crop->w;
- link->h = crop->h;
- link->format = link->src->inputs[0]->format;
+ link->w = crop->cw;
+ link->h = crop->ch;
return 0;
}
@@ -66,10 +86,10 @@ static void start_frame(AVFilterLink *li
CropContext *crop = link->dst->priv;
AVFilterPicRef *ref2 = avfilter_ref_pic(picref);
- ref2->w = crop->w;
- ref2->h = crop->h;
- ref2->data[0] += crop->y * ref2->linesize[0];
- ref2->data[0] += 3 * crop->x;
+ ref2->w = crop->cw;
+ ref2->h = crop->ch;
+ ref2->data[0] += crop->cy * ref2->linesize[0];
+ ref2->data[0] += crop->cx * 3;
av_log(link->dst, AV_LOG_INFO, "start_frame()\n");
avfilter_default_start_frame(link, picref);
@@ -97,20 +117,20 @@ static void draw_slice(AVFilterLink *lin
av_log(link->dst, AV_LOG_INFO, "draw_slice()\n");
- if(y >= crop->y + crop->h || y + h <= crop->y) return;
+ if(y >= crop->cy + crop->ch || y + h <= crop->cy) return;
memcpy(src, data, sizeof(uint8_t *) * 4);
- if(top < crop->y) {
- height -= crop->y - top;
- src[0] += (crop->y - top) * pic->linesize[0];
- top = crop->y;
+ if(top < crop->cy) {
+ height -= crop->cy - top;
+ src[0] += (crop->cy - top) * pic->linesize[0];
+ top = crop->cy;
}
- if(top + height > crop->y + crop->h)
- height = crop->y + crop->h - top;
- src[0] += 3 * crop->x;
+ if(top + height > crop->cy + crop->ch)
+ height = crop->cy + crop->ch - top;
+ src[0] += 3 * crop->cx;
- avfilter_draw_slice(ctx->outputs[0], src, top - crop->y, height);
+ avfilter_draw_slice(ctx->outputs[0], src, top - crop->cy, height);
}
/* XXX: maybe make the default implementation do this? */
@@ -131,12 +151,15 @@ AVFilter vf_crop =
.type = AV_PAD_VIDEO,
.start_frame = start_frame,
.draw_slice = draw_slice,
- .end_frame = end_frame, },
+ .end_frame = end_frame,
+ .query_formats = query_in_formats,
+ .config_props = config_input, },
{ .name = NULL}},
.outputs = (AVFilterPad[]) {{ .name = "default",
.type = AV_PAD_VIDEO,
.request_frame = request_frame,
- .set_video_props = set_video_props},
+ .query_formats = query_out_formats,
+ .config_props = config_output, },
{ .name = NULL}},
};
Modified: libavfilter/vo_sdl.c
==============================================================================
--- libavfilter/vo_sdl.c (original)
+++ libavfilter/vo_sdl.c Thu Jul 5 22:48:48 2007
@@ -34,24 +34,32 @@ static int init(AVFilterContext *ctx, co
{
SDLContext *sdl = ctx->priv;
- if(ctx->inputs[0]->format != PIX_FMT_RGB24) {
- av_log(ctx, AV_LOG_FATAL, "unsupported input format\n");
- return -1;
- }
-
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE)) {
av_log(ctx, AV_LOG_FATAL, "unable to initialize SDL: %s\n",
SDL_GetError());
return -1;
}
- sdl->surface = SDL_SetVideoMode(ctx->inputs[0]->w,
- ctx->inputs[0]->h,
- 24, SDL_HWSURFACE | SDL_DOUBLEBUF);
-
return 0;
}
+static int *query_formats(AVFilterLink *link)
+{
+ return avfilter_make_format_list(1, PIX_FMT_RGB24);
+}
+
+static int config_props(AVFilterLink *link)
+{
+ SDLContext *sdl = link->dst->priv;
+
+ /* SDL docs claim that calling this a second time to resize the
+ * surface will automatically free the old surface for us */
+ sdl->surface = SDL_SetVideoMode(link->w, link->h, 24,
+ SDL_HWSURFACE | SDL_DOUBLEBUF);
+
+ return !sdl->surface;
+}
+
static void uninit(AVFilterContext *ctx)
{
SDL_QuitSubSystem(SDL_INIT_VIDEO);
@@ -117,7 +125,9 @@ AVFilter vo_sdl =
.type = AV_PAD_VIDEO,
.start_frame = start_frame,
.end_frame = end_frame,
- .draw_slice = draw_slice, },
+ .draw_slice = draw_slice,
+ .query_formats = query_formats,
+ .config_props = config_props, },
{ .name = NULL}},
.outputs = (AVFilterPad[]) {{ .name = NULL}},
};
Modified: libavfilter/vsrc_dummy.c
==============================================================================
--- libavfilter/vsrc_dummy.c (original)
+++ libavfilter/vsrc_dummy.c Thu Jul 5 22:48:48 2007
@@ -27,11 +27,15 @@
#define GREEN 0x60
#define BLUE 0xC0
-static int set_video_props(AVFilterLink *link)
+static int *query_formats(AVFilterLink *link)
+{
+ return avfilter_make_format_list(1, PIX_FMT_RGB24);
+}
+
+static int config_props(AVFilterLink *link)
{
link->w = 640;
link->h = 480;
- link->format = PIX_FMT_RGB24;
return 0;
}
@@ -73,7 +77,8 @@ AVFilter vsrc_dummy =
.outputs = (AVFilterPad[]) {{ .name = "default",
.type = AV_PAD_VIDEO,
.request_frame = request_frame,
- .set_video_props = set_video_props, },
+ .query_formats = query_formats,
+ .config_props = config_props, },
{ .name = NULL}},
};
3
3
05 Jul '07
Author: k.nowosad
Date: Mon Jun 25 12:28:41 2007
New Revision: 282
Log:
The basics of encoder. Quantization, dwt 9-7 and some smaller features will be added.
Added:
jpeg2000/checkout.sh (contents, props changed)
jpeg2000/ffmpeg.patch
jpeg2000/j2k.h
jpeg2000/j2kenc.c
Added: jpeg2000/checkout.sh
==============================================================================
--- (empty file)
+++ jpeg2000/checkout.sh Mon Jun 25 12:28:41 2007
@@ -0,0 +1,9 @@
+echo "checking out ffmpeg svn"
+svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk/ ffmpeg
+echo "patching ffmpeg"
+cd ffmpeg/libavcodec ;
+patch -p0 <../../ffmpeg.patch
+echo "copying the jpeg2000 files to ffmpeg/libavcodec"
+ln -s ../../j2kenc.c j2kenc.c
+ln -s ../../j2k.h j2k.h
+echo "Done, now just do a regular configure and make to build."
Added: jpeg2000/ffmpeg.patch
==============================================================================
--- (empty file)
+++ jpeg2000/ffmpeg.patch Mon Jun 25 12:28:41 2007
@@ -0,0 +1,36 @@
+Index: Makefile
+===================================================================
+--- Makefile (wersja 9417)
++++ Makefile (kopia robocza)
+@@ -93,6 +93,7 @@
+ OBJS-$(CONFIG_INDEO3_DECODER) += indeo3.o
+ OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
+ OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER) += dpcm.o
++OBJS-$(CONFIG_JPEG2000_ENCODER) += j2kenc.o
+ OBJS-$(CONFIG_JPEGLS_DECODER) += jpeglsdec.o jpegls.o mjpegdec.o mjpeg.o golomb.o
+ OBJS-$(CONFIG_JPEGLS_ENCODER) += jpeglsenc.o jpegls.o golomb.o
+ OBJS-$(CONFIG_KMVC_DECODER) += kmvc.o
+Index: allcodecs.c
+===================================================================
+--- allcodecs.c (wersja 9417)
++++ allcodecs.c (kopia robocza)
+@@ -92,6 +92,7 @@
+ REGISTER_DECODER(INDEO3, indeo3);
+ REGISTER_DECODER(INTERPLAY_VIDEO, interplay_video);
+ REGISTER_ENCDEC (JPEGLS, jpegls);
++ REGISTER_ENCODER(JPEG2000, jpeg2000);
+ REGISTER_DECODER(KMVC, kmvc);
+ REGISTER_ENCODER(LIBX264, libx264);
+ REGISTER_ENCODER(LIBXVID, libxvid);
+Index: allcodecs.h
+===================================================================
+--- allcodecs.h (wersja 9417)
++++ allcodecs.h (kopia robocza)
+@@ -40,6 +40,7 @@
+ extern AVCodec h264_encoder;
+ extern AVCodec huffyuv_encoder;
+ extern AVCodec jpegls_encoder;
++extern AVCodec jpeg2000_encoder;
+ extern AVCodec ljpeg_encoder;
+ extern AVCodec mdec_encoder;
+ extern AVCodec mjpeg_encoder;
Added: jpeg2000/j2k.h
==============================================================================
--- (empty file)
+++ jpeg2000/j2k.h Mon Jun 25 12:28:41 2007
@@ -0,0 +1,163 @@
+/*
+ * JPEG2000 tables
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * JPEG2000 tables
+ * @file j2k.h
+ * @author Kamil Nowosad
+ */
+
+#ifndef _J2K_H_
+#define _J2K_H_
+
+enum J2kMarkers{
+ J2K_SOC = 0xff4f,
+ J2K_SIZ = 0xff51,
+ J2K_COD,
+ J2K_COC,
+ J2K_TLM = 0xff55,
+ J2K_PLM = 0xff57,
+ J2K_PLT,
+ J2K_QCD = 0xff5c,
+ J2K_QCC,
+ J2K_RGN,
+ J2K_POC,
+ J2K_PPM,
+ J2K_PPT,
+ J2K_CRG,
+ J2K_COM,
+ J2K_SOT = 0xff90,
+ J2K_SOP,
+ J2K_EPH,
+ J2K_SOD,
+ J2K_EOC = 0xffd9,
+};
+
+
+/* arithmetic entropy coder context */
+//TODO: optimize [nice solution in openjpeg]
+typedef struct {
+ unsigned int qe;
+ unsigned int nmps;
+ unsigned int nlps;
+ unsigned int sw;
+} J2kAecState;
+
+const static J2kAecState aec_cx_states[47] = {
+ {0x5601, 1, 1, 1},
+ {0x3401, 2, 6, 0},
+ {0x1801, 3, 9, 0},
+ {0x0AC1, 4, 12, 0},
+ {0x0521, 5, 29, 0},
+ {0x0221, 38, 33, 0},
+ {0x5601, 7, 6, 1},
+ {0x5401, 8, 14, 0},
+ {0x4801, 9, 14, 0},
+ {0x3801, 10, 14, 0},
+ {0x3001, 11, 17, 0},
+ {0x2401, 12, 18, 0},
+ {0x1C01, 13, 20, 0},
+ {0x1601, 29, 21, 0},
+ {0x5601, 15, 14, 1},
+ {0x5401, 16, 14, 0},
+ {0x5101, 17, 15, 0},
+ {0x4801, 18, 16, 0},
+ {0x3801, 19, 17, 0},
+ {0x3401, 20, 18, 0},
+ {0x3001, 21, 19, 0},
+ {0x2801, 22, 19, 0},
+ {0x2401, 23, 20, 0},
+ {0x2201, 24, 21, 0},
+ {0x1C01, 25, 22, 0},
+ {0x1801, 26, 23, 0},
+ {0x1601, 27, 24, 0},
+ {0x1401, 28, 25, 0},
+ {0x1201, 29, 26, 0},
+ {0x1101, 30, 27, 0},
+ {0x0AC1, 31, 28, 0},
+ {0x09C1, 32, 29, 0},
+ {0x08A1, 33, 30, 0},
+ {0x0521, 34, 31, 0},
+ {0x0441, 35, 32, 0},
+ {0x02A1, 36, 33, 0},
+ {0x0221, 37, 34, 0},
+ {0x0141, 38, 35, 0},
+ {0x0111, 39, 36, 0},
+ {0x0085, 40, 37, 0},
+ {0x0049, 41, 38, 0},
+ {0x0025, 42, 39, 0},
+ {0x0015, 43, 40, 0},
+ {0x0009, 44, 41, 0},
+ {0x0005, 45, 42, 0},
+ {0x0001, 45, 43, 0},
+ {0x5601, 46, 46, 0}
+};
+
+typedef struct {
+ unsigned int state;
+ unsigned int mps;
+} J2kAecContext;
+
+typedef struct {
+ uint8_t *bp, *bpstart;
+ unsigned int a;
+ unsigned int c;
+ unsigned int ct;
+ J2kAecContext contexts[19];
+ J2kAecContext *curctx;
+} J2kAec;
+
+#define J2K_MAX_CBLKW 64
+#define J2K_MAX_CBLKH 64
+
+// T1 flags
+// flags determining significance of neighbour coefficients
+#define J2K_T1_SIG_N 0x0001
+#define J2K_T1_SIG_E 0x0002
+#define J2K_T1_SIG_W 0x0004
+#define J2K_T1_SIG_S 0x0008
+#define J2K_T1_SIG_NE 0x0010
+#define J2K_T1_SIG_NW 0x0020
+#define J2K_T1_SIG_SE 0x0040
+#define J2K_T1_SIG_SW 0x0080
+#define J2K_T1_SIG_NB (J2K_T1_SIG_N | J2K_T1_SIG_E | J2K_T1_SIG_S | J2K_T1_SIG_W \
+ |J2K_T1_SIG_NE | J2K_T1_SIG_NW | J2K_T1_SIG_SE | J2K_T1_SIG_SW)
+// flags determining sign bit of neighbour coefficients
+#define J2K_T1_SGN_N 0x0100
+#define J2K_T1_SGN_S 0x0200
+#define J2K_T1_SGN_W 0x0400
+#define J2K_T1_SGN_E 0x0800
+
+#define J2K_T1_VIS 0x1000
+#define J2K_T1_SIG 0x2000
+#define J2K_T1_REF 0x4000
+
+#define J2K_T1_CTX_RL 17
+#define J2K_T1_CTX_UNI 18
+
+typedef struct {
+ int data[J2K_MAX_CBLKW][J2K_MAX_CBLKH];
+ int flags[J2K_MAX_CBLKW+2][J2K_MAX_CBLKH+2];
+ J2kAec aec;
+} J2kT1Context;
+
+#endif
Added: jpeg2000/j2kenc.c
==============================================================================
--- (empty file)
+++ jpeg2000/j2kenc.c Mon Jun 25 12:28:41 2007
@@ -0,0 +1,1266 @@
+/*
+ * JPEG2000 image encoder
+ * Copyright (c) 2007 Kamil Nowosad
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+/**
+ * JPEG2000 image encoder
+ * @file j2kenc.c
+ * @author Kamil Nowosad
+ */
+
+#include "avcodec.h"
+#include "bytestream.h"
+#include "j2k.h"
+#include "common.h"
+
+// TODO: doxygen-compatible comments
+
+typedef struct {
+ int length;
+ int npassess;
+ int zerobits;
+ int zero;
+ uint8_t data[8192];
+} J2kCblk; // code block
+
+typedef struct J2kTgtNode {
+ uint8_t val;
+ uint8_t vis;
+ struct J2kTgtNode *parent;
+} J2kTgtNode;
+
+typedef struct {
+ int xi0, xi1, yi0, yi1; /// indices of codeblocks ([xi0, xi1))
+} J2kPrec; // precinct
+
+typedef struct {
+ int x0, x1, y0, y1;
+ int cblkw, cblkh;
+ int cblknx, cblkny;
+ J2kPrec *prec;
+ J2kCblk *cblk;
+} J2kBand; // subband
+
+typedef struct {
+ int x0, x1, y0, y1;
+ int nbands;
+ int nprecw, nprech;
+ J2kBand *band;
+} J2kResLevel; // resolution level
+
+typedef struct {
+ J2kResLevel *reslevel;
+ int *data;
+ int x0, x1, y0, y1;
+} J2kComponent;
+
+typedef struct { // flatten with context
+ J2kComponent *comp;
+} J2kTile;
+
+typedef struct {
+ AVCodecContext *avctx;
+ AVFrame *picture;
+
+ int Xsiz, Ysiz; // image width and height
+ unsigned int bpp;
+ int ncomponents;
+ int ppx, ppy; // exponent of the precinct size [global]
+ int xcb, ycb; // exponent of the code block size
+ int XTsiz, YTsiz; // tile size
+ int numXtiles, numYtiles;
+
+ int expn;
+ int nguardbits;
+
+// int *samples[3];
+ int nreslevels; // number of resolution levels
+ uint8_t *buf_start;
+ uint8_t *buf;
+ uint8_t *buf_end;
+ int bit_index;
+
+ J2kTile *tile;
+} J2kEncoderContext;
+
+
+/* debug */
+#if 0
+#undef ifprintf
+#undef printf
+
+static void nspaces(FILE *fd, int n)
+{
+ while(n--) putc(' ', fd);
+}
+
+static void printv(int *tab, int l)
+{
+ int i;
+ for (i = 0; i < l; i++)
+ printf("%.3d ", tab[i]);
+ printf("\n");
+}
+
+static void printu(uint8_t *tab, int l)
+{
+ int i;
+ for (i = 0; i < l; i++)
+ printf("%.3hd ", tab[i]);
+ printf("\n");
+}
+
+static void printcomp(J2kComponent *comp)
+{
+ int i;
+ for (i = 0; i < comp->y1 - comp->y0; i++)
+ printv(comp->data + i * (comp->x1 - comp->x0), comp->x1 - comp->x0);
+}
+
+static void dump(J2kEncoderContext *s, FILE *fd)
+{
+ int tileno, compno, reslevelno, bandno, precno;
+ fprintf(fd, "XSiz = %d, YSiz = %d, XTsiz = %d, YTsiz = %d\n"
+ "numXtiles = %d, numYtiles = %d, ncomponents = %d\n"
+ "tiles:\n",
+ s->Xsiz, s->Ysiz, s->XTsiz, s->YTsiz,
+ s->numXtiles, s->numYtiles, s->ncomponents);
+ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
+ J2kTile *tile = s->tile + tileno;
+ nspaces(fd, 2);
+ fprintf(fd, "tile %d:\n", tileno);
+ for(compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = tile->comp + compno;
+ nspaces(fd, 4);
+ fprintf(fd, "component %d:\n", compno);
+ nspaces(fd, 4);
+ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
+ comp->x0, comp->x1, comp->y0, comp->y1);
+ for(reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
+ J2kResLevel *reslevel = comp->reslevel + reslevelno;
+ nspaces(fd, 6);
+ fprintf(fd, "reslevel %d:\n", reslevelno);
+ nspaces(fd, 6);
+ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n",
+ reslevel->x0, reslevel->x1, reslevel->y0,
+ reslevel->y1, reslevel->nbands);
+ for(bandno = 0; bandno < reslevel->nbands; bandno++){
+ J2kBand *band = reslevel->band + bandno;
+ nspaces(fd, 8);
+ fprintf(fd, "band %d:\n", bandno);
+ nspaces(fd, 8);
+ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d,"
+ "cblkw = %d, cblkh = %d cblknx = %d cblkny = %d\n",
+ band->x0, band->x1,
+ band->y0, band->y1,
+ band->cblkw, band->cblkh,
+ band->cblknx, band->cblkny);
+ for (precno = 0; precno < reslevel->nprecw * reslevel->nprech; precno++){
+ J2kPrec *prec = band->prec + precno;
+ nspaces(fd, 10);
+ fprintf(fd, "prec %d:\n", precno);
+ nspaces(fd, 10);
+ fprintf(fd, "xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
+ prec->xi0, prec->xi1, prec->yi0, prec->yi1);
+ }
+ }
+ }
+ }
+ }
+}
+#endif
+
+/* misc tools */
+static int ceildivpow2(int a, int b)
+{
+ return (a + (1 << b) - 1)>> b;
+}
+
+static int ceildiv(int a, int b)
+{
+ return (a + b - 1) / b;
+}
+
+/* bitstream routines */
+
+/* put n times val bit */
+static void put_bits(J2kEncoderContext *s, int val, int n) // TODO: optimize
+{
+ while (n-- > 0){
+ if (s->bit_index == 8)
+ {
+ s->bit_index = *s->buf == 0xff ? 1:0;
+ *(++s->buf) = 0;
+ }
+ *s->buf |= val << (7 - s->bit_index++);
+ }
+}
+
+/* put n least significant bits of a number num */
+static void put_num(J2kEncoderContext *s, int num, int n)
+{
+ while(--n >= 0)
+ put_bits(s, (num & (1<<n)) ? 1:0, 1);
+}
+
+/* flush the bitstream */
+static void j2k_flush(J2kEncoderContext *s)
+{
+ if (s->bit_index){
+ s->bit_index = 0;
+ s->buf++;
+ }
+}
+
+/* tag tree routines */
+
+/* allocate the memory for tag tree */
+//TODO: optimize (too many mallocs)
+static J2kTgtNode *tag_tree_alloc(int w, int h)
+{
+ int i;
+ J2kTgtNode *t = av_malloc(w*h*sizeof(J2kTgtNode));
+ if (t == NULL)
+ return NULL;
+ for (i = 0; i < w*h; i++){
+ t[i].val = 0xff;
+ t[i].vis = 0;
+ }
+ return t;
+}
+
+static J2kTgtNode *tag_tree_init(int w, int h)
+{
+ J2kTgtNode *res = tag_tree_alloc(w, h),
+ *t = res;
+
+ if (res == NULL)
+ return NULL;
+
+ while (w > 1 || h > 1){
+ int pw = w, ph = h;
+ int i, j;
+ J2kTgtNode *t2;
+
+ w = (w+1) >> 1;
+ h = (h+1) >> 1;
+ t2 = tag_tree_alloc(w, h);
+ if (t2 == NULL)
+ return NULL;
+
+ for (i = 0; i < ph; i++)
+ for (j = 0; j < pw; j++){
+ t[i*pw + j].parent = &t2[(i>>1)*w + (j>>1)];
+ }
+ t = t2;
+ }
+ t[0].parent = NULL;
+ return res;
+}
+
+/* code the value stored in node */
+static void tag_tree_code(J2kEncoderContext *s, J2kTgtNode *node)
+{
+ J2kTgtNode *stack[30];
+ int sp = 1, curval = 0;
+ stack[0] = node;
+
+ node = node->parent;
+ while(node != NULL){
+ if (node->vis){
+ curval = node->val;
+ break;
+ }
+ node->vis++;
+ stack[sp++] = node;
+ node = node->parent;
+ }
+ while(--sp >= 0){
+ put_bits(s, 0, stack[sp]->val - curval);
+ put_bits(s, 1, 1);
+ curval = stack[sp]->val;
+ }
+}
+
+/* update the value in node */
+static void tag_tree_update(J2kTgtNode *node)
+{
+ int lev = 0;
+ while (node->parent != NULL){
+ if (node->parent->val <= node->val)
+ break;
+ node->parent->val = node->val;
+ node = node->parent;
+ lev++;
+ }
+}
+
+static void tag_tree_destroy(J2kTgtNode *tree)
+{
+ while (tree != NULL){
+ J2kTgtNode *parent = tree[0].parent;
+ av_free(tree);
+ tree = parent;
+ }
+}
+
+/* marker segments */
+static void put_marker(J2kEncoderContext *s, uint16_t marker)
+{
+ bytestream_put_be16(&s->buf, marker);
+}
+
+static void put_soc(J2kEncoderContext *s)
+{
+ put_marker(s, J2K_SOC);
+}
+
+static void put_siz(J2kEncoderContext *s)
+{
+ int i;
+
+ put_marker(s, J2K_SIZ);
+ bytestream_put_be16(&s->buf, 38 + 3 * s->ncomponents); // Lsiz
+ bytestream_put_be16(&s->buf, 0); // Rsiz
+ bytestream_put_be32(&s->buf, s->Xsiz); // Xsiz
+ bytestream_put_be32(&s->buf, s->Ysiz); // Ysiz
+ bytestream_put_be32(&s->buf, 0); // X0Siz
+ bytestream_put_be32(&s->buf, 0); // Y0Siz
+
+ bytestream_put_be32(&s->buf, s->XTsiz); // XTSiz
+ bytestream_put_be32(&s->buf, s->YTsiz); // YTSiz
+ bytestream_put_be32(&s->buf, 0); // XT0Siz
+ bytestream_put_be32(&s->buf, 0); // YT0Siz
+ bytestream_put_be16(&s->buf, s->ncomponents); // CSiz
+
+ for (i = 0; i < 3; i++){ // Ssiz_i XRsiz_i, YRsiz_i
+ bytestream_put_byte(&s->buf, 7);
+ bytestream_put_byte(&s->buf, 1);
+ bytestream_put_byte(&s->buf, 1);
+ }
+}
+
+static void put_cod(J2kEncoderContext *s)
+{
+ put_marker(s, J2K_COD);
+ bytestream_put_be16(&s->buf, 12); // Lcod
+ bytestream_put_byte(&s->buf, 0); // Scod
+ // SGcod
+ bytestream_put_byte(&s->buf, 0); // progression level
+ bytestream_put_be16(&s->buf, 1); // num of layers
+ bytestream_put_byte(&s->buf, 0); // multiple component transformation
+ // SPcod
+ bytestream_put_byte(&s->buf, s->nreslevels - 1); // num of decomp. levels
+ bytestream_put_byte(&s->buf, s->xcb-2); // cblk width
+ bytestream_put_byte(&s->buf, s->ycb-2); // cblk height
+ bytestream_put_byte(&s->buf, 0); // cblk style
+ bytestream_put_byte(&s->buf, 1); // transformation
+}
+
+static void put_qcd(J2kEncoderContext *s)
+{
+ int reslevelno;
+ put_marker(s, J2K_QCD);
+ bytestream_put_be16(&s->buf, 4+3*(s->nreslevels-1)); // LQcd
+ bytestream_put_byte(&s->buf, s->nguardbits << 5); // Sqcd
+ for (reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
+ int bandno, nbands = reslevelno == 0 ? 1:3;
+ for (bandno = 0; bandno < nbands; bandno++)
+ bytestream_put_byte(&s->buf, s->expn << 3);
+ }
+}
+
+static uint8_t *put_sot(J2kEncoderContext *s, int tileno)
+{
+ uint8_t *psotptr;
+ put_marker(s, J2K_SOT);
+ bytestream_put_be16(&s->buf, 10); // Lsot
+ bytestream_put_be16(&s->buf, tileno); // Isot
+
+ psotptr = s->buf;
+ bytestream_put_be32(&s->buf, 0); // Psot (filled in later)
+
+ bytestream_put_byte(&s->buf, 0); // TPsot
+ bytestream_put_byte(&s->buf, 1); // TNsot
+ return psotptr;
+}
+
+/* compute the sizes of tiles, resolution levels, bands, etc.
+ * allocate memory for them
+ * divide the input image into tile-components
+ */
+static int init_tiles(J2kEncoderContext *s)
+{
+ // only one tile
+ // only rgb24 supported now
+ int y, x, tno, i;
+
+ s->numXtiles = ceildiv(s->Xsiz, s->XTsiz);
+ s->numYtiles = ceildiv(s->Ysiz, s->YTsiz);
+
+ s->tile = av_malloc(s->numXtiles * s->numYtiles * sizeof(J2kTile));
+ if (s->tile == NULL)
+ return -1;
+ for (tno = 0; tno < s->numXtiles * s->numYtiles; tno++){
+ J2kTile *tile = s->tile + tno;
+ int p = tno % s->numXtiles;
+ int q = tno / s->numXtiles;
+ int compno;
+
+ tile->comp = av_malloc(s->ncomponents * sizeof(J2kComponent));
+ if (tile->comp == NULL)
+ return -1;
+ for (compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = tile->comp + compno;
+ int reslevelno;
+
+ comp->x0 = p * s->XTsiz;
+ comp->x1 = FFMIN((p+1)*s->XTsiz, s->Xsiz);
+ comp->y0 = q * s->YTsiz;
+ comp->y1 = FFMIN((q+1)*s->YTsiz, s->Ysiz);
+
+ comp->data = av_malloc((comp->y1 - comp->y0) * (comp->x1 -comp->x0) * sizeof(int));
+ if (comp->data == NULL)
+ return -1;
+ comp->reslevel = av_malloc(s->nreslevels * sizeof(J2kResLevel));
+ if (comp->reslevel == NULL)
+ return -1;
+ for (reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
+ int bandno;
+ int n = s->nreslevels - reslevelno;
+ J2kResLevel *reslevel = comp->reslevel + reslevelno;
+
+ reslevel->x0 = ceildivpow2(comp->x0, s->nreslevels - reslevelno - 1);
+ reslevel->x1 = ceildivpow2(comp->x1, s->nreslevels - reslevelno - 1);
+ reslevel->y0 = ceildivpow2(comp->y0, s->nreslevels - reslevelno - 1);
+ reslevel->y1 = ceildivpow2(comp->y1, s->nreslevels - reslevelno - 1);
+
+ if (reslevelno == 0)
+ reslevel->nbands = 1;
+ else
+ reslevel->nbands = 3;
+
+ if (reslevel->x1 == reslevel->x0)
+ reslevel->nprecw = 0;
+ else
+ reslevel->nprecw = ceildivpow2(reslevel->x1, s->ppx) - reslevel->x0 / (1<<s->ppx);
+
+ if (reslevel->y1 == reslevel->y0)
+ reslevel->nprech = 0;
+ else
+ reslevel->nprech = ceildivpow2(reslevel->y1, s->ppy) - reslevel->y0 / (1<<s->ppy);
+
+ reslevel->band = av_malloc(reslevel->nbands * sizeof(J2kBand));
+ if (reslevel->band == NULL)
+ return -1;
+ for (bandno = 0; bandno < reslevel->nbands; bandno++){
+ J2kBand *band = reslevel->band + bandno;
+ int cblkno, precx, precy, precno;
+ int x0, y0, x1, y1;
+ int xi0, yi0, xi1, yi1;
+ int cblkperprecw, cblkperprech;
+
+ if (reslevelno == 0){ // the same everywhere
+ band->cblkw = 1 << FFMIN(s->xcb, s->ppx-1);
+ band->cblkh = 1 << FFMIN(s->ycb, s->ppy-1);
+
+ band->x0 = ceildivpow2(comp->x0, n-1);
+ band->x1 = ceildivpow2(comp->x1, n-1);
+ band->y0 = ceildivpow2(comp->y0, n-1);
+ band->y1 = ceildivpow2(comp->y1, n-1);
+ }
+ else{
+ band->cblkw = 1 << FFMIN(s->xcb, s->ppx);
+ band->cblkh = 1 << FFMIN(s->ycb, s->ppy);
+
+ band->x0 = ceildivpow2(comp->x0 - (1 << (n-1)) * ((bandno+1)&1), n);
+ band->x1 = ceildivpow2(comp->x1 - (1 << (n-1)) * ((bandno+1)&1), n);
+ band->y0 = ceildivpow2(comp->y0 - (1 << (n-1)) * (((bandno+1)&2)>>1), n);
+ band->y1 = ceildivpow2(comp->y1 - (1 << (n-1)) * (((bandno+1)&2)>>1), n);
+ }
+
+ band->cblknx = ceildiv(band->x1 - band->x0, band->cblkw);
+ band->cblkny = ceildiv(band->y1 - band->y0, band->cblkh);
+
+ band->cblk = av_malloc(band->cblknx * band->cblkny * sizeof(J2kCblk));
+ if (band->cblk == NULL)
+ return -1;
+ band->prec = av_malloc(reslevel->nprecw * reslevel->nprech * sizeof(J2kPrec));
+ if (band->prec == NULL)
+ return -1;
+
+ for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){
+ band->cblk[cblkno].zero = 0;
+ }
+
+ y0 = band->y0;
+ y1 = (band->y0 + (1<<s->ppy))/(1<<s->ppy)*(1<<s->ppy) - band->y0;
+ yi0 = 0;
+ yi1 = ceildiv(y1 - y0, 1<<s->ycb) * (1<<s->ycb);
+ yi1 = FFMIN(yi1, band->cblkny);
+ cblkperprech = 1<<(s->ppy - s->ycb);
+ for (precy = 0, precno = 0; precy < reslevel->nprech; precy++){
+ for (precx = 0; precx < reslevel->nprecw; precx++, precno++){
+ band->prec[precno].yi0 = yi0;
+ band->prec[precno].yi1 = yi1;
+ }
+ yi1 += cblkperprech;
+ yi0 = yi1 - cblkperprech;
+ yi1 = FFMIN(yi1, band->cblkny);
+ }
+ x0 = band->x0;
+ x1 = (band->x0 + (1<<s->ppx))/(1<<s->ppx)*(1<<s->ppx) - band->x0;
+ xi0 = 0;
+ xi1 = ceildiv(x1 - x0, 1<<s->xcb) * (1<<s->xcb);
+ xi1 = FFMIN(xi1, band->cblknx);
+ cblkperprecw = 1<<(s->ppx - s->xcb);
+ for (precx = 0, precno = 0; precx < reslevel->nprecw; precx++){
+ for (precy = 0; precy < reslevel->nprech; precy++, precno = 0){
+ band->prec[precno].xi0 = xi0;
+ band->prec[precno].xi1 = xi1;
+ }
+ xi1 += cblkperprecw;
+ xi0 = xi1 - cblkperprecw;
+ xi1 = FFMIN(xi1, band->cblknx);
+ }
+ }
+ }
+ }
+ }
+ for (tno = 0; tno < s->numXtiles * s->numYtiles; tno++){
+ J2kTile *tile = s->tile + tno;
+ uint8_t *line = s->picture->data[0] + tile->comp[0].y0 * s->picture->linesize[0] + tile->comp[0].x0 * s->ncomponents;
+
+ i = 0;
+ for (y = tile->comp[0].y0; y < tile->comp[0].y1; y++){
+ uint8_t *ptr = line;
+ for (x = tile->comp[0].x0; x < tile->comp[0].x1; x++, i++){
+ int compno;
+ for (compno = 0; compno < s->ncomponents; compno++){
+ tile->comp[compno].data[i] = *ptr++ - (1 << 7);
+ }
+ }
+ line += s->picture->linesize[0];
+ }
+ }
+ return 0;
+}
+
+/* discrete wavelet transform routines */
+static void sd_1d(int *p, int i0, int i1, int ileft, int iright)
+{
+#define PSE (i0 + FFMIN((i-i0+2*(i1-i0-1))%(2*(i1-i0-1)), 2*(i1-i0-1)-(i-i0+2*(i1-i0-1))%(2*(i1-i0-1))))
+ int i;
+
+ for (i = i0 - ileft; i < i0; i++){
+ p[i] = p[PSE];
+ }
+ for (i = i1; i < i1+iright; i++){
+ p[i] = p[PSE];
+ }
+
+ for (i = (i0+1)/2 - 1; i < (i1+1)/2; i++){
+ p[2*i+1] -= (p[2*i] + p[2*i+2]) >> 1;
+ }
+ for (i = (i0+1)/2; i < (i1+1)/2; i++){
+ p[2*i] += (p[2*i-1] + p[2*i+1] + 2) >> 2;
+ }
+#undef PSE
+}
+
+static void dwt_encode53(J2kEncoderContext *s, J2kComponent *comp)
+{
+ int lev = s->nreslevels,
+ *t = comp->data, w = comp->x1 - comp->x0;
+ int *ppv = av_malloc((comp->reslevel[lev-1].y1 + 4)*sizeof(int)), *pv = ppv+2;
+ int *ppu = av_malloc((comp->reslevel[lev-1].x1 + 4)*sizeof(int)), *pu = ppu+2;
+
+ while (--lev){
+ int u0 = comp->reslevel[lev].x0,
+ u1 = comp->reslevel[lev].x1,
+ v0 = comp->reslevel[lev].y0,
+ v1 = comp->reslevel[lev].y1,
+ u = u0, v = v0;
+ const static int tileft[2] = {2, 1}, tiright[2] = {1, 2};
+
+ //VER_SD
+ while (u < u1){
+ int i, j;
+ for (i = v0; i < v1; i++)
+ pv[i] = t[w*(i-v0) + u-u0];
+ sd_1d(pv, v0, v1, tileft[v0&1], tiright[v1&1]);
+
+ // copy back and deinterleave
+ for (i = (v0+1)/2, j = 0; i < (v1+1)/2; i++, j++){
+ t[w*j + u-u0] = pv[2*i];
+ }
+ for (i = v0/2; i < v1/2; i++, j++){
+ t[w*j + u-u0] = pv[2*i+1];
+ }
+ u++;
+ }
+
+ //HOR_SD
+ while (v < v1){
+ int i, j;
+ for (i = u0; i < u1; i++)
+ pu[i] = t[w*(v-v0) + i-u0];
+ sd_1d(pu, u0, u1, tileft[u0&1], tiright[u1&1]);
+
+ // copy back and deinterleave
+ for (i = (u0+1)/2, j = 0; i < (u1+1)/2; i++, j++){
+ t[w*(v-v0) + j] = pu[2*i];
+ }
+ for (i = u0/2; i < u1/2; i++, j++){
+ t[w*(v-v0) + j] = pu[2*i + 1];
+ }
+ v++;
+ }
+ }
+ av_free(ppv);
+ av_free(ppu);
+}
+
+/* arithmetic entropy coder routines: */
+static void aec_initenc(J2kAec *aec, uint8_t *bp)
+{
+ bzero(aec->contexts, 19*sizeof(J2kAecContext));
+ aec->contexts[J2K_T1_CTX_UNI].state = 46;
+ aec->contexts[J2K_T1_CTX_RL].state = 3;
+ aec->contexts[0].state = 4;
+ aec->curctx = aec->contexts;
+
+ aec->a = 0x8000;
+ aec->c = 0;
+ aec->bp = bp-1;
+ aec->bpstart = bp;
+ if (*aec->bp == 0xff)
+ aec->ct = 13;
+ else
+ aec->ct = 12;
+}
+
+static void aec_byteout_l(J2kAec *aec)
+{
+ aec->bp++;
+ *aec->bp = aec->c >> 19;
+ aec->c &= 0x7ffff;
+ aec->ct = 8;
+}
+
+static void aec_byteout_r(J2kAec *aec)
+{
+ aec->bp++;
+ *aec->bp = aec->c >> 20;
+ aec->c &= 0xfffff;
+ aec->ct = 7;
+}
+
+static void aec_byteout(J2kAec *aec)
+{
+ if (*aec->bp == 0xff){
+ aec_byteout_r(aec);
+ }
+ else
+ {
+ if ((aec->c & 0x8000000) == 0){
+ aec_byteout_l(aec);
+ }
+ else{
+ (*aec->bp)++;
+ if (*aec->bp == 0xff){
+ aec->c &= 0x7ffffff;
+ aec_byteout_r(aec);
+ }
+ else{
+ aec_byteout_l(aec);
+ }
+ }
+ }
+}
+
+static void aec_renorme(J2kAec *aec)
+{
+ do{
+ aec->a = aec->a << 1;
+ aec->c = aec->c << 1;
+ aec->ct--;
+ if (!aec->ct)
+ aec_byteout(aec);
+ }
+ while ((aec->a & 0x8000) == 0);
+}
+
+static void aec_codelps(J2kAec *aec)
+{
+ int qe = aec_cx_states[aec->curctx->state].qe;
+ aec->a -= qe;
+ if (aec->a < qe)
+ aec->c += qe;
+ else
+ aec->a = qe;
+ if (aec_cx_states[aec->curctx->state].sw)
+ aec->curctx->mps = 1 - aec->curctx->mps;
+ aec->curctx->state = aec_cx_states[aec->curctx->state].nlps;
+ aec_renorme(aec);
+}
+
+static void aec_codemps(J2kAec *aec)
+{
+ int qe = aec_cx_states[aec->curctx->state].qe;
+ aec->a -= qe;
+ if ((aec->a & 0x8000) == 0){
+ if (aec->a < qe)
+ aec->a = qe;
+ else
+ aec->c += qe;
+ aec->curctx->state = aec_cx_states[aec->curctx->state].nmps;
+ aec_renorme(aec);
+ }
+ else
+ aec->c += qe;
+}
+
+/* code bit d with context cx */
+static void aec_encode(J2kAec *aec, int cx, int d)
+{
+ aec->curctx = aec->contexts + cx;
+ if (aec->curctx->mps == d){
+ aec_codemps(aec);
+ }
+ else{
+ aec_codelps(aec);
+ }
+}
+
+static void aec_setbits(J2kAec *aec)
+{
+ int tmp = aec->c + aec->a;
+ aec->c |= 0xffff;
+ if (aec->c >= tmp)
+ aec->c -= 0x8000;
+}
+
+/* flush the encoder [returns number of bytes encoded] */
+static int aec_flush(J2kAec *aec)
+{
+ aec_setbits(aec);
+ aec->c = aec->c << aec->ct;
+ aec_byteout(aec);
+ aec->c = aec->c << aec->ct;
+ aec_byteout(aec);
+ if (*aec->bp != 0xff)
+ aec->bp++;
+ return aec->bp - aec->bpstart;
+}
+
+/* tier-1 routines */
+static int getnbctxno(int flag, int bandno)
+{
+ int h, v, d;
+
+ h = ((flag & J2K_T1_SIG_E) ? 1:0)+
+ ((flag & J2K_T1_SIG_W) ? 1:0);
+ v = ((flag & J2K_T1_SIG_N) ? 1:0)+
+ ((flag & J2K_T1_SIG_S) ? 1:0);
+ d = ((flag & J2K_T1_SIG_NE) ? 1:0)+
+ ((flag & J2K_T1_SIG_NW) ? 1:0)+
+ ((flag & J2K_T1_SIG_SE) ? 1:0)+
+ ((flag & J2K_T1_SIG_SW) ? 1:0);
+ switch(bandno){
+ case 0: // LL || LH
+ case 2:
+ if (h == 2) return 8;
+ if (h == 1){
+ if (v >= 1) return 7;
+ if (d >= 1) return 6;
+ return 5;
+ }
+ if (v == 2) return 4;
+ if (v == 1) return 3;
+ if (d >= 2) return 2;
+ if (d == 1) return 1;
+ return 0;
+ case 1: // HL
+ if (v == 2) return 8;
+ if (v == 1){
+ if (h >= 1) return 7;
+ if (d >= 1) return 6;
+ return 5;
+ }
+ if (h == 2) return 4;
+ if (h == 1) return 3;
+ if (d >= 2) return 2;
+ if (d >= 1) return 1;
+ return 0;
+ case 3:
+ if (d >= 3) return 8;
+ if (d == 2){
+ if (h+v >= 1) return 7;
+ return 6;
+ }
+ if (d == 1){
+ if (h+v >= 2) return 5;
+ if (h+v == 1) return 4;
+ return 3;
+ }
+ if (h+v >= 2) return 2;
+ if (h+v == 1) return 1;
+ return 0;
+ }
+ assert(0);
+}
+
+static int getrefctxno(int flag)
+{
+ if (!(flag & J2K_T1_REF)){
+ if (flag & J2K_T1_SIG_NB)
+ return 15;
+ return 14;
+ }
+ return 16;
+}
+
+static int getsgnctxno(int flag, int *xorbit)
+{
+ int vcontrib, hcontrib;
+ const int contribtab[3][3] = {{0, -1, 1}, {-1, -1, 0}, {1, 0, 1}};
+ const int ctxlbltab[3][3] = {{13, 12, 11}, {10, 9, 10}, {11, 12, 13}};
+ const int xorbittab[3][3] = {{1, 1, 1,}, {1, 0, 0}, {0, 0, 0}};
+
+ hcontrib = contribtab[flag & J2K_T1_SIG_E ? flag & J2K_T1_SGN_E ? 1:2:0]
+ [flag & J2K_T1_SIG_W ? flag & J2K_T1_SGN_W ? 1:2:0]+1;
+ vcontrib = contribtab[flag & J2K_T1_SIG_S ? flag & J2K_T1_SGN_S ? 1:2:0]
+ [flag & J2K_T1_SIG_N ? flag & J2K_T1_SGN_N ? 1:2:0]+1;
+ *xorbit = xorbittab[hcontrib][vcontrib];
+ return ctxlbltab[hcontrib][vcontrib];
+}
+
+static void set_significant(J2kT1Context *t1, int x, int y)
+{
+ x++; y++;
+ t1->flags[y][x] |= J2K_T1_SIG;
+ if (t1->data[y-1][x-1] < 0){
+ t1->flags[y][x+1] |= J2K_T1_SIG_W | J2K_T1_SGN_W;
+ t1->flags[y][x-1] |= J2K_T1_SIG_E | J2K_T1_SGN_E;
+ t1->flags[y+1][x] |= J2K_T1_SIG_N | J2K_T1_SGN_N;
+ t1->flags[y-1][x] |= J2K_T1_SIG_S | J2K_T1_SGN_S;
+ }
+ else{
+ t1->flags[y][x+1] |= J2K_T1_SIG_W;
+ t1->flags[y][x-1] |= J2K_T1_SIG_E;
+ t1->flags[y+1][x] |= J2K_T1_SIG_N;
+ t1->flags[y-1][x] |= J2K_T1_SIG_S;
+ }
+ t1->flags[y+1][x+1] |= J2K_T1_SIG_NW;
+ t1->flags[y+1][x-1] |= J2K_T1_SIG_NE;
+ t1->flags[y-1][x+1] |= J2K_T1_SIG_SW;
+ t1->flags[y-1][x-1] |= J2K_T1_SIG_SE;
+}
+
+
+static void encode_sigpass(J2kT1Context *t1, int width, int height, int mask, int bandno)
+{
+ int i, j, k;
+ for (i = 0; i < height; i += 4)
+ for (j = 0; j < width; j++)
+ for (k = i; k < height && k < i+4; k++){
+ if (!(t1->flags[k+1][j+1] & J2K_T1_SIG) && (t1->flags[k+1][j+1] & J2K_T1_SIG_NB)){
+ int ctxno = getnbctxno(t1->flags[k+1][j+1], bandno),
+ bit = abs(t1->data[k][j]) & mask ? 1 : 0;
+ aec_encode(&t1->aec, ctxno, bit);
+ if (bit){
+ int xorbit;
+ int ctxno = getsgnctxno(t1->flags[k+1][j+1], &xorbit);
+ aec_encode(&t1->aec, ctxno, (t1->data[k][j] < 0 ? 1:0) ^ xorbit);
+ set_significant(t1, j, k);
+ }
+ t1->flags[k+1][j+1] |= J2K_T1_VIS;
+ }
+ }
+}
+
+static void encode_refpass(J2kT1Context *t1, int width, int height, int mask)
+{
+ int i, j, k;
+ for (i = 0; i < height; i += 4)
+ for (j = 0; j < width; j++)
+ for (k = i; k < height && k < i+4; k++)
+ if ((t1->flags[k+1][j+1] & (J2K_T1_SIG | J2K_T1_VIS)) == J2K_T1_SIG){
+ int ctxno = getrefctxno(t1->flags[k+1][j+1]);
+ aec_encode(&t1->aec, ctxno, abs(t1->data[k][j]) & mask ? 1:0);
+ t1->flags[k+1][j+1] |= J2K_T1_REF;
+ }
+}
+
+static void encode_clnpass(J2kT1Context *t1, int width, int height, int mask, int bandno)
+{
+ int i, j, k;
+ for (i = 0; i < height; i += 4)
+ for (j = 0; j < width; j++){
+ if (i + 3 < height && !(
+ (t1->flags[i+1][j+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
+ (t1->flags[i+2][j+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
+ (t1->flags[i+3][j+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
+ (t1->flags[i+4][j+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG))))
+ {
+ // aggregation mode
+ int rlen;
+ for (rlen = 0; rlen < 4; rlen++)
+ if (abs(t1->data[i+rlen][j]) & mask)
+ break;
+ aec_encode(&t1->aec, J2K_T1_CTX_RL, rlen != 4);
+ if (rlen == 4)
+ continue;
+ aec_encode(&t1->aec, J2K_T1_CTX_UNI, rlen >> 1);
+ aec_encode(&t1->aec, J2K_T1_CTX_UNI, rlen & 1);
+ for (k = i + rlen; k < i + 4; k++){
+ if (!(t1->flags[k+1][j+1] & (J2K_T1_SIG | J2K_T1_VIS))){
+ int ctxno = getnbctxno(t1->flags[k+1][j+1], bandno);
+ if (k > i + rlen)
+ aec_encode(&t1->aec, ctxno, abs(t1->data[k][j]) & mask ? 1:0);
+ if (abs(t1->data[k][j]) & mask){ // newly significant
+ int xorbit;
+ int ctxno = getsgnctxno(t1->flags[k+1][j+1], &xorbit);
+ aec_encode(&t1->aec, ctxno, (t1->data[k][j] < 0 ? 1:0) ^ xorbit);
+ set_significant(t1, j, k);
+ }
+ }
+ t1->flags[k+1][j+1] &= ~J2K_T1_VIS;
+ }
+ }
+ else{
+ for (k = i; k < i + 4 && k < height; k++){
+ if (!(t1->flags[k+1][j+1] & (J2K_T1_SIG | J2K_T1_VIS))){
+ int ctxno = getnbctxno(t1->flags[k+1][j+1], bandno);
+ aec_encode(&t1->aec, ctxno, abs(t1->data[k][j]) & mask ? 1:0);
+ if (abs(t1->data[k][j]) & mask){ // newly significant
+ int xorbit;
+ int ctxno = getsgnctxno(t1->flags[k+1][j+1], &xorbit);
+ aec_encode(&t1->aec, ctxno, (t1->data[k][j] < 0 ? 1:0) ^ xorbit);
+ set_significant(t1, j, k);
+ }
+ }
+ t1->flags[k+1][j+1] &= ~J2K_T1_VIS;
+ }
+ }
+ }
+}
+
+static void encode_cblk(J2kEncoderContext *s, J2kT1Context *t1, J2kCblk *cblk, int width, int height, int bandno)
+{
+ int pass_t = 2, passno, i, j, mask, max=0, nonzerobits;
+
+ for (i = 0; i < height+2; i++)
+ bzero(t1->flags[i], (width+2)*sizeof(int));
+
+ for (i = 0; i < height; i++){
+ for (j = 0; j < width; j++)
+ max = FFMAX(max, abs(t1->data[i][j]));
+ }
+
+ if (max == 0){
+ // XXX: both should be 0, but something goes wrong, when set so
+ // - to be corrected
+ nonzerobits = 1;
+ mask = 1;
+ }
+ else{
+ nonzerobits = av_log2(max) + 1;
+ mask = 1 << (nonzerobits - 1);
+ }
+
+ aec_initenc(&t1->aec, cblk->data);
+
+ cblk->zerobits = s->expn + s->nguardbits - 1 - nonzerobits;
+
+ for (passno = 0; mask != 0; passno++){
+ switch(pass_t){
+ case 0: encode_sigpass(t1, width, height, mask, bandno);
+ break;
+ case 1: encode_refpass(t1, width, height, mask);
+ break;
+ case 2: encode_clnpass(t1, width, height, mask, bandno);
+ break;
+ }
+ if (++pass_t == 3){
+ pass_t = 0;
+ mask = mask >> 1;
+ }
+ }
+ cblk->npassess = passno;
+
+ // TODO: optional flush on each pass
+ cblk->length = aec_flush(&t1->aec);
+}
+
+/* tier-2 routines: */
+
+static void putnumpassess(J2kEncoderContext *s, int n)
+{
+ if (n == 1)
+ put_num(s, 0, 1);
+ else if (n == 2)
+ put_num(s, 2, 2);
+ else if (n <= 5)
+ put_num(s, 0xc | (n-3), 4);
+ else if (n <= 36)
+ put_num(s, 0x1e0 | (n-6), 9);
+ else
+ put_num(s, 0xff80 | (n-37), 16);
+}
+
+
+static void encode_packet(J2kEncoderContext *s, J2kResLevel *rlevel, int precno)
+{
+ int bandno;
+
+ // init bitstream
+ *s->buf = 0;
+ s->bit_index = 0;
+
+ // header
+
+ // is the packet empty?
+ put_bits(s, 1, 1); // 1 - there are not any empty packets
+ for (bandno = 0; bandno < rlevel->nbands; bandno++){
+ J2kBand *band = rlevel->band + bandno;
+ J2kTgtNode *cblkincl, *zerobits;
+ int cblknw, cblknh, yi, xi, pos;
+
+ cblknh = band->prec[precno].yi1 - band->prec[precno].yi0;
+ cblknw = band->prec[precno].xi1 - band->prec[precno].xi0;
+
+ cblkincl = tag_tree_init(cblknw, cblknh);
+ zerobits = tag_tree_init(cblknw, cblknh);
+
+ for (pos=0, yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){
+ for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++, pos++){
+ cblkincl[pos].val = 0;
+ tag_tree_update(cblkincl + pos);
+ zerobits[pos].val = band->cblk[yi * cblknw + xi].zerobits;
+ tag_tree_update(zerobits + pos);
+ }
+ }
+
+ for (pos=0, yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){
+ for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++, pos++){
+ int pad = 0, llen;
+ J2kCblk *cblk = band->cblk + yi * cblknw + xi;
+
+ // inclusion information
+ tag_tree_code(s, cblkincl + pos);
+ // zerobits information
+ tag_tree_code(s, zerobits + pos);
+ // number of passess
+ putnumpassess(s, cblk->npassess);
+
+ llen = av_log2(cblk->length) - av_log2(cblk->npassess) - 2;
+ if (llen < 0){
+ pad = -llen;
+ llen = 0;
+ }
+ // length of code block
+ put_bits(s, 1, llen);
+ put_bits(s, 0, 1);
+ put_num(s, cblk->length, av_log2(cblk->length)+1+pad);
+ }
+ }
+
+ tag_tree_destroy(cblkincl);
+ tag_tree_destroy(zerobits);
+ }
+ j2k_flush(s);
+ for (bandno = 0; bandno < rlevel->nbands; bandno++){
+ J2kBand *band = rlevel->band + bandno;
+ int cblknw, yi;
+ cblknw = band->prec[precno].xi1 - band->prec[precno].xi0;
+ for (yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){
+ int xi;
+ for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++){
+ J2kCblk *cblk = band->cblk + yi * cblknw + xi;
+ bytestream_put_buffer(&s->buf, cblk->data, cblk->length);
+ }
+ }
+ }
+}
+
+static void encode_tile(J2kEncoderContext *s, int tileno)
+{
+ int compno, reslevelno, bandno;
+ J2kT1Context t1;
+ for (compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = s->tile[tileno].comp + compno;
+
+ av_log(s->avctx, AV_LOG_DEBUG,"dwt\n");
+ dwt_encode53(s, &s->tile[tileno].comp[compno]);
+ av_log(s->avctx, AV_LOG_DEBUG,"after dwt -> tier1\n");
+
+ for (reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
+ J2kResLevel *reslevel = comp->reslevel + reslevelno;
+
+ for (bandno = 0; bandno < reslevel->nbands ; bandno++){
+ J2kBand *band = reslevel->band + bandno;
+ int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1;
+ yy0 = bandno == 0 ? 0 : comp->reslevel[reslevelno-1].y1 - comp->reslevel[reslevelno-1].y0;
+ y0 = yy0;
+ yy1 = FFMIN(ceildiv(band->y0 + 1, band->cblkh) * band->cblkh, band->y1) - band->y0 + yy0;
+
+ for (cblky = 0; cblky < band->cblkny; cblky++){
+ if (reslevelno == 0 || bandno == 1)
+ xx0 = 0;
+ else
+ xx0 = comp->reslevel[reslevelno-1].x1 - comp->reslevel[reslevelno-1].x0;
+ x0 = xx0;
+ xx1 = FFMIN(ceildiv(band->x0 + 1, band->cblkw) * band->cblkw, band->x1) - band->x0 + xx0;
+
+ for (cblkx = 0; cblkx < band->cblknx; cblkx++, cblkno++){
+ int y, x;
+ for (y = yy0; y < yy1; y++){
+ int *ptr = t1.data[y-yy0];
+ for (x = xx0; x < xx1; x++)
+ *ptr++ = comp->data[(comp->x1 - comp->x0) * y + x];
+ }
+ encode_cblk(s, &t1, band->cblk + cblkno, xx1 - xx0, yy1 - yy0, bandno + (reslevelno > 0?1:0));
+ xx0 = xx1;
+ xx1 = FFMIN(xx1 + band->cblkw, band->x1 - band->x0 + x0);
+ }
+ yy0 = yy1;
+ yy1 = FFMIN(yy1 + band->cblkh, band->y1 - band->y0 + y0);
+ }
+ }
+ }
+ av_free(comp->data);
+ av_log(s->avctx, AV_LOG_DEBUG, "after tier1\n");
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "tier2\n");
+ // lay-rlevel-comp-pos progression
+ for (reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
+ for (compno = 0; compno < s->ncomponents; compno++){
+ int precno;
+ J2kResLevel *reslevel = s->tile[tileno].comp[compno].reslevel + reslevelno;
+ for (precno = 0; precno < reslevel->nprecw * reslevel->nprech; precno++){
+ encode_packet(s, reslevel, precno);
+ }
+ }
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "after tier2\n");
+}
+
+void free(J2kEncoderContext *s)
+{
+ int tileno, compno, reslevelno, bandno;
+ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
+ for (compno = 0; compno < s->ncomponents; compno++){
+ J2kComponent *comp = s->tile[tileno].comp + compno;
+
+ for (reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
+ J2kResLevel *reslevel = comp->reslevel + reslevelno;
+
+ for (bandno = 0; bandno < reslevel->nbands ; bandno++){
+ J2kBand *band = reslevel->band + bandno;
+ av_free(band->cblk);
+ av_free(band->prec);
+ }
+ av_free(reslevel->band);
+ }
+ av_free(comp->reslevel);
+ }
+ av_free(s->tile[tileno].comp);
+ }
+ av_free(s->tile);
+}
+
+static int encode_frame(AVCodecContext *avctx,
+ uint8_t *buf, int buf_size,
+ void *data)
+{
+ int tileno;
+ J2kEncoderContext *s = avctx->priv_data;
+
+ av_log(s->avctx, AV_LOG_DEBUG, "start\n");
+ s->picture = data;
+
+ // defaults:
+ // TODO: implement setting non-standard precinct size
+ s->ppx = 15; s->ppy = 15;
+
+ s->XTsiz = 256; s->YTsiz = 256;
+ s->nreslevels = 7;
+ s->xcb = s->ycb = 4;
+
+ // init:
+ s->buf = s->buf_start = buf;
+ s->buf_end = buf + buf_size;
+ s->Xsiz = avctx->width;
+ s->Ysiz = avctx->height;
+
+
+ // TODO: other pixel formats
+ if (avctx->pix_fmt == PIX_FMT_RGB24){
+ s->ncomponents = 3;
+ s->bpp = 24;
+
+ // XXX: to beverified (after adding quantization)
+ // (now it just works, but i'm not sure why ;-) )
+ s->nguardbits = 1;
+ s->expn = 8;
+ }
+ else{
+ av_log(avctx, AV_LOG_ERROR, "only rgb24 supported\n");
+ }
+
+ put_soc(s);
+ put_siz(s);
+ put_cod(s);
+ put_qcd(s);
+
+ av_log(s->avctx, AV_LOG_DEBUG, "init\n");
+ init_tiles(s);
+ av_log(s->avctx, AV_LOG_DEBUG, "after init\n");
+
+ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){
+ uint8_t *psotptr;
+ psotptr = put_sot(s, tileno);
+ put_marker(s, J2K_SOD);
+ encode_tile(s, tileno);
+ bytestream_put_be32(&psotptr, s->buf - psotptr + 6);
+ }
+ put_marker(s, J2K_EOC);
+
+ free(s);
+ av_log(s->avctx, AV_LOG_DEBUG, "end\n");
+ return s->buf - s->buf_start;
+}
+
+AVCodec jpeg2000_encoder = {
+ "j2k",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_JPEG2000,
+ sizeof(J2kEncoderContext),
+ NULL,
+ encode_frame,
+ NULL,
+ NULL,
+ 0,
+ .pix_fmts =
+ (enum PixelFormat[]) {PIX_FMT_RGB24, -1}
+};
7
8
Author: reynaldo
Date: Thu Jul 5 23:20:05 2007
New Revision: 318
Log:
- Fixes missing filename update
- Fixes .svn-dir-getting-rewrited issue
Modified:
qcelp/srcprepare.sh
Modified: qcelp/srcprepare.sh
==============================================================================
--- qcelp/srcprepare.sh (original)
+++ qcelp/srcprepare.sh Thu Jul 5 23:20:05 2007
@@ -66,7 +66,7 @@ PATCH=`which patch`
echo -n "syncing FFmpeg sources from $1: "
-for i in `rsync -avz $1 .` ; do true ; done
+for i in `rsync -avz $1/trunk .` ; do true ; done
if [ $? ]; then
echo "Finished"
@@ -79,7 +79,7 @@ echo "Copying needed files and patching
cd trunk
patch -p0 < ../qcelp_glue.diff
cp ../qcelpdec.c libavcodec/
-cp ../qcelp.h libavcodec
+cp ../qcelpdata.h libavcodec
cd ..
1
0