예제 #1
0
        public static int alloc_table(VLC vlc, int size, int use_static)
        {
            int index;

            index           = vlc.table_size;
            vlc.table_size += size;
            if (vlc.table_size > vlc.table_allocated)
            {
                if (use_static != 0)
                {
                    //abort(); //cant do anything, init_vlc() is used with too little memory
                    return(0);
                }
                vlc.table_allocated += 1 << vlc.bits;
                short[][] /*2*/ newTab = Arrays.Create <short>(2 * vlc.table_allocated, 2);
                for (int i = 0; i < vlc.table_base.Length; i++)
                {
                    newTab[i][0] = vlc.table_base[i][0];
                    newTab[i][1] = vlc.table_base[i][1];
                } // for i
                vlc.table_base = newTab;
                //vlc.table = av_realloc(vlc->table,
                //                        sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
                if (null == vlc.table_base)
                {
                    return(-1);
                }
            }
            return(index);
        }
예제 #2
0
        public void ff_h264_decode_init_vlc()
        {
            if (0 == calvc_inited)
            {
                int i;
                int offset;
                calvc_inited = 1;

                //chroma_dc_coeff_token_vlc.table_base = chroma_dc_coeff_token_vlc_table;
                chroma_dc_coeff_token_vlc.table_base = CAVLCTables.expandTable(CAVLCTables.chroma_dc_coeff_token_vlc_table);
                chroma_dc_coeff_token_vlc.table_offset = 0;
                chroma_dc_coeff_token_vlc.table_allocated = chroma_dc_coeff_token_vlc_table_size;
                /*
                GetBitContext.init_vlc(chroma_dc_coeff_token_vlc, H264Context.CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5,
                         chroma_dc_coeff_token_len,0, 1, 1,
                         chroma_dc_coeff_token_bits,0, 1, 1,
                         GetBitContext.INIT_VLC_USE_NEW_STATIC);
                */

                offset = 0;
                for (i = 0; i < 4; i++)
                {
                    coeff_token_vlc[i] = new VLC();
                    //	            coeff_token_vlc[i].table_base = coeff_token_vlc_tables;
                    //	            coeff_token_vlc[i].table_offset = offset;
                    coeff_token_vlc[i].table_base = CAVLCTables.expandTable(CAVLCTables.coeff_token_vlc_table[i]);
                    coeff_token_vlc[i].table_offset = 0;
                    coeff_token_vlc[i].table_allocated = coeff_token_vlc_tables_size[i];
                    /*
                    GetBitContext.init_vlc(coeff_token_vlc[i], H264Context.COEFF_TOKEN_VLC_BITS, 4*17,
                             coeff_token_len [i],0, 1, 1,
                             coeff_token_bits[i],0, 1, 1,
                             GetBitContext.INIT_VLC_USE_NEW_STATIC);
                    */
                    offset += coeff_token_vlc_tables_size[i];
                }
                /*
                 * This is a one time safety check to make sure that
                 * the packed static coeff_token_vlc table sizes
                 * were initialized correctly.
                 */
                ////assert(offset == FF_ARRAY_ELEMS(coeff_token_vlc_tables));

                for (i = 0; i < 3; i++)
                {
                    chroma_dc_total_zeros_vlc[i] = new VLC();
                    //	            chroma_dc_total_zeros_vlc[i].table_base = chroma_dc_total_zeros_vlc_tables[i];
                    chroma_dc_total_zeros_vlc[i].table_base = CAVLCTables.expandTable(CAVLCTables.chroma_dc_total_zeros_vlc_table[i]);
                    chroma_dc_total_zeros_vlc[i].table_offset = 0;
                    chroma_dc_total_zeros_vlc[i].table_allocated = chroma_dc_total_zeros_vlc_tables_size;
                    /*
                    GetBitContext.init_vlc(chroma_dc_total_zeros_vlc[i],
                            H264Context.CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4,
                             chroma_dc_total_zeros_len [i],0, 1, 1,
                             chroma_dc_total_zeros_bits[i],0, 1, 1,
                             GetBitContext.INIT_VLC_USE_NEW_STATIC);
                    */
                }
                for (i = 0; i < 15; i++)
                {
                    total_zeros_vlc[i] = new VLC();
                    //	            total_zeros_vlc[i].table_base = total_zeros_vlc_tables[i];
                    total_zeros_vlc[i].table_base = CAVLCTables.expandTable(CAVLCTables.total_zeros_vlc[i]);
                    total_zeros_vlc[i].table_offset = 0;
                    total_zeros_vlc[i].table_allocated = total_zeros_vlc_tables_size;
                    /*
                    GetBitContext.init_vlc(total_zeros_vlc[i],
                            H264Context.TOTAL_ZEROS_VLC_BITS, 16,
                             total_zeros_len [i],0, 1, 1,
                             total_zeros_bits[i],0, 1, 1,
                             GetBitContext.INIT_VLC_USE_NEW_STATIC);
                    */
                }

                for (i = 0; i < 6; i++)
                {
                    run_vlc[i] = new VLC();
                    //	            run_vlc[i].table_base = run_vlc_tables[i];
                    run_vlc[i].table_base = CAVLCTables.expandTable(CAVLCTables.run_vlc_table[i]);
                    run_vlc[i].table_offset = 0;
                    run_vlc[i].table_allocated = run_vlc_tables_size;
                    /*
                    GetBitContext.init_vlc(run_vlc[i],
                            H264Context.RUN_VLC_BITS, 7,
                             run_len [i],0, 1, 1,
                             run_bits[i],0, 1, 1,
                             GetBitContext.INIT_VLC_USE_NEW_STATIC);
                    */
                }
                //	        run7_vlc.table_base = run7_vlc_table;
                run7_vlc.table_base = CAVLCTables.expandTable(CAVLCTables.run7_vlc_table);
                run7_vlc.table_offset = 0;
                run7_vlc.table_allocated = run7_vlc_table_size;
                /*
                GetBitContext.init_vlc(run7_vlc, H264Context.RUN7_VLC_BITS, 16,
                         run_len [6],0, 1, 1,
                         run_bits[6],0, 1, 1,
                         GetBitContext.INIT_VLC_USE_NEW_STATIC);
                */
                init_cavlc_level_tab();
            }
        }
예제 #3
0
        /**
         * Build VLC decoding tables suitable for use with get_vlc().
         *
         * @param vlc            the context to be initted
         *
         * @param table_nb_bits  max length of vlc codes to store directly in this table
         *                       (Longer codes are delegated to subtables.)
         *
         * @param nb_codes       number of elements in codes[]
         *
         * @param codes          descriptions of the vlc codes
         *                       These must be ordered such that codes going into the same subtable are contiguous.
         *                       Sorting by VLCcode.code is sufficient, though not necessary.
         */
        public static int build_table(VLC vlc, int table_nb_bits, int nb_codes,
                                      VLCcode[] codes_base, int codes_offset, int flags)
        {
            int  table_size, table_index, index, code_prefix, symbol, subtable_bits;
            int  i, k, n, nb, inc;
            long j;
            //uint32_t code;
            long code;

            //VLC_TYPE (*table)[2];
            short[][] table_base;
            int       table_offset;

            table_size  = 1 << table_nb_bits;
            table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC);

            /*
             #ifdef DEBUG_VLC
             *  av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d\n",
             *         table_index, table_size);
             #endif
             */
            if (table_index < 0)
            {
                return(-1);
            }
            table_base   = vlc.table_base;
            table_offset = vlc.table_offset + table_index;

            for (i = 0; i < table_size; i++)
            {
                table_base[table_offset + i][1] = 0;  //bits
                table_base[table_offset + i][0] = -1; //codes
            }

            /* first pass: map codes and compute auxillary table sizes */
            for (i = 0; i < nb_codes; i++)
            {
                n      = codes_base[codes_offset + i].bits;
                code   = codes_base[codes_offset + i].code;
                symbol = codes_base[codes_offset + i].symbol;

                //Console.WriteLine("i="+i+" n="+n+" code="+code);

                if (n <= table_nb_bits)
                {
                    /* no need to add another table */
                    //!!! Prevent 32-Bit value in negative interval
                    long tmp = code & 0xffffffffL;
                    j   = (int)(tmp >> (32 - table_nb_bits));
                    nb  = 1 << (table_nb_bits - n);
                    inc = 1;
                    if ((flags & INIT_VLC_LE) != 0)
                    {
                        j   = bitswap_32(code);
                        inc = 1 << n;
                    }
                    for (k = 0; k < nb; k++)
                    {
                        //Console.WriteLine("["+j+"]: code="+i+" n="+n);

                        if (table_base[(int)(table_offset + j)][1] /*bits*/ != 0)
                        {
                            //Console.WriteLine("incorrect codes.");
                            return(-1);
                        }
                        table_base[(int)(table_offset + j)][1] = (short)n;   //bits
                        table_base[(int)(table_offset + j)][0] = (short)symbol;
                        j += inc;
                    }
                }
                else
                {
                    /* fill auxiliary table recursively */
                    n -= table_nb_bits;
                    long tmp = code & 0xffffffffL;
                    code_prefix   = (int)(tmp >> (32 - table_nb_bits));
                    subtable_bits = n;
                    codes_base[codes_offset + i].bits = (byte)n;
                    codes_base[codes_offset + i].code = (uint)(code << table_nb_bits);
                    for (k = i + 1; k < nb_codes; k++)
                    {
                        n = codes_base[codes_offset + k].bits - table_nb_bits;
                        if (n <= 0)
                        {
                            break;
                        }
                        code = codes_base[codes_offset + k].code;
                        if (code >> (32 - table_nb_bits) != code_prefix)
                        {
                            break;
                        }
                        codes_base[codes_offset + k].bits = (byte)n;
                        codes_base[codes_offset + k].code = (uint)(code << table_nb_bits);
                        subtable_bits = Math.Max(subtable_bits, n);
                    }
                    subtable_bits = Math.Min(subtable_bits, table_nb_bits);
                    j             = (flags & INIT_VLC_LE) != 0 ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix;
                    table_base[(int)(table_offset + j)][1] = (short)-subtable_bits;

                    //Console.WriteLine("["+j+"]: n="+codes_base[codes_offset + i].bits + table_nb_bits+"(subtable)");

                    index = build_table(vlc, subtable_bits, k - i, codes_base, codes_offset + i, flags);
                    if (index < 0)
                    {
                        return(-1);
                    }
                    /* note: realloc has been done, so reload tables */
                    table_base   = vlc.table_base;
                    table_offset = vlc.table_offset + table_index;
                    table_base[(int)(table_offset + j)][0] = (short)index;   //code
                    i = k - 1;
                }
            }
            return(table_index);
        }