Libav
|
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 av_log(h->s.avctx, AV_LOG_ERROR, "chroma_format_idc (%u) out of range\n", sps->chroma_format_idc); 00302 return -1; 00303 } else if(sps->chroma_format_idc == 3) { 00304 sps->residual_color_transform_flag = get_bits1(&s->gb); 00305 } 00306 sps->bit_depth_luma = get_ue_golomb(&s->gb) + 8; 00307 sps->bit_depth_chroma = get_ue_golomb(&s->gb) + 8; 00308 sps->transform_bypass = get_bits1(&s->gb); 00309 decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8); 00310 }else{ 00311 sps->chroma_format_idc= 1; 00312 sps->bit_depth_luma = 8; 00313 sps->bit_depth_chroma = 8; 00314 } 00315 00316 sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4; 00317 sps->poc_type= get_ue_golomb_31(&s->gb); 00318 00319 if(sps->poc_type == 0){ //FIXME #define 00320 sps->log2_max_poc_lsb= get_ue_golomb(&s->gb) + 4; 00321 } else if(sps->poc_type == 1){//FIXME #define 00322 sps->delta_pic_order_always_zero_flag= get_bits1(&s->gb); 00323 sps->offset_for_non_ref_pic= get_se_golomb(&s->gb); 00324 sps->offset_for_top_to_bottom_field= get_se_golomb(&s->gb); 00325 sps->poc_cycle_length = get_ue_golomb(&s->gb); 00326 00327 if((unsigned)sps->poc_cycle_length >= FF_ARRAY_ELEMS(sps->offset_for_ref_frame)){ 00328 av_log(h->s.avctx, AV_LOG_ERROR, "poc_cycle_length overflow %u\n", sps->poc_cycle_length); 00329 goto fail; 00330 } 00331 00332 for(i=0; i<sps->poc_cycle_length; i++) 00333 sps->offset_for_ref_frame[i]= get_se_golomb(&s->gb); 00334 }else if(sps->poc_type != 2){ 00335 av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); 00336 goto fail; 00337 } 00338 00339 sps->ref_frame_count= get_ue_golomb_31(&s->gb); 00340 if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count >= 32U){ 00341 av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n"); 00342 goto fail; 00343 } 00344 sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb); 00345 sps->mb_width = get_ue_golomb(&s->gb) + 1; 00346 sps->mb_height= get_ue_golomb(&s->gb) + 1; 00347 if((unsigned)sps->mb_width >= INT_MAX/16 || (unsigned)sps->mb_height >= INT_MAX/16 || 00348 avcodec_check_dimensions(NULL, 16*sps->mb_width, 16*sps->mb_height)){ 00349 av_log(h->s.avctx, AV_LOG_ERROR, "mb_width/height overflow\n"); 00350 goto fail; 00351 } 00352 00353 sps->frame_mbs_only_flag= get_bits1(&s->gb); 00354 if(!sps->frame_mbs_only_flag) 00355 sps->mb_aff= get_bits1(&s->gb); 00356 else 00357 sps->mb_aff= 0; 00358 00359 sps->direct_8x8_inference_flag= get_bits1(&s->gb); 00360 if(!sps->frame_mbs_only_flag && !sps->direct_8x8_inference_flag){ 00361 av_log(h->s.avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n"); 00362 goto fail; 00363 } 00364 00365 #ifndef ALLOW_INTERLACE 00366 if(sps->mb_aff) 00367 av_log(h->s.avctx, AV_LOG_ERROR, "MBAFF support not included; enable it at compile-time.\n"); 00368 #endif 00369 sps->crop= get_bits1(&s->gb); 00370 if(sps->crop){ 00371 sps->crop_left = get_ue_golomb(&s->gb); 00372 sps->crop_right = get_ue_golomb(&s->gb); 00373 sps->crop_top = get_ue_golomb(&s->gb); 00374 sps->crop_bottom= get_ue_golomb(&s->gb); 00375 if(sps->crop_left || sps->crop_top){ 00376 av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completely supported, this could look slightly wrong ...\n"); 00377 } 00378 if(sps->crop_right >= 8 || sps->crop_bottom >= (8>> !sps->frame_mbs_only_flag)){ 00379 av_log(h->s.avctx, AV_LOG_ERROR, "brainfart cropping not supported, this could look slightly wrong ...\n"); 00380 } 00381 }else{ 00382 sps->crop_left = 00383 sps->crop_right = 00384 sps->crop_top = 00385 sps->crop_bottom= 0; 00386 } 00387 00388 sps->vui_parameters_present_flag= get_bits1(&s->gb); 00389 if( sps->vui_parameters_present_flag ) 00390 if (decode_vui_parameters(h, sps) < 0) 00391 goto fail; 00392 00393 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ 00394 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", 00395 sps_id, sps->profile_idc, sps->level_idc, 00396 sps->poc_type, 00397 sps->ref_frame_count, 00398 sps->mb_width, sps->mb_height, 00399 sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"), 00400 sps->direct_8x8_inference_flag ? "8B8" : "", 00401 sps->crop_left, sps->crop_right, 00402 sps->crop_top, sps->crop_bottom, 00403 sps->vui_parameters_present_flag ? "VUI" : "", 00404 ((const char*[]){"Gray","420","422","444"})[sps->chroma_format_idc], 00405 sps->timing_info_present_flag ? sps->num_units_in_tick : 0, 00406 sps->timing_info_present_flag ? sps->time_scale : 0 00407 ); 00408 } 00409 00410 av_free(h->sps_buffers[sps_id]); 00411 h->sps_buffers[sps_id]= sps; 00412 h->sps = *sps; 00413 return 0; 00414 fail: 00415 av_free(sps); 00416 return -1; 00417 } 00418 00419 static void 00420 build_qp_table(PPS *pps, int t, int index) 00421 { 00422 int i; 00423 for(i = 0; i < 52; i++) 00424 pps->chroma_qp_table[t][i] = ff_h264_chroma_qp[av_clip(i + index, 0, 51)]; 00425 } 00426 00427 int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){ 00428 MpegEncContext * const s = &h->s; 00429 unsigned int pps_id= get_ue_golomb(&s->gb); 00430 PPS *pps; 00431 00432 if(pps_id >= MAX_PPS_COUNT) { 00433 av_log(h->s.avctx, AV_LOG_ERROR, "pps_id (%d) out of range\n", pps_id); 00434 return -1; 00435 } 00436 00437 pps= av_mallocz(sizeof(PPS)); 00438 if(pps == NULL) 00439 return -1; 00440 pps->sps_id= get_ue_golomb_31(&s->gb); 00441 if((unsigned)pps->sps_id>=MAX_SPS_COUNT || h->sps_buffers[pps->sps_id] == NULL){ 00442 av_log(h->s.avctx, AV_LOG_ERROR, "sps_id out of range\n"); 00443 goto fail; 00444 } 00445 00446 pps->cabac= get_bits1(&s->gb); 00447 pps->pic_order_present= get_bits1(&s->gb); 00448 pps->slice_group_count= get_ue_golomb(&s->gb) + 1; 00449 if(pps->slice_group_count > 1 ){ 00450 pps->mb_slice_group_map_type= get_ue_golomb(&s->gb); 00451 av_log(h->s.avctx, AV_LOG_ERROR, "FMO not supported\n"); 00452 switch(pps->mb_slice_group_map_type){ 00453 case 0: 00454 #if 0 00455 | for( i = 0; i <= num_slice_groups_minus1; i++ ) | | | 00456 | run_length[ i ] |1 |ue(v) | 00457 #endif 00458 break; 00459 case 2: 00460 #if 0 00461 | for( i = 0; i < num_slice_groups_minus1; i++ ) | | | 00462 |{ | | | 00463 | top_left_mb[ i ] |1 |ue(v) | 00464 | bottom_right_mb[ i ] |1 |ue(v) | 00465 | } | | | 00466 #endif 00467 break; 00468 case 3: 00469 case 4: 00470 case 5: 00471 #if 0 00472 | slice_group_change_direction_flag |1 |u(1) | 00473 | slice_group_change_rate_minus1 |1 |ue(v) | 00474 #endif 00475 break; 00476 case 6: 00477 #if 0 00478 | slice_group_id_cnt_minus1 |1 |ue(v) | 00479 | for( i = 0; i <= slice_group_id_cnt_minus1; i++ | | | 00480 |) | | | 00481 | slice_group_id[ i ] |1 |u(v) | 00482 #endif 00483 break; 00484 } 00485 } 00486 pps->ref_count[0]= get_ue_golomb(&s->gb) + 1; 00487 pps->ref_count[1]= get_ue_golomb(&s->gb) + 1; 00488 if(pps->ref_count[0]-1 > 32-1 || pps->ref_count[1]-1 > 32-1){ 00489 av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); 00490 goto fail; 00491 } 00492 00493 pps->weighted_pred= get_bits1(&s->gb); 00494 pps->weighted_bipred_idc= get_bits(&s->gb, 2); 00495 pps->init_qp= get_se_golomb(&s->gb) + 26; 00496 pps->init_qs= get_se_golomb(&s->gb) + 26; 00497 pps->chroma_qp_index_offset[0]= get_se_golomb(&s->gb); 00498 pps->deblocking_filter_parameters_present= get_bits1(&s->gb); 00499 pps->constrained_intra_pred= get_bits1(&s->gb); 00500 pps->redundant_pic_cnt_present = get_bits1(&s->gb); 00501 00502 pps->transform_8x8_mode= 0; 00503 h->dequant_coeff_pps= -1; //contents of sps/pps can change even if id doesn't, so reinit 00504 memcpy(pps->scaling_matrix4, h->sps_buffers[pps->sps_id]->scaling_matrix4, sizeof(pps->scaling_matrix4)); 00505 memcpy(pps->scaling_matrix8, h->sps_buffers[pps->sps_id]->scaling_matrix8, sizeof(pps->scaling_matrix8)); 00506 00507 if(get_bits_count(&s->gb) < bit_length){ 00508 pps->transform_8x8_mode= get_bits1(&s->gb); 00509 decode_scaling_matrices(h, h->sps_buffers[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8); 00510 pps->chroma_qp_index_offset[1]= get_se_golomb(&s->gb); //second_chroma_qp_index_offset 00511 } else { 00512 pps->chroma_qp_index_offset[1]= pps->chroma_qp_index_offset[0]; 00513 } 00514 00515 build_qp_table(pps, 0, pps->chroma_qp_index_offset[0]); 00516 build_qp_table(pps, 1, pps->chroma_qp_index_offset[1]); 00517 if(pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1]) 00518 pps->chroma_qp_diff= 1; 00519 00520 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ 00521 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", 00522 pps_id, pps->sps_id, 00523 pps->cabac ? "CABAC" : "CAVLC", 00524 pps->slice_group_count, 00525 pps->ref_count[0], pps->ref_count[1], 00526 pps->weighted_pred ? "weighted" : "", 00527 pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset[0], pps->chroma_qp_index_offset[1], 00528 pps->deblocking_filter_parameters_present ? "LPAR" : "", 00529 pps->constrained_intra_pred ? "CONSTR" : "", 00530 pps->redundant_pic_cnt_present ? "REDU" : "", 00531 pps->transform_8x8_mode ? "8x8DCT" : "" 00532 ); 00533 } 00534 00535 av_free(h->pps_buffers[pps_id]); 00536 h->pps_buffers[pps_id]= pps; 00537 return 0; 00538 fail: 00539 av_free(pps); 00540 return -1; 00541 }