ffmpeg-20150921/libavcodec/dca_exss.c
/**
 * Parse extension substream header (HD)
 */
Parse extension substream header (HD)
Parse extension substream header ( HD )
void ff_dca_exss_parse_header(DCAContext *s)
{
    int asset_size[8];
    int ss_index;
    int blownup;
    int num_audiop = 1;
    int num_assets = 1;
    int active_ss_mask[8];
    int i, j;
    int start_pos;
    int hdrsize;
    uint32_t mkr;
    if (get_bits_left(&s->gb) < 52)
        return;
    start_pos = get_bits_count(&s->gb) - 32;
    skip_bits(&s->gb, 8); 
    ss_index = get_bits(&s->gb, 2);
    blownup = get_bits1(&s->gb);
    hdrsize = get_bits(&s->gb,  8 + 4 * blownup) + 1; 
    skip_bits(&s->gb, 16 + 4 * blownup); 
    s->static_fields = get_bits1(&s->gb);
    if (s->static_fields) {
        skip_bits(&s->gb, 2); 
        skip_bits(&s->gb, 3); 
        if (get_bits1(&s->gb))
            skip_bits_long(&s->gb, 36); 
        num_audiop = get_bits(&s->gb, 3) + 1;
        if (num_audiop > 1) {
            avpriv_request_sample(s->avctx,
                                  "Multiple DTS-HD audio presentations");
            return;
        }
        num_assets = get_bits(&s->gb, 3) + 1;
        if (num_assets > 1) {
            avpriv_request_sample(s->avctx, "Multiple DTS-HD audio assets");
            return;
        }
        for (i = 0; i < num_audiop; i++)
            active_ss_mask[i] = get_bits(&s->gb, ss_index + 1);
        for (i = 0; i < num_audiop; i++)
            for (j = 0; j <= ss_index; j++)
                if (active_ss_mask[i] & (1 << j))
                    skip_bits(&s->gb, 8); 
        s->mix_metadata = get_bits1(&s->gb);
        if (s->mix_metadata) {
            int mix_out_mask_size;
            skip_bits(&s->gb, 2); 
            mix_out_mask_size  = (get_bits(&s->gb, 2) + 1) << 2;
            s->num_mix_configs =  get_bits(&s->gb, 2) + 1;
            for (i = 0; i < s->num_mix_configs; i++) {
                int mix_out_mask        = get_bits(&s->gb, mix_out_mask_size);
                s->mix_config_num_ch[i] = dca_exss_mask2count(mix_out_mask);
            }
        }
    }
    av_assert0(num_assets > 0); 
    for (i = 0; i < num_assets; i++)
        asset_size[i] = get_bits_long(&s->gb, 16 + 4 * blownup) + 1;
    for (i = 0; i < num_assets; i++) {
        if (dca_exss_parse_asset_header(s))
            return;
    }
        j = get_bits_count(&s->gb);
        if (start_pos + hdrsize * 8 > j)
            skip_bits_long(&s->gb, start_pos + hdrsize * 8 - j);
        for (i = 0; i < num_assets; i++) {
            int end_pos;
            start_pos = get_bits_count(&s->gb);
            end_pos   = start_pos + asset_size[i] * 8;
            mkr       = get_bits_long(&s->gb, 32);
            switch (mkr) {
            case DCA_SYNCWORD_XBR:
                ff_dca_xbr_parse_frame(s);
                break;
            case DCA_SYNCWORD_XXCH:
                ff_dca_xxch_decode_frame(s);
                s->core_ext_mask |= DCA_EXT_XXCH; 
                break;
            case DCA_SYNCWORD_XLL:
                if (s->xll_disable) {
                    av_log(s->avctx, AV_LOG_DEBUG,
                           "DTS-XLL: ignoring XLL extension\n");
                    break;
                }
                av_log(s->avctx, AV_LOG_DEBUG,
                       "DTS-XLL: decoding XLL extension\n");
                if (ff_dca_xll_decode_header(s)        == 0 &&
                    ff_dca_xll_decode_navi(s, end_pos) == 0)
                    s->exss_ext_mask |= DCA_EXT_EXSS_XLL;
                break;
            default:
                av_log(s->avctx, AV_LOG_DEBUG,
                       "DTS-ExSS: unknown marker = 0x%08x\n", mkr);
            }
            j = get_bits_count(&s->gb);
            if (j > end_pos)
                av_log(s->avctx, AV_LOG_ERROR,
                       "DTS-ExSS: Processed asset too long.\n");
            if (j < end_pos)
                skip_bits_long(&s->gb, end_pos - j);
        }
}
void ff_dca_exss_parse_header ( DCAContext * s ) { int asset_size [ 8 ] ; int ss_index ; int blownup ; int num_audiop = 1 ; int num_assets = 1 ; int active_ss_mask [ 8 ] ; int i , j ; int start_pos ; int hdrsize ; uint32_t mkr ; if ( get_bits_left ( & s -> gb ) < 52 ) return ; start_pos = get_bits_count ( & s -> gb ) - 32 ; skip_bits ( & s -> gb , 8 ) ; ss_index = get_bits ( & s -> gb , 2 ) ; blownup = get_bits1 ( & s -> gb ) ; hdrsize = get_bits ( & s -> gb , 8 + 4 * blownup ) + 1 ; skip_bits ( & s -> gb , 16 + 4 * blownup ) ; s -> static_fields = get_bits1 ( & s -> gb ) ; if ( s -> static_fields ) { skip_bits ( & s -> gb , 2 ) ; skip_bits ( & s -> gb , 3 ) ; if ( get_bits1 ( & s -> gb ) ) skip_bits_long ( & s -> gb , 36 ) ; num_audiop = get_bits ( & s -> gb , 3 ) + 1 ; if ( num_audiop > 1 ) { avpriv_request_sample ( s -> avctx , " " ) ; return ; } num_assets = get_bits ( & s -> gb , 3 ) + 1 ; if ( num_assets > 1 ) { avpriv_request_sample ( s -> avctx , " " ) ; return ; } for ( i = 0 ; i < num_audiop ; i ++ ) active_ss_mask [ i ] = get_bits ( & s -> gb , ss_index + 1 ) ; for ( i = 0 ; i < num_audiop ; i ++ ) for ( j = 0 ; j <= ss_index ; j ++ ) if ( active_ss_mask [ i ] & ( 1 << j ) ) skip_bits ( & s -> gb , 8 ) ; s -> mix_metadata = get_bits1 ( & s -> gb ) ; if ( s -> mix_metadata ) { int mix_out_mask_size ; skip_bits ( & s -> gb , 2 ) ; mix_out_mask_size = ( get_bits ( & s -> gb , 2 ) + 1 ) << 2 ; s -> num_mix_configs = get_bits ( & s -> gb , 2 ) + 1 ; for ( i = 0 ; i < s -> num_mix_configs ; i ++ ) { int mix_out_mask = get_bits ( & s -> gb , mix_out_mask_size ) ; s -> mix_config_num_ch [ i ] = dca_exss_mask2count ( mix_out_mask ) ; } } } av_assert0 ( num_assets > 0 ) ; for ( i = 0 ; i < num_assets ; i ++ ) asset_size [ i ] = get_bits_long ( & s -> gb , 16 + 4 * blownup ) + 1 ; for ( i = 0 ; i < num_assets ; i ++ ) { if ( dca_exss_parse_asset_header ( s ) ) return ; } j = get_bits_count ( & s -> gb ) ; if ( start_pos + hdrsize * 8 > j ) skip_bits_long ( & s -> gb , start_pos + hdrsize * 8 - j ) ; for ( i = 0 ; i < num_assets ; i ++ ) { int end_pos ; start_pos = get_bits_count ( & s -> gb ) ; end_pos = start_pos + asset_size [ i ] * 8 ; mkr = get_bits_long ( & s -> gb , 32 ) ; switch ( mkr ) { case DCA_SYNCWORD_XBR : ff_dca_xbr_parse_frame ( s ) ; break ; case DCA_SYNCWORD_XXCH : ff_dca_xxch_decode_frame ( s ) ; s -> core_ext_mask |= DCA_EXT_XXCH ; break ; case DCA_SYNCWORD_XLL : if ( s -> xll_disable ) { av_log ( s -> avctx , AV_LOG_DEBUG , " \n " ) ; break ; } av_log ( s -> avctx , AV_LOG_DEBUG , " \n " ) ; if ( ff_dca_xll_decode_header ( s ) == 0 && ff_dca_xll_decode_navi ( s , end_pos ) == 0 ) s -> exss_ext_mask |= DCA_EXT_EXSS_XLL ; break ; default : av_log ( s -> avctx , AV_LOG_DEBUG , " \n " , mkr ) ; } j = get_bits_count ( & s -> gb ) ; if ( j > end_pos ) av_log ( s -> avctx , AV_LOG_ERROR , " \n " ) ; if ( j < end_pos ) skip_bits_long ( & s -> gb , end_pos - j ) ; } }
Parse extension substream header (HD)
Parse extension substream header ( HD )
// user data // header_size // hd_size // reference clock code // frame duration code // timestamp /* a single stream can contain multiple audio assets that can be
         * combined to form multiple audio presentations */ /* ignore such streams for now */ /* ignore such streams for now */ // active asset mask // adjustment level // silence a warning /* parse extensions that we know about */ /* xxx use for chan reordering */ /* skip to end of block */