织梦CMS - 轻松建站从此开始!

罗索

H264参数语法文档: SPS、PPS、IDR

落鹤生 发布于 2011-10-28 16:47 点击:次 
H.264码流 SPS(序列参数集Sequence Parameter Set), PPS, IDR等解析
TAG:

H.264码流第一个 NALU 是 SPS(序列参数集Sequence Parameter Set)
对应H264标准文档 7.3.2.1 序列参数集的语法进行解析

SPS参数解析// fill sps with content of p

  1. int InterpretSPS (VideoParameters *p_Vid, DataPartition *p
  2. , seq_parameter_set_rbsp_t *sps) 
  3.   unsigned i; 
  4.   unsigned n_ScalingList; 
  5.   int reserved_zero; 
  6.   Bitstream *s = p->bitstream; 
  7.  
  8.   assert (p != NULL); 
  9.   assert (p->bitstream != NULL); 
  10.   assert (p->bitstream->streamBuffer != 0); 
  11.   assert (sps != NULL); 
  12.  
  13.   p_Dec->UsedBits = 0; 
  14.  
  15.   sps->profile_idc = u_v  (8, "SPS: profile_idc", s); 
  16.  
  17.   if ((sps->profile_idc!=BASELINE       ) && 
  18.       (sps->profile_idc!=MAIN           ) && 
  19.       (sps->profile_idc!=EXTENDED       ) && 
  20.       (sps->profile_idc!=FREXT_HP       ) && 
  21.       (sps->profile_idc!=FREXT_Hi10P    ) && 
  22.       (sps->profile_idc!=FREXT_Hi422    ) && 
  23.       (sps->profile_idc!=FREXT_Hi444    ) && 
  24.       (sps->profile_idc!=FREXT_CAVLC444 ) 
  25. #if (MVC_EXTENSION_ENABLE) 
  26.       && (sps->profile_idc!=MVC_HIGH) 
  27.       && (sps->profile_idc!=STEREO_HIGH) 
  28. #endif 
  29.       ) 
  30.   { 
  31.     printf("Invalid Profile IDC (%d) encountered. /n", sps->profile_idc); 
  32.     return p_Dec->UsedBits; 
  33.   } 
  34.  
  35.   sps->constrained_set0_flag = u_1("SPS: constrained_set0_flag", s); 
  36.   sps->constrained_set1_flag = u_1("SPS: constrained_set1_flag", s); 
  37.   sps->constrained_set2_flag = u_1("SPS: constrained_set2_flag", s); 
  38.   sps->constrained_set3_flag = u_1("SPS: constrained_set3_flag", s); 
  39. #if (MVC_EXTENSION_ENABLE) 
  40.   sps->constrained_set4_flag = u_1("SPS: constrained_set4_flag", s); 
  41.   reserved_zero = u_v(3, "SPS: reserved_zero_3bits", s); 
  42. #else 
  43.   reserved_zero = u_v(4, "SPS: reserved_zero_4bits", s); 
  44. #endif 
  45.   assert (reserved_zero==0); 
  46.  
  47.   sps->level_idc = u_v(8, "SPS: level_idc", s); 
  48.  
  49.   sps->seq_parameter_set_id = ue_v("SPS: seq_parameter_set_id", s); 
  50.  
  51.   // Fidelity Range Extensions stuff 
  52.   sps->chroma_format_idc = 1; 
  53.   sps->bit_depth_luma_minus8   = 0; 
  54.   sps->bit_depth_chroma_minus8 = 0; 
  55.   p_Vid->lossless_qpprime_flag   = 0; 
  56.   sps->separate_colour_plane_flag = 0; 
  57.  
  58.   if((sps->profile_idc==FREXT_HP   ) || 
  59.      (sps->profile_idc==FREXT_Hi10P) || 
  60.      (sps->profile_idc==FREXT_Hi422) || 
  61.      (sps->profile_idc==FREXT_Hi444) || 
  62.      (sps->profile_idc==FREXT_CAVLC444) 
  63. #if (MVC_EXTENSION_ENABLE) 
  64.      || (sps->profile_idc==MVC_HIGH) 
  65.      || (sps->profile_idc==STEREO_HIGH) 
  66. #endif 
  67.      ) 
  68.   { 
  69.     sps->chroma_format_idc = ue_v ("SPS: chroma_format_idc", s); 
  70.  
  71.     if(sps->chroma_format_idc == YUV444) 
  72.     { 
  73.       sps->separate_colour_plane_flag= u_1("SPS: separate_colour_plane_flag", s); 
  74.     } 
  75.  
  76.     sps->bit_depth_luma_minus8= ue_v ("SPS: bit_depth_luma_minus8", s); 
  77.     sps->bit_depth_chroma_minus8= ue_v ("SPS: bit_depth_chroma_minus8", s); 
  78.     //checking; 
  79.     if((sps->bit_depth_luma_minus8+8 > sizeof(imgpel)*8)
  80. || (sps->bit_depth_chroma_minus8+8> sizeof(imgpel)*8)) 
  81.       error ("Source picture has higher bit depth than imgpel data type. 
  82. /nPlease recompile with larger data type for imgpel.", 500); 
  83.  
  84.     p_Vid->lossless_qpprime_flag = u_1("SPS: lossless_qpprime_y_zero_flag", s); 
  85.  
  86.     sps->seq_scaling_matrix_present_flag= u_1("SPS: seq_scaling_matrix_present_flag", s); 
  87.      
  88.     if(sps->seq_scaling_matrix_present_flag) 
  89.     { 
  90.       n_ScalingList = (sps->chroma_format_idc != YUV444) ? 8 : 12; 
  91.       for(i=0; iseq_scaling_list_present_flag[i]
  92. = u_1("SPS: seq_scaling_list_present_flag", s); 
  93.         if(sps->seq_scaling_list_present_flag[i]) 
  94.         { 
  95.           if(i<6)
  96. scaling_list="">ScalingList4x4[i], 16, &sps->UseDefaultScalingMatrix4x4Flag[i], s); 
  97.           else 
  98. Scaling_List(sps->ScalingList8x8[i-6], 64, &sps->UseDefaultScalingMatrix8x8Flag[i-6], s); 
  99.         } 
  100.       } 
  101.     } 
  102.   } 
  103.  
  104.   sps->log2_max_frame_num_minus4 = ue_v ("SPS: log2_max_frame_num_minus4", s); 
  105.   sps->pic_order_cnt_type = ue_v ("SPS: pic_order_cnt_type", s); 
  106.  
  107.   if (sps->pic_order_cnt_type == 0) 
  108.     sps->log2_max_pic_order_cnt_lsb_minus4
  109. = ue_v ("SPS: log2_max_pic_order_cnt_lsb_minus4", s); 
  110.   else if (sps->pic_order_cnt_type == 1) 
  111.   { 
  112.     sps->delta_pic_order_always_zero_flag
  113. = u_1  ("SPS: delta_pic_order_always_zero_flag", s); 
  114.     sps->offset_for_non_ref_pic= se_v ("SPS: offset_for_non_ref_pic", s); 
  115.     sps->offset_for_top_to_bottom_field
  116. = se_v ("SPS: offset_for_top_to_bottom_field", s); 
  117.     sps->num_ref_frames_in_pic_order_cnt_cycle
  118. = ue_v ("SPS: num_ref_frames_in_pic_order_cnt_cycle"  , s); 
  119.     for(i=0; inum_ref_frames_in_pic_order_cnt_cycle; i++) 
  120.       sps->offset_for_ref_frame[i] = se_v ("SPS: offset_for_ref_frame[i]", s); 
  121.   } 
  122.   sps->num_ref_frames
  123. = ue_v ("SPS: num_ref_frames"                         , s); 
  124.   sps->gaps_in_frame_num_value_allowed_flag 
  125. = u_1  ("SPS: gaps_in_frame_num_value_allowed_flag"   , s); 
  126.   sps->pic_width_in_mbs_minus1
  127. = ue_v ("SPS: pic_width_in_mbs_minus1"                , s); 
  128.   sps->pic_height_in_map_units_minus1
  129. = ue_v ("SPS: pic_height_in_map_units_minus1"         , s); 
  130.   sps->frame_mbs_only_flag
  131. = u_1  ("SPS: frame_mbs_only_flag"                    , s); 
  132.   if (!sps->frame_mbs_only_flag) 
  133.   { 
  134.     sps->mb_adaptive_frame_field_flag
  135. = u_1  ("SPS: mb_adaptive_frame_field_flag"           , s); 
  136.   } 
  137.   sps->direct_8x8_inference_flag
  138. = u_1  ("SPS: direct_8x8_inference_flag"              , s); 
  139.   sps->frame_cropping_flag
  140. = u_1  ("SPS: frame_cropping_flag"                    , s); 
  141.  
  142.   if (sps->frame_cropping_flag) 
  143.   { 
  144.     sps->frame_cropping_rect_left_offset
  145. = ue_v ("SPS: frame_cropping_rect_left_offset"           , s); 
  146.     sps->frame_cropping_rect_right_offset
  147. = ue_v ("SPS: frame_cropping_rect_right_offset"          , s); 
  148.     sps->frame_cropping_rect_top_offset
  149. = ue_v ("SPS: frame_cropping_rect_top_offset"            , s); 
  150.     sps->frame_cropping_rect_bottom_offset
  151. = ue_v ("SPS: frame_cropping_rect_bottom_offset"         , s); 
  152.   } 
  153.   sps->vui_parameters_present_flag
  154. = (Boolean) u_1  ("SPS: vui_parameters_present_flag"      , s); 
  155.  
  156.   InitVUI(sps); 
  157.   ReadVUI(p, sps); 
  158.  
  159.   sps->Valid = TRUE; 
  160.   return p_Dec->UsedBits; 

H.264码流第二个 NALU 是 PPS(图像参数集Picture Parameter Set)
对应H264标准文档 7.3.2.2 序列参数集的语法进行解析

PPS参数解析

  1. int InterpretPPS (VideoParameters *p_Vid, DataPartition *p
  2. , pic_parameter_set_rbsp_t *pps) 
  3.   unsigned i; 
  4.   unsigned n_ScalingList; 
  5.   int chroma_format_idc; 
  6.   int NumberBitsPerSliceGroupId; 
  7.   Bitstream *s = p->bitstream; 
  8.  
  9.   assert (p != NULL); 
  10.   assert (p->bitstream != NULL); 
  11.   assert (p->bitstream->streamBuffer != 0); 
  12.   assert (pps != NULL); 
  13.  
  14.   p_Dec->UsedBits = 0; 
  15.  
  16.   pps->pic_parameter_set_id
  17. = ue_v ("PPS: pic_parameter_set_id"                   , s); 
  18.   pps->seq_parameter_set_id
  19. = ue_v ("PPS: seq_parameter_set_id"                   , s); 
  20.   pps->entropy_coding_mode_flag
  21. = u_1  ("PPS: entropy_coding_mode_flag"               , s); 
  22.  
  23.   //! Note: as per JVT-F078 the following bit is unconditional.  If F078 is not accepted, then 
  24.   //! one has to fetch the correct SPS to check whether the bit is present (hopefully there is 
  25.   //! no consistency problem :-( 
  26.   //! The current encoder code handles this in the same way.  When you change this, don't forget 
  27.   //! the encoder!  StW, 12/8/02 
  28.   pps->bottom_field_pic_order_in_frame_present_flag
  29. = u_1  ("PPS: bottom_field_pic_order_in_frame_present_flag"                 , s); 
  30.  
  31.   pps->num_slice_groups_minus1
  32. = ue_v ("PPS: num_slice_groups_minus1"                , s); 
  33.  
  34.   // FMO stuff begins here 
  35.   if (pps->num_slice_groups_minus1 > 0) 
  36.   { 
  37.     pps->slice_group_map_type
  38. = ue_v ("PPS: slice_group_map_type"                , s); 
  39.     if (pps->slice_group_map_type == 0) 
  40.     { 
  41.       for (i=0; i<=pps->num_slice_groups_minus1; i++) 
  42.         pps->run_length_minus1 [i]
  43. = ue_v ("PPS: run_length_minus1 [i]"              , s); 
  44.     } 
  45.     else if (pps->slice_group_map_type == 2) 
  46.     { 
  47.       for (i=0; inum_slice_groups_minus1; i++) 
  48.       { 
  49.         //! JVT-F078: avoid reference of SPS by using ue(v) instead of u(v) 
  50.         pps->top_left [i]
  51. = ue_v ("PPS: top_left [i]"                        , s); 
  52.         pps->bottom_right [i]
  53. = ue_v ("PPS: bottom_right [i]"                    , s); 
  54.       } 
  55.     } 
  56.     else if (pps->slice_group_map_type == 3 || 
  57.              pps->slice_group_map_type == 4 || 
  58.              pps->slice_group_map_type == 5) 
  59.     { 
  60.       pps->slice_group_change_direction_flag
  61. = u_1  ("PPS: slice_group_change_direction_flag"      , s); 
  62.       pps->slice_group_change_rate_minus1
  63. = ue_v ("PPS: slice_group_change_rate_minus1"         , s); 
  64.     } 
  65.     else if (pps->slice_group_map_type == 6) 
  66.     { 
  67.       if (pps->num_slice_groups_minus1+1 >4) 
  68.         NumberBitsPerSliceGroupId = 3; 
  69.       else if (pps->num_slice_groups_minus1+1 > 2) 
  70.         NumberBitsPerSliceGroupId = 2; 
  71.       else 
  72.         NumberBitsPerSliceGroupId = 1; 
  73.       pps->pic_size_in_map_units_minus1
  74. = ue_v ("PPS: pic_size_in_map_units_minus1"               , s); 
  75.       if ((pps->slice_group_id = calloc (pps->pic_size_in_map_units_minus1+1, 1)) == NULL) 
  76.         no_mem_exit ("InterpretPPS: slice_group_id"); 
  77.       for (i=0; i<=pps->pic_size_in_map_units_minus1; i++) 
  78.         pps->slice_group_id[i] = (byte) u_v (NumberBitsPerSliceGroupId, "slice_group_id[i]", s); 
  79.     } 
  80.   } 
  81.  
  82.   // End of FMO stuff 
  83.  
  84.   pps->num_ref_idx_l0_active_minus1
  85. = ue_v ("PPS: num_ref_idx_l0_active_minus1"           , s); 
  86.   pps->num_ref_idx_l1_active_minus1
  87. = ue_v ("PPS: num_ref_idx_l1_active_minus1"           , s); 
  88.   pps->weighted_pred_flag
  89. = u_1  ("PPS: weighted_pred_flag"                     , s); 
  90.   pps->weighted_bipred_idc
  91. = u_v  ( 2, "PPS: weighted_bipred_idc"                , s); 
  92.   pps->pic_init_qp_minus26 
  93. = se_v ("PPS: pic_init_qp_minus26"                    , s); 
  94.   pps->pic_init_qs_minus26
  95. = se_v ("PPS: pic_init_qs_minus26"                    , s); 
  96.  
  97.   pps->chroma_qp_index_offset
  98. = se_v ("PPS: chroma_qp_index_offset"                 , s); 
  99.  
  100.   pps->deblocking_filter_control_present_flag
  101. = u_1 ("PPS: deblocking_filter_control_present_flag" , s); 
  102.   pps->constrained_intra_pred_flag
  103. = u_1  ("PPS: constrained_intra_pred_flag"            , s); 
  104.   pps->redundant_pic_cnt_present_flag
  105. = u_1  ("PPS: redundant_pic_cnt_present_flag"         , s); 
  106.  
  107.   if(more_rbsp_data(s->streamBuffer, s->frame_bitoffset,s->bitstream_length)) // more_data_in_rbsp() 
  108.   { 
  109.     //Fidelity Range Extensions Stuff 
  110.     pps->transform_8x8_mode_flag
  111. = u_1  ("PPS: transform_8x8_mode_flag"                , s); 
  112.     pps->pic_scaling_matrix_present_flag
  113. =  u_1  ("PPS: pic_scaling_matrix_present_flag"        , s); 
  114.  
  115.     if(pps->pic_scaling_matrix_present_flag) 
  116.     { 
  117.       chroma_format_idc
  118. = p_Vid->SeqParSet[pps->seq_parameter_set_id].chroma_format_idc; 
  119.       n_ScalingList = 6 + 
  120. ((chroma_format_idc != YUV444) ? 2 : 6) * pps->transform_8x8_mode_flag; 
  121.       for(i=0; ipic_scaling_list_present_flag[i]
  122. = u_1  ("PPS: pic_scaling_list_present_flag"          , s); 
  123.  
  124.         if(pps->pic_scaling_list_present_flag[i]) 
  125.         { 
  126.           if(i<6)
  127. scaling_list="">ScalingList4x4[i], 16, &pps->UseDefaultScalingMatrix4x4Flag[i], s); 
  128.           else 
  129. Scaling_List(pps->ScalingList8x8[i-6], 64, &pps->UseDefaultScalingMatrix8x8Flag[i-6], s); 
  130.         } 
  131.       } 
  132.     } 
  133.     pps->second_chroma_qp_index_offset
  134. = se_v ("PPS: second_chroma_qp_index_offset"          , s); 
  135.   } 
  136.   else 
  137.   { 
  138.     pps->second_chroma_qp_index_offset
  139. = pps->chroma_qp_index_offset; 
  140.   } 
  141.  
  142.   pps->Valid = TRUE; 
  143.   return p_Dec->UsedBits; 

H.264码流第三个 NALU 是 IDR(即时解码器刷新)
对应H264标准文档 7.3.3 序列参数集的语法进行解析

IDR参数解析

  1. case NALU_TYPE_IDR: 
  2.         img->idr_flag = (nalu->nal_unit_type == NALU_TYPE_IDR); 
  3.         img->nal_reference_idc = nalu->nal_reference_idc; 
  4.         img->disposable_flag = (nalu->nal_reference_idc
  5. == NALU_PRIORITY_DISPOSABLE); 
  6.         currSlice->dp_mode = PAR_DP_1;
  7. //++ dp_mode:数据分割模式;PAR_DP_1=0:没有数据分割 
  8.         currSlice->max_part_nr = 1; 
  9.         currSlice->ei_flag = 0;
  10. //++ 该处赋值直接影响decode_slice()函数中对decode_one_slice()函数的调用 
  11. //++ 该值不为0,表明当前片出错,解码程序将忽略当前片的解码过程,而使用错误隐藏 
  12.         currStream = currSlice->partArr[0].bitstream; 
  13.         currStream->ei_flag = 0;
  14. //++ 此处的赋值为最终赋值,以后不再改变。该值将对每个宏块的ei_flag产生影响 
  15. //++ 参见macroblock.c文件read_one_macroblock()函数的如下语句: 
  16. //++        :if(!dP->bitstream->ei_flag)        :currMB->ei_flag = 0; 
  17. //++ 该值还在macroblock.c文件if(IS_INTRA (currMB)
  18. // && dP->bitstream->ei_flag && img->number)中用到 
  19.         currStream->frame_bitoffset = currStream->read_len = 0; 
  20.         memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1); 
  21.         currStream->code_len = currStream->bitstream_length
  22. = RBSPtoSODB(currStream->streamBuffer, nalu->len-1); 
  23.  
  24. // Some syntax of the Slice Header depends on the parameter set, which depends on 
  25. // the parameter set ID of the SLice header.  Hence, read the pic_parameter_set_id 
  26. // of the slice header first, then setup the active parameter sets, and then read 
  27. // the rest of the slice header 
  28.         BitsUsedByHeader = FirstPartOfSliceHeader();    //++ 参见标准7.3.3 
  29.         UseParameterSet (currSlice->pic_parameter_set_id); 
  30.         BitsUsedByHeader+= RestOfSliceHeader ();    //++ 参见标准7.3.3 
  31. //++ BitsUsedByHeader在程序中没有实际用处,而且BitsUsedByHeader+= RestOfSliceHeader () 
  32. //++ 重复计算了FirstPartOfSliceHeader()所用到的比特数。因为在FirstPartOfSliceHeader() 
  33. //++ 之后,变量UsedBits值并未被置零就代入RestOfSliceHeader()运算,从而RestOfSliceHeader () 
  34. //++ 在返回时,BitsUsedByHeader+= RestOfSliceHeader()多加了一个BitsUsedByHeader值 
  35.  
  36.         FmoInit (active_pps, active_sps); 
  37.  
  38.         if(is_new_picture()) 
  39.         { 
  40.           init_picture(img, input); 
  41.            
  42.           current_header = SOP; 
  43.           //check zero_byte if it is also the first NAL unit in the access unit 
  44.           CheckZeroByteVCL(nalu, &ret); 
  45.         } 
  46.         else 
  47.           current_header = SOS; 
  48.    
  49.         init_lists(img->type, img->currentSlice->structure); 
  50.         reorder_lists (img->type, img->currentSlice); 
  51.  
  52.         if (img->structure==FRAME) 
  53.         { 
  54.           init_mbaff_lists(); 
  55.         } 
  56.  
  57. /*        if (img->frame_num==1) // write a reference list 
  58.         { 
  59.           count ++; 
  60.           if (count==1) 
  61.             for (i=0; i 
  62.  
  63. // From here on, active_sps, active_pps and the slice header are valid 
  64.         if (img->MbaffFrameFlag) 
  65. img->current_mb_nr = currSlice->start_mb_nr << 1="" style="color: #0000ff">else 
  66. img->current_mb_nr = currSlice->start_mb_nr; 
  67.  
  68.         if (active_pps->entropy_coding_mode_flag) 
  69.         { 
  70.           int ByteStartPosition = currStream->frame_bitoffset/8; 
  71.           if (currStream->frame_bitoffset%8 != 0)  
  72.           { 
  73.             ByteStartPosition++; 
  74.           } 
  75. arideco_start_decoding (&currSlice->partArr[0].de_cabac, currStream->streamBuffer
  76. , ByteStartPosition, &currStream->read_len, img->type); 
  77.         } 
  78. // printf ("read_new_slice: returning %s/n", current_header == SOP?"SOP":"SOS"); 
  79.         FreeNALU(nalu); 
  80.         return current_header; 
  81.         break; 
  82.       case NALU_TYPE_DPA: 
  83. //! The state machine here should follow the same ideas as the old readSliceRTP() 
  84. //! basically: 
  85. //! work on DPA (as above) 
  86. //! read and process all following SEI/SPS/PPS/PD/Filler NALUs 
  87. //! if next video NALU is dpB,  
  88. //!   then read and check whether it belongs to DPA, if yes, use it 
  89. //! else 
  90. //!   ;   // nothing 
  91. //! read and process all following SEI/SPS/PPS/PD/Filler NALUs 
  92. //! if next video NALU is dpC 
  93. //!   then read and check whether it belongs to DPA (and DPB, if present), if yes, use it, done 
  94. //! else 
  95. //!   use the DPA (and the DPB if present) 
  96.  
  97. /*  
  98. LC: inserting the code related to DP processing, mainly copying some of the parts 
  99. related to NALU_TYPE_SLICE, NALU_TYPE_IDR. 
  100. */ 
  101.  
  102.         if(expected_slice_type != NALU_TYPE_DPA) 
  103.         { 
  104.           /* oops... we found the next slice, go back! */ 
  105.           fseek(bits, ftell_position, SEEK_SET); 
  106.           FreeNALU(nalu); 
  107.           return current_header; 
  108.         } 
  109.  
  110.         img->idr_flag          = (nalu->nal_unit_type == NALU_TYPE_IDR); 
  111.         img->nal_reference_idc = nalu->nal_reference_idc; 
  112.         img->disposable_flag   = (nalu->nal_reference_idc == NALU_PRIORITY_DISPOSABLE); 
  113.         currSlice->dp_mode     = PAR_DP_3; 
  114.         currSlice->max_part_nr = 3; 
  115.         currSlice->ei_flag     = 0; 
  116.         currStream             = currSlice->partArr[0].bitstream; 
  117.         currStream->ei_flag    = 0; 
  118.         currStream->frame_bitoffset = currStream->read_len = 0; 
  119.         memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1); 
  120.         currStream->code_len = currStream->bitstream_length
  121.  = RBSPtoSODB(currStream->streamBuffer, nalu->len-1);    //++ 剔除停止比特和填充比特 
  122.          
  123.         BitsUsedByHeader     = FirstPartOfSliceHeader(); 
  124.         UseParameterSet (currSlice->pic_parameter_set_id); 
  125.         BitsUsedByHeader    += RestOfSliceHeader (); 
  126.          
  127.         FmoInit (active_pps, active_sps); 
  128.  
  129.         if(is_new_picture()) 
  130.         { 
  131.           init_picture(img, input); 
  132.           current_header = SOP; 
  133.           CheckZeroByteVCL(nalu, &ret); 
  134.         } 
  135.         else 
  136.           current_header = SOS; 
  137.  
  138.          
  139.         init_lists(img->type, img->currentSlice->structure); 
  140.         reorder_lists (img->type, img->currentSlice); 
  141.          
  142.         if (img->structure==FRAME) 
  143.         { 
  144.           init_mbaff_lists(); 
  145.         } 
  146.  
  147.         // From here on, active_sps, active_pps and the slice header are valid 
  148.         if (img->MbaffFrameFlag) 
  149. img->current_mb_nr = currSlice->start_mb_nr << 1="" style="color: #0000ff">
  150. else 
  151. img->current_mb_nr = currSlice->start_mb_nr; 
  152.         /*  
  153.            LC: 
  154.               Now I need to read the slice ID, which depends on the value of  
  155.               redundant_pic_cnt_present_flag (pag.49).  
  156.         */ 
  157.  
  158.         slice_id_a  = ue_v("NALU:SLICE_A slice_idr", currStream); 
  159.         if (active_pps->entropy_coding_mode_flag) 
  160.         { 
  161.           int ByteStartPosition = currStream->frame_bitoffset/8; 
  162.           if (currStream->frame_bitoffset%8 != 0)  
  163.           { 
  164.             ByteStartPosition++; 
  165.           } 
  166.           arideco_start_decoding (&currSlice->partArr[0].de_cabac
  167. , currStream->streamBuffer, ByteStartPosition, &currStream->read_len, img->type); 
  168.         } 
  169. // printf ("read_new_slice: returning %s/n", current_header == SOP?"SOP":"SOS"); 
  170.         break
  171.       case NALU_TYPE_DPB: 
  172.         /* LC: inserting the code related to DP processing */ 
  173.  
  174.         currStream             = currSlice->partArr[1].bitstream; 
  175.         currStream->ei_flag    = 0; 
  176.         currStream->frame_bitoffset = currStream->read_len = 0; 
  177.         memcpy (currStream->streamBuffer, &nalu->buf[1], nalu->len-1); 
  178.         currStream->code_len = currStream->bitstream_length
  179.  = RBSPtoSODB(currStream->streamBuffer, nalu->len-1); 
  180.  
  181.         slice_id_b  = ue_v("NALU:SLICE_B slice_idr", currStream); 
  182.         if (active_pps->redundant_pic_cnt_present_flag) 
  183.           redundant_pic_cnt_b = ue_v("NALU:SLICE_B redudand_pic_cnt", currStream); 
  184.         else 
  185.           redundant_pic_cnt_b = 0; 
  186.          
  187.         /*  LC: Initializing CABAC for the current data stream. */ 
  188.  
  189.         if (active_pps->entropy_coding_mode_flag) 
  190.         { 
  191.           int ByteStartPosition = currStream->frame_bitoffset/8; 
  192.           if (currStream->frame_bitoffset % 8 != 0)  
  193.             ByteStartPosition++; 
  194.            
  195.           arideco_start_decoding (&currSlice->partArr[1].de_cabac
  196. , currStream->streamBuffer,  
  197.             ByteStartPosition, &currStream->read_len, img->type); 
  198.            
  199.         } 
  200.  
  201.         /* LC: resilience code to be inserted */ 
  202.         /*         FreeNALU(nalu); */ 
  203.         /*         return current_header; */ 
  204.  
  205.         break

IDR参数解析

  1. /* /brief   
  2.  *    read the first part of the header (only the pic_parameter_set_id)   
  3.  * /return   
  4.  *    Length of the first part of the slice header (in bits)   
  5.  */   
  6. //++ 参见标准7.3.3   
  7. int FirstPartOfSliceHeader()   
  8. {   
  9.   Slice *currSlice = img->currentSlice;   
  10.   int dP_nr = assignSE2partition[currSlice->dp_mode][SE_HEADER];   
  11.   DataPartition *partition = &(currSlice->partArr[dP_nr]);   
  12.   Bitstream *currStream = partition->bitstream;   
  13.   int tmp;   
  14.    
  15.   UsedBits= partition->bitstream->frame_bitoffset;
  16. // was hardcoded to 31 for previous start-code. This is better.   
  17.    
  18.   // Get first_mb_in_slice   
  19.   currSlice->start_mb_nr = ue_v ("SH: first_mb_in_slice", currStream);   
  20.    
  21.   tmp = ue_v ("SH: slice_type", currStream);   
  22.      
  23.   if (tmp>4) tmp -=5;   
  24.    
  25.   img->type = currSlice->picture_type = (SliceType) tmp;   
  26.    
  27.   currSlice->pic_parameter_set_id = ue_v ("SH: pic_parameter_set_id", currStream);   
  28.      
  29.   return UsedBits;   
  30. }   

 

(heanyu)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201110/15236.html]
本文出处:blog.csdn.net/heanyu 作者:heanyu
顶一下
(3)
50%
踩一下
(3)
50%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容