• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/h264_ps.c

Go to the documentation of this file.
00001 /*
00002  * H.26L/H.264/AVC/JVT/14496-10/... parameter set decoding
00003  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00028 #include "internal.h"
00029 #include "dsputil.h"
00030 #include "avcodec.h"
00031 #include "h264.h"
00032 #include "h264data.h" //FIXME FIXME FIXME (just for zigzag_scan)
00033 #include "golomb.h"
00034 
00035 
00036 //#undef NDEBUG
00037 #include <assert.h>
00038 
00039 static const AVRational pixel_aspect[17]={
00040  {0, 1},
00041  {1, 1},
00042  {12, 11},
00043  {10, 11},
00044  {16, 11},
00045  {40, 33},
00046  {24, 11},
00047  {20, 11},
00048  {32, 11},
00049  {80, 33},
00050  {18, 11},
00051  {15, 11},
00052  {64, 33},
00053  {160,99},
00054  {4, 3},
00055  {3, 2},
00056  {2, 1},
00057 };
00058 
00059 const uint8_t ff_h264_chroma_qp[52]={
00060     0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,
00061    12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,
00062    28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37,
00063    37,38,38,38,39,39,39,39
00064 };
00065 
00066 static const uint8_t default_scaling4[2][16]={
00067 {   6,13,20,28,
00068    13,20,28,32,
00069    20,28,32,37,
00070    28,32,37,42
00071 },{
00072    10,14,20,24,
00073    14,20,24,27,
00074    20,24,27,30,
00075    24,27,30,34
00076 }};
00077 
00078 static const uint8_t default_scaling8[2][64]={
00079 {   6,10,13,16,18,23,25,27,
00080    10,11,16,18,23,25,27,29,
00081    13,16,18,23,25,27,29,31,
00082    16,18,23,25,27,29,31,33,
00083    18,23,25,27,29,31,33,36,
00084    23,25,27,29,31,33,36,38,
00085    25,27,29,31,33,36,38,40,
00086    27,29,31,33,36,38,40,42
00087 },{
00088     9,13,15,17,19,21,22,24,
00089    13,13,17,19,21,22,24,25,
00090    15,17,19,21,22,24,25,27,
00091    17,19,21,22,24,25,27,28,
00092    19,21,22,24,25,27,28,30,
00093    21,22,24,25,27,28,30,32,
00094    22,24,25,27,28,30,32,33,
00095    24,25,27,28,30,32,33,35
00096 }};
00097 
00098 static inline int decode_hrd_parameters(H264Context *h, SPS *sps){
00099     MpegEncContext * const s = &h->s;
00100     int cpb_count, i;
00101     cpb_count = get_ue_golomb_31(&s->gb) + 1;
00102 
00103     if(cpb_count > 32U){
00104         av_log(h->s.avctx, AV_LOG_ERROR, "cpb_count %d invalid\n", cpb_count);
00105         return -1;
00106     }
00107 
00108     get_bits(&s->gb, 4); /* bit_rate_scale */
00109     get_bits(&s->gb, 4); /* cpb_size_scale */
00110     for(i=0; i<cpb_count; i++){
00111         get_ue_golomb(&s->gb); /* bit_rate_value_minus1 */
00112         get_ue_golomb(&s->gb); /* cpb_size_value_minus1 */
00113         get_bits1(&s->gb);     /* cbr_flag */
00114     }
00115     sps->initial_cpb_removal_delay_length = get_bits(&s->gb, 5) + 1;
00116     sps->cpb_removal_delay_length = get_bits(&s->gb, 5) + 1;
00117     sps->dpb_output_delay_length = get_bits(&s->gb, 5) + 1;
00118     sps->time_offset_length = get_bits(&s->gb, 5);
00119     sps->cpb_cnt = cpb_count;
00120     return 0;
00121 }
00122 
00123 static inline int decode_vui_parameters(H264Context *h, SPS *sps){
00124     MpegEncContext * const s = &h->s;
00125     int aspect_ratio_info_present_flag;
00126     unsigned int aspect_ratio_idc;
00127 
00128     aspect_ratio_info_present_flag= get_bits1(&s->gb);
00129 
00130     if( aspect_ratio_info_present_flag ) {
00131         aspect_ratio_idc= get_bits(&s->gb, 8);
00132         if( aspect_ratio_idc == EXTENDED_SAR ) {
00133             sps->sar.num= get_bits(&s->gb, 16);
00134             sps->sar.den= get_bits(&s->gb, 16);
00135         }else if(aspect_ratio_idc < FF_ARRAY_ELEMS(pixel_aspect)){
00136             sps->sar=  pixel_aspect[aspect_ratio_idc];
00137         }else{
00138             av_log(h->s.avctx, AV_LOG_ERROR, "illegal aspect ratio\n");
00139             return -1;
00140         }
00141     }else{
00142         sps->sar.num=
00143         sps->sar.den= 0;
00144     }
00145 //            s->avctx->aspect_ratio= sar_width*s->width / (float)(s->height*sar_height);
00146 
00147     if(get_bits1(&s->gb)){      /* overscan_info_present_flag */
00148         get_bits1(&s->gb);      /* overscan_appropriate_flag */
00149     }
00150 
00151     sps->video_signal_type_present_flag = get_bits1(&s->gb);
00152     if(sps->video_signal_type_present_flag){
00153         get_bits(&s->gb, 3);    /* video_format */
00154         sps->full_range = get_bits1(&s->gb); /* video_full_range_flag */
00155 
00156         sps->colour_description_present_flag = get_bits1(&s->gb);
00157         if(sps->colour_description_present_flag){
00158             sps->color_primaries = get_bits(&s->gb, 8); /* colour_primaries */
00159             sps->color_trc       = get_bits(&s->gb, 8); /* transfer_characteristics */
00160             sps->colorspace      = get_bits(&s->gb, 8); /* matrix_coefficients */
00161             if (sps->color_primaries >= AVCOL_PRI_NB)
00162                 sps->color_primaries  = AVCOL_PRI_UNSPECIFIED;
00163             if (sps->color_trc >= AVCOL_TRC_NB)
00164                 sps->color_trc  = AVCOL_TRC_UNSPECIFIED;
00165             if (sps->colorspace >= AVCOL_SPC_NB)
00166                 sps->colorspace  = AVCOL_SPC_UNSPECIFIED;
00167         }
00168     }
00169 
00170     if(get_bits1(&s->gb)){      /* chroma_location_info_present_flag */
00171         s->avctx->chroma_sample_location = get_ue_golomb(&s->gb)+1;  /* chroma_sample_location_type_top_field */
00172         get_ue_golomb(&s->gb);  /* chroma_sample_location_type_bottom_field */
00173     }
00174 
00175     sps->timing_info_present_flag = get_bits1(&s->gb);
00176     if(sps->timing_info_present_flag){
00177         sps->num_units_in_tick = get_bits_long(&s->gb, 32);
00178         sps->time_scale = get_bits_long(&s->gb, 32);
00179         if(!sps->num_units_in_tick || !sps->time_scale){
00180             av_log(h->s.avctx, AV_LOG_ERROR, "time_scale/num_units_in_tick invalid or unsupported (%d/%d)\n", sps->time_scale, sps->num_units_in_tick);
00181             return -1;
00182         }
00183         sps->fixed_frame_rate_flag = get_bits1(&s->gb);
00184     }
00185 
00186     sps->nal_hrd_parameters_present_flag = get_bits1(&s->gb);
00187     if(sps->nal_hrd_parameters_present_flag)
00188         if(decode_hrd_parameters(h, sps) < 0)
00189             return -1;
00190     sps->vcl_hrd_parameters_present_flag = get_bits1(&s->gb);
00191     if(sps->vcl_hrd_parameters_present_flag)
00192         if(decode_hrd_parameters(h, sps) < 0)
00193             return -1;
00194     if(sps->nal_hrd_parameters_present_flag || sps->vcl_hrd_parameters_present_flag)
00195         get_bits1(&s->gb);     /* low_delay_hrd_flag */
00196     sps->pic_struct_present_flag = get_bits1(&s->gb);
00197 
00198     sps->bitstream_restriction_flag = get_bits1(&s->gb);
00199     if(sps->bitstream_restriction_flag){
00200         get_bits1(&s->gb);     /* motion_vectors_over_pic_boundaries_flag */
00201         get_ue_golomb(&s->gb); /* max_bytes_per_pic_denom */
00202         get_ue_golomb(&s->gb); /* max_bits_per_mb_denom */
00203         get_ue_golomb(&s->gb); /* log2_max_mv_length_horizontal */
00204         get_ue_golomb(&s->gb); /* log2_max_mv_length_vertical */
00205         sps->num_reorder_frames= get_ue_golomb(&s->gb);
00206         get_ue_golomb(&s->gb); /*max_dec_frame_buffering*/
00207 
00208         if(s->gb.size_in_bits < get_bits_count(&s->gb)){
00209             av_log(h->s.avctx, AV_LOG_ERROR, "Overread VUI by %d bits\n", get_bits_count(&s->gb) - s->gb.size_in_bits);
00210             sps->num_reorder_frames=0;
00211             sps->bitstream_restriction_flag= 0;
00212         }
00213 
00214         if(sps->num_reorder_frames > 16U /*max_dec_frame_buffering || max_dec_frame_buffering > 16*/){
00215             av_log(h->s.avctx, AV_LOG_ERROR, "illegal num_reorder_frames %d\n", sps->num_reorder_frames);
00216             return -1;
00217         }
00218     }
00219 
00220     return 0;
00221 }
00222 
00223 static void decode_scaling_list(H264Context *h, uint8_t *factors, int size,
00224                                 const uint8_t *jvt_list, const uint8_t *fallback_list){
00225     MpegEncContext * const s = &h->s;
00226     int i, last = 8, next = 8;
00227     const uint8_t *scan = size == 16 ? zigzag_scan : ff_zigzag_direct;
00228     if(!get_bits1(&s->gb)) /* matrix not written, we use the predicted one */
00229         memcpy(factors, fallback_list, size*sizeof(uint8_t));
00230     else
00231     for(i=0;i<size;i++){
00232         if(next)
00233             next = (last + get_se_golomb(&s->gb)) & 0xff;
00234         if(!i && !next){ /* matrix not written, we use the preset one */
00235             memcpy(factors, jvt_list, size*sizeof(uint8_t));
00236             break;
00237         }
00238         last = factors[scan[i]] = next ? next : last;
00239     }
00240 }
00241 
00242 static void decode_scaling_matrices(H264Context *h, SPS *sps, PPS *pps, int is_sps,
00243                                    uint8_t (*scaling_matrix4)[16], uint8_t (*scaling_matrix8)[64]){
00244     MpegEncContext * const s = &h->s;
00245     int fallback_sps = !is_sps && sps->scaling_matrix_present;
00246     const uint8_t *fallback[4] = {
00247         fallback_sps ? sps->scaling_matrix4[0] : default_scaling4[0],
00248         fallback_sps ? sps->scaling_matrix4[3] : default_scaling4[1],
00249         fallback_sps ? sps->scaling_matrix8[0] : default_scaling8[0],
00250         fallback_sps ? sps->scaling_matrix8[1] : default_scaling8[1]
00251     };
00252     if(get_bits1(&s->gb)){
00253         sps->scaling_matrix_present |= is_sps;
00254         decode_scaling_list(h,scaling_matrix4[0],16,default_scaling4[0],fallback[0]); // Intra, Y
00255         decode_scaling_list(h,scaling_matrix4[1],16,default_scaling4[0],scaling_matrix4[0]); // Intra, Cr
00256         decode_scaling_list(h,scaling_matrix4[2],16,default_scaling4[0],scaling_matrix4[1]); // Intra, Cb
00257         decode_scaling_list(h,scaling_matrix4[3],16,default_scaling4[1],fallback[1]); // Inter, Y
00258         decode_scaling_list(h,scaling_matrix4[4],16,default_scaling4[1],scaling_matrix4[3]); // Inter, Cr
00259         decode_scaling_list(h,scaling_matrix4[5],16,default_scaling4[1],scaling_matrix4[4]); // Inter, Cb
00260         if(is_sps || pps->transform_8x8_mode){
00261             decode_scaling_list(h,scaling_matrix8[0],64,default_scaling8[0],fallback[2]);  // Intra, Y
00262             decode_scaling_list(h,scaling_matrix8[1],64,default_scaling8[1],fallback[3]);  // Inter, Y
00263         }
00264     }
00265 }
00266 
00267 int ff_h264_decode_seq_parameter_set(H264Context *h){
00268     MpegEncContext * const s = &h->s;
00269     int profile_idc, level_idc;
00270     unsigned int sps_id;
00271     int i;
00272     SPS *sps;
00273 
00274     profile_idc= get_bits(&s->gb, 8);
00275     get_bits1(&s->gb);   //constraint_set0_flag
00276     get_bits1(&s->gb);   //constraint_set1_flag
00277     get_bits1(&s->gb);   //constraint_set2_flag
00278     get_bits1(&s->gb);   //constraint_set3_flag
00279     get_bits(&s->gb, 4); // reserved
00280     level_idc= get_bits(&s->gb, 8);
00281     sps_id= get_ue_golomb_31(&s->gb);
00282 
00283     if(sps_id >= MAX_SPS_COUNT) {
00284         av_log(h->s.avctx, AV_LOG_ERROR, "sps_id (%d) out of range\n", sps_id);
00285         return -1;
00286     }
00287     sps= av_mallocz(sizeof(SPS));
00288     if(sps == NULL)
00289         return -1;
00290 
00291     sps->profile_idc= profile_idc;
00292     sps->level_idc= level_idc;
00293 
00294     memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4));
00295     memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8));
00296     sps->scaling_matrix_present = 0;
00297 
00298     if(sps->profile_idc >= 100){ //high profile
00299         sps->chroma_format_idc= get_ue_golomb_31(&s->gb);
00300         if(sps->chroma_format_idc == 3)
00301             sps->residual_color_transform_flag = get_bits1(&s->gb);
00302         sps->bit_depth_luma   = get_ue_golomb(&s->gb) + 8;
00303         sps->bit_depth_chroma = get_ue_golomb(&s->gb) + 8;
00304         sps->transform_bypass = get_bits1(&s->gb);
00305         decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8);
00306     }else{
00307         sps->chroma_format_idc= 1;
00308         sps->bit_depth_luma   = 8;
00309         sps->bit_depth_chroma = 8;
00310     }
00311 
00312     sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4;
00313     sps->poc_type= get_ue_golomb_31(&s->gb);
00314 
00315     if(sps->poc_type == 0){ //FIXME #define
00316         sps->log2_max_poc_lsb= get_ue_golomb(&s->gb) + 4;
00317     } else if(sps->poc_type == 1){//FIXME #define
00318         sps->delta_pic_order_always_zero_flag= get_bits1(&s->gb);
00319         sps->offset_for_non_ref_pic= get_se_golomb(&s->gb);
00320         sps->offset_for_top_to_bottom_field= get_se_golomb(&s->gb);
00321         sps->poc_cycle_length                = get_ue_golomb(&s->gb);
00322 
00323         if((unsigned)sps->poc_cycle_length >= FF_ARRAY_ELEMS(sps->offset_for_ref_frame)){
00324             av_log(h->s.avctx, AV_LOG_ERROR, "poc_cycle_length overflow %u\n", sps->poc_cycle_length);
00325             goto fail;
00326         }
00327 
00328         for(i=0; i<sps->poc_cycle_length; i++)
00329             sps->offset_for_ref_frame[i]= get_se_golomb(&s->gb);
00330     }else if(sps->poc_type != 2){
00331         av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type);
00332         goto fail;
00333     }
00334 
00335     sps->ref_frame_count= get_ue_golomb_31(&s->gb);
00336     if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count >= 32U){
00337         av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n");
00338         goto fail;
00339     }
00340     sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb);
00341     sps->mb_width = get_ue_golomb(&s->gb) + 1;
00342     sps->mb_height= get_ue_golomb(&s->gb) + 1;
00343     if((unsigned)sps->mb_width >= INT_MAX/16 || (unsigned)sps->mb_height >= INT_MAX/16 ||
00344        avcodec_check_dimensions(NULL, 16*sps->mb_width, 16*sps->mb_height)){
00345         av_log(h->s.avctx, AV_LOG_ERROR, "mb_width/height overflow\n");
00346         goto fail;
00347     }
00348 
00349     sps->frame_mbs_only_flag= get_bits1(&s->gb);
00350     if(!sps->frame_mbs_only_flag)
00351         sps->mb_aff= get_bits1(&s->gb);
00352     else
00353         sps->mb_aff= 0;
00354 
00355     sps->direct_8x8_inference_flag= get_bits1(&s->gb);
00356     if(!sps->frame_mbs_only_flag && !sps->direct_8x8_inference_flag){
00357         av_log(h->s.avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n");
00358         goto fail;
00359     }
00360 
00361 #ifndef ALLOW_INTERLACE
00362     if(sps->mb_aff)
00363         av_log(h->s.avctx, AV_LOG_ERROR, "MBAFF support not included; enable it at compile-time.\n");
00364 #endif
00365     sps->crop= get_bits1(&s->gb);
00366     if(sps->crop){
00367         sps->crop_left  = get_ue_golomb(&s->gb);
00368         sps->crop_right = get_ue_golomb(&s->gb);
00369         sps->crop_top   = get_ue_golomb(&s->gb);
00370         sps->crop_bottom= get_ue_golomb(&s->gb);
00371         if(sps->crop_left || sps->crop_top){
00372             av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completely supported, this could look slightly wrong ...\n");
00373         }
00374         if(sps->crop_right >= 8 || sps->crop_bottom >= (8>> !sps->frame_mbs_only_flag)){
00375             av_log(h->s.avctx, AV_LOG_ERROR, "brainfart cropping not supported, this could look slightly wrong ...\n");
00376         }
00377     }else{
00378         sps->crop_left  =
00379         sps->crop_right =
00380         sps->crop_top   =
00381         sps->crop_bottom= 0;
00382     }
00383 
00384     sps->vui_parameters_present_flag= get_bits1(&s->gb);
00385     if( sps->vui_parameters_present_flag )
00386         if (decode_vui_parameters(h, sps) < 0)
00387             goto fail;
00388 
00389     if(s->avctx->debug&FF_DEBUG_PICT_INFO){
00390         av_log(h->s.avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s %d/%d\n",
00391                sps_id, sps->profile_idc, sps->level_idc,
00392                sps->poc_type,
00393                sps->ref_frame_count,
00394                sps->mb_width, sps->mb_height,
00395                sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"),
00396                sps->direct_8x8_inference_flag ? "8B8" : "",
00397                sps->crop_left, sps->crop_right,
00398                sps->crop_top, sps->crop_bottom,
00399                sps->vui_parameters_present_flag ? "VUI" : "",
00400                ((const char*[]){"Gray","420","422","444"})[sps->chroma_format_idc],
00401                sps->timing_info_present_flag ? sps->num_units_in_tick : 0,
00402                sps->timing_info_present_flag ? sps->time_scale : 0
00403                );
00404     }
00405 
00406     av_free(h->sps_buffers[sps_id]);
00407     h->sps_buffers[sps_id]= sps;
00408     h->sps = *sps;
00409     return 0;
00410 fail:
00411     av_free(sps);
00412     return -1;
00413 }
00414 
00415 static void
00416 build_qp_table(PPS *pps, int t, int index)
00417 {
00418     int i;
00419     for(i = 0; i < 52; i++)
00420         pps->chroma_qp_table[t][i] = ff_h264_chroma_qp[av_clip(i + index, 0, 51)];
00421 }
00422 
00423 int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){
00424     MpegEncContext * const s = &h->s;
00425     unsigned int pps_id= get_ue_golomb(&s->gb);
00426     PPS *pps;
00427 
00428     if(pps_id >= MAX_PPS_COUNT) {
00429         av_log(h->s.avctx, AV_LOG_ERROR, "pps_id (%d) out of range\n", pps_id);
00430         return -1;
00431     }
00432 
00433     pps= av_mallocz(sizeof(PPS));
00434     if(pps == NULL)
00435         return -1;
00436     pps->sps_id= get_ue_golomb_31(&s->gb);
00437     if((unsigned)pps->sps_id>=MAX_SPS_COUNT || h->sps_buffers[pps->sps_id] == NULL){
00438         av_log(h->s.avctx, AV_LOG_ERROR, "sps_id out of range\n");
00439         goto fail;
00440     }
00441 
00442     pps->cabac= get_bits1(&s->gb);
00443     pps->pic_order_present= get_bits1(&s->gb);
00444     pps->slice_group_count= get_ue_golomb(&s->gb) + 1;
00445     if(pps->slice_group_count > 1 ){
00446         pps->mb_slice_group_map_type= get_ue_golomb(&s->gb);
00447         av_log(h->s.avctx, AV_LOG_ERROR, "FMO not supported\n");
00448         switch(pps->mb_slice_group_map_type){
00449         case 0:
00450 #if 0
00451 |   for( i = 0; i <= num_slice_groups_minus1; i++ ) |   |        |
00452 |    run_length[ i ]                                |1  |ue(v)   |
00453 #endif
00454             break;
00455         case 2:
00456 #if 0
00457 |   for( i = 0; i < num_slice_groups_minus1; i++ )  |   |        |
00458 |{                                                  |   |        |
00459 |    top_left_mb[ i ]                               |1  |ue(v)   |
00460 |    bottom_right_mb[ i ]                           |1  |ue(v)   |
00461 |   }                                               |   |        |
00462 #endif
00463             break;
00464         case 3:
00465         case 4:
00466         case 5:
00467 #if 0
00468 |   slice_group_change_direction_flag               |1  |u(1)    |
00469 |   slice_group_change_rate_minus1                  |1  |ue(v)   |
00470 #endif
00471             break;
00472         case 6:
00473 #if 0
00474 |   slice_group_id_cnt_minus1                       |1  |ue(v)   |
00475 |   for( i = 0; i <= slice_group_id_cnt_minus1; i++ |   |        |
00476 |)                                                  |   |        |
00477 |    slice_group_id[ i ]                            |1  |u(v)    |
00478 #endif
00479             break;
00480         }
00481     }
00482     pps->ref_count[0]= get_ue_golomb(&s->gb) + 1;
00483     pps->ref_count[1]= get_ue_golomb(&s->gb) + 1;
00484     if(pps->ref_count[0]-1 > 32-1 || pps->ref_count[1]-1 > 32-1){
00485         av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n");
00486         goto fail;
00487     }
00488 
00489     pps->weighted_pred= get_bits1(&s->gb);
00490     pps->weighted_bipred_idc= get_bits(&s->gb, 2);
00491     pps->init_qp= get_se_golomb(&s->gb) + 26;
00492     pps->init_qs= get_se_golomb(&s->gb) + 26;
00493     pps->chroma_qp_index_offset[0]= get_se_golomb(&s->gb);
00494     pps->deblocking_filter_parameters_present= get_bits1(&s->gb);
00495     pps->constrained_intra_pred= get_bits1(&s->gb);
00496     pps->redundant_pic_cnt_present = get_bits1(&s->gb);
00497 
00498     pps->transform_8x8_mode= 0;
00499     h->dequant_coeff_pps= -1; //contents of sps/pps can change even if id doesn't, so reinit
00500     memcpy(pps->scaling_matrix4, h->sps_buffers[pps->sps_id]->scaling_matrix4, sizeof(pps->scaling_matrix4));
00501     memcpy(pps->scaling_matrix8, h->sps_buffers[pps->sps_id]->scaling_matrix8, sizeof(pps->scaling_matrix8));
00502 
00503     if(get_bits_count(&s->gb) < bit_length){
00504         pps->transform_8x8_mode= get_bits1(&s->gb);
00505         decode_scaling_matrices(h, h->sps_buffers[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8);
00506         pps->chroma_qp_index_offset[1]= get_se_golomb(&s->gb); //second_chroma_qp_index_offset
00507     } else {
00508         pps->chroma_qp_index_offset[1]= pps->chroma_qp_index_offset[0];
00509     }
00510 
00511     build_qp_table(pps, 0, pps->chroma_qp_index_offset[0]);
00512     build_qp_table(pps, 1, pps->chroma_qp_index_offset[1]);
00513     if(pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1])
00514         pps->chroma_qp_diff= 1;
00515 
00516     if(s->avctx->debug&FF_DEBUG_PICT_INFO){
00517         av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d/%d %s %s %s %s\n",
00518                pps_id, pps->sps_id,
00519                pps->cabac ? "CABAC" : "CAVLC",
00520                pps->slice_group_count,
00521                pps->ref_count[0], pps->ref_count[1],
00522                pps->weighted_pred ? "weighted" : "",
00523                pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset[0], pps->chroma_qp_index_offset[1],
00524                pps->deblocking_filter_parameters_present ? "LPAR" : "",
00525                pps->constrained_intra_pred ? "CONSTR" : "",
00526                pps->redundant_pic_cnt_present ? "REDU" : "",
00527                pps->transform_8x8_mode ? "8x8DCT" : ""
00528                );
00529     }
00530 
00531     av_free(h->pps_buffers[pps_id]);
00532     h->pps_buffers[pps_id]= pps;
00533     return 0;
00534 fail:
00535     av_free(pps);
00536     return -1;
00537 }

Generated on Fri Sep 16 2011 17:17:37 for FFmpeg by  doxygen 1.7.1