+ for( int i = 0; i < ((3 != i_chroma_format_idc) ? 8 : 12); i++ )
+ {
+ /* seq_scaling_list_present_flag[i] */
+ i_tmp = bs_read( &s, 1 );
+ if( !i_tmp )
+ continue;
+ const int i_size_of_scaling_list = (i < 6 ) ? 16 : 64;
+ /* scaling_list (...) */
+ int i_lastscale = 8;
+ int i_nextscale = 8;
+ for( int j = 0; j < i_size_of_scaling_list; j++ )
+ {
+ if( i_nextscale != 0 )
+ {
+ /* delta_scale */
+ i_tmp = bs_read( &s, 1 );
+ i_nextscale = ( i_lastscale + i_tmp + 256 ) % 256;
+ /* useDefaultScalingMatrixFlag = ... */
+ }
+ /* scalinglist[j] */
+ i_lastscale = ( i_nextscale == 0 ) ? i_lastscale : i_nextscale;
+ }
+ }
+ }
+ }
+
+ /* Skip i_log2_max_frame_num */
+ p_sys->i_log2_max_frame_num = bs_read_ue( &s );
+ if( p_sys->i_log2_max_frame_num > 12)
+ p_sys->i_log2_max_frame_num = 12;
+ /* Read poc_type */
+ p_sys->i_pic_order_cnt_type = bs_read_ue( &s );
+ if( p_sys->i_pic_order_cnt_type == 0 )
+ {
+ /* skip i_log2_max_poc_lsb */
+ p_sys->i_log2_max_pic_order_cnt_lsb = bs_read_ue( &s );
+ if( p_sys->i_log2_max_pic_order_cnt_lsb > 12 )
+ p_sys->i_log2_max_pic_order_cnt_lsb = 12;
+ }
+ else if( p_sys->i_pic_order_cnt_type == 1 )
+ {
+ int i_cycle;
+ /* skip b_delta_pic_order_always_zero */
+ p_sys->i_delta_pic_order_always_zero_flag = bs_read( &s, 1 );
+ /* skip i_offset_for_non_ref_pic */
+ bs_read_se( &s );
+ /* skip i_offset_for_top_to_bottom_field */
+ bs_read_se( &s );
+ /* read i_num_ref_frames_in_poc_cycle */
+ i_cycle = bs_read_ue( &s );
+ if( i_cycle > 256 ) i_cycle = 256;
+ while( i_cycle > 0 )
+ {
+ /* skip i_offset_for_ref_frame */
+ bs_read_se(&s );
+ i_cycle--;