18 #include "scanner/util/common.h"    30       ((*(gb.buffer + (gb.offset >> 0x3))) >> (0x7 - (gb.offset & 0x7))) & 0x1;
    37   for (i32 i = bits - 1; i >= 0; i--) {
    38     v |= get_bit(gb) << i;
    46   while (0 == get_bit(gb)) {
    51   u32 info = 1 << zeros;
    53   for (i32 i = zeros - 1; i >= 0; i--) {
    54     info |= get_bit(gb) << i;
    63   while (0 == get_bit(gb)) {
    68   u32 info = 1 << zeros;
    70   for (i32 i = zeros - 1; i >= 0; i--) {
    71     info |= get_bit(gb) << i;
    77 inline void next_nal(
const u8*& buffer, i32& buffer_size_left,
    78                      const u8*& nal_start, i32& nal_size) {
    80   while (buffer_size_left > 2) {
    81     if (buffer[0] == 0x00 && buffer[1] == 0x00 && buffer[2] == 0x01) {
    90   buffer_size_left -= 3;
    98   while (buffer_size_left > 2 &&
    99          !(buffer[0] == 0x00 && buffer[1] == 0x00 &&
   100            (buffer[2] == 0x00 || buffer[2] == 0x01))) {
   105   if (!(buffer_size_left > 3)) {
   106     nal_size += buffer_size_left;
   113 inline i32 get_nal_unit_type(
const u8* nal_start) {
   114   return (*nal_start) & 0x1F;
   117 inline i32 get_nal_ref_idc(
const u8* nal_start) { 
return (*nal_start >> 5); }
   119 inline bool is_vcl_nal(i32 nal_type) { 
return nal_type >= 1 && nal_type <= 5; }
   121 inline bool is_first_vcl_nal(i32 nal_type) {
   122   return nal_type >= 1 && nal_type <= 5;
   128   u32 log2_max_frame_num;
   130   u32 log2_max_pic_order_cnt_lsb;
   131   bool delta_pic_order_always_zero_flag;
   132   bool frame_mbs_only_flag;
   137   info.profile_idc = get_bits(gb, 8);
   149   info.sps_id = get_ue_golomb(gb);
   150   if (info.profile_idc == 100 ||  
   151       info.profile_idc == 110 ||  
   152       info.profile_idc == 122 ||  
   153       info.profile_idc == 244 ||  
   154       info.profile_idc == 44 ||   
   155       info.profile_idc == 83 ||   
   156       info.profile_idc == 86 ||   
   157       info.profile_idc == 118 ||  
   158       info.profile_idc == 128 ||  
   159       info.profile_idc == 138 ||  
   160       info.profile_idc == 139 || info.profile_idc == 134 ||
   161       info.profile_idc == 135 || info.profile_idc == 144) {
   163     u32 chroma_format_idc = get_ue_golomb(gb);
   164     if (chroma_format_idc > 3U) {
   165       LOG(WARNING) << 
"invalid chroma format idc " << chroma_format_idc;
   167     } 
else if (chroma_format_idc == 3) {
   169       bool residual_color_transform_flag = get_bit(gb);
   170       if (residual_color_transform_flag) {
   171         LOG(WARNING) << 
"separate color planes not supported";
   176     u32 bit_depth_luma = get_ue_golomb(gb) + 8;
   177     u32 bit_depth_chroma = get_ue_golomb(gb) + 8;
   178     if (bit_depth_chroma != bit_depth_luma) {
   179       LOG(WARNING) << 
"separate color planes not supported";
   182     if (bit_depth_luma < 8 || bit_depth_luma > 14 || bit_depth_chroma < 8 ||
   183         bit_depth_chroma > 14) {
   184       LOG(WARNING) << 
"illegal bit depth value: " << bit_depth_luma << 
", "   192       LOG(WARNING) << 
"scaling matrix not supported";
   196   VLOG(2) << 
"profile idc " << (i32)info.profile_idc;
   198   info.log2_max_frame_num = get_ue_golomb(gb) + 4;
   200   info.poc_type = get_ue_golomb(gb);
   201   switch (info.poc_type) {
   204       info.log2_max_pic_order_cnt_lsb = get_ue_golomb(gb) + 4;
   208       info.delta_pic_order_always_zero_flag = get_bit(gb);
   214       u32 num_ref_frames = get_ue_golomb(gb);
   215       for (u32 i = 0; i < num_ref_frames; i++) {
   224       LOG(WARNING) << 
"Illegal picture_order_count type: " << info.poc_type;
   237   info.frame_mbs_only_flag = get_bit(gb);
   245   bool pic_order_present_flag;
   246   bool redundant_pic_cnt_present_flag;
   247   u32 num_ref_idx_l0_default_active;
   248   u32 num_ref_idx_l1_default_active;
   249   bool weighted_pred_flag;
   250   u8 weighted_bipred_idc;
   255   info.pps_id = get_ue_golomb(gb);
   257   info.sps_id = get_ue_golomb(gb);
   259   bool entropy_coding_mode_flag = get_bit(gb);
   261   info.pic_order_present_flag = get_bit(gb);
   263   u32 num_slice_groups_minus1 = get_ue_golomb(gb);
   264   if (num_slice_groups_minus1 > 0) {
   266     u32 slice_group_map_type = get_ue_golomb(gb);
   268     LOG(WARNING) << 
"FMO encoded video not supported";
   272   info.num_ref_idx_l0_default_active = get_ue_golomb(gb) + 1;
   274   info.num_ref_idx_l1_default_active = get_ue_golomb(gb) + 1;
   276   info.weighted_pred_flag = get_bit(gb);
   278   info.weighted_bipred_idc = get_bits(gb, 2);
   280   u32 pic_init_qp_minus26 = get_se_golomb(gb);
   282   u32 pic_init_qs_minus26 = get_se_golomb(gb);
   284   u32 chroma_qp_index_offset = get_se_golomb(gb);
   290   info.redundant_pic_cnt_present_flag = get_bit(gb);
   304   bool bottom_field_flag;
   306   u32 pic_order_cnt_lsb;
   307   i32 delta_pic_order_cnt_bottom;
   308   u32 delta_pic_order_cnt[2];
   309   u32 redundant_pic_cnt;
   310   u32 num_ref_idx_l0_active;
   311   u32 num_ref_idx_l1_active;
   315                                std::map<u32, PPS>& pps_map, u32 nal_unit_type,
   317   info.nal_unit_type = nal_unit_type;
   318   info.nal_ref_idc = nal_ref_idc;
   322   info.slice_type = get_ue_golomb(gb);
   323   if (info.slice_type > 9) {
   324     LOG(WARNING) << 
"Slice type too long";
   327   info.sps_id = sps.sps_id;
   329   info.pps_id = get_ue_golomb(gb);
   330   PPS& pps = pps_map.at(info.pps_id);
   332   info.frame_num = get_bits(gb, sps.log2_max_frame_num);
   333   if (!sps.frame_mbs_only_flag) {
   335     info.field_pic_flag = get_bit(gb);
   337     info.bottom_field_flag = info.field_pic_flag ? get_bit(gb) : 0;
   339     info.field_pic_flag = 0;
   340     info.bottom_field_flag = -1;
   342   if (nal_unit_type == 5) {
   344     info.idr_pic_id = get_ue_golomb(gb);
   346   info.delta_pic_order_cnt_bottom = 0;
   347   if (sps.poc_type == 0) {
   349     info.pic_order_cnt_lsb = get_bits(gb, sps.log2_max_pic_order_cnt_lsb);
   351     if (pps.pic_order_present_flag == 1 && !info.field_pic_flag) {
   352       info.delta_pic_order_cnt_bottom = get_se_golomb(gb);
   355   info.delta_pic_order_cnt[0] = 0;
   356   info.delta_pic_order_cnt[1] = 0;
   357   if (sps.delta_pic_order_always_zero_flag) {
   358     info.delta_pic_order_cnt[0] = 0;
   359     info.delta_pic_order_cnt[1] = 0;
   360   } 
else if (sps.poc_type == 1) {
   361     info.delta_pic_order_cnt[0] = get_se_golomb(gb);
   362     if ((pps.pic_order_present_flag == 1) && !info.field_pic_flag) {
   363       info.delta_pic_order_cnt[1] = get_se_golomb(gb);
   365       info.delta_pic_order_cnt[1] = 0;
   368   info.redundant_pic_cnt =
   369       pps.redundant_pic_cnt_present_flag ? get_ue_golomb(gb) : 0;
   370   if (info.slice_type == 1 || info.slice_type == 6) {
   371     bool direct_spatial_mv_pred_flag = get_bit(gb);
   373   if (info.slice_type == 0 || info.slice_type == 5 ||  
   374       info.slice_type == 1 || info.slice_type == 6 ||  
   375       info.slice_type == 3 || info.slice_type == 8     
   377     bool num_ref_idx_active_override_flag = get_bit(gb);
   378     if (num_ref_idx_active_override_flag) {
   379       info.num_ref_idx_l0_active = get_ue_golomb(gb);
   380       if (info.slice_type == 1 || info.slice_type == 6) {
   381         info.num_ref_idx_l1_active = get_ue_golomb(gb);
   384       info.num_ref_idx_l0_active = pps.num_ref_idx_l0_default_active;
   385       info.num_ref_idx_l1_active = pps.num_ref_idx_l1_default_active;
   392 inline bool is_new_access_unit(std::map<u32, SPS>& sps_map,
   395   SPS& prev_sps = sps_map.at(prev.sps_id);
   396   SPS& curr_sps = sps_map.at(curr.sps_id);
   397   PPS& curr_pps = pps_map.at(curr.pps_id);
   398   if (curr.nal_unit_type != 5 && curr.frame_num != prev.frame_num) {
   399     VLOG(2) << 
"frame num";
   401   } 
else if (prev.pps_id != curr.pps_id) {
   404   } 
else if (prev.field_pic_flag != curr.field_pic_flag) {
   405     VLOG(2) << 
"field pic";
   407   } 
else if ((prev.bottom_field_flag != -1 && curr.bottom_field_flag != -1) &&
   408              prev.bottom_field_flag != curr.bottom_field_flag) {
   409     VLOG(2) << 
"bottom field";
   411   } 
else if ((prev.nal_ref_idc == 0 || curr.nal_ref_idc == 0) &&
   412              prev.nal_ref_idc != curr.nal_ref_idc) {
   413     VLOG(2) << 
"nal ref";
   415   } 
else if ((prev_sps.poc_type == 0 && curr_sps.poc_type == 0) &&
   416              (prev.pic_order_cnt_lsb != curr.pic_order_cnt_lsb ||
   417               prev.delta_pic_order_cnt_bottom !=
   418                   curr.delta_pic_order_cnt_bottom)) {
   419     VLOG(2) << 
"poc type 0: " << prev.pic_order_cnt_lsb << 
" vs. "   420             << curr.pic_order_cnt_lsb << 
", " << prev.delta_pic_order_cnt_bottom
   421             << 
" vs. " << curr.delta_pic_order_cnt_bottom;
   423   } 
else if ((prev_sps.poc_type == 1 && curr_sps.poc_type == 1) &&
   424              (prev.delta_pic_order_cnt[0] != curr.delta_pic_order_cnt[0] ||
   425               prev.delta_pic_order_cnt[1] != curr.delta_pic_order_cnt[1])) {
   426     VLOG(2) << 
"poc type 1";
   428   } 
else if ((prev.nal_unit_type == 5 || curr.nal_unit_type == 5) &&
   429              prev.nal_unit_type != curr.nal_unit_type) {
   430     VLOG(2) << 
"nal unit type";
   432   } 
else if ((prev.nal_unit_type == 5 && curr.nal_unit_type == 5) &&
   433              prev.idr_pic_id != curr.idr_pic_id) {
 
Definition: database.cpp:36