⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frame.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 3 页
字号:
                if (macroblock_modes & MACROBLOCK_MOTION_FORWARD)                    bs_write( bs, (macroblock_modes & MOTION_TYPE_MASK) / MOTION_TYPE_BASE, 2);                break;            }            else if (tr->frame_pred_frame_dct) break;            else            {                if (macroblock_modes & MACROBLOCK_MOTION_FORWARD)                    bs_write( bs, (macroblock_modes & MOTION_TYPE_MASK) / MOTION_TYPE_BASE, 2);                if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN))                    bs_write( bs, macroblock_modes & DCT_TYPE_INTERLACED ? 1 : 0, 1);                break;            }        case B_TYPE:            if (tr->picture_structure != FRAME_PICTURE)            {                if (! (macroblock_modes & MACROBLOCK_INTRA))                    bs_write( bs, (macroblock_modes & MOTION_TYPE_MASK) / MOTION_TYPE_BASE, 2);                break;            }            else if (tr->frame_pred_frame_dct) break;            else            {                if (macroblock_modes & MACROBLOCK_INTRA) goto intra;                bs_write( bs, (macroblock_modes & MOTION_TYPE_MASK) / MOTION_TYPE_BASE, 2);                if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN))                {                    intra:                    bs_write( bs, macroblock_modes & DCT_TYPE_INTERLACED ? 1 : 0, 1);                }                break;            }    }}static const uint8_t map_non_linear_mquant[113] ={    0,1,2,3,4,5,6,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,    16,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,22,22,    22,22,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,    26,26,26,26,26,26,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,    29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31,31};static inline void put_quantiser( transrate_t *tr ){    bs_transrate_t *bs = &tr->bs;    bs_write( bs, tr->q_scale_type ? map_non_linear_mquant[tr->new_quantizer_scale] : tr->new_quantizer_scale >> 1, 5 );    tr->last_coded_scale = tr->new_quantizer_scale;}/* generate variable length code for macroblock_address_increment (6.3.16) */static inline void putaddrinc( transrate_t *tr, int addrinc ){    bs_transrate_t *bs = &tr->bs;    while ( addrinc >= 33 )    {        bs_write( bs, 0x08, 11 ); /* macroblock_escape */        addrinc -= 33;    }    bs_write( bs, addrinctab[addrinc].code, addrinctab[addrinc].len );}static int slice_init( transrate_t *tr,  int code ){    bs_transrate_t *bs = &tr->bs;    int offset;    const MBAtab * mba;    tr->v_offset = (code - 1) * 16;    tr->quantizer_scale = get_quantizer_scale( tr );    if ( tr->new_quantizer_scale < tr->quantizer_scale )        tr->new_quantizer_scale = scale_quant( tr, tr->qrate );    /*LOGF("************************\nstart of slice %i in %s picture. ori quant: %i new quant: %i\n", code,        (picture_coding_type == I_TYPE ? "I_TYPE" : (picture_coding_type == P_TYPE ? "P_TYPE" : "B_TYPE")),        quantizer_scale, new_quantizer_scale);*/    /* ignore intra_slice and all the extra data */    while (bs->i_bit_in_cache & 0x80000000)    {        bs_flush( bs, 9 );    }    /* decode initial macroblock address increment */    offset = 0;    for( ;; )    {        if (bs->i_bit_in_cache >= 0x08000000)        {            mba = MBA_5 + (UBITS (bs->i_bit_in_cache, 6) - 2);            break;        }        else if (bs->i_bit_in_cache >= 0x01800000)        {            mba = MBA_11 + (UBITS (bs->i_bit_in_cache, 12) - 24);            break;        }        else if( UBITS (bs->i_bit_in_cache, 12 ) == 8 )        {            /* macroblock_escape */            offset += 33;            bs_flush(bs, 11);        }        else        {            return -1;        }    }    bs_flush(bs, mba->len + 1);    tr->h_offset = (offset + mba->mba) << 4;    while( tr->h_offset - (int)tr->horizontal_size_value >= 0)    {        tr->h_offset -= tr->horizontal_size_value;        tr->v_offset += 16;    }    if( tr->v_offset > tr->vertical_size_value - 16 )    {        return -1;    }    return (offset + mba->mba);}static void mpeg2_slice( transrate_t *tr, const int code ){    bs_transrate_t *bs = &tr->bs;    int mba_inc;    int first_in_slice = 1;    if( (mba_inc = slice_init( tr, code )) < 0 )    {        return;    }    for( ;; )    {        const MBAtab * mba;        int macroblock_modes;        int mba_local;        int i;        while (unlikely(bs->i_bit_in < 24)) bs_refill( bs );        macroblock_modes = get_macroblock_modes( tr );        if (macroblock_modes & MACROBLOCK_QUANT)            tr->quantizer_scale = get_quantizer_scale( tr );        if (tr->new_quantizer_scale < tr->quantizer_scale)            tr->new_quantizer_scale = scale_quant( tr, tr->qrate );        //LOGF("blk %i : ", h_offset >> 4);        if (macroblock_modes & MACROBLOCK_INTRA)        {            RunLevel block[6][65]; // terminated by level = 0, so we need 64+1            RunLevel new_block[6][65]; // terminated by level = 0, so we need 64+1            uint32_t dc[6];            uint8_t  dc_len[6];            // begin saving data            int batb;            uint8_t   p_n_ow[32], *p_n_w,                    *p_o_ow = bs->p_ow, *p_o_w = bs->p_w;            uint32_t  i_n_bit_out, i_n_bit_out_cache,                    i_o_bit_out  = bs->i_bit_out, i_o_bit_out_cache = bs->i_bit_out_cache;            bs->i_bit_out_cache = 0; bs->i_bit_out = BITS_IN_BUF;            bs->p_ow = bs->p_w = p_n_ow;            //LOG("intra "); if (macroblock_modes & MACROBLOCK_QUANT) LOGF("got new quant: %i ", quantizer_scale);            if (tr->concealment_motion_vectors)            {                if (tr->picture_structure != FRAME_PICTURE)                {                    bs_copy(bs, 1); /* remove field_select */                }                /* like motion_frame, but parsing without actual motion compensation */                get_motion_delta(bs, tr->f_code[0][0]);                get_motion_delta(bs, tr->f_code[0][1]);                bs_copy(bs, 1); /* remove marker_bit */            }            assert(bs->p_w - bs->p_ow < 32);            p_n_w = bs->p_w;            i_n_bit_out = bs->i_bit_out;            i_n_bit_out_cache = bs->i_bit_out_cache;            assert(bs->p_ow == p_n_ow);            bs->i_bit_out = i_o_bit_out ;            bs->i_bit_out_cache = i_o_bit_out_cache;            bs->p_ow = p_o_ow;            bs->p_w = p_o_w;            // end saving data            if( tr->intra_vlc_format )            {                /* Luma */                for ( i = 0; i < 4; i++ )                {                    get_luma_dc_dct_diff( bs, dc + i, dc_len + i );                    get_intra_block_B15( tr, block[i] );                    if (tr->b_error) return;                }                /* Chroma */                for ( ; i < 6; i++ )                {                    get_chroma_dc_dct_diff( bs, dc + i, dc_len + i );                    get_intra_block_B15( tr, block[i] );                    if (tr->b_error) return;                }            }            else            {                /* Luma */                for ( i = 0; i < 4; i++ )                {                    get_luma_dc_dct_diff( bs, dc + i, dc_len + i );                    get_intra_block_B14( tr, block[i] );                    if (tr->b_error) return;                }                /* Chroma */                for ( ; i < 6; i++ )                {                    get_chroma_dc_dct_diff( bs, dc + i, dc_len + i );                    get_intra_block_B14( tr, block[i] );                    if (tr->b_error) return;                }            }            transrate_mb( tr, block, new_block, 0x3f, 1 );            if (tr->last_coded_scale == tr->new_quantizer_scale)                macroblock_modes &= ~MACROBLOCK_QUANT;            if ( first_in_slice )            {                put_quantiser( tr );                bs_write( bs, 0, 1 );                macroblock_modes &= ~MACROBLOCK_QUANT;            }            putaddrinc( tr, mba_inc );            mba_inc = 0;            putmbdata( tr, macroblock_modes );            if( macroblock_modes & MACROBLOCK_QUANT )            {                put_quantiser( tr );            }            // put saved motion data...            for (batb = 0; batb < (p_n_w - p_n_ow); batb++)            {                bs_write( bs, p_n_ow[batb], 8 );            }            bs_write( bs, i_n_bit_out_cache, BITS_IN_BUF - i_n_bit_out );            // end saved motion data...            for ( i = 0; i < 6; i++ )            {                bs_write( bs, *(dc + i), *(dc_len + i) );                putintrablk( bs, new_block[i], tr->intra_vlc_format );            }         }        else        {            RunLevel block[6][65]; // terminated by level = 0, so we need 64+1            RunLevel new_block[6][65]; // terminated by level = 0, so we need 64+1            int new_coded_block_pattern = 0;            int cbp = 0;            // begin saving data            int batb;            uint8_t   p_n_ow[32], *p_n_w,                    *p_o_ow = bs->p_ow, *p_o_w = bs->p_w;            uint32_t  i_n_bit_out, i_n_bit_out_cache,                    i_o_bit_out  = bs->i_bit_out, i_o_bit_out_cache = bs->i_bit_out_cache;            bs->i_bit_out_cache = 0; bs->i_bit_out = BITS_IN_BUF;            bs->p_ow = bs->p_w = p_n_ow;            if (tr->picture_structure == FRAME_PICTURE)                switch (macroblock_modes & MOTION_TYPE_MASK)                {                    case MC_FRAME: MOTION_CALL (motion_fr_frame, macroblock_modes); break;                    case MC_FIELD: MOTION_CALL (motion_fr_field, macroblock_modes); break;                    case MC_DMV: MOTION_CALL (motion_fr_dmv, MACROBLOCK_MOTION_FORWARD); break;                }            else                switch (macroblock_modes & MOTION_TYPE_MASK)                {                    case MC_FIELD: MOTION_CALL (motion_fi_field, macroblock_modes); break;                    case MC_16X8: MOTION_CALL (motion_fi_16x8, macroblock_modes); break;                    case MC_DMV: MOTION_CALL (motion_fi_dmv, MACROBLOCK_MOTION_FORWARD); break;                }            //LOG("non intra "); if (macroblock_modes & MACROBLOCK_QUANT) LOGF("got new quant: %i ", quantizer_scale);            if (macroblock_modes & MACROBLOCK_PATTERN)            {                int last_in_slice;                cbp = get_coded_block_pattern( bs );                for ( i = 0; i < 6; i++ )                {                    if ( cbp & (1 << (5 - i)) )                    {                        get_non_intra_block( tr, block[i] );                        if (tr->b_error) return;                    }                }                last_in_slice = !UBITS( bs->i_bit_in_cache, 11 );                new_coded_block_pattern = transrate_mb( tr, block, new_block,                                                        cbp, 0 );                if ( !new_coded_block_pattern &&                        !(macroblock_modes                            & (MACROBLOCK_MOTION_FORWARD                                | MACROBLOCK_MOTION_BACKWARD))                        && (first_in_slice || last_in_slice) )                {                    /* First mb in slice, just code a 0-mv mb.                     * This is wrong for last in slice, but it only shows                     * a few artefacts. */                    macroblock_modes |= MACROBLOCK_MOTION_FORWARD;                    if (tr->picture_structure == FRAME_PICTURE)                    {                        macroblock_modes |= MC_FRAME;                        bs_write( bs, 0x3, 2 ); /* motion vectors */                    }                    else                    {                        macroblock_modes |= MC_FIELD;                        bs_write( bs,                             (tr->picture_structure == BOTTOM_FIELD ? 1 : 0),                             1); /* motion field select */                        bs_write( bs, 0x3, 2 ); /* motion vectors */                    }                }                if ( !new_coded_block_pattern )                {                    macroblock_modes &= ~MACROBLOCK_PATTERN;                    macroblock_modes &= ~MACROBLOCK_QUANT;                }                else                {                    if ( tr->last_coded_scale == tr->new_quantizer_scale )                    {                        macroblock_modes &= ~MACROBLOCK_QUANT;                    }                    else                    {                        macroblock_modes |= MACROBLOCK_QUANT;                    }                }            }            assert(bs->p_w - bs->p_ow < 32);            p_n_w = bs->p_w;            i_n_bit_out = bs->i_bit_out;            i_n_bit_out_cache = bs->i_bit_out_cache;            assert(bs->p_ow == p_n_ow);            bs->i_bit_out = i_o_bit_out ;            bs->i_bit_out_cache = i_o_bit_out_cache;            bs->p_ow = p_o_ow;            bs->p_w = p_o_w;            // end saving data            if ( macroblock_modes &                    (MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD                      | MACROBLOCK_PATTERN) )            {                if ( first_in_slice )                {                    put_quantiser( tr );                    bs_write( bs, 0, 1 );                    macroblock_modes &= ~MACROBLOCK_QUANT;                }                putaddrinc( tr, mba_inc );                mba_inc = 0;                putmbdata( tr, macroblock_modes );                if ( macroblock_modes & MACROBLOCK_QUANT )                {                    put_quantiser( tr );                }                // put saved motion data...                for (batb = 0; batb < (p_n_w - p_n_ow); batb++)                {                    bs_write( bs, p_n_ow[batb], 8 );                }                bs_write( bs, i_n_bit_out_cache, BITS_IN_BUF - i_n_bit_out);                // end saved motion data...                if (macroblock_modes & MACROBLOCK_PATTERN)                {                    /* Write CBP */                    bs_write( bs, cbptable[new_coded_block_pattern].code,                              cbptable[new_coded_block_pattern].len );                    for ( i = 0; i < 6; i++ )                    {                        if ( new_coded_block_pattern & (1 << (5 - i)) )                        {                            putnonintrablk( bs, new_block[i] );                        }                    }                }            }            else            {                /* skipped macroblock */                mba_inc++;            }        }        if (bs->p_c > bs->p_r || bs->p_w > bs->p_rw)        {            tr->b_error = 1;            return;        }        //LOGF("\n\to: %i c: %i n: %i\n", quantizer_scale, last_coded_scale, new_quantizer_scale);        NEXT_MACROBLOCK;        first_in_slice = 0;        mba_local = 0;        for ( ; ; )        {            if ( bs->i_bit_in_cache >= 0x10000000 )            {                mba = MBA_5 + (UBITS (bs->i_bit_in_cache, 5) - 2);                break;            }            else if ( bs->i_bit_in_cache >= 0x03000000 )            {                mba = MBA_11 + (UBITS (bs->i_bit_in_cache, 11) - 24);                break;            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -